@commentkit/comment-kit 1.6.0 → 2.0.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 (136) hide show
  1. package/CHANGELOG.md +281 -597
  2. package/README.md +334 -154
  3. package/SECURITY.md +47 -46
  4. package/dist/node/THIRD_PARTY_NOTICES.txt +56 -0
  5. package/dist/node/browser.js +17 -0
  6. package/dist/node/cli/api.js +226 -0
  7. package/dist/node/cli/bin.js +18 -0
  8. package/dist/node/cli/credentials.js +268 -0
  9. package/dist/node/cli/doctor.js +725 -0
  10. package/dist/node/cli/format.js +54 -0
  11. package/dist/node/cli/init.js +372 -0
  12. package/dist/node/cli/main.js +519 -0
  13. package/dist/node/cli/mcp.js +114 -0
  14. package/dist/node/cli/open.js +20 -0
  15. package/dist/node/plugins/astro-B5y1Gtbf.js +31 -0
  16. package/dist/node/plugins/astro.js +26 -0
  17. package/dist/node/plugins/git-BIXLbL3f.js +92 -0
  18. package/dist/node/plugins/jsx-Bg4BdSph.js +7958 -0
  19. package/dist/node/plugins/next.js +48 -0
  20. package/dist/node/plugins/options-THop1K92.js +71 -0
  21. package/dist/node/plugins/transform-CKiAuSbk.js +1155 -0
  22. package/dist/node/plugins/vite-BdAYUW10.js +74 -0
  23. package/dist/node/plugins/vite.js +1 -0
  24. package/dist/node/plugins/webpack-R2U2DLlY.js +35 -0
  25. package/dist/node/plugins/webpack-loader.cjs +21 -0
  26. package/dist/node/plugins/webpack-loader.js +18 -0
  27. package/dist/node/plugins/webpack.js +1 -0
  28. package/dist/node/shared/endpoint.js +26 -0
  29. package/dist/node/shared/format.js +63 -0
  30. package/dist/node/types/astro.d.ts +11 -0
  31. package/dist/node/types/next.d.ts +34 -0
  32. package/dist/node/types/options.d.ts +59 -0
  33. package/dist/node/types/vite.d.ts +11 -0
  34. package/dist/node/types/webpack-loader.d.ts +22 -0
  35. package/dist/node/types/webpack.d.ts +27 -0
  36. package/dist/npm/THIRD_PARTY_NOTICES.txt +6 -6
  37. package/dist/npm/chunks/AgentSend-DxRJIYiz.js +68 -0
  38. package/dist/npm/chunks/Checklist-CnlfeSbc.js +282 -0
  39. package/dist/npm/chunks/Composer-B1bBVszY.js +725 -0
  40. package/dist/npm/chunks/Guest-vvNPz8h-.js +267 -0
  41. package/dist/npm/chunks/MarkupEditor-VCOXh9d2.js +338 -0
  42. package/dist/npm/chunks/Panel-F37vIL1K.js +1206 -0
  43. package/dist/npm/chunks/Settings-BGoZS2iV.js +231 -0
  44. package/dist/npm/chunks/Shortcuts-B2OMvczr.js +62 -0
  45. package/dist/npm/chunks/StyleEditor-CJ_d8Huf.js +46 -0
  46. package/dist/npm/chunks/StylePanel-yQzHHlY7.js +199 -0
  47. package/dist/npm/chunks/TaskFields-fmy6_HtK.js +289 -0
  48. package/dist/npm/chunks/ThreadCard-D51slKST.js +1113 -0
  49. package/dist/npm/chunks/Viewer-BOBadqmC.js +111 -0
  50. package/dist/npm/chunks/{agent-BDMQtOzH.js → agent-C1OQzBAm.js} +9 -9
  51. package/dist/npm/chunks/{anchor-BsradQhn.js → anchor-BsQNVkHj.js} +108 -85
  52. package/dist/npm/chunks/{ar-8tPch6W4.js → ar-CAJ3XT8e.js} +69 -19
  53. package/dist/npm/chunks/card-bits-CAnzrqx3.js +53 -0
  54. package/dist/npm/chunks/{client-EFTWxHbJ.js → client-kNAo2TTG.js} +282 -290
  55. package/dist/npm/chunks/confetti-CkBdSu19.js +49 -0
  56. package/dist/npm/chunks/context-B8UAzve0.js +20 -0
  57. package/dist/npm/chunks/context-BuMl7A07.js +48 -0
  58. package/dist/npm/chunks/{de-C63897uD.js → de-Dl18G48t.js} +60 -18
  59. package/dist/npm/chunks/dialog-GO04oC3D.js +3 -0
  60. package/dist/npm/chunks/dpop-U48QIQd7.js +96 -0
  61. package/dist/npm/chunks/drafts-B0ctr1g9.js +21 -0
  62. package/dist/npm/chunks/{es-CI2bSpvB.js → es-Dxk79lS9.js} +60 -18
  63. package/dist/npm/chunks/extension-CKFpPWmi.js +62 -0
  64. package/dist/npm/chunks/{extension-BST6LH1q.js → extension-E81hWyiT.js} +20 -12
  65. package/dist/npm/chunks/files-DyD5BZgp.js +114 -0
  66. package/dist/npm/chunks/{fr-rsVe-Lqk.js → fr-8BebGKYD.js} +118 -76
  67. package/dist/npm/chunks/{hi-cvwbSaWP.js → hi-BIN6Yy_p.js} +61 -19
  68. package/dist/npm/chunks/{i18n-C4v0M-6z.js → i18n-DOBt8e9U.js} +91 -56
  69. package/dist/npm/chunks/identify-CN-3xzqL.js +106 -0
  70. package/dist/npm/chunks/{it-C8tnV0BF.js → it-Cr6EwpPQ.js} +79 -37
  71. package/dist/npm/chunks/{ja-BWxDfC2f.js → ja-Iy3s5aur.js} +58 -16
  72. package/dist/npm/chunks/late-words-B2bmZceJ.js +12 -0
  73. package/dist/npm/chunks/live-CelVeZfP.js +85 -0
  74. package/dist/npm/chunks/locale-D8Q4Q2Nt.js +26 -0
  75. package/dist/npm/chunks/{nl-DNQ6eCht.js → nl-B84WHqqe.js} +61 -19
  76. package/dist/npm/chunks/page-key-DepmJzC1.js +62 -0
  77. package/dist/npm/chunks/{pick-CLyOdjnD.js → pick-yTyqtxN0.js} +45 -44
  78. package/dist/npm/chunks/pkce-ChKGSW_4.js +8 -0
  79. package/dist/npm/chunks/placement-BF_HOUDD.js +74 -0
  80. package/dist/npm/chunks/privacy-BWUGlHw5.js +57 -0
  81. package/dist/npm/chunks/{pt-BR-CkG7vpU2.js → pt-BR-DOkdlfoe.js} +60 -18
  82. package/dist/npm/chunks/{realtime-DIo-Wth4.js → realtime-C79zF50C.js} +14 -12
  83. package/dist/npm/chunks/report-CrIqQZDI.js +44 -0
  84. package/dist/npm/chunks/show-BgVC8gWY.js +97 -0
  85. package/dist/npm/chunks/signin-Dd1rb2BP.js +75 -0
  86. package/dist/npm/chunks/{source-CS7C6wJA.js → source-pXVve2Cx.js} +1 -1
  87. package/dist/npm/chunks/src-BTMy4Gyc.js +208 -0
  88. package/dist/npm/chunks/start-DtVlpt7p.js +1878 -0
  89. package/dist/npm/chunks/states-sfTbjZz8.js +3 -0
  90. package/dist/npm/chunks/upload-MgPYqPyE.js +42 -0
  91. package/dist/npm/chunks/uploads-D49mywwz.js +1146 -0
  92. package/dist/npm/chunks/wrap-Bl0gbnFa.js +69 -0
  93. package/dist/npm/chunks/{zh-CN-BKuZOLBE.js → zh-CN-Z5fQCb7G.js} +59 -17
  94. package/dist/npm/element.js +58 -21
  95. package/dist/npm/headless.js +7 -3
  96. package/dist/npm/index.js +3 -3
  97. package/dist/npm/react.js +18 -11
  98. package/dist/npm/svelte.js +28 -12
  99. package/dist/npm/types/adapters/react.d.ts +4 -1
  100. package/dist/npm/types/adapters/svelte.d.ts +4 -1
  101. package/dist/npm/types/adapters/vue.d.ts +35 -2
  102. package/dist/npm/types/anchor/index.d.ts +19 -0
  103. package/dist/npm/types/capture/privacy.d.ts +14 -0
  104. package/dist/npm/types/core/api.d.ts +20 -1
  105. package/dist/npm/types/core/auth.d.ts +40 -21
  106. package/dist/npm/types/core/client.d.ts +60 -4
  107. package/dist/npm/types/core/page-key.d.ts +42 -0
  108. package/dist/npm/types/core/types.d.ts +87 -4
  109. package/dist/npm/types/element.d.ts +17 -7
  110. package/dist/npm/types/headless.d.ts +2 -1
  111. package/dist/npm/types/index.d.ts +16 -6
  112. package/dist/npm/vue.js +44 -9
  113. package/package.json +88 -14
  114. package/dist/npm/chunks/AgentSend-2JPDseOo.js +0 -63
  115. package/dist/npm/chunks/Checklist-BpDXQebo.js +0 -257
  116. package/dist/npm/chunks/Composer-CAyj-c8e.js +0 -677
  117. package/dist/npm/chunks/Guest-ZdFmTcXI.js +0 -187
  118. package/dist/npm/chunks/MarkupEditor-BFplZwFy.js +0 -332
  119. package/dist/npm/chunks/Panel-BhZ4XRDR.js +0 -861
  120. package/dist/npm/chunks/Settings-SPG9EHUZ.js +0 -204
  121. package/dist/npm/chunks/Shortcuts-C28HVDw6.js +0 -58
  122. package/dist/npm/chunks/StyleEditor-ByZMtq10.js +0 -43
  123. package/dist/npm/chunks/StylePanel-Iwhce2tE.js +0 -197
  124. package/dist/npm/chunks/TaskFields-BsP_fVJg.js +0 -273
  125. package/dist/npm/chunks/ThreadCard-BzVZdDCb.js +0 -1030
  126. package/dist/npm/chunks/Viewer-CqtGrdD8.js +0 -108
  127. package/dist/npm/chunks/card-bits-Bna-g3Py.js +0 -124
  128. package/dist/npm/chunks/confetti-DTKpwF3O.js +0 -40
  129. package/dist/npm/chunks/drafts-akdBsOd0.js +0 -50
  130. package/dist/npm/chunks/extension-D-V3utTm.js +0 -53
  131. package/dist/npm/chunks/live-BCpJVBeN.js +0 -33
  132. package/dist/npm/chunks/report-BBrT3r89.js +0 -27
  133. package/dist/npm/chunks/src-C4FsVoUp.js +0 -148
  134. package/dist/npm/chunks/start-i9M-r3aH.js +0 -1800
  135. package/dist/npm/chunks/upload-DSv7EyBD.js +0 -41
  136. package/dist/npm/chunks/uploads-I01kdqQF.js +0 -1103
