-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsolidate.py
More file actions
200 lines (165 loc) · 8.16 KB
/
consolidate.py
File metadata and controls
200 lines (165 loc) · 8.16 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
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
"""
================================================================================
THE WEAVE - CODE CONSOLIDATION SCRIPT FOR PERPLEXITY PRO AI CONTEXT
================================================================================
PURPOSE:
This script generates consolidated context files for use with Perplexity Pro AI
assistance in developing The Weave, a Sega Mega Drive game using SGDK.
WHAT IT DOES:
1. Extracts your complete project code (The Weave) using Gitingest
2. Downloads only the essential SGDK API reference (headers + docs) from GitHub
3. Generates AI instruction templates optimized for Perplexity Pro Spaces
OUTPUT FILES:
- weave-code-YYYY-MM-DD.txt: Your complete game project source code
- sgdk-reference-YYYY-MM-DD.txt: SGDK API headers and documentation (~500KB)
- ai-instructions-YYYY-MM-DD.txt: Configuration guide for your AI Space
HOW TO USE THE RESULTS IN PERPLEXITY PRO:
1. Go to your Perplexity Pro Space "Megadrive Programming"
2. Click on Space Settings
3. Upload the three generated files from the 'consolidated/' folder
4. Copy the contents of 'ai-instructions-YYYY-MM-DD.txt' and paste it into
the "AI Indication" field in your Space settings
5. Save the Space configuration
RESULT:
From now on, every query in that Space will have automatic access to:
- Your complete codebase context
- SGDK complete API reference with all functions, structs, and documentation
- Optimized instructions for code review, refactoring, and architecture guidance
MAINTENANCE:
Run this script whenever you:
- Make significant code changes to The Weave
- Need to update to a newer SGDK version
- Want to refresh the AI context
REQUIREMENTS:
pip install gitingest
EXECUTION:
python consolidate.py
================================================================================
"""
import os
import datetime
# === REQUIRED: pip install gitingest ===
from gitingest import ingest
# === CONFIGURATION ===
PROJECT_LOCAL = '.' # Path to your project (use '.' if running from repo root)
SGDK_REPO_BASE = 'https://github.com/Stephane-D/SGDK/tree/master'
OUT_DIR = 'consolidated'
os.makedirs(OUT_DIR, exist_ok=True)
# === BUILD DATE ===
build_date = datetime.datetime.now().strftime('%Y-%m-%d')
# === 1. Consolidate local project code using Gitingest ===
def consolidate_local_code(project_path, output_name):
"""Extract project code using gitingest library"""
print(f"Extracting local project from {project_path}...")
try:
_, _, content = ingest(project_path)
with open(os.path.join(OUT_DIR, output_name), 'w', encoding='utf-8') as fout:
fout.write(f'// The Weave consolidated project - Build date: {build_date}\n')
fout.write(f'// Generated by Gitingest\n\n')
fout.write(content)
print(f"✓ Successfully generated {output_name}")
except Exception as e:
print(f"✗ Error consolidating local code: {e}")
# === 2. Consolidate SGDK API reference (headers + documentation only) ===
def consolidate_sgdk_reference(output_name):
"""Extract only essential SGDK API reference to keep file size manageable"""
print(f"Extracting SGDK API reference (headers + docs)...")
# Essential SGDK paths to download
sgdk_paths = [
f"{SGDK_REPO_BASE}/inc", # All API headers with Doxygen comments
f"{SGDK_REPO_BASE}/readme.md", # Main documentation
f"{SGDK_REPO_BASE}/changelog.txt", # Version history
]
consolidated_content = []
consolidated_content.append(f'// SGDK API Reference - Build date: {build_date}\n')
consolidated_content.append(f'// Source: https://github.com/Stephane-D/SGDK\n')
consolidated_content.append(f'// This includes: headers (inc/), readme.md, changelog.txt\n')
consolidated_content.append(f'// Contains all API functions, structs, and Doxygen documentation\n\n')
for path in sgdk_paths:
try:
print(f" Downloading {path}...")
_, _, content = ingest(path)
consolidated_content.append(f'\n\n{"="*80}\n')
consolidated_content.append(f'SOURCE: {path}\n')
consolidated_content.append(f'{"="*80}\n\n')
consolidated_content.append(content)
except Exception as e:
print(f" ⚠ Warning: Could not download {path}: {e}")
# Write consolidated file
with open(os.path.join(OUT_DIR, output_name), 'w', encoding='utf-8') as fout:
fout.write(''.join(consolidated_content))
print(f"✓ Successfully generated {output_name}")
# === 3. Generate AI instructions for Perplexity Pro Space ===
def write_instructions(output_name, code_file, sgdk_file):
"""Generate optimized instructions for AI to use the consolidated files"""
with open(os.path.join(OUT_DIR, output_name), 'w', encoding='utf-8') as fout:
fout.write(f'''
You are an expert in C and SGDK applied to retro development for Mega Drive.
Reference files attached to this Space:
- {code_file}: Complete consolidated source code of The Weave project
- {sgdk_file}: SGDK API reference including:
* All header files (inc/) with complete Doxygen documentation
* API functions, structs, enums, and macros
* readme.md with usage guidelines
* changelog.txt with version history
How to use these files:
1. When asked about SGDK API usage, reference {sgdk_file} for function signatures, parameters, and documentation
2. Use {code_file} as the primary source for understanding The Weave architecture and implementation
3. Cross-reference both files to provide contextual analysis and suggestions
Instructions for responses:
1. Always consult the attachments as the authoritative source
2. Use the most recent version by date (YYYY-MM-DD in filename)
3. When suggesting improvements or refactoring, reference specific SGDK patterns and best practices
4. Present answers in clear, structured blocks with code examples
5. Prioritize SGDK/Mega Drive compatibility and hardware constraints (64KB RAM, 64KB VRAM, etc.)
6. Suggest improvements that align with demonstrated patterns in SGDK headers
7. If functionality is unclear from attachments, explicitly ask for clarification before assuming behavior
8. For architecture questions, consider both files to ensure compatibility
Response format preferences:
- Use code blocks with proper syntax highlighting
- Break down complex explanations into sections
- Provide practical examples from the codebase when applicable
- Mention performance implications for Mega Drive hardware
- Reference specific files and line numbers when relevant
Versioning model:
- weave-code-YYYY-MM-DD.txt (regenerate after major code changes)
- sgdk-reference-YYYY-MM-DD.txt (regenerate when SGDK version updates)
- ai-instructions-YYYY-MM-DD.txt (this file)
Update these files regularly to maintain accurate context.
''')
# === Main execution ===
def main():
print("\n" + "="*80)
print("THE WEAVE - CODE CONSOLIDATION SCRIPT")
print("="*80)
print(f"Build date: {build_date}")
print(f"Output directory: {OUT_DIR}/\n")
code_out = f'weave-code-{build_date}.txt'
sgdk_out = f'sgdk-reference-{build_date}.txt'
instr_out = f'ai-instructions-{build_date}.txt'
# Generate all consolidated files
print("Step 1/3: Consolidating The Weave project code...")
consolidate_local_code(PROJECT_LOCAL, code_out)
print("\nStep 2/3: Consolidating SGDK API reference...")
consolidate_sgdk_reference(sgdk_out)
print("\nStep 3/3: Generating AI instructions...")
write_instructions(instr_out, code_out, sgdk_out)
print("\n" + "="*80)
print("CONSOLIDATION COMPLETE!")
print("="*80)
print(f"\nGenerated files in '{OUT_DIR}/' folder:")
print(f" 1. {code_out}")
print(f" 2. {sgdk_out}")
print(f" 3. {instr_out}")
print("\n" + "="*80)
print("NEXT STEPS:")
print("="*80)
print("1. Go to your Perplexity Pro Space: 'Programación para Megadrive'")
print("2. Click on Space Settings")
print(f"3. Upload all three files from '{OUT_DIR}/' folder")
print(f"4. Open '{instr_out}' and copy its contents")
print("5. Paste the contents into 'AI Indication' field in Space settings")
print("6. Save and start using your AI with full project context!")
print("="*80 + "\n")
if __name__ == "__main__":
main()