@@ -31,16 +31,74 @@ public interface IStateInterface
3131 void UpdateState ( string newState ) ;
3232 }
3333
34+ // Simple Data Loss Prevention helper
35+ // Implements basic rules to detect 'meme' or potentially large/binary content
36+ // and preserves backups of previous states to prevent loss.
37+ public class DataLossPrevention
38+ {
39+ private readonly string _backupDir = "./.dlp_backups" ;
40+
41+ public DataLossPrevention ( )
42+ {
43+ try
44+ {
45+ System . IO . Directory . CreateDirectory ( _backupDir ) ;
46+ }
47+ catch
48+ {
49+ // ignore errors creating backup dir in restricted environments
50+ }
51+ }
52+
53+ public bool IsPotentialMeme ( string content )
54+ {
55+ if ( string . IsNullOrEmpty ( content ) ) return false ;
56+ var lower = content . ToLowerInvariant ( ) ;
57+ // simple heuristics: references to image files, base64 snippets, or word 'meme'
58+ if ( lower . Contains ( "meme" ) || lower . Contains ( ".png" ) || lower . Contains ( ".jpg" ) || lower . Contains ( ".jpeg" ) || lower . Contains ( "data:image" ) || lower . Contains ( "base64," ) )
59+ return true ;
60+ // long single-line content may be a pasted binary blob
61+ if ( content . Length > 200 && ! content . Contains ( "\n " ) ) return true ;
62+ return false ;
63+ }
64+
65+ public void BackupState ( string state )
66+ {
67+ try
68+ {
69+ var file = System . IO . Path . Combine ( _backupDir , $ "state_{ DateTime . UtcNow : yyyyMMdd_HHmmss_fff} .txt") ;
70+ System . IO . File . WriteAllText ( file , state ?? string . Empty ) ;
71+ }
72+ catch
73+ {
74+ // best-effort backup; swallow IO errors
75+ }
76+ }
77+ }
78+
3479 // Main Deep Learning Protocol class
3580 public class DeepLearningProtocol : AbstractCore , IAimInterface , IDepthInterface , IStateInterface
3681 {
3782 private string _currentState = "Initial" ;
3883 private string _aim = "General Reasoning" ;
84+ private readonly DataLossPrevention _dlp = new ( ) ;
3985
4086 public string GetCurrentState ( ) => _currentState ;
4187
4288 public void UpdateState ( string newState )
4389 {
90+ // backup current state before changing
91+ try { _dlp . BackupState ( _currentState ) ; } catch { }
92+
93+ // If the incoming state looks like a meme or binary payload, prevent accidental loss
94+ if ( _dlp . IsPotentialMeme ( newState ) )
95+ {
96+ Console . WriteLine ( "DLP: Potential meme-like content detected. State update blocked and backed up." ) ;
97+ // mark state as restricted but preserve previous
98+ _currentState = $ "[DLP-BLOCKED]";
99+ return ;
100+ }
101+
44102 _currentState = newState ;
45103 Console . WriteLine ( $ "State updated: { _currentState } ") ;
46104 }
0 commit comments