critiqs-react 0.0.0-stage → 0.3.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 (64) hide show
  1. package/AGENT_SETUP.md +190 -0
  2. package/LICENSE +21 -0
  3. package/README.md +341 -2
  4. package/bin/cli.d.mts +21 -0
  5. package/bin/cli.mjs +293 -0
  6. package/bin/critiqs.mjs +4 -0
  7. package/bin/env.d.mts +41 -0
  8. package/bin/env.mjs +384 -0
  9. package/bin/init.d.mts +126 -0
  10. package/bin/init.mjs +965 -0
  11. package/bin/mcp.d.mts +20 -0
  12. package/bin/mcp.mjs +314 -0
  13. package/bin/setup.d.mts +183 -0
  14. package/bin/setup.mjs +1054 -0
  15. package/dist/Critiqs.d.ts +9 -0
  16. package/dist/backend/convex/_generated/api.d.ts +95 -0
  17. package/dist/backend/convex/_generated/api.js +23 -0
  18. package/dist/backend/convex/_generated/dataModel.d.ts +60 -0
  19. package/dist/backend/convex/_generated/server.d.ts +162 -0
  20. package/dist/backend/convex/_generated/server.js +101 -0
  21. package/dist/backend/convex/ai.ts +93 -0
  22. package/dist/backend/convex/aiSettings.ts +43 -0
  23. package/dist/backend/convex/auth.config.ts +18 -0
  24. package/dist/backend/convex/captureHttp.ts +96 -0
  25. package/dist/backend/convex/captures.ts +167 -0
  26. package/dist/backend/convex/crons.ts +14 -0
  27. package/dist/backend/convex/deviceSignIn.ts +151 -0
  28. package/dist/backend/convex/grouping.ts +41 -0
  29. package/dist/backend/convex/http.ts +724 -0
  30. package/dist/backend/convex/lib/ai.ts +6 -0
  31. package/dist/backend/convex/lib/links.ts +12 -0
  32. package/dist/backend/convex/lib/pages.ts +207 -0
  33. package/dist/backend/convex/lib/r2.ts +75 -0
  34. package/dist/backend/convex/lib/store.ts +509 -0
  35. package/dist/backend/convex/lib/tokens.ts +101 -0
  36. package/dist/backend/convex/lib/validators.ts +73 -0
  37. package/dist/backend/convex/lib/vendor/aws4fetch.js +289 -0
  38. package/dist/backend/convex/lib/vendor/critiqs_ai.js +49081 -0
  39. package/dist/backend/convex/lib/vendor/critiqs_core.js +385 -0
  40. package/dist/backend/convex/lib/vendor/critiqs_server.js +3108 -0
  41. package/dist/backend/convex/notificationEmails.ts +61 -0
  42. package/dist/backend/convex/notifications.ts +182 -0
  43. package/dist/backend/convex/plans.ts +67 -0
  44. package/dist/backend/convex/projects.ts +46 -0
  45. package/dist/backend/convex/schema.ts +343 -0
  46. package/dist/backend/convex/search.ts +26 -0
  47. package/dist/backend/convex/signIn.ts +368 -0
  48. package/dist/backend/convex/tags.ts +68 -0
  49. package/dist/backend/convex/threads.ts +146 -0
  50. package/dist/backend/convex/users.ts +13 -0
  51. package/dist/constants.d.ts +4 -0
  52. package/dist/core/types.d.ts +72 -0
  53. package/dist/host.d.ts +66 -0
  54. package/dist/index.d.ts +4 -0
  55. package/dist/index.js +8076 -0
  56. package/dist/server/chunks/driver-n9zpr0k3.js +21 -0
  57. package/dist/server/chunks/index-9bg7tmnq.js +522 -0
  58. package/dist/server/chunks/index-askcfn7t.js +148 -0
  59. package/dist/server/chunks/providers-rv184xvj.js +48444 -0
  60. package/dist/server/chunks/token-kzddms7r.js +63 -0
  61. package/dist/server/chunks/token-util-k8bee1wc.js +4 -0
  62. package/dist/server/index.d.ts +87 -0
  63. package/dist/server/index.js +4889 -0
  64. package/package.json +77 -4
