error-mom 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +45 -20
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { Command } from "commander";
|
|
|
10
10
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
11
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
12
12
|
import { z } from "zod";
|
|
13
|
-
var VERSION = "0.
|
|
13
|
+
var VERSION = "0.4.0";
|
|
14
14
|
var CONFIG_DIR = join(homedir(), ".error-mom");
|
|
15
15
|
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
16
16
|
var program = new Command().name("error-mom").description("Query and operate a self-hosted Error Mom incident desk").version(VERSION);
|
|
@@ -64,6 +64,17 @@ program.command("resolve").description("Resolve one issue and record the release
|
|
|
64
64
|
)
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
|
+
program.command("delete-project").description("Permanently delete one project and all of its issues and history").argument("<project-id>").action(async (projectId) => {
|
|
68
|
+
const config = await loadConfig();
|
|
69
|
+
print(
|
|
70
|
+
await request(
|
|
71
|
+
config.server,
|
|
72
|
+
config.adminToken,
|
|
73
|
+
`/api/v1/projects/${encodeURIComponent(projectId)}`,
|
|
74
|
+
{ method: "DELETE" }
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
});
|
|
67
78
|
program.command("doctor").description("Verify collector health, credentials, and optional project ingestion").option("--project-key <key>", "Send and verify a synthetic event with this write-only key").action(async (options) => {
|
|
68
79
|
const config = await loadConfig();
|
|
69
80
|
const health = await request(config.server, void 0, "/api/health");
|
|
@@ -109,7 +120,7 @@ program.command("init").description("Create/select a project, install the SDK, a
|
|
|
109
120
|
}
|
|
110
121
|
const framework = detectFramework(packageJson);
|
|
111
122
|
if (!options.skipInstall) installSdk(detectPackageManager(process.cwd()));
|
|
112
|
-
const setupPath = await writeSetup(framework);
|
|
123
|
+
const setupPath = await writeSetup(framework, config.server, project.ingestKey);
|
|
113
124
|
await writeFile(
|
|
114
125
|
join(process.cwd(), ".error-mom.json"),
|
|
115
126
|
`${JSON.stringify({ server: config.server, projectId: project.id, projectName: project.name, framework: framework.id }, null, 2)}
|
|
@@ -123,7 +134,7 @@ program.command("init").description("Create/select a project, install the SDK, a
|
|
|
123
134
|
setupFile: setupPath,
|
|
124
135
|
verified: false,
|
|
125
136
|
wiring: framework.wiring,
|
|
126
|
-
nextAction: `Wire it up: ${framework.wiring} For handlers where a framework catches errors itself (queue/cron jobs, webhooks, MCP tools), wrap each with errorMom.wrap(fn, { culprit: "<name>" }). Then run error-mom doctor --project-key <key>.`
|
|
137
|
+
nextAction: `Wire it up: ${framework.wiring} If the app routes caught errors through a central handler or error-broadcast function, call errorMom.captureError(err) inside it \u2014 that is where framework-caught and LLM errors surface. For handlers where a framework catches errors itself (queue/cron jobs, webhooks, MCP tools), wrap each with errorMom.wrap(fn, { culprit: "<name>" }). The setup file has the write-only project key baked in so production builds report without any CI configuration. Then run error-mom doctor --project-key <key>.`
|
|
127
138
|
});
|
|
128
139
|
});
|
|
129
140
|
program.command("mcp").description("Run Error Mom tools over MCP stdio for coding agents").action(async () => {
|
|
@@ -194,6 +205,21 @@ async function runMcpServer() {
|
|
|
194
205
|
)
|
|
195
206
|
)
|
|
196
207
|
);
|
|
208
|
+
server.registerTool(
|
|
209
|
+
"delete_project",
|
|
210
|
+
{
|
|
211
|
+
description: "Permanently delete a project and all of its issues, samples, and history. Irreversible.",
|
|
212
|
+
inputSchema: { projectId: z.string().min(1) }
|
|
213
|
+
},
|
|
214
|
+
async ({ projectId }) => toolResult(
|
|
215
|
+
await request(
|
|
216
|
+
config.server,
|
|
217
|
+
config.adminToken,
|
|
218
|
+
`/api/v1/projects/${encodeURIComponent(projectId)}`,
|
|
219
|
+
{ method: "DELETE" }
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
);
|
|
197
223
|
await server.connect(new StdioServerTransport());
|
|
198
224
|
}
|
|
199
225
|
function toolResult(value) {
|
|
@@ -380,47 +406,46 @@ function installSdk(packageManager) {
|
|
|
380
406
|
stdio: "inherit"
|
|
381
407
|
});
|
|
382
408
|
}
|
|
383
|
-
async function writeSetup(framework) {
|
|
409
|
+
async function writeSetup(framework, server, ingestKey) {
|
|
384
410
|
const sourceDirectory = existsSync(join(process.cwd(), "src")) ? "src" : ".";
|
|
385
411
|
const relativePath = join(sourceDirectory, "error-mom.ts");
|
|
386
|
-
if (framework.id === "next") await writeNextInstrumentation(sourceDirectory);
|
|
412
|
+
if (framework.id === "next") await writeNextInstrumentation(sourceDirectory, server, ingestKey);
|
|
387
413
|
const environment = framework.envStyle === "next" ? "process.env.NEXT_PUBLIC_" : framework.envStyle === "vite" ? "import.meta.env.VITE_" : "process.env.";
|
|
388
414
|
const moduleName = framework.envStyle === "node" ? "@kenkaiiii/error-mom/node" : "@kenkaiiii/error-mom";
|
|
389
415
|
const contents = `${framework.id === "next" ? '"use client";\n\n' : ""}import { initErrorMom } from "${moduleName}";
|
|
390
416
|
|
|
391
|
-
|
|
392
|
-
|
|
417
|
+
// The project key is write-only (submit errors, read nothing), so committing
|
|
418
|
+
// it is safe \u2014 same model as a Sentry DSN. Env vars override when present.
|
|
419
|
+
const server = ${environment}ERROR_MOM_SERVER ?? ${JSON.stringify(server)};
|
|
420
|
+
const projectKey = ${environment}ERROR_MOM_PROJECT_KEY ?? ${JSON.stringify(ingestKey)};
|
|
393
421
|
const release = ${environment}ERROR_MOM_RELEASE;
|
|
394
422
|
|
|
395
|
-
export const errorMom =
|
|
396
|
-
server
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
...(release ? { release } : {}),
|
|
402
|
-
})
|
|
403
|
-
: undefined;
|
|
423
|
+
export const errorMom = initErrorMom({
|
|
424
|
+
server,
|
|
425
|
+
projectKey,
|
|
426
|
+
environment: ${environment}ERROR_MOM_ENVIRONMENT ?? "production",
|
|
427
|
+
...(release ? { release } : {}),
|
|
428
|
+
});
|
|
404
429
|
`;
|
|
405
430
|
await writeFile(join(process.cwd(), relativePath), contents);
|
|
406
431
|
return relativePath;
|
|
407
432
|
}
|
|
408
|
-
async function writeNextInstrumentation(sourceDirectory) {
|
|
433
|
+
async function writeNextInstrumentation(sourceDirectory, configuredServer, ingestKey) {
|
|
409
434
|
const file = join(process.cwd(), sourceDirectory, "instrumentation.ts");
|
|
410
435
|
if (existsSync(file)) return;
|
|
411
436
|
const contents = `import type { Instrumentation } from "next";
|
|
412
437
|
|
|
413
438
|
// Reports server-side errors (API routes, SSR, server actions, middleware)
|
|
414
439
|
// that Next.js catches before they can become uncaught exceptions.
|
|
440
|
+
// The baked-in project key is write-only, so committing it is safe.
|
|
415
441
|
export const onRequestError: Instrumentation.onRequestError = async (
|
|
416
442
|
error,
|
|
417
443
|
request,
|
|
418
444
|
context,
|
|
419
445
|
) => {
|
|
420
446
|
if (process.env.NEXT_RUNTIME !== "nodejs") return;
|
|
421
|
-
const server = process.env.NEXT_PUBLIC_ERROR_MOM_SERVER;
|
|
422
|
-
const projectKey = process.env.NEXT_PUBLIC_ERROR_MOM_PROJECT_KEY;
|
|
423
|
-
if (!server || !projectKey) return;
|
|
447
|
+
const server = process.env.NEXT_PUBLIC_ERROR_MOM_SERVER ?? ${JSON.stringify(configuredServer)};
|
|
448
|
+
const projectKey = process.env.NEXT_PUBLIC_ERROR_MOM_PROJECT_KEY ?? ${JSON.stringify(ingestKey)};
|
|
424
449
|
const { initErrorMom } = await import("@kenkaiiii/error-mom/node");
|
|
425
450
|
initErrorMom({
|
|
426
451
|
server,
|