File size: 45,276 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
# WidgetTDC Enhancement Assessment & Implementation Plan

**Dato**: 25. november 2025  
**Status**: VURDERING KOMPLET - INTEGRERET MED TIDLIGERE ANALYSE  
**Kritisk Begrænsning**: INGEN VÆSENTLIGE ÆNDRINGER TIL EKSISTERENDE KODE  
**Version**: 2.0 - Omfatter tidligere chat-analyse af autonome widgets og dokumentgeneratorer

---

## πŸ“Š EXECUTIVE SUMMARY

Efter grundig analyse af:
- Den eksisterende WidgetTDC kodebase (38 widgets, 30+ MCP tools)
- "500% Enhancement Architecture" dokumentet
- **Tidligere chat-analyse af autonome OSINT/Cybersecurity widgets**
- **Dokumentgenerator-widgets (PowerPoint, Word, Excel)**
- **MCP PowerPoint Server integrations (PPTAgent, MultiAgentPPT, ChatPPT-MCP)**

Denne plan præsenterer en **realistisk, additiv** implementeringsstrategi der:

1. **Bevarer 100%** af eksisterende funktionalitet
2. **TilfΓΈjer 3 kategorier af nye widgets**: OSINT, Cybersecurity, Document Generation
3. **Integrerer eksisterende MCP PowerPoint server** fra Clauskraft/powerpoint
4. **Implementerer autonomt "spor following"** via eksisterende TaskRecorder + EventBus
5. **Udnytter PPTAgent + MultiAgentPPT** arkitekturen for dokumentgenerering

### Vurdering af Samlede Forbedringer

| Aspekt | Vurdering | Risiko | Anbefaling |
|--------|-----------|--------|------------|
| 7 OSINT Widgets | βœ… REALISTISK | LAV | ImplementΓ©r gradvist |
| Autonomous Threat Hunter | βœ… REALISTISK | LAV | FΓΈlger eksisterende patterns |
| "Spor Following" Engine | βœ… MULIGT | MEDIUM | Via TaskRecorder + EventBus |
| Dokumentgeneratorer (PPT/Word/Excel) | βœ… REALISTISK | LAV | IntegrΓ©r eksisterende MCP server |
| PPTAgent Integration | βœ… ADDITIVT | MEDIUM | Docker-baseret, selvstΓ¦ndig |
| MultiAgentPPT Arkitektur | ⚠️ KOMPLEKST | MEDIUM | POC først |
| HuggingFace Integration | ⚠️ KOMPLEKST | MEDIUM | Start med 2-3 modeller |
| Klavis Integration | ⚠️ EXTERNAL | MEDIUM | POC først |

**Samlet Vurdering**: 75% af forslagene kan implementeres sikkert inden for 8 uger uden at Γ¦ndre eksisterende arkitektur.

---

## πŸ†• NYT FRA TIDLIGERE CHAT-ANALYSE

### Identificerede Ressourcer til Integration

| Ressource | Type | Key Features | Integration Værdi |
|-----------|------|--------------|-------------------|
| **Clauskraft/powerpoint** | MCP Server | python-pptx, FLUX images, 7 tools | ⭐⭐⭐⭐⭐ EKSISTERER |
| **PPTAgent (icip-cas)** | Python Framework | 2-stage generation, PPTEval, Zenodo10K | ⭐⭐⭐⭐⭐ GAME CHANGER |
| **MultiAgentPPT** | Multi-Agent System | A2A + MCP + ADK, parallel agents | ⭐⭐⭐⭐⭐ PERFEKT TIL WIDGETDC |
| **ChatPPT-MCP** | Commercial MCP | 18 APIs, HTTP streaming | ⭐⭐⭐⭐ Enterprise-ready |
| **Zenodo10K Dataset** | Training Data | 10,000+ .pptx files | ⭐⭐⭐⭐⭐ CRITICAL |

### Nye Widget-Kategorier fra Analyse

```
NYE WIDGETS (fra tidligere chat):
β”œβ”€ AUTONOME OSINT (3 stk)
β”‚  β”œβ”€ AutonomousOSINTEmailWidget      (31 KB, 954 linjer)
β”‚  β”œβ”€ AutonomousThreatHunterWidget    (34 KB, 1000+ linjer)
β”‚  └─ MasterOrchestratorWidget        (25 KB, 800+ linjer)
β”‚
β”œβ”€ DOKUMENTGENERATORER (3 stk)
β”‚  β”œβ”€ AutonomousPowerPointMaster      (35 KB, 1113 linjer)
β”‚  β”œβ”€ AutonomousWordArchitect         (47 KB, 1202 linjer)
β”‚  └─ AutonomousExcelAnalyzer         (38 KB, 1230 linjer)
β”‚
└─ TOTAL: 6 nye enterprise-grade widgets (210 KB, 5300+ linjer)

---

## πŸ” EKSISTERENDE STATE (Verificeret fra kodebase)

### Aktuelle Widgets (35 stk i widgetRegistry.js)

```
KATEGORIER (verificeret):
β”œβ”€ agents (6): AgentMonitor, AgentBuilder, AgentChat, AgentStatusDashboard, 
β”‚              PersonaCoordinator, PersonalAgent, EvolutionAgent
β”œβ”€ security (4): CybersecurityOverwatch, DarkWebMonitor, LocalScan, NetworkSpy
β”œβ”€ monitoring (4): ActivityStream, PerformanceMonitor, StatusWidget, SystemMonitor
β”œβ”€ integration (3): MCPConnector, MCPEmailRAG, McpRouter
β”œβ”€ media (3): ImageAnalyzer, AudioTranscriber, VideoAnalyzer
β”œβ”€ productivity (4): IntelligentNotes, Kanban, Phase1CFastTrack, SearchInterface
β”œβ”€ communication (2): AgentChat, LiveConversation
β”œβ”€ development (2): CodeAnalysis, NexusTerminal
β”œβ”€ ai (2): AiPal, PromptLibrary
β”œβ”€ analytics (2): CmaDecision, ProcurementIntelligence
β”œβ”€ compliance (1): SragGovernance
β”œβ”€ data (1): FeedIngestion
β”œβ”€ settings (1): SystemSettings
└─ system (1): WidgetImporter
```

### MCP Infrastruktur (SOLID FOUNDATION)

```typescript
// Eksisterende - apps/backend/src/mcp/
β”œβ”€ mcpRouter.ts          // HTTP POST /route + GET /tools + GET /resources
β”œβ”€ mcpRegistry.ts        // Tool registration + routing + server management
β”œβ”€ mcpWebsocketServer.ts // WebSocket on /mcp/ws with broadcast
β”œβ”€ toolHandlers.ts       // 30+ tool handlers (CMA, SRAG, PAL, Evolution, etc.)
└─ EventBus.ts           // Event-driven communication
```

### Cognitive Services (ALLEREDE IMPLEMENTERET)

| Service | Status | Lokation |
|---------|--------|----------|
| UnifiedMemorySystem | βœ… AKTIV | `mcp/cognitive/UnifiedMemorySystem.ts` |
| TaskRecorder | βœ… AKTIV | `mcp/cognitive/TaskRecorder.ts` |
| PatternEvolutionEngine | βœ… AKTIV | `mcp/cognitive/PatternEvolutionEngine.ts` |
| StateGraphRouter | βœ… AKTIV | `mcp/cognitive/StateGraphRouter.ts` |
| HybridSearchEngine | βœ… AKTIV | `mcp/cognitive/HybridSearchEngine.ts` |
| UnifiedGraphRAG | βœ… AKTIV | `mcp/cognitive/UnifiedGraphRAG.ts` |
| AgentTeam | βœ… AKTIV | `mcp/cognitive/AgentTeam.ts` |

### Eksisterende MCP Tools (30+ handlers)

```typescript
// Verificeret i toolHandlers.ts:
CMA: cma.context, cma.ingest, cma.memory.store, cma.memory.retrieve
SRAG: srag.query, srag.governance.check
Evolution: evolution.report, evolution.get.prompt, evolution.analyze.prompts
PAL: pal.event, pal.board.action, pal.optimize.workflow, pal.analyze.sentiment
Notes: notes.list, notes.create, notes.update, notes.delete, notes.get
Autonomous: autonomous.graph-rag, autonomous.state-graph, autonomous.evolution, 
            autonomous.agent-team, autonomous.agent-team.coordinate
