sysprom 1.23.0 → 1.24.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/src/cli/program.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, resolve } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { buildCommander } from "./define-command.js";
|
|
6
|
+
import { formatCliError } from "./shared.js";
|
|
6
7
|
let cachedVersion;
|
|
7
8
|
function getVersion() {
|
|
8
9
|
if (cachedVersion === undefined) {
|
|
@@ -81,3 +82,13 @@ program
|
|
|
81
82
|
.action(async () => {
|
|
82
83
|
await import("../mcp/server.js");
|
|
83
84
|
});
|
|
85
|
+
// Global error handlers for uncaught exceptions
|
|
86
|
+
process.on("uncaughtException", (error) => {
|
|
87
|
+
console.error(formatCliError(error, false));
|
|
88
|
+
process.exit(1);
|
|
89
|
+
});
|
|
90
|
+
process.on("unhandledRejection", (reason) => {
|
|
91
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
92
|
+
console.error(formatCliError(error, false));
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
package/dist/src/cli/shared.d.ts
CHANGED
|
@@ -72,3 +72,18 @@ export declare function loadDoc(input?: string): LoadedDoc;
|
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
74
|
export declare function persistDoc(doc: SysProMDocument, loaded: LoadedDoc, opts: MutationOpts): void;
|
|
75
|
+
/**
|
|
76
|
+
* Format an error message for CLI output with issue filing guidance.
|
|
77
|
+
* If the error appears to be unexpected (not a user error), suggests filing an issue.
|
|
78
|
+
* @param error - The error to format
|
|
79
|
+
* @param isUserError - Whether this is a user error (e.g. invalid input); if false, suggests filing an issue
|
|
80
|
+
* @returns Formatted error message
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* try { ... } catch (err: unknown) {
|
|
84
|
+
* console.error(formatCliError(err, false)); // Not a user error - suggest issue
|
|
85
|
+
* process.exit(1);
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function formatCliError(error: unknown, isUserError?: boolean): string;
|
package/dist/src/cli/shared.js
CHANGED
|
@@ -207,3 +207,28 @@ export function persistDoc(doc, loaded, opts) {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Error formatting and reporting
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
const ISSUE_URL = "https://github.com/ExaDev/SysProM/issues/new";
|
|
214
|
+
/**
|
|
215
|
+
* Format an error message for CLI output with issue filing guidance.
|
|
216
|
+
* If the error appears to be unexpected (not a user error), suggests filing an issue.
|
|
217
|
+
* @param error - The error to format
|
|
218
|
+
* @param isUserError - Whether this is a user error (e.g. invalid input); if false, suggests filing an issue
|
|
219
|
+
* @returns Formatted error message
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* try { ... } catch (err: unknown) {
|
|
223
|
+
* console.error(formatCliError(err, false)); // Not a user error - suggest issue
|
|
224
|
+
* process.exit(1);
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function formatCliError(error, isUserError = false) {
|
|
229
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
230
|
+
if (isUserError) {
|
|
231
|
+
return message;
|
|
232
|
+
}
|
|
233
|
+
return `${message}\n\nIf this was unexpected or bad UX, please file an issue:\n${ISSUE_URL}`;
|
|
234
|
+
}
|
package/dist/src/mcp/server.js
CHANGED
|
@@ -7,19 +7,27 @@ import { NodeType, RelationshipType } from "../schema.js";
|
|
|
7
7
|
import { validateOp, statsOp, queryNodesOp, queryNodeOp, queryRelationshipsOp, traceFromNodeOp, addNodeOp, removeNodeOp, updateNodeOp, addRelationshipOp, removeRelationshipOp, nextIdOp, inferCompletenessOp, inferLifecycleOp, inferImpactOp, impactSummaryOp, inferDerivedOp, } from "../operations/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* Wrap an error with a descriptive prefix and attach the original as cause.
|
|
10
|
+
* Adds issue filing guidance for unexpected errors.
|
|
10
11
|
* @param prefix - The error prefix (e.g., "Failed to add node")
|
|
11
12
|
* @param error - The caught error
|
|
13
|
+
* @param isUserError - Whether this is a user error; if false, suggests filing an issue
|
|
12
14
|
* @example
|
|
13
15
|
* ```ts
|
|
14
16
|
* try {
|
|
15
17
|
* someOperation();
|
|
16
18
|
* } catch (error) {
|
|
17
|
-
* wrapError("Failed to do X", error);
|
|
19
|
+
* wrapError("Failed to do X", error, false); // Not a user error - suggest issue
|
|
18
20
|
* }
|
|
19
21
|
* ```
|
|
20
22
|
*/
|
|
21
|
-
function wrapError(prefix, error) {
|
|
22
|
-
|
|
23
|
+
function wrapError(prefix, error, isUserError = false) {
|
|
24
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
25
|
+
const fullMessage = `${prefix}: ${message}`;
|
|
26
|
+
const issueUrl = "https://github.com/ExaDev/SysProM/issues/new";
|
|
27
|
+
const errorMsg = isUserError
|
|
28
|
+
? fullMessage
|
|
29
|
+
: `${fullMessage}\n\nIf this was unexpected or bad UX, please file an issue: ${issueUrl}`;
|
|
30
|
+
throw new Error(errorMsg, { cause: error });
|
|
23
31
|
}
|
|
24
32
|
// Create MCP server instance
|
|
25
33
|
const server = new McpServer({
|
|
@@ -105,6 +105,24 @@ const NODE_TYPE_SHAPES = {
|
|
|
105
105
|
export function mermaidShapeForNode(node) {
|
|
106
106
|
return NODE_TYPE_SHAPES[node.type] ?? "rectangle";
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Escape a Mermaid label by wrapping in quotes if it contains special characters.
|
|
110
|
+
* Mermaid shape delimiters and other special chars need escaping: ( ) { } [ ] / \
|
|
111
|
+
* Wrapping in double quotes allows these characters to be rendered as-is.
|
|
112
|
+
* @param label - The label text to escape
|
|
113
|
+
* @returns The label, quoted if it contains special characters
|
|
114
|
+
* @example
|
|
115
|
+
* escapeMermaidLabel("Firebase (Tenant)") // returns '"Firebase (Tenant)"'
|
|
116
|
+
*/
|
|
117
|
+
function escapeMermaidLabel(label) {
|
|
118
|
+
// Check if label contains any Mermaid special characters that need escaping
|
|
119
|
+
const specialChars = ["(", ")", "{", "}", "[", "]", "/", "\\"];
|
|
120
|
+
if (specialChars.some((char) => label.includes(char))) {
|
|
121
|
+
// Wrap in double quotes to escape
|
|
122
|
+
return `"${label}"`;
|
|
123
|
+
}
|
|
124
|
+
return label;
|
|
125
|
+
}
|
|
108
126
|
/**
|
|
109
127
|
* Render a Mermaid node definition for a node id/name/shape.
|
|
110
128
|
* @param id - Node id
|
|
@@ -116,16 +134,17 @@ export function mermaidShapeForNode(node) {
|
|
|
116
134
|
export function renderMermaidNode(id, name, shape, mode = "friendly") {
|
|
117
135
|
const safeId = sanitiseMermaidId(id);
|
|
118
136
|
const label = mode === "compact" ? id : `${id}: ${name}`;
|
|
137
|
+
const escapedLabel = escapeMermaidLabel(label);
|
|
119
138
|
switch (shape) {
|
|
120
139
|
case "rounded":
|
|
121
|
-
return `${safeId}([${
|
|
140
|
+
return `${safeId}([${escapedLabel}])`;
|
|
122
141
|
case "rhombus":
|
|
123
|
-
return `${safeId}{{${
|
|
142
|
+
return `${safeId}{{${escapedLabel}}}`;
|
|
124
143
|
case "parallelogram":
|
|
125
|
-
return `${safeId}[/${
|
|
144
|
+
return `${safeId}[/${escapedLabel}/]`;
|
|
126
145
|
case "rectangle":
|
|
127
146
|
default:
|
|
128
|
-
return `${safeId}[${
|
|
147
|
+
return `${safeId}[${escapedLabel}]`;
|
|
129
148
|
}
|
|
130
149
|
}
|
|
131
150
|
/**
|