@uicontract/annotator
v0.3.0
Published
Source code annotator that inserts data-agent-id attributes into UI components
Maintainers
Readme
@uicontract/annotator
Source code annotator that inserts data-agent-id attributes into UI components.
Install
npm install @uicontract/annotatorUsage
import { annotate } from '@uicontract/annotator';
const result = await annotate({
projectRoot: '/path/to/my-app',
elements: namedElements, // NamedElement[] from @uicontract/namer
dryRun: true, // preview patches without writing files
});
console.log(result.patches); // files that would be modified
console.log(result.warnings); // elements that could not be annotatedMost users interact with the annotator through the CLI:
# Always preview before writing
npx uicontract annotate --dry-run
# Write data-agent-id attributes to source files
npx uicontract annotateAPI
annotate(options): Reads source files, computes patches insertingdata-agent-idat element locations reported by the parser, and optionally writes them. Returns{ patches, warnings }.
Safety guarantees:
- Creates a
.uic-backup/directory before modifying any file. - Refuses to run on a project with uncommitted git changes.
dryRun: truereturns patches without touching the filesystem.
Part of UI Contracts
This package is part of UI Contracts - making web app UIs machine-readable.