Vidensarkiv: vidensarkiv.search, vidensarkiv.add, vidensarkiv.batch-add, 
             vidensarkiv.get-related, vidensarkiv.list, vidensarkiv.stats
TaskRecorder: taskrecorder.get-suggestions, taskrecorder.approve, 
              taskrecorder.reject, taskrecorder.execute, taskrecorder.get-patterns
Email: email.rag
Agentic: agentic.run
```

---

## ⚠️ KRITISKE ERKENDELSER

### Hvad "500% Enhancement" Forslaget OVERSER

1. **Widget-to-Widget Communication Eksisterer Allerede**
   - EventBus (`mcp/EventBus.ts`) hΓ₯ndterer cross-widget events
   - WebSocket broadcast sender til alle connected clients
   - TaskRecorder observerer alle tool executions

2. **Autonomous Capabilities Er Allerede Tilstede**
   - `StateGraphRouter` implementerer state-machine baseret routing
   - `PatternEvolutionEngine` hΓ₯ndterer pattern learning
   - `AgentTeam.coordinate()` orchestrerer multi-agent tasks

3. **Memory/Correlation Findes**
   - `UnifiedMemorySystem.findHolographicPatterns()` korrelerer pΓ₯ tvΓ¦rs af subsystems
   - `HybridSearchEngine` kombinerer multiple search strategies
   - `UnifiedGraphRAG` implementerer graph-based retrieval

### Hvad Der FAKTISK Mangler

| OmrΓ₯de | NuvΓ¦rende State | ForeslΓ₯et LΓΈsning |
|--------|-----------------|-------------------|
| OSINT Widgets | Dark Web + Search + Feed | TilfΓΈj 5-7 specialiserede widgets |
| ML/AI Models | Kun LLM via llmService | TilfΓΈj HuggingFace embedding + classification |
| Widget Discovery | Hardcoded i constants.ts | Dynamic registry med capabilities |
| Cross-Widget Data | Ingen shared findings | Unified findings store |
| External Services | OAuth i OutlookJsonAdapter | Udnyt Klavis for flere services |

---

## 🎯 ANBEFALET IMPLEMENTERINGSPLAN

### Princip: ADDITIV UDVIKLING

```
                         EKSISTERENDE KODE
                         (100% bevaret)
                               β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β–Ό                     β–Ό
              NYE MCP TOOLS          NYE WIDGETS
              (additive)             (fΓΈlger pattern)
                    β”‚                     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β–Ό
                      ENHANCEMENT LAYER
                      (ovenpΓ₯ eksisterende)
```

---

## PHASE 1: QUICK WINS (Uge 1-2)

### 1.1 Widget Orchestration Tools (Additive MCP)

**Lokation**: `apps/backend/src/mcp/toolHandlers.ts` (tilfΓΈj til eksisterende)

```typescript
// NYE MCP TOOLS - tilfΓΈjes til eksisterende toolHandlers.ts

/**
 * widgets.invoke - Trigger another widget with data
 */
export async function widgetsInvokeHandler(payload: any, ctx: McpContext): Promise<any> {
  const { targetWidget, action, data } = payload;
  
  // Emit event for target widget
  eventBus.emit(`widget.${targetWidget}.${action}`, {
    ...data,
    sourceContext: ctx,
    timestamp: new Date().toISOString()
  });
  
  return {
    success: true,
    targetWidget,
    action,
    message: `Event emitted to ${targetWidget}`
  };
}

/**
 * widgets.discover - Get widget capabilities
 */
export async function widgetsDiscoverHandler(payload: any, _ctx: McpContext): Promise<any> {
  const { filter } = payload;
  
  // Use existing WIDGET_REGISTRY from widgetRegistry.js
  const { WIDGET_REGISTRY, WIDGET_CATEGORIES } = await import('../../../matrix-frontend/widgetRegistry.js');
  
  let widgets = Object.values(WIDGET_REGISTRY);
  
  if (filter?.category) {
    widgets = widgets.filter((w: any) => w.category === filter.category);
  }
  
  return {
    success: true,
    widgets: widgets.map((w: any) => ({
      id: w.id,
      name: w.name,
      category: w.category,
      description: w.description
    })),
    categories: Object.keys(WIDGET_CATEGORIES),
    count: widgets.length
  };
}

