Skip to content

refactor: deduplicate cross-platform stat and JSON parsing patterns#9

Open
artifex-bot[bot] wants to merge 1 commit intomainfrom
artifex/lets-assess-the-codebase-and-plan-for-op-mnovys0b
Open

refactor: deduplicate cross-platform stat and JSON parsing patterns#9
artifex-bot[bot] wants to merge 1 commit intomainfrom
artifex/lets-assess-the-codebase-and-plan-for-op-mnovys0b

Conversation

@artifex-bot
Copy link
Copy Markdown

@artifex-bot artifex-bot bot commented Apr 7, 2026

What

  • Added get_file_mtime(), get_file_size(), and get_file_mtime_human() helpers to lib/platform.sh to centralize cross-platform stat commands
  • Updated handoff.sh, session-start.sh, and checkpoint.sh to use the shared helpers instead of inline stat fallback chains
  • Reduced redundant jq invocations in lib/hook-config.sh by combining the type-check and value-extraction into a single jq call per config file
  • Deduplicated JSON parsing fallback pattern in tldr-stats.sh and track-tldr.sh with a shared json_num() helper
  • Simplified logging setup in compile-skills.sh to a single conditional pattern

Why

The codebase had the same cross-platform stat fallback pattern (stat -f%m ... || stat -c%Y ... || echo 0) duplicated across 5+ scripts. Similarly, get_hook_config() was making 2 jq calls per config file (type check + value extraction) when 1 suffices. These are low-effort, high-impact maintainability wins that reduce code duplication and improve consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants