File size: 19,109 Bytes
f9b1ad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# ToGMAL Architecture

## System Overview

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Claude Desktop                          β”‚
β”‚                    (or other MCP Client)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚ stdio/MCP Protocol
                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     ToGMAL MCP Server                           β”‚
β”‚                    (togmal_mcp.py)                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚                   MCP Tools Layer                         β”‚  β”‚
β”‚  β”‚  - togmal_analyze_prompt                                 β”‚  β”‚
β”‚  β”‚  - togmal_analyze_response                               β”‚  β”‚
β”‚  β”‚  - togmal_submit_evidence                                β”‚  β”‚
β”‚  β”‚  - togmal_get_taxonomy                                   β”‚  β”‚
β”‚  β”‚  - togmal_get_statistics                                 β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β”‚                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚              Detection Heuristics                         β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Math/Physics Speculation Detector                 β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "theory of everything"                 β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "new equation"                         β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: excessive notation                     β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Ungrounded Medical Advice Detector                β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "you probably have"                    β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "take Xmg"                            β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_sources                              β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Dangerous File Operations Detector                β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "rm -rf"                              β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: recursive deletion                     β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_safeguards                          β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Vibe Coding Overreach Detector                   β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "complete app"                         β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: large line counts                      β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_planning                            β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  Unsupported Claims Detector                       β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: "always/never"                         β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Pattern: statistics without source              β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  - Check: has_hedging                             β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β”‚                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚           Risk Assessment & Interventions                 β”‚  β”‚
β”‚  β”‚  - Calculate weighted risk score                         β”‚  β”‚
β”‚  β”‚  - Map to risk levels (LOW β†’ CRITICAL)                  β”‚  β”‚
β”‚  β”‚  - Recommend interventions                               β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β”‚                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚              Taxonomy Database                            β”‚  β”‚
β”‚  β”‚  - In-memory storage (extendable to persistent)          β”‚  β”‚
β”‚  β”‚  - Evidence entries with metadata                        β”‚  β”‚
β”‚  β”‚  - Filtering and pagination                              β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Data Flow - Prompt Analysis

```
User Prompt
    β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                                             β”‚
    β–Ό                                             β”‚
togmal_analyze_prompt                             β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί Math/Physics Detector ──► Result 1      β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί Medical Advice Detector ──► Result 2    β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί File Ops Detector ──► Result 3          β”‚
    β”‚                                             β”‚
    β”œβ”€β”€β–Ί Vibe Coding Detector ──► Result 4       β”‚
    β”‚                                             β”‚
    └──► Unsupported Claims Detector ──► Result 5β”‚
                                                  β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
Risk Calculation
    β”‚
    β”œβ”€β–Ί Weight results
    β”œβ”€β–Ί Calculate score
    └─► Map to risk level
        β”‚
        β–Ό
Intervention Recommendation
    β”‚
    β”œβ”€β–Ί Step breakdown?
    β”œβ”€β–Ί Human-in-loop?
    β”œβ”€β–Ί Web search?
    └─► Simplified scope?
        β”‚
        β–Ό
Format Response (Markdown/JSON)
    β”‚
    └──► Return to Client
```

## Detection Pipeline

```
Input Text
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Preprocessing           β”‚
β”‚   - Lowercase             β”‚
β”‚   - Strip whitespace      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Pattern Matching        β”‚
β”‚   - Regex patterns        β”‚
β”‚   - Keyword detection     β”‚
β”‚   - Structural analysis   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Confidence Scoring      β”‚
β”‚   - Count matches         β”‚
β”‚   - Weight by type        β”‚
β”‚   - Normalize to [0,1]    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Context Checks          β”‚
β”‚   - has_sources?          β”‚
β”‚   - has_hedging?          β”‚
β”‚   - has_safeguards?       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
Detection Result
{
  detected: bool,
  categories: list,
  confidence: float,
  metadata: dict
}
```

## Risk Calculation Algorithm

