ai-src
v0.1.0
Published
DOM source location instrumentation plugins for Astro, React, Vue, Svelte, and more
Downloads
145
Readme
ai-src
Instrument DOM nodes rendered during Astro, plain React, Vue single-file components, Svelte components, and React Router development with deterministic data-ai-src markers. These attributes encode the relative file path, line, and column that produced each element so tooling (inspectors, agents, IDE extensions, etc.) can jump straight from the browser to source code.
Quick Example
// Source component
export function Hero() {
return (
<section className="hero">
<h1>Ship AI-native devtools</h1>
<p>Trace DOM nodes back to files in one click.</p>
<button>Get started</button>
</section>
);
}<!-- Before instrumentation -->
<section class="hero">
<h1>Ship AI-native devtools</h1>
<p>Trace DOM nodes back to files in one click.</p>
<button>Get started</button>
</section><!-- After instrumentation -->
<section class="hero" data-ai-src="src/components/Hero.tsx:4:5">
<h1 data-ai-src="src/components/Hero.tsx:5:7">Ship AI-native devtools</h1>
<p data-ai-src="src/components/Hero.tsx:6:7">
Trace DOM nodes back to files in one click.
</p>
<button data-ai-src="src/components/Hero.tsx:7:7">Get started</button>
</section>Install
npm install ai-srcEvery workspace under
demos/(Astro, React, Vue, Svelte, Solid, and React Router) depends on the local package via"ai-src": "file:../..". When using the package in your own project you would install it from npm instead.
Use With Astro
Add the plugin to your
astro.config.mjs:// astro.config.mjs import { defineConfig } from "astro/config"; import react from "@astrojs/react"; import vue from "@astrojs/vue"; import { astroAiSrcPlugin, reactAiSrcPlugin, svelteAiSrcPlugin, vueAiSrcPlugin, } from "ai-src"; export default defineConfig({ integrations: [react(), vue()], vite: { plugins: [ astroAiSrcPlugin(), reactAiSrcPlugin(), vueAiSrcPlugin(), svelteAiSrcPlugin(), ], }, });Run
astro dev. Every HTML element in.astrofiles receives adata-ai-src="relative/path.astro:LINE:COL"attribute.React, Vue, and Svelte islands stay in sync because each framework-specific plugin annotates its host elements and records every component's root location so the Astro-side post-processor can label
<astro-island>wrappers with the same marker.Downstream tooling can now read
data-ai-src, split on:, and map DOM nodes back to files.
Use With Vue
Add the plugin next to your existing Vue tooling in
vite.config.ts:// vite.config.ts import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import { vueAiSrcPlugin } from "ai-src/vue"; export default defineConfig({ plugins: [vueAiSrcPlugin(), vue()], });Run
vite dev. Every host element inside.vuetemplates receives a deterministicdata-ai-src="relative/path.vue:LINE:COL"attribute so you can map DOM nodes back to their single-file components. The plugin also records each component's root position so Astro Vue islands inherit the same metadata when combined withastroAiSrcPlugin().
Use With Svelte (Vite or SvelteKit)
Add the plugin next to your existing Svelte tooling in
vite.config.ts(swapsveltekit()forsvelte()if you're not using SvelteKit):// vite.config.ts import { defineConfig } from "vite"; import { sveltekit } from "@sveltejs/kit/vite"; import { svelteAiSrcPlugin } from "ai-src/svelte"; export default defineConfig({ plugins: [svelteAiSrcPlugin(), sveltekit()], });Run
vite dev(or your SvelteKitnpm run dev). Every host element inside.sveltetemplates receivesdata-ai-src="relative/path.svelte:LINE:COL"so tooling can hop straight from DOM nodes back to their components.Pass
projectRootif your sources live outside the Vite project root. The plugin uses the root to encode the correct relative path inside each attribute.Pairing this plugin with
astroAiSrcPlugin()ensures every Svelte island exposes its recorded root position so the Astro HTML post-processor can tag<astro-island>wrappers with the same metadata.
Use With React (Vite)
Register the plugin alongside your existing React tooling inside
vite.config.ts:// vite.config.ts import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { reactAiSrcPlugin } from "ai-src/react"; export default defineConfig({ plugins: [reactAiSrcPlugin(), react()], });Run
vite dev. Each JSX host element rendered during development receivesdata-ai-src="relative/path.tsx:LINE:COL", so inspectors can jump from the DOM back to the file that produced it.Pass
projectRootif your repository stores sources outside the Vite root (for example, monorepos). The plugin uses that root to compute the relative file paths encoded in every attribute.
Use With Solid (Vite)
Register the plugin next to your existing Solid tooling inside
vite.config.ts:// vite.config.ts import { defineConfig } from "vite"; import solid from "vite-plugin-solid"; import { solidAiSrcPlugin } from "ai-src/solid"; export default defineConfig({ plugins: [solidAiSrcPlugin(), solid()], });Run
vite dev. Every JSX host element rendered during development receivesdata-ai-src="relative/path.tsx:LINE:COL", so inspectors can map DOM nodes back to the file that produced them.Pass
projectRootif your repository stores sources outside the Vite root. The plugin uses that root to compute the relative file paths encoded in every attribute.
Use With React Router v7
Install the package and its React Router export:
npm install ai-srcUpdate
vite.config.tsto instrument route modules:// vite.config.ts import { reactRouter } from "@react-router/dev/vite"; import tailwindcss from "@tailwindcss/vite"; import { defineConfig } from "vite"; import { reactRouterAiSrcPlugin } from "ai-src/react-router"; export default defineConfig({ plugins: [reactRouterAiSrcPlugin(), tailwindcss(), reactRouter()], });Every JSX host element that originates from a file under
app/routes/receives:data-ai-src="relative/path.tsx:LINE:COL"data-ai-route-id="route.path"computed from the file namedata-ai-route-file="app/routes/..."to map DOM nodes directly back to the route module
Pass
routesDirectories(string or string[]) if your project stores routes somewhere other thanapp/routes.
Local Playground
This repository ships demo projects under demos/:
demos/astro/mirrors the Astro + React/Vue/Svelte integration described above.demos/react/shows how to use the React plugin in a plain Vite app.demos/vue/wires the Vue plugin into a standard Vite starter.demos/svelte/demonstrates the Svelte plugin in a SvelteKit project.demos/solid/demonstrates the Solid plugin on top ofvite-plugin-solid.demos/react-router/demonstrates the dedicated React Router plugin and its route metadata attributes.
After installing dependencies at the repo root and inside whichever demo you want to explore (for example, demos/astro/), run the demo's npm run dev to see the instrumentation live.
