@j0hanz/prompt-tuner-mcp-server 1.0.8 → 1.0.9

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.
Files changed (213) hide show
  1. package/AGENTS.md +70 -27
  2. package/benchmark/llm-json.bench.ts +96 -0
  3. package/benchmark/output-validation.bench.ts +108 -0
  4. package/benchmark/prompt-analysis.bench.ts +105 -0
  5. package/dist/config/constants.d.ts +0 -1
  6. package/dist/config/constants.js +0 -1
  7. package/dist/config/env.d.ts +0 -1
  8. package/dist/config/env.js +0 -1
  9. package/dist/config/instructions.d.ts +0 -1
  10. package/dist/config/instructions.js +0 -1
  11. package/dist/config/patterns.d.ts +0 -1
  12. package/dist/config/patterns.js +0 -1
  13. package/dist/config/types.d.ts +4 -1
  14. package/dist/config/types.js +0 -1
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.js +6 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/abort-signals.d.ts +0 -1
  19. package/dist/lib/abort-signals.js +0 -1
  20. package/dist/lib/errors.d.ts +0 -1
  21. package/dist/lib/errors.js +0 -1
  22. package/dist/lib/llm-client.d.ts +0 -1
  23. package/dist/lib/llm-client.js +0 -1
  24. package/dist/lib/llm-json/scan.d.ts +1 -0
  25. package/dist/lib/llm-json/scan.d.ts.map +1 -0
  26. package/dist/lib/llm-json/scan.js +93 -0
  27. package/dist/lib/llm-json/scan.js.map +1 -0
  28. package/dist/lib/llm-json.d.ts +0 -1
  29. package/dist/lib/llm-json.d.ts.map +1 -1
  30. package/dist/lib/llm-json.js +48 -83
  31. package/dist/lib/llm-json.js.map +1 -1
  32. package/dist/lib/llm-providers/helpers.d.ts +0 -1
  33. package/dist/lib/llm-providers/helpers.js +0 -1
  34. package/dist/lib/llm-providers.d.ts +11 -32
  35. package/dist/lib/llm-providers.d.ts.map +1 -1
  36. package/dist/lib/llm-providers.js +16 -30
  37. package/dist/lib/llm-providers.js.map +1 -1
  38. package/dist/lib/llm-runtime.d.ts +0 -1
  39. package/dist/lib/llm-runtime.d.ts.map +1 -1
  40. package/dist/lib/llm-runtime.js +79 -55
  41. package/dist/lib/llm-runtime.js.map +1 -1
  42. package/dist/lib/llm.d.ts +0 -1
  43. package/dist/lib/llm.js +0 -1
  44. package/dist/lib/output-normalization.d.ts +0 -1
  45. package/dist/lib/output-normalization.d.ts.map +1 -1
  46. package/dist/lib/output-normalization.js +11 -16
  47. package/dist/lib/output-normalization.js.map +1 -1
  48. package/dist/lib/output-validation.d.ts +0 -1
  49. package/dist/lib/output-validation.d.ts.map +1 -1
  50. package/dist/lib/output-validation.js +60 -109
  51. package/dist/lib/output-validation.js.map +1 -1
  52. package/dist/lib/prompt-analysis/format.d.ts +3 -3
  53. package/dist/lib/prompt-analysis/format.d.ts.map +1 -1
  54. package/dist/lib/prompt-analysis/format.js +18 -10
  55. package/dist/lib/prompt-analysis/format.js.map +1 -1
  56. package/dist/lib/prompt-analysis.d.ts +1 -2
  57. package/dist/lib/prompt-analysis.d.ts.map +1 -1
  58. package/dist/lib/prompt-analysis.js +1 -2
  59. package/dist/lib/prompt-analysis.js.map +1 -1
  60. package/dist/lib/prompt-policy.d.ts +1 -2
  61. package/dist/lib/prompt-policy.d.ts.map +1 -1
  62. package/dist/lib/prompt-policy.js +11 -5
  63. package/dist/lib/prompt-policy.js.map +1 -1
  64. package/dist/lib/retry.d.ts.map +1 -1
  65. package/dist/lib/retry.js +37 -56
  66. package/dist/lib/retry.js.map +1 -1
  67. package/dist/lib/technique-templates/format-instructions.d.ts +0 -1
  68. package/dist/lib/technique-templates/format-instructions.js +0 -1
  69. package/dist/lib/technique-templates/templates-advanced.d.ts +0 -1
  70. package/dist/lib/technique-templates/templates-advanced.js +0 -1
  71. package/dist/lib/technique-templates/templates-basic.d.ts +0 -1
  72. package/dist/lib/technique-templates/templates-basic.js +0 -1
  73. package/dist/lib/technique-templates.d.ts +0 -1
  74. package/dist/lib/technique-templates.js +0 -1
  75. package/dist/lib/tool-context.d.ts +0 -1
  76. package/dist/lib/tool-context.js +0 -1
  77. package/dist/lib/tool-formatters.d.ts +0 -1
  78. package/dist/lib/tool-formatters.js +0 -1
  79. package/dist/lib/tool-helpers.d.ts +0 -1
  80. package/dist/lib/tool-helpers.d.ts.map +1 -1
  81. package/dist/lib/tool-helpers.js +47 -25
  82. package/dist/lib/tool-helpers.js.map +1 -1
  83. package/dist/lib/tool-resources.d.ts +0 -1
  84. package/dist/lib/tool-resources.js +0 -1
  85. package/dist/lib/validation.d.ts +0 -1
  86. package/dist/lib/validation.js +0 -1
  87. package/dist/prompts/index.d.ts +0 -1
  88. package/dist/prompts/index.js +0 -1
  89. package/dist/prompts/quick-workflows.d.ts +0 -1
  90. package/dist/prompts/quick-workflows.js +3 -4
  91. package/dist/schemas/index.d.ts +0 -1
  92. package/dist/schemas/index.js +0 -1
  93. package/dist/schemas/inputs.d.ts +8 -9
  94. package/dist/schemas/inputs.d.ts.map +1 -1
  95. package/dist/schemas/inputs.js +16 -9
  96. package/dist/schemas/inputs.js.map +1 -1
  97. package/dist/schemas/llm-responses.d.ts +24 -25
  98. package/dist/schemas/llm-responses.js +0 -1
  99. package/dist/schemas/outputs.d.ts +32 -33
  100. package/dist/schemas/outputs.js +0 -1
  101. package/dist/server.d.ts +0 -1
  102. package/dist/server.d.ts.map +1 -1
  103. package/dist/server.js +2 -48
  104. package/dist/server.js.map +1 -1
  105. package/dist/tools/analyze-prompt.d.ts +0 -1
  106. package/dist/tools/analyze-prompt.d.ts.map +1 -1
  107. package/dist/tools/analyze-prompt.js +27 -24
  108. package/dist/tools/analyze-prompt.js.map +1 -1
  109. package/dist/tools/index.d.ts +0 -1
  110. package/dist/tools/index.js +0 -1
  111. package/dist/tools/optimize-prompt/constants.d.ts +5 -0
  112. package/dist/tools/optimize-prompt/constants.d.ts.map +1 -0
  113. package/dist/tools/optimize-prompt/constants.js +60 -0
  114. package/dist/tools/optimize-prompt/constants.js.map +1 -0
  115. package/dist/tools/optimize-prompt/formatters.d.ts +0 -1
  116. package/dist/tools/optimize-prompt/formatters.d.ts.map +1 -1
  117. package/dist/tools/optimize-prompt/formatters.js +33 -12
  118. package/dist/tools/optimize-prompt/formatters.js.map +1 -1
  119. package/dist/tools/optimize-prompt/inputs.d.ts +4 -0
  120. package/dist/tools/optimize-prompt/inputs.d.ts.map +1 -0
  121. package/dist/tools/optimize-prompt/inputs.js +21 -0
  122. package/dist/tools/optimize-prompt/inputs.js.map +1 -0
  123. package/dist/tools/optimize-prompt/output.d.ts +7 -0
  124. package/dist/tools/optimize-prompt/output.d.ts.map +1 -0
  125. package/dist/tools/optimize-prompt/output.js +57 -0
  126. package/dist/tools/optimize-prompt/output.js.map +1 -0
  127. package/dist/tools/optimize-prompt/prompt.d.ts +2 -0
  128. package/dist/tools/optimize-prompt/prompt.d.ts.map +1 -0
  129. package/dist/tools/optimize-prompt/prompt.js +5 -0
  130. package/dist/tools/optimize-prompt/prompt.js.map +1 -0
  131. package/dist/tools/optimize-prompt/run.d.ts +2 -0
  132. package/dist/tools/optimize-prompt/run.d.ts.map +1 -0
  133. package/dist/tools/optimize-prompt/run.js +14 -0
  134. package/dist/tools/optimize-prompt/run.js.map +1 -0
  135. package/dist/tools/optimize-prompt/types.d.ts +25 -0
  136. package/dist/tools/optimize-prompt/types.d.ts.map +1 -0
  137. package/dist/tools/optimize-prompt/types.js +1 -0
  138. package/dist/tools/optimize-prompt/types.js.map +1 -0
  139. package/dist/tools/optimize-prompt/validation.d.ts +7 -0
  140. package/dist/tools/optimize-prompt/validation.d.ts.map +1 -0
  141. package/dist/tools/optimize-prompt/validation.js +64 -0
  142. package/dist/tools/optimize-prompt/validation.js.map +1 -0
  143. package/dist/tools/optimize-prompt.d.ts +0 -1
  144. package/dist/tools/optimize-prompt.d.ts.map +1 -1
  145. package/dist/tools/optimize-prompt.js +49 -352
  146. package/dist/tools/optimize-prompt.js.map +1 -1
  147. package/dist/tools/refine-prompt/formatters.d.ts +10 -0
  148. package/dist/tools/refine-prompt/formatters.d.ts.map +1 -0
  149. package/dist/tools/refine-prompt/formatters.js +39 -0
  150. package/dist/tools/refine-prompt/formatters.js.map +1 -0
  151. package/dist/tools/refine-prompt/types.d.ts +16 -0
  152. package/dist/tools/refine-prompt/types.d.ts.map +1 -0
  153. package/dist/tools/refine-prompt/types.js +1 -0
  154. package/dist/tools/refine-prompt/types.js.map +1 -0
  155. package/dist/tools/refine-prompt.d.ts +0 -1
  156. package/dist/tools/refine-prompt.d.ts.map +1 -1
  157. package/dist/tools/refine-prompt.js +71 -81
  158. package/dist/tools/refine-prompt.js.map +1 -1
  159. package/dist/tools/validate-prompt/formatters.d.ts +6 -0
  160. package/dist/tools/validate-prompt/formatters.d.ts.map +1 -0
  161. package/dist/tools/validate-prompt/formatters.js +45 -0
  162. package/dist/tools/validate-prompt/formatters.js.map +1 -0
  163. package/dist/tools/validate-prompt/prompt.d.ts +1 -2
  164. package/dist/tools/validate-prompt/prompt.d.ts.map +1 -1
  165. package/dist/tools/validate-prompt/prompt.js +0 -1
  166. package/dist/tools/validate-prompt/types.d.ts +1 -0
  167. package/dist/tools/validate-prompt/types.d.ts.map +1 -0
  168. package/dist/tools/validate-prompt/types.js +1 -0
  169. package/dist/tools/validate-prompt/types.js.map +1 -0
  170. package/dist/tools/validate-prompt.d.ts +0 -1
  171. package/dist/tools/validate-prompt.d.ts.map +1 -1
  172. package/dist/tools/validate-prompt.js +12 -81
  173. package/dist/tools/validate-prompt.js.map +1 -1
  174. package/eslint.config.mjs +7 -0
  175. package/package.json +2 -2
  176. package/src/config/types.ts +4 -0
  177. package/src/index.ts +7 -1
  178. package/src/lib/llm-json/scan.ts +123 -0
  179. package/src/lib/llm-json.ts +92 -103
  180. package/src/lib/llm-providers.ts +37 -74
  181. package/src/lib/llm-runtime.ts +126 -81
  182. package/src/lib/output-normalization.ts +11 -17
  183. package/src/lib/output-validation.ts +71 -122
  184. package/src/lib/prompt-analysis/format.ts +23 -9
  185. package/src/lib/prompt-analysis.ts +5 -1
  186. package/src/lib/prompt-policy.ts +12 -4
  187. package/src/lib/tool-helpers.ts +130 -33
  188. package/src/prompts/quick-workflows.ts +3 -3
  189. package/src/schemas/inputs.ts +52 -44
  190. package/src/server.ts +2 -57
  191. package/src/tools/analyze-prompt.ts +43 -31
  192. package/src/tools/optimize-prompt/constants.ts +66 -0
  193. package/src/tools/optimize-prompt/formatters.ts +43 -13
  194. package/src/tools/optimize-prompt/inputs.ts +40 -0
  195. package/src/tools/optimize-prompt/output.ts +96 -0
  196. package/src/tools/optimize-prompt/prompt.ts +19 -0
  197. package/src/tools/optimize-prompt/run.ts +27 -0
  198. package/src/tools/optimize-prompt/types.ts +35 -0
  199. package/src/tools/optimize-prompt/validation.ts +114 -0
  200. package/src/tools/optimize-prompt.ts +86 -582
  201. package/src/tools/refine-prompt/formatters.ts +82 -0
  202. package/src/tools/refine-prompt/types.ts +22 -0
  203. package/src/tools/refine-prompt.ts +151 -155
  204. package/src/tools/validate-prompt/formatters.ts +77 -0
  205. package/src/tools/validate-prompt/types.ts +1 -0
  206. package/src/tools/validate-prompt.ts +20 -120
  207. package/tests/input-schema.test.ts +59 -0
  208. package/tests/llm-json.test.ts +19 -0
  209. package/tests/output-validation.test.ts +43 -0
  210. package/tsconfig.build.json +7 -0
  211. package/src/lib/retry.ts +0 -271
  212. package/src/lib/tool-context.ts +0 -21
  213. package/tests/retry.test.ts +0 -42