/**
 * widgets.correlate - Share findings across widgets
 */
export async function widgetsCorrelateHandler(payload: any, ctx: McpContext): Promise<any> {
  const { sourceWidget, findings, tags } = payload;
  
  // Store in unified memory
  await unifiedMemorySystem.updateWorkingMemory(ctx, {
    type: 'widget_findings',
    sourceWidget,
    findings,
    tags,
    timestamp: new Date().toISOString()
  });
  
  // Broadcast to all widgets
  eventBus.emit('widgets.findings.new', {
    sourceWidget,
    findings,
    tags,
    orgId: ctx.orgId,
    userId: ctx.userId
  });
  
  return {
    success: true,
    message: `Findings from ${sourceWidget} shared`,
    findingsCount: findings.length,
    tags
  };
}
```

**Registrering** (tilfΓΈj til index.ts):

```typescript
mcpRegistry.registerTool('widgets.invoke', widgetsInvokeHandler);
mcpRegistry.registerTool('widgets.discover', widgetsDiscoverHandler);
mcpRegistry.registerTool('widgets.correlate', widgetsCorrelateHandler);
```

### 1.2 Dynamic Widget Registry Enhancement

**Lokation**: Ny fil `apps/matrix-frontend/src/services/WidgetDiscoveryService.ts`

```typescript
import { WIDGET_REGISTRY, WIDGET_CATEGORIES } from '../../widgetRegistry.js';

export interface WidgetCapability {
  id: string;
  name: string;
  category: string;
  capabilities: string[];
  mcpTools?: string[];
  autonomyLevel: 'MANUAL' | 'SEMI' | 'FULL';
}

export class WidgetDiscoveryService {
  private static instance: WidgetDiscoveryService;
  private capabilities: Map<string, WidgetCapability> = new Map();
  
  static getInstance(): WidgetDiscoveryService {
    if (!this.instance) {
      this.instance = new WidgetDiscoveryService();
    }
    return this.instance;
  }
  
  constructor() {
    this.initializeFromRegistry();
  }
  
  private initializeFromRegistry(): void {
    Object.entries(WIDGET_REGISTRY).forEach(([id, widget]: [string, any]) => {
      this.capabilities.set(id, {
        id,
        name: widget.name,
        category: widget.category,
        capabilities: this.inferCapabilities(widget),
        mcpTools: this.inferMcpTools(id),
        autonomyLevel: this.inferAutonomyLevel(widget.category)
      });
    });
  }
  
  private inferCapabilities(widget: any): string[] {
    const caps: string[] = [];
    const desc = (widget.description || '').toLowerCase();
    
    if (desc.includes('search') || desc.includes('query')) caps.push('search');
    if (desc.includes('monitor') || desc.includes('track')) caps.push('monitoring');
    if (desc.includes('analysis') || desc.includes('analyze')) caps.push('analysis');
    if (desc.includes('ai') || desc.includes('intelligence')) caps.push('ai-powered');
    if (desc.includes('security') || desc.includes('threat')) caps.push('security');
    
    return caps;
  }
  
  private inferMcpTools(widgetId: string): string[] {
    const toolMap: Record<string, string[]> = {
      'SearchInterfaceWidget': ['srag.query', 'vidensarkiv.search'],
      'DarkWebMonitorWidget': ['srag.query', 'widgets.correlate'],
      'FeedIngestionWidget': ['srag.query', 'cma.ingest'],
      'AgentChatWidget': ['cma.context', 'pal.analyze.sentiment'],
      'CmaDecisionWidget': ['cma.context', 'cma.memory.retrieve'],
      // Add more mappings as needed
    };
    return toolMap[widgetId] || [];
  }
  
  private inferAutonomyLevel(category: string): 'MANUAL' | 'SEMI' | 'FULL' {
    if (category === 'agents') return 'FULL';
    if (category === 'monitoring' || category === 'security') return 'SEMI';
    return 'MANUAL';
  }
  
  getByCapability(capability: string): WidgetCapability[] {
    return Array.from(this.capabilities.values())
      .filter(w => w.capabilities.includes(capability));
  }
  
  getByCategory(category: string): WidgetCapability[] {
    return Array.from(this.capabilities.values())
      .filter(w => w.category === category);
  }
  
  getAll(): WidgetCapability[] {
    return Array.from(this.capabilities.values());
  }
}

export const widgetDiscovery = WidgetDiscoveryService.getInstance();
```

---

## PHASE 2: OSINT WIDGET FOUNDATION (Uge 2-3)

### 2.1 Base OSINT Widget Pattern

**Princip**: FΓΈlg eksisterende widget pattern fra `apps/matrix-frontend/widgets/`

```typescript
// apps/matrix-frontend/widgets/DomainIntelligenceWidget.tsx

import React, { useState, useCallback } from 'react';
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card';
import { Input } from '../components/ui/input';
import { Button } from '../components/ui/button';
import { useMcpClient } from '../hooks/useMcpClient';
import { Globe, Shield, Server, AlertTriangle } from 'lucide-react';

interface DomainResult {
  domain: string;
  whois?: { registrar: string; created: string; expires: string };
  dns?: { a: string[]; mx: string[]; ns: string[] };
  ssl?: { issuer: string; validUntil: string; grade: string };
  threats?: { score: number; issues: string[] };
}

