๐ ZSHAND Header Standardยถ
Defines the documentation header convention for every source file in the ZSHAND framework โ scripts, functions, widgets, and configs alike.
๐ฏ Goal: Consistency ยท ๐ Scannability ยท ๐ค Machine-readability ยท ๐ก Discoverability
๐ง Philosophy
The default stance is include it. More useful info is better than less. Headers serve ๐ค humans, ๐ค AI assistants, and ๐ automated tooling equally. If a section might be useful, add it. You can always trim later โ but missing documentation is invisible and compounds.
๐งฐ Tooling Stackยถ
This standard is designed to work with the ZSHAND development toolchain. ๐ Headers should reference these tools where appropriate (e.g., just test in EXAMPLES, ๐งช ShellSpec specs in TESTING, โก Hyperfine thresholds in PERFORMANCE).
| Tool | Function | Config | Role in Headers |
|---|---|---|---|
| ๐ Just | Orchestration | Justfile | EXAMPLES use just <recipe> as primary invocation |
| โจ Trunk | Linting & Security | .trunk/ | LINTING section references ShellCheck/shfmt |
| ๐งช ShellSpec | Testing | spec/ | TESTING section references BDD-style specs |
| ๐ Kcov | Coverage | CI only | TESTING section references coverage targets |
| ๐ zshdb | Debugging | .vscode/launch.json | TROUBLESHOOTING can reference debug commands |
| โก Hyperfine | Benchmarking | CI / Justfile | PERFORMANCE section references benchmark targets |
| ๐ Direnv | Secrets | .envrc | ENVIRONMENT can note direnv-managed vars |
| ๐ EditorConfig | Consistency | .editorconfig | Alignment rules enforced automatically |
| ๐ณ Dev Containers | Onboarding | .devcontainer/ | SEE ALSO can reference for contributor setup |
๐จ Visual Elementsยถ
Measuring divider width
All dividers are 78 characters after #. Use just lint or trunk check to catch misaligned rules automatically.
๐๏ธ Title Box (Full tier only)ยถ
Used for complex files (200+ lines, multiple consumers, rich behavior). The box is exactly 80 characters wide after #:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ Title โ Short Description โ
# โ Extended description line two if needed. โ
# โ Extended description line three if needed. โ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Rules:
- โญ Content starts 2 spaces after
โ, rightโat fixed column - ๐ 2โ4 description lines inside the box
- โก๏ธ Use
โfor transformation descriptions (e.g., โlogs โ graded reportsโ)
โ๏ธ Title Line (Standard/Compact tiers)ยถ
Used for most files. Combines the name, a dash separator, and description:
# โโ name โ Short Description โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Rules:
- ๐ฏ
namematches the function/command name or filename (without.zsh) - โ๏ธ Use em-dash
โbetween name and description - ๐ Pad with
โto 78 characters after# - ๐ข For numbered files, include the number:
# โโ 06_engine โ High-Performance Execution Engine โโ...
โ๏ธ Section Dividersยถ
Every section uses an inline divider. The label is UPPERCASE, padded to 78 chars:
# โโ SECTION NAME โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Rules:
- โฌ๏ธ One blank comment line (
#) before and after each section divider - โฎ๏ธ Content indented 2 spaces from
#(i.e.,# content) - ๐ซ No blank lines between items within a section unless separating sub-groups
๐ Closing Ruleยถ
Every header ends with a plain thin rule:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ Emoji Referenceยถ
Emojis improve scannability in headers. Use them consistently across files. These are the recommended emojis for common header patterns:
๐ฆ Status Indicators (TESTING, ROADMAP)ยถ
| Emoji | Meaning | Usage |
|---|---|---|
| โ | Done / passing | Test scenario covered, feature complete |
| โฌ | Not yet done | Test scenario not yet written |
| โ ๏ธ | Partial / warning | Partially covered, needs attention |
| โ | Failing / blocked | Test failing, feature broken |
| ๐ง | Not yet written | Spec file doesn't exist yet |
๐ญ Section Content (OUTPUT, BEHAVIOR, TIPS)ยถ
| Emoji | Meaning | Usage |
|---|---|---|
| ๐ค | User item | User-sourced file or config in OUTPUT |
| ๐ฆ | System/framework item | Framework-sourced file in OUTPUT |
| ๐ | Security concern | Trust boundary, privileged operation |
| โก | Performance note | Speed-critical path, optimization |
| ๐ก | Tip / recommendation | Helpful advice in TIPS section |
| ๐ | Bug / known issue | Known issue in EDGE CASES or ROADMAP |
| ๐ง | Fix / workaround | Troubleshooting resolution |
๐ฆ Dependency Status (DEPENDENCIES)ยถ
| Emoji | Meaning | Usage |
|---|---|---|
| ๐ข | Required, present | Verified dependency |
| ๐ก | Optional | Nice-to-have dependency |
| ๐ด | Required, missing | Broken dependency |
๐ฅ Audience (TARGET USERS)ยถ
| Emoji | Meaning | Usage |
|---|---|---|
| ๐ค | Human developer | Direct user of the tool |
| ๐ | CI/CD pipeline | Automated consumer |
| ๐ค | AI assistant | Machine consumer parsing output |
๐บ๏ธ Priority / Effort (ROADMAP)ยถ
| Emoji | Meaning | Usage |
|---|---|---|
| ๐ข | Soon | Next up, high priority |
| ๐ก | Later | Medium priority, planned |
| ๐ต | Someday | Low priority, wishlist |
| Tag | Meaning |
|---|---|
[S] | Hours โ small task |
[M] | Days โ medium task |
[L] | Week โ large task |
[XL] | Multi-week โ epic |
๐ Environment (ENVIRONMENT, SECURITY)ยถ
| Emoji | Meaning | Usage |
|---|---|---|
| ๐ก | Direnv-managed | Variable set via .envrc |
| ๐ข | Clean / safe | No secrets, no network |
| โ ๏ธ | Caution | Secrets nearby, needs attention |
Emoji in code headers
Emojis in zsh comment headers render correctly in most modern terminals and all AI assistants. They're safe to use in # comment lines. Prefer text-based status (required/optional) for columnar data and emojis for checklist-style items.
Using emojis in TESTING
zsh # Must cover: # โ
Happy path with valid input # โ
Missing dependency โ exit 1 # โฌ Edge case: empty input # โฌ Edge case: path with spaces
๐ Section Referenceยถ
๐ Every possible section, in canonical order. The default stance is include it โ most files benefit from most sections. Only omit a section if it genuinely adds nothing (e.g., โญ GRADING SCALE on a utility function, or ๐ LOAD ORDER on a hook).
| # | Section | Full | Standard | Compact | Minimal | Notes |
|---|---|---|---|---|---|---|
| 1 | ๐ฅ TARGET USERS | rec | opt | โ | โ | Include if >1 audience (human, CI, AI) |
| 2 | โถ๏ธ USAGE / TRIGGER | req | req | req | req | TRIGGER for widgets, USAGE for all else |
| 3 | ๐ ENVIRONMENT | req | rec | opt | โ | Include if any env var affects behavior |
| 4 | ๐ค OUTPUT | req | rec | opt | โ | What stdout/stderr produce |
| 5 | ๐ LOAD ORDER | rec | opt | โ | โ | For files that define execution sequence |
| 6 | ๐ PIPELINE / WORKFLOW | rec | rec | opt | โ | PIPELINE for build, WORKFLOW for widgets |
| 7 | ๐ FILES | rec | rec | opt | โ | Input/output files with formats |
| 8 | ๐ฅ ARGUMENTS / OPTIONS | req | req | opt | โ | OPTIONS for bin/ CLI tools |
| 9 | ๐ฆ DEPENDENCIES | req | req | rec | โ | External commands and modules |
| 10 | โก PERFORMANCE | rec | rec | opt | โ | Benchmarks, Hyperfine thresholds |
| 11 | ๐ช EXIT CODES | req | req | req | โ | Every non-trivial script |
| 12 | ๐ง INTERNAL HELPERS | rec | opt | โ | โ | For files with internal sub-functions |
| 13 | โญ GRADING SCALE | opt | opt | โ | โ | Only for report/scoring tools |
| 14 | ๐ป EXAMPLES | req | req | req | opt | Concrete, copy-pasteable invocations |
| 15 | ๐ TROUBLESHOOTING | rec | rec | opt | โ | "error message" โ fix format |
| 16 | โ ๏ธ EDGE CASES | rec | rec | opt | โ | Table: condition โ behavior |
| 17 | ๐ก TIPS | rec | opt | โ | โ | Grouped: Accuracy, Analysis, Performance |
| 18 | โจ LINTING | rec | rec | opt | โ | ShellCheck/shfmt directives & overrides |
| 19 | ๐ SECURITY | rec | rec | opt | โ | Trust boundaries + Gitleaks compliance |
| 20 | ๐งช TESTING | req | rec | opt | โ | ShellSpec specs, Kcov, must-cover list |
| 21 | ๐ค AI INTEGRATION | rec | opt | โ | โ | For AI-consumed tools |
| 22 | ๐ HISTORY | rec | rec | opt | โ | Version log: vX.Y YYYY-MM-DD Desc |
| 23 | ๐บ๏ธ ROADMAP | rec | opt | โ | โ | Planned enhancements |
| 24 | ๐ SEE ALSO | req | req | rec | โ | Related files and external docs |
Key: ๐ข req = required ยท ๐ก rec = recommended (include unless genuinely N/A) ยท โช opt = include when useful ยท โ = skip
๐ Section Formatting Rulesยถ
๐ฅ TARGET USERSยถ
Bullet list describing who this file is for and why. Helps AI assistants scope their advice and helps contributors understand the audience.
When to include
Include whenever the file has more than one audience (e.g., human developers, CI pipelines, AI assistants) or when the audience is non-obvious (e.g., a private function only called by the build system).
# โโ TARGET USERS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ๐ค Human developers optimizing shell startup performance
# ๐ CI/CD pipelines monitoring for performance regressions
# ๐ค AI assistants analyzing bottlenecks and suggesting fixes
๐ Parsing: Each line starts with # followed by an optional emoji and the audience description. Regex: ^#\s{3}(\S+)\s+(.+)$
โถ๏ธ USAGE / TRIGGERยถ
Show the function signature with argument placeholders, then describe each argument in a columnar table. Include ๐ prerequisites, โฉ๏ธ return value, and โ how to verify it works.
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# function_name <required_arg> [optional_arg]
#
# $1 Description of first argument (type, required)
# $2 Description of second argument (type, optional, default: value)
#
# Returns: 0 on success, 1 on failure (see EXIT CODES)
# Output: Report to stdout (see OUTPUT)
#
# Prerequisite:
# Run `zprofile --full` first to generate timing data.
Angle brackets vs square brackets
Use <arg> for required arguments, [arg] for optional ones. This follows POSIX/man-page convention and is parseable.
For widgets, use TRIGGER instead:
# โโ TRIGGER โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Keybinding: Ctrl+E (configured in core/16_widgets.zsh)
# Direct: widget_name
# ZLE register: zle -N widget_name
# Verify: bindkey | grep widget_name
๐งช ShellSpec mapping: Each argument and prerequisite should have at least one spec scenario. The "Returns" line maps directly to your It "returns 0" blocks.
๐ ENVIRONMENTยถ
Columnar table. Columns: name, type, default, description. This is one of the most-referenced sections โ people want to know exactly what knobs exist and what they do.
# โโ ENVIRONMENT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ZSHAND_CACHE_DIR string $XDG_CACHE_HOME/zshand Cache directory
# ZSHAND_PROFILE_SHOW_ALL bool 0 Show all items
# ZSHAND_PROFILE_VERBOSE bool 0 Debug output
# COLUMNS int auto Terminal width
# ZSHAND_DEV_MODE bool 0 ๐ก via .envrc
Alignment: Pad variable names to longest + 2 spaces, type to 8 chars, default to context.
๐ Parsing regex: ^#\s{3}(\S+)\s+(\w+)\s+(\S+)\s+(.+)$ captures: (name, type, default, description)
Direnv flag
Mark direnv-managed variables with ๐ก in the description so developers know to check .envrc rather than setting them manually: zsh # ZSHAND_DEV_MODE bool 0 ๐ก via .envrc (direnv-managed)
๐ LOAD ORDERยถ
For files that define an execution sequence (entry points, build scripts). Number each step so the sequence is unambiguous. Include what happens if a step fails โ this matters for debugging startup issues.
# โโ LOAD ORDER โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1 shared_functions Error handling, logging, utilities (always first)
# 2 startup Early env checks, dev mode, clipboard
# 3 user_environment User's env.zsh, secrets.zsh, config.toml exports
# 4 init.d User's pre-core initialization scripts
# 5 core Framework engine, paths, audit, hooks, widgets
# 6 functions User-facing shell functions
# 7 widgets ZLE widgets (keybinding-driven tools)
# 8 hooks Tool integrations (mise, atuin, docker, ssh-agent)
# 9 plugins Third-party plugin loading
# 10 private_functions Internal framework functions (_-prefixed)
# 11 post.d User's post-core scripts and final overrides
๐ Parsing: ^#\s{3,}(\d+)\s{2}(\S+)\s+(.*?)$ captures: (step_num, phase_name, description)
๐ค OUTPUTยถ
๐ค Split by stream. Document what each stream produces, whether output is ๐ค human-readable or ๐ค machine-parseable, and how to โก๏ธ redirect or capture it.
# โโ OUTPUT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# stdout:
# Formatted performance report with grading, bar charts, and
# per-directory breakdown. Human-readable with ANSI color codes.
# Pipe-safe: detects non-interactive and disables color.
#
# stderr:
# Warnings and errors prefixed with โโโ or โโ โ.
# All errors include actionable fix instructions.
#
# Icons:
# ๐ค User-sourced item (from config directory)
# ๐ฆ Framework-sourced item (from ZSHAND base)
#
# Machine-readable:
# Pipe to `grep -P '^\s+\d' | awk '{print $NF}'` to extract timing values.
# Future: --json flag planned (see ROADMAP).
Parseable output
Document extraction patterns in OUTPUT so scripts and AI assistants can reliably parse the data without guessing at the format.
๐ PIPELINE / WORKFLOWยถ
๐ข Numbered steps. PIPELINE for data processing flows, WORKFLOW for user-interactive sequences. Include what happens on โ failure at each step โ this is critical for ๐ debugging and for ๐ค AI assistants tracing issues.
# โโ PIPELINE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1 Argument validation Check required paths exist โ exit 1
# 2 File discovery Walk framework + user dirs โ exit 1
# 3 Merge resolution User files override by basename โ continue
# 4 Concatenation Assemble source with markers โ exit 1
# 5 Compilation zcompile to .zwc bytecode โ exit 1
๐ Parsing: ^#\s{3}(\d+)\s{2}(\S.+?)\s{4,}(\S.+?)\s{4,}(.+)$ captures: (step_num, step_name, description, on_failure)
For widgets with complex multi-phase behavior, use WORKFLOW with sub-steps:
# โโ WORKFLOW โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1. Context Gathering
# - Read staged changes (git diff --cached)
# - Load project context via _get_project_context
# - Fail: abort with "nothing staged" message
#
# 2. Prompt Construction
# - Build AI prompt with context + diff
# - Fail: falls back to manual commit
๐ฅ ARGUMENTSยถ
For functions called by other framework code (lib/, private_functions/). Columnar: position, description, type + constraint, default. Include โ ๏ธ validation behavior โ what happens when arguments are wrong.
# โโ ARGUMENTS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# $1 Directory path to check (string, required)
# Must exist and be readable. Exit 1 if missing.
# $2 Base directory for deps (string, optional, default: $ZSHAND)
# Falls back to $ZSHAND if empty or unset.
# $3 Quiet mode (bool, optional, default: false)
# "true" suppresses all stdout output.
๐งช ShellSpec mapping: Each argument with validation should have a spec:
Describe "argument validation"
It "exits 1 when directory path missing"
It "uses ZSHAND as default base directory"
It "suppresses output in quiet mode"
End
๐๏ธ OPTIONS (for bin/ CLI tools)ยถ
For executable scripts in bin/ that accept flags and positional arguments. ๐ Group: positional args first, then short flags, then long flags. Note ๐ซ mutual exclusivity and constraints.
# โโ OPTIONS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Positional:
# <depth> Tree depth level (1-9, default: 2)
# <path> Directory to analyze (default: cwd)
#
# Flags:
# -c [file] Include file content (latest or specific path)
# -e Include sanitized .env keys (values stripped)
# -h Show help and exit
# --verbose Print debug information to stderr
#
# Constraints:
# -c and -e can be combined.
# -h overrides all other flags (prints help and exits 0).
๐ FILESยถ
Columnar: path, required/optional, description. Include ๐ format details for parseable files, ๐ permissions, and ๐งน cleanup behavior.
# โโ FILES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Input:
# $cache_dir/profile-timing.log required Raw timing data
# Format: TYPE|NAME|START|END (pipe-delimited, one entry per line)
# Perms: 644 (created by zprofile)
#
# Output:
# $cache_dir/zshand-full.zwc generated Compiled bytecode bundle
# Perms: 644 (overwritten on each rebuild)
# Cleanup: Stale .zwc removed by zprime --clean
#
# Temp:
# $cache_dir/.compile.lock transient Prevents concurrent builds
# Cleaned up on exit (trap EXIT)
Format details matter
Always document the format of parseable files (delimiter, encoding, line structure). This is the #1 thing people need when debugging data issues.
๐ฆ DEPENDENCIESยถ
Columnar: name, required/optional, description, version, ๐ฅ install hint, โ check command.
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# awk required Floating point arithmetic
# tput required Terminal width detection
# gum optional Enhanced terminal UI (graceful fallback)
# Install: just install-gum OR brew install gum
# Check: command -v gum
# zsh/datetime optional Benchmark via EPOCHREALTIME
# Version: 5.8+
# Install: zmodload zsh/datetime
# Check: zmodload zsh/datetime 2>/dev/null && echo ok
๐ Parsing: ^#\s{3}(\S+)\s+(required|optional)\s+(.+)$ captures: (name, required_or_optional, description)
๐งช ShellSpec mapping: Every required dependency needs a spec for the missing-dependency path. Every optional dependency needs a spec for the graceful fallback behavior.
๐ช EXIT CODESยถ
List every exit code the script can return. Include the ๐ฏ condition that triggers it. Group by code number. Note ๐จ signal handling if applicable.
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Report generated successfully
# 1 No timing data found (missing profile-timing.log)
# 1 Analysis failed (zero total time, divide-by-zero guard)
# 2 Invalid arguments (unrecognized option or bad path)
#
# Signals:
# SIGINT (Ctrl+C) Cleans up temp files, exits 130
# SIGTERM Cleans up temp files, exits 143
For display-only functions that always return 0, say so explicitly:
๐ Parsing: ^#\s{3}(\d+)\s{2}(.+)$ captures: (code, description)
๐งช ShellSpec mapping: Each exit code is a spec:
It "exits 0 on successful report generation"
It "exits 1 when timing data is missing"
It "exits 2 on invalid arguments"
๐ง INTERNAL HELPERSยถ
Document internal sub-functions, math wrappers, or private helpers defined within the file. Group by concern. Include approximate line numbers so maintainers can jump directly to the implementation.
# โโ INTERNAL HELPERS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Floating point math wrappers (~L280, zsh integer-only workaround):
# _fadd, _fsub, _fmul, _fdiv Basic arithmetic (9 decimal places)
# _fgt, _fge, _fle Comparisons (via exit code)
# _fms Convert seconds โ milliseconds
# _fpct Calculate percentage
#
# Rendering (~L350):
# _make_bar Render โโ progress bar (scaled to max)
#
# Constants:
# Widget slow threshold: 5ms (hardcoded)
# Plugin slow threshold: 10ms (triggers lazy-load suggestion)
Line number hints
Approximate line numbers (~L280) help maintainers navigate large files. They don't need to be exact โ update them when you do major refactors.
โญ GRADING SCALEยถ
๐ Only for files that produce scored/graded output. Show the full scale with ๐ thresholds, โญ symbols, and ๐ค human-readable descriptions.
# โโ GRADING SCALE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# A โ
โ
โ
โ
< 50ms Excellent โ near-instant startup
# A- โ
โ
โ
โ < 100ms Great โ barely perceptible delay
# B โ
โ
โ
< 150ms Good โ fast enough for most users
# B- โ
โ
โ < 200ms Acceptable โ room for improvement
# C โ
โ
< 250ms Mediocre โ consider optimizations
# C- โ
โ < 350ms Slow โ deferred loading recommended
# D โ
< 500ms Poor โ significant optimization needed
# F โฅ 500ms Failing โ major performance issues
๐ป EXAMPLESยถ
๐ Concrete, copy-pasteable. Group by scenario with # comment labels. ๐ Prefer just recipes first, then raw commands. Include โ
expected output for non-obvious commands so users know what ๐ success looks like.
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Via Just (preferred)
# just test # Run full test suite
# just test spec/unit # Run specific spec
# just bench # Benchmark startup time
#
# # Direct invocation
# function_name
# function_name "arg1"
# # โ Expected: "Success: processed 42 items"
#
# # Scripted / CI usage
# result=$(function_name | grep "pattern")
# echo $? # โ 0 on success
๐งช ShellSpec mapping: Every example should be verifiable as a spec scenario. Each # group label maps to a Describe block:
Describe "via just"
It "runs full test suite"
It "runs specific spec"
End
Describe "direct invocation"
It "succeeds with no arguments"
It "succeeds with arg1"
End
๐ TROUBLESHOOTINGยถ
๐ Lookup table format โ quoted error message, then structured fix with labeled steps: ๐ Cause, ๐ฌ Inspect, ๐ง Fix, โ Verify. Include every user-visible error the script can produce. ๐จ This section is the first place people look when something breaks.
# โโ TROUBLESHOOTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ๐ง "No timing data found"
# Cause: Profiling data hasn't been generated yet.
# Fix: zprofile --full && _zshand_profile_bundle_report
# Verify: ls -la "$cache_dir/profile-timing.log"
#
# ๐ง "awk: cmd. line:1: error"
# Cause: Corrupted entries in timing log.
# Inspect: head -20 "$cache_dir/profile-timing.log"
# Fix: zprofile --rebuild
#
# ๐ง "tput: unknown terminal"
# Cause: Terminal type not recognized by ncurses.
# Fix: export COLUMNS=120
#
# ๐ง "Permission denied"
# Cause: Cannot read cache directory or timing logs.
# Inspect: ls -la "$cache_dir/"
# Fix: chmod 644 "$cache_dir/profile-timing.log"
#
# ๐ Debug with zshdb (step-through):
# zshdb build/profile_bundle_report.zsh
Error messages are spec scenarios
Every quoted error in TROUBLESHOOTING should have a ShellSpec scenario that triggers that error and verifies the message and exit code: It "prints 'No timing data found' when log missing"
โ ๏ธ EDGE CASESยถ
Columnar: condition โ behavior. Document every ๐ฏ boundary condition, ๐ก๏ธ graceful fallback, and ๐ค unusual input the script handles. This is the ๐ฅ second most important section for CI reliability (after EXIT CODES).
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# No timing data โ exit 1 with instructions
# Missing gum โ falls back to plain text automatically
# Terminal too narrow โ clamps to minimum 80 columns
# Terminal too wide โ caps at 200 columns for readability
# Invalid timing data โ skips malformed entries, warns on stderr
# Zero total time โ exit 1 instead of divide-by-zero
# Missing exceptions โ runs without filtering, flags all items
# Empty cache dir โ creates directory, or errors clearly
# Non-interactive โ detects pipe/redirect, disables color
๐ Parsing: ^#\s{3}(\S.+?)\s{2,}โ\s{2}(.+)$ captures: (condition, behavior)
๐งช ShellSpec mapping: Every edge case row is a spec:
Describe "edge cases"
It "clamps terminal width to minimum 80"
It "falls back to plain text when gum missing"
It "exits 1 on zero total time"
End
โจ LINTINGยถ
โจ Document ShellCheck directives, shfmt compliance, and any overrides. โ ๏ธ Every override must be justified โ unexplained disables are tech debt.
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ShellCheck: โ
Clean (managed by Trunk, auto-run on commit)
# shfmt: โ
Formatted per .editorconfig rules
# Dialect: zsh (default) / bash (for installers)
#
# Overrides:
# # shellcheck disable=SC2034 โ Variable used by caller via eval
# # shellcheck disable=SC2086 โ Intentional word splitting for $opts
#
# Verify: trunk check <file> OR just lint
If there are no overrides, a one-liner is fine:
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# โ
Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
Common ShellCheck overrides
If you find yourself disabling the same SC code across many files, add it to .trunk/configs/.shellcheckrc instead of per-file overrides.
๐ SECURITYยถ
๐ก๏ธ Trust boundary table. Think about: what data โก๏ธ flows in, what โฌ ๏ธ flows out, what could go wrong if this code were ๐จ compromised or misused.
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads Cache files, timing logs, framework source
# Writes stdout report (or "None โ pure function")
# Network None (or: "ICMP ping to 8.8.8.8")
# Privileges None โ user-level only (or: "sudo for apt")
# Data Shell metadata; no credentials or PII
# Secrets ๐ข None (or: ๐ก ".envrc secrets via direnv")
# Gitleaks โ
Clean (or: โ ๏ธ override needed โ explain why)
For simple files, an inline one-liner works:
๐ Parsing: ^#\s{3}(\w+)\s+(.*?)$ captures: (field, value)
๐งช TESTINGยถ
The TESTING section documents ๐ฏ what should be tested, ๐ where the tests live, โถ๏ธ how to run them, and โฌ what's still missing. This section serves as both a โก quick-reference for running tests and a โ living checklist for test coverage.
๐ Full format โ for files with complex behavior and multiple code paths:
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/build/profile_bundle_report_spec.sh
# Run: just test spec/build/profile_bundle_report_spec.sh
# Coverage: Kcov via CI (target: 90%+)
# Status: โ
Passing (last verified: 2026-02-05)
#
# Must cover:
# โ
Report generation with valid timing data
# โ
Missing timing log โ graceful error (exit 1)
# โ
Grade calculation at every boundary (A through F)
# โ
Gum rendering path vs plain text fallback
# โ
Terminal width clamping (narrow, wide, default)
# โ
Profile exception filtering
# โฌ Deferred/lazy operation analysis accuracy
# โฌ Real startup benchmark (3-run average) correctness
# โฌ CI pipeline integration (machine-readable output)
#
# TODO:
# - Add spec for ZSHAND_PROFILE_VERBOSE=1 output differences
# - Add edge case spec for corrupted timing log entries
# - Benchmark spec: verify Hyperfine threshold enforcement
๐ Key elements:
- ๐งช Spec โ path to the ShellSpec spec file (mirrors source tree)
- โถ๏ธ Run โ the
justcommand to execute it - ๐ Coverage โ Kcov target percentage
- ๐ฆ Status โ โ Passing, โ ๏ธ Partial, โ Failing, or ๐ง Not yet written
- โ Must cover โ checklist of scenarios that should have specs (โ done, โฌ not yet)
- ๐ TODO โ specific test gaps to fill, ordered by priority
๐ Standard format โ for files with straightforward behavior:
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/functions/dcopy_spec.sh
# Run: just test spec/functions/dcopy_spec.sh
# Status: โ
Passing
#
# Must cover:
# โ
Copies $PWD to clipboard successfully
# โ
Exits 1 when wl-copy missing
# โ
Handles paths with spaces and special characters
# โฌ Non-Wayland environment detection
Compact format โ for simple utilities where testing is minimal:
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/functions/dcopy_spec.sh Run: just test spec/functions/
# Status: โ
Passing Must cover: clipboard copy, missing dep, special chars
When spec doesn't exist yet:
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/hooks/01_mise_spec.sh (๐ง not yet written)
# Status: ๐ง No spec
#
# Must cover:
# โฌ Skip when mise not installed
# โฌ Cache regeneration when binary newer
# โฌ Cache directory creation failure
# โฌ Deferred activation timing
ShellSpec BDD structure (click to expand)
Each "Must cover" item maps to a ShellSpec It block. Structure your spec file to mirror the header sections:
```sh
# spec/hooks/01_mise_spec.sh
Describe "01_mise.zsh"
Include "hooks/01_mise.zsh"
Describe "when mise is not installed"
setup() { PATH="/empty"; }
It "skips silently"
When call source hooks/01_mise.zsh
The status should be success
The stderr should be blank
End
End
Describe "cache management"
It "regenerates cache when binary newer"
It "creates cache directory if missing"
It "handles cache directory creation failure"
End
End
```
**Naming convention:** `spec/<dir>/<name>_spec.sh` mirrors `<dir>/<name>.zsh`.
**Common matchers:**
| Matcher | Usage |
|---------|-------|
| `The status should be success` | Exit code 0 |
| `The status should be failure` | Exit code non-zero |
| `The output should include "text"` | stdout contains |
| `The stderr should include "text"` | stderr contains |
| `The variable VAR should eq "val"` | Variable check |
| `The path "file" should be exist` | File exists |
โก PERFORMANCEยถ
โก Document execution time, ๐ algorithmic complexity, ๐ป benchmark commands, and ๐ CI thresholds. Include a ๐ baseline so regressions are detectable.
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Execution time <100ms typical, <5ms cached path
# Complexity O(n) where n = timing entries
# Memory ~4MB resident (report generation)
#
# Baseline (2026-02-03, higtop):
# just bench โ mean 3.2ms ยฑ 0.4ms (3-run warm)
#
# Benchmark:
# just bench # Full startup benchmark
# hyperfine --warmup 3 'zsh -ic exit' # Raw startup time
# hyperfine --warmup 3 'source file.zsh' # Single file load time
#
# CI threshold: Fails build if startup regresses > 10ms vs baseline
# Regression: Compare with `just bench --export-json` across commits
Keep baselines fresh
Update the baseline date and machine name when significant changes land. Stale baselines make regression detection meaningless.
For simple files, an inline format works:
๐ก TIPSยถ
๐ก Grouped practical advice. Organize into sub-headings by concern. Use ๐ก emoji prefix for tips and โ ๏ธ for gotchas so theyโre ๐๏ธ scannable at a glance.
# โโ TIPS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Accuracy:
# ๐ก Always run `zprofile` immediately before analysis for fresh data
# ๐ก Use `zprofile --rebuild` if timing data seems stale
# โ ๏ธ Profiled times include instrumentation overhead; real startup is faster
# ๐ก The real startup benchmark (3-run average) shows actual user experience
#
# Analysis:
# ๐ก ZSHAND_PROFILE_SHOW_ALL=1 for the full component listing
# ๐ก Set COLUMNS for consistent output when piping or scripting
# ๐ก Pipe to `less -R` for color-preserving paging of long reports
# ๐ก Focus on the bottleneck directory first โ biggest wins there
#
# Performance:
# ๐ก Install gum for enhanced visual readability
# ๐ก Items in profile-exceptions.conf are excluded from slow warnings
# ๐ก Consider lazy-loading any plugin above 10ms
# ๐ก Compare reports across framework versions for trend analysis
# ๐ก Run `just bench` to verify improvements with Hyperfine
๐ค AI INTEGRATIONยถ
๐ค For tools that produce output consumed by AI assistants. Document: ๐ฏ what an AI should do with this file/output, ๐ how to parse it, and ๐ what patterns to look for.
# โโ AI INTEGRATION โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Use cases:
# ๐ค Identify optimization opportunities from timing data
# ๐ค Suggest lazy-loading for slow components (>10ms threshold)
# ๐ค Compare performance across framework versions
# ๐ค Flag performance regressions in pull requests
# ๐ค Help diagnose slow startup issues via bottleneck analysis
#
# Parsing patterns:
# Timing log: grep 'TYPE|NAME' $cache_dir/profile-timing.log
# Grade: grep -oP 'Grade: \K[A-F][+-]?'
# Total time: grep -oP 'Total: \K[\d.]+ms'
# Slow items: grep 'โ ' (items flagged as slow)
#
# AI-friendly features:
# โ
Structured, parseable output with reliable extraction patterns
# โ
Consistent error messages (grep-able, deterministic)
# โ
Pipe-separated timing log format (TYPE|NAME|START|END)
# โ
Idempotent โ safe for repeated execution
# โ
Headers follow this standard for consistent context gathering
AI context gathering
When an AI assistant reads a file with this header standard, it can extract structured information from any section using the documented parsing regexes. This makes the headers a reliable API for AI tools.
๐ HISTORYยถ
๐ Version table. Newest version first. Use ๐ YYYY-MM-DD dates (at minimum YYYY-MM) so changes can be correlated with git history and CI runs. For major rewrites, note the architectural shift. Tag โ ๏ธ breaking changes clearly.
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v2.0 2026-02-03 โ ๏ธ Terminal-width awareness, gum integration, enhanced UI,
# real startup benchmarking, user/system item icons
# Breaking: removed --legacy flag, changed exit codes
# v1.5 2025-08-15 Deferred/lazy operation analysis, performance grading
# v1.0 2024-11-20 Initial implementation with basic text output
๐ Parsing: ^#\s{3}(v[\d.]+)\s{2}(\d{4}-\d{2}-\d{2})\s{2}(.+)$ captures: (version, date, description)
๐บ๏ธ ROADMAPยถ
๐บ๏ธ Planned enhancements. Ordered by priority. Include ๐๏ธ effort estimate so contributors can pick appropriately-sized tasks. ๐ฅ Helps avoid duplicate work.
# โโ ROADMAP โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ๐ข Soon:
# - JSON output for programmatic consumption [M]
# - Historical trend analysis across multiple runs [L]
#
# ๐ก Later:
# - Memory profiling (RAM usage alongside timing) [L]
# - Configurable performance thresholds and alerting [M]
#
# ๐ต Someday:
# - AI-enhanced recommendations using pattern detection [XL]
# - Flamegraph-style visualization for deep analysis [XL]
#
# Effort: [S] = hours, [M] = days, [L] = week, [XL] = multi-week
๐ SEE ALSOยถ
๐ Columnar: name/file, description or URL. Group by category: ๐ framework files first, then ๐งช specs, then ๐ external docs. Always include the spec file.
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Framework:
# profile_time_all_widgets.zsh Widget profiling data source
# compile_profile_bundle.zsh Bundle compilation with profiling
# zprofile High-level profiling command (caller)
# profile-exceptions.conf Per-item performance exception rules
#
# Specs:
# spec/build/profile_bundle_report_spec.sh Tests for this file
#
# External:
# gum https://github.com/charmbracelet/gum
# awk https://www.gnu.org/software/gawk/manual/
# tput https://man7.org/linux/man-pages/man1/tput.1.html
# Zsh modules https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html
#
# Tooling:
# Justfile Task orchestration (just --list)
# .devcontainer/ Contributor onboarding
# spec/ ShellSpec test suite
Always link the spec file
Every SEE ALSO section should include a Specs group pointing to the corresponding ShellSpec file. This makes it trivial to jump between source and tests.
MkDocs note: In the rendered docs site, SEE ALSO entries for framework files can be converted to cross-reference links if you use the autorefs plugin.
๐งช ShellSpec Integrationยถ
This standard is designed to work hand-in-hand with ShellSpec. Every header section maps to spec scenarios, creating a traceable link between documentation and test coverage.
๐บ๏ธ Header โ Spec Mappingยถ
| Header Section | Maps to ShellSpec | Example |
|---|---|---|
| โถ๏ธ USAGE | Describe "usage" | Signature, arguments, prerequisites |
| ๐ช EXIT CODES | The status should be success/failure | Every exit code = a spec |
| โ ๏ธ EDGE CASES | Describe "edge cases" | Every row = an It block |
| ๐ TROUBLESHOOTING | It "prints error when..." | Every error message = a spec |
| ๐ป EXAMPLES | Describe "examples" | Every example = a verifiable spec |
| ๐ฆ DEPENDENCIES | Describe "missing dependencies" | Required deps: missing โ exit 1 |
| ๐ ENVIRONMENT | Describe "environment" | Each var: unset, default, override |
๐ Spec File Conventionsยถ
spec/
โโโ build/
โ โโโ profile_bundle_report_spec.sh # โ build/profile_bundle_report.zsh
โโโ core/
โ โโโ 06_engine_spec.sh # โ core/06_engine.zsh
โโโ functions/
โ โโโ dcopy_spec.sh # โ functions/dcopy.zsh
โโโ hooks/
โ โโโ 01_mise_spec.sh # โ hooks/01_mise.zsh
โโโ spec_helper.sh # Shared setup (sourced by all specs)
Rule: spec/<dir>/<name>_spec.sh mirrors <dir>/<name>.zsh.
๐ Spec Structure Templateยถ
# spec/functions/dcopy_spec.sh
Describe "dcopy.zsh"
Include "functions/dcopy.zsh"
# Maps to: USAGE section
Describe "usage"
It "copies current directory to clipboard"
# ...
End
End
# Maps to: EXIT CODES section
Describe "exit codes"
It "returns 0 on success"
It "returns 1 when wl-copy missing"
End
# Maps to: EDGE CASES section
Describe "edge cases"
It "handles paths with spaces"
It "handles paths with special characters"
End
# Maps to: ENVIRONMENT section
Describe "environment"
It "respects WAYLAND_DISPLAY"
End
End
โถ๏ธ Running Specsยถ
just test # All specs
just test spec/functions/ # One directory
just test spec/functions/dcopy_spec.sh # One file
just coverage # Kcov report (CI)
!!! info "Coverage targets" - Core modules: 90%+ (critical path) - Build scripts: 80%+ (complex but less frequently changed) - Functions/widgets: 70%+ (user-facing) - Hooks/startup: 60%+ (hard to test in isolation)
๐๏ธ Tier Systemยถ
When in doubt, tier up
If you're unsure whether a file is Standard or Full, lean toward the higher tier. Extra documentation never hurts; missing documentation always does.
๐ Full Tierยถ
When: Complex files with 200+ lines, multiple consumers, rich configuration, or central importance to the framework (build scripts, entry points, complex widgets).
๐จ Title: โโโ box ๐ข Required: USAGE, ENVIRONMENT, OUTPUT, DEPENDENCIES, EXIT CODES, EXAMPLES, TESTING, SEE ALSO ๐ก Include most of: PIPELINE/WORKFLOW, FILES, PERFORMANCE, EDGE CASES, TROUBLESHOOTING, LINTING, SECURITY, HISTORY, TIPS, AI INTEGRATION, ROADMAP, INTERNAL HELPERS
๐ฌ Full-tier files should aim for near-complete coverage. If a section exists in the reference table, it probably belongs here. Donโt count lines โ focus on covering every section that adds value.
๐ Files that qualify:
- ๐๏ธ
build/profile_bundle_report.zshโ โญ reference implementation - ๐๏ธ
build/compile_full_bundle.zsh - ๐ฏ
zshrc.zsh - ๐ฏ
setup.zsh - โจ๏ธ
widgets/aicmit.zsh - โจ๏ธ
widgets/aidebug.zsh - โ๏ธ
core/06_engine.zsh
๐ Standard Tierยถ
When: Most files. Functions, hooks, startup scripts, installers, lib modules, bin tools, private functions โ anything with meaningful behavior worth documenting.
๐จ Title: โโ name โ Description โโ line ๐ข Required: PURPOSE (in title or first paragraph), USAGE, DEPENDENCIES, EXIT CODES, EXAMPLES ๐ก Include most of: ENVIRONMENT, OUTPUT, PIPELINE/WORKFLOW, FILES, PERFORMANCE, EDGE CASES, TROUBLESHOOTING, LINTING, SECURITY, TESTING, HISTORY, SEE ALSO
๐ฌ When in doubt, add the section โ more useful info is better than less.
๐ Files that qualify:
- ๐ ๏ธ
functions/*.zsh - ๐ชจ
hooks/*.zsh - ๐
startup/*.zsh - ๐
bin/* - ๐ฅ
installers/*.sh,installers/*.zsh - ๐
lib/**/*.zsh - ๐
private_functions/*.zsh - โ๏ธ
core/*.zsh(simpler ones) - โจ๏ธ
widgets/*.zsh(simpler ones) - ๐งช
spec/**/*_spec.sh(complex spec files)
๐ฆ Compact Tierยถ
When: Small utility functions under ~50 lines with simple, obvious behavior.
๐จ Title: โโ name โ Description โโ line ๐ข Required: PURPOSE (in title), USAGE, EXIT CODES, EXAMPLES โช Include when relevant: DEPENDENCIES, OUTPUT, EDGE CASES, TESTING, LINTING, SECURITY, TROUBLESHOOTING, SEE ALSO, HISTORY, PERFORMANCE
๐ฌ Even compact files benefit from most sections in short form. A one-liner TESTING or LINTING section costs one line and adds real value.
๐ Files that qualify:
- ๐งฑ
shared_functions/*.zsh - ๐ ๏ธ Very small
functions/*.zsh - ๐งช Simple ShellSpec helpers in
spec/support/
๐ท๏ธ Minimal Tierยถ
When: Config files, dependency manifests, orchestration files, or files where the format is self-documenting.
๐จ Title: Brief # comment block (no dividers) โช Required sections: None formal โ just a brief description and format example
๐ Files that qualify:
- โ๏ธ
config/*.conf - ๐ฆ
.zshand-depsmanifests - ๐
Justfile - ๐
.envrc - ๐
.editorconfig - ๐ณ
.devcontainer/devcontainer.json - ๐งฐ
spec/spec_helper.sh(ShellSpec bootstrap)
๐ File Type Variationsยถ
Collapsible templates
Each file type below includes a complete example header. In MkDocs, these render as collapsible sections โ click to expand the one you need.
๐๏ธ build/*.zsh โ Build System Scriptsยถ
๐๏ธ Tier: Full (for complex scripts) or Standard (for simpler build helpers)
โญ Distinguishing: PIPELINE, FILES (with format details), PERFORMANCE, INTERNAL HELPERS ๐ก Recommended: TESTING (full format), EDGE CASES, LINTING, SECURITY (when touching user files)
#!/usr/bin/env zsh
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ ZSHAND Build System: Full Bundle Compiler โ
# โ Builds a single .zwc bytecode bundle containing the entire ZSHAND โ
# โ framework plus user config. Merges files in correct load order with โ
# โ user overrides, then compiles to optimized bytecode. โ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# _zshand_compile_full_bundle "$base" "$config" [cache_dir] [quiet]
#
# $1 Base ZSHAND directory (string, required)
# $2 User config directory ZSHAND_CONFIG_DIR (string, required)
# $3 Cache directory (string, optional, default: ZSHAND_CACHE_DIR)
# $4 "true" for quiet operation (bool, optional)
#
# โโ ENVIRONMENT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ZSHAND_CACHE_DIR string $XDG_CACHE_HOME/zshand Cache directory
# ZSHAND_CONFIG_DIR string $XDG_CONFIG_HOME/zshand User config directory
# ZSHAND_BASE_DIR string auto-detect Framework root
#
# โโ PIPELINE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1 Argument validation Check required paths exist
# 2 File discovery Walk framework + user dirs in load order
# 3 Merge resolution User files override framework by basename
# 4 Concatenation Assemble zshand-full.zsh with debug markers
# 5 Compilation zcompile to zshand-full.zwc bytecode
#
# โโ FILES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Input:
# $base_dir/shared_functions/*.zsh required Framework shared functions
# $config_dir/env.zsh optional User environment variables
# $config_dir/secrets.zsh optional User API keys and tokens
# $config_dir/config.toml optional Parsed to shell exports
#
# Output:
# $cache_dir/zshand-full.zsh Concatenated source with markers
# $cache_dir/zshand-full.zwc Bytecode bundle (fast loading)
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# zcompile required Zsh bytecode compiler
# find required File discovery in directories
# sort required Deterministic file ordering
#
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Execution time <200ms typical (depends on file count)
# Complexity O(n) where n = total framework + user files
# File I/O Two passes: discovery + concatenation
#
# Benchmark:
# just build
# hyperfine 'zsh -c "source build/compile_full_bundle.zsh; ..."'
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Full bundle created successfully
# 1 Missing dependencies, invalid paths, or compilation failure
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Via Just
# just build
#
# # Direct invocation
# _zshand_compile_full_bundle "$ZSHAND" "$ZSHAND_CONFIG"
# _zshand_compile_full_bundle "$ZSHAND" "$ZSHAND_CONFIG" "/tmp/cache" true
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# No user config dir Compiles framework-only bundle
# Empty directories Skips gracefully, no empty markers
# Duplicate basenames User file wins (override by convention)
# Missing cache dir Creates it automatically
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/build/compile_full_bundle_spec.sh
# Run: just test spec/build/compile_full_bundle_spec.sh
# Coverage: Kcov via CI (target: 90%+)
# Status: โ
Passing
#
# Must cover:
# โ
Argument validation (missing paths)
# โ
File discovery across all framework directories
# โ
User override resolution (duplicate basenames)
# โ
Concatenation with debug markers
# โ
zcompile bytecode generation
# โฌ Framework-only bundle (no user config)
# โฌ Empty directories in load order
#
# TODO:
# - Add spec for incremental rebuild (only changed dirs)
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# compile_profile_bundle.zsh Profiling-instrumented variant
# optimize_startup.zsh Startup optimization passes
# profile_bundle_report.zsh Performance reporting (reference impl)
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ core/*.zsh โ Framework Core Modulesยถ
โ๏ธ Tier: Standard (most) or Full (engine, major modules)
โญ Distinguishing: BEHAVIOR (numbered steps), note about auto-loading. ๐ข Include the numbered prefix in the title. ๐ก Recommended: TESTING, EDGE CASES, LINTING, PERFORMANCE (startup-critical code), SECURITY (when touching file permissions, network, or daemon lifecycle).
๐ฌ Core modules are the backbone โ they deserve thorough coverage.
#!/usr/bin/env zsh
# โโ 06_engine โ High-Performance Execution Engine & Bootstrapper โโโโโโโโโโโโ
#
# Core framework engine providing system initialization, command execution
# logging (zrun), and compilation/reload infrastructure (zprime). Handles
# Atuin daemon lifecycle, file permissions, completion generation, and
# .zwc bytecode compilation for optimal shell startup performance.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Loaded automatically during shell initialization (core loading sequence).
# Functions become globally available after sourcing.
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# - System initialization: Atuin daemon, security, terminal titles
# - Command execution: zrun wrapper with telemetry and validation
# - Framework compilation: zprime engine for bytecode compilation
# - Directory compilation: Single-directory rebuilds, incremental updates
# - Completion generation: Atomic generation for external tools
# - Bundle compilation: Framework directories into optimized .zwc bundles
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# zsh 5.0+ required Base shell with zcompile support
# date required Timestamp generation for logs
# chmod required File permission enforcement
# find required File discovery for compilation
# atuin optional History sync daemon management
# git optional Auto-backup before destructive operations
# ping optional Network connectivity check
# gh optional GitHub CLI completions
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Normal operation (functions loaded, zprime success)
# 1 Compilation failure or missing framework directory
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Execute with telemetry logging
# zrun "mise install"
#
# # Recompile and reload framework
# zprime
# zprime --quiet
#
# # Via Just
# just build
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Missing atuin Skips daemon management gracefully
# No network Defers sync, logs warning
# Stale .zwc bundles Detected and rebuilt automatically
# Read-only filesystem Logs warning, continues without compilation
#
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Load time <5ms (sourced at every shell startup)
# zprime time <500ms typical (full framework recompile)
# zrun overhead <1ms per invocation (telemetry wrapper)
#
# Benchmark:
# just bench
# hyperfine --warmup 3 'zsh -ic exit'
#
# CI threshold: Core load must not regress startup by >2ms
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads Framework source files, cache directory, timing logs
# Writes .zwc bytecode bundles, completion files, cache data
# Network Atuin sync (via daemon), connectivity checks (ping)
# Privileges None (user-level only)
# Data Shell configuration and metadata; no credentials
# Gitleaks Clean (no secrets handled directly)
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/core/06_engine_spec.sh
# Run: just test spec/core/06_engine_spec.sh
# Coverage: Kcov via CI (target: 85%+)
# Status: โ ๏ธ Partial
#
# Must cover:
# โ
zprime recompile and reload
# โ
zrun telemetry logging
# โ
Directory compilation (.zwc generation)
# โ
Atuin daemon start/stop lifecycle
# โ
Permission enforcement (chmod on sensitive files)
# โฌ Completion generation (atomic write)
# โฌ Incremental rebuild detection
# โฌ Network-offline graceful degradation
# โฌ Read-only filesystem handling
#
# TODO:
# - Add spec for completion generation race conditions
# - Add benchmark spec: zprime must complete in <500ms
# - Test zrun with commands that produce stderr
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# core/04_path.zsh Path management and $PATH construction
# core/08_audit.zsh Security auditing and permission checks
# build/optimize_startup.zsh Startup optimization passes
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ๏ธ functions/*.zsh โ User-Facing Shell Functionsยถ
๐ ๏ธ Tier: Standard
โญ Distinguishing: OUTPUT (what the user sees), BEHAVIOR (step-by-step). ๐ก Recommended: TESTING (standard format), EDGE CASES, TROUBLESHOOTING.
# โโ dcopy โ Copy Current Directory Path to Clipboard โโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Copies $PWD to the system clipboard for use in terminals, editors, and
# AI assistants. Designed for Wayland environments with robust error handling.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# dcopy
#
# โโ OUTPUT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# stdout: Confirmation message with the copied path
# stderr: Error messages with exit code
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# - Uses $PWD directly (faster than external pwd)
# - Handles path escaping for display
# - Validates dependencies before attempting copy
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# wl-copy required Wayland clipboard utility
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Path copied successfully
# 1 Missing dependency or clipboard failure
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# dcopy # Copy current directory
# dcopy && cd /tmp # Copy, then change dir
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# wl-copy missing Exits 1 with install hint
# Empty $PWD Should not happen (always set by shell)
# Path with spaces Handled correctly via quoting
# Non-Wayland env Exits 1 (wl-copy requires Wayland)
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/functions/dcopy_spec.sh
# Run: just test spec/functions/dcopy_spec.sh
# Status: โ
Passing
#
# Must cover:
# โ
Copies $PWD to clipboard successfully
# โ
Exits 1 when wl-copy missing
# โ
Handles paths with spaces and special characters
# โฌ Non-Wayland environment detection
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# shared_functions/09_clipboard.zsh Low-level clipboard abstraction
# wl-copy https://github.com/bugaevc/wl-clipboard
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งฑ shared_functions/*.zsh โ Small Utility Functionsยถ
๐งฑ Tier: Compact
โญ Distinguishing: Simple building blocks. PURPOSE is embedded in the title line.
๐ฌ Even compact files should carry most sections โ keep each one short (1โ3 lines) but present. A one-liner TESTING or LINTING section costs almost nothing.
#!/usr/bin/env zsh
# โโ stderr_error โ Red Error Message to stderr โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# stderr_error "message"
#
# โโ OUTPUT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# stderr: Red "๓ฑธ ERROR:" prefix followed by message
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# None (uses only zsh builtins: print -P)
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Always (display function, no failure mode)
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# stderr_error "Config not found"
# stderr_error "Failed to compile: $file"
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Empty message Prints prefix with no text (valid but odd)
# Multi-line input Each line gets the ERROR prefix
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads: None Writes: stderr only Network: None Gitleaks: Clean
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/shared_functions/stderr_error_spec.sh
# Run: just test spec/shared_functions/stderr_error_spec.sh
# Status: โ
Passing Must cover: output format, empty input
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v1.0 2024-11-20 Initial implementation
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 02_stderr_warn.zsh Warning-level variant (yellow)
# 04_echo_info.zsh Info-level variant (stdout, blue)
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โจ๏ธ widgets/*.zsh โ ZLE Widgetsยถ
โจ๏ธ Tier: Full (complex widgets) or Standard (simple widgets)
โญ Distinguishing: TRIGGER (not USAGE), VERSION, WORKFLOW (not PIPELINE). ๐จ Widgets are interactive โ document keybinding, clipboard behavior, and user flow. ๐ก Recommended: TESTING (full format for complex, standard for simple), SECURITY (clipboard access, git operations), EDGE CASES, TROUBLESHOOTING.
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ aicmit โ AI-Assisted Git Commit Message Generator โ
# โ Generates commit messages from project context, staged changes, and โ
# โ optional PROFILE.md documentation via AI prompt construction. โ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# โโ TRIGGER โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Direct invocation: aicmit
# Keybinding: (configured in core/16_widgets.zsh)
# ZLE registration: zle -N aicmit
#
# โโ VERSION โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# V18 (Unified Lifecycle & Modular Context)
#
# โโ WORKFLOW โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1. Git Repository Validation
# - Ensures repo exists with configured identity
#
# 2. Smart Staging
# - Detects unstaged changes, offers interactive staging
#
# 3. Context Gathering (Adaptive)
# - โค3 files: full diff >3 files: diff --stat
#
# 4. AI Prompt Construction
# - Assembles directive with context, diff, and metadata
#
# 5. Clipboard Export
# - Copies prompt to clipboard via wl-copy
#
# โโ ENVIRONMENT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# AICMIT_AUTO_PUSH bool false Auto-push after commit
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# git required Repository operations
# wl-copy required Clipboard export
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Prompt generated and copied
# 1 Not in a git repo or nothing staged
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# aicmit # Generate commit prompt
# AICMIT_AUTO_PUSH=1 aicmit # Generate and auto-push
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# core/16_widgets.zsh Widget keybinding registration
# _get_project_context Context gathering function
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ชจ hooks/*.zsh โ Hook Scriptsยถ
๐ชจ Tier: Standard
โญ Distinguishing: note how/when the hook is loaded, caching behavior if applicable. ๐ก Recommended: TESTING, EDGE CASES, PERFORMANCE (hooks run at startup โ โก every ms counts).
#!/usr/bin/env zsh
# โโ 01_mise โ Polyglot Runtime Manager with Cached Activation โโโโโโโโโโโโโโโโ
#
# Initializes mise for managing runtime versions. Uses intelligent caching
# to avoid subprocess overhead, regenerating only when mise binary updates.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Loaded automatically via core/18_hooks.zsh during shell initialization.
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# - Skips if mise not installed
# - Cache: $XDG_CACHE_HOME/zshand/mise-activate.zsh
# - Regenerates when cache missing or binary newer
# - Deferred activation after first prompt
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# mise required Polyglot runtime manager
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Hook registered or skipped
# 1 Cache directory creation failure
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Force cache regeneration
# rm ~/.cache/zshand/mise-activate.zsh
# source hooks/01_mise.zsh
#
# # Disable this hook entirely
# # (remove or rename the file, or uninstall mise)
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# mise not installed Skips entirely (no error, no warning)
# Stale cache Regenerated automatically on next shell start
# Cache dir missing Created with mkdir -p, warns on failure
# Binary updated Cache invalidated, regenerated on next source
#
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Load time <1ms (cached path), ~50ms (cache miss / regeneration)
# Strategy Deferred activation + binary-timestamp caching
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads: mise binary, cache file Writes: cache file Network: None
# Gitleaks: Clean
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/hooks/01_mise_spec.sh (๐ง not yet written)
# Status: ๐ง No spec
#
# Must cover:
# โฌ Skip when mise not installed
# โฌ Cache regeneration when binary newer
# โฌ Cache directory creation failure
# โฌ Deferred activation timing
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v1.1 2025-06-12 Added binary-timestamp caching, deferred activation
# v1.0 2024-11-20 Initial implementation with direct eval
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# core/18_hooks.zsh Hook loading infrastructure
# mise https://mise.jdx.dev/
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ startup/*.zsh โ Early Startup Scriptsยถ
๐ Tier: Standard
โญ Distinguishing: numbered prefix, note about when it runs in the startup sequence. ๐ Often guarded by environment variable checks. ๐ก Recommended: TESTING, EDGE CASES, PERFORMANCE (โก startup-critical โ measure with Hyperfine), ENVIRONMENT (most are guarded by env var checks).
#!/usr/bin/env zsh
# โโ 05_az_dev_mode_check โ Auto-Rebuild When Stale (Dev Mode) โโโโโโโโโโโโโโโโ
#
# Automatically rebuilds stale bundles when ZSHAND_DEV_MODE=1 and
# ZSHAND_DEV_AUTO_REBUILD=1. Runs early in startup, before core loading.
# Only executes once per shell session via re-entrancy guard.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Loaded automatically during startup sequence.
# Requires: ZSHAND_DEV_MODE=1, ZSHAND_DEV_AUTO_REBUILD=1
#
# โโ ENVIRONMENT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# ZSHAND_DEV_MODE bool 0 Enables dev mode (set via .envrc / direnv)
# ZSHAND_DEV_AUTO_REBUILD bool 0 Enables auto-rebuild on stale bundles
# ZSHAND string Framework root directory path
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1 Re-entrancy guard Only runs once per session
# 2 Environment check Requires both DEV_MODE and AUTO_REBUILD
# 3 Framework validation Ensures ZSHAND path is set
# 4 Dependency loading Sources rebuild check and dir list functions
# 5 Stale detection Scans framework directories for changes
# 6 Auto-rebuild Silently runs zprime --quiet if stale
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# _zshand_check_needs_rebuild_directory() Rebuild checking function
# _ZSHAND_FRAMEWORK_DIRS Framework directory list
# zprime Framework rebuild function
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Check completed (rebuild triggered or not needed)
# 0 Skipped (dev mode disabled, or already ran this session)
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Enable dev mode (typically in .envrc)
# export ZSHAND_DEV_MODE=1
# export ZSHAND_DEV_AUTO_REBUILD=1
#
# # Manually trigger check
# _az_dev_mode_check
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# DEV_MODE unset Skips silently (production behavior)
# ZSHAND unset Skips with no error (can't locate framework)
# Already ran Re-entrancy guard prevents duplicate work
# zprime missing Should not happen (loaded earlier in sequence)
#
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Load time <1ms (guard check only when dev mode disabled)
# <200ms (when rebuild is triggered via zprime)
#
# Benchmark: hyperfine --warmup 3 'ZSHAND_DEV_MODE=1 zsh -ic exit'
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads: framework source directories Writes: .zwc bundles (via zprime)
# Network: None Gitleaks: Clean
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/startup/05_az_dev_mode_check_spec.sh
# Run: just test spec/startup/05_az_dev_mode_check_spec.sh
# Status: ๐ง No spec
#
# Must cover:
# โฌ Skip when DEV_MODE=0 or unset
# โฌ Skip when AUTO_REBUILD=0 or unset
# โฌ Re-entrancy guard prevents duplicate runs
# โฌ Triggers zprime when framework directories are stale
# โฌ Graceful skip when ZSHAND is unset
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v1.0 2025-03-10 Initial implementation with re-entrancy guard
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# lib/rebuild/check_with_deps.zsh Rebuild checking logic
# core/06_engine.zsh zprime implementation
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ bin/* โ Executable CLI Toolsยถ
๐ Tier: Standard
โญ Distinguishing: OPTIONS section (flag-style arguments), shebang is critical. ๐ค These are user-facing commands run from $PATH. ๐ก Recommended: TESTING (standard format), EDGE CASES, TROUBLESHOOTING, SECURITY (๐ user-facing tools may handle paths, env vars, or network).
#!/usr/bin/env zsh
# โโ aicontext โ AI Context Generator for Code Assistants โโโโโโโโโโโโโโโโโโโโโ
#
# Generates comprehensive project context manifests for AI coding assistants.
# Creates markdown with file tree, environment keys, and optional file content.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# aicontext [depth] [path] [flags]
#
# โโ OPTIONS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# <depth> Tree depth level (1-9, default: 2)
# <path> Directory to analyze (default: cwd)
# -c [file] Include file content
# -e Include sanitized .env keys
# -h Show help
#
# โโ OUTPUT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Markdown manifest copied to clipboard containing:
# - Directory tree, git branch, project type
# - Environment variables (sanitized)
# - Token estimate
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# tree required Directory visualization
# wl-copy required Wayland clipboard
# git optional Branch detection
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Context generated and copied
# 1 Missing dependencies or invalid arguments
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Via Just
# just context
#
# # Direct invocation
# aicontext # Default 2-level tree
# aicontext 4 ~/project -e # Deep scan with env
# aicontext 1 . -c main.py # Include file content
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# tree not installed Exits 1 with install hint
# No .gitignore tree runs without ignore filter
# Binary files Skipped via MIME type detection
# Very deep trees Capped by depth argument
# No clipboard Outputs to stdout instead of clipboard
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/bin/aicontext_spec.sh
# Run: just test spec/bin/aicontext_spec.sh
# Status: โ ๏ธ Partial
#
# Must cover:
# โ
Default invocation (2-level tree, clipboard copy)
# โ
Custom depth and path arguments
# โ
-h flag shows help and exits 0
# โ
Missing tree dependency โ exit 1
# โฌ -c flag includes file content
# โฌ -e flag sanitizes .env keys (no values leaked)
# โฌ Output to stdout when clipboard unavailable
#
# TODO:
# - Add spec for token estimate accuracy
# - Add security spec: -e must never include secret values
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads Directory tree, .env files (keys only), git metadata
# Writes Clipboard (wl-copy)
# Network None
# Data Sanitizes .env values โ only key names are included
# Gitleaks Clean (secrets never copied to manifest)
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v2.0 2025-09-01 Token estimation, -c file content flag, -e env sanitization
# v1.0 2024-11-20 Basic tree + clipboard output
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# _get_project_context Project metadata gathering function
# tree https://mama.indstate.edu/users/ice/tree/
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฅ installers/.sh, installers/.zsh โ System Installersยถ
๐ฅ Tier: Standard
โญ Distinguishing: may use bash shebang, document PLATFORM, PRIVILEGES (๐ sudo). โ ๏ธ These are run once or rarely, so troubleshooting is especially important. ๐ก Recommended: TESTING (even if manual verification), TROUBLESHOOTING (๐ฅ critical for one-time scripts), SECURITY (๐ข required โ these run with sudo and touch system state).
#!/usr/bin/env bash
# โโ debian.sh โ Debian/Ubuntu System Dependency Installer โโโโโโโโโโโโโโโโโโโโ
#
# Installs system dependencies for zshand on Debian-based distributions.
# Handles packages, shell configuration, and framework setup.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# bash installers/debian.sh
#
# โโ PLATFORM โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Debian, Ubuntu, and derivatives (apt-based)
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1 Lock management Prevents concurrent execution
# 2 Package installation apt update + install core deps
# 3 Tool installation Downloads tools not in repos
# 4 Shell configuration Sets zsh as default shell
# 5 Framework setup Runs modular directory/link scripts
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# sudo required Privileged package installation
# apt required Debian package manager
# curl required Tool downloads
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Installation completed
# 1 Failed or another instance running
#
# โโ TROUBLESHOOTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# "Another instance is running" โ Remove lock: rm /tmp/zshand-install.lock
# "Permission denied" โ Run with: sudo bash installers/debian.sh
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Fresh install on a new Debian machine
# bash installers/debian.sh
#
# # Via Dev Container (automatic)
# # .devcontainer/postCreateCommand runs this for you
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# No internet apt update fails with clear error
# Already installed Packages skip gracefully (apt idempotent)
# Non-Debian distro Exits with unsupported platform message
# Concurrent runs Lock file prevents corruption
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
# Note: Uses bash, not zsh โ ShellCheck dialect set to bash
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads Package lists, /etc/os-release
# Writes System packages via apt, shell config via chsh
# Network Downloads packages from apt repos and GitHub releases
# Privileges Requires sudo for package installation
# Data System configuration only; no user data or credentials
# Gitleaks Clean (no secrets in installer scripts)
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/installers/debian_spec.sh (๐ง not yet written)
# Status: ๐ง No spec (manual verification in Dev Container)
#
# Must cover:
# โฌ Lock file prevents concurrent execution
# โฌ Core package installation completes
# โฌ Shell set to zsh after install
# โฌ Graceful failure on non-Debian systems
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v2.0 2025-04-15 Modular directory/link scripts, lock management
# v1.0 2024-11-20 Monolithic package installation
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# installers/manjaro.sh Manjaro/Arch variant
# setup.zsh Framework setup entry point
# .devcontainer/ One-click container setup
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ private_functions/*.zsh โ Internal Framework Functionsยถ
๐ Tier: Standard
โญ Distinguishing: same as functions/ but note the private/internal nature. Use _ prefix. ๐ซ These are not for direct user invocation โ always note this in the description. ๐ก Recommended: TESTING, EDGE CASES, SECURITY (๐ when handling network, daemons, or locks).
# โโ _zshand_network_monitor โ Background Network State Tracker โโโโโโโโโโโโโโโ
#
# Private background service that monitors connectivity and triggers Atuin
# sync on reconnection. Internal to the framework; not for direct user use.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# _zshand_network_monitor
# Called internally by _zshand_start_network_monitor() at shell init.
# Enabled via: ZSHAND_NETWORK_MONITOR=1
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# - Network check: Pings 8.8.8.8 with 0.5s timeout
# - State tracking: $ZSHAND_CACHE_DIR/network_state
# - Sync trigger: atuin sync on offline โ online transition
# - Service lifecycle: 30s startup delay, 5min check interval
# - Lock file coordination prevents duplicate monitors
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# atuin required History sync tool
# ping required Network connectivity test
# timeout required Command timeout wrapper
# stat optional Lock file age check
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Monitor running normally (infinite loop, never exits cleanly)
# 1 Another instance already running (lock file exists)
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Enable network monitoring
# export ZSHAND_NETWORK_MONITOR=1
# # (monitor starts automatically at next shell init)
#
# # Check if monitor is running
# cat "$ZSHAND_CACHE_DIR/network_state"
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# No network at all State stays "offline", no sync attempted
# Lock file stale Age check prevents permanent lock
# atuin not installed Should not happen (guard in caller)
#
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Background service โ minimal CPU (<0.1% at 5min interval)
# Memory: ~2MB resident (subshell with sleep loop)
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads Lock file, network state file
# Writes Network state file, lock file
# Network ICMP ping to 8.8.8.8 (connectivity check)
# Privileges None (user-level only)
# Gitleaks Clean
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/private_functions/_zshand_network_monitor_spec.sh
# Run: just test spec/private_functions/
# Status: ๐ง No spec
#
# Must cover:
# โฌ Lock file prevents duplicate monitors
# โฌ Offline โ online triggers atuin sync
# โฌ Stale lock file detection and cleanup
# โฌ Graceful behavior when atuin missing
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v1.0 2025-01-20 Initial implementation with lock file coordination
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# hooks/02_atuin.zsh Atuin initialization hook
# atuin https://atuin.sh/
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ lib/*/.zsh โ Library Support Modulesยถ
๐ Tier: Standard
โญ Distinguishing: Include ARGUMENTS section since these are called by other framework code. ๐งฉ These are internal building blocks โ focus on the API contract. ๐ก Recommended: TESTING, EDGE CASES, FILES (when reading manifests or config).
#!/usr/bin/env zsh
# โโ check_with_deps โ Rebuild Check Including Dependencies โโโโโโโโโโโโโโโโโโโ
#
# Dependency-aware rebuild checking. Returns success (exit 0) if the
# directory or any of its declared dependencies needs recompilation.
# Enables efficient incremental rebuilds.
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# _zshand_check_needs_rebuild_directory_with_deps "/path/to/dir" [base_dir]
#
# โโ ARGUMENTS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# $1 Directory path to check (string, required)
# $2 Base directory for resolving dependencies (string, optional, default: $ZSHAND)
#
# โโ BEHAVIOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 1 Validates directory path is provided
# 2 Checks if directory itself needs rebuild
# 3 Reads .zshand-deps manifest for declared dependencies
# 4 Checks each dependency for staleness
# 5 Returns 0 if any component needs rebuild, 1 otherwise
#
# โโ FILES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# $dir/.zshand-deps optional Dependency manifest (one dir name per line)
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# _zshand_check_needs_rebuild_directory Core rebuild check
# _zshand_read_manifest_deps Manifest reader
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Rebuild needed (directory or dependency is stale)
# 1 No rebuild needed (everything is current)
# 1 Missing directory path argument
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# # Check if widgets directory needs rebuild
# if _zshand_check_needs_rebuild_directory_with_deps "$ZSHAND/widgets"; then
# echo "Rebuild needed"
# fi
#
# โโ EDGE CASES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# No .zshand-deps Only checks the directory itself
# Circular deps Not detected (caller responsibility)
# Missing base_dir Falls back to $ZSHAND, skips if unset
#
# โโ PERFORMANCE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Execution time <5ms (file stat operations only)
# Complexity O(d) where d = number of declared dependencies
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ SECURITY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Reads: .zshand-deps manifests, directory stats Writes: None
# Network: None Gitleaks: Clean
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/lib/rebuild/check_with_deps_spec.sh
# Run: just test spec/lib/rebuild/check_with_deps_spec.sh
# Status: โ
Passing
#
# Must cover:
# โ
Directory needs rebuild (stale .zwc)
# โ
Directory is current (no rebuild)
# โ
Dependency triggers rebuild
# โ
Missing directory path argument
# โฌ No .zshand-deps manifest
# โฌ Missing base_dir fallback
#
# โโ HISTORY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# v1.0 2025-02-10 Initial implementation with manifest-based dependency resolution
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# lib/rebuild/dirs.zsh Framework directory listing
# core/06_engine.zsh zprime uses this for incremental rebuilds
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งช spec/*/_spec.sh โ ShellSpec Test Filesยถ
๐งช Tier: Standard (complex specs) or Minimal (simple specs)
โญ Distinguishing: ShellSpec BDD-style Describe/It blocks. ๐ Spec files mirror the source tree: functions/dcopy.zsh โ spec/functions/dcopy_spec.sh.
๐ง Complex spec with fixtures:
#!/usr/bin/env shellspec
# โโ profile_bundle_report_spec โ Report Generator Tests โโโโโโโโโโโโโโโโโโโ
#
# Tests for build/profile_bundle_report.zsh covering report generation,
# grading boundaries, gum/plain-text paths, and error handling.
#
# โโ RUN โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# just test spec/build/profile_bundle_report_spec.sh
# shellspec spec/build/profile_bundle_report_spec.sh
#
# โโ FIXTURES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# spec/fixtures/timing.log Mock timing data
# spec/fixtures/empty.log Empty log for error path
#
# โโ COVERAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Kcov target: 90%+ (measured in CI)
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Simple spec (no header needed beyond shebang โ the BDD blocks are self-documenting):
#!/usr/bin/env shellspec
# spec/shared_functions/stderr_error_spec.sh
Describe 'stderr_error'
It 'prints red error to stderr'
When call stderr_error "test message"
The stderr should include "ERROR:"
The stderr should include "test message"
End
End
๐งฐ spec/spec_helper.sh โ ShellSpec Bootstrapยถ
๐งฐ Tier: Minimal
โก Loaded before every spec. Keep the header minimal since ShellSpec documents its own helper format.
# spec/spec_helper.sh - ShellSpec bootstrap
# Loaded automatically before all specs.
# See: https://github.com/shellspec/shellspec#spec_helpersh
set -eu
shellspec_spec_helper_configure() {
: # Custom setup here
}
โ๏ธ config/*.conf โ Configuration Filesยถ
Tier: Minimal
No section dividers. Brief description block with FORMAT and field documentation.
# ZSHAND Profile Report - Acceptable Slow Operations
#
# Format: pattern|max_time_ms|reason
#
# pattern Glob matching filename (e.g., "*.zsh" or "exact.zsh")
# max_time_ms Maximum acceptable time in milliseconds
# reason Why this operation is acceptable
#
# Examples:
# 10-you-should-use.zsh|20|Command suggestions worth the cost
# 02_atuin.zsh|15|History search integration justified
#
# Lines starting with # are comments.
๐ฆ .zshand-deps โ Dependency Manifestsยถ
Tier: Minimal (no header needed)
These are plain-text lists. A one-line comment is sufficient if anything:
๐ Justfile โ Task Orchestrationยถ
Tier: Minimal
The Justfile is the command center. Recipes are self-documenting via Just's built-in [doc] attribute and just --list. Header is brief.
# ZSHAND Justfile โ Development task orchestration
# Run `just --list` for available recipes.
# See: https://just.systems/man/en/
set shell := ["zsh", "-cu"]
# Run the full test suite
test *ARGS:
shellspec {{ ARGS }}
# Benchmark shell startup time
bench:
hyperfine --warmup 3 'zsh -ic exit'
# Lint all shell files
lint:
trunk check
๐ .envrc โ Direnv Environmentยถ
Tier: Minimal
Loaded automatically by direnv on cd. Keep secrets out of this file (use .env which is gitignored, or a secrets manager).
# .envrc โ Auto-loaded by direnv on cd
# Manages development environment variables.
# Secrets: loaded from .env (gitignored) via dotenv
# See: https://direnv.net/
dotenv_if_exists .env
export ZSHAND_DEV_MODE=1
๐ .editorconfig โ Editor Consistencyยถ
Tier: Minimal
Enforced by EditorConfig plugins in all major editors. No comment header needed โ the format is self-documenting.
# .editorconfig โ Consistent formatting across all editors
# See: https://editorconfig.org/
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.zsh]
indent_size = 4
[Justfile]
indent_size = 4
๐ณ .devcontainer/ โ Dev Container Configurationยถ
Tier: Minimal
One-click onboarding for new contributors. The devcontainer.json spec is self-documenting; add a brief comment for context.
// .devcontainer/devcontainer.json
// One-click dev environment for ZSHAND contributors.
// Opens in VS Code / Cursor with all tooling pre-installed.
// See: https://containers.dev/
{
"name": "zshand-dev",
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
},
"postCreateCommand": "zsh setup.zsh",
}
๐ฏ Root Entry Points (zshrc.zsh, setup.zsh)ยถ
๐ฏ Tier: Full
๐ These are the most important files in the framework. Use the title box and comprehensive documentation. Include ๐ LOAD ORDER since they define the initialization sequence.
๐ Alignment Guidelinesยถ
๐ Column Alignmentยถ
Within any columnar section, align columns consistently:
โ
Good:
ZSHAND_CACHE_DIR string auto Cache directory
ZSHAND_BASE_DIR string auto Framework base
COLUMNS int auto Terminal width
โ Bad:
ZSHAND_CACHE_DIR string auto Cache directory
ZSHAND_BASE_DIR string auto Framework base
COLUMNS int auto Terminal width
๐ Rule: Pad the first column to the length of the longest entry + 2 spaces minimum. Align subsequent columns at consistent tab stops.
๐ Line Lengthยถ
- โ๏ธ Section dividers: exactly 78 characters after
#(80 total with#prefix) - ๐ Content lines: stay under 80 characters after
#when possible - ๐ URLs and long paths may exceed 80 characters โ donโt break them
โฎ๏ธ Indentationยถ
- โฎ๏ธ All content indented 2 spaces from
#:# content here - โฎ๏ธโฎ๏ธ Sub-items indented 4 spaces from
#:# sub-item here - ๐ป Code examples indented 2 spaces from
#:# command --flag
โ Checklist for New Filesยถ
Quick validation
Run trunk check <file> to verify ShellCheck compliance. Use grep -c '# โโ' <file> to count section dividers and confirm you haven't missed any.
- ๐๏ธ Determine tier based on file complexity and location
- ๐จ Choose title style โ
โโโbox for Full,โโ name โโfor others - ๐ข Include required sections for the tier (see table above)
- ๐ก Add recommended sections that add genuine value
- ๐ Verify alignment โ columns line up, dividers are 78 chars
- ๐ป Include at least one example โ prefer
justrecipes where available - ๐ End with closing rule โ
# โโโ...โโโ - โ Blank line between closing rule and first line of code
- โจ ShellCheck clean โ
trunk checkpasses (document overrides in LINTING) - ๐งช Spec file exists โ
spec/<dir>/<name>_spec.shmirrors source path - ๐ Justfile recipe โ add a
justrecipe if the file introduces a new command
๐ Migration Notesยถ
Don't batch-migrate
Migrate files as you touch them, not all at once. Large bulk reformatting creates noisy diffs and merge conflicts.
When updating existing files to this standard:
- ๐ฃ Don't force it. Migrate files as you touch them, not all at once.
- ๐ฆ Preserve content. The goal is better presentation, not content reduction.
- ๐๏ธ Match the tier. Don't over-document simple functions or under-document complex ones.
- ๐ Keep section order canonical. Follow the order in the Section Reference table.
- โ๏ธ Replace old separators (
===,โโโโโโโ,โโโ) with the newโโ SECTION โโstyle. - ๐งน Remove markdown-style headings (
##,###) from shell comment headers. - ๐ Convert bulleted lists to columnar tables where the data is structured.
When migrating to the new tooling stack:
- ๐งช Tests: Move from
tests/*.zshtospec/**/*_spec.sh(ShellSpec BDD format). - โจ Linting: Remove manual ShellCheck invocations; Trunk handles it on commit.
- ๐ป Examples: Replace raw
zsh tests/run_all.zshwithjust test. - โก Performance: Replace ad-hoc timing with
just bench/ Hyperfine. - ๐ CI/CD examples: Reference Justfile recipes instead of raw shell commands.
- ๐งช TESTING sections: Update to reference
spec/paths and Kcov coverage. - ๐ SECURITY sections: Add Gitleaks row if the file touches secrets/env vars.
๐ MkDocs Integrationยถ
This document is designed to render well in MkDocs Material. When building the docs site, keep these things in mind:
๐งฉ Features Usedยถ
| Feature | Where | Purpose |
|---|---|---|
| ๐ YAML frontmatter | Top of this file | Title, description, tags for search |
| ๐ฃ Admonitions | Throughout | !!! tip, !!! warning, !!! note callouts |
| ๐ป Fenced code blocks | Templates | zsh and bash syntax highlighting |
| ๐ Tables | Section Reference, Emoji Reference | Structured data |
| ๐จ Emoji shortcodes | Headings | Visual scanability in nav sidebar |
๐ง Recommended mkdocs.yml Extensionsยถ
markdown_extensions:
- admonition # !!! tip, !!! warning, etc.
- pymdownx.details # Collapsible admonitions (??? tip)
- pymdownx.superfences # Nested code blocks inside admonitions
- pymdownx.emoji: # :emoji: shortcodes
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.tabbed: # Tabbed content blocks
alternate_style: true
- toc:
permalink: true # Anchor links on every heading
๐งญ Navigation Placementยถ
Searchable headers
MkDocs Material's built-in search indexes all headings and content. The YAML tags in frontmatter enable tag-based search and filtering if the tags plugin is enabled.
โก Quick Referenceยถ
๐ One-page cheat sheet for the most common patterns. Print this or keep it open as a sidebar reference while writing headers.
โ๏ธ Divider Templateยถ
# โโ SECTION NAME โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ 78 chars after #. Copy-paste and replace SECTION NAME.
๐ฆ Minimum Viable Header (Compact)ยถ
# โโ name โ Short Description โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# โโ USAGE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# name [args]
#
# โโ DEPENDENCIES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# dep_name required What it does
#
# โโ EXIT CODES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# 0 Success
# 1 Failure
#
# โโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# name arg1 arg2
#
# โโ TESTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Spec: spec/dir/name_spec.sh Run: just test spec/dir/
# Status: ๐ง No spec Must cover: happy path, missing deps
#
# โโ LINTING โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# Clean: ShellCheck + shfmt (Trunk-managed, no overrides)
#
# โโ SEE ALSO โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#
# related_file.zsh What it does
#
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Column Alignment Cheat Sheetยถ
๐ Variable table: NAMEโโโโโโtypeโโโโdefaultโโDescription
๐ฆ Dependency table: nameโโโโโโrequiredโDescription
๐ช Exit code table: 0โโDescription
โ ๏ธ Edge case table: Conditionโโโโโโโโโ Behavior
๐ Files table: pathโโโโโโโโrequiredโDescription
๐ Security table: FieldโโโโโโโValue
โ = pad to longest entry + 2 spaces.
๐งช TESTING Status Iconsยถ
| Icon | Meaning | When to use |
|---|---|---|
| โ | Covered | Spec exists and passes |
| โฌ | Not yet | Scenario identified but no spec |
| โ ๏ธ | Partial | Spec exists but incomplete |
| โ | Failing | Spec exists and fails |
| ๐ง | No spec | Spec file doesn't exist at all |
๐ HISTORY Date Formatยถ
# v2.0 2026-02-03 Description of what changed
# Continuation line (indented to description column)
# v1.0 2024-11-20 Initial implementation
๐ Always YYYY-MM-DD. Newest first. Tag breaking changes with โ ๏ธ.