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.
- package/AGENT_SETUP.md +190 -0
- package/LICENSE +21 -0
- package/README.md +341 -2
- package/bin/cli.d.mts +21 -0
- package/bin/cli.mjs +293 -0
- package/bin/critiqs.mjs +4 -0
- package/bin/env.d.mts +41 -0
- package/bin/env.mjs +384 -0
- package/bin/init.d.mts +126 -0
- package/bin/init.mjs +965 -0
- package/bin/mcp.d.mts +20 -0
- package/bin/mcp.mjs +314 -0
- package/bin/setup.d.mts +183 -0
- package/bin/setup.mjs +1054 -0
- package/dist/Critiqs.d.ts +9 -0
- package/dist/backend/convex/_generated/api.d.ts +95 -0
- package/dist/backend/convex/_generated/api.js +23 -0
- package/dist/backend/convex/_generated/dataModel.d.ts +60 -0
- package/dist/backend/convex/_generated/server.d.ts +162 -0
- package/dist/backend/convex/_generated/server.js +101 -0
- package/dist/backend/convex/ai.ts +93 -0
- package/dist/backend/convex/aiSettings.ts +43 -0
- package/dist/backend/convex/auth.config.ts +18 -0
- package/dist/backend/convex/captureHttp.ts +96 -0
- package/dist/backend/convex/captures.ts +167 -0
- package/dist/backend/convex/crons.ts +14 -0
- package/dist/backend/convex/deviceSignIn.ts +151 -0
- package/dist/backend/convex/grouping.ts +41 -0
- package/dist/backend/convex/http.ts +724 -0
- package/dist/backend/convex/lib/ai.ts +6 -0
- package/dist/backend/convex/lib/links.ts +12 -0
- package/dist/backend/convex/lib/pages.ts +207 -0
- package/dist/backend/convex/lib/r2.ts +75 -0
- package/dist/backend/convex/lib/store.ts +509 -0
- package/dist/backend/convex/lib/tokens.ts +101 -0
- package/dist/backend/convex/lib/validators.ts +73 -0
- package/dist/backend/convex/lib/vendor/aws4fetch.js +289 -0
- package/dist/backend/convex/lib/vendor/critiqs_ai.js +49081 -0
- package/dist/backend/convex/lib/vendor/critiqs_core.js +385 -0
- package/dist/backend/convex/lib/vendor/critiqs_server.js +3108 -0
- package/dist/backend/convex/notificationEmails.ts +61 -0
- package/dist/backend/convex/notifications.ts +182 -0
- package/dist/backend/convex/plans.ts +67 -0
- package/dist/backend/convex/projects.ts +46 -0
- package/dist/backend/convex/schema.ts +343 -0
- package/dist/backend/convex/search.ts +26 -0
- package/dist/backend/convex/signIn.ts +368 -0
- package/dist/backend/convex/tags.ts +68 -0
- package/dist/backend/convex/threads.ts +146 -0
- package/dist/backend/convex/users.ts +13 -0
- package/dist/constants.d.ts +4 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/host.d.ts +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8076 -0
- package/dist/server/chunks/driver-n9zpr0k3.js +21 -0
- package/dist/server/chunks/index-9bg7tmnq.js +522 -0
- package/dist/server/chunks/index-askcfn7t.js +148 -0
- package/dist/server/chunks/providers-rv184xvj.js +48444 -0
- package/dist/server/chunks/token-kzddms7r.js +63 -0
- package/dist/server/chunks/token-util-k8bee1wc.js +4 -0
- package/dist/server/index.d.ts +87 -0
- package/dist/server/index.js +4889 -0
- package/package.json +77 -4
package/bin/mcp.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ToolResult {
|
|
2
|
+
content: { type: "text"; text: string }[];
|
|
3
|
+
isError?: boolean;
|
|
4
|
+
/** The same result as data, for agents that read it. */
|
|
5
|
+
structuredContent?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare const TOOLS: { name: string; description: string; inputSchema: Record<string, unknown> }[];
|
|
8
|
+
export declare function createTools(options?: {
|
|
9
|
+
cwd?: string;
|
|
10
|
+
env?: Record<string, string | undefined>;
|
|
11
|
+
open?: (url: string) => void;
|
|
12
|
+
fetchFn?: typeof fetch;
|
|
13
|
+
sleep?: (ms: number) => Promise<void>;
|
|
14
|
+
}): { call(name: string, args?: Record<string, unknown>): Promise<ToolResult>; close(): void };
|
|
15
|
+
export declare function handleMessage(
|
|
16
|
+
message: unknown,
|
|
17
|
+
tools: { call(name: string, args?: Record<string, unknown>): Promise<ToolResult> },
|
|
18
|
+
version: string,
|
|
19
|
+
): Promise<Record<string, unknown> | null>;
|
|
20
|
+
export declare function serveMcp(options?: { cwd?: string; input?: NodeJS.ReadableStream; output?: NodeJS.WritableStream }): Promise<void>;
|
package/bin/mcp.mjs
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `critiqs mcp`: an MCP server over standard input and output that offers
|
|
3
|
+
* Critiqs's setup steps to coding agents. It runs the same setup code as the
|
|
4
|
+
* CLI. Keys are read from the server's environment, never from tool
|
|
5
|
+
* arguments, so they don't pass through the agent's conversation.
|
|
6
|
+
*/
|
|
7
|
+
import { createInterface } from "node:readline";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { runInit } from "./init.mjs";
|
|
10
|
+
import { beginSetup, CLOUD_BACKEND_URL, doctor, doctorReport, openBrowser, readiness, SetupError } from "./setup.mjs";
|
|
11
|
+
|
|
12
|
+
const INSTRUCTIONS = `Critiqs adds review comments to a running React prototype through one <Critiqs /> component from the critiqs-react package.
|
|
13
|
+
To set it up: install critiqs-react with the project's package manager, then call critiqs_setup_start. It adds <Critiqs /> where the app renders when the code has none (or name the file with entry), and keeps a project the code already names.
|
|
14
|
+
In Vite and Next.js apps the component reads its project ID from the app's public environment variable, which setup sets in .env.local; each deployment sets its own, and copies without one show nothing. In a workspace (monorepo), pass the app's folder as dir; each app gets its own project.
|
|
15
|
+
It returns either an address to open on this computer, or, with signIn "remote", an address and a short code the person can approve from any device. Pass them on exactly; then call critiqs_setup_finish until it reports the project.
|
|
16
|
+
Critiqs Cloud needs no keys. For the team's own Convex deployment, CONVEX_DEPLOY_KEY must be set in this MCP server's environment; never ask for keys in the conversation.
|
|
17
|
+
Call critiqs_doctor afterwards to check the setup. AI is optional; comments work without it.`;
|
|
18
|
+
|
|
19
|
+
const dirProperty = { type: "string", description: "The app's folder, relative to the project root. Default: the project root. In a workspace, name one app's folder." };
|
|
20
|
+
const envFileProperty = { type: "string", description: "The .env file setup writes or doctor checks, relative to dir, when the app reads its project ID from the environment. Default: the app's .env.local." };
|
|
21
|
+
|
|
22
|
+
export const TOOLS = [
|
|
23
|
+
{
|
|
24
|
+
name: "critiqs_setup_start",
|
|
25
|
+
description:
|
|
26
|
+
"Starts setting up Critiqs for the prototype: checks the code can take <Critiqs /> (adding it where the app renders when there is none), keeps a project the code already names, deploys to the team's own Convex when asked, and starts sign-in. Returns the address (and, for remote approval, the code) for the person.",
|
|
27
|
+
inputSchema: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
dir: dirProperty,
|
|
31
|
+
target: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: 'Where feedback lives: "cloud" (Critiqs Cloud, the default), "own-convex" (deploy to the team\'s Convex; needs CONVEX_DEPLOY_KEY in this server\'s environment), or the URL of an existing Critiqs backend.',
|
|
34
|
+
},
|
|
35
|
+
name: { type: "string", description: "Project name. Default: the app's package name." },
|
|
36
|
+
reviewUrl: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "The prototype's deployed https:// address, where mention emails link. Without it, add it later in the Critiqs sidebar's Project setup.",
|
|
39
|
+
},
|
|
40
|
+
signIn: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: ["auto", "browser", "remote"],
|
|
43
|
+
description:
|
|
44
|
+
'"browser" opens sign-in on this computer; "remote" returns an address and a code the person approves from a browser on any device (for remote machines and cloud agents). Default "auto": remote when this computer seems to have no browser.',
|
|
45
|
+
},
|
|
46
|
+
entry: { type: "string", description: "The file where the app renders, relative to dir, when the code has no <Critiqs /> yet." },
|
|
47
|
+
mount: { type: "string", description: "The element in entry to add <Critiqs /> beside, such as App." },
|
|
48
|
+
newProject: { type: "boolean", description: "Create a new project even if the code or the person's account already has one with this name." },
|
|
49
|
+
envFile: envFileProperty,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "critiqs_setup_finish",
|
|
55
|
+
description:
|
|
56
|
+
"Waits for the person to sign in or approve from critiqs_setup_start, then reuses their project with this name or creates one, and writes its ID (and backend, unless Critiqs Cloud) into the code. Reports each stage: code, project, trying it locally, and reviewers elsewhere. Call again while it reports waiting.",
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: { waitSeconds: { type: "number", description: "How long to wait for sign-in, up to 50 seconds. Default 45." } },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "critiqs_write_project_id",
|
|
64
|
+
description:
|
|
65
|
+
"Connects the prototype's <Critiqs /> component to an existing Critiqs project, adding the component where the app renders when there is none. In Vite and Next.js apps it sets the app's environment variable in .env.local; otherwise it writes the ID into the component.",
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
projectId: { type: "string", description: "The project ID from project setup in the Critiqs sidebar." },
|
|
70
|
+
dir: dirProperty,
|
|
71
|
+
dryRun: { type: "boolean", description: "Show the change without writing it." },
|
|
72
|
+
entry: { type: "string", description: "The file where the app renders, relative to dir, when the code has no <Critiqs /> yet." },
|
|
73
|
+
mount: { type: "string", description: "The element in entry to add <Critiqs /> beside, such as App." },
|
|
74
|
+
envFile: envFileProperty,
|
|
75
|
+
},
|
|
76
|
+
required: ["projectId"],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "critiqs_doctor",
|
|
81
|
+
description:
|
|
82
|
+
"Checks the prototype's Critiqs setup: the component and its settings, the backend's version, sign-in, the project, its review address, and whether mention emails are going out. Each check says whether it read configuration or something the backend observed; it never sends email or posts a comment.",
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: { dir: dirProperty, envFile: envFileProperty, backend: { type: "string", description: "Check this backend URL instead of the one the code names." } },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
/** Handles tool calls; holds the setup waiting for sign-in, if any. */
|
|
91
|
+
const lines = (checks) => checks.map((item) => `${item.status.toUpperCase()} ${item.name}: ${item.detail}`).join("\n");
|
|
92
|
+
|
|
93
|
+
export function createTools({ cwd = process.cwd(), env = process.env, open = openBrowser, fetchFn = fetch, sleep } = {}) {
|
|
94
|
+
/** The setup waiting for sign-in. Starting another replaces it. */
|
|
95
|
+
let pending = null;
|
|
96
|
+
/** Starts run one at a time, so two can't both become the pending setup. */
|
|
97
|
+
let starting = Promise.resolve();
|
|
98
|
+
let closed = false;
|
|
99
|
+
const text = (message, isError = false) => ({ content: [{ type: "text", text: message }], ...(isError ? { isError: true } : {}) });
|
|
100
|
+
const rootOf = (dir) => resolve(cwd, typeof dir === "string" && dir !== "" ? dir : ".");
|
|
101
|
+
|
|
102
|
+
function start(args) {
|
|
103
|
+
const run = starting.then(() => startNow(args));
|
|
104
|
+
starting = run.catch(() => {});
|
|
105
|
+
return run;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function startNow(args) {
|
|
109
|
+
if (closed) return text("The Critiqs MCP server is shutting down.", true);
|
|
110
|
+
pending?.setup.cancel();
|
|
111
|
+
pending = null;
|
|
112
|
+
const target = typeof args.target === "string" && args.target !== "" ? args.target : "cloud";
|
|
113
|
+
if (target === "own-convex" && !env.CONVEX_DEPLOY_KEY && !env.CONVEX_SELF_HOSTED_ADMIN_KEY) {
|
|
114
|
+
return text(
|
|
115
|
+
"Deploying to the team's own Convex needs CONVEX_DEPLOY_KEY (a production deploy key from the Convex project's settings) in this MCP server's environment. Ask the person to add it to the server's configuration, then try again. Don't ask for the key in the conversation.",
|
|
116
|
+
true,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const string = (value) => (typeof value === "string" && value !== "" ? value : undefined);
|
|
120
|
+
const setup = await beginSetup({
|
|
121
|
+
root: rootOf(args.dir),
|
|
122
|
+
cwd,
|
|
123
|
+
target: string(args.target) ?? null,
|
|
124
|
+
name: string(args.name),
|
|
125
|
+
reviewUrl: string(args.reviewUrl),
|
|
126
|
+
env,
|
|
127
|
+
fetchFn,
|
|
128
|
+
entry: string(args.entry) ?? null,
|
|
129
|
+
mount: string(args.mount) ?? null,
|
|
130
|
+
newProject: args.newProject === true,
|
|
131
|
+
signIn: ["browser", "remote"].includes(args.signIn) ? args.signIn : "auto",
|
|
132
|
+
envFile: string(args.envFile) ?? null,
|
|
133
|
+
...(sleep ? { sleep } : {}),
|
|
134
|
+
});
|
|
135
|
+
if (setup.connected) {
|
|
136
|
+
const report = doctorReport(await doctor({ root: rootOf(args.dir), cwd, fetchFn, env, envFile: string(args.envFile) ?? null }));
|
|
137
|
+
return {
|
|
138
|
+
...text(
|
|
139
|
+
`The code already uses Critiqs project ${setup.connected.projectId}${setup.connected.env ? ` (${setup.connected.env.name} in ${setup.connected.env.file})` : ""}, so nothing was created. Its checks:\n${lines(report.checks)}\n` +
|
|
140
|
+
"Call again with newProject: true only if the person wants a different project.",
|
|
141
|
+
!report.ok,
|
|
142
|
+
),
|
|
143
|
+
structuredContent: { connected: setup.connected, ...report },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const finished = setup.finish();
|
|
147
|
+
finished.catch(() => {});
|
|
148
|
+
pending = { setup, finished };
|
|
149
|
+
const where = setup.backendUrl === CLOUD_BACKEND_URL ? "Critiqs Cloud" : setup.backendUrl;
|
|
150
|
+
if (setup.method === "remote") {
|
|
151
|
+
return text(
|
|
152
|
+
`Ask the person to open ${setup.url} in a browser on any device, enter the code ${setup.userCode}, sign in, and choose Approve. ` +
|
|
153
|
+
`The code works for 10 minutes. Then call critiqs_setup_finish. Feedback will live on ${where}.`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
open(setup.url);
|
|
157
|
+
return text(
|
|
158
|
+
`Ask the person to open ${setup.url} on this computer and sign in to Critiqs (it may already be open in their browser). ` +
|
|
159
|
+
`If they aren't at this computer, start again with signIn "remote". Then call critiqs_setup_finish. Feedback will live on ${where}.`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function finish(args) {
|
|
164
|
+
await starting;
|
|
165
|
+
const current = pending;
|
|
166
|
+
if (current === null) return text("No setup is waiting. Call critiqs_setup_start first.", true);
|
|
167
|
+
const seconds = Math.min(Math.max(Number(args.waitSeconds) || 45, 1), 50);
|
|
168
|
+
let timer;
|
|
169
|
+
const outcome = await Promise.race([
|
|
170
|
+
current.finished.then((result) => ({ result }), (error) => ({ error })),
|
|
171
|
+
new Promise((done) => (timer = setTimeout(() => done({ waiting: true }), seconds * 1000))),
|
|
172
|
+
]);
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
if (outcome.waiting) {
|
|
175
|
+
return text(
|
|
176
|
+
current.setup.method === "remote"
|
|
177
|
+
? `Still waiting for approval at ${current.setup.url} with the code ${current.setup.userCode}. Call critiqs_setup_finish again.`
|
|
178
|
+
: `Still waiting for the person to sign in at ${current.setup.url}. Call critiqs_setup_finish again.`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
// Only the setup this call waited on is done; a newer one may have replaced it.
|
|
182
|
+
if (pending === current) pending = null;
|
|
183
|
+
if (outcome.error) throw outcome.error;
|
|
184
|
+
const { result } = outcome;
|
|
185
|
+
const stages = readiness(result);
|
|
186
|
+
return {
|
|
187
|
+
...text(
|
|
188
|
+
`${result.reused ? "Reused" : "Created"} the Critiqs project "${result.projectName}" (${result.projectId}).\n${lines(stages)}` +
|
|
189
|
+
(result.written.ok
|
|
190
|
+
? result.written.env
|
|
191
|
+
? `\nCommit the code change, but not ${result.written.env.file}: each deployment sets ${result.written.env.name} itself.`
|
|
192
|
+
: "\nCommit the change so every copy of the prototype shares this project's feedback."
|
|
193
|
+
: ""),
|
|
194
|
+
!result.written.ok,
|
|
195
|
+
),
|
|
196
|
+
structuredContent: {
|
|
197
|
+
ok: result.written.ok,
|
|
198
|
+
projectId: result.projectId,
|
|
199
|
+
projectName: result.projectName,
|
|
200
|
+
backendUrl: result.backendUrl,
|
|
201
|
+
reused: result.reused,
|
|
202
|
+
env: result.written.env ? { name: result.written.env.name, file: result.written.env.file } : null,
|
|
203
|
+
stages,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function writeProjectId(args) {
|
|
209
|
+
const output = [];
|
|
210
|
+
const optional = (flag, value) => (typeof value === "string" && value !== "" ? [flag, value] : []);
|
|
211
|
+
const code = runInit(
|
|
212
|
+
[
|
|
213
|
+
"init",
|
|
214
|
+
String(args.projectId ?? ""),
|
|
215
|
+
"--dir",
|
|
216
|
+
rootOf(args.dir),
|
|
217
|
+
...optional("--entry", args.entry),
|
|
218
|
+
...optional("--mount", args.mount),
|
|
219
|
+
...optional("--project-env-file", args.envFile),
|
|
220
|
+
...(args.dryRun ? ["--dry-run"] : []),
|
|
221
|
+
],
|
|
222
|
+
{
|
|
223
|
+
cwd,
|
|
224
|
+
print: (line) => output.push(line),
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
return text(output.join("\n"), code !== 0);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function check(args) {
|
|
231
|
+
const report = doctorReport(
|
|
232
|
+
await doctor({ root: rootOf(args.dir), cwd, fetchFn, env, envFile: typeof args.envFile === "string" && args.envFile !== "" ? args.envFile : null, backendUrl: typeof args.backend === "string" && args.backend !== "" ? args.backend : undefined }),
|
|
233
|
+
);
|
|
234
|
+
return { ...text(`${lines(report.checks)}\n${report.note}`, !report.ok), structuredContent: report };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const handlers = { critiqs_setup_start: start, critiqs_setup_finish: finish, critiqs_write_project_id: writeProjectId, critiqs_doctor: check };
|
|
238
|
+
return {
|
|
239
|
+
call: async (name, args = {}) => {
|
|
240
|
+
const handler = handlers[name];
|
|
241
|
+
if (handler === undefined) return text(`Unknown tool ${name}.`, true);
|
|
242
|
+
try {
|
|
243
|
+
return await handler(args);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (error instanceof SetupError) return text(error.message, true);
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
close: () => {
|
|
250
|
+
closed = true;
|
|
251
|
+
pending?.setup.cancel();
|
|
252
|
+
// A start still in progress becomes pending and is cancelled once it settles.
|
|
253
|
+
void starting.then(() => pending?.setup.cancel());
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Answers one JSON-RPC message; returns the response, or null for notifications. */
|
|
259
|
+
export async function handleMessage(message, tools, version) {
|
|
260
|
+
if (typeof message !== "object" || message === null || Array.isArray(message) || typeof message.method !== "string") {
|
|
261
|
+
const id = typeof message?.id === "string" || typeof message?.id === "number" ? message.id : null;
|
|
262
|
+
return { jsonrpc: "2.0", id, error: { code: -32600, message: "Invalid request." } };
|
|
263
|
+
}
|
|
264
|
+
const { id, method, params } = message;
|
|
265
|
+
const reply = (result) => (id === undefined ? null : { jsonrpc: "2.0", id, result });
|
|
266
|
+
const error = (code, text) => (id === undefined ? null : { jsonrpc: "2.0", id, error: { code, message: text } });
|
|
267
|
+
switch (method) {
|
|
268
|
+
case "initialize":
|
|
269
|
+
return reply({
|
|
270
|
+
protocolVersion: params?.protocolVersion ?? "2025-06-18",
|
|
271
|
+
capabilities: { tools: {} },
|
|
272
|
+
serverInfo: { name: "critiqs", version },
|
|
273
|
+
instructions: INSTRUCTIONS,
|
|
274
|
+
});
|
|
275
|
+
case "ping":
|
|
276
|
+
return reply({});
|
|
277
|
+
case "tools/list":
|
|
278
|
+
return reply({ tools: TOOLS });
|
|
279
|
+
case "tools/call":
|
|
280
|
+
try {
|
|
281
|
+
return reply(await tools.call(params?.name, params?.arguments ?? {}));
|
|
282
|
+
} catch (failure) {
|
|
283
|
+
return reply({ content: [{ type: "text", text: `Setup failed: ${failure?.message ?? failure}` }], isError: true });
|
|
284
|
+
}
|
|
285
|
+
default:
|
|
286
|
+
return method?.startsWith("notifications/") ? null : error(-32601, `Unknown method ${method}.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Serves MCP over standard input and output until input ends. */
|
|
291
|
+
export async function serveMcp({ cwd = process.cwd(), input = process.stdin, output = process.stdout } = {}) {
|
|
292
|
+
const { readFileSync } = await import("node:fs");
|
|
293
|
+
const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
294
|
+
const tools = createTools({ cwd });
|
|
295
|
+
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
296
|
+
const send = (response) => output.write(`${JSON.stringify(response)}\n`);
|
|
297
|
+
const inFlight = new Set();
|
|
298
|
+
for await (const line of lines) {
|
|
299
|
+
if (line.trim() === "") continue;
|
|
300
|
+
let message;
|
|
301
|
+
try {
|
|
302
|
+
message = JSON.parse(line);
|
|
303
|
+
} catch {
|
|
304
|
+
send({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error." } });
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
// Calls run concurrently, so a long wait for sign-in doesn't block pings.
|
|
308
|
+
const work = handleMessage(message, tools, version).then((response) => response !== null && send(response));
|
|
309
|
+
inFlight.add(work);
|
|
310
|
+
work.finally(() => inFlight.delete(work));
|
|
311
|
+
}
|
|
312
|
+
await Promise.allSettled(inFlight);
|
|
313
|
+
tools.close();
|
|
314
|
+
}
|
package/bin/setup.d.mts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { JsxElement, Props, Wiring } from "./init.mjs";
|
|
2
|
+
|
|
3
|
+
export declare const CLOUD_BACKEND_URL: string;
|
|
4
|
+
export declare const BACKEND_PROTOCOL: number;
|
|
5
|
+
export declare const SIGN_IN_PROTOCOL: number;
|
|
6
|
+
export declare class SetupError extends Error {}
|
|
7
|
+
|
|
8
|
+
export type Fetch = typeof fetch;
|
|
9
|
+
export type PropValue = { kind: "literal"; value: string } | { kind: "expression"; text?: string } | null;
|
|
10
|
+
|
|
11
|
+
export declare function siteUrlOf(backendUrl: string): string;
|
|
12
|
+
export declare function resolveBackend(
|
|
13
|
+
backendUrl: string,
|
|
14
|
+
options?: { fetchFn?: Fetch },
|
|
15
|
+
): Promise<{ backendUrl: string; siteUrl: string; signInUrl: string; transport: "convex" | "http" }>;
|
|
16
|
+
export declare function openBrowser(url: string): void;
|
|
17
|
+
export declare function startBrowserSignIn(options?: {
|
|
18
|
+
signInUrl?: string;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
port?: number;
|
|
21
|
+
}): Promise<{ url: string; tokens: Promise<{ accessToken: string; refreshToken: string }>; close(): void }>;
|
|
22
|
+
export declare function callConvex(
|
|
23
|
+
backendUrl: string,
|
|
24
|
+
kind: "query" | "mutation" | "action",
|
|
25
|
+
path: string,
|
|
26
|
+
args: Record<string, unknown>,
|
|
27
|
+
accessToken: string,
|
|
28
|
+
options?: { fetchFn?: Fetch },
|
|
29
|
+
): Promise<unknown>;
|
|
30
|
+
export declare function createProject(args: {
|
|
31
|
+
backendUrl: string;
|
|
32
|
+
accessToken: string;
|
|
33
|
+
name: string;
|
|
34
|
+
reviewUrl?: string | null;
|
|
35
|
+
fetchFn?: Fetch;
|
|
36
|
+
}): Promise<string>;
|
|
37
|
+
export declare function signOut(signInUrl: string, refreshToken: string, options?: { origin?: string; fetchFn?: Fetch }): Promise<void>;
|
|
38
|
+
export declare function locateComponent(
|
|
39
|
+
root: string,
|
|
40
|
+
cwd?: string,
|
|
41
|
+
): { error: string } | { usage: { file: string; source: string; element: JsxElement } };
|
|
42
|
+
export declare function isHeadless(env?: Record<string, string | undefined>, platform?: string): boolean;
|
|
43
|
+
export declare function startRemoteSignIn(options: {
|
|
44
|
+
signInUrl: string;
|
|
45
|
+
fetchFn?: Fetch;
|
|
46
|
+
sleep?: (ms: number) => Promise<void>;
|
|
47
|
+
now?: () => number;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
url: string;
|
|
50
|
+
userCode: string;
|
|
51
|
+
expiresAt: number;
|
|
52
|
+
tokens: Promise<{ accessToken: string; refreshToken: null; reviewer: { name: string; email: string } | null }>;
|
|
53
|
+
close(): void;
|
|
54
|
+
}>;
|
|
55
|
+
export declare function listMyProjects(args: {
|
|
56
|
+
backendUrl: string;
|
|
57
|
+
accessToken: string;
|
|
58
|
+
fetchFn?: Fetch;
|
|
59
|
+
}): Promise<{ _id: string; name: string; reviewUrl: string | null }[]>;
|
|
60
|
+
export interface Written {
|
|
61
|
+
ok: boolean;
|
|
62
|
+
message: string;
|
|
63
|
+
file?: string;
|
|
64
|
+
line?: number;
|
|
65
|
+
changed?: string[];
|
|
66
|
+
installed?: boolean;
|
|
67
|
+
preview?: string[];
|
|
68
|
+
/** For an environment-backed project ID: the variable, the file set on this computer, and what each deployment does. */
|
|
69
|
+
env?: { name: string; file: string; advice: string; ignored?: boolean | null };
|
|
70
|
+
}
|
|
71
|
+
export declare function writeComponentProps(args: {
|
|
72
|
+
root: string;
|
|
73
|
+
cwd?: string;
|
|
74
|
+
props: Props;
|
|
75
|
+
dryRun?: boolean;
|
|
76
|
+
entry?: string | null;
|
|
77
|
+
mount?: string | null;
|
|
78
|
+
also?: string;
|
|
79
|
+
}): Written;
|
|
80
|
+
export declare function writeConnection(args: {
|
|
81
|
+
root: string;
|
|
82
|
+
cwd?: string;
|
|
83
|
+
wiring: Wiring;
|
|
84
|
+
projectId: string;
|
|
85
|
+
backend?: string;
|
|
86
|
+
dryRun?: boolean;
|
|
87
|
+
entry?: string | null;
|
|
88
|
+
mount?: string | null;
|
|
89
|
+
}): Written;
|
|
90
|
+
export declare function readComponentProps(
|
|
91
|
+
root: string,
|
|
92
|
+
cwd?: string,
|
|
93
|
+
): { error: string } | { file: string; line: number; projectId: PropValue; backend: PropValue; requireProjectId: boolean };
|
|
94
|
+
export declare function targetDeployment(env: Record<string, string | undefined>): { backendUrl: string; env: Record<string, string> };
|
|
95
|
+
export declare function convexEnv(
|
|
96
|
+
target: { env: Record<string, string> },
|
|
97
|
+
base?: Record<string, string | undefined>,
|
|
98
|
+
): Record<string, string | undefined>;
|
|
99
|
+
export declare function deployOwnConvex(args: {
|
|
100
|
+
env?: Record<string, string | undefined>;
|
|
101
|
+
signInUrl?: string;
|
|
102
|
+
resendApiKey?: string;
|
|
103
|
+
emailFrom?: string;
|
|
104
|
+
log?: (message: string) => void;
|
|
105
|
+
}): Promise<string>;
|
|
106
|
+
export interface Check {
|
|
107
|
+
/** `info`: an optional feature, such as AI, is off. */
|
|
108
|
+
status: "pass" | "warn" | "fail" | "info";
|
|
109
|
+
name: string;
|
|
110
|
+
detail: string;
|
|
111
|
+
stage: "code" | "service" | "project" | "reviewers" | "optional";
|
|
112
|
+
/** Whether the check read settings, or something the backend actually did. */
|
|
113
|
+
basis: "configuration" | "observed";
|
|
114
|
+
}
|
|
115
|
+
export declare const DOCTOR_NOTE: string;
|
|
116
|
+
export declare function isLocalAddress(address: string): boolean;
|
|
117
|
+
export declare function doctor(args: {
|
|
118
|
+
root: string;
|
|
119
|
+
cwd?: string;
|
|
120
|
+
/** The .env file the app loads, relative to root, for custom framework env directories. */
|
|
121
|
+
envFile?: string | null;
|
|
122
|
+
backendUrl?: string;
|
|
123
|
+
fetchFn?: Fetch;
|
|
124
|
+
now?: number;
|
|
125
|
+
/** The environment builds started here would see; defaults to this process's. */
|
|
126
|
+
env?: Record<string, string | undefined>;
|
|
127
|
+
}): Promise<Check[]>;
|
|
128
|
+
export declare function doctorReport(checks: Check[]): { ok: boolean; checks: Check[]; note: string };
|
|
129
|
+
export interface Stage {
|
|
130
|
+
status: "pass" | "warn" | "fail" | "next";
|
|
131
|
+
name: string;
|
|
132
|
+
detail: string;
|
|
133
|
+
}
|
|
134
|
+
export declare function readiness(result: {
|
|
135
|
+
written: Written;
|
|
136
|
+
projectId: string;
|
|
137
|
+
projectName: string;
|
|
138
|
+
backendUrl: string;
|
|
139
|
+
reviewAddress?: string | null;
|
|
140
|
+
reused?: boolean;
|
|
141
|
+
connected?: boolean;
|
|
142
|
+
}): Stage[];
|
|
143
|
+
export declare function defaultProjectName(root: string): string;
|
|
144
|
+
export interface SetupResult {
|
|
145
|
+
projectId: string;
|
|
146
|
+
projectName: string;
|
|
147
|
+
backendUrl: string;
|
|
148
|
+
written: Written;
|
|
149
|
+
reviewAddress: string | null;
|
|
150
|
+
reused: boolean;
|
|
151
|
+
connected: boolean;
|
|
152
|
+
approvedBy: { name: string; email: string } | null;
|
|
153
|
+
}
|
|
154
|
+
export declare function beginSetup(args: {
|
|
155
|
+
root: string;
|
|
156
|
+
cwd?: string;
|
|
157
|
+
/** "cloud", "own-convex", or a backend URL; null keeps a project the code names, or uses Critiqs Cloud. */
|
|
158
|
+
target?: string | null;
|
|
159
|
+
name?: string;
|
|
160
|
+
reviewUrl?: string;
|
|
161
|
+
keys?: { convexDeployKey?: string; resendApiKey?: string; emailFrom?: string };
|
|
162
|
+
env?: Record<string, string | undefined>;
|
|
163
|
+
log?: (message: string) => void;
|
|
164
|
+
fetchFn?: Fetch;
|
|
165
|
+
entry?: string | null;
|
|
166
|
+
mount?: string | null;
|
|
167
|
+
newProject?: boolean;
|
|
168
|
+
signIn?: "auto" | "browser" | "remote";
|
|
169
|
+
/** The .env file to set an environment-backed project ID in, relative to `root`. */
|
|
170
|
+
envFile?: string | null;
|
|
171
|
+
sleep?: (ms: number) => Promise<void>;
|
|
172
|
+
}): Promise<
|
|
173
|
+
| { connected: { projectId: string; backendUrl: string; env?: { name: string; file: string } }; backendUrl: string }
|
|
174
|
+
| {
|
|
175
|
+
connected?: undefined;
|
|
176
|
+
url: string;
|
|
177
|
+
method: "browser" | "remote";
|
|
178
|
+
userCode: string | null;
|
|
179
|
+
backendUrl: string;
|
|
180
|
+
cancel(): void;
|
|
181
|
+
finish(): Promise<SetupResult>;
|
|
182
|
+
}
|
|
183
|
+
>;
|