export const DomainIntelligenceWidget: React.FC = () => {
  const [domain, setDomain] = useState('');
  const [result, setResult] = useState<DomainResult | null>(null);
  const [loading, setLoading] = useState(false);
  const { invoke } = useMcpClient();
  
  const handleLookup = useCallback(async () => {
    if (!domain.trim()) return;
    
    setLoading(true);
    try {
      // Use MCP tool for domain lookup
      const response = await invoke('osint.domain.lookup', { domain });
      setResult(response);
      
      // Share findings with other widgets
      await invoke('widgets.correlate', {
        sourceWidget: 'DomainIntelligenceWidget',
        findings: [{ type: 'DOMAIN_INTEL', data: response }],
        tags: ['domain', 'osint', domain]
      });
    } catch (error) {
      console.error('Domain lookup failed:', error);
    } finally {
      setLoading(false);
    }
  }, [domain, invoke]);
  
  return (
    <Card className="h-full">
      <CardHeader className="pb-2">
        <CardTitle className="flex items-center gap-2">
          <Globe className="h-5 w-5" />
          Domain Intelligence
        </CardTitle>
      </CardHeader>
      <CardContent>
        <div className="flex gap-2 mb-4">
          <Input
            placeholder="Enter domain (e.g., example.com)"
            value={domain}
            onChange={(e) => setDomain(e.target.value)}
            onKeyPress={(e) => e.key === 'Enter' && handleLookup()}
          />
          <Button onClick={handleLookup} disabled={loading}>
            {loading ? 'Scanning...' : 'Lookup'}
          </Button>
        </div>
        
        {result && (
          <div className="space-y-4">
            {/* WHOIS Section */}
            {result.whois && (
              <div className="p-3 bg-muted rounded-lg">
                <h4 className="font-semibold flex items-center gap-2">
                  <Server className="h-4 w-4" /> WHOIS
                </h4>
                <div className="text-sm mt-2 space-y-1">
                  <div>Registrar: {result.whois.registrar}</div>
                  <div>Created: {result.whois.created}</div>
                  <div>Expires: {result.whois.expires}</div>
                </div>
              </div>
            )}
            
            {/* DNS Section */}
            {result.dns && (
              <div className="p-3 bg-muted rounded-lg">
                <h4 className="font-semibold flex items-center gap-2">
                  <Globe className="h-4 w-4" /> DNS Records
                </h4>
                <div className="text-sm mt-2 space-y-1">
                  <div>A: {result.dns.a?.join(', ') || 'N/A'}</div>
                  <div>MX: {result.dns.mx?.join(', ') || 'N/A'}</div>
                  <div>NS: {result.dns.ns?.join(', ') || 'N/A'}</div>
                </div>
              </div>
            )}
            
            {/* Threat Score */}
            {result.threats && (
              <div className={`p-3 rounded-lg ${
                result.threats.score > 70 ? 'bg-red-100 dark:bg-red-900/20' :
                result.threats.score > 30 ? 'bg-yellow-100 dark:bg-yellow-900/20' :
                'bg-green-100 dark:bg-green-900/20'
              }`}>
                <h4 className="font-semibold flex items-center gap-2">
                  <AlertTriangle className="h-4 w-4" /> Threat Score
                </h4>
                <div className="text-2xl font-bold">{result.threats.score}/100</div>
                {result.threats.issues.length > 0 && (
                  <ul className="text-sm mt-2">
                    {result.threats.issues.map((issue, i) => (
                      <li key={i}>β€’ {issue}</li>
                    ))}
                  </ul>
                )}
              </div>
            )}
          </div>
        )}
      </CardContent>
    </Card>
  );
};

export default DomainIntelligenceWidget;
```

### 2.2 OSINT MCP Tool Handler

**Lokation**: `apps/backend/src/mcp/osintHandlers.ts` (ny fil)

```typescript
import { McpContext } from '@widget-tdc/mcp-types';

// Domain Intelligence Handler
export async function osintDomainLookupHandler(payload: any, ctx: McpContext): Promise<any> {
  const { domain } = payload;
  
  if (!domain) {
    throw new Error('Domain is required');
  }
  
  // Basic domain analysis (expand with real APIs later)
  const result = {
    domain,
    timestamp: new Date().toISOString(),
    whois: await fetchWhoisData(domain),
    dns: await fetchDnsRecords(domain),
    ssl: await checkSslCertificate(domain),
    threats: await checkThreatIntel(domain)
  };
  
  return result;
}

// Helper functions (placeholder - implement with real services)
async function fetchWhoisData(domain: string): Promise<any> {
  // TODO: Integrate with WHOIS API (e.g., WhoisXML, SecurityTrails)
  return {
    registrar: 'Placeholder Registrar',
    created: '2020-01-01',
    expires: '2025-01-01'
  };
}

async function fetchDnsRecords(domain: string): Promise<any> {
  // TODO: Integrate with DNS resolution
  return {
    a: ['1.2.3.4'],
    mx: ['mail.' + domain],
    ns: ['ns1.' + domain, 'ns2.' + domain]
  };
}

async function checkSslCertificate(domain: string): Promise<any> {
  // TODO: Integrate with SSL checker
  return {
    issuer: 'Let\'s Encrypt',
    validUntil: '2025-06-01',
    grade: 'A'
  };
}

async function checkThreatIntel(domain: string): Promise<any> {
  // TODO: Integrate with VirusTotal, Shodan, etc.
  return {
    score: 15,
    issues: []
  };
}

// Email Intelligence Handler
export async function osintEmailLookupHandler(payload: any, ctx: McpContext): Promise<any> {
  const { email } = payload;
  
  if (!email) {
    throw new Error('Email is required');
  }
  
  return {
    email,
    timestamp: new Date().toISOString(),
    valid: email.includes('@'),
    domain: email.split('@')[1],
    breachCheck: {
      breached: false,
      breaches: []
    },
    reputation: {
      score: 85,
      issues: []
    }
  };
}

// IP Intelligence Handler
export async function osintIpLookupHandler(payload: any, ctx: McpContext): Promise<any> {
  const { ip } = payload;
  
  if (!ip) {
    throw new Error('IP address is required');
  }
  
  return {
    ip,
    timestamp: new Date().toISOString(),
    geolocation: {
      country: 'DK',
      city: 'Copenhagen',
      lat: 55.6761,
      lon: 12.5683
    },
    asn: {
      number: 3292,
      name: 'TDC NET'
    },
    threats: {
      score: 10,
      issues: []
    }
  };
}
```

### 2.3 Widget Registry Update

**TilfΓΈj til**: `apps/matrix-frontend/widgetRegistry.js`

```javascript
// TilfΓΈj til WIDGET_REGISTRY:

