feat: enhance temporal context and self-managed memory protocols
This commit is contained in:
43
jarvis.py
43
jarvis.py
@@ -39,9 +39,11 @@ def get_latest_session_id():
|
||||
try:
|
||||
# Check sessions from the workspace context
|
||||
result = subprocess.run(["gemini", "--list-sessions"], capture_output=True, text=True, cwd=WORKSPACE_DIR)
|
||||
match = re.search(r"1\..*?\[(.*?)\]", result.stdout)
|
||||
if match:
|
||||
return match.group(1)
|
||||
# Find all UUIDs inside brackets [UUID]
|
||||
matches = re.findall(r"\[([a-f0-9\-]+)\]", result.stdout)
|
||||
if matches:
|
||||
# Return the last one in the list
|
||||
return matches[-1]
|
||||
except Exception as e:
|
||||
print(f"Error fetching session ID: {e}")
|
||||
return None
|
||||
@@ -78,19 +80,37 @@ def run_gemini(command, is_init=False):
|
||||
if current_session_id:
|
||||
args.extend(["--resume", current_session_id])
|
||||
|
||||
if is_init:
|
||||
# Read soul.md from root and pass as system instruction
|
||||
if os.path.exists(SOUL_PATH):
|
||||
args.extend(["--system-instruction", os.path.abspath(SOUL_PATH)])
|
||||
print(f"\n[Jarvis] Initializing system protocol...")
|
||||
# Set up environment for Gemini CLI
|
||||
env = os.environ.copy()
|
||||
|
||||
if os.path.exists(SOUL_PATH):
|
||||
with open(SOUL_PATH, 'r') as f:
|
||||
soul_content = f.read()
|
||||
|
||||
# Inject date/time context only on initialization
|
||||
if is_init:
|
||||
current_time = time.strftime("%A, %B %d, %Y, %I:%M %p")
|
||||
soul_content = f"Temporal Context: The current date and time is {current_time}.\n\n" + soul_content
|
||||
print(f"\n[Jarvis] Initializing system protocol with temporal context...")
|
||||
else:
|
||||
print(f"\n[Jarvis] Communicating with Gemini...")
|
||||
|
||||
# Use a temporary file for the system instruction
|
||||
system_md_path = os.path.abspath(os.path.join(WORKSPACE_DIR, ".system_prompt.md"))
|
||||
with open(system_md_path, 'w') as f:
|
||||
f.write(soul_content)
|
||||
env["GEMINI_SYSTEM_MD"] = system_md_path
|
||||
else:
|
||||
print(f"\n[Jarvis] Communicating with Gemini...")
|
||||
if is_init:
|
||||
print(f"\n[Jarvis] Initializing system protocol...")
|
||||
else:
|
||||
print(f"\n[Jarvis] Communicating with Gemini...")
|
||||
|
||||
print(f"[Jarvis] Executing: {' '.join(args)} in {WORKSPACE_DIR}")
|
||||
|
||||
try:
|
||||
# All Gemini commands run inside the workspace directory
|
||||
process = subprocess.run(args, capture_output=True, text=True, cwd=WORKSPACE_DIR)
|
||||
process = subprocess.run(args, capture_output=True, text=True, cwd=WORKSPACE_DIR, env=env)
|
||||
response = process.stdout.strip()
|
||||
|
||||
if response:
|
||||
@@ -128,7 +148,8 @@ with mic as source:
|
||||
recognizer.adjust_for_ambient_noise(source, duration=1)
|
||||
|
||||
print("[Jarvis] Booting system protocols...")
|
||||
run_gemini("System initialization complete. Awaiting orders, Sir.", is_init=True)
|
||||
current_time = time.strftime("%A, %B %d, %Y, %I:%M %p")
|
||||
run_gemini(f"System initialization complete. The current date and time is {current_time}. Awaiting orders, Sir.", is_init=True)
|
||||
|
||||
print(f"Listening for '{WAKE_WORD}'...")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user