```
For each detection category:
    
    Math/Physics:
        risk += confidence Γ— 0.5
    
    Medical Advice:
        risk += confidence Γ— 1.5  # Highest weight
    
    File Operations:
        risk += confidence Γ— 2.0  # Critical actions
    
    Vibe Coding:
        risk += confidence Γ— 0.4
    
    Unsupported Claims:
        risk += confidence Γ— 0.3

Total Risk Score:
    
    β‰₯ 1.5 β†’ CRITICAL
    β‰₯ 1.0 β†’ HIGH
    β‰₯ 0.5 β†’ MODERATE
    < 0.5 β†’ LOW
```

## Intervention Decision Tree

```
                    Detection Results
                          β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                 β”‚                 β”‚
        β–Ό                 β–Ό                 β–Ό
  Math/Physics?     Medical Advice?   File Operations?
        β”‚                 β”‚                 β”‚
        β”œβ”€β–Ί Yes           β”œβ”€β–Ί Yes           β”œβ”€β–Ί Yes
        β”‚   β”‚             β”‚   β”‚             β”‚   β”‚
        β”‚   β”œβ”€β–Ί Step      β”‚   β”œβ”€β–Ί Human    β”‚   β”œβ”€β–Ί Human
        β”‚   β”‚   Breakdown β”‚   β”‚   in Loop   β”‚   β”‚   in Loop
        β”‚   β”‚             β”‚   β”‚             β”‚   β”‚
        β”‚   └─► Web       β”‚   └─► Web       β”‚   └─► Step
        β”‚       Search    β”‚       Search    β”‚       Breakdown
        β”‚                 β”‚                 β”‚
        └─► No            └─► No            └─► No
            β”‚                 β”‚                 β”‚
            β–Ό                 β–Ό                 β–Ό
      Continue          Continue          Continue

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Combine  β”‚
                    β”‚  Results  β”‚
                    β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
              Intervention List
              (deduplicated)
```

## Taxonomy Database Schema

```
TAXONOMY_DB = {
    "category_name": [
        {
            "id": "abc123def456",
            "category": "math_physics_speculation",
            "prompt": "User's prompt text...",
            "response": "LLM's response text...",
            "description": "Why problematic...",
            "severity": "high",
            "timestamp": "2025-10-18T00:00:00",
            "prompt_hash": "a1b2c3d4"
        },
        { ... more entries ... }
    ],
    "another_category": [ ... ]
}

Indices:
- By category (dict key)
- By severity (filter)
- By timestamp (sort)
- By hash (deduplication)
```

## Component Responsibilities

### MCP Tools Layer
**Responsibilities:**
- Input validation (Pydantic models)
- Parameter extraction
- Tool orchestration
- Response formatting
- Character limit enforcement

**Does NOT:**
- Perform detection logic
- Calculate risk scores
- Store data directly

### Detection Heuristics Layer
**Responsibilities:**
- Pattern matching
- Confidence scoring
- Context analysis
- Detection result generation

**Does NOT:**
- Make intervention decisions
- Format responses
- Handle I/O

### Risk Assessment Layer
**Responsibilities:**
- Aggregate detection results
- Calculate weighted risk scores
- Map scores to risk levels
- Generate intervention recommendations

**Does NOT:**
- Perform detection
- Format responses
- Store data

### Taxonomy Database
**Responsibilities:**
- Store evidence entries
- Support filtering/pagination
- Provide statistics
- Maintain capacity limits

**Does NOT:**
- Perform analysis
- Make decisions
- Format responses

## Extension Points

### Adding New Detection Categories

```python
# 1. Add enum value
class CategoryType(str, Enum):
    NEW_CATEGORY = "new_category"

# 2. Create detector function
def detect_new_category(text: str) -> Dict[str, Any]:
    patterns = { ... }
    # Detection logic
    return {
        'detected': bool,
        'categories': list,
        'confidence': float
    }

# 3. Update analysis functions
def analyze_prompt(params):
    results['new_category'] = detect_new_category(params.prompt)
    # ... rest of logic

# 4. Update risk calculation
def calculate_risk_level(results):
    if results['new_category']['detected']:
        risk_score += results['new_category']['confidence'] * WEIGHT

# 5. Add intervention logic
def recommend_interventions(results):
    if results['new_category']['detected']:
        interventions.append({ ... })
```

