critiqs-react 0.3.0 → 0.5.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 (58) hide show
  1. package/AGENT_SETUP.md +198 -66
  2. package/README.md +214 -31
  3. package/bin/critiqs.mjs +3 -1
  4. package/dist/index.js +16877 -4770
  5. package/dist/server/index.d.ts +1 -87
  6. package/dist/server/index.js +1 -4889
  7. package/package.json +6 -5
  8. package/bin/cli.d.mts +0 -21
  9. package/bin/cli.mjs +0 -293
  10. package/bin/env.d.mts +0 -41
  11. package/bin/env.mjs +0 -384
  12. package/bin/init.d.mts +0 -126
  13. package/bin/init.mjs +0 -965
  14. package/bin/mcp.d.mts +0 -20
  15. package/bin/mcp.mjs +0 -314
  16. package/bin/setup.d.mts +0 -183
  17. package/bin/setup.mjs +0 -1054
  18. package/dist/backend/convex/_generated/api.d.ts +0 -95
  19. package/dist/backend/convex/_generated/api.js +0 -23
  20. package/dist/backend/convex/_generated/dataModel.d.ts +0 -60
  21. package/dist/backend/convex/_generated/server.d.ts +0 -162
  22. package/dist/backend/convex/_generated/server.js +0 -101
  23. package/dist/backend/convex/ai.ts +0 -93
  24. package/dist/backend/convex/aiSettings.ts +0 -43
  25. package/dist/backend/convex/auth.config.ts +0 -18
  26. package/dist/backend/convex/captureHttp.ts +0 -96
  27. package/dist/backend/convex/captures.ts +0 -167
  28. package/dist/backend/convex/crons.ts +0 -14
  29. package/dist/backend/convex/deviceSignIn.ts +0 -151
  30. package/dist/backend/convex/grouping.ts +0 -41
  31. package/dist/backend/convex/http.ts +0 -724
  32. package/dist/backend/convex/lib/ai.ts +0 -6
  33. package/dist/backend/convex/lib/links.ts +0 -12
  34. package/dist/backend/convex/lib/pages.ts +0 -207
  35. package/dist/backend/convex/lib/r2.ts +0 -75
  36. package/dist/backend/convex/lib/store.ts +0 -509
  37. package/dist/backend/convex/lib/tokens.ts +0 -101
  38. package/dist/backend/convex/lib/validators.ts +0 -73
  39. package/dist/backend/convex/lib/vendor/aws4fetch.js +0 -289
  40. package/dist/backend/convex/lib/vendor/critiqs_ai.js +0 -49081
  41. package/dist/backend/convex/lib/vendor/critiqs_core.js +0 -385
  42. package/dist/backend/convex/lib/vendor/critiqs_server.js +0 -3108
  43. package/dist/backend/convex/notificationEmails.ts +0 -61
  44. package/dist/backend/convex/notifications.ts +0 -182
  45. package/dist/backend/convex/plans.ts +0 -67
  46. package/dist/backend/convex/projects.ts +0 -46
  47. package/dist/backend/convex/schema.ts +0 -343
  48. package/dist/backend/convex/search.ts +0 -26
  49. package/dist/backend/convex/signIn.ts +0 -368
  50. package/dist/backend/convex/tags.ts +0 -68
  51. package/dist/backend/convex/threads.ts +0 -146
  52. package/dist/backend/convex/users.ts +0 -13
  53. package/dist/server/chunks/driver-n9zpr0k3.js +0 -21
  54. package/dist/server/chunks/index-9bg7tmnq.js +0 -522
  55. package/dist/server/chunks/index-askcfn7t.js +0 -148
  56. package/dist/server/chunks/providers-rv184xvj.js +0 -48444
  57. package/dist/server/chunks/token-kzddms7r.js +0 -63
  58. package/dist/server/chunks/token-util-k8bee1wc.js +0 -4
