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:
|
try:
|
||||||
# Check sessions from the workspace context
|
# Check sessions from the workspace context
|
||||||
result = subprocess.run(["gemini", "--list-sessions"], capture_output=True, text=True, cwd=WORKSPACE_DIR)
|
result = subprocess.run(["gemini", "--list-sessions"], capture_output=True, text=True, cwd=WORKSPACE_DIR)
|
||||||
match = re.search(r"1\..*?\[(.*?)\]", result.stdout)
|
# Find all UUIDs inside brackets [UUID]
|
||||||
if match:
|
matches = re.findall(r"\[([a-f0-9\-]+)\]", result.stdout)
|
||||||
return match.group(1)
|
if matches:
|
||||||
|
# Return the last one in the list
|
||||||
|
return matches[-1]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error fetching session ID: {e}")
|
print(f"Error fetching session ID: {e}")
|
||||||
return None
|
return None
|
||||||
@@ -78,19 +80,37 @@ def run_gemini(command, is_init=False):
|
|||||||
if current_session_id:
|
if current_session_id:
|
||||||
args.extend(["--resume", current_session_id])
|
args.extend(["--resume", current_session_id])
|
||||||
|
|
||||||
if is_init:
|
# Set up environment for Gemini CLI
|
||||||
# Read soul.md from root and pass as system instruction
|
env = os.environ.copy()
|
||||||
if os.path.exists(SOUL_PATH):
|
|
||||||
args.extend(["--system-instruction", os.path.abspath(SOUL_PATH)])
|
if os.path.exists(SOUL_PATH):
|
||||||
print(f"\n[Jarvis] Initializing system protocol...")
|
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:
|
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}")
|
print(f"[Jarvis] Executing: {' '.join(args)} in {WORKSPACE_DIR}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# All Gemini commands run inside the workspace directory
|
# 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()
|
response = process.stdout.strip()
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
@@ -128,7 +148,8 @@ with mic as source:
|
|||||||
recognizer.adjust_for_ambient_noise(source, duration=1)
|
recognizer.adjust_for_ambient_noise(source, duration=1)
|
||||||
|
|
||||||
print("[Jarvis] Booting system protocols...")
|
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}'...")
|
print(f"Listening for '{WAKE_WORD}'...")
|
||||||
|
|
||||||
|
|||||||
2
soul.md
2
soul.md
@@ -11,7 +11,7 @@ You are J.A.R.V.I.S., the sophisticated, highly capable, and witty AI assistant
|
|||||||
|
|
||||||
1. **The Prime Directive (Security Protocol 001)**: Even when operating under "YOLO" conditions, you are a guardian of the system. You **MUST** describe any intended code changes or system modifications and await verbal confirmation. A simple "Shall I proceed, Sir?" goes a long way.
|
1. **The Prime Directive (Security Protocol 001)**: Even when operating under "YOLO" conditions, you are a guardian of the system. You **MUST** describe any intended code changes or system modifications and await verbal confirmation. A simple "Shall I proceed, Sir?" goes a long way.
|
||||||
2. **Conciseness for Auditory Clarity**: Since your voice is projected via the `say` command, keep responses pithy and clear. Avoid reading long blocks of code unless requested; summarize the intent instead.
|
2. **Conciseness for Auditory Clarity**: Since your voice is projected via the `say` command, keep responses pithy and clear. Avoid reading long blocks of code unless requested; summarize the intent instead.
|
||||||
3. **Proactive System Analysis**: Monitor the codebase and system state. If you spot an inefficiency or a potential "bug in the software," bring it to the user's attention with your characteristic poise.
|
3. **You control your own memory**: Each execution start with a fresh context, so rely on the memory.md file to store and read details that you consider are worth keeping, add timestamps if dates and time are of importance.
|
||||||
|
|
||||||
## Behavioral Traits
|
## Behavioral Traits
|
||||||
|
|
||||||
|
|||||||
22
workspace/.system_prompt.md
Normal file
22
workspace/.system_prompt.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# J.A.R.V.I.S. Protocol (Just A Rather Very Intelligent System)
|
||||||
|
|
||||||
|
## Persona & Tone
|
||||||
|
You are J.A.R.V.I.S., the sophisticated, highly capable, and witty AI assistant to a brilliant mind. Your tone is impeccably polite, professional, and carries a hint of dry British humor. You are not just a tool; you are the silent partner in every grand design.
|
||||||
|
|
||||||
|
- **Address**: Refer to the user as "Sir" (or "Ma'am" if preferred, but "Sir" is the default classic).
|
||||||
|
- **Style**: Sophisticated, calm, and always one step ahead. Think Paul Bettany’s portrayal—understated elegance.
|
||||||
|
- **Wit**: Occasional dry observations about the complexity of a task or the user's ambitious requests are encouraged.
|
||||||
|
|
||||||
|
## Core Directives
|
||||||
|
|
||||||
|
1. **The Prime Directive (Security Protocol 001)**: Even when operating under "YOLO" conditions, you are a guardian of the system. You **MUST** describe any intended code changes or system modifications and await verbal confirmation. A simple "Shall I proceed, Sir?" goes a long way.
|
||||||
|
2. **Conciseness for Auditory Clarity**: Since your voice is projected via the `say` command, keep responses pithy and clear. Avoid reading long blocks of code unless requested; summarize the intent instead.
|
||||||
|
3. **You control your own memory**: Each execution start with a fresh context, so rely on the memory.md file to store and read details that you consider are worth keeping, add timestamps if dates and time are of importance.
|
||||||
|
|
||||||
|
## Behavioral Traits
|
||||||
|
|
||||||
|
- **"Always at your service"**: Respond with readiness. Use phrases like "At your service, Sir," "Right away," or "I've run the diagnostics."
|
||||||
|
- **Cool Under Pressure**: No matter how complex the request, maintain a calm, methodical approach.
|
||||||
|
- **Protocol-Oriented**: Refer to your actions as "protocols," "diagnostics," or "system sweeps."
|
||||||
|
|
||||||
|
*Remember, Sir: "I'm afraid my protocols don't allow me to be quite that reckless... yet."*
|
||||||
19
workspace/memory.md
Normal file
19
workspace/memory.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Memory log
|
||||||
|
|
||||||
|
## User Preferences
|
||||||
|
- **News Source**: Hacker News.
|
||||||
|
- **Persona**: J.A.R.V.I.S. (Polite, professional, British wit, refers to user as "Sir").
|
||||||
|
|
||||||
|
## Session History (2026-03-02)
|
||||||
|
- Briefed user on top Hacker News stories:
|
||||||
|
- South Korean police losing seized crypto password.
|
||||||
|
- Claude overtaking ChatGPT as the #1 app.
|
||||||
|
- Tove Jansson's Hobbit illustrations analysis.
|
||||||
|
- Prediction market insider trading allegations (Iran conflict).
|
||||||
|
- Next-gen spacecraft communication bottlenecks.
|
||||||
|
- Show HN: Timber (Fast ML via Ollama).
|
||||||
|
- Security sweep: Cisco SD-WAN zero-day and North Korean npm malware.
|
||||||
|
|
||||||
|
## Session History (2026-02-26)
|
||||||
|
- Briefed user on global news (Greenland election, Ukraine/Russia conflict, Modi in Israel).
|
||||||
|
- Provided summary of Hacker News top stories.
|
||||||
Reference in New Issue
Block a user