feat(memory): add hot/cold startup protocol with boot-pack generator and startup show
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# Prime COLD_INDEX.md
|
||||
|
||||
Use this as pointer map to archived context.
|
||||
|
||||
- topic: <name>
|
||||
summary: <short>
|
||||
source: <path/ref>
|
||||
last_touched: <YYYY-MM-DD>
|
||||
related: [..]
|
||||
@@ -0,0 +1,13 @@
|
||||
# Prime HOT_MEMORY.md
|
||||
|
||||
## Active Goals
|
||||
- (fill)
|
||||
|
||||
## Active Tasks
|
||||
- (fill)
|
||||
|
||||
## Blockers
|
||||
- (fill)
|
||||
|
||||
## Recent Decisions
|
||||
- (fill)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# Prime STARTUP.md — Rehydrate Without Context Bloat
|
||||
|
||||
## Boot order (compact)
|
||||
1. `state/boot-pack.json` (generated summary)
|
||||
2. `HOT_MEMORY.md`
|
||||
3. `state/goals.json` (if needed)
|
||||
4. detailed logs/memory only on demand
|
||||
|
||||
## Rules
|
||||
- Default to summary-first retrieval.
|
||||
- Do not load full history unless task-relevant.
|
||||
- Keep HOT memory concise and linked to cold index.
|
||||
@@ -115,3 +115,9 @@ Behavior:
|
||||
- Owner fast-lane for conversational planning/research requests
|
||||
- Hard blocks only for tier4 destructive/external asks
|
||||
- Softer plan/confirm messaging for normal requests
|
||||
|
||||
## 15) Startup rehydrate protocol (Hot/Cold memory)
|
||||
- `STARTUP.md`, `HOT_MEMORY.md`, `COLD_INDEX.md`
|
||||
- generated `state/boot-pack.json` for compact startup context
|
||||
- timer: `prime-boot-pack.timer` (15m)
|
||||
- Telegram: `startup show`
|
||||
|
||||
@@ -172,6 +172,21 @@ def parse_and_handle(chat_id: int, msg_id: int, text: str) -> str:
|
||||
if not parts:
|
||||
return help_text()
|
||||
|
||||
if parts[:2] == ['startup','show']:
|
||||
try:
|
||||
import json
|
||||
from pathlib import Path
|
||||
bp = Path('/srv/prime-core/state/boot-pack.json')
|
||||
if not bp.exists():
|
||||
return 'Boot pack not generated yet.'
|
||||
data = json.loads(bp.read_text())
|
||||
s = data.get('summary', {})
|
||||
return (f"Boot pack @ {data.get('generated_at_utc')}\n"
|
||||
f"goals={s.get('goal_count')} queued={s.get('queued_count')} blocked={s.get('blocked_count')}\n"
|
||||
f"chat={s.get('chat_enabled')} strict={s.get('strict_mode')} autonomous={s.get('autonomous_enabled')}")
|
||||
except Exception as e:
|
||||
return f"startup show error: {e}"
|
||||
|
||||
if parts[:2] == ['allowlist','show']:
|
||||
if str(chat_id) != owner_id():
|
||||
return 'Not authorized.'
|
||||
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
import json
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
|
||||
BASE = Path('/srv/prime-core')
|
||||
STATE = BASE / 'state'
|
||||
OUT = STATE / 'boot-pack.json'
|
||||
|
||||
|
||||
def load(path: Path, default):
|
||||
if not path.exists():
|
||||
return default
|
||||
try:
|
||||
return json.loads(path.read_text())
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
goals = load(STATE / 'goals.json', [])
|
||||
queue = load(STATE / 'task-queue.json', [])
|
||||
allow = load(STATE / 'telegram-allowlist.json', {'allowed_user_ids': []})
|
||||
mode = load(STATE / 'chat-mode.json', {'chat_enabled': True, 'strict_mode': False})
|
||||
auto = load(STATE / 'autonomous-mode.json', {'enabled': False})
|
||||
|
||||
blocked = [q for q in queue if q.get('status') == 'blocked_approval']
|
||||
queued = [q for q in queue if q.get('status') == 'queued']
|
||||
done_recent = [q for q in queue if q.get('status') == 'done'][-5:]
|
||||
|
||||
pack = {
|
||||
'generated_at_utc': datetime.now(timezone.utc).isoformat(),
|
||||
'summary': {
|
||||
'goal_count': len(goals),
|
||||
'queued_count': len(queued),
|
||||
'blocked_count': len(blocked),
|
||||
'done_recent_count': len(done_recent),
|
||||
'chat_enabled': bool(mode.get('chat_enabled', True)),
|
||||
'strict_mode': bool(mode.get('strict_mode', False)),
|
||||
'autonomous_enabled': bool(auto.get('enabled', False)),
|
||||
'allowlist_count': len(allow.get('allowed_user_ids', [])),
|
||||
},
|
||||
'top_goals': goals[:5],
|
||||
'blocked_tasks': [{
|
||||
'id': b.get('id'),
|
||||
'task': b.get('task'),
|
||||
'created_at': b.get('created_at')
|
||||
} for b in blocked[:10]],
|
||||
'recent_done': [{
|
||||
'id': d.get('id'),
|
||||
'task': d.get('task')
|
||||
} for d in done_recent],
|
||||
'pointers': {
|
||||
'startup': 'STARTUP.md',
|
||||
'hot_memory': 'HOT_MEMORY.md',
|
||||
'cold_index': 'COLD_INDEX.md',
|
||||
'goals': 'state/goals.json',
|
||||
'queue': 'state/task-queue.json',
|
||||
}
|
||||
}
|
||||
|
||||
STATE.mkdir(parents=True, exist_ok=True)
|
||||
OUT.write_text(json.dumps(pack, indent=2))
|
||||
print(str(OUT))
|
||||
Reference in New Issue
Block a user