@paretools/shared 0.13.0 → 0.14.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/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/output.d.ts +7 -2
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +50 -8
- package/dist/output.js.map +1 -1
- package/dist/runner.d.ts +31 -5
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +140 -12
- package/dist/runner.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +35 -0
- package/dist/server.js.map +1 -1
- package/dist/strict-input.d.ts +19 -0
- package/dist/strict-input.d.ts.map +1 -0
- package/dist/strict-input.js +59 -0
- package/dist/strict-input.js.map +1 -0
- package/dist/validation.d.ts +8 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +17 -0
- package/dist/validation.js.map +1 -1
- package/dist/version.d.ts +16 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +42 -0
- package/dist/version.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { dualOutput, estimateTokens, compactDualOutput, strippedDualOutput, strippedCompactDualOutput, } from "./output.js";
|
|
2
|
-
export { run, escapeCmdArg, type RunResult, type RunOptions } from "./runner.js";
|
|
2
|
+
export { run, escapeCmdArg, _buildSpawnConfig, type RunResult, type RunOptions, type SpawnConfig, } from "./runner.js";
|
|
3
3
|
export { stripAnsi } from "./ansi.js";
|
|
4
|
-
export { assertNoFlagInjection, assertValidSortKey, assertValidLogOpts, assertAllowedCommand, } from "./validation.js";
|
|
4
|
+
export { coerceJsonArray, assertNoFlagInjection, assertValidSortKey, assertValidLogOpts, assertAllowedCommand, } from "./validation.js";
|
|
5
5
|
export { INPUT_LIMITS } from "./limits.js";
|
|
6
6
|
export { compactInput, projectPathInput, repoPathInput, cwdPathInput, fixInput, pathInput, configInput, filePatternsInput, } from "./input-schemas.js";
|
|
7
7
|
export { sanitizeErrorOutput } from "./sanitize.js";
|
|
@@ -16,4 +16,5 @@ export { PareErrorCategory, PareErrorSchema, classifyError, errorOutput, invalid
|
|
|
16
16
|
export type { PareErrorCategoryType, PareError } from "./errors.js";
|
|
17
17
|
export { createServer } from "./server.js";
|
|
18
18
|
export type { CreateServerOptions } from "./server.js";
|
|
19
|
+
export { readPackageVersion } from "./version.js";
|
|
19
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,GAAG,EACH,YAAY,EACZ,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC1F,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,WAAW,EACX,UAAU,EACV,UAAU,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { dualOutput, estimateTokens, compactDualOutput, strippedDualOutput, strippedCompactDualOutput, } from "./output.js";
|
|
2
|
-
export { run, escapeCmdArg } from "./runner.js";
|
|
2
|
+
export { run, escapeCmdArg, _buildSpawnConfig, } from "./runner.js";
|
|
3
3
|
export { stripAnsi } from "./ansi.js";
|
|
4
|
-
export { assertNoFlagInjection, assertValidSortKey, assertValidLogOpts, assertAllowedCommand, } from "./validation.js";
|
|
4
|
+
export { coerceJsonArray, assertNoFlagInjection, assertValidSortKey, assertValidLogOpts, assertAllowedCommand, } from "./validation.js";
|
|
5
5
|
export { INPUT_LIMITS } from "./limits.js";
|
|
6
6
|
export { compactInput, projectPathInput, repoPathInput, cwdPathInput, fixInput, pathInput, configInput, filePatternsInput, } from "./input-schemas.js";
|
|
7
7
|
export { sanitizeErrorOutput } from "./sanitize.js";
|
|
@@ -12,4 +12,5 @@ export { registerDiscoverTool } from "./discover-tool.js";
|
|
|
12
12
|
export { assertAllowedByPolicy, assertAllowedRoot, assertNoPathQualifiedCommand, } from "./policy.js";
|
|
13
13
|
export { PareErrorCategory, PareErrorSchema, classifyError, errorOutput, invalidInputError, isCommandNotFound, isPermissionDenied, isTimeout, isNetworkError, isAuthError, isConflict, isNotFound, isAlreadyExists, isConfigurationError, } from "./errors.js";
|
|
14
14
|
export { createServer } from "./server.js";
|
|
15
|
+
export { readPackageVersion } from "./version.js";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,GAAG,EACH,YAAY,EACZ,iBAAiB,GAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EACL,qBAAqB,GAGtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,WAAW,EACX,UAAU,EACV,UAAU,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/output.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
1
2
|
import type { ToolOutput } from "./types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Creates the dual-output response that every pare tool returns.
|
|
@@ -27,8 +28,11 @@ export declare function estimateTokens(text: string): number;
|
|
|
27
28
|
* @param compactMap - Projects full data into a compact shape.
|
|
28
29
|
* @param compactFormat - Formatter for compact data.
|
|
29
30
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
31
|
+
* @param outputSchema - Optional Zod schema. In dev mode (NODE_ENV !== 'production' or PARE_DEBUG set),
|
|
32
|
+
* the structured output is validated against this schema before returning. Mismatches throw a
|
|
33
|
+
* descriptive error, catching compact-map bugs during development/testing rather than in production.
|
|
30
34
|
*/
|
|
31
|
-
export declare function compactDualOutput<T, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean): ToolOutput<T | C>;
|
|
35
|
+
export declare function compactDualOutput<T, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean, outputSchema?: ZodType): ToolOutput<T | C>;
|
|
32
36
|
/**
|
|
33
37
|
* Creates a dual-output response where the formatter receives the full internal
|
|
34
38
|
* data (with extra fields for human-readable output) while structuredContent
|
|
@@ -54,6 +58,7 @@ export declare function strippedDualOutput<T, S>(data: T, humanFormat: (d: T) =>
|
|
|
54
58
|
* @param compactMap - Projects full data into a compact shape (for compact mode).
|
|
55
59
|
* @param compactFormat - Formatter for compact data.
|
|
56
60
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
61
|
+
* @param outputSchema - Optional Zod schema for dev-mode validation (see compactDualOutput).
|
|
57
62
|
*/
|
|
58
|
-
export declare function strippedCompactDualOutput<T, S, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, schemaMap: (d: T) => S, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean): ToolOutput<S | C>;
|
|
63
|
+
export declare function strippedCompactDualOutput<T, S, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, schemaMap: (d: T) => S, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean, outputSchema?: ZodType): ToolOutput<S | C>;
|
|
59
64
|
//# sourceMappingURL=output.d.ts.map
|
package/dist/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA+B7C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAKnF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EACpC,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC7B,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACvB,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC/B,eAAe,EAAE,OAAO,EACxB,YAAY,CAAC,EAAE,OAAO,GACrB,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAoBnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EACrC,IAAI,EAAE,CAAC,EACP,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC7B,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACrB,UAAU,CAAC,CAAC,CAAC,CAKf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/C,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC7B,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACtB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACvB,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC/B,eAAe,EAAE,OAAO,EACxB,YAAY,CAAC,EAAE,OAAO,GACrB,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAoBnB"}
|
package/dist/output.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when dev-mode validation should run.
|
|
3
|
+
* Active when NODE_ENV is NOT 'production' or PARE_DEBUG is set.
|
|
4
|
+
*/
|
|
5
|
+
function isDevMode() {
|
|
6
|
+
return process.env.NODE_ENV !== "production" || !!process.env.PARE_DEBUG;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Validates `data` against a Zod `outputSchema` in dev mode.
|
|
10
|
+
* Throws a descriptive error when the data does not match the schema,
|
|
11
|
+
* helping developers catch compact-map / schema mismatches early.
|
|
12
|
+
*
|
|
13
|
+
* No-ops in production (NODE_ENV=production without PARE_DEBUG).
|
|
14
|
+
*/
|
|
15
|
+
function devValidate(data, outputSchema, label) {
|
|
16
|
+
if (!outputSchema || !isDevMode())
|
|
17
|
+
return;
|
|
18
|
+
const result = outputSchema.safeParse(data);
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
const issues = result.error.issues
|
|
21
|
+
.map((i) => ` - ${i.path.join(".")}: ${i.message}`)
|
|
22
|
+
.join("\n");
|
|
23
|
+
throw new Error(`compactDualOutput (${label}): structured output does not match outputSchema.\n` +
|
|
24
|
+
`Validation errors:\n${issues}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
1
27
|
/**
|
|
2
28
|
* Creates the dual-output response that every pare tool returns.
|
|
3
29
|
*
|
|
@@ -33,18 +59,27 @@ export function estimateTokens(text) {
|
|
|
33
59
|
* @param compactMap - Projects full data into a compact shape.
|
|
34
60
|
* @param compactFormat - Formatter for compact data.
|
|
35
61
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
62
|
+
* @param outputSchema - Optional Zod schema. In dev mode (NODE_ENV !== 'production' or PARE_DEBUG set),
|
|
63
|
+
* the structured output is validated against this schema before returning. Mismatches throw a
|
|
64
|
+
* descriptive error, catching compact-map bugs during development/testing rather than in production.
|
|
36
65
|
*/
|
|
37
|
-
export function compactDualOutput(data, rawStdout, humanFormat, compactMap, compactFormat, forceFullSchema) {
|
|
66
|
+
export function compactDualOutput(data, rawStdout, humanFormat, compactMap, compactFormat, forceFullSchema, outputSchema) {
|
|
38
67
|
if (forceFullSchema) {
|
|
39
|
-
|
|
68
|
+
const out = dualOutput(data, humanFormat);
|
|
69
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
70
|
+
return out;
|
|
40
71
|
}
|
|
41
72
|
const structuredTokens = estimateTokens(JSON.stringify(data));
|
|
42
73
|
const rawTokens = estimateTokens(rawStdout);
|
|
43
74
|
if (structuredTokens >= rawTokens) {
|
|
44
75
|
const compact = compactMap(data);
|
|
45
|
-
|
|
76
|
+
const out = dualOutput(compact, compactFormat);
|
|
77
|
+
devValidate(out.structuredContent, outputSchema, "compact");
|
|
78
|
+
return out;
|
|
46
79
|
}
|
|
47
|
-
|
|
80
|
+
const out = dualOutput(data, humanFormat);
|
|
81
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
82
|
+
return out;
|
|
48
83
|
}
|
|
49
84
|
/**
|
|
50
85
|
* Creates a dual-output response where the formatter receives the full internal
|
|
@@ -76,17 +111,24 @@ export function strippedDualOutput(data, humanFormat, schemaMap) {
|
|
|
76
111
|
* @param compactMap - Projects full data into a compact shape (for compact mode).
|
|
77
112
|
* @param compactFormat - Formatter for compact data.
|
|
78
113
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
114
|
+
* @param outputSchema - Optional Zod schema for dev-mode validation (see compactDualOutput).
|
|
79
115
|
*/
|
|
80
|
-
export function strippedCompactDualOutput(data, rawStdout, humanFormat, schemaMap, compactMap, compactFormat, forceFullSchema) {
|
|
116
|
+
export function strippedCompactDualOutput(data, rawStdout, humanFormat, schemaMap, compactMap, compactFormat, forceFullSchema, outputSchema) {
|
|
81
117
|
if (forceFullSchema) {
|
|
82
|
-
|
|
118
|
+
const out = strippedDualOutput(data, humanFormat, schemaMap);
|
|
119
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
120
|
+
return out;
|
|
83
121
|
}
|
|
84
122
|
const structuredTokens = estimateTokens(JSON.stringify(data));
|
|
85
123
|
const rawTokens = estimateTokens(rawStdout);
|
|
86
124
|
if (structuredTokens >= rawTokens) {
|
|
87
125
|
const compact = compactMap(data);
|
|
88
|
-
|
|
126
|
+
const out = dualOutput(compact, compactFormat);
|
|
127
|
+
devValidate(out.structuredContent, outputSchema, "compact");
|
|
128
|
+
return out;
|
|
89
129
|
}
|
|
90
|
-
|
|
130
|
+
const out = strippedDualOutput(data, humanFormat, schemaMap);
|
|
131
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
132
|
+
return out;
|
|
91
133
|
}
|
|
92
134
|
//# sourceMappingURL=output.js.map
|
package/dist/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WA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AAE,YAAY,EAAE,MAAM,CAAC,CAAC;QACzD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAE5C,IAAI,gBAAgB,IAAI,SAAS,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,aAAa,CAAsB,CAAC;QACpE,WAAW,CAAC,GAAG,CAAC,iBAAiB,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QAC5D,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,GAAG,GAAG,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAsB,CAAC;IAClF,WAAW,CAAC,GAAG,CAAC,iBAAiB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACzD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export interface RunOptions {
|
|
|
7
7
|
* (e.g., `git commit --file -`) instead of passing it as a command arg,
|
|
8
8
|
* which avoids cmd.exe argument-length and newline limitations on Windows. */
|
|
9
9
|
stdin?: string;
|
|
10
|
-
/** Override shell mode. Defaults to `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
/** Override shell mode. Defaults to `false` on all platforms. On Windows,
|
|
11
|
+
* .cmd/.bat wrappers are automatically handled via cmd.exe invocation without
|
|
12
|
+
* shell mode. Set to `true` only when you need shell features (pipes, globs). */
|
|
13
13
|
shell?: boolean;
|
|
14
14
|
/** Maximum combined stdout+stderr buffer size in bytes. Defaults to 10 MB. */
|
|
15
15
|
maxBuffer?: number;
|
|
@@ -45,14 +45,40 @@ export interface RunResult {
|
|
|
45
45
|
* they are literal, and outside quotes they rarely appear in tool args.
|
|
46
46
|
*/
|
|
47
47
|
export declare function escapeCmdArg(arg: string): string;
|
|
48
|
+
/** Configuration for how to invoke `spawn()`. @internal — exported for testing only. */
|
|
49
|
+
export interface SpawnConfig {
|
|
50
|
+
command: string;
|
|
51
|
+
args: string[];
|
|
52
|
+
shell: boolean;
|
|
53
|
+
windowsVerbatimArguments: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Determines how to spawn a command, handling Windows .cmd/.bat wrappers
|
|
57
|
+
* without using `shell: true` (which triggers CodeQL alert #16).
|
|
58
|
+
*
|
|
59
|
+
* @internal — Exported for unit testing only. Use `run()` instead.
|
|
60
|
+
*
|
|
61
|
+
* Branches:
|
|
62
|
+
* 1. Explicit `shell: true` — pass cmd directly, don't resolve (caller wants shell features)
|
|
63
|
+
* 2. Windows native .exe/.com — spawn resolved path directly
|
|
64
|
+
* 3. Windows non-exe (cmd/bat/extensionless/bare) — cmd.exe /d /s /c with windowsVerbatimArguments
|
|
65
|
+
* 4. Unix — spawn cmd directly, execvp handles PATH
|
|
66
|
+
*/
|
|
67
|
+
export declare function _buildSpawnConfig(cmd: string, args: string[], opts?: {
|
|
68
|
+
shell?: boolean;
|
|
69
|
+
}, platform?: string, resolver?: (cmd: string) => string): SpawnConfig;
|
|
48
70
|
/**
|
|
49
71
|
* Executes a command and returns cleaned output with ANSI codes stripped.
|
|
50
72
|
* Uses spawn (not exec) to avoid shell injection. The child is spawned in its
|
|
51
73
|
* own process group (`detached: true` on Unix) so that on timeout we can kill
|
|
52
74
|
* the entire group — preventing orphaned grandchild processes.
|
|
53
75
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
76
|
+
* Shell mode defaults to `false` on all platforms. On Windows, .cmd/.bat
|
|
77
|
+
* wrappers (like npm, npx) are automatically handled via cmd.exe invocation
|
|
78
|
+
* with windowsVerbatimArguments (cross-spawn pattern), avoiding shell injection.
|
|
79
|
+
*
|
|
80
|
+
* Callers can opt in to `shell: true` for shell features (pipes, globs),
|
|
81
|
+
* but this bypasses security protections — use only with trusted input.
|
|
56
82
|
*
|
|
57
83
|
* Throws on system-level errors (command not found, permission denied, timeout).
|
|
58
84
|
* Normal non-zero exit codes are returned in the result, not thrown.
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAiDA,uGAAuG;AACvG,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;mFAE+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;sFAEkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;0FACsF;IACtF,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgCD,+FAA+F;AAC/F,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqChD;AAgDD,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,wBAAwB,EAAE,OAAO,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,EAC1B,QAAQ,GAAE,MAAyB,EACnC,QAAQ,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAuB,GACjD,WAAW,CA2Cb;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAqJtF"}
|
package/dist/runner.js
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
import { spawn, execFileSync } from "node:child_process";
|
|
2
|
+
import { normalize } from "node:path";
|
|
2
3
|
import { stripAnsi } from "./ansi.js";
|
|
3
4
|
import { sanitizeErrorOutput } from "./sanitize.js";
|
|
5
|
+
/**
|
|
6
|
+
* Resolves a command name to its absolute path using `where` (Windows) or
|
|
7
|
+
* `which` (Unix). On Windows this is used to detect whether a command is a
|
|
8
|
+
* .cmd/.bat wrapper so the runner can invoke it via cmd.exe without using
|
|
9
|
+
* `shell: true` (which triggers CodeQL alert #16).
|
|
10
|
+
*
|
|
11
|
+
* Returns the original command string if resolution fails (e.g., the command
|
|
12
|
+
* is already an absolute path, or `which`/`where` is unavailable).
|
|
13
|
+
*/
|
|
14
|
+
function resolveCommand(cmd) {
|
|
15
|
+
// Skip resolution if cmd is already an absolute path
|
|
16
|
+
if (cmd.startsWith("/") || /^[A-Za-z]:[/\\]/.test(cmd)) {
|
|
17
|
+
return cmd;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const resolver = process.platform === "win32" ? "where" : "which";
|
|
21
|
+
const output = execFileSync(resolver, [cmd], {
|
|
22
|
+
timeout: 5_000,
|
|
23
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
24
|
+
windowsHide: true,
|
|
25
|
+
}).toString("utf-8");
|
|
26
|
+
const lines = output
|
|
27
|
+
.split(/\r?\n/)
|
|
28
|
+
.map((l) => l.trim())
|
|
29
|
+
.filter(Boolean);
|
|
30
|
+
if (process.platform === "win32" && lines.length > 1) {
|
|
31
|
+
// On Windows, `where` returns multiple matches (e.g., `npx` and `npx.cmd`).
|
|
32
|
+
// Prefer .cmd/.bat entries so _buildSpawnConfig routes them through the
|
|
33
|
+
// cmd.exe wrapper path (Branch 2) instead of trying to execute an
|
|
34
|
+
// extensionless shell script with shell: false (which would fail).
|
|
35
|
+
const cmdLine = lines.find((l) => /\.(cmd|bat)$/i.test(l));
|
|
36
|
+
if (cmdLine)
|
|
37
|
+
return cmdLine;
|
|
38
|
+
}
|
|
39
|
+
return lines[0] || cmd;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// Resolution failed — fall back to the bare command name so existing
|
|
43
|
+
// behavior (PATH lookup by the shell/OS) is preserved.
|
|
44
|
+
return cmd;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
4
47
|
/**
|
|
5
48
|
* Kills an entire process group (Unix) or process tree (Windows).
|
|
6
49
|
*
|
|
@@ -87,32 +130,117 @@ export function escapeCmdArg(arg) {
|
|
|
87
130
|
escaped = escaped.replace(/!/g, "^!");
|
|
88
131
|
return escaped;
|
|
89
132
|
}
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Verbatim-mode escaping helpers (cross-spawn pattern)
|
|
135
|
+
//
|
|
136
|
+
// These are used when spawning .cmd/.bat files via cmd.exe with
|
|
137
|
+
// windowsVerbatimArguments: true, where libuv performs NO quoting.
|
|
138
|
+
// Algorithm ported from cross-spawn (https://github.com/moxystudio/node-cross-spawn).
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
/** cmd.exe metacharacters that need caret-escaping. */
|
|
141
|
+
const META_CHARS_RE = /([()\][%!^"`<>&|;, *?])/g;
|
|
142
|
+
/** Caret-escape cmd.exe metacharacters in a command path. */
|
|
143
|
+
function escapeCommandForVerbatim(cmd) {
|
|
144
|
+
return cmd.replace(META_CHARS_RE, "^$1");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Escapes a single argument for cmd.exe in windowsVerbatimArguments mode.
|
|
148
|
+
*
|
|
149
|
+
* Based on https://qntm.org/cmd (same algorithm as cross-spawn):
|
|
150
|
+
* 1. Handle backslash+quote sequences for MSVC C runtime parsing
|
|
151
|
+
* 2. Wrap in double quotes
|
|
152
|
+
* 3. Caret-escape cmd.exe metacharacters on the quoted result
|
|
153
|
+
*/
|
|
154
|
+
function escapeArgForVerbatim(arg) {
|
|
155
|
+
// Sequence of backslashes followed by a double quote:
|
|
156
|
+
// double up all the backslashes and escape the double quote.
|
|
157
|
+
// The outer `?` makes the capture group optional so bare `"` (zero
|
|
158
|
+
// preceding backslashes) is also matched — matching cross-spawn exactly.
|
|
159
|
+
let escaped = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
|
|
160
|
+
// Sequence of backslashes at end of string (will be followed by our closing quote):
|
|
161
|
+
// double up all the backslashes
|
|
162
|
+
escaped = escaped.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
163
|
+
// Wrap in double quotes, then caret-escape metacharacters
|
|
164
|
+
escaped = `"${escaped}"`;
|
|
165
|
+
escaped = escaped.replace(META_CHARS_RE, "^$1");
|
|
166
|
+
return escaped;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Determines how to spawn a command, handling Windows .cmd/.bat wrappers
|
|
170
|
+
* without using `shell: true` (which triggers CodeQL alert #16).
|
|
171
|
+
*
|
|
172
|
+
* @internal — Exported for unit testing only. Use `run()` instead.
|
|
173
|
+
*
|
|
174
|
+
* Branches:
|
|
175
|
+
* 1. Explicit `shell: true` — pass cmd directly, don't resolve (caller wants shell features)
|
|
176
|
+
* 2. Windows native .exe/.com — spawn resolved path directly
|
|
177
|
+
* 3. Windows non-exe (cmd/bat/extensionless/bare) — cmd.exe /d /s /c with windowsVerbatimArguments
|
|
178
|
+
* 4. Unix — spawn cmd directly, execvp handles PATH
|
|
179
|
+
*/
|
|
180
|
+
export function _buildSpawnConfig(cmd, args, opts, platform = process.platform, resolver = resolveCommand) {
|
|
181
|
+
// Branch 1: Explicit shell: true — caller wants shell features (pipes, globs).
|
|
182
|
+
// Pass cmd directly to spawn with shell: true — do NOT call resolveCommand,
|
|
183
|
+
// which breaks the taint flow that CodeQL flags (environment → shell command).
|
|
184
|
+
if (opts?.shell === true) {
|
|
185
|
+
const safeArgs = platform === "win32" ? args.map(escapeCmdArg) : args;
|
|
186
|
+
return { command: cmd, args: safeArgs, shell: true, windowsVerbatimArguments: false };
|
|
187
|
+
}
|
|
188
|
+
// Branches 2+3: Windows without shell
|
|
189
|
+
if (platform === "win32") {
|
|
190
|
+
const resolved = resolver(cmd);
|
|
191
|
+
// Branch 2: Native .exe/.com — spawn resolved path directly.
|
|
192
|
+
// Only these extensions are true PE executables that CreateProcessW can run
|
|
193
|
+
// without a shell. This matches cross-spawn's isExecutableRegExp check.
|
|
194
|
+
if (/\.(exe|com)$/i.test(resolved)) {
|
|
195
|
+
return { command: resolved, args, shell: false, windowsVerbatimArguments: false };
|
|
196
|
+
}
|
|
197
|
+
// Branch 3: Everything else (.cmd, .bat, extensionless, bare names) needs
|
|
198
|
+
// cmd.exe to interpret it. Use cross-spawn pattern:
|
|
199
|
+
// cmd.exe /d /s /c "escaped-command escaped-args"
|
|
200
|
+
// with windowsVerbatimArguments: true so libuv doesn't re-quote.
|
|
201
|
+
// shell: false ensures resolveCommand output never enters a shell command
|
|
202
|
+
// string from Node's perspective — satisfying CodeQL.
|
|
203
|
+
// Normalize posix slashes to Windows backslashes (cross-spawn does this too).
|
|
204
|
+
const normalizedCmd = normalize(resolved);
|
|
205
|
+
const escapedParts = [
|
|
206
|
+
escapeCommandForVerbatim(normalizedCmd),
|
|
207
|
+
...args.map((a) => escapeArgForVerbatim(a)),
|
|
208
|
+
];
|
|
209
|
+
return {
|
|
210
|
+
command: "cmd.exe",
|
|
211
|
+
args: ["/d", "/s", "/c", `"${escapedParts.join(" ")}"`],
|
|
212
|
+
shell: false,
|
|
213
|
+
windowsVerbatimArguments: true,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// Branch 4: Unix — spawn cmd directly with shell: false.
|
|
217
|
+
// execvp handles PATH lookup natively, no resolution needed.
|
|
218
|
+
return { command: cmd, args, shell: false, windowsVerbatimArguments: false };
|
|
219
|
+
}
|
|
90
220
|
/**
|
|
91
221
|
* Executes a command and returns cleaned output with ANSI codes stripped.
|
|
92
222
|
* Uses spawn (not exec) to avoid shell injection. The child is spawned in its
|
|
93
223
|
* own process group (`detached: true` on Unix) so that on timeout we can kill
|
|
94
224
|
* the entire group — preventing orphaned grandchild processes.
|
|
95
225
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
226
|
+
* Shell mode defaults to `false` on all platforms. On Windows, .cmd/.bat
|
|
227
|
+
* wrappers (like npm, npx) are automatically handled via cmd.exe invocation
|
|
228
|
+
* with windowsVerbatimArguments (cross-spawn pattern), avoiding shell injection.
|
|
229
|
+
*
|
|
230
|
+
* Callers can opt in to `shell: true` for shell features (pipes, globs),
|
|
231
|
+
* but this bypasses security protections — use only with trusted input.
|
|
98
232
|
*
|
|
99
233
|
* Throws on system-level errors (command not found, permission denied, timeout).
|
|
100
234
|
* Normal non-zero exit codes are returned in the result, not thrown.
|
|
101
235
|
*/
|
|
102
236
|
export function run(cmd, args, opts) {
|
|
103
237
|
return new Promise((resolve, reject) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// mangling format strings that contain < > characters).
|
|
107
|
-
const useShell = opts?.shell ?? process.platform === "win32";
|
|
108
|
-
// On Windows with shell mode, escape cmd.exe metacharacters to prevent
|
|
109
|
-
// environment variable expansion and command injection via special chars.
|
|
110
|
-
// See escapeCmdArg() for details on what is escaped and why.
|
|
111
|
-
const safeArgs = useShell && process.platform === "win32" ? args.map(escapeCmdArg) : args;
|
|
112
|
-
const child = spawn(cmd, safeArgs, {
|
|
238
|
+
const config = _buildSpawnConfig(cmd, args, { shell: opts?.shell });
|
|
239
|
+
const child = spawn(config.command, config.args, {
|
|
113
240
|
cwd: opts?.cwd,
|
|
114
241
|
env: opts?.env ? (opts.replaceEnv ? opts.env : { ...process.env, ...opts.env }) : undefined,
|
|
115
|
-
shell:
|
|
242
|
+
shell: config.shell,
|
|
243
|
+
windowsVerbatimArguments: config.windowsVerbatimArguments,
|
|
116
244
|
// Unix: creates a new process group via setsid(2) so we can kill the
|
|
117
245
|
// entire group on timeout (prevents orphaned grandchild processes).
|
|
118
246
|
// Windows: skip — detached on Windows creates a visible console window,
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,qDAAqD;IACrD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,CAAC;QACH,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KAAK,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAQpE,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3E;AA0BD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,CA0BnF"}
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { ErrorCode, ListResourcesRequestSchema, McpError, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
3
4
|
import { createLazyToolManager } from "./lazy-tools.js";
|
|
4
5
|
import { isLazyEnabled } from "./tool-filter.js";
|
|
6
|
+
import { strictifyInputSchema } from "./strict-input.js";
|
|
7
|
+
/**
|
|
8
|
+
* Wraps an McpServer so that every `registerTool` call automatically applies
|
|
9
|
+
* strict input validation (rejects unknown parameters) to the tool's
|
|
10
|
+
* inputSchema. This prevents AI agents from silently passing wrong-but-
|
|
11
|
+
* plausible parameter names (e.g. `branch` instead of `ref`).
|
|
12
|
+
*/
|
|
13
|
+
function applyStrictInputSchemas(server) {
|
|
14
|
+
const original = server.registerTool.bind(server);
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
server.registerTool = function (...args) {
|
|
17
|
+
// The config-based overload: registerTool(name, config, callback)
|
|
18
|
+
// config is always the second argument and contains inputSchema
|
|
19
|
+
if (args.length >= 2 && typeof args[1] === "object" && args[1] !== null) {
|
|
20
|
+
const config = args[1];
|
|
21
|
+
if (config.inputSchema) {
|
|
22
|
+
config.inputSchema = strictifyInputSchema(config.inputSchema);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
26
|
+
return original(...args);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
5
29
|
/**
|
|
6
30
|
* Creates an MCP server with the standard Pare boilerplate:
|
|
7
31
|
* instantiates McpServer, registers tools via callback, connects StdioServerTransport.
|
|
@@ -11,9 +35,20 @@ import { isLazyEnabled } from "./tool-filter.js";
|
|
|
11
35
|
export async function createServer(options) {
|
|
12
36
|
const { name, version, instructions, registerTools } = options;
|
|
13
37
|
const server = new McpServer({ name, version }, { instructions });
|
|
38
|
+
applyStrictInputSchemas(server);
|
|
14
39
|
const lazy = isLazyEnabled();
|
|
15
40
|
const lazyManager = lazy ? createLazyToolManager(server) : undefined;
|
|
16
41
|
registerTools(server, lazyManager);
|
|
42
|
+
// Pare servers are tool-only and register no resources. Some MCP clients
|
|
43
|
+
// (e.g. OpenCode) fire `resources/read` after every structured tool call,
|
|
44
|
+
// which causes a -32603 InternalError because no resource handler exists.
|
|
45
|
+
// Register stub handlers so those requests receive a clean -32602 response
|
|
46
|
+
// ("Resource not found") instead of the confusing generic error.
|
|
47
|
+
server.server.registerCapabilities({ resources: {} });
|
|
48
|
+
server.server.setRequestHandler(ListResourcesRequestSchema, () => ({ resources: [] }));
|
|
49
|
+
server.server.setRequestHandler(ReadResourceRequestSchema, (request) => {
|
|
50
|
+
throw new McpError(ErrorCode.InvalidParams, `Resource not found: ${request.params.uri}`);
|
|
51
|
+
});
|
|
17
52
|
const transport = new StdioServerTransport();
|
|
18
53
|
await server.connect(transport);
|
|
19
54
|
return server;
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,SAAS,EACT,0BAA0B,EAC1B,QAAQ,EACR,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAoBzD;;;;;GAKG;AACH,SAAS,uBAAuB,CAAC,MAAiB;IAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAElD,8DAA8D;IAC7D,MAAc,CAAC,YAAY,GAAG,UAAU,GAAG,IAAW;QACrD,kEAAkE;QAClE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C;IACvF,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,yBAAyB,EAAE,CAAC,OAAO,EAAE,EAAE;QACrE,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,aAAa,EAAE,uBAAuB,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3F,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a raw Zod shape (used as `inputSchema` in tool registration) into
|
|
3
|
+
* a strict Zod object schema that rejects unrecognized properties.
|
|
4
|
+
*
|
|
5
|
+
* By default the MCP SDK wraps raw shapes with `z.object(shape)` which
|
|
6
|
+
* silently strips unknown keys. This causes confusing errors when an AI agent
|
|
7
|
+
* passes a wrong-but-plausible parameter name (e.g. `branch` instead of `ref`).
|
|
8
|
+
*
|
|
9
|
+
* Applying `z.strictObject(shape)` instead causes validation to fail with a
|
|
10
|
+
* clear error message listing the unrecognized key.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* If `schema` is a raw Zod shape, wraps it in `z.strictObject()` so that
|
|
14
|
+
* unknown parameters are rejected during validation. If the schema is already
|
|
15
|
+
* a Zod schema instance, applies `.strict()` if it's an object schema.
|
|
16
|
+
* Otherwise returns the schema unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export declare function strictifyInputSchema<T>(schema: T): T;
|
|
19
|
+
//# sourceMappingURL=strict-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-input.d.ts","sourceRoot":"","sources":["../src/strict-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2BH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAiBpD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a raw Zod shape (used as `inputSchema` in tool registration) into
|
|
3
|
+
* a strict Zod object schema that rejects unrecognized properties.
|
|
4
|
+
*
|
|
5
|
+
* By default the MCP SDK wraps raw shapes with `z.object(shape)` which
|
|
6
|
+
* silently strips unknown keys. This causes confusing errors when an AI agent
|
|
7
|
+
* passes a wrong-but-plausible parameter name (e.g. `branch` instead of `ref`).
|
|
8
|
+
*
|
|
9
|
+
* Applying `z.strictObject(shape)` instead causes validation to fail with a
|
|
10
|
+
* clear error message listing the unrecognized key.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether a value is a Zod schema instance (has `_zod` for v4).
|
|
15
|
+
*/
|
|
16
|
+
function isZodSchema(value) {
|
|
17
|
+
return typeof value === "object" && value !== null && ("_zod" in value || "_def" in value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether a value is a "raw shape" — a plain object whose values are
|
|
21
|
+
* Zod schemas. This is the shorthand form used by all Pare tools:
|
|
22
|
+
* `{ path: z.string(), maxCount: z.number() }`.
|
|
23
|
+
*/
|
|
24
|
+
function isRawShape(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null)
|
|
26
|
+
return false;
|
|
27
|
+
// If it's already a Zod schema instance, it's NOT a raw shape
|
|
28
|
+
if (isZodSchema(value))
|
|
29
|
+
return false;
|
|
30
|
+
const entries = Object.values(value);
|
|
31
|
+
// Empty shape is valid (tools with no parameters)
|
|
32
|
+
if (entries.length === 0)
|
|
33
|
+
return true;
|
|
34
|
+
// A raw shape has values that are Zod schemas
|
|
35
|
+
return entries.some((v) => isZodSchema(v));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* If `schema` is a raw Zod shape, wraps it in `z.strictObject()` so that
|
|
39
|
+
* unknown parameters are rejected during validation. If the schema is already
|
|
40
|
+
* a Zod schema instance, applies `.strict()` if it's an object schema.
|
|
41
|
+
* Otherwise returns the schema unchanged.
|
|
42
|
+
*/
|
|
43
|
+
export function strictifyInputSchema(schema) {
|
|
44
|
+
if (!schema)
|
|
45
|
+
return schema;
|
|
46
|
+
if (isRawShape(schema)) {
|
|
47
|
+
// Convert raw shape to strict object schema.
|
|
48
|
+
// The MCP SDK's normalizeObjectSchema will recognize this as a pre-built
|
|
49
|
+
// Zod v4 schema and use it directly instead of wrapping in z.object().
|
|
50
|
+
return z.strictObject(schema);
|
|
51
|
+
}
|
|
52
|
+
// If it's already a Zod object schema, apply .strict()
|
|
53
|
+
const schemaObj = schema;
|
|
54
|
+
if (isZodSchema(schema) && typeof schemaObj.strict === "function") {
|
|
55
|
+
return schemaObj.strict();
|
|
56
|
+
}
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=strict-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-input.js","sourceRoot":"","sources":["../src/strict-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,8DAA8D;IAC9D,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,kDAAkD;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,8CAA8C;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAI,MAAS;IAC/C,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAE3B,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,6CAA6C;QAC7C,yEAAyE;QACzE,uEAAuE;QACvE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAmC,CAAiB,CAAC;IAC7E,CAAC;IAED,uDAAuD;IACvD,MAAM,SAAS,GAAG,MAAiC,CAAC;IACpD,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,OAAO,SAAS,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAClE,OAAQ,SAAS,CAAC,MAAwB,EAAO,CAAC;IACpD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preprocess function for Zod schemas that coerces a JSON string to an array.
|
|
3
|
+
* Handles the case where MCP clients serialize array parameters as JSON strings
|
|
4
|
+
* before the tool schema is fully loaded.
|
|
5
|
+
*
|
|
6
|
+
* Usage: `z.preprocess(coerceJsonArray, z.array(z.string()))`
|
|
7
|
+
*/
|
|
8
|
+
export declare function coerceJsonArray(val: unknown): unknown;
|
|
1
9
|
/**
|
|
2
10
|
* Validates that a string argument is safe to pass as a positional argument to a CLI tool.
|
|
3
11
|
* Prevents flag injection attacks (e.g., passing "--output=/etc/passwd" as a ref name).
|
package/dist/validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAM5E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAMzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CASzE;AAiCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAwB1D"}
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOrD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAM5E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAMzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CASzE;AAiCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAwB1D"}
|
package/dist/validation.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preprocess function for Zod schemas that coerces a JSON string to an array.
|
|
3
|
+
* Handles the case where MCP clients serialize array parameters as JSON strings
|
|
4
|
+
* before the tool schema is fully loaded.
|
|
5
|
+
*
|
|
6
|
+
* Usage: `z.preprocess(coerceJsonArray, z.array(z.string()))`
|
|
7
|
+
*/
|
|
8
|
+
export function coerceJsonArray(val) {
|
|
9
|
+
if (typeof val !== "string")
|
|
10
|
+
return val;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(val);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return val;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
1
18
|
/**
|
|
2
19
|
* Validates that a string argument is safe to pass as a positional argument to a CLI tool.
|
|
3
20
|
* Prevents flag injection attacks (e.g., passing "--output=/etc/passwd" as a ref name).
|
package/dist/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa,EAAE,SAAiB;IACpE,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,MAAM,KAAK,kEAAkE,CAClG,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,SAAiB;IACjE,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,MAAM,KAAK,yDAAyD,CACzF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,SAAiB;IACjE,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,YAAY,KAAK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AM;IACN,OAAO;IACP,QAAQ;IACR,SAAS;IACT,KAAK;IACL,KAAK;IACL,OAAO;IACP,IAAI;IACJ,QAAQ;IACR,SAAS;IACT,KAAK;IACL,SAAS;IACT,MAAM;IACN,SAAS;IACT,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,OAAO;CACR,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,+EAA+E;IAC/E,MAAM,IAAI,GACR,OAAO;SACJ,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,EAAE;QACN,EAAE,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,YAAY,OAAO,+CAA+C;YAChE,YAAY,CAAC,GAAG,sBAAsB,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC9D,CAAC;IACJ,CAAC;IAED,2FAA2F;IAC3F,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CACV,8CAA8C,OAAO,KAAK;YACxD,sBAAsB,IAAI,yCAAyC;YACnE,8CAA8C,CACjD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the `version` field from the nearest `package.json` relative to
|
|
3
|
+
* the calling module's `import.meta.url`.
|
|
4
|
+
*
|
|
5
|
+
* Walks up directory tree from the given module URL until it finds a
|
|
6
|
+
* `package.json` with a `version` field, or returns `"0.0.0"` as a
|
|
7
|
+
* fallback.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { readPackageVersion } from "@paretools/shared";
|
|
12
|
+
* const version = readPackageVersion(import.meta.url);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function readPackageVersion(importMetaUrl: string): string;
|
|
16
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAwBhE"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Reads the `version` field from the nearest `package.json` relative to
|
|
6
|
+
* the calling module's `import.meta.url`.
|
|
7
|
+
*
|
|
8
|
+
* Walks up directory tree from the given module URL until it finds a
|
|
9
|
+
* `package.json` with a `version` field, or returns `"0.0.0"` as a
|
|
10
|
+
* fallback.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { readPackageVersion } from "@paretools/shared";
|
|
15
|
+
* const version = readPackageVersion(import.meta.url);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function readPackageVersion(importMetaUrl) {
|
|
19
|
+
let dir = dirname(fileURLToPath(importMetaUrl));
|
|
20
|
+
// Walk up to find the nearest package.json with a version field
|
|
21
|
+
for (;;) {
|
|
22
|
+
try {
|
|
23
|
+
const pkgPath = join(dir, "package.json");
|
|
24
|
+
const raw = readFileSync(pkgPath, "utf-8");
|
|
25
|
+
const pkg = JSON.parse(raw);
|
|
26
|
+
if (pkg.version) {
|
|
27
|
+
return pkg.version;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// No package.json in this directory, keep walking up
|
|
32
|
+
}
|
|
33
|
+
const parent = dirname(dir);
|
|
34
|
+
if (parent === dir) {
|
|
35
|
+
// Reached filesystem root
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
dir = parent;
|
|
39
|
+
}
|
|
40
|
+
return "0.0.0";
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,aAAqB;IACtD,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IAEhD,gEAAgE;IAChE,SAAS,CAAC;QACR,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;YAC1C,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;YACpD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;gBAChB,OAAO,GAAG,CAAC,OAAO,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,qDAAqD;QACvD,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,0BAA0B;YAC1B,MAAM;QACR,CAAC;QACD,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paretools/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Shared utilities for Pare MCP servers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@modelcontextprotocol/sdk": "^1.27.
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
44
44
|
"zod": "^4.3.6"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^25.3.
|
|
47
|
+
"@types/node": "^25.3.3",
|
|
48
48
|
"typescript": "^5.7.0",
|
|
49
49
|
"vitest": "^4.0.18",
|
|
50
50
|
"@paretools/tsconfig": "0.0.0"
|