Skip to content

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

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

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.

@arzafran
Copy link
Copy Markdown
Member

Closing as obsolete.

All 8 files this PR touches were removed in the bash → TypeScript-on-Bun migration (Phase 7, April 2026 — see docs/migration-coexistence.md and current CLAUDE.md):

Old bash Current TS equivalent
lib/platform.sh src/lib/platform.ts
lib/hook-config.sh src/schemas/hooks.ts + hook wiring in src/setup.ts
scripts/handoff.sh src/scripts/handoff.ts
scripts/session-start.sh src/hooks/session-start.ts
scripts/checkpoint.sh src/scripts/checkpoint.ts
scripts/tldr-stats.sh src/scripts/tldr-stats.ts
scripts/track-tldr.sh src/scripts/track-tldr.ts
scripts/compile-skills.sh src/scripts/compile-skills.ts

The duplication this PR addresses (cross-platform stat fallbacks, double jq calls for type + value extraction) doesn't apply to the TS ports — they use node:fs.stat and typed JSON parsing directly via zod.

Thanks for the refactor pass — if you want to take a look at consolidation opportunities in the current TS codebase, that would be welcome.

@arzafran arzafran closed this Apr 21, 2026
@arzafran arzafran deleted the artifex/lets-assess-the-codebase-and-plan-for-op-mnovys0b branch April 21, 2026 15:11
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.

1 participant