Add token usage reporter and optimization skill
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 68/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- documentation, testing-qa, tooling
Research direction
Start with the reporter contract in src/reporters/contract.ts and the existing reporter guidance in docs/reporters.md. Review skills/core.md and DICTIONARY.md for the skill and terminology updates, then inspect existing reporter tests and built-in loading behavior. Done means strict JSON output, correct aggregation and exclusion cases, the documented token-optimization skill, and passing tests.
Written by the indexing model from the issue text.
Description
Skillgym can evaluate whether agents preserve behavior, but it does not yet provide a token-efficient workflow for optimizing skill or project metadata. Maintainers and agents need a way to reduce billable token usage from files such as skills or repository instructions while proving that output quality remains protected by Skillgym cases.
This feature should make Skillgym suitable for an optimization loop where an agent writes or selects evals, captures baseline billable token usage, edits an explicitly provided metadata target, reruns the evals, and repeats until the requested budget, reduction, or iteration limit is reached.
Product Requirements
- Add a built-in
token-usagereporter. - Add a
token-optimizationSkillgym skill that instructs agents how to run this workflow safely. - Keep the reporter stdout compact, strict JSON, and optimized for agent consumption.
- Reuse normal Skillgym artifacts for failure debugging instead of creating a second detailed token report format.
- Document the reporter and skill so another agent can discover and use them without reading implementation code.
Observed Findings
- Built-in reporters currently include
standard,json,json-summary,github-actions, andhtml. - Reporter selection is documented in
docs/reporters.mdand exposed throughskillgym run <suite.ts> --reporter <name>. - Reporter hooks receive final
SuiteRunResultdata inonSuiteFinishviasrc/reporters/contract.ts. - Session usage is normalized in
UsageReportwith optionalinputTokens,outputTokens,reasoningTokens,cacheTokens,totalTokens, and usage source metadata. - The default reporter already exposes comparable billable token semantics through normalized total-token reporting, displayed as
billable. json-summaryis useful for LLM consumption, but it still includes more result and artifact detail than this optimization loop needs.skills/core.mdalready points agents to reporter and snapshot workflows, but no skill describes a metadata token optimization loop.DICTIONARY.mddoes not yet includetoken-usageortoken-optimization.
Suggested Behavior
token-usage Reporter
The new built-in reporter should be selectable with:
skillgym run <suite.ts> --reporter token-usage
It should write only strict JSON to stdout. No progress lines, Markdown, prose, or extra diagnostics should be mixed into stdout.
The output should include:
- top-level
passedfor the suite run result - top-level
billableaggregate using only passed rows with provider-sourced billable usage - top-level
artifactspointing to the suite-run artifact directory rows, one row per case x runner result
Suggested compact shape:
{
"passed": true,
"billable": { "sum": 4200, "avg": 2100 },
"artifacts": "artifacts/...",
"rows": [
{
"case": "keeps-critical-rule",
"runner": "opencode:gpt-5.5",
"passed": true,
"billable": { "sum": 4200, "avg": 2100 }
}
]
}
Case x runner rows are required because token usage can differ by runner and model.
Billable semantics:
- Only use billable token data equivalent to the default reporter's
billable/normalized total-token semantics. - Only aggregate provider-sourced token usage.
- Failed rows must not contribute to token aggregates because failed runs do not represent normal workflow cost.
- Rows without provider-sourced billable usage must not contribute to token aggregates.
- A failed row should still appear, with
passed: false,billable: null, and enough failure signal to identify what broke. - A row with unavailable or derived-only token usage should still appear, with
billable: nulland a usage marker such asusage: "derived"orusage: "unavailable". - Top-level aggregate
billable.sumshould sum billable usage across included rows. - Top-level aggregate
billable.avgshould average included row averages. - Each successful comparable row should expose
billable.sumandbillable.avgrather than a single number, so repeats can be interpreted correctly.
Failure diagnostics:
- The reporter should be stdout-only.
- It should not write a separate
token-usage-report.jsonunless existing artifacts later prove insufficient. - It should include the top-level artifact directory once only, not repeated per row.
- Agents should use the normal Skillgym artifacts or rerun with the default reporter when a row fails.
token-optimization Skill
Add a Skillgym skill named token-optimization, discoverable through the existing skills mechanism.
The skill should instruct an agent to:
- Require an explicit optimization target from the invoker.
- Ask one short clarification question if the optimization target is missing.
- Identify an existing protection suite or create/strengthen the smallest suite that protects the target behavior.
- Run a baseline with
--reporter token-usagebefore making minimization edits. - Treat a passing baseline as a hard prerequisite for optimization edits.
- Use compact reporter stdout for before/after token comparison.
- If any row fails, inspect normal Skillgym artifacts/default reporter output and do not count lower token usage from that failed row as an improvement.
- Make the smallest safe metadata changes to the explicit optimization target.
- Rerun with
--reporter token-usageafter each change. - Stop according to the invoker-provided token budget, percentage reduction target, or max iteration count.
- If no stopping rule is provided, default to one safe minimization pass plus one verification run.
- Describe snapshots as optional post-optimization regression protection after behavior is stable.
The skill should not prescribe which files to optimize by default. It may give examples, but the actual target must come from the invoker.
Documentation And Dictionary
Update documentation so users can discover:
- the
token-usagereporter name - the stdout JSON contract
- provider-sourced billable-token-only aggregation
- failed-row and derived-usage exclusion behavior
- artifact debugging expectations
- the
token-optimizationskill workflow
Update DICTIONARY.md with approved terms:
token-usagetoken-optimization
Acceptance Criteria
skillgym run <suite.ts> --reporter token-usageloads as a built-in reporter.- Reporter stdout is strict JSON.
- Reporter stdout has one row per case x runner result.
- Passed rows with provider-sourced billable usage include
{ "sum": number, "avg": number }. - Failed rows have
billable: nulland are excluded from all aggregates. - Derived or unavailable usage rows have
billable: nulland are excluded from all aggregates. - Top-level
artifactspoints to the suite-run artifact directory and is not repeated per row. - The reporter does not create a separate detailed token report file.
- Tests cover built-in reporter loading/listing and the aggregation/exclusion semantics above.
token-optimizationskill exists and documents the target requirement, baseline passing rule, optimization loop, stopping rule, failure handling, and optional snapshot usage.- Reporter docs and dictionary are updated.
Resolution Summary
Skillgym should provide a compact token-usage reporter and a token-optimization skill so agents can safely minimize explicitly targeted metadata while preserving behavior through passing evals and comparing only provider-sourced billable token usage from successful runs.
- Dominant language
- TypeScript
- Stars
- 69
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from callstackincubator/skillgym
-
Plan approval needed
Difficulty 4/5 3-5 days Newbie friendliness 45/100
callstackincubator/skillgym#4 · 1 comment ·
All issues in callstackincubator/skillgym
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
earendil-works/gondolin#222 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
endora-commerce/endora-commerce#2203 ·
Maintainers usually reply within 1 day
-
enhancement priority:medium ready-for-human
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
wondermoney/wondermoney#1079 ·
Maintainers usually reply within 1 day