'DomainIntelligenceWidget': {
    id: 'DomainIntelligenceWidget',
    name: 'Domain Intelligence',
    category: 'security',
    path: './widgets/DomainIntelligenceWidget',
    icon: 'Globe',
    defaultSize: { w: 6, h: 3 },
    description: 'Domain WHOIS, DNS, SSL and threat analysis'
},
'EmailIntelligenceWidget': {
    id: 'EmailIntelligenceWidget',
    name: 'Email Intelligence',
    category: 'security',
    path: './widgets/EmailIntelligenceWidget',
    icon: 'Mail',
    defaultSize: { w: 6, h: 2 },
    description: 'Email validation, breach checking, and reputation analysis'
},
'IPIntelligenceWidget': {
    id: 'IPIntelligenceWidget',
    name: 'IP Intelligence',
    category: 'security',
    path: './widgets/IPIntelligenceWidget',
    icon: 'Wifi',
    defaultSize: { w: 6, h: 3 },
    description: 'IP geolocation, ASN lookup, and threat analysis'
},
'GithubIntelligenceWidget': {
    id: 'GithubIntelligenceWidget',
    name: 'GitHub Intelligence',
    category: 'security',
    path: './widgets/GithubIntelligenceWidget',
    icon: 'Github',
    defaultSize: { w: 6, h: 3 },
    description: 'Repository mining, secret scanning, and committer profiling'
},
'PasteMonitorWidget': {
    id: 'PasteMonitorWidget',
    name: 'Paste Monitor',
    category: 'security',
    path: './widgets/PasteMonitorWidget',
    icon: 'FileText',
    defaultSize: { w: 6, h: 2 },
    description: 'Monitor paste sites for credential leaks and sensitive data'
},
```

---

## PHASE 3: HUGGINGFACE INTEGRATION (Uge 3-4)

### 3.1 Embedding Service Enhancement

**Lokation**: Udvid `apps/backend/src/services/embeddings/EmbeddingService.ts`

```typescript
// TilfΓΈj HuggingFace model support

import { pipeline, env } from '@xenova/transformers';

// Configure transformers.js
env.cacheDir = './.cache/models';
env.allowLocalModels = true;

export class HuggingFaceEmbeddings {
  private embeddingPipeline: any = null;
  private classificationPipeline: any = null;
  private nerPipeline: any = null;
  
  async initEmbeddings(): Promise<void> {
    if (!this.embeddingPipeline) {
      // Use sentence-transformers for embeddings
      this.embeddingPipeline = await pipeline(
        'feature-extraction',
        'Xenova/all-MiniLM-L6-v2'
      );
    }
  }
  
  async initClassification(): Promise<void> {
    if (!this.classificationPipeline) {
      // Use for threat classification
      this.classificationPipeline = await pipeline(
        'text-classification',
        'Xenova/distilbert-base-uncased-finetuned-sst-2-english'
      );
    }
  }
  
  async initNER(): Promise<void> {
    if (!this.nerPipeline) {
      // Use for entity extraction
      this.nerPipeline = await pipeline(
        'token-classification',
        'Xenova/bert-base-NER'
      );
    }
  }
  
  async embed(text: string): Promise<number[]> {
    await this.initEmbeddings();
    const result = await this.embeddingPipeline(text, { pooling: 'mean', normalize: true });
    return Array.from(result.data);
  }
  
  async classify(text: string): Promise<{ label: string; score: number }> {
    await this.initClassification();
    const result = await this.classificationPipeline(text);
    return result[0];
  }
  
  async extractEntities(text: string): Promise<Array<{ entity: string; word: string; score: number }>> {
    await this.initNER();
    const result = await this.nerPipeline(text);
    return result;
  }
}

export const hfEmbeddings = new HuggingFaceEmbeddings();
```

### 3.2 MCP Tool for HuggingFace

**TilfΓΈj til toolHandlers.ts**:

```typescript
// HuggingFace AI Tools

export async function hfEmbedHandler(payload: any, _ctx: McpContext): Promise<any> {
  const { text } = payload;
  if (!text) throw new Error('Text is required');
  
  const embedding = await hfEmbeddings.embed(text);
  return { embedding, dimensions: embedding.length };
}

export async function hfClassifyHandler(payload: any, _ctx: McpContext): Promise<any> {
  const { text } = payload;
  if (!text) throw new Error('Text is required');
  
  const result = await hfEmbeddings.classify(text);
  return result;
}

export async function hfNerHandler(payload: any, _ctx: McpContext): Promise<any> {
  const { text } = payload;
  if (!text) throw new Error('Text is required');
  
  const entities = await hfEmbeddings.extractEntities(text);
  return { entities };
}
```

---

## PHASE 4: KLAVIS INTEGRATION POC (Uge 4-5)

### 4.1 Vurdering af Klavis

| Aspekt | Fordel | Ulempe | Anbefaling |
|--------|--------|--------|------------|
| Progressive Discovery | LΓΈser tool overload | External dependency | βœ… POC |
| 50+ OAuth Services | Instant integrations | Vendor lock-in | ⚠️ Evaluer |
| Enterprise Security | SOC 2, GDPR ready | Cost | βœ… Matcher krav |
| Self-hosting | Docker support | Maintenance overhead | βœ… Acceptabel |

### 4.2 Klavis POC Implementation

**Lokation**: `apps/backend/src/services/klavis/KlavisAdapter.ts`

```typescript
// Minimal Klavis integration for POC

export class KlavisAdapter {
  private apiKey: string;
  private baseUrl: string;
  
  constructor() {
    this.apiKey = process.env.KLAVIS_API_KEY || '';
    this.baseUrl = process.env.KLAVIS_BASE_URL || 'https://api.klavis.ai';
  }
  
  async createStrataServer(userId: string, servers: string[]): Promise<any> {
    if (!this.apiKey) {
      return { error: 'Klavis API key not configured', fallback: true };
    }
    
    // POC: Use Klavis for external service discovery
    const response = await fetch(`${this.baseUrl}/v1/strata/create`, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${this.apiKey}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        user_id: userId,
        servers
      })
    });
    
    return response.json();
  }
  
  async discoverTools(intent: string): Promise<any> {
    // Progressive discovery for tool selection
    // Fallback to local widget discovery if Klavis unavailable
    if (!this.apiKey) {
      // Use local WidgetDiscoveryService
      const { widgetDiscovery } = await import('../../../matrix-frontend/src/services/WidgetDiscoveryService');
      return widgetDiscovery.getAll();
    }
    
    // Use Klavis progressive discovery
    const response = await fetch(`${this.baseUrl}/v1/discover`, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${this.apiKey}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ intent })
    });
    
    return response.json();
  }
}

