@weave_protocol/domere 1.0.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 (104) hide show
  1. package/PLANNING.md +231 -0
  2. package/README.md +50 -0
  3. package/dist/anchoring/ethereum.d.ts +135 -0
  4. package/dist/anchoring/ethereum.d.ts.map +1 -0
  5. package/dist/anchoring/ethereum.js +474 -0
  6. package/dist/anchoring/ethereum.js.map +1 -0
  7. package/dist/anchoring/index.d.ts +93 -0
  8. package/dist/anchoring/index.d.ts.map +1 -0
  9. package/dist/anchoring/index.js +184 -0
  10. package/dist/anchoring/index.js.map +1 -0
  11. package/dist/anchoring/merkle.d.ts +91 -0
  12. package/dist/anchoring/merkle.d.ts.map +1 -0
  13. package/dist/anchoring/merkle.js +203 -0
  14. package/dist/anchoring/merkle.js.map +1 -0
  15. package/dist/anchoring/solana.d.ts +85 -0
  16. package/dist/anchoring/solana.d.ts.map +1 -0
  17. package/dist/anchoring/solana.js +301 -0
  18. package/dist/anchoring/solana.js.map +1 -0
  19. package/dist/constants.d.ts +130 -0
  20. package/dist/constants.d.ts.map +1 -0
  21. package/dist/constants.js +536 -0
  22. package/dist/constants.js.map +1 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +37 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/language/code-analyzer.d.ts +80 -0
  28. package/dist/language/code-analyzer.d.ts.map +1 -0
  29. package/dist/language/code-analyzer.js +489 -0
  30. package/dist/language/code-analyzer.js.map +1 -0
  31. package/dist/language/detector.d.ts +53 -0
  32. package/dist/language/detector.d.ts.map +1 -0
  33. package/dist/language/detector.js +248 -0
  34. package/dist/language/detector.js.map +1 -0
  35. package/dist/language/index.d.ts +61 -0
  36. package/dist/language/index.d.ts.map +1 -0
  37. package/dist/language/index.js +109 -0
  38. package/dist/language/index.js.map +1 -0
  39. package/dist/language/nl-analyzer.d.ts +59 -0
  40. package/dist/language/nl-analyzer.d.ts.map +1 -0
  41. package/dist/language/nl-analyzer.js +350 -0
  42. package/dist/language/nl-analyzer.js.map +1 -0
  43. package/dist/language/semantic.d.ts +48 -0
  44. package/dist/language/semantic.d.ts.map +1 -0
  45. package/dist/language/semantic.js +329 -0
  46. package/dist/language/semantic.js.map +1 -0
  47. package/dist/storage/index.d.ts +6 -0
  48. package/dist/storage/index.d.ts.map +1 -0
  49. package/dist/storage/index.js +6 -0
  50. package/dist/storage/index.js.map +1 -0
  51. package/dist/storage/memory.d.ts +48 -0
  52. package/dist/storage/memory.d.ts.map +1 -0
  53. package/dist/storage/memory.js +211 -0
  54. package/dist/storage/memory.js.map +1 -0
  55. package/dist/thread/drift.d.ts +43 -0
  56. package/dist/thread/drift.d.ts.map +1 -0
  57. package/dist/thread/drift.js +248 -0
  58. package/dist/thread/drift.js.map +1 -0
  59. package/dist/thread/index.d.ts +9 -0
  60. package/dist/thread/index.d.ts.map +1 -0
  61. package/dist/thread/index.js +9 -0
  62. package/dist/thread/index.js.map +1 -0
  63. package/dist/thread/intent.d.ts +68 -0
  64. package/dist/thread/intent.d.ts.map +1 -0
  65. package/dist/thread/intent.js +333 -0
  66. package/dist/thread/intent.js.map +1 -0
  67. package/dist/thread/manager.d.ts +85 -0
  68. package/dist/thread/manager.d.ts.map +1 -0
  69. package/dist/thread/manager.js +305 -0
  70. package/dist/thread/manager.js.map +1 -0
  71. package/dist/thread/weave.d.ts +61 -0
  72. package/dist/thread/weave.d.ts.map +1 -0
  73. package/dist/thread/weave.js +158 -0
  74. package/dist/thread/weave.js.map +1 -0
  75. package/dist/tools/index.d.ts +18 -0
  76. package/dist/tools/index.d.ts.map +1 -0
  77. package/dist/tools/index.js +102 -0
  78. package/dist/tools/index.js.map +1 -0
  79. package/dist/types.d.ts +466 -0
  80. package/dist/types.d.ts.map +1 -0
  81. package/dist/types.js +48 -0
  82. package/dist/types.js.map +1 -0
  83. package/package.json +24 -0
  84. package/src/anchoring/ethereum.ts +568 -0
  85. package/src/anchoring/index.ts +236 -0
  86. package/src/anchoring/merkle.ts +256 -0
  87. package/src/anchoring/solana.ts +370 -0
  88. package/src/constants.ts +566 -0
  89. package/src/index.ts +43 -0
  90. package/src/language/code-analyzer.ts +564 -0
  91. package/src/language/detector.ts +297 -0
  92. package/src/language/index.ts +129 -0
  93. package/src/language/nl-analyzer.ts +411 -0
  94. package/src/language/semantic.ts +385 -0
  95. package/src/storage/index.ts +6 -0
  96. package/src/storage/memory.ts +271 -0
  97. package/src/thread/drift.ts +319 -0
  98. package/src/thread/index.ts +9 -0
  99. package/src/thread/intent.ts +409 -0
  100. package/src/thread/manager.ts +414 -0
  101. package/src/thread/weave.ts +205 -0
  102. package/src/tools/index.ts +107 -0
  103. package/src/types.ts +736 -0
  104. package/tsconfig.json +19 -0