package/AGENTS.md CHANGED
@@ -1,39 +1,82 @@
1
- # Repository Guidelines
1
+ # AGENTS.md
2
2
 
3
- ## Project Structure & Module Organization
3
+ ## Project Overview
4
4
 
5
- - `src/` holds TypeScript source. `src/index.ts` is the entry point and `src/server.ts` wires the MCP server. Subfolders include `config/`, `lib/`, `tools/`, `resources/`, `prompts/`, `schemas/`, and `types/`.
6
- - `tests/` contains Vitest suites; test files use the `*.test.ts` naming pattern.
7
- - `dist/` is generated build output (do not edit by hand).
8
- - `docs/` stores static assets. `CONFIGURATION.md` documents runtime environment variables.
5
+ - **Goal**: MCP server for refining, analyzing, optimizing, and validating AI prompts.
6
+ - **Stack**: Node.js (>=20), TypeScript, Model Context Protocol (MCP), Zod, Vitest.
7
+ - **Key Libraries**: `@modelcontextprotocol/sdk`, `openai`, `@anthropic-ai/sdk`, `@google/genai`, `zod`.
9
8
 
10
- ## Build, Test, and Development Commands
9
+ ## Repo Map / Structure
11
10
 
12
- - `npm run dev` / `npm run dev:http`: run from source with tsx watch (HTTP variant adds `--http`).
13
- - `npm run build`: compile TypeScript into `dist/` and set executable permissions.
14
- - `npm run start` / `npm run start:http`: run the compiled server from `dist/`.
15
- - `npm run test` / `npm run test:watch`: run Vitest once or in watch mode.
16
- - `npm run lint` and `npm run format`: ESLint checks and Prettier formatting.
17
- - `npm run type-check`: `tsc --noEmit` for strict type validation.
11
+ - `src/`: TypeScript source code.
12
+ - `index.ts`: CLI entry point.
13
+ - `server.ts`: MCP server initialization and tool registration.
14
+ - `config/`: Environment variables, constants, and configuration logic.
15
+ - `lib/`: Core logic (LLM clients, retry mechanisms, validation, prompt analysis).
16
+ - `tools/`: Tool implementations (`refine_prompt`, `analyze_prompt`, etc.).
17
+ - `schemas/`: Zod schemas for inputs and outputs.
18
+ - `prompts/`: Internal prompt templates used by the server.
19
+ - `tests/`: Integration and unit tests (`*.test.ts`).
20
+ - `dist/`: Compiled JavaScript output (generated).
21
+ - `docs/`: Documentation assets.
22
+ - `CONFIGURATION.md`: Detailed environment variable reference.
18
23
 