export const klavisAdapter = new KlavisAdapter();
```

---

## πŸ“‹ IMPLEMENTATION CHECKLIST

### Phase 1: Quick Wins (Uge 1-2)
- [ ] TilfΓΈj `widgets.invoke` MCP tool
- [ ] TilfΓΈj `widgets.discover` MCP tool  
- [ ] TilfΓΈj `widgets.correlate` MCP tool
- [ ] Opret `WidgetDiscoveryService.ts`
- [ ] Test widget-to-widget communication
- [ ] Dokumentation

### Phase 2: OSINT Widgets (Uge 2-3)
- [ ] `DomainIntelligenceWidget.tsx`
- [ ] `EmailIntelligenceWidget.tsx`
- [ ] `IPIntelligenceWidget.tsx`
- [ ] `GithubIntelligenceWidget.tsx`
- [ ] `PasteMonitorWidget.tsx`
- [ ] OSINT MCP handlers
- [ ] Widget registry updates
- [ ] Integration tests

### Phase 3: HuggingFace (Uge 3-4)
- [ ] Installer `@xenova/transformers`
- [ ] `HuggingFaceEmbeddings` service
- [ ] `hf.embed` MCP tool
- [ ] `hf.classify` MCP tool
- [ ] `hf.ner` MCP tool
- [ ] IntegrΓ©r med eksisterende vidensarkiv

### Phase 4: Klavis POC (Uge 4-5)
- [ ] `KlavisAdapter.ts`
- [ ] Environment variables setup
- [ ] Progressive discovery integration
- [ ] Fallback til local widgets
- [ ] Evaluering af værdi

### Phase 5: Correlation Engine (Uge 5-6)
- [ ] Unified findings store (SQLite table)
- [ ] Correlation rules engine
- [ ] Auto-correlation pΓ₯ tvΓ¦rs af widgets
- [ ] Dashboard for korrelerede findings

---

## ⚠️ HVAD VI IKKE IMPLEMENTERER (ENDNU)

### Udskudt til Later Phases

1. **"Spor Following" Engine**
   - Risiko: For komplekst, kan destabilisere
   - Alternativ: TaskRecorder + EventBus giver 80% af værdien

2. **Full Neo4j Knowledge Graph**
   - Risiko: Stor infrastruktur overhead
   - Alternativ: SQLite + UnifiedGraphRAG er sufficient

3. **Custom HuggingFace Training**
   - Risiko: Kræver ML expertise, GPU resources
   - Alternativ: Pre-trained models er fine for POC

4. **Widget Marketplace**
   - Risiko: Security concerns, complexity
   - Alternativ: Static registry med dynamic discovery

---

## πŸ“Š SUCCESS METRICS

| Metric | MΓ₯l | MΓ₯ling |
|--------|-----|--------|
| Nye Widgets | +5 OSINT | Widget count |
| Nye MCP Tools | +10 | Tool registry count |
| Cross-Widget Events | >100/dag | EventBus metrics |
| HF Model Latency | <500ms | P95 latency |
| Klavis Uptime | >99% | Health checks |
| Zero Breaking Changes | 0 | Regression tests |

---

## πŸ” SECURITY CONSIDERATIONS

1. **API Keys**: Alle external services (Klavis, HuggingFace) via environment variables
2. **GDPR**: Ingen PII i correlation store uden consent
3. **Rate Limiting**: ImplementΓ©r for OSINT API calls
4. **Audit Trail**: TaskRecorder logger alle tool executions

---

## πŸ”„ NYT: AUTONOM "SPOR FOLLOWING" ARKITEKTUR

### Hvordan Det Virker (fra tidligere chat)

Den autonome sporopfΓΈlgning bruger **eksisterende infrastruktur** med ny orkestrering:

```
                    USER INPUT (email/domain/IP)
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ INVESTIGATION ENGINE β”‚
                    β”‚ (Multi-threaded)     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό                     β–Ό                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   TIER 1      β”‚   β”‚   TIER 2      β”‚   β”‚   TIER 3      β”‚
β”‚ (No deps)     β”‚   β”‚ (Depends T1)  β”‚   β”‚ (Depends T2)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚β€’ Email Valid  β”‚   β”‚β€’ LinkedIn     β”‚   β”‚β€’ Employment   β”‚
β”‚β€’ Breach Check β”‚   β”‚β€’ Twitter/X    β”‚   β”‚β€’ Pattern      β”‚
β”‚β€’ WHOIS        β”‚   β”‚β€’ Dark Web     β”‚   β”‚β€’ Deep Scan    β”‚
β”‚β€’ DNS Enum     β”‚   β”‚β€’ Social Media β”‚   β”‚β€’ CVE Check    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                     β”‚                     β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  DATA CORRELATION   β”‚
                    β”‚ (UnifiedMemorySystem)β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  UNIFIED FINDINGS   β”‚
                    β”‚  Export: JSON/PDF   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Integration med Eksisterende Systemer

| Eksisterende System | Rolle i Autonomt Investigation |
|---------------------|-------------------------------|
| `TaskRecorder` | Observerer alle threads, lærer patterns |
| `EventBus` | Thread-to-thread kommunikation |
| `UnifiedMemorySystem` | Korrelation via `findHolographicPatterns()` |
| `StateGraphRouter` | State-machine for investigation flow |
| `AgentTeam.coordinate()` | Multi-agent orchestration |

### NΓΈgle Interfaces (fra Widget Spec)

```typescript
// Investigation Thread Interface
interface InvestigationThread {
  id: string;
  name: string;
  status: 'pending' | 'running' | 'completed' | 'failed';
  progress: number;
  findings: Finding[];
  dependencies: string[];  // Thread IDs this depends on
  priority: number;        // 1-5 (5 = highest)
  requiredTools?: string[];
}

// Finding Interface
interface Finding {
  id: string;
  threadId: string;
  source: string;
  type: 'email' | 'phone' | 'breach' | 'social' | 'darkweb' | 'domain';
  data: any;
  confidence: number;  // 0-100
  relatedFindings: string[];
  timestamp: number;
}

// Widget Config Interface
interface WidgetConfig {
  id: string;
  type: string;
  version: string;
  category: 'osint' | 'cybersecurity' | 'document-generation';
  gdprCompliant: boolean;
  dataRetentionDays: number;
}
```

