verifiable-thinking-mcp 0.4.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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +339 -0
  3. package/package.json +75 -0
  4. package/src/index.ts +38 -0
  5. package/src/lib/cache.ts +246 -0
  6. package/src/lib/compression.ts +804 -0
  7. package/src/lib/compute/cache.ts +86 -0
  8. package/src/lib/compute/classifier.ts +555 -0
  9. package/src/lib/compute/confidence.ts +79 -0
  10. package/src/lib/compute/context.ts +154 -0
  11. package/src/lib/compute/extract.ts +200 -0
  12. package/src/lib/compute/filter.ts +224 -0
  13. package/src/lib/compute/index.ts +171 -0
  14. package/src/lib/compute/math.ts +247 -0
  15. package/src/lib/compute/patterns.ts +564 -0
  16. package/src/lib/compute/registry.ts +145 -0
  17. package/src/lib/compute/solvers/arithmetic.ts +65 -0
  18. package/src/lib/compute/solvers/calculus.ts +249 -0
  19. package/src/lib/compute/solvers/derivation-core.ts +371 -0
  20. package/src/lib/compute/solvers/derivation-latex.ts +160 -0
  21. package/src/lib/compute/solvers/derivation-mistakes.ts +1046 -0
  22. package/src/lib/compute/solvers/derivation-simplify.ts +451 -0
  23. package/src/lib/compute/solvers/derivation-transform.ts +620 -0
  24. package/src/lib/compute/solvers/derivation.ts +67 -0
  25. package/src/lib/compute/solvers/facts.ts +120 -0
  26. package/src/lib/compute/solvers/formula.ts +728 -0
  27. package/src/lib/compute/solvers/index.ts +36 -0
  28. package/src/lib/compute/solvers/logic.ts +422 -0
  29. package/src/lib/compute/solvers/probability.ts +307 -0
  30. package/src/lib/compute/solvers/statistics.ts +262 -0
  31. package/src/lib/compute/solvers/word-problems.ts +408 -0
  32. package/src/lib/compute/types.ts +107 -0
  33. package/src/lib/concepts.ts +111 -0
  34. package/src/lib/domain.ts +731 -0
  35. package/src/lib/extraction.ts +912 -0
  36. package/src/lib/index.ts +122 -0
  37. package/src/lib/judge.ts +260 -0
  38. package/src/lib/math/ast.ts +842 -0
  39. package/src/lib/math/index.ts +8 -0
  40. package/src/lib/math/operators.ts +171 -0
  41. package/src/lib/math/tokenizer.ts +477 -0
  42. package/src/lib/patterns.ts +200 -0
  43. package/src/lib/session.ts +825 -0
  44. package/src/lib/think/challenge.ts +323 -0
  45. package/src/lib/think/complexity.ts +504 -0
  46. package/src/lib/think/confidence-drift.ts +507 -0
  47. package/src/lib/think/consistency.ts +347 -0
  48. package/src/lib/think/guidance.ts +188 -0
  49. package/src/lib/think/helpers.ts +568 -0
  50. package/src/lib/think/hypothesis.ts +216 -0
  51. package/src/lib/think/index.ts +127 -0
  52. package/src/lib/think/prompts.ts +262 -0
  53. package/src/lib/think/route.ts +358 -0
  54. package/src/lib/think/schema.ts +98 -0
  55. package/src/lib/think/scratchpad-schema.ts +662 -0
  56. package/src/lib/think/spot-check.ts +961 -0
  57. package/src/lib/think/types.ts +93 -0
  58. package/src/lib/think/verification.ts +260 -0
  59. package/src/lib/tokens.ts +177 -0
  60. package/src/lib/verification.ts +620 -0
  61. package/src/prompts/index.ts +10 -0
  62. package/src/prompts/templates.ts +336 -0
  63. package/src/resources/index.ts +8 -0
  64. package/src/resources/sessions.ts +196 -0
  65. package/src/tools/compress.ts +138 -0
  66. package/src/tools/index.ts +5 -0
  67. package/src/tools/scratchpad.ts +2659 -0
  68. package/src/tools/sessions.ts +144 -0
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Pre-compiled Regex Patterns for LLM Output Processing
3
+ *
4
+ * Centralized patterns for:
5
+ * - Thinking/reasoning tag removal
6
+ * - Markdown stripping
7
+ * - LaTeX extraction
8
+ * - Model-specific token cleanup
9
+ *
10
+ * Module-level constants avoid recompilation on every call.
11
+ * All patterns are exported for testing and reuse.
12
+ */
13
+
14
+ // =============================================================================
15
+ // THINKING/REASONING TAGS
16
+ // =============================================================================
17
+
18
+ /** Remove <think>...</think> blocks */
19
+ export const RE_THINK = /<think>[\s\S]*?<\/think>/gi;
20
+
21
+ /** Remove <thinking>...</thinking> blocks */
22
+ export const RE_THINKING = /<thinking>[\s\S]*?<\/thinking>/gi;
23
+
24
+ /** Remove <reasoning>...</reasoning> blocks */
25
+ export const RE_REASONING = /<reasoning>[\s\S]*?<\/reasoning>/gi;
26
+
27
+ /** Remove <antithink>...</antithink> blocks (Anthropic) */
28
+ export const RE_ANTITHINK = /<antithink>[\s\S]*?<\/antithink>/gi;
29
+
30
+ /** Remove <thought>...</thought> blocks */
31
+ export const RE_THOUGHT = /<thought>[\s\S]*?<\/thought>/gi;
32
+
33
+ /** Remove <thoughts>...</thoughts> blocks */
34
+ export const RE_THOUGHTS = /<thoughts>[\s\S]*?<\/thoughts>/gi;
35
+
36
+ /** Remove <reflection>...</reflection> blocks */
37
+ export const RE_REFLECTION = /<reflection>[\s\S]*?<\/reflection>/gi;
38
+
39
+ /** Remove <internal_monologue>...</internal_monologue> blocks */
40
+ export const RE_INTERNAL_MONOLOGUE = /<internal_monologue>[\s\S]*?<\/internal_monologue>/gi;
41
+
42
+ // =============================================================================
43
+ // TOOL/ARTIFACT CONTAINERS
44
+ // =============================================================================
45
+
46
+ /** Remove <tool_call>...</tool_call> blocks */
47
+ export const RE_TOOL_CALL = /<tool_call>[\s\S]*?<\/tool_call>/gi;
48
+
49
+ /** Remove <tool_result>...</tool_result> blocks */
50
+ export const RE_TOOL_RESULT = /<tool_result>[\s\S]*?<\/tool_result>/gi;
51
+
52
+ /** Remove <ARTIFACTS>...</ARTIFACTS> blocks */
53
+ export const RE_ARTIFACTS = /<ARTIFACTS>[\s\S]*?<\/ARTIFACTS>/gi;
54
+
55
+ /** Remove <document_content>...</document_content> blocks */
56
+ export const RE_DOCUMENT_CONTENT = /<document_content>[\s\S]*?<\/document_content>/gi;
57
+
58
+ /** Remove <context>...</context> blocks */
59
+ export const RE_CONTEXT = /<context>[\s\S]*?<\/context>/gi;
60
+
61
+ // =============================================================================
62
+ // MODEL-SPECIFIC TOKENS
63
+ // =============================================================================
64
+
65
+ /** Remove <|begin_of_box|> tokens */
66
+ export const RE_BEGIN_BOX = /<\|begin_of_box\|>/gi;
67
+
68
+ /** Remove <|end_of_box|> tokens */
69
+ export const RE_END_BOX = /<\|end_of_box\|>/gi;
70
+
71
+ /** Remove <|im_start|>...<|im_end|> blocks (ChatML) */
72
+ export const RE_IM_BLOCK = /<\|im_start\|>[\s\S]*?<\|im_end\|>/gi;
73
+
74
+ /** Remove <|endoftext|> tokens */
75
+ export const RE_ENDOFTEXT = /<\|endoftext\|>/gi;
76
+
77
+ /** Remove <|pad|> tokens */
78
+ export const RE_PAD = /<\|pad\|>/gi;
79
+
80
+ // =============================================================================
81
+ // MARKDOWN
82
+ // =============================================================================
83
+
84
+ /** Remove code blocks ```...``` */
85
+ export const RE_CODE_BLOCK = /```[\s\S]*?```/g;
86
+
87
+ /** Extract bold text **...** */
88
+ export const RE_BOLD_ASTERISK = /\*\*([^*]+)\*\*/g;
89
+
90
+ /** Extract bold text __...__ */
91
+ export const RE_BOLD_UNDERSCORE = /__([^_]+)__/g;
92
+
93
+ /** Extract italic text *...* */
94
+ export const RE_ITALIC_ASTERISK = /\*([^*]+)\*/g;
95
+
96
+ /** Extract italic text _..._ */
97
+ export const RE_ITALIC_UNDERSCORE = /_([^_]+)_/g;
98
+
99
+ /** Extract inline code `...` */
100
+ export const RE_INLINE_CODE = /`([^`]+)`/g;
101
+
102
+ /** Remove heading markers # */
103
+ export const RE_HEADINGS = /^#{1,6}\s*/gm;
104
+
105
+ /** Extract strikethrough text ~~...~~ */
106
+ export const RE_STRIKETHROUGH = /~~([^~]+)~~/g;
107
+
108
+ /** Remove image syntax ![...](...) */
109
+ export const RE_IMAGES = /!\[[^\]]*\]\([^)]+\)/g;
110
+
111
+ /** Extract link text [...](...) */
112
+ export const RE_LINKS = /\[([^\]]+)\]\([^)]+\)/g;
113
+
114
+ /** Remove blockquote markers > */
115
+ export const RE_BLOCKQUOTE = /^>\s*/gm;
116
+
117
+ /** Remove horizontal rules --- or *** or ___ */
118
+ export const RE_HORIZONTAL_RULE = /^[-*_]{3,}\s*$/gm;
119
+
120
+ /** Remove unordered list markers - * + */
121
+ export const RE_UNORDERED_LIST = /^[\s]*[-*+]\s+/gm;
122
+
123
+ /** Remove ordered list markers 1. 2. etc */
124
+ export const RE_ORDERED_LIST = /^[\s]*\d+\.\s+/gm;
125
+
126
+ // =============================================================================
127
+ // LATEX
128
+ // =============================================================================
129
+
130
+ /** Extract content from $\boxed{...}$ */
131
+ export const RE_BOXED_DOLLAR = /\$\\boxed\{([^}]+)\}\$/g;
132
+
133
+ /** Extract content from \boxed{...} */
134
+ export const RE_BOXED = /\\boxed\{([^}]+)\}/g;
135
+
136
+ /** Extract content from inline math $...$ */
137
+ export const RE_INLINE_MATH = /\$([^$]+)\$/g;
138
+
139
+ // =============================================================================
140
+ // HTML ENTITIES
141
+ // =============================================================================
142
+
143
+ /** Replace &nbsp; with space */
144
+ export const RE_NBSP = /&nbsp;/gi;
145
+
146
+ /** Replace &amp; with & */
147
+ export const RE_AMP = /&amp;/gi;
148
+
149
+ /** Replace &lt; with < */
150
+ export const RE_LT = /&lt;/gi;
151
+
152
+ /** Replace &gt; with > */
153
+ export const RE_GT = /&gt;/gi;
154
+
155
+ /** Replace &quot; with " */
156
+ export const RE_QUOT = /&quot;/gi;
157
+
158
+ /** Replace &#39; with ' */
159
+ export const RE_APOS = /&#39;/gi;
160
+
161
+ /** Replace <br> with newline */
162
+ export const RE_BR = /<br\s*\/?>/gi;
163
+
164
+ /** Remove simple HTML tags <p>, <div>, <span>, <b>, <i>, <u>, <em>, <strong> */
165
+ export const RE_SIMPLE_TAGS = /<\/?(?:p|div|span|b|i|u|em|strong)>/gi;
166
+
167
+ // =============================================================================
168
+ // FAST-PATH TOKENS (Combined patterns for performance)
169
+ // =============================================================================
170
+
171
+ /** Model tokens commonly appearing with thinking tags (for fast strip) */
172
+ export const RE_MODEL_TOKENS_FAST = /<\|(?:endoftext|pad|begin_of_box|end_of_box)\|>/gi;
173
+
174
+ // =============================================================================
175
+ // WHITESPACE
176
+ // =============================================================================
177
+
178
+ /** Collapse 3+ newlines to 2 */
179
+ export const RE_MULTI_NEWLINE = /\n{3,}/g;
180
+
181
+ /** Remove trailing whitespace from lines */
182
+ export const RE_TRAILING_WHITESPACE = /[ \t]+$/gm;
183
+
184
+ /** Collapse multiple spaces to one */
185
+ export const RE_MULTI_SPACE = /[ \t]{2,}/g;
186
+
187
+ // =============================================================================
188
+ // ANSWER EXTRACTION
189
+ // =============================================================================
190
+
191
+ /** Word fractions: "one half", "two thirds", etc */
192
+ export const RE_WORD_FRACTION =
193
+ /\b(a|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)[-\s]?(half|halves|third|thirds|fourth|fourths|quarter|quarters|fifth|fifths|sixth|sixths|seventh|sevenths|eighth|eighths|ninth|ninths|tenth|tenths)\b/gi;
194
+
195
+ /** Word fraction at start of string */
196
+ export const RE_WORD_FRACTION_START =
197
+ /^(a|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)[-\s]?(half|halves|third|thirds|fourth|fourths|quarter|quarters|fifth|fifths|sixth|sixths|seventh|sevenths|eighth|eighths|ninth|ninths|tenth|tenths)\b/i;
198
+
199
+ /** Percentage pattern: 42%, -3.14% */
200
+ export const RE_PERCENTAGE = /(-?[\d,]+(?:\.\d+)?)\s*%/g;