Skip to content

fix(skill-token-count): stamp token counts into each SKILL.md instead of a shared table - #1394

Merged
potiuk merged 1 commit into
apache:mainfrom
potiuk:feat/skill-tokens-in-frontmatter
Sep 26, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
potiuk:feat/skill-tokens-in-frontmatter

Conversation

@potiuk

@potiuk potiuk commented Sep 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Every skill PR conflicted on docs/mode-economics.md. The generated table there had two lines, the measurement date and the manifest SHA-256, that changed on every regeneration. The skill-token-count hook forces a regeneration on any SKILL.md edit, so any two skill PRs rewrote the same lines. Alphabetically adjacent rows collided as well. 58 of 213 commits on main this month touched the file.
  • Each skill now carries its own count in a generated measured_tokens: frontmatter line, stamped the same way as surface_hash:. It's measured over the full file with its own line excluded, so writing the stamp never changes the count it records. Two PRs now conflict on a stamp only if they edit the same skill, which they would anyway.
  • The table is no longer committed. skill-token-count --table prints it; docs/mode-economics.md explains where the numbers live and carries a marker the website build replaces with the rendered table (follow-up PR on apache/magpie-site).
  • The stamp sits immediately after license:; surface_hash: sits immediately before it. Anchoring on opposite sides keeps the two stampers from reordering each other's line, so each is idempotent whichever runs last.

Type of change

  • Python package (tools/*/ with pyproject.toml) — skill-token-count (stamp / check / table), skill-and-tool-validator (format check for the new key)
  • Skill change — all 75 SKILL.md gain a generated measured_tokens: line (no prose change)
  • Documentation — docs/mode-economics.md, tools/skill-token-count/README.md, AGENTS.md (Keeping evals and mode-economics in sync)
  • CI / dev loop — hook name and files:, the skill-token-count workflow path filter, the dependabot / pyproject comments on the tiktoken pin

Test plan

  • prek run --all-files passes
  • uv run --directory tools/skill-token-count pytest — rewritten suite covers:
    • --check never writes; --write is idempotent
    • the stamp excludes itself
    • the stamp sits after license:, and a restamp replaces rather than duplicates
    • drift from an edit, tampering, or a removed stamp is caught
    • editing one skill never writes another
    • --table writes nothing
    • redirects, symlinks, and a missing license: are handled
    • the vocabulary cache still fails closed
    • every repository skill is stamped
  • uv run --directory tools/skill-and-tool-validator pytest — new tests reject a malformed measured_tokens (0, -5, 1,234, many) and accept a valid one
  • All 75 stamped counts are identical to the last committed table
  • skill-surface-hash.py stays in sync after stamping, and a second --write changes nothing, so the two stampers don't fight
  • Merge simulation: two branches each editing an alphabetically adjacent skill (audit-finding-fix / ci-runner-audit) and restamping merge cleanly, and --check passes on the merge result. Before this change that pair always conflicted.

Notes for reviewers (optional)

  • The per-skill source SHA-256 and the aggregate manifest hash are gone. The stamp is checked by re-measuring, which is the same guarantee the manifest gave (any content change is caught) without a shared line. Tokenizer identity lives in the exact tiktoken pin; a bump that changes tokenization fails --check on every skill until restamped, as before.
  • Open PRs that touch a SKILL.md will need skill-token-count --write once after rebasing onto this. That's the last time the table conflicts.

🤖 Generated with Claude Code

… of a shared table

The generated table in docs/mode-economics.md carried a measurement
date and a manifest hash that changed on every regeneration, and the
hook regenerates on any SKILL.md edit, so any two skill PRs conflicted
(adjacent rows did too). Stamp each count into the skill's own
frontmatter as measured_tokens (measured excluding that line, placed
after license: so it never reorders surface_hash), print the table
on demand with --table, and stop committing it. The website build
renders the table from the stamps.

Generated-by: Claude Opus 5
@potiuk potiuk added family:tools tools/* capability:fix Implement code change to resolve an issue labels Sep 26, 2026
@potiuk

potiuk commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

This should completely remove the constant need of resolving conflicts in mode_economics.md

@github-actions github-actions Bot added substrate:analytics Tool substrate: read-only metrics / dashboards / renderers substrate:framework-dev Tool substrate: build / validate / eval the framework itself labels Sep 26, 2026
@potiuk
potiuk merged commit eca2009 into apache:main Sep 26, 2026
13 checks passed
potiuk added a commit to apache/magpie-site that referenced this pull request Sep 26, 2026
…amps (#203)

apache/magpie#1394 moved each skill's token count into its own
measured_tokens frontmatter stamp and replaced the committed table in
docs/mode-economics.md with a marker. Render the table from the stamps
during sync-docs, before the link rewrite, so the page keeps its table
and the rows link to GitHub as before.

Generated-by: Claude Opus 5
potiuk added a commit to potiuk/magpie that referenced this pull request Sep 26, 2026
Pick up today's merges (apache#1390, apache#1391-apache#1394, apache#1398, apache#1399) in a fresh
marketplace build. pyproject.toml, uv.lock and every generated
plugin/marketplace manifest move from 0.9.0.dev202609251939.

Generated-by: Claude Opus 5
potiuk added a commit that referenced this pull request Sep 26, 2026
Pick up today's merges (#1390, #1391-#1394, #1398, #1399) in a fresh
marketplace build. pyproject.toml, uv.lock and every generated
plugin/marketplace manifest move from 0.9.0.dev202609251939.

Generated-by: Claude Opus 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:fix Implement code change to resolve an issue family:tools tools/* substrate:analytics Tool substrate: read-only metrics / dashboards / renderers substrate:framework-dev Tool substrate: build / validate / eval the framework itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant