dart_minify 0.1.1 copy "dart_minify: ^0.1.1" to clipboard
dart_minify: ^0.1.1 copied to clipboard

CLI for compressing Dart and Flutter source before sending it to AI agents.

dart_minify #

dart_minify is a Dart/Flutter CLI that compresses source code before sending it to AI agents, then expands responses back into readable code.

It is designed for agent workflows where prompt size, cost, and latency matter.

What it does #

  • minify/expand: payload-based compression and round-trip recovery.
  • stats: quick byte/token savings estimate.
  • doctor: project sanity checks before running transforms.
  • lossy-build/apply-lossy: build-runner workflow for project-side lossy output.

Why this exists #

Agent context windows are limited and expensive. dart_minify helps by:

  • removing comments and whitespace noise
  • applying conservative renaming in aggressive lossy mode
  • producing map/manifests so outputs can be expanded or safely applied

Real project example (Prism lib/, aggressive lossy build):

  • Original: 3,407,823 bytes
  • Minified: 2,203,323 bytes
  • Saved: 1,204,500 bytes (35.35%)

Install #

Global activate:

dart pub global activate dart_minify

Then run:

dart-minify --help

Local repository usage:

dart pub get
dart run bin/dart_minify.dart --help

Quickstart #

1) Minify for agent context #

dart run bin/dart_minify.dart minify \
  --project-root ../Prism \
  --mode mostly-lossless \
  --map-out /tmp/prism.map.json \
  ../Prism/lib > /tmp/prism.payload.txt

2) Expand agent output back to readable code #

dart run bin/dart_minify.dart expand \
  --map-in /tmp/prism.map.json \
  --input /tmp/agent-response.txt > /tmp/prism.expanded.txt

3) Check savings first #

dart run bin/dart_minify.dart stats \
  --project-root ../Prism \
  --mode mostly-lossless \
  ../Prism/lib

Modes #

  • mostly-lossless
    • strips comments and compresses whitespace
    • preserves identifiers
    • safest default for context packing
  • aggressive-lossy
    • adds analyzer-backed renaming plus whitespace/comment compression
    • current stable scope: local variables and local functions
    • stronger compression, lower readability

Lossy build workflow #

dart run bin/dart_minify.dart lossy-build --project-root ../Prism
dart run bin/dart_minify.dart apply-lossy --project-root ../Prism

Manifest output:

  • ../Prism/.dart_minify/lossy-manifest.json

apply-lossy validates source checksums from the manifest before replacement. Use --force only when you intentionally want to bypass that protection.

Flutter + FVM #

This repository pins Flutter 3.41.4 in .fvmrc for local consistency.

Typical local commands:

fvm flutter --version
fvm dart --version
fvm dart test

If your target project is Flutter, lossy-build automatically runs flutter pub run build_runner (or fvm flutter pub run build_runner when .fvmrc is present in that project).

Examples #

  • CLI and wrapper examples: example/

Docs #

  • Agent Integration Guide
  • Benchmarks

Limitations #

  • Aggressive renaming is intentionally conservative in v1.
  • This is a context-optimization tool, not a production obfuscator.
  • After large transforms, run dart analyze or flutter analyze.
1
likes
120
points
101
downloads

Documentation

Documentation
API reference

Publisher

verified publisherhashstudios.dev

Weekly Downloads

CLI for compressing Dart and Flutter source before sending it to AI agents.

Repository (GitHub)
View/report issues

Topics

#ai #cli #flutter #minification #tooling

License

MIT (license)

Dependencies

analyzer, args, build, crypto, dart_style, path

More

Packages that depend on dart_minify