---

## πŸ“„ NYT: DOKUMENTGENERATOR INTEGRATION

### MCP PowerPoint Server (Clauskraft/powerpoint)

Din eksisterende MCP server har fΓΈlgende tools:

| Tool | Beskrivelse | Integration Status |
|------|-------------|-------------------|
| `create-presentation` | Opretter ny prΓ¦sentation | βœ… Klar |
| `add-slide-title-only` | Titel slide | βœ… Klar |
| `add-slide-section-header` | Section header | βœ… Klar |
| `add-slide-title-content` | Titel + indhold | βœ… Klar |
| `add-slide-title-with-table` | Slide med tabel | βœ… Klar |
| `add-slide-title-with-chart` | Slide med chart | βœ… Klar |
| `add-slide-picture-with-caption` | Billede slide | βœ… Klar |
| `generate-and-save-image` | FLUX image generation | βœ… Klar |

### Integration i WidgeTDC Backend

```typescript
// apps/backend/src/services/MCPPowerPointBackend.ts

export class MCPPowerPointBackend {
  private mcpClient: MCPClient;
  
  constructor() {
    this.mcpClient = new MCPClient({
      serverCommand: 'uv',
      serverArgs: [
        '--directory',
        process.env.POWERPOINT_MCP_PATH || 'C:\\Users\\claus\\Projects\\powerpoint',
        'run',
        'powerpoint',
        '--folder-path',
        process.env.PRESENTATIONS_PATH || './presentations'
      ]
    });
  }
  
  async createPresentation(name: string): Promise<string> {
    return this.mcpClient.callTool('create-presentation', { name });
  }
  
  async addSlide(presentationName: string, slideType: string, data: any): Promise<void> {
    const toolName = `add-slide-${slideType}`;
    await this.mcpClient.callTool(toolName, {
      presentation_name: presentationName,
      ...data
    });
  }
  
  async generateImage(prompt: string, fileName: string): Promise<string> {
    const result = await this.mcpClient.callTool('generate-and-save-image', {
      prompt,
      file_name: fileName
    });
    return result.image_path;
  }
  
  async savePresentation(presentationName: string): Promise<string> {
    const result = await this.mcpClient.callTool('save-presentation', {
      presentation_name: presentationName
    });
    return result.file_path;
  }
}
```

### PPTAgent Integration (2-Stage Generation)

```typescript
// apps/backend/src/services/PPTAgentService.ts

export class PPTAgentService {
  private apiBase = 'http://localhost:9297';
  
  /**
   * Stage 1: Analyze reference presentations
   */
  async analyzeReferences(referenceFiles: string[]): Promise<AnalysisResult> {
    const response = await fetch(`${this.apiBase}/api/analyze`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ references: referenceFiles })
    });
    return response.json();
  }
  
  /**
   * Stage 2: Generate with learned patterns
   */
  async generatePresentation(input: GenerationInput): Promise<string> {
    const response = await fetch(`${this.apiBase}/api/generate`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        document: input.sourceDocument,
        outline: input.outline,
        style_patterns: input.learnedPatterns,
        language_model: 'Qwen2.5-72B-Instruct',
        vision_model: 'gpt-4o'
      })
    });
    return (await response.json()).presentation_path;
  }
  
  /**
   * Evaluate generated presentation
   */
  async evaluatePresentation(pptxPath: string): Promise<PPTEvalResult> {
    const response = await fetch(`${this.apiBase}/api/evaluate`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ presentation_path: pptxPath })
    });
    return response.json(); // { content: 8.5, design: 9.2, coherence: 8.8 }
  }
}

interface AnalysisResult {
  slide_roles: string[];
  structural_patterns: any;
  content_schemas: any;
}

interface GenerationInput {
  sourceDocument: string;
  outline: string;
  learnedPatterns: any;
}

interface PPTEvalResult {
  content: number;
  design: number;
  coherence: number;
  suggestions: string[];
}
```

---

## πŸ—οΈ OPDATERET IMPLEMENTERINGSPLAN (8 UGER)

### PHASE 0: SETUP (Dag 1-3)

```bash
# 1. Clone PPTAgent
cd C:\Users\claus\Projects
git clone https://github.com/icip-cas/PPTAgent.git

# 2. Start PPTAgent Docker container
docker pull forceless/pptagent
docker run -dt --gpus all --name pptagent \
  -e OPENAI_API_KEY=$env:OPENAI_API_KEY \
  -p 9297:9297 -p 8088:8088 \
  -v $env:USERPROFILE:/root \
  forceless/pptagent

# 3. Clone MultiAgentPPT (for research)
git clone https://github.com/johnson7788/MultiAgentPPT.git

# 4. Download Zenodo10K templates (optional)
git lfs clone https://huggingface.co/datasets/Forceless/Zenodo10K
```

### PHASE 1: Quick Wins + Autonome Widgets (Uge 1-2)

| Task | Prioritet | Ansvarlig |
|------|-----------|-----------|
| Tilføj `widgets.invoke/discover/correlate` MCP tools | HØJ | Backend |
| Kopier 3 autonome OSINT widgets til projekt | HØJ | Frontend |
| Integrér MCP PowerPoint server | HØJ | Backend |
| Test widget-to-widget communication | MEDIUM | QA |
| Registrér nye widgets i registry | HØJ | Frontend |

### PHASE 2: Dokumentgeneratorer (Uge 3-4)

| Task | Prioritet | Ansvarlig |
|------|-----------|-----------|
| Kopier 3 dokumentgenerator widgets | HØJ | Frontend |
| Implementér `MCPPowerPointBackend.ts` | HØJ | Backend |
| ImplementΓ©r `PPTAgentService.ts` | MEDIUM | Backend |
| FLUX image generation integration | MEDIUM | Backend |
| Test PPT generation end-to-end | HØJ | QA |

### PHASE 3: OSINT Backend + HuggingFace (Uge 4-5)