package/bin/env.mjs ADDED
@@ -0,0 +1,384 @@
1
+ /**
2
+ * How a React app reads its Critiqs project ID from its environment: the
3
+ * framework that builds it, the variable's name, the `.env` files it loads,
4
+ * and the workspace it belongs to. Init writes the variable; each deployment
5
+ * sets its own, so only correctly configured copies of the app show Critiqs.
6
+ * Dependency-free so it runs under Node and Bun without a build.
7
+ */
8
+ import { spawnSync } from "node:child_process";
9
+ import { createHash } from "node:crypto";
10
+ import { accessSync, constants, existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
11
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
12
+
13
+ /** Frameworks whose public environment variables reach the browser build, and how code reads them. */
14
+ export const FRAMEWORKS = {
15
+ next: { name: "Next.js", access: "process.env", prefix: "NEXT_PUBLIC_" },
16
+ vite: { name: "Vite", access: "import.meta.env", prefix: "VITE_" },
17
+ };
18
+
19
+ /** The `.env` files frameworks load during development, highest precedence first. */
20
+ export const ENV_FILES = [".env.development.local", ".env.local", ".env.development", ".env"];
21
+ /** Of those, the ones that stay on one computer. */
22
+ const LOCAL_FILES = new Set([".env.development.local", ".env.local"]);
23
+
24
+ const posix = (path) => path.split(sep).join("/");
25
+
26
+ function readJson(path) {
27
+ try {
28
+ return JSON.parse(readFileSync(path, "utf8"));
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ function isDirectory(path) {
35
+ try {
36
+ return statSync(path).isDirectory();
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ const CONFIG_EXTENSIONS = ["ts", "mts", "js", "mjs", "cts", "cjs"];
43
+ const configFile = (root, name) => CONFIG_EXTENSIONS.map((extension) => join(root, `${name}.config.${extension}`)).find((path) => existsSync(path)) ?? null;
44
+
45
+ /** "next", "vite", or null for a build init doesn't know how to give public settings to. */
46
+ export function detectFramework(root) {
47
+ const manifest = readJson(join(root, "package.json")) ?? {};
48
+ const dependencies = { ...manifest.devDependencies, ...manifest.dependencies };
49
+ if ("next" in dependencies || configFile(root, "next") !== null) return "next";
50
+ if ("vite" in dependencies || configFile(root, "vite") !== null) return "vite";
51
+ return null;
52
+ }
53
+
54
+ /**
55
+ * Where a Vite app loads `.env` files: its own folder, or the `envDir` its
56
+ * config names as a literal path or `resolve(__dirname, "…")`. `known` is false
57
+ * when `envDir` is computed some other way, which init can't follow.
58
+ */
59
+ function viteSettings(root) {
60
+ const file = configFile(root, "vite");
61
+ if (file === null) return { envDir: root, known: true, customPrefix: false };
62
+ let text = "";
63
+ try {
64
+ text = readFileSync(file, "utf8");
65
+ } catch {
66
+ return { envDir: root, known: false, customPrefix: false, config: file };
67
+ }
68
+ const customPrefix = /\benvPrefix\b/.test(text);
69
+ const mentions = text.match(/\benvDir\b/g) ?? [];
70
+ if (mentions.length === 0) return { envDir: root, known: true, customPrefix, config: file };
71
+ const base = dirname(file);
72
+ const literal = /\benvDir\s*:\s*(["'`])([^"'`$\n]*)\1/.exec(text);
73
+ const resolved = /\benvDir\s*:\s*(?:path\.)?(?:resolve|join)\(\s*(?:__dirname|import\.meta\.dirname)\s*((?:,\s*(["'])[^"'\n]*\2\s*)*),?\s*\)/.exec(text);
74
+ const fromUrl = /\benvDir\s*:\s*fileURLToPath\(\s*new\s+URL\(\s*(["'])([^"'\n]*)\1\s*,\s*import\.meta\.url\s*\)\s*\)/.exec(text);
75
+ if (mentions.length === 1 && literal !== null) return { envDir: resolve(base, literal[2]), known: true, customPrefix, config: file };
76
+ if (mentions.length === 1 && resolved !== null) {
77
+ const parts = [...resolved[1].matchAll(/(["'])([^"'\n]*)\1/g)].map((match) => match[2]);
78
+ return { envDir: resolve(base, ...parts), known: true, customPrefix, config: file };
79
+ }
80
+ if (mentions.length === 1 && fromUrl !== null) return { envDir: resolve(base, fromUrl[2]), known: true, customPrefix, config: file };
81
+ return { envDir: root, known: false, customPrefix, config: file };
82
+ }
83
+
84
+ // ---------------------------------------------------------------------------
85
+ // Workspaces
86
+
87
+ /** The package patterns a folder's workspace declares (npm, Yarn, Bun, or pnpm), or null when it declares none. */
88
+ export function workspacePatterns(dir) {
89
+ const manifest = readJson(join(dir, "package.json"));
90
+ const declared = Array.isArray(manifest?.workspaces) ? manifest.workspaces : Array.isArray(manifest?.workspaces?.packages) ? manifest.workspaces.packages : null;
91
+ let pnpm = null;
92
+ try {
93
+ const yaml = readFileSync(join(dir, "pnpm-workspace.yaml"), "utf8");
94
+ const block = /^packages:\s*\n((?:[ \t]+[^\n]*\n?|\s*\n)*)/m.exec(yaml)?.[1] ?? "";
95
+ pnpm = [...block.matchAll(/^[ \t]+-[ \t]*(["']?)([^"'#\n]+?)\1[ \t]*(?:#.*)?$/gm)].map((match) => match[2]);
96
+ } catch {}
97
+ if (declared === null && pnpm === null) return null;
98
+ return [...(declared ?? []), ...(pnpm ?? [])].filter((pattern) => typeof pattern === "string");
99
+ }
100
+
101
+ /** The package folders a workspace's patterns match: `dir/*`, `dir/**`, and literal folders, excluding `!` patterns. */
102
+ export function workspaceMembers(workspaceRoot, patterns = workspacePatterns(workspaceRoot) ?? []) {
103
+ const found = new Set();
104
+ const segment = (part) => new RegExp(`^${part.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("*", "[^/]*").replaceAll("?", "[^/]")}$`);
105
+ const children = (dir) => {
106
+ try {
107
+ return readdirSync(dir, { withFileTypes: true })
108
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
109
+ .map((entry) => entry.name)
110
+ .sort();
111
+ } catch {
112
+ return [];
113
+ }
114
+ };
115
+ const expand = (dir, parts, depth) => {
116
+ if (parts.length === 0) {
117
+ if (existsSync(join(dir, "package.json"))) found.add(resolve(dir));
118
+ return;
119
+ }
120
+ const [part, ...rest] = parts;
121
+ if (part === "**") {
122
+ expand(dir, rest, depth);
123
+ if (depth < 6) for (const child of children(dir)) expand(join(dir, child), parts, depth + 1);
124
+ } else if (/[*?]/.test(part)) {
125
+ const pattern = segment(part);
126
+ for (const child of children(dir)) if (pattern.test(child)) expand(join(dir, child), rest, depth);
127
+ } else if (part !== "" && part !== ".") {
128
+ expand(join(dir, part), rest, depth);
129
+ } else {
130
+ expand(dir, rest, depth);
131
+ }
132
+ };
133
+ const excluded = new Set();
134
+ for (const pattern of patterns) {
135
+ const negated = pattern.startsWith("!");
136
+ const parts = posix(pattern.replace(/^!/, "").replace(/^\.\//, "").replace(/\/+$/, "")).split("/");
137
+ if (negated) {
138
+ const before = new Set(found);
139
+ found.clear();
140
+ expand(workspaceRoot, parts, 0);
141
+ for (const dir of found) excluded.add(dir);
142
+ found.clear();
143
+ for (const dir of before) found.add(dir);
144
+ } else {
145
+ expand(workspaceRoot, parts, 0);
146
+ }
147
+ }
148
+ return [...found].filter((dir) => !excluded.has(dir) && dir !== resolve(workspaceRoot)).sort();
149
+ }
150
+
151
+ /** The workspace an app folder belongs to: the nearest enclosing folder declaring workspaces, within its repository. */
152
+ export function findWorkspace(root) {
153
+ const start = resolve(root);
154
+ if (existsSync(join(start, ".git"))) return null;
155
+ for (let dir = dirname(start); ; dir = dirname(dir)) {
156
+ const patterns = workspacePatterns(dir);
157
+ if (patterns !== null) return { root: dir, patterns };
158
+ if (existsSync(join(dir, ".git")) || dirname(dir) === dir) return null;
159
+ }
160
+ }
161
+
162
+ const packageName = (dir) => {
163
+ const name = readJson(join(dir, "package.json"))?.name;
164
+ return typeof name === "string" && name.trim() !== "" ? name.trim() : null;
165
+ };
166
+ const shortName = (dir) => packageName(dir)?.replace(/^@[^/]+\//, "") ?? basename(resolve(dir));
167
+
168
+ /**
169
+ * The app's name within its workspace: its package name without a scope, or
170
+ * its folder's, unless another workspace package has the same one; then its
171
+ * path from the workspace root, which is unique.
172
+ */
173
+ function workspaceLabel(root, workspace, members = workspaceMembers(workspace.root, workspace.patterns)) {
174
+ const own = shortName(root);
175
+ const others = members.filter((dir) => dir !== resolve(root));
176
+ if (!others.some((dir) => shortName(dir).toLowerCase() === own.toLowerCase())) return own;
177
+ return posix(relative(workspace.root, root));
178
+ }
179
+
180
+ const variableSuffix = (label) => label.toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
181
+
182
+ /** Resolve collisions after normalization, including paths such as apps/a-b and apps/a_b. */
183
+ function workspaceSuffix(root, workspace, members) {
184
+ const entries = [...new Set([...members, resolve(root)])].map((dir) => ({
185
+ dir,
186
+ suffix: variableSuffix(workspaceLabel(dir, workspace, members)),
187
+ }));
188
+ const names = entries.map(({ dir, suffix }) => ({
189
+ dir,
190
+ suffix: entries.some((entry) => entry.dir !== dir && entry.suffix === suffix)
191
+ ? `${suffix}_${createHash("sha256").update(posix(relative(workspace.root, dir))).digest("hex").slice(0, 12).toUpperCase()}`
192
+ : suffix,
193
+ }));
194
+ const own = names.find((entry) => entry.dir === resolve(root));
195
+ // A generated name could also match another package's literal name. Refuse rather than overwrite it.
196
+ return names.some((entry) => entry.dir !== own.dir && entry.suffix === own.suffix) ? null : own.suffix;
197
+ }
198
+
199
+ /**
200
+ * Everything init needs to give one app its project ID through the
201
+ * environment, without reading anything the app computes at run time:
202
+ * - `framework`: "next", "vite", or null (init then writes the ID into the code);
203
+ * - `variable`: the name init gives the setting. In a workspace it names the
204
+ * app, so a value shared across the workspace (a root `.env`, or a build
205
+ * job's settings) can't configure every app with one project;
206
+ * - `envDir` and `envFile`: where the setting is written for this computer;
207
+ * - `problem`: why init can't choose these safely, with what to do instead.
208
+ */
209
+ export function describeApp(root, { envFile = null } = {}) {
210
+ const framework = detectFramework(root);
211
+ const workspace = findWorkspace(root);
212
+ const members = workspace === null ? [] : workspaceMembers(workspace.root, workspace.patterns);
213
+ const label = workspace === null ? null : workspaceLabel(root, workspace, members);
214
+ const workspaceName = workspace === null ? null : shortName(workspace.root);
215
+ const app = {
216
+ root: resolve(root),
217
+ framework,
218
+ workspace: workspace === null ? null : { root: workspace.root, name: workspaceName, label },
219
+ projectName: workspace === null ? shortName(root) : `${workspaceName}/${label}`,
220
+ envDir: resolve(root),
221
+ envFile: envFile === null ? null : resolve(root, envFile),
222
+ sharedEnv: false,
223
+ variable: null,
224
+ access: null,
225
+ problem: null,
226
+ };
227
+ if (framework === null) return app;
228
+ const { access, prefix } = FRAMEWORKS[framework];
229
+ app.access = access;
230
+ const suffix = workspace === null ? "" : workspaceSuffix(root, workspace, members);
231
+ if (suffix === null) {
232
+ app.problem = "Workspace apps would use the same Critiqs environment variable. Choose distinct package names or wire distinct public project-ID variables before running init.";
233
+ return app;
234
+ }
235
+ app.variable = `${prefix}CRITIQS_PROJECT_ID${label === null ? "" : `_${suffix}`}`;
236
+ if (framework === "vite") {
237
+ const vite = viteSettings(root);
238
+ app.envDir = vite.envDir;
239
+ app.customPrefix = vite.customPrefix;
240
+ if (!vite.known && app.envFile === null) {
241
+ app.problem =
242
+ `${posix(relative(root, vite.config ?? root)) || "vite.config"} sets envDir in a way init can't follow, so it doesn't know which .env file this app loads. ` +
243
+ "Run init again with --project-env-file <the .env.local file Vite loads, relative to the app>, and nothing else changes.";
244
+ }
245
+ }
246
+ app.sharedEnv = app.envDir !== app.root;
247
+ return app;
248
+ }
249
+
250
+ /**
251
+ * The variable an expression reads, when it is exactly one public setting of
252
+ * the app's framework: `import.meta.env.VITE_…` in Vite, or
253
+ * `process.env.NEXT_PUBLIC_…` in Next.js. Anything else is code init doesn't
254
+ * evaluate.
255
+ */
256
+ export function envVariableOf(text, app) {
257
+ if (typeof text !== "string" || app.framework === null) return null;
258
+ const match = /^\s*(import\.meta\.env|process\.env)\.([A-Za-z_][A-Za-z0-9_]*)\s*$/.exec(text);
259
+ if (match === null || match[1] !== FRAMEWORKS[app.framework].access) return null;
260
+ // Vite exposes only its prefix, unless the app changed it (then the author chose the name).
261
+ if (!match[2].startsWith(FRAMEWORKS[app.framework].prefix) && !(app.framework === "vite" && app.customPrefix)) return null;
262
+ return match[2];
263
+ }
264
+
265
+ // ---------------------------------------------------------------------------
266
+ // .env files
267
+
268
+ const DEFINITION = /^[ \t]*(export[ \t]+)?([A-Za-z_][A-Za-z0-9_.-]*)[ \t]*=(.*)$/;
269
+
270
+ /** A `.env` value as frameworks read it: quotes removed, or an unquoted value without its trailing comment. */
271
+ function envValue(raw) {
272
+ const text = raw.trim();
273
+ const quoted = /^(["'`])(.*)\1/.exec(text);
274
+ if (quoted !== null) return quoted[2];
275
+ return text.replace(/\s+#.*$/, "").trim();
276
+ }
277
+
278
+ function readText(path) {
279
+ try {
280
+ return readFileSync(path, "utf8");
281
+ } catch (error) {
282
+ if (error?.code === "ENOENT") return null;
283
+ throw error;
284
+ }
285
+ }
286
+
287
+ /** The `.env` files to read for this app on this computer, highest precedence first. */
288
+ export function envFiles(app) {
289
+ const files = ENV_FILES.map((name) => join(app.envDir, name));
290
+ return app.envFile === null ? files : [app.envFile, ...files.filter((file) => file !== app.envFile)];
291
+ }
292
+
293
+ /** Where this computer's `.env` files set a variable: the value and file that win, or null. */
294
+ export function readEnvValue(app, name) {
295
+ for (const file of envFiles(app)) {
296
+ const text = readText(file);
297
+ if (text === null) continue;
298
+ let value = null;
299
+ for (const line of text.split(/\r?\n/)) {
300
+ const match = DEFINITION.exec(line);
301
+ // The last definition in a file wins.
302
+ if (match !== null && match[2] === name) value = envValue(match[3]);
303
+ }
304
+ if (value !== null) return { value, file };
305
+ }
306
+ return null;
307
+ }
308
+
309
+ /** How many times a file's text defines a variable. */
310
+ const definitions = (text, name) => (text ?? "").split(/\r?\n/).filter((line) => DEFINITION.exec(line)?.[2] === name).length;
311
+
312
+ /** Sets `name=value` in one file's text, replacing its definitions and keeping every other line as it is. */
313
+ function setInText(text, name, value, comment) {
314
+ const eol = text?.includes("\r\n") ? "\r\n" : "\n";
315
+ if (text === null || text === "") return `${comment === null ? "" : `# ${comment}${eol}`}${name}=${value}${eol}`;
316
+ const lines = text.split(/\r?\n/);
317
+ let found = false;
318
+ const updated = lines.map((line) => {
319
+ const match = DEFINITION.exec(line);
320
+ if (match === null || match[2] !== name) return line;
321
+ found = true;
322
+ return `${match[1] ?? ""}${name}=${value}`;
323
+ });
324
+ if (found) return updated.join(eol);
325
+ const separator = text.endsWith("\n") ? "" : eol;
326
+ return `${text}${separator}${comment === null ? "" : `# ${comment}${eol}`}${name}=${value}${eol}`;
327
+ }
328
+
329
+ /**
330
+ * Plans this computer's setting: `name=value` in the local `.env` file that
331
+ * already sets it with the highest precedence, or else the app's `.env.local`
332
+ * (or `--project-env-file`), plus an empty entry in the `.env.example` beside it for
333
+ * the next developer and each deployment. Writes nothing.
334
+ */
335
+ export function planEnv(app, name, value) {
336
+ const local =
337
+ app.envFile ??
338
+ ENV_FILES.filter((file) => LOCAL_FILES.has(file))
339
+ .map((file) => join(app.envDir, file))
340
+ .find((file) => definitions(readText(file), name) > 0) ??
341
+ join(app.envDir, ".env.local");
342
+ const original = readText(local);
343
+ const source = setInText(original, name, value, `Critiqs project for ${app.workspace?.label ?? "this app"} on this computer. Each deployment sets its own.`);
344
+ const exampleFile = join(dirname(local), ".env.example");
345
+ const exampleOriginal = readText(exampleFile);
346
+ const listed = definitions(exampleOriginal, name) > 0;
347
+ const example = listed
348
+ ? null
349
+ : {
350
+ file: exampleFile,
351
+ original: exampleOriginal,
352
+ source: setInText(exampleOriginal, name, "", `Critiqs project ID for ${app.workspace?.label ?? "this app"}. Set it in each deployment that should show Critiqs; leave it unset to keep Critiqs off.`),
353
+ };
354
+ return { name, value, file: local, original, source, changed: source !== original, example };
355
+ }
356
+
357
+ /** Throws unless `file` can be written: the file itself, or its folder when it doesn't exist yet. */
358
+ export function checkWritable(file) {
359
+ accessSync(existsSync(file) ? file : dirname(file), constants.W_OK);
360
+ if (!isDirectory(dirname(file))) throw new Error(`${dirname(file)} is not a folder.`);
361
+ }
362
+
363
+ /** Writes an env plan's local file, then its example; the example is a convenience, so only the first can fail the plan. */
364
+ export function applyEnv(plan) {
365
+ if (plan.changed) writeFileSync(plan.file, plan.source);
366
+ let example = null;
367
+ if (plan.example !== null) {
368
+ try {
369
+ writeFileSync(plan.example.file, plan.example.source);
370
+ example = plan.example.file;
371
+ } catch {}
372
+ }
373
+ return { example };
374
+ }
375
+
376
+ /** Whether Git ignores a file (true), tracks or would commit it (false), or can't tell (null). */
377
+ export function gitIgnored(file) {
378
+ try {
379
+ const result = spawnSync("git", ["check-ignore", "-q", basename(file)], { cwd: dirname(file), stdio: "ignore" });
380
+ return result.status === 0 ? true : result.status === 1 ? false : null;
381
+ } catch {
382
+ return null;
383
+ }
384
+ }
package/bin/init.d.mts ADDED
@@ -0,0 +1,126 @@
1
+ export declare const PROJECT_ID_PATTERN: RegExp;
2
+ export declare const SOURCE_EXTENSIONS: ReadonlySet<string>;
3
+ export declare const IGNORED_DIRECTORIES: ReadonlySet<string>;
4
+ export declare const HELP: string;
5
+ import type { AppEnvironment } from "./env.mjs";
6
+
7
+ /** A property as init writes it: a string literal, code such as `import.meta.env.VITE_…`, or `true` for a bare attribute. */
8
+ export type PropValue = string | { expression: string } | true;
9
+ export type Props = Record<string, PropValue>;
10
+
11
+ export type Wiring =
12
+ | { mode: "literal"; app: AppEnvironment; problem?: undefined }
13
+ | { mode: "env"; app: AppEnvironment; variable?: string; addFlag?: boolean; problem: string | null };
14
+
15
+ export interface JsxAttribute {
16
+ name: string;
17
+ start: number;
18
+ nameEnd: number;
19
+ /** null for a bare attribute such as `<Critiqs projectId />`. */
20
+ value: { kind: "string" | "expression" | "element"; start: number; end: number } | null;
21
+ }
22
+
23
+ export interface JsxElement {
24
+ /** Index of `<`. */
25
+ start: number;
26
+ /** Index right after the tag name. */
27
+ nameEnd: number;
28
+ /** Index right after the opening element's `>`. */
29
+ end: number;
30
+ line: number;
31
+ attributes: JsxAttribute[];
32
+ /** Index right after the last spread prop such as `{...props}`, or null when there is none. */
33
+ spreadEnd: number | null;
34
+ }
35
+
36
+ export type ProjectIdPlan =
37
+ | { action: "insert" | "replace"; source: string; line: number }
38
+ | { action: "unchanged" | "expression" | "spread"; line: number };
39
+
40
+ export interface InitOptions {
41
+ help: boolean;
42
+ command: string | null;
43
+ projectId: string | null;
44
+ dir: string;
45
+ entry: string | null;
46
+ mount: string | null;
47
+ envFile: string | null;
48
+ dryRun: boolean;
49
+ }
50
+
51
+ /** Any JSX element, with where its children close (`close` is null for `<X />`). */
52
+ export interface AnyJsxElement {
53
+ name: string;
54
+ start: number;
55
+ openEnd: number;
56
+ end: number;
57
+ /** How many elements enclose it. */
58
+ depth: number;
59
+ close: { start: number; end: number } | null;
60
+ }
61
+
62
+ export type MountKind = "next-app" | "next-pages" | "react-root" | "chosen";
63
+ export declare const MOUNT_KINDS: Record<MountKind, string>;
64
+ export interface MountPoint {
65
+ kind: MountKind;
66
+ element: AnyJsxElement;
67
+ line: number;
68
+ }
69
+
70
+ export type ComponentPlan =
71
+ | {
72
+ ok: true;
73
+ action: "install" | "update" | "unchanged";
74
+ file: string;
75
+ original: string;
76
+ source: string;
77
+ line: number;
78
+ changed: string[];
79
+ kind?: MountKind;
80
+ imported?: boolean;
81
+ preview?: string[];
82
+ }
83
+ | { ok: false; reason: string; [detail: string]: unknown };
84
+
85
+ export declare function isValidProjectId(id: string): boolean;
86
+ export declare function findSourceFiles(root: string): string[];
87
+ export declare function scanSource(
88
+ source: string,
89
+ options?: { jsx?: boolean; tagName?: string },
90
+ ): { elements: JsxElement[]; all: AnyJsxElement[]; comments: [number, number][]; literals: [number, number][] };
91
+ export declare function lineAt(source: string, index: number): number;
92
+ /** `excluded` ranges (comments and strings) default to those found by `scanSource`. */
93
+ export declare function importsCritiqs(source: string, excluded?: [number, number][]): boolean;
94
+ export declare function findCritiqsElements(source: string, options?: { jsx?: boolean }): JsxElement[];
95
+ export declare function planProp(source: string, element: JsxElement, name: string, value: PropValue): ProjectIdPlan;
96
+ export declare function planProjectId(source: string, element: JsxElement, projectId: string): ProjectIdPlan;
97
+ export declare function readProp(
98
+ source: string,
99
+ element: JsxElement,
100
+ name: string,
101
+ ): { kind: "literal"; value: string } | { kind: "expression"; text?: string } | null;
102
+ export declare function findCritiqsUsages(root: string): { file: string; source: string; element: JsxElement }[];
103
+ export declare function parseArguments(argv: string[]): InitOptions | { error: string };
104
+ export declare function runInit(argv: string[], options?: { cwd?: string; print?: (message: string) => void }): number;
105
+ export declare function mountPointsIn(source: string, path: string, options?: { mount?: string | null; explicit?: boolean }): MountPoint[];
106
+ export declare function findMountPoints(
107
+ root: string,
108
+ options?: { entry?: string | null; mount?: string | null },
109
+ ): (MountPoint & { file: string; source: string })[];
110
+ export declare function changedLines(before: string, after: string): string[];
111
+ export declare function propsText(props: Props): string;
112
+ export declare function planInstall(root: string, props: Props, options?: { entry?: string | null; mount?: string | null }): ComponentPlan;
113
+ export declare function planComponent(root: string, props: Props, options?: { entry?: string | null; mount?: string | null }): ComponentPlan;
114
+ export declare function applyPlan(plan: ComponentPlan): void;
115
+ export declare function manualInstructions(props: Props): string;
116
+ export declare function refusal(
117
+ plan: ComponentPlan & { ok: false },
118
+ props: Props,
119
+ where: (file: string, line: number) => string,
120
+ folder: string,
121
+ ): string;
122
+ export declare function chooseWiring(root: string, options?: { envFile?: string | null }): Wiring;
123
+ export declare function connectionProps(wiring: Wiring, projectId: string, backend?: string | null): Props;
124
+ export declare function deploymentAdvice(wiring: Wiring): string;
125
+ export declare function workspaceApps(root: string): string[] | null;
126
+ export declare function workspaceRefusal(apps: string[], folder: string, show: (dir: string) => string, command: string): string;