Repository navigation
Add .auto content mapper and Vite plugin backed by the Claude CLI - #1
Merged
Merged
Conversation
A TypeScript 7.1 content mapper turns .auto files (plain-language module descriptions) into TypeScript generated by `claude --print`. A Vite plugin serves the same modules. Both go through one loadAutoModule() function and a shared, committable cache (.auto-cache/, keyed by description, path, model and instructions), with a cross-process lock so tsc, the editor and Vite never generate the same file twice. Includes a demo app with committed generated modules, and tests covering the JSON-RPC protocol and tsc/Vite cache sharing using a fake Claude CLI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KZB12ZvzrAveULf7rh79H6
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.
Summary
This adds
content-mapper-auto. A.autofile contains a plain-language description of a module. Claude writes the implementation, and you import it from TypeScript like any other module.src/mapper/): the mapper process TypeScript launches, speaking JSON-RPC over stdio (initialize/openProject/transform/closeProject).tsc --runExternalCodeand the language server see the generated module's real types.content-mapper-auto/vite): serves and bundles the same generated module, compiled from TypeScript with Oxc (Vite 8) or esbuild (Vite 7).src/core/): both sides call the sameloadAutoModule().claude --printwith structured JSON output and read-only tools (Read/Glob/Grep).contentMappersentry, followingextendsandreferences. Both tools therefore compute the same cache keys and paths.src/foo.autois cached as.auto-cache/src/foo.auto.ts, keyed by a hash of the description, file path, model and instructions.tscand Vite never generate the same file twice.offline/CONTENT_MAPPER_AUTO_OFFLINE=1, CI fails when a description changed but its module wasn't regenerated.auto2"save to regenerate" diagnostic. Generation failures (auto1) and bad options (auto10) appear as diagnostics, and bad options point at their exact location in tsconfig.examples/demo): a todo app whose store and relative-time formatting are.autofiles. The generated modules are committed, so it runs without Claude.I worked out the protocol details from
microsoft/typescript-go'sinternal/contentmapper, as of #4712.Testing
npm testruns 19 tests against a fake Claude CLI:tsc7.1.0-beta andvite buildsharing the cache in both directions;tscand Vite started at the same moment, calling Claude only once;tsc --runExternalCodegenerated the demo modules in about 20s;vite buildandvite devreused the cache with Claude disabled, and the app worked in a headless browser;vite devregenerated the module, andtscthen type-checked against the new export without calling Claude.Limitations
tsc --build/ incremental builds don't notice when cache entries are deleted or edited by hand..autofile, with line and column numbers from the cache file.Generated by Claude Code