Skip to content

Optimize memory usage, improve YAML parsing, and add CLI enhancements#3

Merged
Binb1 merged 2 commits intofeat/ags-v0from
claude/review-pr-improvements-ICPYr
Apr 4, 2026
Merged

Optimize memory usage, improve YAML parsing, and add CLI enhancements#3
Binb1 merged 2 commits intofeat/ags-v0from
claude/review-pr-improvements-ICPYr

Conversation

@Binb1
Copy link
Copy Markdown
Contributor

@Binb1 Binb1 commented Apr 4, 2026

Summary

This PR improves performance and reliability across multiple areas: streaming large JSONL files to reduce memory footprint, enhancing the YAML parser to support multi-line strings, refining CLI argument parsing with short flags, and adding comprehensive test coverage.

Key Changes

Memory & Performance

  • Replace readFileSync with streaming in stats.ts to handle large session files without loading entire contents into memory
  • Implement line-by-line processing with proper chunk boundary handling
  • Add caching to findProjectRoot() to avoid repeated filesystem traversal
  • Improve token estimation algorithm from simple length-based to word+symbol heuristic for better accuracy

YAML Parser Enhancement

  • Add support for multi-line literal (|) and folded (>) blocks in skill frontmatter
  • Implement proper indentation tracking and block termination detection
  • Refactor parser with helper functions (flushMultiLine, flushList) for cleaner state management
  • Add comprehensive documentation of parser capabilities and limitations

CLI Improvements

  • Add short flag aliases: -j (json), -a (agent), -t (type), -s (scope), -p (period), -v (version), -h (help)
  • Support combined short flags (e.g., -js) with proper boolean/value handling
  • Support --key=value syntax for long flags
  • Distinguish between boolean-only flags and value-accepting flags

Dry-Run Support

  • Add --dry-run flag to grab and rm commands for preview mode
  • Update output formatting to indicate dry-run status with visual indicators
  • Include dryRun flag in JSON output responses

GitHub Fetch Robustness

  • Replace simple response.text() with streaming reader to enforce size limits regardless of content-length header
  • Properly handle missing or incorrect content-length headers
  • Implement byte-by-byte size checking with early cancellation

Path Cleaning Logic

  • Refactor cleanDirName() with two-phase approach: strip HOME prefix segments in order, then skip container directories
  • Improve accuracy of project name extraction from encoded directory paths

Testing

  • Add comprehensive test suites for parser, health badges, tokens, and GitHub utilities
  • Add CI workflow for automated testing on push and pull requests

https://claude.ai/code/session_01879LywhiKaXPsPbcsGgpZi

claude added 2 commits April 4, 2026 06:57
- Security: cap fetch body size regardless of content-length header
- Performance: stream JSONL parsing in stats instead of readFileSync
- Accuracy: word+symbol token estimation replacing naive length/4
- Safety: add --dry-run flag for grab and rm commands
- UX: support short flags (-j, -a), --key=value syntax in arg parser
- Parser: proper multi-line string support (| and >) in YAML frontmatter
- Fix: cleanDirName strips only actual HOME prefix, not project names
- Fix: JSON output in grab/rm uses explicit return after printJson
- Perf: memoize findProjectRoot to avoid repeated fs walks
- Tests: add 61 unit tests for parser, tokens, health, github, args

https://claude.ai/code/session_01879LywhiKaXPsPbcsGgpZi
- Cut from 61 to 15 focused regression tests
- Remove args.test.ts (was testing duplicated code)
- Add CI workflow: typecheck + test on push/PR to main

https://claude.ai/code/session_01879LywhiKaXPsPbcsGgpZi
@Binb1 Binb1 merged commit dc97a6e into feat/ags-v0 Apr 4, 2026
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.

2 participants