@sightmap/react 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +88 -112
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @sightmap/react
2
2
 
3
- React framework adapter for the [Sightmap](https://sightmap.org) spec.
3
+ React runtime for the [Sightmap](https://sightmap.org) spec.
4
4
 
5
- Mount one provider; an agent does the rest.
5
+ Mount one provider; an agent does the rest — it introspects the live React
6
+ tree via [bippy](https://github.com/aidenybai/bippy) and curates the project's
7
+ `.sightmap/` YAML inventory through the [`@sightmap/mcp`](../mcp) tools.
6
8
 
7
9
  ## Install
8
10
 
@@ -10,60 +12,45 @@ Mount one provider; an agent does the rest.
10
12
  pnpm add @sightmap/react @sightmap/sightmap
11
13
  ```
12
14
 
13
- `@sightmap/sightmap` is a peer dep — installed alongside.
15
+ `@sightmap/sightmap` is a peer dep — install it alongside.
14
16
 
15
17
  ## Use
16
18
 
17
- ### 1. Bootstrap your `.sightmap/` from source
19
+ ### 1. Mount the provider
18
20
 
19
- ```bash
20
- # scan your react-router 7 routes + data-sightmap props
21
- # and scaffold .sightmap/<feature>.yaml files
22
- pnpm sightmap-react gen
23
- ```
24
-
25
- `gen` walks your router config, finds any `data-sightmap="..."` props in source, and writes feature-scoped YAML files to `.sightmap/` — one per top-level route. Re-run any time routes or selectors change; agent-authored fields (`memory`, intent, requests) are preserved.
26
-
27
- #### First run
28
-
29
- Running `sightmap-react gen` against a project with no `.sightmap/` directory does three things:
30
-
31
- 1. AST-scans your source for `data-sightmap` attributes and reads your React Router config to discover routes.
32
- 2. Writes per-feature YAML files under `.sightmap/` (one file per feature group of routes), each seeded with:
33
- - **Structural fields** the codegen owns: view name, route pattern, component selectors.
34
- - **Commented TODO blocks** for the agent-authored fields the codegen does NOT own: `memory`, `intent`, `requests`. These are YAML comments — the file parses cleanly until you uncomment and fill them in.
35
- 3. Prints a summary listing the views written, components linked, and the suggested first-edit targets.
21
+ ```tsx
22
+ // app entry must import BEFORE react-dom does any work.
23
+ import { SightmapProvider } from "@sightmap/react";
36
24
 
37
- Re-running `gen` is idempotent: structural fields refresh from source, agent-authored fields are preserved, and the TODO scaffolding is **not** re-emitted into files that already exist (per the codegen spec in `docs/superpowers/specs/2026-05-08-react-sdk-bootstrap-codegen.md`).
25
+ export function App() {
26
+ return (
27
+ <SightmapProvider runtimeIntrospection="dev">
28
+ <YourApp />
29
+ </SightmapProvider>
30
+ );
31
+ }
32
+ ```
38
33
 
39
- Two-minute walkthrough:
34
+ Importing `@sightmap/react` installs a [bippy](https://github.com/aidenybai/bippy)
35
+ fiber-tree hook and exposes:
40
36
 
41
- ```bash
42
- # In a fresh RR7 project root:
43
- npx sightmap-react gen
44
- # → wrote N file(s) (first run on empty .sightmap/)
45
- # → Views (N total)
46
- # → views: Login, Dashboard, ...
47
- # → Next steps — open these files and replace the TODO blocks with real values:
48
- # → - .sightmap/login.yaml
49
- # → - .sightmap/dashboard.yaml
50
- # → Run /sightmap:audit (Claude Code plugin) to surface missing memory and broken selectors.
51
-
52
- # Open the first suggested file. Replace the commented TODO blocks with real values:
53
- $EDITOR .sightmap/login.yaml
54
-
55
- # Re-run any time you change routes or add data-sightmap attributes:
56
- npx sightmap-react gen
57
- # → sightmap: up to date (or a list of structural changes only)
37
+ ```ts
38
+ window.__sightmap__ = { snapshot(): SightmapSnapshot };
58
39
  ```
59
40
 
60
- #### `--live <url>` (optional)
61
-
62
- If you have `sightmap-react`'s dev middleware running at `http://localhost:5173/__sightmap__/sightmap.json`, pass `--live <url>` to additionally fetch the runtime snapshot. Views present at runtime but not discovered by the static AST scan are surfaced as `react.live-only-view` info diagnostics `gen` does not auto-emit YAML for them; the curator hand-authors a file per the diagnostic's hint.
41
+ The snapshot returns the live React fiber tree as a flat list of
42
+ `ComponentNode`s plus a ranked `CandidateSelector[]` per node (existing
43
+ `data-sightmap` > test-id > `role`+`aria-label` > id > synthesized) and a
44
+ parallel list of `data-sightmap` markers and unmarked-but-named candidates.
45
+ An agent (Subtext, Claude Code, a Playwright-driven MCP) reads it to plan
46
+ selectors and to decide which components deserve a `data-sightmap` marker.
63
47
 
64
- The static path is the source of truth for codegen. `--live` is a discovery aid, not a parallel write path.
48
+ `runtimeIntrospection` modes:
49
+ - `"dev"` (default): hook installs only when `process.env.NODE_ENV !== "production"`.
50
+ - `"enabled"`: install always — opt-in for prod when you want agents to drive a live app.
51
+ - `"off"`: do not install the hook.
65
52
 
66
- ### 2. Add the Vite dev plugin (optional but recommended)
53
+ ### 2. Add the Vite plugin (optional but recommended)
67
54
 
68
55
  ```ts
69
56
  // vite.config.ts
@@ -74,99 +61,88 @@ import { sightmap } from "@sightmap/react/vite";
74
61
  export default defineConfig({
75
62
  plugins: [
76
63
  react(),
77
- sightmap(),
64
+ sightmap({ autoInject: true }),
78
65
  ],
79
66
  });
80
67
  ```
81
68
 
82
- The plugin registers a `/__sightmap__/sightmap.json` endpoint in dev so the runtime provider can fetch the merged sightmap. It does **not** write to `.sightmap/` — generation is explicit (`sightmap-react gen`).
69
+ The plugin does two things:
83
70
 
84
- ### 3. Mount the provider
71
+ 1. Registers a dev middleware at `/__sightmap__/snapshot.json`. The browser
72
+ POSTs a snapshot to it during render; the MCP server's
73
+ `sightmap_runtime_snapshot` tool (`kind: "endpoint"`) GETs it back. This
74
+ is the lowest-friction way to feed snapshots to an out-of-process agent
75
+ that isn't driving the browser.
76
+ 2. With `autoInject: true`, prepends `import "@sightmap/react";` to your app
77
+ entry (`src/main.tsx`, `app/entry.client.tsx`, etc.) so the bippy hook
78
+ installs before React-DOM imports. If you'd rather wire it manually, omit
79
+ the option and import `@sightmap/react` at the top of your entry file.
85
80
 
86
- ```tsx
87
- // app root
88
- import { SightmapProvider } from "@sightmap/react";
81
+ The plugin does **not** write to `.sightmap/` — curation is agent-driven via
82
+ `@sightmap/mcp` and the [`sightmap` plugin](https://github.com/sightmap/plugin).
89
83
 
90
- export function App() {
91
- return (
92
- <SightmapProvider runtimeIntrospection="dev">
93
- <YourApp />
94
- </SightmapProvider>
95
- );
96
- }
97
- ```
98
-
99
- The provider:
100
- - Loads the merged sightmap (from `/__sightmap__/sightmap.json` in dev, or a static `/sightmap.json` in prod).
101
- - Installs `window.__SIGHTMAP__` for an agent to introspect (dev by default; opt-in for prod).
102
-
103
- ### 4. Let an agent curate
84
+ ### 3. Let an agent curate
104
85
 
105
- The agent (Subtext, Claude Code, Playwright MCP, etc.) inspects the running app via `window.__SIGHTMAP__` and writes `data-sightmap="..."` props into source where it needs stable selectors. Re-run `sightmap-react gen` to refresh the structural skeleton; the agent's `memory`, intent, and request annotations survive untouched.
106
-
107
- ### 5. The rest of the CLI
86
+ After install, the fastest path is:
108
87
 
109
88
  ```bash
110
- # rerun whenever routes or data-sightmap props change
111
- sightmap-react gen
112
-
113
- # CI gate: dry-run; exit 1 if .sightmap/ is out of date
114
- sightmap-react gen --check
89
+ # In your project root, with .sightmap/ scaffolded by `sightmap init`:
90
+ # (run inside Claude Code / Cursor / Codex / opencode with the sightmap plugin installed)
91
+ /sightmap:bootstrap
92
+ ```
115
93
 
116
- # print a unified diff of would-be changes; writes nothing
117
- sightmap-react gen --diff
94
+ `/sightmap:bootstrap` walks the live app, reads the snapshot, and proposes a
95
+ starter `.sightmap/` inventory — view files with routes, components, ranked
96
+ selectors, and seed `description`/`intent`/`memory`. You confirm and the
97
+ plugin writes the files via the MCP curation tools.
118
98
 
119
- # validate; warns about routes with no view, drift between source and YAML
120
- sightmap-react validate
121
- ```
99
+ Subsequent loops:
100
+ - `/sightmap:audit` — six-dimension lint of the inventory.
101
+ - `/sightmap:fix` — applies audit-driven patches (confirm-first; `--apply` to auto-apply).
102
+ - `/sightmap:reflect` — at end of turn, folds the agent's just-made source edits back into intent/memory.
122
103
 
123
- Run `sightmap-react gen --check` in CI to fail the build when routes or
124
- `data-sightmap` props have drifted from the committed `.sightmap/` files.
125
- Run `sightmap-react gen` to fix.
104
+ You can also add `data-sightmap="ComponentName"` props to JSX wherever you
105
+ want stable agent-facing selectors. They bubble through the snapshot's
106
+ `markers` list and rank highest in selector ranking.
126
107
 
127
108
  ## File layout
128
109
 
129
110
  ```
130
111
  .sightmap/
131
- login.yaml # plugin-scaffolded, agent-curated: view + components for /login
132
- dashboard.yaml # plugin-scaffolded, agent-curated
133
- shared.yaml # plugin-scaffolded: cross-route components
134
- extras.yaml # agent-only: non-derivable additions
112
+ app.yaml # corpus-level metadata
113
+ login.yaml # one view per top-level route
114
+ dashboard.yaml
115
+ shared.yaml # cross-route components
135
116
  ```
136
117
 
137
- Plugin owns: `name`, `route`, `selector`, `children`. Agent owns: `memory`, intent, requests, and any unknown field. Smart-merge preserves agent fields, comments, and ordering.
138
-
139
- ## What's in v0.1
140
-
141
- - `<SightmapProvider>` + `window.__SIGHTMAP__` (read-only basics: `walkTree`, `inspectAt`, `getCurrentView`, `getSightmap`, `match`, `findByDataSightmap`, `version`)
142
- - Vite dev plugin (registers `/__sightmap__/sightmap.json` middleware)
143
- - React-router 7 declarative-mode adapter (driven from the CLI)
144
- - React-router 7 framework-mode adapter (`app/routes.ts` programmatic config)
145
- - Smart-merge YAML writer (idempotent; preserves agent fields)
146
- - CLI: `gen`, `validate`
147
-
148
- ### Selecting an adapter
118
+ The agent owns every field — structural (`name`, `route`, `components`,
119
+ per-component `selector`/`memory`) and semantic (`description`, `intent`,
120
+ view-level `memory`). The hooks shipped by the sightmap plugin run
121
+ `sightmap check` and `sightmap audit` after each write to keep curation
122
+ honest.
149
123
 
150
- `sightmap-react gen --router <name>` accepts:
124
+ ## What's exported
151
125
 
152
- - `react-router-7` — declarative `<Routes><Route />` JSX (default).
153
- - `react-router-7-framework` programmatic `app/routes.ts` config using `route`, `index`, `layout`, `prefix` from `@react-router/dev/routes`.
154
- - `auto` — picks framework mode if `app/routes.ts` exists, else declarative.
155
-
156
- Framework-mode v0.1 limitations: hardcoded `app/` directory (custom `appDirectory` from `react-router.config.ts` is not yet honored), top-level helper identifiers only (no namespaced/aliased calls), string-literal arguments only, and no support for `flatRoutes()` filesystem-based routing.
157
-
158
- ## Coming in v0.2
159
-
160
- - React-router 7 data-mode adapter
161
- - `flatRoutes()` filesystem-based discovery for framework mode
162
- - Adapters for Next.js, Remix, TanStack Router
163
- - Curation helpers in the runtime API: `suggestSelector`, `verifySelector`, `diff`
164
- - CLI: `diff`
126
+ ```ts
127
+ // public runtime + types
128
+ import {
129
+ SightmapProvider,
130
+ useSightmap,
131
+ sightmap as sightmapVitePlugin, // also re-exported from @sightmap/react/vite
132
+ type SightmapSnapshot,
133
+ type SightmapMarker,
134
+ type UnmarkedCandidate,
135
+ type ComponentNode,
136
+ type CandidateSelector,
137
+ type SelectorStability,
138
+ type SelectorSource,
139
+ } from "@sightmap/react";
140
+ ```
165
141
 
166
142
  ## Design
167
143
 
168
144
  - v0 design: [docs/superpowers/specs/2026-04-26-react-sdk-design.md](https://github.com/sightmap/sightmap-js/blob/main/docs/superpowers/specs/2026-04-26-react-sdk-design.md)
169
- - Bootstrap-only codegen pivot: [docs/superpowers/specs/2026-05-08-react-sdk-bootstrap-codegen.md](https://github.com/sightmap/sightmap-js/blob/main/docs/superpowers/specs/2026-05-08-react-sdk-bootstrap-codegen.md)
145
+ - Codegen-to-runtime pivot: [docs/superpowers/plans/2026-05-13-codegen-to-runtime-agent-pivot.md](https://github.com/sightmap/sightmap-js/blob/main/docs/superpowers/plans/2026-05-13-codegen-to-runtime-agent-pivot.md)
170
146
 
171
147
  ## License
172
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sightmap/react",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "React runtime for the Sightmap spec — SightmapProvider, runtime introspection hook, and Vite plugin.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -60,7 +60,7 @@
60
60
  "typescript": "~5.7.3",
61
61
  "vite": "^7.0.0",
62
62
  "vitest": "^3.0.0",
63
- "@sightmap/sightmap": "^0.8.0"
63
+ "@sightmap/sightmap": "^0.10.0"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "tsup",