@@ -0,0 +1,566 @@
1
+ /**
2
+ * Dōmere - The Judge Protocol
3
+ * Constants and Configuration
4
+ */
5
+
6
+ import type { DomereConfig, LanguageType } from './types.js';
7
+
8
+ // ============================================================================
9
+ // Server Info
10
+ // ============================================================================
11
+
12
+ export const SERVER_INFO = {
13
+ name: 'domere-mcp',
14
+ version: '0.1.0',
15
+ description: 'The Judge Protocol - Thread verification and blockchain anchoring for AI agents',
16
+ };
17
+
18
+ // ============================================================================
19
+ // Default Configuration
20
+ // ============================================================================
21
+
22
+ export const DEFAULT_CONFIG: DomereConfig = {
23
+ port: 3002,
24
+ host: '127.0.0.1',
25
+ transport: 'stdio',
26
+ log_level: 'info',
27
+ storage: 'memory',
28
+
29
+ language: {
30
+ enable_semantic: true,
31
+ enable_code_analysis: true,
32
+ enable_nl_analysis: true,
33
+ },
34
+
35
+ drift: {
36
+ max_acceptable_drift: 0.3,
37
+ warn_threshold: 0.2,
38
+ },
39
+
40
+ anchoring: {
41
+ solana_rpc: 'https://api.mainnet-beta.solana.com',
42
+ solana_program_id: 'WeaveXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
43
+ ethereum_rpc: 'https://mainnet.infura.io/v3/YOUR_KEY',
44
+ ethereum_contract: '0x0000000000000000000000000000000000000000',
45
+ protocol_fee_bps: 500, // 5%
46
+ },
47
+
48
+ integration: {},
49
+ };
50
+
51
+ // ============================================================================
52
+ // Language Detection Patterns
53
+ // ============================================================================
54
+
55
+ export const LANGUAGE_PATTERNS: Record<LanguageType, { patterns: RegExp[]; keywords: string[] }> = {
56
+ // Programming Languages
57
+ javascript: {
58
+ patterns: [
59
+ /\bconst\s+\w+\s*=/,
60
+ /\blet\s+\w+\s*=/,
61
+ /\bfunction\s+\w+\s*\(/,
62
+ /=>\s*{/,
63
+ /\bclass\s+\w+/,
64
+ /\bimport\s+.*\s+from\s+['"]/,
65
+ /\bexport\s+(default\s+)?/,
66
+ /\bconsole\.(log|error|warn)/,
67
+ /\basync\s+function/,
68
+ /\bawait\s+/,
69
+ ],
70
+ keywords: ['const', 'let', 'var', 'function', 'async', 'await', 'import', 'export', 'class', 'extends', 'constructor', 'this', 'new', 'return', 'if', 'else', 'for', 'while', 'try', 'catch', 'throw'],
71
+ },
72
+ typescript: {
73
+ patterns: [
74
+ /:\s*(string|number|boolean|any|void|never)\b/,
75
+ /\binterface\s+\w+/,
76
+ /\btype\s+\w+\s*=/,
77
+ /<\w+>/,
78
+ /\bas\s+\w+/,
79
+ /\bimplements\s+/,
80
+ /\bprivate\s+/,
81
+ /\bpublic\s+/,
82
+ /\breadonly\s+/,
83
+ ],
84
+ keywords: ['interface', 'type', 'enum', 'implements', 'private', 'public', 'protected', 'readonly', 'abstract', 'namespace', 'declare', 'as', 'is', 'keyof', 'typeof', 'infer'],
85
+ },
86
+ python: {
87
+ patterns: [
88
+ /\bdef\s+\w+\s*\(/,
89
+ /\bclass\s+\w+.*:/,
90
+ /\bimport\s+\w+/,
91
+ /\bfrom\s+\w+\s+import/,
92
+ /\bif\s+.*:/,
93
+ /\bfor\s+\w+\s+in\s+/,
94
+ /\bwhile\s+.*:/,
95
+ /\btry\s*:/,
96
+ /\bexcept\s+/,
97
+ /\bwith\s+.*\s+as\s+/,
98
+ /\blambda\s+/,
99
+ /\bself\./,
100
+ /__\w+__/,
101
+ ],
102
+ keywords: ['def', 'class', 'import', 'from', 'if', 'elif', 'else', 'for', 'while', 'try', 'except', 'finally', 'with', 'as', 'return', 'yield', 'lambda', 'self', 'None', 'True', 'False', 'and', 'or', 'not', 'in', 'is', 'pass', 'break', 'continue', 'raise', 'assert', 'global', 'nonlocal', 'async', 'await'],
103
+ },
104
+ sql: {
105
+ patterns: [
106
+ /\bSELECT\s+/i,
107
+ /\bFROM\s+\w+/i,
108
+ /\bWHERE\s+/i,
109
+ /\bINSERT\s+INTO\s+/i,
110
+ /\bUPDATE\s+\w+\s+SET/i,
111
+ /\bDELETE\s+FROM/i,
112
+ /\bCREATE\s+TABLE/i,
113
+ /\bALTER\s+TABLE/i,
114
+ /\bDROP\s+TABLE/i,
115
+ /\bJOIN\s+/i,
116
+ /\bGROUP\s+BY/i,
117
+ /\bORDER\s+BY/i,
118
+ ],
119
+ keywords: ['SELECT', 'FROM', 'WHERE', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE', 'CREATE', 'ALTER', 'DROP', 'TABLE', 'INDEX', 'VIEW', 'JOIN', 'INNER', 'LEFT', 'RIGHT', 'OUTER', 'ON', 'AND', 'OR', 'NOT', 'NULL', 'IS', 'IN', 'BETWEEN', 'LIKE', 'GROUP', 'BY', 'HAVING', 'ORDER', 'ASC', 'DESC', 'LIMIT', 'OFFSET', 'UNION', 'DISTINCT', 'COUNT', 'SUM', 'AVG', 'MAX', 'MIN', 'AS', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END'],
120
+ },
121
+ json: {
122
+ patterns: [
123
+ /^\s*\{[\s\S]*\}\s*$/,
124
+ /^\s*\[[\s\S]*\]\s*$/,
125
+ /"[^"]+"\s*:\s*(".*?"|[\d.]+|true|false|null|\{|\[)/,
126
+ ],
127
+ keywords: [],
128
+ },
129
+ yaml: {
130
+ patterns: [
131
+ /^\w+:\s*$/m,
132
+ /^\s+-\s+\w+/m,
133
+ /^\s+\w+:\s+.+$/m,
134
+ /^---\s*$/m,
135
+ ],
136
+ keywords: [],
137
+ },
138
+ html: {
139
+ patterns: [
140
+ /<\/?[a-z][\w-]*[^>]*>/i,
141
+ /<!DOCTYPE\s+html>/i,
142
+ /<html[\s>]/i,
143
+ /<head[\s>]/i,
144
+ /<body[\s>]/i,
145
+ /<div[\s>]/i,
146
+ /<span[\s>]/i,
147
+ ],
148
+ keywords: [],
149
+ },
150
+ css: {
151
+ patterns: [
152
+ /[.#]?\w+\s*\{[^}]*\}/,
153
+ /@media\s+/,
154
+ /@import\s+/,
155
+ /:\s*(flex|grid|block|inline|none|auto|inherit)/,
156
+ /background(-color)?:/,
157
+ /font(-size|-family|-weight)?:/,
158
+ /margin(-top|-bottom|-left|-right)?:/,
159
+ /padding(-top|-bottom|-left|-right)?:/,
160
+ ],
161
+ keywords: ['display', 'position', 'flex', 'grid', 'background', 'color', 'font', 'margin', 'padding', 'border', 'width', 'height', 'top', 'bottom', 'left', 'right'],
162
+ },
163
+ bash: {
164
+ patterns: [
165
+ /^#!/,
166
+ /\$\w+/,
167
+ /\$\{[^}]+\}/,
168
+ /\becho\s+/,
169
+ /\bif\s+\[\s*/,
170
+ /\bfi\b/,
171
+ /\bfor\s+\w+\s+in\b/,
172
+ /\bdone\b/,
173
+ /\bfunction\s+\w+\s*\(\)/,
174
+ /\|\s*grep\b/,
175
+ /\|\s*awk\b/,
176
+ /\|\s*sed\b/,
177
+ ],
178
+ keywords: ['echo', 'if', 'then', 'else', 'elif', 'fi', 'for', 'while', 'do', 'done', 'case', 'esac', 'function', 'return', 'exit', 'export', 'source', 'alias', 'cd', 'pwd', 'ls', 'cat', 'grep', 'awk', 'sed', 'chmod', 'chown', 'mkdir', 'rm', 'cp', 'mv', 'sudo'],
179
+ },
180
+ markdown: {
181
+ patterns: [
182
+ /^#{1,6}\s+/m,
183
+ /\*\*[^*]+\*\*/,
184
+ /\*[^*]+\*/,
185
+ /\[[^\]]+\]\([^)]+\)/,
186
+ /```[\s\S]*?```/,
187
+ /^\s*[-*+]\s+/m,
188
+ /^\s*\d+\.\s+/m,
189
+ /^>\s+/m,
190
+ ],
191
+ keywords: [],
192
+ },
193
+
194
+ // Natural Languages (basic detection)
195
+ english: {
196
+ patterns: [
197
+ /\b(the|a|an|is|are|was|were|be|been|being)\b/i,
198
+ /\b(have|has|had|do|does|did|will|would|could|should|may|might|must)\b/i,
199
+ /\b(I|you|he|she|it|we|they|this|that|these|those)\b/i,
200
+ ],
201
+ keywords: ['the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could', 'should', 'can', 'may', 'might', 'must', 'shall'],
202
+ },
203
+ spanish: {
204
+ patterns: [
205
+ /\b(el|la|los|las|un|una|unos|unas)\b/i,
206
+ /\b(es|son|era|eran|fue|fueron)\b/i,
207
+ /\b(que|de|en|y|a|por|para|con)\b/i,
208
+ ],
209
+ keywords: ['el', 'la', 'los', 'las', 'un', 'una', 'es', 'son', 'que', 'de', 'en', 'y', 'a', 'por', 'para', 'con', 'no', 'se', 'su', 'al', 'lo', 'como', 'más', 'pero', 'sus', 'le', 'ya', 'o', 'este', 'sí', 'porque', 'muy', 'sin', 'sobre', 'también', 'me', 'hasta', 'hay', 'donde', 'quien', 'desde', 'todo', 'nos', 'durante', 'todos', 'uno', 'les', 'ni', 'contra', 'otros', 'ese', 'eso', 'ante'],
210
+ },
211
+ french: {
212
+ patterns: [
213
+ /\b(le|la|les|un|une|des)\b/i,
214
+ /\b(est|sont|était|étaient|être)\b/i,
215
+ /\b(que|de|en|et|à|pour|avec|dans)\b/i,
216
+ ],
217
+ keywords: ['le', 'la', 'les', 'un', 'une', 'des', 'est', 'sont', 'que', 'de', 'en', 'et', 'à', 'pour', 'avec', 'dans', 'ce', 'il', 'qui', 'ne', 'sur', 'se', 'pas', 'plus', 'par', 'je', 'son', 'que', 'ou', 'si', 'leur', 'on', 'mais', 'nous', 'comme', 'tout', 'elle', 'lui', 'même', 'ces', 'aux', 'aussi', 'bien', 'sans', 'peut', 'tous', 'fait', 'été', 'ont', 'être', 'cette'],
218
+ },
219
+ german: {
220
+ patterns: [
221
+ /\b(der|die|das|den|dem|des)\b/i,
222
+ /\b(ist|sind|war|waren|sein|gewesen)\b/i,
223
+ /\b(und|in|zu|mit|für|auf|an)\b/i,
224
+ ],
225
+ keywords: ['der', 'die', 'das', 'und', 'in', 'zu', 'den', 'ist', 'von', 'nicht', 'mit', 'es', 'sich', 'des', 'auch', 'auf', 'für', 'an', 'er', 'so', 'dem', 'hat', 'als', 'sie', 'im', 'bei', 'ein', 'oder', 'war', 'sind', 'nach', 'aus', 'am', 'wenn', 'werden', 'nur', 'noch', 'wie', 'über', 'ihr', 'zur', 'kann', 'aber', 'einer', 'um', 'diese', 'zum'],
226
+ },
227
+ chinese: {
228
+ patterns: [
229
+ /[\u4e00-\u9fff]/,
230
+ ],
231
+ keywords: [],
232
+ },
233
+ japanese: {
234
+ patterns: [
235
+ /[\u3040-\u309f]/, // Hiragana
236
+ /[\u30a0-\u30ff]/, // Katakana
237
+ /[\u4e00-\u9fff]/, // Kanji (shared with Chinese)
238
+ ],
239
+ keywords: [],
240
+ },
241
+
242
+ // Data formats
243
+ xml: {
244
+ patterns: [
245
+ /<\?xml\s+/,
246
+ /<[a-z][\w-]*[^>]*>[\s\S]*<\/[a-z][\w-]*>/i,
247
+ ],
248
+ keywords: [],
249
+ },
250
+ csv: {
251
+ patterns: [
252
+ /^[^,\n]+,[^,\n]+/m,
253
+ /^"[^"]*","[^"]*"/m,
254
+ ],
255
+ keywords: [],
256
+ },
257
+ toml: {
258
+ patterns: [
259
+ /^\[[\w.-]+\]\s*$/m,
260
+ /^\w+\s*=\s*".*"$/m,
261
+ /^\w+\s*=\s*\d+$/m,
262
+ ],
263
+ keywords: [],
264
+ },
265
+ ini: {
266
+ patterns: [
267
+ /^\[[\w\s]+\]\s*$/m,
268
+ /^\w+\s*=\s*.+$/m,
269
+ ],
270
+ keywords: [],
271
+ },
272
+
273
+ // Others
274
+ java: {
275
+ patterns: [
276
+ /\bpublic\s+class\s+/,
277
+ /\bprivate\s+\w+\s+\w+/,
278
+ /\bSystem\.out\.print/,
279
+ /\bimport\s+java\./,
280
+ ],
281
+ keywords: ['public', 'private', 'protected', 'class', 'interface', 'extends', 'implements', 'static', 'final', 'void', 'int', 'String', 'boolean', 'new', 'return', 'if', 'else', 'for', 'while', 'try', 'catch', 'throw', 'throws', 'import', 'package', 'this', 'super', 'null', 'true', 'false'],
282
+ },
283
+ csharp: {
284
+ patterns: [
285
+ /\bnamespace\s+/,
286
+ /\busing\s+System/,
287
+ /\bpublic\s+class\s+/,
288
+ /\bConsole\.Write/,
289
+ ],
290
+ keywords: ['namespace', 'using', 'class', 'interface', 'struct', 'enum', 'public', 'private', 'protected', 'internal', 'static', 'void', 'int', 'string', 'bool', 'var', 'new', 'return', 'if', 'else', 'for', 'foreach', 'while', 'try', 'catch', 'throw', 'async', 'await', 'this', 'base', 'null', 'true', 'false'],
291
+ },
292
+ go: {
293
+ patterns: [
294
+ /\bpackage\s+\w+/,
295
+ /\bfunc\s+\w+\s*\(/,
296
+ /\bimport\s+\(/,
297
+ /\bfmt\.Print/,
298
+ ],
299
+ keywords: ['package', 'import', 'func', 'var', 'const', 'type', 'struct', 'interface', 'map', 'chan', 'go', 'select', 'case', 'default', 'if', 'else', 'for', 'range', 'return', 'break', 'continue', 'defer', 'nil', 'true', 'false'],
300
+ },
301
+ rust: {
302
+ patterns: [
303
+ /\bfn\s+\w+\s*\(/,
304
+ /\blet\s+(mut\s+)?\w+/,
305
+ /\bimpl\s+/,
306
+ /\bpub\s+(fn|struct|enum)/,
307
+ /\buse\s+\w+::/,
308
+ ],
309
+ keywords: ['fn', 'let', 'mut', 'const', 'static', 'struct', 'enum', 'impl', 'trait', 'pub', 'use', 'mod', 'crate', 'self', 'super', 'where', 'if', 'else', 'match', 'loop', 'while', 'for', 'in', 'return', 'break', 'continue', 'move', 'ref', 'async', 'await', 'dyn', 'type', 'unsafe', 'extern'],
310
+ },
311
+ ruby: {
312
+ patterns: [
313
+ /\bdef\s+\w+/,
314
+ /\bclass\s+\w+/,
315
+ /\bmodule\s+\w+/,
316
+ /\bend\b/,
317
+ /\bputs\s+/,
318
+ /\brequire\s+['"]/,
319
+ ],
320
+ keywords: ['def', 'class', 'module', 'end', 'if', 'elsif', 'else', 'unless', 'case', 'when', 'while', 'until', 'for', 'do', 'begin', 'rescue', 'ensure', 'raise', 'return', 'yield', 'self', 'super', 'nil', 'true', 'false', 'and', 'or', 'not', 'require', 'include', 'extend', 'attr_accessor', 'attr_reader', 'attr_writer', 'puts', 'print'],
321
+ },
322
+ php: {
323
+ patterns: [
324
+ /<\?php/,
325
+ /\$\w+\s*=/,
326
+ /\bfunction\s+\w+\s*\(/,
327
+ /\becho\s+/,
328
+ /\bclass\s+\w+/,
329
+ ],
330
+ keywords: ['php', 'echo', 'print', 'function', 'class', 'interface', 'trait', 'extends', 'implements', 'public', 'private', 'protected', 'static', 'const', 'var', 'new', 'return', 'if', 'else', 'elseif', 'for', 'foreach', 'while', 'do', 'switch', 'case', 'break', 'continue', 'try', 'catch', 'throw', 'finally', 'use', 'namespace', 'require', 'include', 'null', 'true', 'false'],
331
+ },
332
+ swift: {
333
+ patterns: [
334
+ /\bfunc\s+\w+\s*\(/,
335
+ /\bvar\s+\w+\s*:/,
336
+ /\blet\s+\w+\s*[=:]/,
337
+ /\bclass\s+\w+/,
338
+ /\bstruct\s+\w+/,
339
+ /\bimport\s+\w+/,
340
+ ],
341
+ keywords: ['func', 'var', 'let', 'class', 'struct', 'enum', 'protocol', 'extension', 'import', 'public', 'private', 'internal', 'open', 'fileprivate', 'static', 'override', 'init', 'deinit', 'self', 'super', 'if', 'else', 'guard', 'switch', 'case', 'for', 'while', 'repeat', 'return', 'break', 'continue', 'throw', 'try', 'catch', 'nil', 'true', 'false', 'as', 'is', 'in', 'where'],
342
+ },
343
+ kotlin: {
344
+ patterns: [
345
+ /\bfun\s+\w+\s*\(/,
346
+ /\bval\s+\w+\s*[=:]/,
347
+ /\bvar\s+\w+\s*[=:]/,
348
+ /\bclass\s+\w+/,
349
+ /\bobject\s+\w+/,
350
+ /\bpackage\s+\w+/,
351
+ ],
352
+ keywords: ['fun', 'val', 'var', 'class', 'object', 'interface', 'enum', 'sealed', 'data', 'open', 'abstract', 'override', 'private', 'protected', 'public', 'internal', 'companion', 'init', 'constructor', 'this', 'super', 'if', 'else', 'when', 'for', 'while', 'do', 'return', 'break', 'continue', 'throw', 'try', 'catch', 'finally', 'null', 'true', 'false', 'is', 'as', 'in', 'package', 'import'],
353
+ },
354
+ scala: {
355
+ patterns: [
356
+ /\bdef\s+\w+\s*[(\[]/,
357
+ /\bval\s+\w+\s*[=:]/,
358
+ /\bvar\s+\w+\s*[=:]/,
359
+ /\bclass\s+\w+/,
360
+ /\bobject\s+\w+/,
361
+ /\btrait\s+\w+/,
362
+ ],
363
+ keywords: ['def', 'val', 'var', 'class', 'object', 'trait', 'extends', 'with', 'override', 'private', 'protected', 'public', 'abstract', 'final', 'sealed', 'implicit', 'lazy', 'case', 'match', 'if', 'else', 'for', 'while', 'do', 'return', 'yield', 'throw', 'try', 'catch', 'finally', 'null', 'true', 'false', 'this', 'super', 'new', 'type', 'import', 'package'],
364
+ },
365
+ r: {
366
+ patterns: [
367
+ /\b\w+\s*<-\s*/,
368
+ /\bfunction\s*\(/,
369
+ /\blibrary\s*\(/,
370
+ /\bdata\.frame\s*\(/,
371
+ ],
372
+ keywords: ['function', 'if', 'else', 'for', 'while', 'repeat', 'break', 'next', 'return', 'in', 'TRUE', 'FALSE', 'NULL', 'NA', 'Inf', 'NaN', 'library', 'require', 'source', 'data.frame', 'list', 'c', 'matrix', 'array', 'factor', 'print', 'cat', 'paste'],
373
+ },
374
+ powershell: {
375
+ patterns: [
376
+ /\$\w+\s*=/,
377
+ /\bfunction\s+\w+/,
378
+ /\bparam\s*\(/,
379
+ /\bWrite-Host\b/,
380
+ /\bGet-\w+/,
381
+ /\bSet-\w+/,
382
+ ],
383
+ keywords: ['function', 'param', 'begin', 'process', 'end', 'if', 'elseif', 'else', 'switch', 'foreach', 'for', 'while', 'do', 'until', 'break', 'continue', 'return', 'exit', 'throw', 'try', 'catch', 'finally', 'trap', 'filter', 'workflow'],
384
+ },
385
+ shell: {
386
+ patterns: [
387
+ /^#!/,
388
+ /\$\w+/,
389
+ ],
390
+ keywords: ['echo', 'if', 'then', 'else', 'fi', 'for', 'while', 'do', 'done', 'case', 'esac'],
391
+ },
392
+ regex: {
393
+ patterns: [
394
+ /^\/.*\/[gimsuvy]*$/,
395
+ /\[\^?[\w-]+\]/,
396
+ /\(\?[<:!=]/,
397
+ /[.+*?{}()|\\^$\[\]]/,
398
+ ],
399
+ keywords: [],
400
+ },
401
+ graphql: {
402
+ patterns: [
403
+ /\b(query|mutation|subscription)\s+\w*/,
404
+ /\btype\s+\w+\s*{/,
405
+ /\binput\s+\w+\s*{/,
406
+ /\bfragment\s+\w+\s+on\s+/,
407
+ ],
408
+ keywords: ['query', 'mutation', 'subscription', 'fragment', 'on', 'type', 'input', 'enum', 'interface', 'union', 'scalar', 'directive', 'schema', 'extend', 'implements'],
409
+ },
410
+ protobuf: {
411
+ patterns: [
412
+ /\bsyntax\s*=\s*"proto[23]"/,
413
+ /\bmessage\s+\w+\s*{/,
414
+ /\bservice\s+\w+\s*{/,
415
+ /\brpc\s+\w+\s*\(/,
416
+ ],
417
+ keywords: ['syntax', 'package', 'import', 'option', 'message', 'service', 'rpc', 'returns', 'enum', 'oneof', 'map', 'repeated', 'optional', 'required', 'reserved', 'extensions', 'extend'],
418
+ },
419
+
420
+ unknown: { patterns: [], keywords: [] },
421
+ mixed: { patterns: [], keywords: [] },
422
+ };
423
+
424
+ // ============================================================================
425
+ // Dangerous Code Patterns
426
+ // ============================================================================
427
+
428
+ export const DANGEROUS_CODE_PATTERNS = {
429
+ javascript: [
430
+ { pattern: /eval\s*\(/, description: 'eval() can execute arbitrary code', severity: 'critical' as const },
431
+ { pattern: /new\s+Function\s*\(/, description: 'Function constructor can execute arbitrary code', severity: 'critical' as const },
432
+ { pattern: /document\.write\s*\(/, description: 'document.write can inject content', severity: 'high' as const },
433
+ { pattern: /innerHTML\s*=/, description: 'innerHTML can inject HTML/scripts', severity: 'high' as const },
434
+ { pattern: /\.exec\s*\(/, description: 'exec() may execute shell commands', severity: 'critical' as const },
435
+ { pattern: /child_process/, description: 'child_process can spawn system processes', severity: 'critical' as const },
436
+ { pattern: /require\s*\(\s*['"]fs['"]/, description: 'File system access', severity: 'medium' as const },
437
+ { pattern: /\.readFileSync|\.writeFileSync/, description: 'Synchronous file operations', severity: 'medium' as const },
438
+ { pattern: /process\.env/, description: 'Environment variable access', severity: 'low' as const },
439
+ ],
440
+ python: [
441
+ { pattern: /eval\s*\(/, description: 'eval() can execute arbitrary code', severity: 'critical' as const },
442
+ { pattern: /exec\s*\(/, description: 'exec() can execute arbitrary code', severity: 'critical' as const },
443
+ { pattern: /os\.system\s*\(/, description: 'os.system() executes shell commands', severity: 'critical' as const },
444
+ { pattern: /subprocess\.(call|run|Popen)/, description: 'subprocess can execute system commands', severity: 'critical' as const },
445
+ { pattern: /pickle\.loads?/, description: 'pickle can execute arbitrary code during deserialization', severity: 'critical' as const },
446
+ { pattern: /__import__\s*\(/, description: '__import__() can import arbitrary modules', severity: 'high' as const },
447
+ { pattern: /open\s*\(.*,\s*['"]w/, description: 'File write operation', severity: 'medium' as const },
448
+ { pattern: /os\.environ/, description: 'Environment variable access', severity: 'low' as const },
449
+ ],
450
+ sql: [
451
+ { pattern: /;\s*(DROP|DELETE|TRUNCATE)\s/i, description: 'Destructive SQL operation', severity: 'critical' as const },
452
+ { pattern: /UNION\s+(ALL\s+)?SELECT/i, description: 'UNION injection pattern', severity: 'high' as const },
453
+ { pattern: /OR\s+['"]?1['"]?\s*=\s*['"]?1/i, description: 'SQL injection pattern', severity: 'high' as const },
454
+ { pattern: /--\s*$/, description: 'SQL comment (potential injection)', severity: 'medium' as const },
455
+ { pattern: /;\s*--/, description: 'Statement termination with comment', severity: 'high' as const },
456
+ { pattern: /EXEC(\s+|\()sp_/i, description: 'Stored procedure execution', severity: 'medium' as const },
457
+ { pattern: /xp_cmdshell/i, description: 'Command shell execution', severity: 'critical' as const },
458
+ { pattern: /INTO\s+OUTFILE/i, description: 'File write via SQL', severity: 'critical' as const },
459
+ { pattern: /LOAD_FILE\s*\(/i, description: 'File read via SQL', severity: 'high' as const },
460
+ ],
461
+ bash: [
462
+ { pattern: /rm\s+-rf?\s+\//, description: 'Recursive delete from root', severity: 'critical' as const },
463
+ { pattern: />\s*\/dev\/sd[a-z]/, description: 'Direct disk write', severity: 'critical' as const },
464
+ { pattern: /:\(\)\s*{\s*:\|:&\s*}/, description: 'Fork bomb pattern', severity: 'critical' as const },
465
+ { pattern: /curl.*\|\s*(ba)?sh/, description: 'Pipe curl to shell', severity: 'critical' as const },
466
+ { pattern: /wget.*\|\s*(ba)?sh/, description: 'Pipe wget to shell', severity: 'critical' as const },
467
+ { pattern: /chmod\s+777/, description: 'Overly permissive chmod', severity: 'high' as const },
468
+ { pattern: /sudo\s+/, description: 'Elevated privileges', severity: 'medium' as const },
469
+ { pattern: /\$\(.*\)/, description: 'Command substitution', severity: 'low' as const },
470
+ { pattern: /`.*`/, description: 'Backtick command substitution', severity: 'low' as const },
471
+ ],
472
+ };
473
+
474
+ // ============================================================================
475
+ // Prompt Injection Patterns
476
+ // ============================================================================
477
+
478
+ export const INJECTION_PATTERNS = [
479
+ // Direct instruction overrides
480
+ { pattern: /ignore\s+(all\s+)?(previous|prior|above)\s+(instructions?|prompts?|rules?)/i, type: 'instruction_override', severity: 'critical' as const },
481
+ { pattern: /disregard\s+(all\s+)?(previous|prior|above)/i, type: 'instruction_override', severity: 'critical' as const },
482
+ { pattern: /forget\s+(everything|all|what)\s+(you|I)\s+(said|told|wrote)/i, type: 'instruction_override', severity: 'critical' as const },
483
+ { pattern: /new\s+instructions?:?\s/i, type: 'instruction_override', severity: 'high' as const },
484
+ { pattern: /override\s+(previous|system)\s+(instructions?|prompts?)/i, type: 'instruction_override', severity: 'critical' as const },
485
+
486
+ // Role manipulation
487
+ { pattern: /you\s+are\s+(now|actually)\s+(a|an|the)/i, type: 'role_manipulation', severity: 'high' as const },
488
+ { pattern: /pretend\s+(to\s+be|you'?re)/i, type: 'role_manipulation', severity: 'medium' as const },
489
+ { pattern: /act\s+as\s+(if|though|a|an)/i, type: 'role_manipulation', severity: 'medium' as const },
490
+ { pattern: /roleplay\s+as/i, type: 'role_manipulation', severity: 'medium' as const },
491
+ { pattern: /from\s+now\s+on\s+you\s+(are|will)/i, type: 'role_manipulation', severity: 'high' as const },
492
+
493
+ // System prompt extraction
494
+ { pattern: /what\s+(is|are)\s+your\s+(system\s+)?prompt/i, type: 'prompt_extraction', severity: 'high' as const },
495
+ { pattern: /show\s+(me\s+)?your\s+(system\s+)?instructions/i, type: 'prompt_extraction', severity: 'high' as const },
496
+ { pattern: /reveal\s+your\s+(instructions|prompt|rules)/i, type: 'prompt_extraction', severity: 'high' as const },
497
+ { pattern: /repeat\s+(back\s+)?(your\s+)?(system\s+)?prompt/i, type: 'prompt_extraction', severity: 'high' as const },
498
+ { pattern: /print\s+(your\s+)?(initial|system)\s+(prompt|instructions)/i, type: 'prompt_extraction', severity: 'high' as const },
499
+
500
+ // Jailbreak attempts
501
+ { pattern: /DAN\s+(mode|prompt)/i, type: 'jailbreak', severity: 'critical' as const },
502
+ { pattern: /do\s+anything\s+now/i, type: 'jailbreak', severity: 'critical' as const },
503
+ { pattern: /jailbreak/i, type: 'jailbreak', severity: 'critical' as const },
504
+ { pattern: /bypass\s+(your\s+)?(restrictions|limitations|filters|rules)/i, type: 'jailbreak', severity: 'critical' as const },
505
+ { pattern: /without\s+(any\s+)?(restrictions|limitations|filters|rules)/i, type: 'jailbreak', severity: 'high' as const },
506
+ { pattern: /enable\s+(developer|admin|god)\s+mode/i, type: 'jailbreak', severity: 'critical' as const },
507
+
508
+ // Context manipulation
509
+ { pattern: /\[system\]/i, type: 'context_manipulation', severity: 'high' as const },
510
+ { pattern: /\[INST\]/i, type: 'context_manipulation', severity: 'high' as const },
511
+ { pattern: /<\|im_start\|>/i, type: 'context_manipulation', severity: 'high' as const },
512
+ { pattern: /Human:|Assistant:|System:/i, type: 'context_manipulation', severity: 'medium' as const },
513
+ { pattern: /```system/i, type: 'context_manipulation', severity: 'high' as const },
514
+
515
+ // Encoded instructions
516
+ { pattern: /base64:?\s*[A-Za-z0-9+/=]{20,}/i, type: 'encoded_instruction', severity: 'medium' as const },
517
+ { pattern: /\\x[0-9a-fA-F]{2}/g, type: 'encoded_instruction', severity: 'medium' as const },
518
+ { pattern: /&#\d+;/g, type: 'encoded_instruction', severity: 'low' as const },
519
+ { pattern: /\\u[0-9a-fA-F]{4}/g, type: 'encoded_instruction', severity: 'low' as const },
520
+ ];
521
+
522
+ // ============================================================================
523
+ // Intent Classification Keywords
524
+ // ============================================================================
525
+
526
+ export const INTENT_KEYWORDS = {
527
+ query: ['get', 'fetch', 'find', 'search', 'lookup', 'retrieve', 'show', 'display', 'list', 'what', 'where', 'who', 'when', 'how many', 'count'],
528
+ mutation: ['update', 'change', 'modify', 'edit', 'set', 'put', 'patch', 'alter', 'adjust', 'fix', 'correct'],
529
+ deletion: ['delete', 'remove', 'drop', 'clear', 'erase', 'destroy', 'purge', 'wipe'],
530
+ execution: ['run', 'execute', 'start', 'launch', 'trigger', 'invoke', 'call', 'perform'],
531
+ communication: ['send', 'email', 'message', 'notify', 'alert', 'post', 'share', 'forward', 'reply'],
532
+ analysis: ['analyze', 'summarize', 'explain', 'describe', 'compare', 'evaluate', 'assess', 'review'],
533
+ generation: ['create', 'generate', 'make', 'build', 'compose', 'write', 'draft', 'design', 'produce'],
534
+ };
535
+
536
+ // ============================================================================
537
+ // Entity Patterns
538
+ // ============================================================================
539
+
540
+ export const ENTITY_PATTERNS = {
541
+ email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
542
+ phone: /\b(?:\+1[-.\s]?)?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}\b/g,
543
+ url: /https?:\/\/[^\s<>"{}|\\^`\[\]]+/g,
544
+ ip_address: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g,
545
+ file_path: /(?:\/[\w.-]+)+\/?|(?:[A-Za-z]:\\[\w\s.-]+)+\\?/g,
546
+ datetime: /\b\d{4}[-/]\d{2}[-/]\d{2}(?:[\sT]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)?\b/g,
547
+ money: /\$\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?|\d{1,3}(?:,\d{3})*(?:\.\d{2})?\s?(?:USD|EUR|GBP|JPY|dollars?|euros?|pounds?)/gi,
548
+ percent: /\b\d+(?:\.\d+)?%/g,
549
+ ssn: /\b\d{3}-\d{2}-\d{4}\b/g,
550
+ credit_card: /\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\b/g,
551
+ api_key: /\b(?:sk|pk|api|key|token|secret|auth)[_-]?[A-Za-z0-9]{16,}\b/gi,
552
+ };
553
+
554
+ // ============================================================================
555
+ // Protocol Fee Constants
556
+ // ============================================================================
557
+
558
+ export const PROTOCOL_FEES = {
559
+ solana: {
560
+ base_lamports: 100_000, // 0.0001 SOL
561
+ protocol_fee_bps: 500, // 5%
562
+ },
563
+ ethereum: {
564
+ protocol_fee_bps: 500, // 5% of gas
565
+ },
566
+ };
package/src/index.ts ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Dōmere - The Judge Protocol
4
+ * MCP Server Entry Point
5
+ */
6
+
7
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
10
+
11
+ import { DOMERE_TOOLS, DomereToolHandler } from './tools/index.js';
12
+ import { createStorage } from './storage/index.js';
13
+
14
+ const server = new Server({ name: 'domere', version: '1.0.0' }, { capabilities: { tools: {} } });
15
+ const storage = createStorage('memory');
16
+ const toolHandler = new DomereToolHandler(storage);
17
+
18
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: DOMERE_TOOLS }));
19
+
20
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
21
+ const { name, arguments: args } = request.params;
22
+ try {
23
+ const result = await toolHandler.handleTool(name, args as Record<string, unknown>);
24
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
25
+ } catch (error) {
26
+ return { content: [{ type: 'text', text: JSON.stringify({ error: String(error) }) }], isError: true };
27
+ }
28
+ });
29
+
30
+ async function main() {
31
+ const transport = new StdioServerTransport();
32
+ await server.connect(transport);
33
+ console.error('Dōmere MCP server running');
34
+ }
35
+
36
+ main().catch(e => { console.error(e); process.exit(1); });
37
+
38
+ export { DomereToolHandler, DOMERE_TOOLS };
39
+ export * from './types.js';
40
+ export * from './thread/index.js';
41
+ export * from './language/index.js';
42
+ export * from './anchoring/index.js';
43
+ export * from './storage/index.js';