Repository navigation
Scripted commands and a skill so AI agents can label datasets - #1
Merged
Merged
Conversation
Profiling the headless commands on a 10,000-image / 26,000-box dataset showed the time going to shared format code, most of it Foundation bridging: - CreateMLFormat.load reads JSONSerialization's NSArray/NSDictionary directly instead of casting each entry to [String: Any], which copied the dictionary and bridged every key - filenames and labels are converted to native Swift strings once, on the way in, so later Set/Dictionary work no longer hashes through NSString - CreateMLWriter caches its indentation strings, formats coordinates as integer hundredths instead of String(format:), and skips escaping for strings that need none - JSONIndent sniffs the first 64 KB rather than splitting the whole file - ImageDirectoryScanner lists with contentsOfDirectory and sorts by selector, keeping comparisons inside Foundation; names that compare equal are settled by plain comparison so the order is deterministic Saved bytes are unchanged: a test compares the new coordinate formatting with the previous implementation over 420,000 values, and the existing golden and round-trip tests still pass. Adds concurrentMap and uniqued helpers used by the commands that follow.
Until now nothing could write boxes into annotations.json from the terminal, so an agent had to hand-edit the file and lose the format guarantees. This adds the headless verbs for a full label-check-fix loop: - annotate: add or replace boxes from --box flags, JSON, NDJSON or stdin. Reads what models and tools emit (Gemini box_2d, corner lists, 0-1 and 0-1000 units, centre anchors, COCO files, detect output); --units, --origin, --anchor, --order and --image-size name a convention instead of converting. Adding is idempotent down to the bytes; unusable input writes nothing. - stats: JSON summary (labelled, negative, unlabelled, missing, per-label counts, the image with the most boxes) - validate: errors and warnings with stable codes, exit 1 on errors; also finds the same photo saved under two names - render: draw saved boxes on downscaled JPEGs, numbered to match validate; --grid adds a ruler in original-image pixels, --unlabeled renders the to-do - skill: print or install the Agent Skill that teaches a client the loop (~/.agents/skills and ~/.claude/skills, or --project / --dir / --snippet). The text is compiled in and mirrored at skills/labelkit/SKILL.md; a test keeps the two identical. - open --select <image>: show a given image; with the editor already open it reloads the dataset from disk and jumps there The logic is in Sources/LabelKit/Headless with tests; the command files only parse and print. detect and train now share the same output helpers. All commands write the result to stdout, notes to stderr, and exit 0 / 1 / 64. scripts/smoke-scripted.sh exercises them end to end and runs in CI.
…ions - docs/agents.md: one-minute setup, per-client skill locations (Claude Code, Codex, opencode, Cursor, Gemini CLI, Antigravity, Copilot, Amp, Goose, Aider), the label-check-fix loop, how to review, input formats per model and tool, the JSON and exit-code contract, measured timings - README: a section on using labelkit from an agent and the scripted commands - CHANGELOG: the new commands and the faster load/save under Unreleased - AGENTS.md is now the canonical instructions file, read natively by most agent clients; CLAUDE.md imports it so Claude Code reads the same text. It gains a section on the scripted surface as a public interface. - .claude-plugin/marketplace.json lets Claude Code install the skill as a plugin (passes 'claude plugin validate')
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.
What this does
An AI agent (or a shell script) can now label a dataset with labelkit end to end, without the editor and without hand-editing
annotations.json. Setup for the person using it is one command:labelkit skill --install.It also makes large datasets load, list and save several times faster, because profiling the new commands showed their time going to shared format code.
New commands
labelkit annotate <dataset> …--boxflags, JSON, NDJSON or stdinlabelkit stats <dataset>labelkit validate <dataset>labelkit render <dataset> --out DIR--grid Nadds a pixel rulerlabelkit skill [--install]labelkit <dataset> --select <image>All of them write the result to stdout as JSON, notes to stderr, and exit
0(ok),1(problem found) or64(usage error). None touches AppKit.Design decisions worth reviewing
annotateaccepts what models actually emit. Geminibox_2d, corner lists, 0–1 and 0–1000 units, centre anchors, parallelboxes/labelslists, COCO files andlabelkit detectoutput are read as they are. For anything else you name the convention (--units,--origin,--anchor,--order,--image-size) instead of converting numbers. Nothing is inferred from the values.1;--lenientapplies the valid part.CreateMLWriter, so entry order, unknown keys, negatives and the file's own indentation are preserved.AgentGuide.skill) solabelkit skillalways matches the installed version.skills/labelkit/SKILL.mdis the same text for repository-based installers; a test fails if they differ.AGENTS.mdis now the canonical project instructions;CLAUDE.mdimports it. This is a change to how the repo instructs agents, so please check you are happy with it.Two real-world inputs shaped this: the iris card-detector labelling work (agents writing whole-image box lists, checking them against a labelled pixel grid, mixed coordinate conventions, byte-identical duplicate images with conflicting labels) and the current documentation of nine agent clients and the common box formats.
Speed
Measured on a 10,000-image dataset with 26,000 boxes (5 MB
annotations.json), Apple silicon, release build:statsannotate(one image)validateThe gains come from the first commit and also apply to the editor's open and save: the loader reads Foundation's containers directly instead of bridging every dictionary, filenames and labels become native Swift strings once, the writer formats coordinates as integer hundredths, indent detection reads 64 KB instead of the whole file, and the directory sort stays inside Foundation.
Saved bytes are unchanged. A test compares the new coordinate formatting with the previous implementation over 420,000 values, and the existing golden and round-trip tests pass untouched.
How it was checked
swift test: 166 tests, 0 failures (63 of them new).scripts/smoke-scripted.sh(new, runs in CI): drives every scripted command on a throwaway dataset and checks exit codes, refusal of bad input, and byte-identical repeats.docs/agents.mdwas run against the release binary, with the saved coordinates checked by hand.claude plugin validate .passes for the plugin manifest.Not checked:
--selectin the running editor. It builds and is wired through all three launch paths, but I did not see it work in a window.npx skills add. Both need this branch onmain; only the manifest was validated.Commits
perf:the loader, scanner and writer speed-ups, with their testsfeat:the commands, the library code behind them, tests, the skill file, the smoke testdocs:docs/agents.md, README, CHANGELOG,AGENTS.md, the plugin manifestLeft for later
annotations.jsonchanges underneath it (today you re-runlabelkit <dataset>to reload)🤖 Generated with Claude Code