Skip to content

๐Ÿ“ 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:

  • ๐ŸŽฏ name matches 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:

#   0  Always (display function, no failure mode)

๐Ÿ” 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:

#   ๐Ÿ”’ Reads: None  Writes: stderr  Network: None  Gitleaks: โœ… Clean

๐Ÿ” 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 just command 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:

#   โšก Load time: <1ms  |  Complexity: O(1)  |  No benchmark needed

๐Ÿ’ก 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-deps manifests
  • ๐Ÿ“‹ 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:

# Dependencies for this directory (one per line)
core
private_functions

๐Ÿ“‹ 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.

  1. ๐Ÿ—๏ธ Determine tier based on file complexity and location
  2. ๐ŸŽจ Choose title style โ€” โ•”โ•โ•— box for Full, โ”€โ”€ name โ”€โ”€ for others
  3. ๐ŸŸข Include required sections for the tier (see table above)
  4. ๐ŸŸก Add recommended sections that add genuine value
  5. ๐Ÿ“ Verify alignment โ€” columns line up, dividers are 78 chars
  6. ๐Ÿ’ป Include at least one example โ€” prefer just recipes where available
  7. ๐Ÿ End with closing rule โ€” # โ”€โ”€โ”€...โ”€โ”€โ”€
  8. โŽ Blank line between closing rule and first line of code
  9. โœจ ShellCheck clean โ€” trunk check passes (document overrides in LINTING)
  10. ๐Ÿงช Spec file exists โ€” spec/<dir>/<name>_spec.sh mirrors source path
  11. ๐Ÿ“‹ Justfile recipe โ€” add a just recipe 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/*.zsh to spec/**/*_spec.sh (ShellSpec BDD format).
  • โœจ Linting: Remove manual ShellCheck invocations; Trunk handles it on commit.
  • ๐Ÿ’ป Examples: Replace raw zsh tests/run_all.zsh with just 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
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
nav:
  - Home: index.md
  - Standards:
      - Header Standard: HEADER_STANDARD.md
  - ...

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 โš ๏ธ.