package/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # CommentKit
2
2
 
3
- Figma-style comments for any website.
3
+ Figma-style comments on any website. Your clients click the part of the page they mean, write what should change, and CommentKit pins the comment there with a screenshot of what they saw.
4
4
 
5
- Your clients click the part of the page they mean and write what should change. CommentKit pins the comment to that exact spot, attaches a screenshot of what they saw, and records the page, browser and screen size. You see the feedback on your live site, your staging and preview links, and on `localhost` — and you can hand it straight to your AI coding agent.
5
+ You see the feedback on your live site, your staging and preview links and on `localhost`, and you can hand it to your AI coding agent.
6
6
 
7
- - **One install, every stack.** A script tag works on any website (WordPress, Webflow, Shopify, plain HTML). npm users get `init()` plus tiny React, Vue and Svelte helpers. Nothing else to install: no React required on your side.
8
- - **Built for people who have never used a feedback tool.** Clients open a client link, click, type, confirm their email once. No account, no password.
9
- - **Built for developers.** Feedback per branch and environment, element selectors and source locations, console errors, a dashboard with list and board views, email notifications, and an MCP server for Claude Code, Cursor and other agents.
7
+ This package, `@commentkit/comment-kit`, holds the browser SDK, the build plugins and the `commentkit` command. It has no runtime dependencies.
10
8
 
11
- ## Install
9
+ ## Install in 60 seconds
12
10
 