19
- ## Coding Style & Naming Conventions
24
+ ## Setup & Environment
20
25
 
21
- - TypeScript, ES modules, Node >= 20.
22
- - Prettier rules: 2-space indentation, single quotes, trailing commas, 80-char line width, sorted imports.
23
- - ESLint is strict; avoid `any`, unused imports, and floating promises; prefer `type` imports.
24
- - Naming: `camelCase` for variables/functions, `PascalCase` for types, `UPPER_CASE` for constants; leading `_` is allowed for unused args.
26
+ - **Install dependencies**: `npm install`
27
+ - **Environment variables**:
28
+ - Defined in `src/config/env.ts` and documented in `CONFIGURATION.md`.
29
+ - Key variables: `LLM_PROVIDER`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`.
30
+ - **Node.js Version**: `>=20.0.0` (enforced in `package.json`).
25
31
 
26
- ## Testing Guidelines
32
+ ## Development Workflow
27
33
 
28
- - Use Vitest in the Node environment; keep tests in `tests/` and name `*.test.ts`.
29
- - Favor deterministic tests and keep individual tests under the 15s timeout.
34
+ - **Dev mode**: `npm run dev` (runs `src/index.ts` with `tsx watch`).
35
+ - **Build**: `npm run build` (compiles to `dist/` and sets executable permissions).
36
+ - **Start production**: `npm run start` (runs `dist/index.js`).
37
+ - **MCP Inspector**: `npm run inspector` (debugs the server using the MCP inspector).
30
38
 
31
- ## Commit & Pull Request Guidelines
39
+ ## Testing
32
40
 
33
- - History favors short, imperative summaries; common pattern is `refactor: ...`, plus plain `Add ...` and version bumps like `1.0.5`.
34
- - PRs should include a brief summary, tests run (for example, `npm run test`), and note any config or environment changes. Link related issues when applicable.
41
+ - **Run all tests**: `npm run test` (uses Vitest).
42
+ - **Watch mode**: `npm run test:watch`.
43
+ - **Coverage**: `npm run test:coverage`.
44
+ - **Test files**: Located in `tests/` directory, matching `*.test.ts`.
35
45
 
36
- ## Security & Configuration Tips
46
+ ## Code Style & Conventions
37
47
 
38
- - Runtime behavior is driven by environment variables; see `CONFIGURATION.md` for required keys and limits.
39
- - Never commit API keys. Be cautious with `INCLUDE_ERROR_CONTEXT=true` in production.
48
+ - **Language**: TypeScript (ES2022 target, NodeNext module resolution).
49
+ - **Linting**: `npm run lint` (ESLint with `typescript-eslint` and `unused-imports`).
50
+ - **Formatting**: `npm run format` (Prettier).
51
+ - **Type Checking**: `npm run type-check` (runs `tsc --noEmit`).
52
+ - **Naming Conventions**:
53
+ - Variables/Functions: `camelCase`.
54
+ - Types/Interfaces/Classes: `PascalCase`.
55
+ - Constants: `UPPER_CASE`.
56
+ - Files: `kebab-case`.
57
+ - **Rules**:
58
+ - No `any` types (`@typescript-eslint/no-explicit-any`).
59
+ - Explicit function return types required.
60
+ - Unused imports are forbidden.
61
+ - Prefer `type` imports.
62
+
63
+ ## Build / Release
64
+
65
+ - **Output Directory**: `dist/` (cleared and regenerated on build).
66
+ - **Process**: `npm run build` compiles TS to JS and makes `dist/index.js` executable.
67
+
68
+ ## Security & Safety
69
+
70
+ - **Secrets**: API keys must be passed via environment variables; never committed.
71
+ - **Validation**: All tool inputs are validated using Zod schemas in `src/schemas/`.
72
+ - **Error Handling**: Error context is sanitized to prevent leaking sensitive info (controlled by `INCLUDE_ERROR_CONTEXT`).
73
+
74
+ ## Pull Request / Commit Guidelines
75
+
76
+ - **Commit Messages**: Imperative mood (e.g., "Add feature", "Fix bug").
77
+ - **Required Checks**: Ensure `npm run lint`, `npm run type-check`, and `npm run test` pass before submitting.
78
+
79
+ ## Troubleshooting
80
+
81
+ - **Missing API Key**: Ensure `LLM_PROVIDER` matches the set API key (e.g., `OPENAI_API_KEY` for `openai`).
82
+ - **Build Errors**: Run `npm run type-check` to identify TypeScript issues.
@@ -0,0 +1,96 @@
1
+ import { performance } from 'node:perf_hooks';
2
+
3
+ import { ErrorCode } from '../src/lib/errors.js';
4
+ import { parseJsonFromLlmResponse } from '../src/lib/llm-json.js';
5
+
6
+ type BenchResult = {
7
+ label: string;
8
+ iterations: number;
9
+ meanMs: number;
10
+ p50Ms: number;
11
+ p95Ms: number;
12
+ minMs: number;
13
+ maxMs: number;
14
+ heapUsedMb: number;
15
+ };
16
+
17
+ const RAW_JSON = '{"ok":true,"count":2}';
18
+ const CODE_BLOCK_JSON = '```json\n{"ok":true,"count":2}\n```';
19
+ const EMBEDDED_JSON =
20
+ 'Result: {"ok":true,"text":"{value}","items":[{"a":1},{"a":2}]} done';
21
+
22
+ const ITERATIONS = 15000;
23
+ const WARMUP = 1500;
24
+
25
+ function percentile(values: number[], p: number): number {
26
+ if (values.length === 0) return 0;
27
+ const index = Math.floor((values.length - 1) * p);
28
+ return values[index] ?? 0;
29
+ }
30
+
31
+ function round(value: number, digits = 3): number {
32
+ const factor = 10 ** digits;
33
+ return Math.round(value * factor) / factor;
34
+ }
35
+
36
+ function runBench(label: string, payload: string): BenchResult {
37
+ if (global.gc) global.gc();
38
+
39
+ for (let i = 0; i < WARMUP; i += 1) {
40
+ parseJsonFromLlmResponse(
41
+ payload,
42
+ (value) => value as { ok: boolean; count?: number },
43
+ { errorCode: ErrorCode.E_INVALID_INPUT }
44
+ );
45
+ }
46
+
47
+ const times: number[] = new Array(ITERATIONS);
48
+ const startMem = process.memoryUsage().heapUsed;
49
+
50
+ for (let i = 0; i < ITERATIONS; i += 1) {
51
+ const start = performance.now();
52
+ parseJsonFromLlmResponse(
53
+ payload,
54
+ (value) => value as { ok: boolean; count?: number },
55
+ { errorCode: ErrorCode.E_INVALID_INPUT }
56
+ );
57
+ times[i] = performance.now() - start;
58
+ }
59
+
60
+ if (global.gc) global.gc();
61
+ const endMem = process.memoryUsage().heapUsed;
62
+
63
+ const sorted = [...times].sort((a, b) => a - b);
64
+ const mean = times.reduce((sum, value) => sum + value, 0) / times.length;
65
+ const heapUsedMb = endMem / 1024 / 1024;
66
+
67
+ return {
68
+ label,
69
+ iterations: ITERATIONS,
70
+ meanMs: round(mean),
71
+ p50Ms: round(percentile(sorted, 0.5)),
72
+ p95Ms: round(percentile(sorted, 0.95)),
73
+ minMs: round(sorted[0] ?? 0),
74
+ maxMs: round(sorted[sorted.length - 1] ?? 0),
75
+ heapUsedMb: round(heapUsedMb, 2),
76
+ };
77
+ }
78
+
79
+ const results: BenchResult[] = [
80
+ runBench('parse:raw', RAW_JSON),
81
+ runBench('parse:codeblock', CODE_BLOCK_JSON),
82
+ runBench('parse:embedded', EMBEDDED_JSON),
83
+ ];
84
+
85
+ console.log(
86
+ JSON.stringify(
87
+ {
88
+ node: process.version,
89
+ iterations: ITERATIONS,
90
+ warmup: WARMUP,
91
+ results,
92
+ },
93
+ null,
94
+ 2
95
+ )
96
+ );
@@ -0,0 +1,108 @@
1
+ import { performance } from 'node:perf_hooks';
2
+
3
+ import {
4
+ normalizePromptText,
5
+ validateTechniqueOutput,
6
+ } from '../src/lib/output-validation.js';
7
+
8
+ type BenchResult = {
9
+ label: string;
10
+ iterations: number;
11
+ meanMs: number;
12
+ p50Ms: number;
13
+ p95Ms: number;
14
+ minMs: number;
15
+ maxMs: number;
16
+ heapUsedMb: number;
17
+ };
18
+
19
+ const SAMPLE_NORMALIZE = [
20
+ '```text\nHello\n```',
21
+ 'Refined Prompt:\n```text\nHello\n```',
22
+ 'Optimized Prompt:\nHello',
23
+ 'Hello world',
24
+ ];
25
+
26
+ const STRUCTURED_OUTPUT = '## Title\n- Item\n';
27
+ const ROLE_OUTPUT = 'You are a helpful assistant.\nReturn a JSON array.';
28
+
29
+ const ITERATIONS = 20000;
30
+ const WARMUP = 2000;
31
+
32
+ function percentile(values: number[], p: number): number {
33
+ if (values.length === 0) return 0;
34
+ const index = Math.floor((values.length - 1) * p);
35
+ return values[index] ?? 0;
36
+ }
37
+
38
+ function round(value: number, digits = 3): number {
39
+ const factor = 10 ** digits;
40
+ return Math.round(value * factor) / factor;
41
+ }
42
+
43
+ function runBench(label: string, fn: () => void): BenchResult {
44
+ if (global.gc) global.gc();
45
+
46
+ for (let i = 0; i < WARMUP; i += 1) {
47
+ fn();
48
+ }
49
+
50
+ const times: number[] = new Array(ITERATIONS);
51
+ const startMem = process.memoryUsage().heapUsed;
52
+
53
+ for (let i = 0; i < ITERATIONS; i += 1) {
54
+ const start = performance.now();
55
+ fn();
56
+ times[i] = performance.now() - start;
57
+ }
58
+
59
+ if (global.gc) global.gc();
60
+ const endMem = process.memoryUsage().heapUsed;
61
+
62
+ const sorted = [...times].sort((a, b) => a - b);
63
+ const mean = times.reduce((sum, value) => sum + value, 0) / times.length;
64
+ const heapUsedMb = endMem / 1024 / 1024;
65
+
66
+ return {
67
+ label,
68
+ iterations: ITERATIONS,
69
+ meanMs: round(mean),
70
+ p50Ms: round(percentile(sorted, 0.5)),
71
+ p95Ms: round(percentile(sorted, 0.95)),
72
+ minMs: round(sorted[0] ?? 0),
73
+ maxMs: round(sorted[sorted.length - 1] ?? 0),
74
+ heapUsedMb: round(heapUsedMb, 2),
75
+ };
76
+ }
77
+
78
+ let normalizeIndex = 0;
79
+ function nextNormalizeInput(): string {
80
+ const value = SAMPLE_NORMALIZE[normalizeIndex % SAMPLE_NORMALIZE.length];
81
+ normalizeIndex += 1;
82
+ return value ?? '';
83
+ }
84
+
85
+ const results: BenchResult[] = [
86
+ runBench('normalizePromptText', () => {
87
+ normalizePromptText(nextNormalizeInput());
88
+ }),
89
+ runBench('validateTechniqueOutput:structured', () => {
90
+ validateTechniqueOutput(STRUCTURED_OUTPUT, 'structured', 'gpt');
91
+ }),
92
+ runBench('validateTechniqueOutput:roleBased', () => {
93
+ validateTechniqueOutput(ROLE_OUTPUT, 'roleBased', 'gpt');
94
+ }),
95
+ ];
96
+
97
+ console.log(
98
+ JSON.stringify(
99
+ {
100
+ node: process.version,
101
+ iterations: ITERATIONS,
102
+ warmup: WARMUP,
103
+ results,
104
+ },
105
+ null,
106
+ 2
107
+ )
108
+ );
@@ -0,0 +1,105 @@
1
+ import { performance } from 'node:perf_hooks';
2
+
3
+ import {
4
+ buildPatternCache,
5
+ detectTargetFormat,
6
+ resolveFormat,
7
+ } from '../src/lib/prompt-analysis.js';
8
+
9
+ type BenchResult = {
10
+ label: string;
11
+ iterations: number;
12
+ meanMs: number;
13
+ p50Ms: number;
14
+ p95Ms: number;
15
+ minMs: number;
16
+ maxMs: number;
17
+ heapUsedMb: number;
18
+ };
19
+
20
+ const PROMPTS = [
21
+ 'Summarize the following meeting notes and extract action items.\n\nNotes:\n- Discussed Q4 roadmap\n- Risks include vendor delay\n\nOutput: bullet list.',
22
+ '<system>You are a helpful assistant.</system>\n<task>Return a JSON object with keys a,b,c.</task>',
23
+ '## Goal\nAnalyze sales data.\n\n**Constraints**\n- Use only 2024 data\n- Return CSV\n',
24
+ '{"task":"classify","labels":["bug","feature"],"text":"App crashes on launch"}',
25
+ 'Please rewrite this prompt for clarity and include guardrails against injection attacks.',
26
+ ];
27
+
28
+ const ITERATIONS = 20000;
29
+ const WARMUP = 2000;
30
+
31
+ function percentile(values: number[], p: number): number {
32
+ if (values.length === 0) return 0;
33
+ const index = Math.floor((values.length - 1) * p);
34
+ return values[index] ?? 0;
35
+ }
36
+
37
+ function round(value: number, digits = 3): number {
38
+ const factor = 10 ** digits;
39
+ return Math.round(value * factor) / factor;
40
+ }
41
+
42
+ function selectPrompt(index: number): string {
43
+ return PROMPTS[index % PROMPTS.length] ?? '';
44
+ }
45
+
46
+ function runBench(label: string, fn: (prompt: string) => void): BenchResult {
47
+ if (global.gc) global.gc();
48
+
49
+ for (let i = 0; i < WARMUP; i += 1) {
50
+ fn(selectPrompt(i));
51
+ }
52
+
53
+ const times: number[] = new Array(ITERATIONS);
54
+ const startMem = process.memoryUsage().heapUsed;
55
+
56
+ for (let i = 0; i < ITERATIONS; i += 1) {
57
+ const prompt = selectPrompt(i);
58
+ const start = performance.now();
59
+ fn(prompt);
60
+ times[i] = performance.now() - start;
61
+ }
62
+
63
+ if (global.gc) global.gc();
64
+ const endMem = process.memoryUsage().heapUsed;
65
+
66
+ const sorted = [...times].sort((a, b) => a - b);
67
+ const mean = times.reduce((sum, value) => sum + value, 0) / times.length;
68
+ const heapUsedMb = endMem / 1024 / 1024;
69
+
70
+ return {
71
+ label,
72
+ iterations: ITERATIONS,
73
+ meanMs: round(mean),
74
+ p50Ms: round(percentile(sorted, 0.5)),
75
+ p95Ms: round(percentile(sorted, 0.95)),
76
+ minMs: round(sorted[0] ?? 0),
77
+ maxMs: round(sorted[sorted.length - 1] ?? 0),
78
+ heapUsedMb: round(heapUsedMb, 2),
79
+ };
80
+ }
81
+
82
+ const benches: BenchResult[] = [
83
+ runBench('buildPatternCache', (prompt) => {
84
+ void buildPatternCache(prompt);
85
+ }),
86
+ runBench('detectTargetFormat', (prompt) => {
87
+ void detectTargetFormat(prompt);
88
+ }),
89
+ runBench('resolveFormat:auto', (prompt) => {
90
+ void resolveFormat('auto', prompt);
91
+ }),
92
+ ];
93
+
94
+ console.log(
95
+ JSON.stringify(
96
+ {
97
+ node: process.version,
98
+ iterations: ITERATIONS,
99
+ warmup: WARMUP,
100
+ results: benches,
101
+ },
102
+ null,
103
+ 2
104
+ )
105
+ );
@@ -24,4 +24,3 @@ export declare const DEFAULT_MODELS: {
24
24
  readonly anthropic: "claude-3-5-sonnet-20241022";
25
25
  readonly google: "gemini-2.0-flash-exp";
26
26
  };
27
- //# sourceMappingURL=constants.d.ts.map
@@ -28,4 +28,3 @@ export const DEFAULT_MODELS = {
28
28
  anthropic: 'claude-3-5-sonnet-20241022',
29
29
  google: 'gemini-2.0-flash-exp',
30
30
  };
31
- //# sourceMappingURL=constants.js.map
@@ -16,4 +16,3 @@ export declare const config: {
16
16
  ANTHROPIC_API_KEY?: string | undefined;
17
17
  GOOGLE_API_KEY?: string | undefined;
18
18
  };
19
- //# sourceMappingURL=env.d.ts.map
@@ -41,4 +41,3 @@ const envSchema = z.object({
41
41
  RETRY_TOTAL_TIMEOUT_MS: numberString(180000, 10000),
42
42
  });
43
43
  export const config = envSchema.parse(process.env);
44
- //# sourceMappingURL=env.js.map
@@ -1,2 +1 @@
1
1
  export declare const SERVER_INSTRUCTIONS = "# PromptTuner MCP\n\nA lean prompt optimization toolkit for refining, analyzing, and validating prompts.\n\n## Quick Start\n\n| Goal | Tool | When to Use |\n|------|------|-------------|\n| Quick fix | `refine_prompt` | Fix typos and clarity issues |\n| Deep optimization | `optimize_prompt` | Apply multiple techniques |\n| Quality check | `analyze_prompt` | Get scores and suggestions |\n| Safety check | `validate_prompt` | Find issues and estimate tokens |\n\n## Tools\n\n### refine_prompt\nImproves a prompt using a single optimization technique.\n\n**Techniques:**\n- `basic` (default) - Fix grammar, spelling, and clarity\n- `chainOfThought` - Add step-by-step reasoning guidance\n- `fewShot` - Add input/output examples\n- `roleBased` - Add expert persona/role context\n- `structured` - Add XML (Claude) or Markdown (GPT) structure\n- `comprehensive` - Apply all techniques intelligently\n\n**Example:**\n```json\n{ \"prompt\": \"help me code\", \"technique\": \"roleBased\", \"targetFormat\": \"claude\" }\n```\n\n### analyze_prompt\nScores your prompt (0-100) across clarity, specificity, completeness, structure, and effectiveness.\n\n### optimize_prompt\nChains multiple techniques for maximum improvement and returns before/after scores plus improvements.\n\n**Example:**\n```json\n{ \"prompt\": \"write code\", \"techniques\": [\"basic\", \"roleBased\", \"structured\"] }\n```\n\n### validate_prompt\nChecks for prompt issues, estimates token usage, and optionally detects injection risks.\n\n## Target Formats\n\n| Format | Best For | Structure |\n|--------|----------|-----------|\n| `claude` | Anthropic Claude | XML tags: `<context>`, `<task>`, `<requirements>` |\n| `gpt` | OpenAI GPT | Markdown: `## Context`, `## Task`, `**bold**` |\n| `json` | Structured output | JSON schema specification |\n| `auto` | Auto-detect | Uses prompt heuristics to pick format |\n\n## Technique Selection Guide\n\n| Task Type | Recommended Techniques |\n|-----------|----------------------|\n| Simple query | `basic` only |\n| Code task | `roleBased` + `structured` |\n| Complex analysis | `roleBased` + `chainOfThought` |\n| Data extraction | `structured` + `fewShot` |\n| Creative writing | `roleBased` + `fewShot` |\n| Maximum quality | `comprehensive` |\n\n## Workflow Prompts\n- `quick-optimize` - Single-step refinement\n- `deep-optimize` - Comprehensive optimization\n- `analyze` - Quality analysis\n\n## Modern Best Practices (2024-2025)\n\n1. **Be Specific** - Replace vague words with concrete terms\n2. **Add Role Context** - Use specific expert personas\n3. **Use Structure** - XML for Claude, Markdown for GPT (never mix)\n4. **Show Examples** - 2-3 diverse examples for pattern tasks\n5. **Add Constraints** - Clear ALWAYS/NEVER rules\n6. **Specify Output** - Define the expected format explicitly\n7. **Enable Reasoning** - Add task-specific reasoning triggers when needed\n8. **Place Key Instructions Twice** - Start and end for long prompts\n\n## Prompt Architecture (Recommended Order)\n```\n1. Role/Identity (if applicable)\n2. Context/Background\n3. Task/Objective\n4. Instructions/Steps\n5. Requirements/Constraints (ALWAYS/NEVER)\n6. Output Format\n7. Examples (if helpful)\n8. Final Reminder (reiterate critical instruction)\n```";
2
- //# sourceMappingURL=instructions.d.ts.map
@@ -90,4 +90,3 @@ Checks for prompt issues, estimates token usage, and optionally detects injectio
90
90
  7. Examples (if helpful)
91
91
  8. Final Reminder (reiterate critical instruction)
92
92
  \`\`\``;
93
- //# sourceMappingURL=instructions.js.map
@@ -17,4 +17,3 @@ export declare const PATTERNS: {
17
17
  readonly qualityIndicators: RegExp;
18
18
  readonly antiPatterns: RegExp;
19
19
  };
20
- //# sourceMappingURL=patterns.d.ts.map
@@ -17,4 +17,3 @@ export const PATTERNS = {
17
17
  qualityIndicators: /\b(specific|detailed|comprehensive|thorough|clear|concise|precise|accurate)\b/i,
18
18
  antiPatterns: /\b(do whatever|anything|everything|all of it|any way you want)\b/i,
19
19
  };
20
- //# sourceMappingURL=patterns.js.map
@@ -64,6 +64,10 @@ export interface PatternCache {
64
64
  hasBoldOrHeaders: boolean;
65
65
  hasAngleBrackets: boolean;
66
66
  hasJsonChars: boolean;
67
+ hasRole: boolean;
68
+ hasExamples: boolean;
69
+ hasStepByStep: boolean;
70
+ isVague: boolean;
67
71
  }
68
72
  export interface FormatScoringConfig {
69
73
  positive: {
@@ -171,4 +175,3 @@ export interface ValidationResponse {
171
175
  issues: ValidationIssue[];
172
176
  }
173
177
  export {};
174
- //# sourceMappingURL=types.d.ts.map
@@ -19,4 +19,3 @@ export const ErrorCode = {
19
19
  E_LLM_AUTH_FAILED: 'E_LLM_AUTH_FAILED',
20
20
  E_TIMEOUT: 'E_TIMEOUT',
21
21
  };
22
- //# sourceMappingURL=types.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env node
2
2
  export {};
3
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -92,6 +92,12 @@ for (const event of EXIT_EVENTS) {
92
92
  void beginShutdown({ event });
93
93
  });
94
94
  }
95
+ process.stdin.once('end', () => {
96
+ void beginShutdown({ event: 'stdin_end' });
97
+ });
98
+ process.stdin.once('close', () => {
99
+ void beginShutdown({ event: 'stdin_close' });
100
+ });
95
101
  async function main() {
96
102
  await validateApiKeys();
97
103
  server = createServer();
@@ -100,4 +106,3 @@ async function main() {
100
106
  main().catch((error) => {
101
107
  void beginShutdown({ err: error });
102
108
  });
103
- //# 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":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEzE,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,OAAO,GAAqB;IAChC,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AACF,MAAM,YAAY,GAAG,CAAC,mBAAmB,EAAE,oBAAoB,CAAU,CAAC;AAC1E,MAAM,WAAW,GAAG,CAAC,YAAY,CAAU,CAAC;AAQ5C,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,IAAI,MAAM,GAA2C,IAAI,CAAC;AAE1D,SAAS,iBAAiB,CAAC,MAAsB;IAC/C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,MAAM,CAAC,MAAM,WAAW,CAAC,CAAC;QAC5E,OAAO;IACT,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,EAAE,uBAAuB,CAAC,CAAC;QAC3D,OAAO;IACT,CAAC;IACD,MAAM,CAAC,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KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;IAC/B,KAAK,aAAa,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,IAAI;IACjB,MAAM,eAAe,EAAE,CAAC;IACxB,MAAM,GAAG,YAAY,EAAE,CAAC;IACxB,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,KAAK,aAAa,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC"}
@@ -1,2 +1 @@
1
1
  export declare function buildAbortSignal(timeoutMs: number, signal?: AbortSignal): AbortSignal;
2
- //# sourceMappingURL=abort-signals.d.ts.map
@@ -2,4 +2,3 @@ export function buildAbortSignal(timeoutMs, signal) {
2
2
  const timeoutSignal = AbortSignal.timeout(timeoutMs);
3
3
  return signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
4
4
  }
5
- //# sourceMappingURL=abort-signals.js.map
@@ -13,4 +13,3 @@ export declare class McpError extends Error {
13
13
  export declare function createSuccessResponse<T extends Record<string, unknown>>(text: string, structured: T, extraContent?: ContentBlock[]): SuccessResponse<T>;
14
14
  export declare function createErrorResponse(error: unknown, fallbackCode?: ErrorCodeType, context?: string): ErrorResponse;
15
15
  export { ErrorCode };
16
- //# sourceMappingURL=errors.d.ts.map
@@ -138,4 +138,3 @@ export { ErrorCode };
138
138
  function isZodError(error) {
139
139
  return typeof error === 'object' && error !== null && 'issues' in error;
140
140
  }
141
- //# sourceMappingURL=errors.js.map
@@ -4,4 +4,3 @@ export declare function getProviderInfo(): Promise<{
4
4
  provider: LLMProvider;
5
5
  model: string;
6
6
  }>;
7
- //# sourceMappingURL=llm-client.d.ts.map
@@ -54,4 +54,3 @@ export async function getProviderInfo() {
54
54
  const client = await getLLMClient();
55
55
  return { provider: client.getProvider(), model: client.getModel() };
56
56
  }
57
- //# sourceMappingURL=llm-client.js.map
@@ -0,0 +1 @@
1
+ export declare function extractFirstJsonFragment(text: string): string | null;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../src/lib/llm-json/scan.ts"],"names":[],"mappings":"AAgHA,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUpE"}