File size: 1,068 Bytes
29cdc9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os

class ContextSerializer:
    def __init__(self, workspace_path):
        self.root = workspace_path
        self.ledger_path = os.path.join(workspace_path, "project_ledger.json")

    def generate_context(self):
        # 1. Summarize Ledger
        ledger_data = {}
        if os.path.exists(self.ledger_path):
            with open(self.ledger_path, 'r') as f:
                ledger_data = json.load(f)
        
        # 2. Map File Structure
        structure = []
        for root, dirs, files in os.walk(self.root):
            if '.git' in root or '__pycache__' in root or 'ide_kernel' in root:
                continue
            structure.append(f"{root}: {files}")

        # 3. Compile
        context = "--- PROJECT STATE ---\n"
        context += f"History: {json.dumps(ledger_data, indent=2)}\n"
        context += f"Filesystem: {structure}\n"
        context += "---------------------\n"
        return context

if __name__ == "__main__":
    serializer = ContextSerializer(os.getcwd())
    print(serializer.generate_context())