-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodessa_quickstart.py
More file actions
273 lines (218 loc) Β· 8.97 KB
/
codessa_quickstart.py
File metadata and controls
273 lines (218 loc) Β· 8.97 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
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
#!/usr/bin/env python3
"""
Codessa Quick Start Script
==========================
Interactive setup wizard for Codessa Intelligence Integration
Run this first to validate your configuration before using the sync daemon.
"""
import os
import sys
from pathlib import Path
from typing import Optional, Dict
try:
from notion_client import Client as NotionClient
from github import Github
from dotenv import load_dotenv
except ImportError:
print("β Missing dependencies. Please run:")
print(" pip install notion-client PyGithub python-dotenv")
sys.exit(1)
# ANSI color codes for pretty output
class Color:
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BLUE = '\033[94m'
BOLD = '\033[1m'
END = '\033[0m'
def print_header(text: str):
print(f"\n{Color.BOLD}{Color.BLUE}{'='*60}{Color.END}")
print(f"{Color.BOLD}{Color.BLUE}{text.center(60)}{Color.END}")
print(f"{Color.BOLD}{Color.BLUE}{'='*60}{Color.END}\n")
def print_success(text: str):
print(f"{Color.GREEN}β{Color.END} {text}")
def print_error(text: str):
print(f"{Color.RED}β{Color.END} {text}")
def print_warning(text: str):
print(f"{Color.YELLOW}β {Color.END} {text}")
def print_info(text: str):
print(f"{Color.BLUE}βΉ{Color.END} {text}")
def get_input(prompt: str, default: Optional[str] = None) -> str:
"""Get user input with optional default value."""
if default:
user_input = input(f"{prompt} [{default}]: ").strip()
return user_input if user_input else default
return input(f"{prompt}: ").strip()
def test_notion_connection(token: str) -> tuple[bool, Optional[str]]:
"""Test Notion API connection."""
try:
notion = NotionClient(auth=token)
# Try to list users as a simple connection test
notion.users.list()
return True, None
except Exception as e:
return False, str(e)
def test_notion_database(notion: NotionClient, db_id: str, db_name: str) -> bool:
"""Test access to a specific Notion database."""
try:
notion.databases.retrieve(database_id=db_id)
print_success(f"{db_name} database accessible")
return True
except Exception as e:
print_error(f"{db_name} database: {e}")
print_info(f" Make sure the database is shared with your integration")
return False
def test_github_connection(token: str) -> tuple[bool, Optional[str]]:
"""Test GitHub API connection."""
try:
gh = Github(token)
user = gh.get_user()
return True, user.login
except Exception as e:
return False, str(e)
def create_env_file(config: Dict[str, str]):
"""Create .env file with provided configuration."""
env_path = Path(".env")
if env_path.exists():
backup = input("\n.env file already exists. Backup and overwrite? (y/N): ")
if backup.lower() == 'y':
env_path.rename(".env.backup")
print_success("Existing .env backed up to .env.backup")
else:
print_info("Keeping existing .env file")
return
with open(env_path, 'w') as f:
f.write("# Codessa Intelligence Integration Configuration\n")
f.write("# Generated by codessa_quickstart.py\n\n")
f.write("# Notion Configuration\n")
f.write(f"NOTION_TOKEN={config['notion_token']}\n")
f.write(f"NOTION_INTELLIGENCE_DB={config['intelligence_db']}\n")
f.write(f"NOTION_CODESTONES_DB={config['codestones_db']}\n")
f.write(f"NOTION_REFLECTIONS_DB={config['reflections_db']}\n")
f.write(f"NOTION_EXECUTION_DB={config['execution_db']}\n\n")
f.write("# GitHub Configuration\n")
f.write(f"GITHUB_TOKEN={config['github_token']}\n")
f.write(f"GITHUB_OWNER={config['github_owner']}\n\n")
f.write("# Export Files Location\n")
f.write(f"EXPORTS_PATH={config['exports_path']}\n")
print_success(".env file created successfully")
def create_directory_structure():
"""Create necessary directories."""
dirs = ['exports', 'exports/chatgpt', 'exports/claude', 'exports/grok']
for dir_path in dirs:
Path(dir_path).mkdir(parents=True, exist_ok=True)
print_success("Directory structure created")
def main():
print_header("π Codessa Intelligence Integration Setup")
print("This wizard will help you set up your Codessa system.")
print("You'll need:")
print(" β’ Notion integration token")
print(" β’ 4 Notion database IDs")
print(" β’ GitHub personal access token")
print("\nLet's begin!\n")
config = {}
# =========================
# NOTION CONFIGURATION
# =========================
print_header("π Notion Configuration")
print("First, create a Notion integration:")
print(" 1. Visit https://www.notion.so/my-integrations")
print(" 2. Click 'New integration'")
print(" 3. Name it 'Codessa Sync'")
print(" 4. Copy the Internal Integration Token\n")
notion_token = get_input("Notion Integration Token")
print("\nTesting Notion connection...")
success, error = test_notion_connection(notion_token)
if not success:
print_error(f"Connection failed: {error}")
print_info("Please check your token and try again")
sys.exit(1)
print_success("Notion connection successful!")
config['notion_token'] = notion_token
notion = NotionClient(auth=notion_token)
# Database IDs
print("\n" + "β" * 60)
print("\nNow, you need to create 4 databases in Notion:")
print(" 1. Intelligence_Streams")
print(" 2. Codestones")
print(" 3. Reflections")
print(" 4. Execution_Queue")
print("\nFor each database:")
print(" β’ Open it as a full page")
print(" β’ Copy the ID from URL: notion.so/[workspace]/[THIS-IS-THE-ID]")
print(" β’ Share it with your 'Codessa Sync' integration\n")
db_configs = [
('intelligence_db', 'Intelligence_Streams'),
('codestones_db', 'Codestones'),
('reflections_db', 'Reflections'),
('execution_db', 'Execution_Queue')
]
all_dbs_valid = True
for key, name in db_configs:
db_id = get_input(f"{name} database ID")
config[key] = db_id
if not test_notion_database(notion, db_id, name):
all_dbs_valid = False
if not all_dbs_valid:
print_warning("\nSome databases couldn't be accessed.")
print_info("Make sure each database is shared with your integration:")
print_info(" Database β β― β Add connections β Codessa Sync")
continue_anyway = input("\nContinue anyway? (y/N): ")
if continue_anyway.lower() != 'y':
sys.exit(1)
# =========================
# GITHUB CONFIGURATION
# =========================
print_header("π§ GitHub Configuration")
print("Create a GitHub personal access token:")
print(" 1. Visit https://github.com/settings/tokens")
print(" 2. Generate new token (classic)")
print(" 3. Select scopes: repo, issues, pull_requests")
print(" 4. Copy the token\n")
github_token = get_input("GitHub Personal Access Token")
print("\nTesting GitHub connection...")
success, username = test_github_connection(github_token)
if not success:
print_error(f"Connection failed: {username}")
sys.exit(1)
print_success(f"GitHub connection successful! Logged in as: {username}")
config['github_token'] = github_token
config['github_owner'] = username
# =========================
# EXPORTS CONFIGURATION
# =========================
print_header("π Exports Configuration")
default_path = str(Path.cwd() / "exports")
exports_path = get_input("Path for conversation exports", default_path)
config['exports_path'] = exports_path
# =========================
# FINALIZE
# =========================
print_header("β¨ Finalizing Setup")
print("\nConfiguration summary:")
print(f" Notion: Connected")
print(f" GitHub: {config['github_owner']}")
print(f" Exports: {config['exports_path']}")
print(f" Databases: {len(db_configs)} configured")
print("\nCreating .env file...")
create_env_file(config)
print("\nCreating directory structure...")
create_directory_structure()
print_header("π Setup Complete!")
print("Next steps:")
print(" 1. Export a ChatGPT conversation as JSON")
print(f" 2. Place it in: {config['exports_path']}/")
print(" 3. Run: python codessa_sync_daemon.py")
print(" 4. Check your Notion databases for new entries!")
print("\n" + "β" * 60)
print("\n⨠Your Codessa system is ready.")
print(" 'Reflection completes the loop.'\n")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\nSetup cancelled.")
sys.exit(0)
except Exception as e:
print_error(f"\nUnexpected error: {e}")
sys.exit(1)