critiqs-react 0.0.0-stage → 0.4.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.
package/AGENT_SETUP.md ADDED
@@ -0,0 +1,322 @@
1
+ <!-- Generated from packages/critiqs/AGENT_SETUP.md when critiqs-react is built; edit that file. -->
2
+ # Setting up Critiqs: instructions for coding agents
3
+
4
+ Critiqs lets reviewers comment directly on a running prototype. Each framework
5
+ has a small Critiqs package that builds on the shared `critiqs` package, and
6
+ one setup command, `critiqs`, sets up any of them:
7
+
8
+ | Framework | Package |
9
+ | --- | --- |
10
+ | React, Next.js | `critiqs-react` |
11
+ | Vue | `critiqs-vue` |
12
+ | Nuxt | `critiqs-nuxt` |
13
+ | Svelte, SvelteKit | `critiqs-svelte` |
14
+ | Angular | `critiqs-angular` |
15
+ | Astro | `critiqs-astro` |
16
+ | Solid | `critiqs-solid` |
17
+ | Ruby on Rails | the `critiqs-rails` gem |
18
+ | Django | `django-critiqs` on PyPI |
19
+ | Flask | `flask-critiqs` on PyPI |
20
+
21
+ A page with no build at all uses `<critiqs-app>` from `critiqs` itself; see its
22
+ README. The command line is enough; the MCP server (step 5) is optional.
23
+
24
+ The setup CLI supports Node.js 20 or later. For the optional embedded SQLite
25
+ server use Node.js 22.13 or later, or Bun. Node.js 20 can build the browser
26
+ integration and run setup, but cannot run the built-in SQLite server.
27
+
28
+ Never ask the person to paste keys, tokens, or sign-in codes into the
29
+ conversation. Critiqs Cloud, the default, needs none. AI is optional: don't set
30
+ it up unless asked.
31
+
32
+ ## 1. Run setup
33
+
34
+ Run the commands below in the app's folder (the one with its `package.json`,
35
+ `Gemfile`, or `manage.py`), or pass `--dir <folder>`. Use `npx critiqs …` (or
36
+ `pnpm dlx critiqs`, `yarn dlx critiqs`, `bunx critiqs`). In an app that already has `critiqs-react`,
37
+ `npx critiqs-react …` runs the same command, so existing instructions keep
38
+ working.
39
+
40
+ Setup finds the app's framework from its `package.json`, `Gemfile`, or
41
+ `manage.py` and `requirements.txt`. Critiqs the code already has comes first:
42
+ setup updates it whatever the framework (such as `critiqs-react` in an Astro
43
+ app's React island), and changes nothing when two framework packages each set
44
+ it up. When the app doesn't list the framework's Critiqs package yet, setup
45
+ says which one to install, with the command for the project's package manager
46
+ (as its lockfile shows), naming the app when run from elsewhere in its
47
+ workspace. Install it: setup adds the code that uses it, not the package.
48
+
49
+ **Monorepos:** each app gets its own project. Run init once per app with
50
+ `--dir apps/<app>`; at the workspace root, init lists the apps with these exact
51
+ commands and changes nothing. Ask the person which apps should have Critiqs;
52
+ never connect two apps to one project unless they ask for that.
53
+
54
+ ## 2. Add Critiqs and create the project
55
+
56
+ ```sh
57
+ npx critiqs init --json
58
+ ```
59
+
60
+ Init adds the framework's Critiqs component or tag, and its import, where the
61
+ app renders. In React it goes beside `<App />` in a `createRoot(…).render(…)`
62
+ or `ReactDOM.render(…)` call, or beside the element `hydrateRoot` receives; in
63
+ Next.js inside `<body>` in `app/layout.tsx` (the layout stays a server
64
+ component; the package declares the client boundary), or beside
65
+ `<Component {...pageProps} />` in `pages/_app.tsx`. Each framework package's
66
+ README says where it goes there. For other structures, name the file:
67
+ `npx critiqs init --entry src/Shell.tsx`, and in React and Next.js the element
68
+ to add it beside: `--mount Outlet`. Preview with
69
+ `npx critiqs init <projectId> --dry-run` when the project already exists.
70
+
71
+ Then init signs the person in and creates the project:
72
+
73
+ - **Browser on this computer:** init opens a sign-in page. Tell the person to
74
+ sign in there with their email.
75
+ - **No browser here** (SSH, a container, a cloud agent): pass `--remote`, or
76
+ let init choose it. It prints an address and a code such as `BCDF-GHJK`. Give
77
+ both to the person exactly and ask them to open the address on any device,
78
+ enter the code, sign in, and choose Approve. The code expires after 10
79
+ minutes. Never ask them to send you the email code. The address is always
80
+ the sign-in service's own `/auth/device` page. For a backend other than
81
+ Critiqs Cloud, the sign-in service must confirm that its page names the
82
+ backend, as for `sign-in` below.
83
+
84
+ With `--json`, standard output is one JSON object; progress, including the
85
+ address and code, goes to standard error. The result's `stages` say where
86
+ setup stands: `Code`, `Project`, `Finish setup` (when the framework's package
87
+ still needs installing, or the framework has another step), `Try it locally`,
88
+ and `Reviewers elsewhere`, each `pass`, `warn`, `fail`, or `next`. Report them
89
+ to the person, including any `warn` (such as a missing review address), and
90
+ take or report every `next` step (install the package, run the dev server,
91
+ deploy).
92
+
93
+ Where the framework has a public environment variable, init makes Critiqs read
94
+ its project ID from it, sets it in the app's local `.env` file, and lists it
95
+ empty in `.env.example`. In a Vite app (React, Vue, Svelte, Solid) it is
96
+ `VITE_CRITIQS_PROJECT_ID`, in Next.js `NEXT_PUBLIC_CRITIQS_PROJECT_ID`, and
97
+ each framework's package README names its own; workspace apps get a name with
98
+ the app's suffix, such as `VITE_CRITIQS_PROJECT_ID_ADMIN`. A React app then
99
+ has `<Critiqs projectId={import.meta.env.VITE_CRITIQS_PROJECT_ID} requireProjectId />`.
100
+ The result's `env` names the variable and file, and the `Deployments` stage
101
+ says what to do: commit the code change but not the local `.env` file, and tell
102
+ the person to set the variable in the settings of each deployment that should
103
+ show Critiqs, leaving it unset where Critiqs shouldn't appear. A variable read
104
+ when the app is built needs a rebuild after it changes. Server frameworks
105
+ (Rails, Django, Flask) read it from the server's environment instead. Other
106
+ apps get the ID written into the code; commit it. The project ID is public
107
+ configuration, not a secret.
108
+
109
+ Running init again is safe: it keeps the project the code names (a literal ID,
110
+ or the variable's value in `.env` files), and after an interrupted run it
111
+ reuses the person's project with the same name. Only pass `--new-project` when
112
+ the person wants another project. Init never edits code that computes the ID,
113
+ or a wrapper the person wrote; it prints what to set instead.
114
+
115
+ If the person already has a project ID, connect it instead:
116
+ `npx critiqs init <projectId>` (no sign-in needed). It sets the variable
117
+ when Critiqs reads one.
118
+
119
+ ## 3. Check the setup
120
+
121
+ ```sh
122
+ npx critiqs doctor --json
123
+ ```
124
+
125
+ `ok` is false when any check `fail`s. Each check has a `stage` (`code`,
126
+ `service`, `project`, `reviewers`, `optional`) and a `basis`: `configuration`
127
+ means the settings are in place; `observed` means the backend has actually
128
+ done it (such as sending a mention email). Doctor never sends email, uploads a
129
+ screenshot, or posts a comment, so don't report those as proven; the first real
130
+ comment proves them. `info` (AI off) is not a problem. For an environment-backed
131
+ ID, doctor checks the value in this computer's `.env` files against the
132
+ backend; it can't see a deployment's build settings, and says so in the
133
+ `Deployments` check.
134
+ If setup used `--project-env-file`, pass the same file to doctor, for example
135
+ `npx critiqs doctor --project-env-file config/.env.local --json` (or `envFile`
136
+ on `critiqs_doctor`). If the environment directory cannot be determined,
137
+ doctor reports that uncertainty instead of saying the app is disabled.
138
+
139
+ Once the prototype is deployed, record its address, including any path, so
140
+ mention emails from every copy open it:
141
+ `npx critiqs init --review-url https://<deployed address>`. Don't guess
142
+ it from a local, private, or Tailscale address; ask the person if unsure. Then ask
143
+ the person to open the deployed prototype and leave a comment.
144
+
145
+ ## 4. When something fails
146
+
147
+ | Output | Do this |
148
+ | --- | --- |
149
+ | `Init didn't find where the app renders` | Find the file that renders the app's root and rerun with `--entry <file>` (and in React, `--mount <Element>`), or add Critiqs there by hand as the printed instructions say and rerun init. |
150
+ | `Setup didn't recognize this app's framework` | Check the app's folder (`--dir`) and that its `package.json`, `Gemfile`, or Python requirements list the framework. In a page without a build, use `<critiqs-app>` from `critiqs`. |
151
+ | `Found several places the app could render Critiqs` | Ask which app this is; rerun with `--entry`, or in that app's folder. |
152
+ | `is a workspace with … apps` | Ask which apps should have Critiqs; run the printed `--dir` command for each. |
153
+ | `sets envDir in a way init can't follow` | Find the `.env.local` the app's Vite config loads and rerun with `--project-env-file <file>`, relative to the app. |
154
+ | `sets envPrefix` | In this Vite app, give `<Critiqs />` `projectId={import.meta.env.<name with the app's prefix>} requireProjectId`, then rerun init. |
155
+ | `Couldn't write .env.local` after the project was created | Add the printed `NAME=<project ID>` line to that file; the project and the code change already exist. |
156
+ | `uses Critiqs under another name` | Critiqs is already mounted there; set the printed properties on it by hand. |
157
+ | `already loads … in a way setup can't read` | Critiqs is already on the page another way (a namespace import, a re-export, `mountCritiqs`, or a router helper). Ask whether to keep it: set its project ID by hand, or remove it and rerun init. |
158
+ | `several … config files` | Ask which config file the app uses; remove the others, then rerun init. |
159
+ | `sets projectId from code` | The code computes the ID (a wrapper or fallback); init leaves it alone. Put the printed ID where that code reads it, without making it secret. |
160
+ | `doesn't support approving setup from another device yet` | Run init where a browser can open, using the chosen backend, or create the project in the matching prototype's Critiqs sidebar, then run `npx critiqs init <projectId>`, which keeps its backend. |
161
+ | `Setup was denied` or `The setup code expired` | Run init again; nothing was created. |
162
+ | `doesn't confirm its approval page names the backend`, `on its approval page, not`, `didn't say clearly which addresses`, or `didn't confirm it with the approval` | The sign-in service can't show, or didn't confirm, the backend the person would approve, so nothing was created. Tell the person; its operator deploys the current Critiqs backend. Don't retry with another backend without asking. |
163
+ | Source became unreadable or unwritable after approval | Keep the returned project ID and backend. Restore access, then apply the complete instructions it printed, at the file it names, and the `.env` line. Update an existing Critiqs setup; do not use an ID-only command that would lose the selected backend. |
164
+ | `The code already uses project …` | Nothing changed. Use `--review-url` to set its address, or `--new-project` only if asked. |
165
+ | `Critiqs Cloud isn't ready for this version` | The hosted backend is older than the package; tell the person. Don't switch backends without asking. |
166
+
167
+ ## 5. Optional: the MCP server
168
+
169
+ `critiqs mcp` offers the same steps as tools. Add it to the agent's MCP
170
+ configuration, with any keys in its environment rather than in tool calls:
171
+
172
+ ```json
173
+ {
174
+ "mcpServers": {
175
+ "critiqs": { "command": "npx", "args": ["critiqs", "mcp"] }
176
+ }
177
+ }
178
+ ```
179
+
180
+ A configuration with `"args": ["critiqs-react", "mcp"]` keeps working: it runs
181
+ the same server.
182
+
183
+ - `critiqs_setup_start` (`signIn`: `"auto"`, `"browser"`, or `"remote"`;
184
+ `entry`, `mount`, `name`, `reviewUrl`, `newProject`, `dir`, `envFile`; `target`:
185
+ `"cloud"` by default, `"own-convex"`, or an existing backend's URL). Returns
186
+ the address, and for remote approval the code, to give the person.
187
+ - `critiqs_setup_finish`: waits for sign-in or approval, then reuses or
188
+ creates the project and writes its ID. Call again while it reports waiting.
189
+ Its `structuredContent.stages` and `env` match init's.
190
+ - `critiqs_write_project_id` (`projectId`, `dir`, `entry`, `mount`, `envFile`, `dryRun`).
191
+ - `critiqs_doctor` (`dir`, `backend`, `envFile`); `structuredContent` matches
192
+ `doctor --json`.
193
+
194
+ ## 6. Optional: more context, own backend, and AI
195
+
196
+ These are separate from basic setup; skip them unless the person asks.
197
+
198
+ - **Context:** the `version`, `getContext`, and `restoreContext` settings
199
+ record and restore the prototype's view state; see the framework package's
200
+ README.
201
+ - **The team's own Convex deployment:** `npx critiqs init --own-convex`.
202
+ It needs `CONVEX_DEPLOY_KEY`, a production deploy key the person sets in the
203
+ environment themselves; `RESEND_API_KEY` and `CRITIQS_EMAIL_FROM` are
204
+ optional and turn on mention emails. It also sets Critiqs's backend setting
205
+ to `https://<deployment>.convex.cloud` in the code.
206
+ - **Inside the app's own Node or Bun server:** `critiqs/server` (also
207
+ `critiqs-react/server`) runs Critiqs on SQLite; see the `critiqs-react`
208
+ README. Set the mounted path as Critiqs's backend setting (for example
209
+ `/critiqs`), create the project in the
210
+ Critiqs sidebar, and write its ID with `npx critiqs init <projectId>`.
211
+ `npx critiqs doctor --backend http://localhost:<port>/critiqs` checks it.
212
+ - **AI:** works without any setup in the host app. On the team's own Convex
213
+ deployment, the person can set `CRITIQS_AI_ENCRYPTION_KEY` (32 or more random
214
+ characters, such as from `openssl rand -base64 32`) with `npx convex env set
215
+ CRITIQS_AI_ENCRYPTION_KEY`, typing the value at its prompt, so project owners
216
+ can connect a provider in the Critiqs sidebar. After upgrading a deployment
217
+ that already has feedback, run `npx convex run tags:backfill` once.
218
+
219
+ ## 7. Reading feedback
220
+
221
+ To act on reviewers' feedback, read it with the MCP server's tools. They work
222
+ with Critiqs Cloud and Convex deployments, not yet with Critiqs inside the
223
+ app's own server.
224
+
225
+ 1. **Sign the computer in once.** The first reading call says the computer
226
+ isn't signed in. Call `critiqs_sign_in` (`signIn`: `"auto"`, `"browser"` to
227
+ also open the approval page on this computer, or `"remote"`; `backend` when
228
+ not on Critiqs Cloud). Give the person the address and code exactly, as in
229
+ setup, then call `critiqs_sign_in_finish` until it reports who signed in.
230
+ People can instead run `npx critiqs sign-in`. The sign-in is kept on the
231
+ computer, readable only by its user, and is reused by later sessions until
232
+ `critiqs_sign_out` (or `npx critiqs sign-out`), 30 days without use,
233
+ or 90 days. It is sent only to the backends it was approved for, and to
234
+ where each serves screenshots and page copies; the approval page names
235
+ them, and the person should check it does. Signing in for a backend other
236
+ than Critiqs Cloud needs a sign-in service that names it there (the
237
+ current Critiqs backend). Critiqs Cloud's older sign-in service names no
238
+ backend; then check only that the page's address is the one given. Never
239
+ ask for the code the person receives by email.
240
+ 2. **`critiqs_comments`** (`projectId`, required; `status`: `"open"` by
241
+ default, `"resolved"`, or `"all"`; `author`: a display name or an author ID;
242
+ `since` and `until`: a date such as `2026-10-01`, a date and time, or an age
243
+ such as `7d`; `tag`; `screen`; `text`; `limit`, 50 by default). Returns
244
+ matching threads, newest activity first, each with its whole discussion
245
+ and context: `context.target.purposeId` is the element's `data-critiqs-id`
246
+ in the code, with the screen, view state, record, scope, page address,
247
+ window size, demo persona, build revision, and `movedTo` when a thread was
248
+ reattached. With author, time, or text filters, a thread matches when any of
249
+ its messages does, and each message's `matches` says which. `truncated`
250
+ says when more matched than `limit`.
251
+ 3. **`critiqs_thread`** (`thread`: an ID or a Critiqs link) adds mentions,
252
+ reactions, who last resolved or reopened the thread and who moved it, its
253
+ screenshot's state, and, where the backend has tickets, `tickets`: each
254
+ Linear, GitHub Issues, or Jira ticket linked to it, with its key, title,
255
+ status (`lastKnown` when Critiqs can no longer check it), and address.
256
+ 4. **`critiqs_screenshot`** (`thread`; `file` to save it) returns what the
257
+ reviewer saw, with the commented element outlined. Images over 5 MB need
258
+ `file`.
259
+ 5. **`critiqs_reply`** (`thread`, `body`; `mention`: display names or author
260
+ IDs from `critiqs_thread`; `revision`, such as the commit) posts a reply as
261
+ the signed-in person, shown as "Name · via coding agent". Use it once the
262
+ work is done, to say what changed and ask the right people to check it.
263
+ Everyone else in the thread is emailed about it (unless they turned that
264
+ off); people you mention get a mention email. Write only what you actually
265
+ did and verified.
266
+ 6. **`critiqs_mockups`** (`projectId`, required; `screen`; `text` in the
267
+ title; `limit`, 50 by default) lists the project's mockups, most recently
268
+ changed first: proposed changes reviewers made with Critiqs AI on frozen
269
+ copies of a page. Each has the page it was made from (address, screen,
270
+ view state, build revision, demo persona), its version and thread counts,
271
+ its page copies' IDs and widths, and its mockup threads: each one's ID,
272
+ status, first message, author, and last activity. A mockup made in the
273
+ Mockup panel has one thread, whose first message says what it is for.
274
+ 7. **`critiqs_mockup`** (`mockup`, required; `version`, the latest by
275
+ default, or `0` for the original copies; `saveCopies`, a folder) returns
276
+ what to build. For each page copy, `edits` lists every change from the
277
+ original copy in order: CSS rules, text, attributes, and inserted,
278
+ replaced, or removed elements, each naming an element by its
279
+ `data-critiqs-node` number. A change's `original` is that element as the
280
+ copy has it: its start tag without the number, its text, and the nearest
281
+ `data-critiqs-id` (`purposeId`), to find the component in the code.
282
+ `original` is null with `addedByChange` when an earlier change in the list
283
+ added the element. It also returns the version history, the mockup
284
+ threads with their whole discussions (Critiqs AI's replies have
285
+ `via: "ai"`, `askedBy`, and the `mockupVersion` they saved), and the
286
+ linked feedback threads, which `critiqs_thread` reads in full. With
287
+ `saveCopies`, each copy's original HTML is written to
288
+ `<folder>/<mockupId>/<copyId>.html` and the version's changes to
289
+ `edits-v<N>.json` beside them. Build the change in the app's own
290
+ components; don't paste the copy's HTML.
291
+
292
+ | Message | What to do |
293
+ | --- | --- |
294
+ | `isn't signed in` or `sign-in ended` | Call `critiqs_sign_in` and have the person approve. |
295
+ | `isn't approved for the backend at` | Nothing was sent to that backend. Ask the person whether they trust it; only then call `critiqs_sign_in` with that `backend`, and have them check that the approval page names it. |
296
+ | `with screenshots and page copies from` | The sign-in was approved for other download addresses than the backend now uses. Nothing was sent. Ask the person whether they trust the new address; only then sign in again for that `backend`. |
297
+ | `doesn't use HTTPS` | Critiqs sends sign-ins over plain http only to this computer (`localhost`, `127.0.0.1`, or `[::1]`). Use the backend's HTTPS address. |
298
+ | `answered with a redirect` | Critiqs doesn't follow redirects with a sign-in, and sent it nowhere else. Use the backend's own address; tell the person if it keeps happening. |
299
+ | `doesn't confirm its approval page names the backend` | The sign-in service is older than the package, so its approval page can't show the backend. Tell the person; its operator deploys the current backend. |
300
+ | `on its approval page, not` | The sign-in service would show a different address than this backend, so the sign-in stopped. Tell the person; don't retry. |
301
+ | `didn't say clearly which addresses` or `didn't confirm it with the approval` | The sign-in service didn't confirm both addresses the page showed, so the computer kept nothing. Tell the person; its operator deploys the current Critiqs backend. |
302
+ | `people are named` | Use one of the listed author IDs. |
303
+ | `No one named … has commented in this project` | Mention only people who have commented there, by the names or author IDs `critiqs_thread` shows. |
304
+ | `can't post agent replies yet` | The backend is older than the package; tell the person. Its operator deploys the current backend. |
305
+ | `has no mockups yet` | The backend is older than the package; tell the person. Its operator deploys the current backend. |
306
+ | `runs an older version that can't keep this computer signed in` | The backend is older than the package; tell the person. Its operator deploys the current backend. |
307
+ | `didn't confirm signing out` | The computer is still signed in; try again when the backend is reachable. |
308
+
309
+ ## What not to do
310
+
311
+ - Don't add a second Critiqs component or tag, or wrap the app in Critiqs
312
+ providers or `"use client"` boundaries; the package handles its own.
313
+ - Don't put keys in source files, tool arguments, the conversation, or the
314
+ prototype's browser code or build settings: AI and email keys belong on the
315
+ backend only.
316
+ - Don't identify projects by the prototype's URL. The project ID decides
317
+ which feedback a copy (local, preview, deployed) shows; a preview never
318
+ changes the project's review address unless someone runs `--review-url` for
319
+ it.
320
+ - Don't commit the local `.env` file (such as `.env.local`), copy one app's project ID into another app's
321
+ variable, or set one generic `VITE_CRITIQS_PROJECT_ID` for a build that
322
+ builds several apps.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Noah Jung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.