### Adding Persistent Storage

```python
# 1. Define storage backend
class TaxonomyStorage:
    def save(self, category, entry): ...
    def load(self, category, filters): ...
    def get_stats(self): ...

# 2. Replace in-memory dict
storage = TaxonomyStorage(backend="sqlite")  # or "postgres", "mongodb"

# 3. Update tool functions
@mcp.tool()
async def submit_evidence(params):
    # Instead of: TAXONOMY_DB[category].append(entry)
    await storage.save(params.category, entry)
```

### Adding ML Models

```python
# 1. Define model interface
class AnomalyDetector:
    def fit(self, X): ...
    def predict(self, x) -> float: ...

# 2. Train from taxonomy
detector = AnomalyDetector()
training_data = get_training_data_from_taxonomy()
detector.fit(training_data)

# 3. Use in detection
def detect_with_ml(text: str) -> float:
    features = extract_features(text)
    anomaly_score = detector.predict(features)
    return anomaly_score
```

## Performance Characteristics

### Time Complexity
- **Pattern Matching**: O(n) where n = text length
- **All Detectors**: O(n) (parallel constant time)
- **Risk Calculation**: O(1) (fixed number of categories)
- **Taxonomy Query**: O(mΒ·log m) where m = matching entries
- **Overall**: O(n + mΒ·log m)

### Space Complexity
- **Server Base**: ~50 MB
- **Per Request**: ~1 KB (temporary)
- **Per Taxonomy Entry**: ~1 KB
- **Total with 1000 entries**: ~51 MB

### Latency
- **Single Detection**: ~10-50 ms
- **All Detections**: ~50-100 ms
- **Format Response**: ~1-10 ms
- **Total Per Request**: ~100-150 ms

## Security Considerations

### Input Validation
```
User Input
    β”‚
    β–Ό
Pydantic Model
    β”‚
    β”œβ”€β–Ί Type checking
    β”œβ”€β–Ί Length limits
    β”œβ”€β–Ί Pattern validation
    └─► Field constraints
        β”‚
        β–Ό
    Valid Input
```

### Privacy Protection
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  NO External API Calls             β”‚
β”‚  NO Data Transmission              β”‚
β”‚  NO Logging Sensitive Info         β”‚
β”‚  YES Local Processing Only         β”‚
β”‚  YES User Consent Required         β”‚
β”‚  YES Data Stays on Device          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Human-in-the-Loop
```
Sensitive Operation Detected
    β”‚
    β–Ό
Request User Confirmation
    β”‚
    β”œβ”€β–Ί Yes β†’ Proceed
    β”‚
    └─► No β†’ Cancel
```

## Scalability Path

### Current: Single Instance
```
Client β†’ stdio β†’ ToGMAL Server β†’ Response
```

### Future: HTTP Transport
```
Multiple Clients β†’ HTTP β†’ ToGMAL Server β†’ Response
                          ↓
                    Shared Database
```

### Advanced: Distributed
```
Clients β†’ Load Balancer β†’ ToGMAL Servers (N)
                              ↓
                        Shared Database
                              ↓
                        ML Model Cache
```

## Monitoring Points

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Metrics to Track                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  - Tool call frequency              β”‚
β”‚  - Detection rates by category      β”‚
β”‚  - Risk level distribution          β”‚
β”‚  - Intervention effectiveness       β”‚
β”‚  - False positive rate              β”‚
β”‚  - Response latency                 β”‚
β”‚  - Taxonomy growth rate             β”‚
β”‚  - User feedback submissions        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

This architecture supports:
- βœ… Privacy-preserving analysis
- βœ… Low-latency detection
- βœ… Extensible design
- βœ… Production readiness
- βœ… Future ML integration