13
- ### Any website
11
+ Find your project key in CommentKit under **Project → Setup**, and add every address the site runs on there (live, staging, previews). A wildcard such as `https://*.preview.example.com` covers one level of subdomains (`pr-1.preview.example.com`, not `a.b.preview.example.com`); shared hosts such as `vercel.app` take the exact address instead (or `https://*--yoursite.netlify.app` for one Netlify site's previews). `localhost` always works for your team.
12
+
13
+ ### Any website: the script tag
14
14
 
15
15
  Paste before `</body>`:
16
16
 
@@ -18,28 +18,43 @@ Paste before `</body>`:
18
18
  <script src="https://commentkit.dev/cdn/v1/loader.js" data-project="pk_live_your_key" defer></script>
19
19
  ```
20
20
 
21
- ### npm
21
+ That is all for WordPress, Webflow, Shopify, plain HTML and server-rendered apps. Tag managers that drop `data-*` attributes can use `loader.js?project=pk_live_your_key` instead.
22
+
23
+ ### npm, with the setup command
22
24
 
23
25
  ```bash
24
26
  npm install @commentkit/comment-kit
27
+ npx @commentkit/comment-kit init
25
28
  ```
26
29
 
30
+ `init` finds your framework (Next.js, Vite, SvelteKit, React Router, Remix, Astro, Nuxt or a plain website) and shows each change before it makes it: the key in your env file, the build plugin in your config, `.commentkit/` in `.gitignore` and the widget in your layout or entry file. Without signing in, pass the key: `npx @commentkit/comment-kit init --key pk_live_your_key`. The full package name works before and after the package is installed.
31
+
32
+ Or call `init()` yourself, once, in browser code:
33
+
27
34
  ```ts
28
35
  import { init } from "@commentkit/comment-kit";
29
36
 
30
37
  init({ project: "pk_live_your_key" });
31
38
  ```
32
39
 
33
- ### React / Next.js
40
+ The package installs on Node 18 or newer. The `commentkit` command needs Node 20 or newer, and the build plugins' source locations need Node 22.18+ or 24.11+; each says so in one line on an older Node.
41
+
42
+ ## Frameworks
43
+
44
+ Every helper below calls the same `init()` and takes the same options (see [Options](#options)). Each one renders nothing itself and never throws into your app.
45
+
46
+ ### React and Next.js
34
47
 
35
48
  ```tsx
36
49
  import { CommentKit } from "@commentkit/comment-kit/react";
37
50
 
38
51
  // Root layout, next to {children}. Works in Next.js server layouts.
39
- <CommentKit project="pk_live_your_key" branch={process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF} />
52
+ <CommentKit project="pk_live_your_key" />
40
53
  ```
41
54
 
42
- ### Vue / Nuxt
55
+ Options are read when it mounts. A change to `project`, `branch`, `commit`, `endpoint`, `privacy` or `toggleShortcut` restarts the widget; a new `identity` token signs that person in without a restart.
56
+
57
+ ### Vue and Nuxt
43
58
 
44
59
  ```ts
45
60
  import { CommentKitPlugin } from "@commentkit/comment-kit/vue";
@@ -47,19 +62,21 @@ import { CommentKitPlugin } from "@commentkit/comment-kit/vue";
47
62
  app.use(CommentKitPlugin, { project: "pk_live_your_key" });
48
63
  ```
49
64
 
65
+ Or place `<CommentKit project="pk_live_your_key" />` from `@commentkit/comment-kit/vue` once in your root component. Its props are the options. A change to `project`, `branch`, `commit`, `endpoint`, `privacy` or `toggleShortcut` restarts the widget; a new `identity` token signs that person in without a restart.
66
+
50
67
  Nuxt: create `plugins/commentkit.client.ts`:
51
68
 
52
69
  ```ts
53
- import { CommentKitPlugin } from "@commentkit/comment-kit/vue";
70
+ import { init } from "@commentkit/comment-kit";
54
71
 
55
- export default defineNuxtPlugin((nuxtApp) => {
56
- nuxtApp.vueApp.use(CommentKitPlugin, { project: useRuntimeConfig().public.commentkitKey });
72
+ export default defineNuxtPlugin(() => {
73
+ init({ project: useRuntimeConfig().public.commentkitKey });
57
74
  });
58
75
  ```
59
76
 
60
- Or place `<CommentKit project="pk_live_your_key" />` from `@commentkit/comment-kit/vue` once in your root component; it accepts every option below as a prop.
77
+ and add `runtimeConfig: { public: { commentkitKey: "" } }` to `nuxt.config.ts` (set it with `NUXT_PUBLIC_COMMENTKIT_KEY`).
61
78
 
62
- ### Svelte / SvelteKit
79
+ ### Svelte and SvelteKit
63
80
 
64
81
  ```svelte
65
82
  <!-- src/routes/+layout.svelte -->
@@ -72,9 +89,11 @@ Or place `<CommentKit project="pk_live_your_key" />` from `@commentkit/comment-k
72
89
  {@render children()}
73
90
  ```
74
91
 
75
- ### Anything else
92
+ A change to `project`, `branch`, `commit`, `endpoint`, `privacy` or `toggleShortcut` restarts the widget.
76
93
 
77
- Angular, Solid, Astro, Qwik, Remix, or a custom setup: call `init()` once in the browser. If you prefer markup, import the custom element once in your bundle and place the tag anywhere:
94
+ ### Custom element (Angular, Solid, Astro, Qwik, anything else)
95
+
96
+ Import it once in your bundle, then place the tag anywhere:
78
97
 
79
98
  ```ts
80
99
  import "@commentkit/comment-kit/element";
@@ -84,208 +103,369 @@ import "@commentkit/comment-kit/element";
84
103
  <comment-kit project="pk_live_your_key" branch="main"></comment-kit>
85
104
  ```
86
105
 
87
- Attributes: `project` (required), `branch`, `commit`, `locale`, `theme`, `position`, `auth`, `endpoint`, `deployment-url`, `hide-on-production="false"`, `shortcuts="false"`. Changing `project` restarts the widget.
106
+ A change to any attribute restarts the widget with the new settings. You can also call `init()` once in browser code instead.
88
107
 
89
- Find your key in the dashboard under **Project → Setup** (or run `npx @commentkit/cli login` and then `npx @commentkit/cli init`, or `npx @commentkit/cli init --key pk_live_…` without signing in), and add every website address there (live, staging, preview, e.g. `https://*.vercel.app`). Localhost always works for your team.
108
+ ### Headless
90
109
 
91
- ## How it behaves
110
+ `@commentkit/comment-kit/headless` exports `CommentKitClient`, `createAnchor`, `resolveAnchor`, `stableSelector`, `pageKey`, `configurePrivacy`, `ApiClient` and `AuthManager` for your own interface. It adds nothing to the page.
92
111
 
93
- | Where | Who sees the widget |
94
- | --- | --- |
95
- | `localhost`, `*.localhost`, `*.test` | Always visible, for your team |
96
- | Live, staging and preview sites | Hidden from visitors. Shown when someone opens a client link (`?ck=…`), an email link, presses **Cmd/Ctrl + Shift + K**, or is already signed in on that device |
112
+ ## Options
97
113
 
98
- People leave feedback with one tool:
114
+ One table for every way in. `init()` and the React, Vue and Svelte helpers take the option names as written. The script tag and the custom element take the attributes shown; "—" means that way in does not offer it.
115
+
116
+ | Option | Type | Default | What it does | Script tag | `<comment-kit>` |
117
+ | --- | --- | --- | --- | --- | --- |
118
+ | `project` | `string` | required | Your publishable key, `pk_live_…` or `pk_test_…`. | `data-project` | `project` |
119
+ | `branch` | `string \| null` | from the build plugin, else none | The branch this build is from, so feedback can be filtered per branch. | `data-branch` | `branch` |
120
+ | `commit` | `string \| null` | from the build plugin, else none | The commit this build is from. | `data-commit` | `commit` |
121
+ | `deploymentUrl` | `string \| null` | none | The preview deployment's address, stored with new feedback. | — | `deployment-url` |
122
+ | `endpoint` | `string` | `https://commentkit.dev` | Another CommentKit server (staging, self-hosting). | `data-endpoint` | `endpoint` |
123
+ | `hideOnProduction` | `boolean` | `true` | `false` shows the widget to every visitor, not only to people who bring a reason (see [What CommentKit does to your page](#what-commentkit-does-to-your-page)). | `data-hide-on-production="false"` | `hide-on-production="false"` |
124
+ | `theme` | `"auto" \| "light" \| "dark"` | the dashboard setting | Colour scheme. A reader's own choice in Settings wins. | — | `theme` |
125
+ | `position` | `"bottom-right" \| "bottom-left" \| "top-right" \| "top-left"` | the dashboard setting | Where the widget starts. Readers can drag it. | — | `position` |
126
+ | `privacy` | `"standard" \| "strict"` | `"standard"` | `"strict"` also leaves every form field's value and every editable region out of screenshots (see [Privacy](#privacy)). | `data-privacy="strict"` | `privacy="strict"` |
127
+ | `redact` | `string[]` | none | CSS selectors whose content never appears in screenshots or in the text a comment keeps to find its spot. Added to the dashboard's privacy selectors. | `data-redact=".a, #b"` (one selector list) | `redact=".a, #b"` |
128
+ | `locale` | `string` | `<html lang>`, then the browser | Widget language, for example `"fr"` or `"pt-BR"` (see [Languages](#languages)). | `data-locale` | `locale` |
129
+ | `auth` | `"auto" \| "popup" \| "redirect"` | `"auto"` | How sign-in opens: a popup, or a same-tab redirect in in-app browsers and when popups are blocked. | `data-auth` | `auth` |
130
+ | `shortcuts` | `boolean` | `true` | Allows single-key shortcuts while the widget is shown: C comment, J / K next or previous, E resolve, ? list. They start on for team members and off for clients, and each reader can switch them in Settings. `false` turns them off for everyone, for example when your app uses those keys. Esc and Cmd/Ctrl+Shift+K keep working. | `data-shortcuts="false"` | `shortcuts="false"` |
131
+ | `toggleShortcut` | `boolean` | `true` | Cmd/Ctrl+Shift+K shows the widget, and while it is shown opens the inbox. Set `false` if your site uses that combination; show the widget with `show()` or `comment()` instead. | `data-toggle-shortcut="false"` | `toggle-shortcut="false"` |
132
+ | `tools` | `{ screenshots?, markup?, text?, attachments?, style?, checklist? }` (booleans) | all on | Turn parts of the comment tools off. `text: false` stops selected text becoming a quoted comment. `style` (suggested CSS changes) and `checklist` are only offered to team members who can triage. Screenshots also follow the dashboard setting. | — | `tools-off="style checklist"` (space-separated names) |
133
+ | `identity` | `string \| () => string \| Promise<string>` | none | Signs the reviewer in from your website's own login (see [Sign reviewers in from your own login](#sign-reviewers-in-from-your-own-login)). | `window.CommentKit = { identity }` before the tag | — (call `element.identify(token)`) |
134
+
135
+ Settings that apply without a deploy live in the dashboard: pausing feedback, theme, position, accent colour, privacy selectors, and console and network capture.
136
+
137
+ ### Methods and events
138
+
139
+ `init()` returns a handle. Every method is safe to call at any time: none throws, and the promises never reject.
99
140
 
100
- - **Click** an element to comment on it.
101
- - **Drag** to mark an area.
102
- - **Select text first** to comment on exactly that text.
141
+ ```ts
142
+ const kit = init({ project: "pk_live_your_key" });
103
143
 
104
- A screenshot of the visible page is attached automatically with the pin drawn on it. Reviewers can draw on it (arrow, box, pen, blur to hide private details, text). Passwords, card fields, one-time codes and anything marked `data-commentkit-redact` are never captured.
144
+ kit.show(); // show the widget (same as Cmd/Ctrl+Shift+K)
145
+ kit.hide(); // hide it; feedback stays on the server
146
+ kit.open("CK-12"); // show the widget and open one conversation (id or reference)
147
+ kit.comment(); // start comment mode from your own "Leave feedback" button; comment(false) stops it
148
+ await kit.signIn(); // open the sign-in window; call from a click. Resolves false when not signed in
149
+ await kit.identify(token); // sign in your site's user (see below). Resolves false when the token is refused
150
+ await kit.signOut(); // sign the reviewer out of CommentKit on this browser, for example on your own logout
151
+ kit.session(); // { person, role, project, environment, capabilities } | null
152
+ const off = kit.on("thread:created", ({ thread }) => console.log(thread.reference));
153
+ kit.destroy(); // release this handle; the last one removes the widget
154
+ ```
105
155
 
106
- Sign-in opens a small CommentKit window (or continues in the same tab inside in-app browsers like WhatsApp and Instagram). Credentials never touch your page.
156
+ `init()` can be called more than once: each call returns its own handle onto the same widget, which stays until the last handle is destroyed. A second copy of the SDK on the same page (npm and the script tag together) stays off and says so in the console.
107
157
 
108
- ## Options
158
+ Events: `ready`, `session:change`, `thread:created`, `thread:updated`, `message:created`, `mode` (`{ commenting }`, when comment mode starts or stops) and `error` (`{ error }`, a `CommentKitError` whose `code` is explained at `https://commentkit.dev/docs/errors#<code>`).
109
159
 
110
- ```ts
111
- init({
112
- project: "pk_live_…", // required
113
- branch: "feature/checkout", // filter feedback per branch
114
- commit: "a1b2c3d",
115
- deploymentUrl: "https://pr-12.example.vercel.app",
116
- hideOnProduction: true, // default; false shows the launcher to everyone
117
- theme: "auto", // "light" | "dark" — default from the dashboard
118
- position: "bottom-right",
119
- redact: [".customer-email"], // extra selectors never captured
120
- locale: "fr", // default: <html lang>, then the browser (see Languages)
121
- auth: "auto", // "popup" | "redirect"
122
- shortcuts: true, // false turns off C, J / K, E and ? (Esc and Cmd/Ctrl+Shift+K stay)
123
- tools: { screenshots: true, markup: true, text: true, attachments: true }, // turn parts of the comment tools off
124
- });
160
+ ### Script tag API: `window.CommentKit`
161
+
162
+ Once the widget is shown, the loader sets `window.CommentKit`:
163
+
164
+ ```js
165
+ CommentKit.version; // the SDK version
166
+ CommentKit.show(); // Promise
167
+ CommentKit.hide();
168
+ CommentKit.open("CK-12"); // or a thread id
169
+ CommentKit.comment(); // Promise; comment(false) stops comment mode
170
+ CommentKit.identify(token); // Promise<boolean>
171
+ CommentKit.signOut(); // Promise; for example when someone logs out of your site
172
+ const onNew = ({ thread }) => console.log(thread.reference);
173
+ CommentKit.on("thread:created", onNew);
174
+ CommentKit.off("thread:created", onNew);
175
+ CommentKit.destroy(); // removes the widget, its listeners and window.CommentKit
125
176
  ```
126
177
 
127
- Most behaviour is set in the dashboard and applies instantly without a deploy: pausing feedback on all sites, theme, position, accent colour, privacy selectors, and console/network capture.
178
+ It exists only while the widget is shown on that page, so check first: `window.CommentKit?.open("CK-12")`.
128
179
 
129
- ### Script-tag attributes
180
+ ### Languages
130
181
 
131
- `data-project` (required), `data-branch`, `data-commit`, `data-locale`, `data-auth`, `data-endpoint` (another CommentKit server), `data-hide-on-production="false"`, `data-shortcuts="false"`. `theme`, `position`, `redact` and `deploymentUrl` are `init()` options; theme, position and privacy selectors can also be set in the dashboard.
182
+ The widget speaks English, Spanish (`es`), French (`fr`), German (`de`), Portuguese for Brazil (`pt-BR`), Italian (`it`), Dutch (`nl`), Japanese (`ja`), Simplified Chinese (`zh-CN`), Hindi (`hi`) and Arabic (`ar`, right to left).
132
183
 
133
- ## Languages
184
+ It uses the first match from `locale`, the page's `<html lang>`, then the reader's browser languages, and falls back to English. Regions fall back to the language: `es-MX` gets Spanish, `pt` and `pt-PT` get Brazilian Portuguese, `zh` gets Simplified Chinese. English is built in; each other language is a separate file of 6.7 to 8 KB (gzip), loaded only for readers who need it. Only the widget is translated; the dashboard and emails are in English.
134
185
 
135
- The widget speaks English, Spanish (`es`), French (`fr`), German (`de`), Portuguese for Brazil (`pt-BR`), Italian (`it`), Dutch (`nl`), Japanese (`ja`), Chinese, Simplified (`zh-CN`), Hindi (`hi`) and Arabic (`ar`, right to left).
186
+ ## What CommentKit does to your page
136
187
 
137
- It picks the first match from `init({ locale })` (or `data-locale` / `<comment-kit locale>`), then the page's `<html lang>`, then the reader's browser languages, and falls back to English. Regions fall back to the language: `es-MX` gets Spanish, `pt` and `pt-PT` get Brazilian Portuguese, `zh` gets Simplified Chinese. Times ("5 minutes ago") and counts use the browser's `Intl` formatting for that language.
188
+ Read this before you add CommentKit to a client's production site.
138
189
 
139
- English is built in. Each other language is a separate ~2.5–3 KB (gzip) file, loaded only for readers who need it, while the widget starts. The widget is right to left when its language is Arabic, and otherwise follows the page's `dir` or `<html lang>`.
190
+ **What loads, and when.** Sizes are gzip, from the build of this version.
140
191
 
141
- Only the widget is translated; the dashboard and emails are in English for now.
192
+ | Install | On every page | When the widget shows | Only when needed |
193
+ | --- | --- | --- | --- |
194
+ | Script tag | `loader.js`, 1.5 KB. It decides whether to show and makes no request otherwise. | The widget, about 54.5 KB (entry 11.0 KB + interface 43.5 KB). On the `/cdn/v1/` channel the loader first asks CommentKit which version to load (at most 1.5 s, then the stable one). | Screenshot engine, about 70 KB, while commenting. Live updates, about 21 KB, for signed-in people. Each language other than English, 6.7 to 8 KB. |
195
+ | npm | `init()`, 10.5 KB in your bundle. No request until the widget shows. | The interface, 44.0 KB, as lazy chunks of your own bundle. | The same as above. |
142
196
 
143
- ## API
197
+ **Hidden on production until someone brings a reason.** On `localhost`, `127.0.0.1`, `[::1]`, `*.localhost` and `*.test` the widget shows for your team. Everywhere else it stays hidden, and nothing beyond the loader (or `init()`) runs, until one of these is true:
144
198
 
145
- `init()` returns an instance:
199
+ - the visitor opened a share link (`?ck=…`) or a link from a CommentKit email (`?ck_thread=…`, `#ck_signin=…`, or the code email's "Send my comment" button, `#ck_code=…`);
200
+ - they are already signed in to CommentKit for this project on this browser;
201
+ - your page passes an `identity` (your site's own signed-in user);
202
+ - the CommentKit browser extension turned comments on for this tab;
203
+ - they pressed Cmd/Ctrl+Shift+K. This is remembered on that browser (`commentkit:active` in `localStorage`) once the widget has shown.
146
204
 
147
- ```ts
148
- const kit = init({ project: "pk_live_…" });
205
+ Turn the shortcut off with `toggleShortcut: false` (`data-toggle-shortcut="false"`, `toggle-shortcut="false"`). While the widget is hidden, the key also reaches your page's own handlers; only a shown widget keeps it. `hideOnProduction: false` shows the widget to every visitor. If the widget crashes three times in a row on a browser, it stays hidden there for six hours unless a link, the shortcut or `show()` brings it back.
149
206
 
150
- kit.show(); // bring a hidden widget back (Cmd/Ctrl + Shift + K does too)
151
- kit.hide();
152
- kit.open("CK-12"); // show the widget and open one conversation (id or reference)
153
- kit.comment(); // start comment mode from your own "Leave feedback" button; comment(false) stops it
154
- await kit.signIn(); // call from a click
155
- await kit.signOut();
156
- kit.session(); // { person, role, project, environment, capabilities } | null
157
- kit.on("thread:created", ({ thread }) => {});
158
- kit.destroy(); // removes every trace from the page
159
- ```
207
+ **What it adds to the page.**
160
208
 
161
- Events: `ready`, `session:change`, `thread:created`, `thread:updated`, `message:created`, `mode` (`{ commenting }`, when comment mode starts or stops), and `error` (the widget could not start; `error.code` is listed at https://commentkit.dev/docs/errors).
209
+ - One element, `<div data-commentkit-host>`, appended to `<html>` (not `<body>`, which some frameworks replace), with the widget inside an open Shadow DOM. Its styles are constructable stylesheets inside that shadow root; no CSS reaches your page. From the script tag it joins the page after the `load` event, when the browser is idle.
210
+ - The script tag adds one global, `window.CommentKit`, while the widget is shown, and marks `<html data-commentkit-loader>` so that Turbo, Livewire and htmx page changes do not start it twice. npm installs add no global.
211
+ - A `keydown` listener for Cmd/Ctrl+Shift+K (unless `toggleShortcut` is `false`).
212
+ - Only when the project turns console or network capture on, and only while the widget is shown: wrappers around `console.error`, `console.warn`, `fetch` and `XMLHttpRequest`, and `error` and `unhandledrejection` listeners. They record metadata only (see [Privacy](#privacy)).
213
+ - No cookies. One IndexedDB database, `commentkit` (store `keys`), holding one record per project key: the browser's sign-in key for that website (`{ pair }`, an ECDSA P-256 key pair whose private key cannot be read out, see [Sessions are bound to this browser](#sessions-are-bound-to-this-browser)). It is made at the first sign-in and deleted at sign-out. `localStorage` and `sessionStorage` keys, all starting `commentkit:`: the sign-in (`commentkit:v1:<project key>`, a rotating refresh token that only works together with that key; in `sessionStorage` when the project turns "keep reviewers signed in" off, and not stored at all where IndexedDB is unavailable), unsent drafts (`commentkit:draft:v2:…`, hashed keys, deleted after 7 days), the reader's preferences (`commentkit:v1:prefs`, `commentkit:theme`, `commentkit:dock`, `commentkit:welcomed`, `commentkit:agent`, `commentkit:dblclick-hint`), activation and the crash guard (`commentkit:active`, `commentkit:crashes`), and short-lived sign-in and hand-off state (`commentkit:pkce:<key>`, `commentkit:share`, `commentkit:pending-*`, `commentkit:guest-details`, `commentkit:confetti`, and `commentkit:lock:*` in browsers without Web Locks).
162
214
 
163
- While the widget is shown, **Cmd/Ctrl + Shift + K** opens or closes the inbox. People hide the widget from its **More** menu (Hide CommentKit), and the same keys bring it back.
215
+ **Sessions are bound to this browser.** Every widget session (and a guest's comment waiting for its code) only works together with a key that cannot leave the browser (DPoP, RFC 9449). At the first sign-in the widget makes a non-extractable ECDSA P-256 key for this website and keeps it in IndexedDB, so every tab of the site shares it, and every request that starts, renews or uses the session carries a fresh proof signed with it (`Authorization: DPoP` and a `DPoP` header). Where IndexedDB is unavailable (some private windows, blocked storage, sandboxed frames) the key stays in memory: the session then ends when the page closes, and its refresh token is not stored either. Pages where nobody is signed in never load this code.
164
216
 
165
- ### Script tag API: `window.CommentKit`
217
+ - What it protects against: a token copied out of the page (by a script, an extension, a log, a stolen backup of the browser's storage) is useless anywhere else, and useless after the tab is closed, because it cannot be used without the key. A refresh token presented with another key, or with none, ends the whole session.
218
+ - What it does not: a script running on your page while the tab is open can still ask the widget's code to act for the signed-in reviewer, as it always could (see [SECURITY.md](SECURITY.md#trust-model)).
219
+ - Signing out deletes the key with the session; the next sign-in makes a new one. If someone clears the website's data, the key is gone and the widget asks them to sign in again.
220
+ - A device clock that is off is corrected from the server's `Date` header when the browser can read it; when the API asks for a nonce, the widget signs again with it. Agent tokens (CLI, MCP, CI) and the browser extension's own sign-in stay plain bearer tokens.
166
221
 
167
- On sites that use the script-tag loader, the loader sets one global once the widget is ready, `window.CommentKit`, and `destroy()` removes it again. It is the only global CommentKit adds; npm installs use the `init()` instance instead.
222
+ **It never throws into your page.** `init()`, every method and every helper catch their own errors. A blocked download, a setup problem or a crash inside the widget logs one console warning starting `[CommentKit]` and the widget removes itself. Crashes of the widget itself (never your page's errors) are reported to CommentKit with the SDK version, the message and a stack with query strings removed, at most three per page.
168
223
 
169
- ```js
170
- CommentKit.version; // "1.0.0"
171
- CommentKit.show(); // Promise
172
- CommentKit.hide();
173
- CommentKit.open("CK-12"); // or a thread id
174
- CommentKit.comment(); // start comment mode (Promise); comment(false) stops it
175
- const onNew = ({ thread }) => console.log(thread.reference);
176
- CommentKit.on("thread:created", onNew);
177
- CommentKit.off("thread:created", onNew);
178
- CommentKit.destroy(); // removes the widget, its listeners and window.CommentKit
224
+ **Kill switches.**
225
+
226
+ - Pausing feedback for a project in the dashboard hides the widget on open pages within about a minute (the widget reads its settings again every minute while the tab is visible). Visitors who came from a link see a short note instead of nothing.
227
+ - CommentKit can switch off a broken SDK version remotely. That version then stays silent (no widget, no warnings) and checks again every minute. New `/cdn/v1/` versions roll out to a share of projects first; the widget reports its own crashes per version, so a release that breaks is rolled back.
228
+
229
+ **Content Security Policy.** No `unsafe-eval` and no `unsafe-inline` are needed. Allow:
230
+
231
+ - `script-src https://commentkit.dev`, for the script tag only (with npm the code is in your bundle);
232
+ - `connect-src https://commentkit.dev`, the storage host that screenshots and attachments upload to, and, when live updates are on, the realtime `wss://` host;
233
+ - `img-src https://commentkit.dev blob:` (emoji, screenshots and the screenshot preview before upload), and the storage host for screenshot thumbnails. Profile pictures come from the person's sign-in provider; without that host, initials are shown.
234
+
235
+ The exact hosts for your project are listed at `https://commentkit.dev/docs/csp`. `npx @commentkit/comment-kit doctor https://your-site.com` reads your page's policy and says what to add (see [Troubleshooting](#troubleshooting)).
236
+
237
+ **Trusted Types.** The widget works under `require-trusted-types-for 'script'`. The screenshot engine writes two fixed strings through one policy, `commentkit-capture`, that accepts nothing else; no default policy is created. If your CSP lists allowed policy names with `trusted-types`, add `commentkit-capture`; without it screenshots fail and everything else works.
238
+
239
+ **Server rendering.** `init()` does nothing when there is no `window`, and importing `@commentkit/comment-kit`, `/element` or the helpers on the server is safe. The build plugins (`/vite`, `/next`, `/webpack`, `/astro`) are for your build config only: imported into browser code they fail with one error that says so.
240
+
241
+ **Printing.** The widget is hidden when the page is printed.
242
+
243
+ **Removing it.** `kit.destroy()` (the last handle), or `window.CommentKit.destroy()` for the script tag, removes the element, the listeners, the wrappers and the global. Signing out, from your code with `signOut()`, from the widget's Settings or in another tab, ends the session and removes that person's drafts on this device.
244
+
245
+ **No automatic updates.** `/cdn/v1/loader.js` always loads the latest 1.x release. To pin one version, use its folder and its Subresource Integrity hash from `https://commentkit.dev/cdn/integrity.json` (keyed by version, then file):
246
+
247
+ ```html
248
+ <script src="https://commentkit.dev/cdn/1.6.0/loader.js" integrity="sha384-…" crossorigin="anonymous" data-project="pk_live_your_key" defer></script>
179
249
  ```
180
250
 
181
- `window.CommentKit` only exists while the widget is shown on that page (local development, a share or email link, a signed-in person, or after Cmd/Ctrl + Shift + K). Check for it before calling: `window.CommentKit?.open("CK-12")`.
251
+ A pinned loader never switches version and loads the rest of the widget from the same folder, which never changes after it is published. The browser checks the hash of `loader.js` itself; the files the loader then imports (`commentkit.js` and its chunks) are not covered by that hash, because browsers do not apply a preloaded integrity hash to a later dynamic import (see [SECURITY.md](SECURITY.md#trust-model)). If you need every byte checked, install from npm and bundle it. A pinned version gets no fixes: move to a newer one on purpose. With npm, pin an exact version (`npm install --save-exact`) and commit your lockfile.
182
252
 
183
- Nothing CommentKit does can break your page: a failed download, a setup error or a crash inside the widget logs one console warning and the widget removes itself.
253
+ ## Privacy
184
254
 
185
- `@commentkit/comment-kit/headless` exports `CommentKitClient`, `createAnchor` and `resolveAnchor` for custom interfaces and browser extensions.
255
+ **What leaves the browser, and when.** Nothing, until the widget shows. Then:
186
256
 
187
- ## AI agents
257
+ | What | When |
258
+ | --- | --- |
259
+ | The widget's settings request (project key, the page's origin, the SDK version) | When the widget is about to show |
260
+ | The comment's text, its spot on the page (selectors, source location, a short text fingerprint of the element and its neighbours, the selected text for a text comment), the page address and title, branch and commit | When a comment is sent |
261
+ | A screenshot of the visible part of the page (not the whole page), with the pin drawn on it and any drawing the reviewer added | When a comment is sent, unless the reviewer removed it or screenshots are turned off |
262
+ | Device details: browser and version, operating system, device type, viewport size, pixel ratio, zoom, language, colour scheme, user agent | When a comment is sent |
263
+ | Recent console errors and warnings, and failed requests (method, address, status, timing) | Only when the project turns console or network capture on, and the reviewer leaves "Include browser errors" ticked for that comment |
264
+ | Files the reviewer attaches | When the comment is sent. Your CommentKit workspace may limit attachments to images; the paperclip then offers and accepts only those. |
188
265
 
189
- The easiest way: add `https://commentkit.dev/mcp` as a remote MCP server in Claude, Cursor or VS Code and sign in. You choose the project and what the agent may do.
266
+ **Masked by default.** Screenshots leave out password, hidden, email and phone inputs; any field whose `autocomplete` says it is a password, one-time code, payment, contact (email, phone, address, postal code) or identity (name, username, birthday, organisation) field; every iframe; the widget itself; and anything matching `data-commentkit-redact`, your `redact` selectors or the dashboard's privacy selectors. The text a comment keeps to find its spot never comes from those elements and never contains what anyone typed into a form field.
190
267
 
191
- ```sh
192
- claude mcp add --transport http commentkit https://commentkit.dev/mcp
268
+ **`privacy: "strict"`** also leaves every form field's value (`input`, `textarea`, `select`) and every editable region (`contenteditable`) out of screenshots. The website's settings in CommentKit can turn this on for everyone ("Hide everything people type in screenshots"): the widget then uses strict mode whatever `init()` says. The stricter of the two always wins; `privacy: "standard"` never turns the dashboard's setting off.
269
+
270
+ **Mark private parts of your page** with the attribute, or list selectors:
271
+
272
+ ```html
273
+ <div data-commentkit-redact>Account number: 1234 5678</div>
193
274
  ```
194
275
 
195
- Or run the server on your computer: create an agent token in **Project → Connect**, then add it to your agent:
196
-
197
- ```json
198
- {
199
- "mcpServers": {
200
- "commentkit": {
201
- "command": "npx",
202
- "args": ["-y", "comment-kit-mcp"],
203
- "env": { "COMMENTKIT_PROJECT_ID": "123", "COMMENTKIT_TOKEN": "…" }
204
- }
205
- }
206
- }
276
+ ```ts
277
+ init({ project: "pk_live_your_key", redact: [".customer-email", "#account-number"] });
207
278
  ```
208
279
 
209
- **Send to agent from the inbox.** Team members choose comments in the inbox (all shown ones start ticked, so the page, branch and filters decide what goes) and send them in one prompt. **Open in Cursor**, **Open in Claude Code** and **Open in Codex** open the agent with the prompt filled in, never sent until you press Enter. The full prompt is always copied to the clipboard as well, for other agents and when a batch is too long for a link (then the link carries a shorter version). With the MCP server connected, `/fix_feedback` does the same from inside the agent.
280
+ Both apply to screenshots and to the text a pin keeps. Reviewers can also blur parts of the screenshot before sending.
210
281
 
211
- Agents can list, search and read feedback and dashboard tasks (including the screenshot, by id or `CK-12`). With the permissions you choose, they can reply, link the commit and mark a task **ready for review**; by default a person approves each of these first (Agent requests). The reviewer then checks and resolves it. Agents never resolve, assign or delete. See [`mcp/README.md`](mcp/README.md).
282
+ **Console and network capture** keep only metadata: message and level, or method, address, status and timing. Never request or response bodies or headers. Credential-like query values are removed by name and by value, and email addresses and long numbers are masked in messages.
212
283
 
213
- ## Terminal and build tools
284
+ **Guests** (people who came from a share link) see, before they send: "Your name, email, comments, the screenshot and basic browser details go to the team that runs this website, and to CommentKit, which runs this comment tool for them", with a link to CommentKit's privacy notice and, when the website's settings in CommentKit give one, a link to the website's own privacy notice next to it. Their first comment is published once they enter the 6-digit code sent to their email, in the same browser tab they asked for it from (the code is tied to that tab, so reloading the page is fine; another browser is not). The email also has a **Send my comment** button, for a guest who closed the tab: it opens the page with `#ck_code=…`, the widget takes that off the address at once and asks "Send your comment?", and only that click publishes the comment (so a mail scanner that opens links never does). It works once, for 10 minutes, on the website the comment was left on, in any browser.
214
285
 
215
- - [`@commentkit/cli`](cli/README.md): `commentkit login` (a short code confirmed in the browser), `init` (adds the key, the build plugin and `.gitignore` entry), `pull` (open feedback to `.commentkit/feedback.md` for any agent), `open CK-12`, and tokens for CI.
216
- - [`@commentkit/build`](build/README.md): Vite, Next.js, webpack and Astro plugins that tag elements with their source file and line in development, and record the branch and commit. On localhost the widget then shows this branch's feedback first, with "All branches" one click away.
286
+ **Drafts** of unsent comments stay on the device for 7 days. They belong to the person who wrote them: another person signing in on the same browser does not see them, and signing out from the widget removes them.
217
287
 
218
- ## Privacy and security
288
+ See [SECURITY.md](SECURITY.md) for the trust model and how to report a vulnerability.
219
289
 
220
- - The project key (`pk_…`) only identifies a project. Everything is authorised on the server: the widget only works on the websites you list, sessions are bound to that website, and reviewers only see projects they were invited to.
221
- - The widget runs in a Shadow DOM, adds one element to your page, needs no `unsafe-eval`, and removes itself completely on `destroy()`.
222
- - Trusted Types: the widget works under `require-trusted-types-for 'script'`. The screenshot engine writes two fixed strings through one narrowly named policy, `commentkit-capture`, that accepts nothing else; no default policy is created. If your CSP limits policy names with `trusted-types`, add `commentkit-capture` (without it, screenshots are skipped and everything else works).
223
- - Console and network capture are off unless the project turns them on, and then each reviewer chooses per comment ("Include browser errors to help the developer"). Only metadata is kept (message; or method, URL, status, timing for `fetch` and `XMLHttpRequest`), never bodies or headers, and credential-looking values are removed from URLs and text by name and by value. "Copy for AI agent" removes them too.
224
- - Feedback text is rendered as plain text with safe links only. Agent output marks feedback as untrusted.
225
- - See [SECURITY.md](SECURITY.md) for hardening guidance and how to report a vulnerability.
290
+ ## Sign reviewers in from your own login
226
291
 
227
- ## Size
292
+ If your website has its own login, the people signed in to it can comment without a second sign-in. Your **server** makes a short-lived token for the signed-in user, and the page passes it to the widget.
228
293
 
229
- | Loaded | Gzip |
230
- | --- | --- |
231
- | Script-tag loader (every page) | ~1.3 KB |
232
- | Widget when activated (incl. Preact) | ~31 KB |
233
- | Screenshot engine (only while commenting) | ~51 KB |
234
- | Realtime (signed-in people only) | ~21 KB |
294
+ 1. In CommentKit open your website's settings → **For developers** → **Sign in from your website**, and create the identity secret. Keep it on your server only.
295
+ 2. On your server, make a token for the signed-in user. It is an HS256 JWT with `sub` (your user id), `email`, optional `name`, `aud` (your project key), `iat` and `exp` (at most 10 minutes after `iat`). An optional `jti` makes it work once.
296
+
297
+ Node (no dependencies):
298
+
299
+ ```js
300
+ import { createHmac } from "node:crypto";
301
+ const b64 = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
302
+ export function commentkitToken(user) {
303
+ const now = Math.floor(Date.now() / 1000);
304
+ const body = `${b64({ alg: "HS256", typ: "JWT" })}.${b64({ sub: String(user.id), email: user.email, name: user.name, aud: "pk_live_your_key", iat: now, exp: now + 300 })}`;
305
+ return `${body}.${createHmac("sha256", process.env.COMMENTKIT_IDENTITY_SECRET).update(body).digest("base64url")}`;
306
+ }
307
+ ```
308
+
309
+ PHP (no dependencies):
310
+
311
+ ```php
312
+ function commentkit_token(array $user): string {
313
+ $b64 = fn ($v) => rtrim(strtr(base64_encode(json_encode($v)), '+/', '-_'), '=');
314
+ $now = time();
315
+ $body = $b64(['alg' => 'HS256', 'typ' => 'JWT']) . '.' . $b64(['sub' => (string) $user['id'], 'email' => $user['email'], 'name' => $user['name'], 'aud' => 'pk_live_your_key', 'iat' => $now, 'exp' => $now + 300]);
316
+ return $body . '.' . rtrim(strtr(base64_encode(hash_hmac('sha256', $body, getenv('COMMENTKIT_IDENTITY_SECRET'), true)), '+/', '-_'), '=');
317
+ }
318
+ ```
319
+
320
+ Any JWT library works too (for example `jsonwebtoken` or `firebase/php-jwt` with `HS256`).
321
+
322
+ 3. Give the token to the widget. A function is best: the widget calls it again whenever the CommentKit session ends.
323
+
324
+ ```ts
325
+ init({ project: "pk_live_your_key", identity: () => fetch("/commentkit-token").then((r) => r.text()) });
326
+ ```
327
+
328
+ Script tag: set `window.CommentKit = { identity: () => fetch("/commentkit-token").then((r) => r.text()) }` before the tag. Later, for example right after someone logs in: `kit.identify(token)`, `window.CommentKit.identify(token)` or `document.querySelector("comment-kit").identify(token)`. Tokens never go in attributes or URLs; the widget never stores or logs them.
329
+
330
+ 4. When someone logs out of your site, sign them out of CommentKit too: `kit.signOut()`, `window.CommentKit.signOut()` or `document.querySelector("comment-kit").signOut()`. The widget does not sign them back in on its own during that visit; the next token your site gives does (an `identify()` call, or `identity` on the next page load), so stop handing out tokens once someone is logged out.
331
+
332
+ **Treat every token as single-use.** Make a new token for every sign-in (a `jti` claim makes the server refuse a second use). If the connection drops while a token is on its way (it may have been used), the widget never sends it again: with a function it asks for a new one and tries again, with a plain token it gives up and says so in the console. When CommentKit is busy (`429`), it waits as long as the answer says and tries the same token again, a few times at most.
333
+
334
+ **What the reviewer can do.** They are always a client-level reviewer (a guest) of this project, never a team member, even if their email belongs to one: your website vouches for its own users, not for CommentKit accounts. They can comment, reply and approve pages. A CommentKit team member already signed in on that browser stays signed in as themselves. With an identity, the widget shows for that person on production too.
335
+
336
+ **When it fails.** `identify()` resolves `false`, the `error` event fires with the code, the console says what to fix when the setup is wrong, and the normal "Sign in" button stays. Codes: `identity_not_set_up` (no identity secret yet), `identity_invalid` (signature, algorithm, audience, claims or size), `identity_expired`, `identity_replayed` (that token was used already), `identity_conflict` (the email belongs to someone else: another user of your site, or a reviewer who joined with an emailed code; to let your login vouch for addresses like that, turn on **Trust email addresses from my website's login** in your website's settings → **For developers**, or use a different address), `guest_removed` (your team removed that person in CommentKit), `plan_required` (the website is read-only: its plan has ended), `origin_not_allowed` (the website is not on the project's list; this sign-in never works on `localhost`). Details: `https://commentkit.dev/docs/identify`.
337
+
338
+ ## Page sign-off
339
+
340
+ Reviewers can approve a page when they are happy with it. In the inbox, above "This page", they see "Happy with this page?" and **Approve this page**, with an optional note. Afterwards the row says who approved and when, and they can **Withdraw approval**. If comments are still open it says how many, and they can approve anyway.
341
+
342
+ - Anyone who may comment on the website can approve, including guests who confirmed their email. It is not offered on a read-only project.
343
+ - There is one approval per page, environment and person; approving again replaces it.
344
+ - An approval becomes outdated when new feedback that is still open, in progress or ready for review is left on the page in that environment after it, or when the page is later seen on a different commit than the one approved. The row then says "New feedback came in after this page was approved." or "This page has changed since it was approved." and offers **Approve again**.
345
+ - Your team is notified, and the `page.approved` and `page.approval_withdrawn` webhooks are sent.
235
346
 
236
- ## Versioning and support
347
+ **One page, one identity.** Feedback and approvals are kept per page key, not per raw address, so `/pricing`, `/pricing/` and `/pricing?utm_source=x` are one page. The key lower-cases the scheme and host, drops the default port and trailing slashes, keeps a fragment only when it is a route (`#/…`, `#!/…`), sorts the remaining query parameters, and drops these: any `utm_*`, CommentKit's own `ck` and `ck_*`, `gclid`, `gbraid`, `wbraid`, `fbclid`, `msclkid`, `mc_cid`, `mc_eid`, `_ga`, `_gl`, `ref_src`, `igshid` and `yclid`. A hash route gets the same rules as the address (its own tracking parameters dropped, its query sorted, trailing slashes dropped). A project can list more parameters that do not change the page in its settings; the widget reads that list with its settings, so its key matches the server's before anyone comments on a page. `pageKey(address, ignored)` from `@commentkit/comment-kit/headless` computes the same key.
237
348
 
238
- CommentKit follows [semantic versioning](https://semver.org): a patch fixes bugs, a minor adds options or features without breaking anything, and only a new major version may remove or change behaviour. `init()` options, the instance API, events, `data-*` attributes, the custom element and the adapters are the public API. The look of the widget and its wording can improve in any release.
349
+ ## Build plugin
239
350
 
240
- **Script tag channels**
351
+ Optional. The plugins tag elements with their source location in development, so a comment says which file and line to open, and they record the branch and commit of each build, so the widget shows this branch's feedback first.
241
352
 
242
- | Address | What you get |
353
+ ```ts
354
+ // vite.config.ts (also SvelteKit and Nuxt)
355
+ import { defineConfig } from "vite";
356
+ import react from "@vitejs/plugin-react";
357
+ import commentkit from "@commentkit/comment-kit/vite";
358
+
359
+ export default defineConfig({ plugins: [commentkit(), react()] });
360
+ ```
361
+
362
+ ```js
363
+ // next.config.mjs
364
+ import { withCommentKit } from "@commentkit/comment-kit/next";
365
+ export default withCommentKit({ reactStrictMode: true });
366
+ ```
367
+
368
+ Also `@commentkit/comment-kit/webpack` (`new CommentKitWebpackPlugin()`) and `@commentkit/comment-kit/astro` (`integrations: [commentkit()]`).
369
+
370
+ | Option | Type | Default | What it does |
371
+ | --- | --- | --- | --- |
372
+ | `source` | `boolean \| "dev"` | `"dev"` | Tag elements with `data-ck-src="file:line:col"`: dev servers and non-production builds, `true` always, `false` never. `COMMENTKIT_SOURCE=1` tags a preview build, `=0` turns it off. |
373
+ | `buildInfo` | `boolean \| "development"` | `true` | Put the git branch and commit into the bundle as `__COMMENTKIT_BUILD__`; `"development"` only in dev and non-production builds; `false` never runs git. Anyone who can load the site can read these values. |
374
+ | `include`, `exclude` | path prefixes or RegExps | all files, never `node_modules` | Which files to tag. |
375
+ | `root` | `string` | the bundler root | Paths in `data-ck-src` are relative to it. |
376
+ | `inject` | `{ project, endpoint?, src? }` | none | Vite and Astro dev server only: adds the loader script tag. |
377
+
378
+ Full details: [plugins/README.md](plugins/README.md).
379
+
380
+ ## CLI
381
+
382
+ The command comes with the package. Run it as `npx @commentkit/comment-kit <command>`: that works before and after the package is installed. (Installed, the package also has a `commentkit` command, but a bare `npx commentkit` outside that folder would fetch an unrelated npm package.)
383
+
384
+ | Command | What it does |
243
385
  | --- | --- |
244
- | `https://commentkit.dev/cdn/v1/loader.js` | Moving channel: always the latest 1.x release, with fixes and new features as soon as they ship. Recommended for most sites. |
245
- | `https://commentkit.dev/cdn/<version>/loader.js` (for example `/cdn/1.2.3/`) | Pinned: that exact release, never changed after it is published. |
386
+ | `login` | Shows a short code and opens CommentKit in your browser; confirm it and choose the project and what the CLI may do. |
387
+ | `logout` | Forgets the sign-in on this computer. |
388
+ | `status` | Who and which project you are signed in to, and what the CLI may do. |
389
+ | `init` | Adds the key, the build plugin, `.commentkit/` in `.gitignore` and the widget to your app. Asks before each change. |
390
+ | `doctor [url]` | Finds out why the widget is not showing, in this folder and on your site. |
391
+ | `pull` | Saves open feedback and tasks to `.commentkit/feedback.md` for your coding agent. |
392
+ | `open [CK-12]` | Opens a task, or the task board, in the browser. |
393
+ | `token list\|create\|revoke` | Tokens for CI. |
394
+ | `mcp install <cursor\|vscode\|claude\|codex>` | Adds the hosted CommentKit MCP server to your coding agent's config. |
246
395
 
247
- To pin, use the exact version and its Subresource Integrity hash, so the browser refuses the file if it ever differs. The hashes for every published version are in `https://commentkit.dev/cdn/integrity.json` (served from `public/cdn/integrity.json` in the backend):
396
+ Every command takes `--help`. Full reference: [cli/README.md](cli/README.md).
248
397
 
249
- ```html
250
- <script src="https://commentkit.dev/cdn/1.2.3/loader.js" integrity="sha384-…" crossorigin="anonymous" data-project="pk_live_your_key" defer></script>
398
+ ## AI agents (MCP)
399
+
400
+ Connect your coding agent to `https://commentkit.dev/mcp` and sign in when it asks; in the browser you choose the project and what the agent may do. Nothing to install:
401
+
402
+ ```sh
403
+ npx @commentkit/comment-kit mcp install cursor # or vscode, claude, codex
404
+ claude mcp add --transport http commentkit https://commentkit.dev/mcp
251
405
  ```
252
406
 
253
- The loader then loads the rest of the widget from the same pinned folder, which is immutable. A pinned version gets no fixes: move to a newer one on purpose, and check its changelog first.
407
+ Agents can list, search and read feedback and tasks, including the screenshot. With the permissions you choose they can reply, link a commit and mark a task **ready for review**; by default a person approves each of these first. Agents never resolve, assign or delete. For CI or offline use there is a local server, `comment-kit-mcp`, that reads an agent token from `COMMENTKIT_TOKEN` and the project from `COMMENTKIT_PROJECT_ID`; see [mcp/README.md](mcp/README.md).
254
408
 
255
- **npm**: `npm install @commentkit/comment-kit@^1` follows 1.x the same way as `/cdn/v1`; use an exact version (`--save-exact`) and your lockfile to pin. Release candidates for a future major are published under the `next` tag and are never installed by `^1`. The full rules are in [docs/VERSIONING.md](docs/VERSIONING.md).
409
+ From the inbox, team members can also choose comments and send them to an agent in one prompt: **Open in Cursor**, **Open in Claude Code** and **Open in Codex** open the agent with the prompt filled in but not sent, and the prompt is always copied to the clipboard too. Feedback is marked as untrusted text in every prompt.
256
410
 
257
- **Support window**: each major version gets security fixes for 24 months after the next major version is released, and bug fixes until then. The end date of each major is announced in the [changelog](CHANGELOG.md) when its successor ships. Security fixes land in the latest minor of every supported major, so the moving channel and `^` ranges receive them automatically; pinned versions do not. See [SECURITY.md](SECURITY.md) to report a vulnerability.
411
+ ## Troubleshooting
258
412
 
259
- ## Development
413
+ Run `doctor` in your app's folder, with your site's address:
260
414
 
261
- ```bash
262
- npm ci
263
- npm run typecheck
264
- npm test # unit tests (Vitest)
265
- npm run build # npm + CDN bundles, public types, size budgets
266
- npm run test:e2e # Playwright: Chromium, Firefox, WebKit
267
- npm run test:visual # screenshot tests of the main widget states (Chromium; baselines recorded on macOS)
268
- npm run test:host-matrix # packed SDK in Next.js, Nuxt, SvelteKit, Angular, Astro, React Router, HTML, WordPress (slow)
269
- semgrep scan --config .semgrep.yml --error src # security rules for the widget (brew install semgrep)
270
- npm run ci # every gate; HOST_MATRIX=1 npm run ci adds the host matrix
415
+ ```sh
416
+ npx @commentkit/comment-kit doctor https://staging.acme.com
271
417
  ```
272
418
 
273
- Locally Playwright reuses an e2e server already running on port 5190; when several checkouts (git worktrees) test at once, give each its own with `CK_E2E_PORT=5291 npm run test:e2e`. Screenshot baselines live in `e2e/specs/visual.spec.ts-snapshots/`. After an intended visual change, update them with `npx playwright test e2e/specs/visual.spec.ts --project=chromium --update-snapshots` and review the new images before committing. The host matrix (`scripts/host-matrix.mjs`) installs the `npm pack` tarball into each app in `e2e/host-matrix/`, builds it for production and checks that the widget mounts once on localhost with no console errors, and that single-page apps destroy it on a route without it. Pass app names to run some of them (`npm run test:host-matrix -- next astro`); WordPress needs `php` on the PATH and is skipped without it.
419
+ It checks the package or script tag, the key (unknown, paused or read-only), whether the site is on the project's allowed websites, whether the page has CommentKit, and whether its Content Security Policy lets CommentKit load. It sends no cookies or passwords, and exits 0 when nothing is wrong and 1 when something is. `--json` prints the result as JSON.
420
+
421
+ A site with everything in place:
274
422
 
275
- The architecture and roadmap live in [ARCHITECTURE-BLUEPRINT.md](ARCHITECTURE-BLUEPRINT.md) and [TASKS.md](TASKS.md).
423
+ ```text
424
+ CommentKit doctor (https://commentkit.dev)
276
425
 
277
- ## Releasing
426
+ ✓ @commentkit/comment-kit 1.6.0 is installed (Vite).
427
+ ✓ The widget is added in your layout or entry file.
428
+ ✓ Project key pk_live_abcd… found in .env.local (VITE_COMMENTKIT_KEY).
429
+ ✓ The build plugin is set up in vite.config.ts.
430
+ ✓ The CLI is signed in to “Acme site”.
431
+ ✓ CommentKit knows the key pk_live_abcd… (project “Acme site”) and feedback is on.
432
+ ✓ https://staging.acme.com is on the project's allowed websites (staging).
433
+ ✓ The page shows signs of the bundled SDK (your project key).
434
+ ✓ The page's CSP lets the widget talk to https://commentkit.dev.
435
+ ✓ The page's CSP lets screenshots and emoji load from https://commentkit.dev.
436
+ • On staging.acme.com the Comment button is hidden from ordinary visitors. It appears after opening a share link, for signed-in reviewers, or after pressing Cmd+Shift+K (Ctrl+Shift+K on Windows).
437
+
438
+ Everything CommentKit needs is in place.
439
+ ```
440
+
441
+ A site that is not on the project's list and whose CSP blocks CommentKit:
442
+
443
+ ```text
444
+ ✗ https://shop.acme.com is not on the project's list of allowed websites, so the widget will not load there. Add it in CommentKit under Project → Setup, step 1 (a project admin can).
445
+ ✓ The page has the CommentKit script tag (key pk_live_abcd…).
446
+ ✗ The page's CSP blocks the CommentKit script: script-src does not allow https://commentkit.dev. Add https://commentkit.dev to script-src in the Content-Security-Policy header.
447
+ ✗ The page's CSP blocks the widget's requests: default-src does not allow https://commentkit.dev. Add https://commentkit.dev to default-src in the Content-Security-Policy header.
448
+ ! The page's CSP blocks images from https://commentkit.dev (default-src): screenshots and emoji will not show in the widget. Add https://commentkit.dev to default-src in the Content-Security-Policy header.
449
+
450
+ 3 problems found. Fix the ✗ lines, then run npx @commentkit/comment-kit doctor again.
451
+ ```
278
452
 
279
- Versions and changelogs are managed with [Changesets](https://github.com/changesets/changesets) for the four published packages: `@commentkit/comment-kit` (this folder), `comment-kit-mcp` (`mcp/`), `@commentkit/cli` (`cli/`) and `@commentkit/build` (`build/`). The browser extension, the Zapier app and the Make app are private and never versioned this way. There are no npm workspaces: each package keeps its own lockfile, and `lerna.json` only tells Changesets where the packages are.
453
+ Other things to check:
280
454
 
281
- 1. With every change that people using a package will notice, add a changeset: `npm run changeset`. Pick the packages, the bump (patch, minor or major, see Versioning above) and write one plain sentence for the changelog. Commit the file in `.changeset/` with the change.
282
- 2. To prepare a release, run `npm run release:status` to see what will be bumped, then `npm run version`. It applies the bumps to each `package.json` and writes the changelogs. Review the diff, update each package's lockfile (`npm install --package-lock-only` in that folder), and commit.
283
- 3. While 1.x is in beta, run `npx changeset pre enter beta` once first, so versions come out as `1.0.0-beta.N` instead of jumping to `1.0.0`; `npx changeset pre exit` before the stable release.
284
- 4. Publishing stays manual and needs the owner's go-ahead each time: in each package folder, `npm run check` (or that package's gates) and `node scripts/check-pack.mjs`, then `npm publish`. Do not run `changeset publish`.
455
+ - **Nothing on a production site** is expected: open a share link or press Cmd/Ctrl+Shift+K (see [What CommentKit does to your page](#what-commentkit-does-to-your-page)).
456
+ - **The console** has one `[CommentKit]` line explaining any setup problem: a missing or wrong key, CommentKit added twice, `init()` called with a second project, or the widget resting after repeated crashes.
457
+ - **`error` event codes** are explained at `https://commentkit.dev/docs/errors`.
285
458
 
286
- 5. The CDN widget rolls out gradually. In the backend, `scripts/sync-sdk.sh` writes the pinned `public/cdn/<version>/` folder (with SRI hashes); deploy it, then `php artisan cdn:canary <version> --percent=1`, later `10` and `100`. The `/cdn/v1/` loader asks `/api/v1/widget/channel` which version to load, so a change takes effect within a minute. Widget crashes are counted per version, and the canary is rolled back automatically when it crashes in more than 1% of loads or three times as often as stable (`cdn:canary --status`, `--rollback` by hand). When it has held at 100%, sync it into `/cdn/v1/` (the stable files), deploy, and `cdn:canary --clear`.
459
+ ## Links
287
460
 
288
- `npm run version` is also npm's lifecycle hook for `npm version`, so `npm version` in this folder runs Changesets too; use the steps above instead of `npm version`.
461
+ - Website and docs: <https://commentkit.dev>
462
+ - Build plugins: [plugins/README.md](plugins/README.md)
463
+ - `commentkit` command: [cli/README.md](cli/README.md)
464
+ - MCP server: [mcp/README.md](mcp/README.md)
465
+ - Browser extension, WordPress, Zapier and Make: [extension/](extension/README.md), [wordpress/](wordpress/README.md), [zapier/](zapier/README.md), [make/](make/README.md)
466
+ - Security and vulnerability reports: [SECURITY.md](SECURITY.md)
467
+ - Versions and support: [docs/VERSIONING.md](docs/VERSIONING.md) and the [changelog](CHANGELOG.md). Each major version gets security fixes for 24 months after the next major is released.
468
+ - Working on this repository: [CLAUDE.md](CLAUDE.md)
289
469
 
290
470
  ## License
291
471