@@ -1,385 +0,0 @@
1
- // ../core/src/types.ts
2
- var REACTIONS = ["\uD83D\uDC4D", "❤️", "\uD83C\uDF89", "\uD83D\uDC40", "✅", "\uD83D\uDE04"];
3
- // ../core/src/anchor.ts
4
- var PURPOSE_ATTRIBUTE = "data-critiqs-id";
5
- var RECORD_ATTRIBUTE = "data-critiqs-record";
6
- var MAX_LABEL_LENGTH = 80;
7
- function describeTarget(selected, root) {
8
- const element = selected.closest(`[${PURPOSE_ATTRIBUTE}]`) ?? selected;
9
- return {
10
- element,
11
- target: {
12
- purposeId: element.getAttribute(PURPOSE_ATTRIBUTE),
13
- recordKey: recordKeyOf(element),
14
- clues: cluesOf(element, root)
15
- }
16
- };
17
- }
18
- function locateTarget(target, scope, root, isCandidate = () => true) {
19
- if (target.purposeId === null)
20
- return locateByClues(target, scope, root, isCandidate);
21
- const candidates = Array.from(root.querySelectorAll(`[${PURPOSE_ATTRIBUTE}]`)).filter((element) => element.getAttribute(PURPOSE_ATTRIBUTE) === target.purposeId && isCandidate(element));
22
- if (candidates.length === 0)
23
- return { status: "not-found" };
24
- if (scope === "shared")
25
- return { status: "found", elements: candidates };
26
- const sameRecord = candidates.filter((element) => recordKeyOf(element) === target.recordKey);
27
- if (sameRecord.length === 0)
28
- return { status: "wrong-record" };
29
- if (sameRecord.length > 1)
30
- return { status: "ambiguous", candidates: sameRecord.length };
31
- return { status: "found", elements: sameRecord };
32
- }
33
- function locateByClues(target, scope, root, isCandidate) {
34
- const atPath = resolvePath(target.clues.path, root);
35
- const element = atPath !== null && isCandidate(atPath) && cluesAgree(target.clues, cluesOf(atPath, root)) ? atPath : null;
36
- if (element === null)
37
- return { status: "not-found" };
38
- if (scope === "record" && recordKeyOf(element) !== target.recordKey) {
39
- return { status: "wrong-record" };
40
- }
41
- return { status: "found", elements: [element] };
42
- }
43
- function cluesAgree(saved, live) {
44
- return saved.tagName === live.tagName && saved.role === live.role && saved.label === live.label;
45
- }
46
- function recordKeyOf(element) {
47
- return element.closest(`[${RECORD_ATTRIBUTE}]`)?.getAttribute(RECORD_ATTRIBUTE) ?? null;
48
- }
49
- function cluesOf(element, root) {
50
- return {
51
- tagName: element.tagName.toLowerCase(),
52
- role: element.getAttribute("role"),
53
- label: labelOf(element),
54
- path: pathOf(element, root)
55
- };
56
- }
57
- function labelOf(element) {
58
- const text = element.getAttribute("aria-label") ?? element.textContent ?? "";
59
- const normalized = text.replace(/\s+/g, " ").trim();
60
- return normalized === "" ? null : normalized.slice(0, MAX_LABEL_LENGTH);
61
- }
62
- function pathOf(element, root) {
63
- const segments = [];
64
- let current = element;
65
- while (current !== null && current !== root) {
66
- const tagName = current.tagName;
67
- const sameTag = current.parentElement ? Array.from(current.parentElement.children).filter((sibling) => sibling.tagName === tagName) : [current];
68
- segments.unshift(`${tagName.toLowerCase()}:${sameTag.indexOf(current) + 1}`);
69
- current = current.parentElement;
70
- }
71
- return segments.join("/");
72
- }
73
- function resolvePath(path, root) {
74
- if (path === "")
75
- return root;
76
- let current = root;
77
- for (const segment of path.split("/")) {
78
- const [tagName, position] = segment.split(":");
79
- if (current === null || tagName === undefined || position === undefined)
80
- return null;
81
- const sameTag = Array.from(current.children).filter((child) => child.tagName.toLowerCase() === tagName);
82
- current = sameTag[Number(position) - 1] ?? null;
83
- }
84
- return current;
85
- }
86
- // ../core/src/read-state.ts
87
- function isUnread(lastMessageAt, state) {
88
- if (state === null)
89
- return true;
90
- return state.manualUnread || lastMessageAt > state.lastReadAt;
91
- }
92
- // ../core/src/tags.ts
93
- var MAX_TAG_LENGTH = 50;
94
- var MAX_THREAD_TAGS = 50;
95
- var MAX_MESSAGE_HASHTAGS = 30;
96
- var MAX_THREAD_TEXT_TAGS = 200;
97
- var MAX_TAG_LIST = MAX_THREAD_TAGS + MAX_THREAD_TEXT_TAGS;
98
- var BOUNDARY = /[\s\p{Ps}\p{Pi}]/u;
99
- var TAG_START = /\p{L}/u;
100
- var TAG_CHAR = /[\p{L}\p{N}\p{M}_-]/u;
101
- function parseHashtags(text) {
102
- const found = [];
103
- const chars = Array.from(text);
104
- let offset = 0;
105
- const offsets = [];
106
- for (const char of chars) {
107
- offsets.push(offset);
108
- offset += char.length;
109
- }
110
- offsets.push(offset);
111
- for (let i = 0;i < chars.length; i++) {
112
- if (chars[i] !== "#")
113
- continue;
114
- if (i > 0 && !BOUNDARY.test(chars[i - 1]))
115
- continue;
116
- const first = chars[i + 1];
117
- if (first === undefined || !TAG_START.test(first))
118
- continue;
119
- let j = i + 1;
120
- while (j < chars.length && TAG_CHAR.test(chars[j]))
121
- j++;
122
- let last = j;
123
- while (last > i + 2 && /[_-]/.test(chars[last - 1]))
124
- last--;
125
- const length = last - (i + 1);
126
- if (length <= MAX_TAG_LENGTH) {
127
- const label = chars.slice(i + 1, last).join("");
128
- found.push({ key: tagKey(label), label, start: offsets[i], end: offsets[last] });
129
- }
130
- i = j - 1;
131
- }
132
- return found;
133
- }
134
- function hashtagLabels(text) {
135
- const seen = new Map;
136
- for (const tag of parseHashtags(text))
137
- if (!seen.has(tag.key))
138
- seen.set(tag.key, tag.label);
139
- return [...seen.values()];
140
- }
141
- function tagKey(label) {
142
- return label.replace(/^#/, "").normalize("NFKC").toLowerCase().trim().replace(/[\s_]+/g, "-");
143
- }
144
- function cleanTagLabel(label) {
145
- const cleaned = label.replace(/^#/, "").normalize("NFC").replace(/\s+/g, " ").trim();
146
- if (cleaned === "" || Array.from(cleaned).length > MAX_TAG_LENGTH)
147
- return null;
148
- if (/[\p{Cc}\p{Cf}#]/u.test(cleaned))
149
- return null;
150
- return cleaned;
151
- }
152
- function uniqueTags(labels) {
153
- const seen = new Map;
154
- for (const label of labels) {
155
- const key = tagKey(label);
156
- if (key !== "" && !seen.has(key))
157
- seen.set(key, label);
158
- }
159
- return [...seen.values()];
160
- }
161
- function hasTag(labels, label) {
162
- const key = tagKey(label);
163
- return labels.some((candidate) => tagKey(candidate) === key);
164
- }
165
-
166
- // ../core/src/sidebar.ts
167
- var DEFAULT_FILTERS = {
168
- status: "open",
169
- unreadOnly: false,
170
- tags: [],
171
- screens: "all"
172
- };
173
- var GROUP_ORDER = ["current-view", "other-view", "other-screen"];
174
- function groupThreads(threads, view, filters = DEFAULT_FILTERS) {
175
- const groups = new Map;
176
- for (const thread of threads) {
177
- if (!matchesFilters(thread, filters, view.currentScreen))
178
- continue;
179
- const placement = placementOf(thread, view);
180
- groups.set(placement, [...groups.get(placement) ?? [], thread]);
181
- }
182
- return GROUP_ORDER.flatMap((placement) => {
183
- const grouped = groups.get(placement);
184
- if (grouped === undefined)
185
- return [];
186
- return [{ placement, threads: grouped.sort((a, b) => b.lastActivityAt - a.lastActivityAt) }];
187
- });
188
- }
189
- function placementOf(thread, view) {
190
- if (thread.screen !== view.currentScreen)
191
- return "other-screen";
192
- return view.isLive(thread.id) ? "current-view" : "other-view";
193
- }
194
- function matchesFilters(thread, filters, currentScreen) {
195
- if (thread.status === "deleted")
196
- return false;
197
- if (filters.status !== "all" && thread.status !== filters.status)
198
- return false;
199
- if (filters.unreadOnly && !thread.unread)
200
- return false;
201
- if (filters.tags.length > 0) {
202
- const wanted = new Set(filters.tags.map(tagKey));
203
- if (!thread.tags.some((tag) => wanted.has(tagKey(tag))))
204
- return false;
205
- }
206
- if (filters.screens === "current" && thread.screen !== currentScreen)
207
- return false;
208
- return true;
209
- }
210
- function expandTagFilter(filters, members) {
211
- const groups = filters.groups ?? [];
212
- if (groups.length === 0)
213
- return filters;
214
- const tags = new Map(filters.tags.map((tag) => [tagKey(tag), tag]));
215
- for (const group of groups)
216
- for (const tag of members(group))
217
- if (!tags.has(tagKey(tag)))
218
- tags.set(tagKey(tag), tag);
219
- const expanded = [...tags.values()];
220
- return { ...filters, tags: expanded.length === 0 ? ["\x00no-tags"] : expanded, groups: [] };
221
- }
222
- // ../core/src/export.ts
223
- var EXPORT_SCHEMA_VERSION = 1;
224
- function exportJson(collection) {
225
- return JSON.stringify({ schemaVersion: EXPORT_SCHEMA_VERSION, ...collection }, null, 2);
226
- }
227
- function exportMarkdown(collection) {
228
- const lines = [
229
- `# ${collection.title}`,
230
- "",
231
- `Project: ${collection.projectName} `,
232
- `Exported: ${formatTime(collection.exportedAt)} `,
233
- `Threads: ${collection.threads.length}`
234
- ];
235
- for (const thread of collection.threads) {
236
- lines.push("", ...threadMarkdown(thread));
237
- }
238
- return `${lines.join(`
239
- `)}
240
- `;
241
- }
242
- function threadMarkdown(thread) {
243
- const [first] = thread.messages;
244
- const heading = first === undefined ? "(no messages)" : summarize(first.body);
245
- const lines = [
246
- `## ${heading}`,
247
- "",
248
- `- Link: ${thread.link}`,
249
- `- Status: ${thread.status}`,
250
- `- Tags: ${thread.tags.length > 0 ? thread.tags.join(", ") : "none"}`,
251
- `- Screen: ${thread.screen}`,
252
- `- Target: ${describeTarget2(thread)}${thread.reattached ? " (reattached)" : ""}`,
253
- `- Scope: ${thread.scope === "shared" ? "shared across records" : "this record only"}`,
254
- `- Revision: ${thread.revision ?? "unknown"}`,
255
- `- Page: ${thread.pageUrl} at ${thread.viewport.width}×${thread.viewport.height}`
256
- ];
257
- if (thread.persona !== null)
258
- lines.push(`- Demo persona: ${thread.persona}`);
259
- const viewState = Object.entries(thread.viewState);
260
- if (viewState.length > 0) {
261
- lines.push(`- View state: ${viewState.map(([key, value]) => `${key}=${String(value)}`).join(", ")}`);
262
- }
263
- lines.push(`- Capture: ${thread.hasCapture ? "saved; open the link to view it" : "none"}`);
264
- lines.push("", "### Discussion");
265
- for (const message of thread.messages) {
266
- const edited = message.editedAt === null ? "" : " (edited)";
267
- lines.push("", `**${message.author}**, ${formatTime(message.createdAt)}${edited}, revision ${message.revision ?? "unknown"}:`, "", ...message.body.split(`
268
- `).map((line) => `> ${line}`));
269
- }
270
- return lines;
271
- }
272
- function describeTarget2(thread) {
273
- const parts = [
274
- thread.target.purposeId === null ? null : `\`${thread.target.purposeId}\``,
275
- thread.target.label === null ? null : `"${thread.target.label}"`,
276
- thread.target.recordKey === null ? null : `record ${thread.target.recordKey}`
277
- ].filter((part) => part !== null);
278
- return parts.length > 0 ? parts.join(", ") : "unknown";
279
- }
280
- function summarize(body) {
281
- const firstLine = body.split(`
282
- `)[0]?.trim() ?? "";
283
- return firstLine.length > 72 ? `${firstLine.slice(0, 71)}…` : firstLine || "(empty comment)";
284
- }
285
- function formatTime(timestamp) {
286
- return new Date(timestamp).toISOString();
287
- }
288
- // ../core/src/links.ts
289
- var LINK_PARAMETER = "critiqs";
290
- function buildLink(currentOrigin, pageUrl, target) {
291
- const saved = new URL(pageUrl, currentOrigin);
292
- const url = new URL(currentOrigin);
293
- url.pathname = saved.pathname;
294
- url.search = saved.search;
295
- url.hash = saved.hash;
296
- const value = target.messageId === null ? target.threadId : `${target.threadId}.${target.messageId}`;
297
- url.searchParams.set(LINK_PARAMETER, value);
298
- return url.toString();
299
- }
300
- function parseLink(href) {
301
- const value = new URL(href).searchParams.get(LINK_PARAMETER);
302
- if (value === null || value === "")
303
- return null;
304
- const [threadId, messageId] = value.split(".");
305
- if (threadId === undefined || threadId === "")
306
- return null;
307
- return { threadId, messageId: messageId === undefined || messageId === "" ? null : messageId };
308
- }
309
- function removeLink(href) {
310
- const url = new URL(href);
311
- url.searchParams.delete(LINK_PARAMETER);
312
- return url.toString();
313
- }
314
- // ../core/src/restore.ts
315
- var READY_POLL_MS = 50;
316
- function waitForTarget(target, scope, root, {
317
- timeoutMs = 3000,
318
- signal,
319
- isCandidate,
320
- ready
321
- } = {}) {
322
- return new Promise((resolve) => {
323
- const isReady = () => ready === undefined || ready();
324
- let last = locateTarget(target, scope, root, isCandidate);
325
- if (last.status === "found" && isReady() || signal?.aborted)
326
- return resolve(last);
327
- const check = () => {
328
- last = locateTarget(target, scope, root, isCandidate);
329
- if (last.status === "found" && isReady())
330
- finish();
331
- };
332
- const finish = () => {
333
- observer.disconnect();
334
- clearTimeout(timer);
335
- clearInterval(poll);
336
- signal?.removeEventListener("abort", finish);
337
- resolve(last);
338
- };
339
- const observer = new MutationObserver(check);
340
- observer.observe(root, { childList: true, subtree: true, attributes: true });
341
- const poll = ready === undefined ? undefined : setInterval(check, READY_POLL_MS);
342
- const timer = setTimeout(finish, timeoutMs);
343
- signal?.addEventListener("abort", finish);
344
- });
345
- }
346
- // ../core/src/ai.ts
347
- var AI_PROVIDERS = [
348
- { id: "openai", label: "OpenAI", needsKey: true },
349
- { id: "anthropic", label: "Anthropic", needsKey: true },
350
- { id: "google", label: "Google Gemini", needsKey: true },
351
- { id: "gateway", label: "Vercel AI Gateway", needsKey: true },
352
- { id: "compatible", label: "OpenAI-compatible endpoint", needsKey: false }
353
- ];
354
- export {
355
- AI_PROVIDERS,
356
- DEFAULT_FILTERS,
357
- EXPORT_SCHEMA_VERSION,
358
- LINK_PARAMETER,
359
- MAX_MESSAGE_HASHTAGS,
360
- MAX_TAG_LENGTH,
361
- MAX_TAG_LIST,
362
- MAX_THREAD_TAGS,
363
- MAX_THREAD_TEXT_TAGS,
364
- PURPOSE_ATTRIBUTE,
365
- REACTIONS,
366
- RECORD_ATTRIBUTE,
367
- buildLink,
368
- cleanTagLabel,
369
- describeTarget,
370
- expandTagFilter,
371
- exportJson,
372
- exportMarkdown,
373
- groupThreads,
374
- hasTag,
375
- hashtagLabels,
376
- isUnread,
377
- locateTarget,
378
- parseHashtags,
379
- parseLink,
380
- recordKeyOf,
381
- removeLink,
382
- tagKey,
383
- uniqueTags,
384
- waitForTarget
385
- };