error-mom 0.1.1 → 0.2.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/LICENSE +21 -0
- package/dist/cli.js +32 -2
- package/package.json +8 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ken Kai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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.2.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);
|
|
@@ -122,7 +122,7 @@ program.command("init").description("Create/select a project, install the SDK, a
|
|
|
122
122
|
framework,
|
|
123
123
|
setupFile: setupPath,
|
|
124
124
|
verified: false,
|
|
125
|
-
nextAction: `Import ${setupPath} from the earliest ${framework} entry point,
|
|
125
|
+
nextAction: framework === "next" ? `Import ${setupPath} from the root layout for client errors; instrumentation.ts already reports server errors. For jobs/handlers that catch errors themselves (queues, webhooks, MCP tools), wrap them with errorMom.wrap(fn). Then run error-mom doctor --project-key <key>.` : `Import ${setupPath} from the earliest ${framework} entry point. For code where a framework catches errors itself (job runners, webhooks, MCP tools), wrap handlers with errorMom.wrap(fn). Then run error-mom doctor --project-key <key>.`
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
program.command("mcp").description("Run Error Mom tools over MCP stdio for coding agents").action(async () => {
|
|
@@ -271,6 +271,7 @@ function installSdk(packageManager) {
|
|
|
271
271
|
async function writeSetup(framework) {
|
|
272
272
|
const sourceDirectory = existsSync(join(process.cwd(), "src")) ? "src" : ".";
|
|
273
273
|
const relativePath = join(sourceDirectory, "error-mom.ts");
|
|
274
|
+
if (framework === "next") await writeNextInstrumentation(sourceDirectory);
|
|
274
275
|
const environment = framework === "next" ? "process.env.NEXT_PUBLIC_" : framework === "vite" ? "import.meta.env.VITE_" : "process.env.";
|
|
275
276
|
const moduleName = framework === "node" ? "@kenkaiiii/error-mom/node" : "@kenkaiiii/error-mom";
|
|
276
277
|
const contents = `${framework === "next" ? '"use client";\n\n' : ""}import { initErrorMom } from "${moduleName}";
|
|
@@ -293,6 +294,35 @@ initErrorMom({
|
|
|
293
294
|
await writeFile(join(process.cwd(), relativePath), contents);
|
|
294
295
|
return relativePath;
|
|
295
296
|
}
|
|
297
|
+
async function writeNextInstrumentation(sourceDirectory) {
|
|
298
|
+
const file = join(process.cwd(), sourceDirectory, "instrumentation.ts");
|
|
299
|
+
if (existsSync(file)) return;
|
|
300
|
+
const contents = `import type { Instrumentation } from "next";
|
|
301
|
+
|
|
302
|
+
// Reports server-side errors (API routes, SSR, server actions, middleware)
|
|
303
|
+
// that Next.js catches before they can become uncaught exceptions.
|
|
304
|
+
export const onRequestError: Instrumentation.onRequestError = async (
|
|
305
|
+
error,
|
|
306
|
+
request,
|
|
307
|
+
context,
|
|
308
|
+
) => {
|
|
309
|
+
if (process.env.NEXT_RUNTIME !== "nodejs") return;
|
|
310
|
+
const server = process.env.NEXT_PUBLIC_ERROR_MOM_SERVER;
|
|
311
|
+
const projectKey = process.env.NEXT_PUBLIC_ERROR_MOM_PROJECT_KEY;
|
|
312
|
+
if (!server || !projectKey) return;
|
|
313
|
+
const { initErrorMom } = await import("@kenkaiiii/error-mom/node");
|
|
314
|
+
initErrorMom({
|
|
315
|
+
server,
|
|
316
|
+
projectKey,
|
|
317
|
+
environment: process.env.NEXT_PUBLIC_ERROR_MOM_ENVIRONMENT ?? "production",
|
|
318
|
+
}).captureError(error, {
|
|
319
|
+
culprit: \`\${request.method} \${request.path}\`,
|
|
320
|
+
tags: { routerKind: context.routerKind, routeType: context.routeType, runtime: "server" },
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
`;
|
|
324
|
+
await writeFile(file, contents);
|
|
325
|
+
}
|
|
296
326
|
async function appendEnvironment(framework, server, key) {
|
|
297
327
|
const prefix = framework === "next" ? "NEXT_PUBLIC_" : framework === "vite" ? "VITE_" : "";
|
|
298
328
|
const file = join(process.cwd(), ".env.local");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "error-mom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Agent-first CLI and MCP tools for self-hosted Error Mom",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,11 +11,6 @@
|
|
|
11
11
|
"dist",
|
|
12
12
|
"README.md"
|
|
13
13
|
],
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsup src/cli.ts --format esm --dts --clean",
|
|
16
|
-
"check": "tsc --noEmit",
|
|
17
|
-
"test": "vitest run --passWithNoTests"
|
|
18
|
-
},
|
|
19
14
|
"dependencies": {
|
|
20
15
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
21
16
|
"commander": "^15.0.0",
|
|
@@ -28,5 +23,10 @@
|
|
|
28
23
|
"publishConfig": {
|
|
29
24
|
"access": "public"
|
|
30
25
|
},
|
|
31
|
-
"license": "MIT"
|
|
32
|
-
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/cli.ts --format esm --dts --clean",
|
|
29
|
+
"check": "tsc --noEmit",
|
|
30
|
+
"test": "vitest run --passWithNoTests"
|
|
31
|
+
}
|
|
32
|
+
}
|