-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypercode.py
More file actions
143 lines (121 loc) · 4.58 KB
/
hypercode.py
File metadata and controls
143 lines (121 loc) · 4.58 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
import sys
import os
import requests
import json
API_URL = "http://localhost:8000/api/v1/tasks/"
def get_token():
"""Retrieves the auth token from token.txt."""
token_path = "token.txt"
if not os.path.exists(token_path):
return None
with open(token_path, "r") as f:
return f.read().strip()
def translate_file(filepath):
"""Reads a local file and sends it to the Translator Agent."""
if not os.path.exists(filepath):
print(f"❌ Bro, I can't find that file: {filepath}")
return
print(f"👁️ Scanning {filepath}...")
with open(filepath, "r", encoding="utf-8") as f:
code_content = f.read()
token = get_token()
if not token:
print("❌ Missing auth token! Please run seed_data.py or ensure token.txt exists.")
return
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
print("📡 Beaming code to the Cognitive Swarm...")
# Corrected payload to match TaskCreate schema
payload = {
"title": f"CLI Translation: {os.path.basename(filepath)}",
"description": code_content,
"priority": "high",
"type": "translate",
"project_id": 1 # Defaulting to project 1
}
try:
response = requests.post(API_URL, json=payload, headers=headers)
if response.status_code == 200:
task_data = response.json()
task_id = task_data.get("id", "UNKNOWN")
print(f"✅ BOOM! Task {task_id} queued.")
print(f"👀 Keep an eye on the docs/outputs folder for the magic!")
else:
print(f"⚠️ Something tripped up: {response.status_code} - {response.text}")
except Exception as e:
print(f"🛑 Backend offline? Is Docker running, mate? Error: {e}")
def check_pulse():
print("🏥 Pinging the Pulse Agent (The Medic)...")
token = get_token()
if not token:
print("❌ Missing auth token! Please run seed_data.py or ensure token.txt exists.")
return
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
payload = {
"title": "System Health Check",
"description": "Check swarm vitals",
"priority": "high",
"type": "health", # Routes to PulseAgent!
"project_id": 1
}
try:
response = requests.post(API_URL, json=payload, headers=headers)
if response.status_code == 200:
task_id = response.json().get("id", "UNKNOWN")
print(f"✅ Pulse check queued! Task ID: {task_id}")
print(f"👀 Check docs/outputs/translation_{task_id}.md for the diagnosis!")
else:
print(f"⚠️ Tripped up: {response.text}")
except Exception as e:
print(f"🛑 Backend offline? Error: {e}")
def research_topic(topic):
print(f"📚 Waking up The Archivist to research: '{topic}'...")
token = get_token()
if not token:
print("❌ Missing auth token! Please run seed_data.py or ensure token.txt exists.")
return
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
payload = {
"title": f"Research: {topic}",
"description": topic,
"priority": "normal",
"type": "research", # Routes to the Research Agent!
"project_id": 1
}
try:
response = requests.post(API_URL, json=payload, headers=headers)
if response.status_code == 200:
task_id = response.json().get("id", "UNKNOWN")
print(f"✅ Research queued! Task ID: {task_id}")
print(f"👀 Go grab a coffee. The brief will drop in docs/outputs soon!")
else:
print(f"⚠️ Tripped up: {response.status_code} - {response.text}")
except Exception as e:
print(f"🛑 Backend offline? Error: {e}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("🚀 HYPERCODE CLI v1.2")
print("👉 Usage:")
print(" python hypercode.py translate <file.py>")
print(" python hypercode.py pulse")
print(" python hypercode.py research \"Your wild topic here\"")
sys.exit(1)
command = sys.argv[1]
if command == "translate" and len(sys.argv) == 3:
translate_file(sys.argv[2])
elif command == "pulse":
check_pulse()
elif command == "research" and len(sys.argv) >= 3:
# Join all arguments after "research" into a single string
topic = " ".join(sys.argv[2:])
research_topic(topic)
else:
print("❌ Invalid command, bro.")