-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexporter.py
More file actions
124 lines (111 loc) · 5.32 KB
/
Copy pathexporter.py
File metadata and controls
124 lines (111 loc) · 5.32 KB
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
import os
import subprocess
import platform
import asyncio
import devbrain_core
import dotenv
# Load environment variables
dotenv.load_dotenv()
def copy_to_clipboard(text: str) -> bool:
"""Copies text to the system clipboard using native commands or fallback library."""
try:
system = platform.system()
if system == "Windows":
# Use Windows clip command
process = subprocess.Popen("clip", stdin=subprocess.PIPE, text=True, shell=True)
process.communicate(text)
return True
elif system == "Darwin":
# Use macOS pbcopy command
process = subprocess.Popen("pbcopy", stdin=subprocess.PIPE, text=True)
process.communicate(text)
return True
else:
# Use Linux xclip command
process = subprocess.Popen(["xclip", "-selection", "clipboard"], stdin=subprocess.PIPE, text=True)
process.communicate(text)
return True
except Exception as e:
# Fallback to pyperclip if installed
try:
import pyperclip
pyperclip.copy(text)
return True
except ImportError:
pass
print(f"[Warning] Native clipboard integration failed: {e}")
return False
async def export_context() -> str:
"""Queries Cognee memory, builds the markdown manifest, and exports it."""
# Ensure memory is initialized and config runs
await devbrain_core.init_memory()
# Query local memory for specific sections
print("[Exporter] Retrieving consolidated project memory from local graph database...")
consolidated_query = (
"Provide a comprehensive summary of the project memory. Please format your response strictly with the following three markdown sections:\n\n"
"## 🏗️ System Architecture & Constraints\n"
"(Describe core system architecture constraints, features, and active structural boundaries here)\n\n"
"## ⚖️ Engineering Decisions (The 'Why')\n"
"(Describe recent engineering decisions, patterns, choices, and the 'why' behind them here)\n\n"
"## ⚠️ Active Feature Dependencies & Structural Blockers\n"
"(Describe active feature dependencies, structural bottlenecks, or coding blockers here)"
)
consolidated_result = await devbrain_core.query_memory_result(consolidated_query)
consolidated_info = consolidated_result.get("data") or ""
recall_sources = consolidated_result.get("source", "unknown")
recall_errors = [consolidated_result.get("error")] if consolidated_result.get("error") else []
if not consolidated_info.strip():
consolidated_info = (
"## 🏗️ System Architecture & Constraints\n"
"No architectural constraints or structural boundaries documented.\n\n"
"## ⚖️ Engineering Decisions (The 'Why')\n"
"No engineering decisions or rationale recorded.\n\n"
"## ⚠️ Active Feature Dependencies & Structural Blockers\n"
"No active feature dependencies or structural blockers detected.\n"
)
# Format the markdown manifest
manifest_content = (
f"# DEVBRAIN PROJECT MEMORY\n\n"
f"## Memory Source & Recall Status\n"
f"Source: {recall_sources}\n"
f"Fallback Used: {consolidated_result.get('fallbackUsed', False)}\n"
f"Errors: {'; '.join(recall_errors) if recall_errors else 'None'}\n\n"
f"{consolidated_info}\n"
)
# Write the compiled manifest to file
manifest_filename = "devbrain_manifest.md"
try:
with open(manifest_filename, "w", encoding="utf-8") as f:
f.write(manifest_content)
print(f"[Exporter] Successfully compiled and saved manifest to: {manifest_filename}")
except Exception as e:
print(f"[Exporter] Error writing to {manifest_filename}: {e}")
# Write a copy to dashboard/public/devbrain_context.md for dashboard export
try:
base_dir = os.path.dirname(os.path.abspath(__file__))
dashboard_pub_dir = os.path.join(base_dir, "dashboard", "public")
if os.path.exists(dashboard_pub_dir):
devbrain_context_path = os.path.join(dashboard_pub_dir, "devbrain_context.md")
with open(devbrain_context_path, "w", encoding="utf-8") as f:
f.write(manifest_content)
print(f"[Exporter] Successfully compiled and saved dashboard copy to: {devbrain_context_path}")
else:
alt_path = os.path.join("dashboard", "public", "devbrain_context.md")
alt_dir = os.path.dirname(alt_path)
if os.path.exists(alt_dir):
with open(alt_path, "w", encoding="utf-8") as f:
f.write(manifest_content)
print(f"[Exporter] Successfully compiled and saved dashboard copy to: {alt_path}")
except Exception as e:
print(f"[Exporter] Error writing dashboard public copy: {e}")
# Copy manifest content to the clipboard
if copy_to_clipboard(manifest_content):
print("[Exporter] Manifest copied directly to system clipboard.")
else:
print("[Exporter] Clipboard copy not supported on this platform.")
return manifest_content
if __name__ == "__main__":
try:
asyncio.run(export_context())
except KeyboardInterrupt:
print("\n[Exporter] Export execution interrupted.")