feat: agent-first skill scripts — structured returns + minified build#63
Merged
feat: agent-first skill scripts — structured returns + minified build#63
Conversation
All IIFE scripts now return a JSON object from evaluate_script(),
enabling agents to read structured data directly from the return value
instead of parsing console output.
- Every script returns { script, status, ...} matching SCHEMA.md
- Audit scripts include count, items[], issues[]
- Tracking scripts return { status: "tracking", getDataFn } with a
window function agents can call later for results
- Early returns (no data / unsupported API) also return structured objects
- No console output changed — the return value is additive
Inspired by https://justin.poehnelt.com/posts/rewrite-your-cli-for-ai-agents/ — skill scripts are now generated agent-first: no human-readable console output, no comments, minimal token footprint. - generate-skills.js now calls terser instead of copyFileSync - drop_console: true removes all console.* calls - mangle + no comments produces a single minified line per script - fallback to raw copy if minification fails (never breaks the build) - Each generated script gets a one-line header: // snippets/<Category>/<file>.js | sha256:<16-char> | <github-url> SHA-256 is computed from the original source, allowing verification that the minified script corresponds to a specific snippet version - terser added as devDependency
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
After `drop_console: true` removes console.* calls, Terser left behind
constants that were only used for console output (e.g. the RATING object
with emoji icons/colors like { good: { icon: "🟢", color: "#0CCE6A" }, ... }).
This happened because Terser's single-pass compression couldn't determine
that destructured values from those constants were unused after console
removal.
Fix: add two Terser compress options:
- `pure_getters: true` — tells Terser that property accesses (obj.prop,
obj[key]) have no side effects, so unused destructured results can be
safely dropped
- `passes: 2` — runs a second compression pass to eliminate secondary dead
code (unused variables whose only consumers were already removed in the
first pass)
Result: emoji/color constants and their associated destructuring assignments
are fully eliminated from the generated skill scripts, reducing token
footprint further.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Inspired by Rewrite your CLI for AI agents — agents consuming these scripts don't need color-coded console output, emojis, or pretty-printed tables. What they need is structured data they can act on, and the smallest possible token footprint.
This PR makes skill scripts agent-first end to end.
Changes
1. Structured return values on all snippets (
snippets/**/*.js)Every IIFE now returns a JSON object when executed via
evaluate_script(). Agents read the return value directly instead of parsing console output.Schema documented in
.claude/skills/SCHEMA.md:{ value, unit, rating, thresholds, details }{ count, items[], issues[] }{ status: "tracking", getDataFn }+ awindow.getFn()that returns structured data after user interaction{ status: "error"|"unsupported", error }Console output is unchanged — the return value is purely additive.
2. Agent-first build pipeline (
scripts/generate-skills.js)The generator minifies skill scripts at build time using terser instead of copying them verbatim:
drop_console: true— strips allconsole.*callspure_getters: true— marks property accesses as side-effect-free, enabling removal of dead code left behind after console strippingpasses: 2— second compression pass eliminates secondary dead code (unused variables whose only consumers were removed in the first pass)mangle: true+comments: false— single minified line per scriptDead code elimination
Without
pure_getters+passes: 2, constants used exclusively for console output (e.g. theRATINGobject with emoji icons and colors) survived minification:Each generated skill script gets a one-line traceability header:
The SHA-256 is computed from the original source file, so you can verify at any time that the minified skill script matches its snippet:
Token impact
A verbose snippet with console output (~80 lines) becomes a single minified line (~300 chars). Across ~50 scripts loaded by an agent in a session, this is a significant reduction. Emoji/color constants eliminated by dead code removal reduce this further.
Usage
npm install # adds terser devDependency npm run generate-skills