@paretools/shared 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dave London
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/ansi.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function stripAnsi(str: string): string;
2
+ //# sourceMappingURL=ansi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAOA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
package/dist/ansi.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Strips ANSI escape codes from a string.
3
+ * Handles SGR (colors/styles), cursor movement, and other terminal sequences.
4
+ */
5
+ // eslint-disable-next-line no-control-regex
6
+ const ANSI_REGEX = /\x1B(?:\][^\x07]*\x07|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
7
+ export function stripAnsi(str) {
8
+ return str.replace(ANSI_REGEX, "");
9
+ }
10
+ //# sourceMappingURL=ansi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi.js","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,4CAA4C;AAC5C,MAAM,UAAU,GAAG,uDAAuD,CAAC;AAE3E,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { dualOutput } from "./output.js";
2
+ export { run, type RunResult, type RunOptions } from "./runner.js";
3
+ export { stripAnsi } from "./ansi.js";
4
+ export type { ToolOutput } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { dualOutput } from "./output.js";
2
+ export { run } from "./runner.js";
3
+ export { stripAnsi } from "./ansi.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAmC,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ToolOutput } from "./types.js";
2
+ /**
3
+ * Creates the dual-output response that every pare tool returns.
4
+ *
5
+ * - `content`: Human-readable text for MCP clients that don't support structuredContent.
6
+ * - `structuredContent`: Typed, schema-validated JSON for agents.
7
+ *
8
+ * @param data - The structured data to return.
9
+ * @param humanFormat - A function that formats `data` as human-readable text.
10
+ */
11
+ export declare function dualOutput<T>(data: T, humanFormat: (d: T) => string): ToolOutput<T>;
12
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;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"}
package/dist/output.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Creates the dual-output response that every pare tool returns.
3
+ *
4
+ * - `content`: Human-readable text for MCP clients that don't support structuredContent.
5
+ * - `structuredContent`: Typed, schema-validated JSON for agents.
6
+ *
7
+ * @param data - The structured data to return.
8
+ * @param humanFormat - A function that formats `data` as human-readable text.
9
+ */
10
+ export function dualOutput(data, humanFormat) {
11
+ return {
12
+ content: [{ type: "text", text: humanFormat(data) }],
13
+ structuredContent: data,
14
+ };
15
+ }
16
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAI,IAAO,EAAE,WAA6B;IAClE,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,iBAAiB,EAAE,IAAI;KACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ export interface RunOptions {
2
+ cwd?: string;
3
+ timeout?: number;
4
+ env?: Record<string, string>;
5
+ }
6
+ export interface RunResult {
7
+ exitCode: number;
8
+ stdout: string;
9
+ stderr: string;
10
+ }
11
+ /**
12
+ * Executes a command and returns cleaned output with ANSI codes stripped.
13
+ * Uses execFile (not exec) to avoid shell injection. On Windows, shell is
14
+ * enabled so that .cmd/.bat wrappers (like npx) can be executed — args are
15
+ * still passed as an array so they remain properly escaped.
16
+ */
17
+ export declare function run(cmd: string, args: string[], opts?: RunOptions): Promise<RunResult>;
18
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAGA,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;CAC9B;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBtF"}
package/dist/runner.js ADDED
@@ -0,0 +1,26 @@
1
+ import { execFile } from "node:child_process";
2
+ import { stripAnsi } from "./ansi.js";
3
+ /**
4
+ * Executes a command and returns cleaned output with ANSI codes stripped.
5
+ * Uses execFile (not exec) to avoid shell injection. On Windows, shell is
6
+ * enabled so that .cmd/.bat wrappers (like npx) can be executed — args are
7
+ * still passed as an array so they remain properly escaped.
8
+ */
9
+ export function run(cmd, args, opts) {
10
+ return new Promise((resolve) => {
11
+ execFile(cmd, args, {
12
+ cwd: opts?.cwd,
13
+ timeout: opts?.timeout ?? 30_000,
14
+ env: opts?.env ? { ...process.env, ...opts.env } : undefined,
15
+ maxBuffer: 10 * 1024 * 1024, // 10 MB
16
+ shell: process.platform === "win32",
17
+ }, (error, stdout, stderr) => {
18
+ resolve({
19
+ exitCode: error && "code" in error ? error.code : error ? 1 : 0,
20
+ stdout: stripAnsi(stdout),
21
+ stderr: stripAnsi(stderr),
22
+ });
23
+ });
24
+ });
25
+ }
26
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AActC;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,IAAc,EAAE,IAAiB;IAChE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,QAAQ,CACN,GAAG,EACH,IAAI,EACJ;YACE,GAAG,EAAE,IAAI,EAAE,GAAG;YACd,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,MAAM;YAChC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS;YAC5D,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,QAAQ;YACrC,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;SACpC,EACD,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACxB,OAAO,CAAC;gBACN,QAAQ,EAAE,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,CAAE,KAAK,CAAC,IAAe,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3E,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;gBACzB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;aAC1B,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The return type for every pare tool — dual output with both
3
+ * human-readable content and machine-parseable structuredContent.
4
+ *
5
+ * The index signature satisfies the MCP SDK's CallToolResult type.
6
+ */
7
+ export type ToolOutput<T = unknown> = {
8
+ [key: string]: unknown;
9
+ content: Array<{
10
+ type: "text";
11
+ text: string;
12
+ }>;
13
+ structuredContent: T;
14
+ };
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,CAAC,CAAC;CACtB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@paretools/shared",
3
+ "version": "0.2.0",
4
+ "description": "Shared utilities for pare MCP servers",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/Dave-London/pare.git",
19
+ "directory": "packages/shared"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@modelcontextprotocol/sdk": "^1.26.0",
26
+ "zod": "^3.25.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^22.0.0",
30
+ "typescript": "^5.7.0",
31
+ "vitest": "^3.0.0",
32
+ "@paretools/tsconfig": "0.0.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "test": "vitest run",
37
+ "lint": "eslint src/"
38
+ }
39
+ }