| Task | Prioritet | Ansvarlig |
|------|-----------|-----------|
| Implementér OSINT MCP handlers | HØJ | Backend |
| TilfΓΈj HuggingFace embeddings | MEDIUM | Backend |
| IntegrΓ©r med VirusTotal/Shodan API | MEDIUM | Backend |
| Test autonomous investigation flow | HØJ | QA |

### PHASE 4: MultiAgent Orchestration (Uge 5-6)

| Task | Prioritet | Ansvarlig |
|------|-----------|-----------|
| ImplementΓ©r MultiAgentOrchestrator | MEDIUM | Backend |
| Parallel research agents | MEDIUM | Backend |
| Quality checker agent | LAV | Backend |
| Streaming WebSocket updates | HØJ | Frontend |

### PHASE 5: Correlation Engine (Uge 7-8)

| Task | Prioritet | Ansvarlig |
|------|-----------|-----------|
| Unified findings store (SQLite) | MEDIUM | Backend |
| Cross-widget correlation rules | MEDIUM | Backend |
| Dashboard for korrelerede findings | MEDIUM | Frontend |
| GDPR compliance audit | HØJ | Security |

---

## πŸ“‹ WIDGET REGISTRY OPDATERINGER

```javascript
// TilfΓΈj til apps/matrix-frontend/widgetRegistry.js

// === AUTONOME OSINT WIDGETS ===
'AutonomousOSINTEmailWidget': {
  id: 'AutonomousOSINTEmailWidget',
  name: 'Autonomous OSINT Email',
  category: 'security',
  path: './widgets/autonomous/autonomous-osint-email-widget',
  icon: 'Mail',
  defaultSize: { w: 12, h: 8 },
  description: 'Multi-threaded email OSINT with auto spor-following'
},
'AutonomousThreatHunterWidget': {
  id: 'AutonomousThreatHunterWidget',
  name: 'Autonomous Threat Hunter',
  category: 'security',
  path: './widgets/autonomous/autonomous-threat-hunter-widget',
  icon: 'Shield',
  defaultSize: { w: 12, h: 8 },
  description: 'Cybersecurity vulnerability assessment with CVE detection'
},
'MasterOrchestratorWidget': {
  id: 'MasterOrchestratorWidget',
  name: 'Master Orchestrator',
  category: 'security',
  path: './widgets/autonomous/master-orchestrator-widget',
  icon: 'Zap',
  defaultSize: { w: 12, h: 10 },
  description: 'Combined OSINT + Cybersecurity orchestration'
},

// === DOKUMENTGENERATORER ===
'AutonomousPowerPointMaster': {
  id: 'AutonomousPowerPointMaster',
  name: 'PowerPoint Master',
  category: 'productivity',
  path: './widgets/doc-generators/autonomous-powerpoint-master',
  icon: 'Presentation',
  defaultSize: { w: 12, h: 8 },
  description: 'AI-driven presentation generation with DALL-E images'
},
'AutonomousWordArchitect': {
  id: 'AutonomousWordArchitect',
  name: 'Word Architect',
  category: 'productivity',
  path: './widgets/doc-generators/autonomous-word-architect',
  icon: 'FileText',
  defaultSize: { w: 12, h: 8 },
  description: 'Intelligent document generation with knowledge mining'
},
'AutonomousExcelAnalyzer': {
  id: 'AutonomousExcelAnalyzer',
  name: 'Excel Analyzer',
  category: 'productivity',
  path: './widgets/doc-generators/autonomous-excel-analyzer',
  icon: 'Table',
  defaultSize: { w: 12, h: 8 },
  description: 'Data-to-insights Excel with auto charts and financial models'
},
```

---

## πŸ“Š OPDATERET SUCCESS METRICS

| Metric | MΓ₯l | MΓ₯ling |
|--------|-----|--------|
| Nye Widgets | +9 (6 autonome + 3 OSINT) | Widget count |
| Nye MCP Tools | +15 | Tool registry count |
| Cross-Widget Events | >200/dag | EventBus metrics |
| Investigation Threads | <60s for 10 threads | P95 latency |
| PPT Generation | <90s for 10-slide deck | P95 latency |
| HF Model Latency | <500ms | P95 latency |
| Zero Breaking Changes | 0 | Regression tests |
| GDPR Compliance | 30-day retention | Audit |

---

## πŸ” SIKKERHEDSOVERVEJELSER (UDVIDET)

### API Keys og Secrets
- `OPENAI_API_KEY` - For PPTAgent
- `TOGETHER_API_KEY` - For FLUX image generation
- `VIRUSTOTAL_API_KEY` - For threat intel
- `SHODAN_API_KEY` - For infrastructure scanning
- Alle via environment variables, aldrig hardcoded

### GDPR Compliance
- Automatisk data retention (30 dage default)
- PII anonymization i findings
- Audit logging af alle data access
- Right to be forgotten support

### Rate Limiting
```typescript
const apiLimits = {
  'hibp': { max: 10, window: 60000 },      // 10 req/min
  'virustotal': { max: 4, window: 60000 }, // 4 req/min
  'shodan': { max: 1, window: 1000 }       // 1 req/sec
};
```

---

## πŸ“ KONKLUSION

Dette dokument præsenterer en **omfattende, additiv** approach til at forbedre WidgetTDC med:

1. βœ… **6 nye autonome widgets** (OSINT + Dokumentgeneratorer)
2. βœ… **MCP PowerPoint Server integration** (Clauskraft/powerpoint)
3. βœ… **PPTAgent 2-stage generation** (icip-cas)
4. βœ… **Autonomt "spor following"** via TaskRecorder + EventBus
5. βœ… **MultiAgent arkitektur** for parallel research
6. βœ… **100% backwards compatibility** med eksisterende widgets

**Forventet Outcome**: 300% improvement i capabilities inden for 8 uger, med 0% breaking changes.

**NΓΈgleprincipper**:
- Byg ovenpΓ₯ eksisterende MCP infrastructure
- FΓΈlg etablerede widget patterns
- TilfΓΈj nye tools, fjern ikke eksisterende
- POC external integrations fΓΈr commitment
- Bevar 100% backwards compatibility

---

**Document Owner**: Architecture Enhancement Initiative  
**Last Updated**: 25. november 2025  
**Version**: 2.0 - Integreret med tidligere chat-analyse  
**Status**: READY FOR IMPLEMENTATION