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,144 @@
1
+ import { z } from "zod";
2
+ import { clearTracker } from "../lib/concepts.ts";
3
+ import { SessionManager } from "../lib/session.ts";
4
+ import { calculateTokenUsage, clearAllSessionTokens, clearSessionTokens } from "../lib/tokens.ts";
5
+
6
+ /**
7
+ * Session management tools for reasoning chains
8
+ */
9
+
10
+ export const listSessionsTool = {
11
+ name: "list_sessions",
12
+ description: "List all active reasoning sessions with their thought counts and branches",
13
+ parameters: z.object({}),
14
+ execute: async () => {
15
+ const args = {};
16
+ const sessions = SessionManager.list();
17
+
18
+ let result: string;
19
+ if (sessions.length === 0) {
20
+ result = "No active sessions.";
21
+ } else {
22
+ const lines = [
23
+ `**Active Sessions** (${sessions.length})`,
24
+ "",
25
+ "| Session | Thoughts | Branches | Age |",
26
+ "|---------|----------|----------|-----|",
27
+ ];
28
+
29
+ for (const s of sessions) {
30
+ const age = formatAge(s.age_ms);
31
+ lines.push(
32
+ `| ${s.id.slice(0, 20)}... | ${s.thought_count} | ${s.branches.join(", ")} | ${age} |`,
33
+ );
34
+ }
35
+ result = lines.join("\n");
36
+ }
37
+
38
+ const tokens = calculateTokenUsage(args, result);
39
+ return `${result}\n\n---\n_tokens: ${tokens.input_tokens} in, ${tokens.output_tokens} out, ${tokens.total_tokens} total_`;
40
+ },
41
+ };
42
+
43
+ export const getSessionTool = {
44
+ name: "get_session",
45
+ description: "Get reasoning chain for a session in full, summary, or compressed format",
46
+ parameters: z.object({
47
+ session_id: z.string().describe("Session ID to retrieve"),
48
+ format: z
49
+ .enum(["full", "summary", "compressed"])
50
+ .default("summary")
51
+ .describe(
52
+ "Output format: full (all thoughts), summary (overview), compressed (key thoughts only)",
53
+ ),
54
+ branch_id: z.string().optional().describe("Filter by branch ID"),
55
+ }),
56
+ execute: async (args: { session_id: string; format?: string; branch_id?: string }) => {
57
+ const session = SessionManager.get(args.session_id);
58
+
59
+ let result: string;
60
+ if (!session) {
61
+ result = `Session not found: ${args.session_id}`;
62
+ } else {
63
+ const format = args.format || "summary";
64
+
65
+ if (format === "compressed") {
66
+ result = SessionManager.getCompressed(args.session_id) || "No thoughts to compress.";
67
+ } else if (format === "summary") {
68
+ result = SessionManager.getSummary(args.session_id) || "No summary available.";
69
+ } else {
70
+ // Full format
71
+ const thoughts = args.branch_id
72
+ ? SessionManager.getThoughts(args.session_id, args.branch_id)
73
+ : SessionManager.getThoughts(args.session_id);
74
+
75
+ if (thoughts.length === 0) {
76
+ result = "No thoughts in session.";
77
+ } else {
78
+ const lines = [
79
+ `**Session**: ${args.session_id}`,
80
+ `**Branches**: ${Array.from(session.branches).join(", ")}`,
81
+ `**Thoughts**: ${thoughts.length}`,
82
+ "",
83
+ ];
84
+
85
+ for (const t of thoughts) {
86
+ const v = t.verification;
87
+ const status = v ? (v.passed ? "✓" : "✗") : "○";
88
+ const confidence = v ? ` (${Math.round(v.confidence * 100)}%)` : "";
89
+
90
+ lines.push(`### Step ${t.step_number} [${t.branch_id}] ${status}${confidence}`);
91
+ lines.push(t.thought);
92
+
93
+ if (t.concepts && t.concepts.length > 0) {
94
+ lines.push(`*Concepts: ${t.concepts.join(", ")}*`);
95
+ }
96
+ lines.push("");
97
+ }
98
+ result = lines.join("\n");
99
+ }
100
+ }
101
+ }
102
+
103
+ const tokens = calculateTokenUsage(args, result);
104
+ return `${result}\n\n---\n_tokens: ${tokens.input_tokens} in, ${tokens.output_tokens} out, ${tokens.total_tokens} total_`;
105
+ },
106
+ };
107
+
108
+ export const clearSessionTool = {
109
+ name: "clear_session",
110
+ description: "Clear a specific session or all sessions to free memory",
111
+ parameters: z.object({
112
+ session_id: z.string().optional().describe("Session ID to clear (omit for all)"),
113
+ all: z.boolean().default(false).describe("Clear all sessions"),
114
+ }),
115
+ execute: async (args: { session_id?: string; all?: boolean }) => {
116
+ let result: string;
117
+
118
+ if (args.all) {
119
+ const count = SessionManager.clearAll();
120
+ clearAllSessionTokens();
121
+ result = `Cleared ${count} session(s).`;
122
+ } else if (!args.session_id) {
123
+ result = "Provide session_id or set all=true";
124
+ } else {
125
+ // Also clear concept tracker and token tracking for this session
126
+ clearTracker(args.session_id);
127
+ clearSessionTokens(args.session_id);
128
+
129
+ const cleared = SessionManager.clear(args.session_id);
130
+ result = cleared
131
+ ? `Cleared session: ${args.session_id}`
132
+ : `Session not found: ${args.session_id}`;
133
+ }
134
+
135
+ const tokens = calculateTokenUsage(args, result);
136
+ return `${result}\n\n---\n_tokens: ${tokens.input_tokens} in, ${tokens.output_tokens} out, ${tokens.total_tokens} total_`;
137
+ },
138
+ };
139
+
140
+ function formatAge(ms: number): string {
141
+ if (ms < 60_000) return `${Math.round(ms / 1000)}s`;
142
+ if (ms < 3_600_000) return `${Math.round(ms / 60_000)}m`;
143
+ return `${Math.round(ms / 3_600_000)}h`;
144
+ }