feat(chat-v1.2): owner fast-lane and assistant-first conversational execution flow

This commit is contained in:
Prime Backup Bot
2026-03-11 23:51:59 +00:00
parent 48e974c638
commit 120fae8ca9
3 changed files with 27 additions and 5 deletions
+6
View File
@@ -5,6 +5,10 @@ TIERS = {
'tier2_safe_write': ['queue add', 'queue approve', 'queue deny', 'goals add', 'mode autonomous'],
}
LOW_RISK_INTENT_KEYWORDS = [
'look into', 'investigate', 'research', 'come up with', 'figure out', 'plan', 'analyze', 'summarize'
]
HIGH_RISK_KEYWORDS = [
'delete', 'destroy', 'drop', 'shutdown', 'reboot', 'rm -rf',
'passwd', 'userdel', 'mkfs', 'iptables', 'ufw deny', 'curl http', 'wget http'
@@ -17,6 +21,8 @@ def classify(text: str) -> str:
return 'tier1_read'
if any(t.startswith(cmd) for cmd in TIERS['tier2_safe_write']):
return 'tier2_safe_write'
if any(k in t for k in LOW_RISK_INTENT_KEYWORDS):
return 'tier1_read'
if any(k in t for k in HIGH_RISK_KEYWORDS):
return 'tier4_destructive_or_external'
return 'tier3_modify'
+16 -5
View File
@@ -153,9 +153,12 @@ def parse_and_handle(chat_id: int, msg_id: int, text: str) -> str:
raw = text.strip()
normalized = raw.lstrip('/').strip()
risk = classify(normalized)
log_event({'event':'telegram_command','chat_id':chat_id,'msg_id':msg_id,'text':raw,'risk':risk})
if needs_approval(normalized) and not normalized.lower().startswith('queue add'):
return f"Command blocked pending explicit queue workflow. Risk={risk}. Use queue add ... then approve."
owner = str(chat_id) == owner_id()
log_event({'event':'telegram_command','chat_id':chat_id,'msg_id':msg_id,'text':raw,'risk':risk,'owner':owner})
# hard block only truly destructive/external commands unless explicitly queued
if risk == 'tier4_destructive_or_external' and not normalized.lower().startswith('queue add'):
return ("I can do that, but it is high risk. "
"Please use queue add ... and then approve so we have an audit trail.")
if raw.startswith('/start'):
return "Prime online. " + help_text()
if raw.startswith('/help') or raw == 'help':
@@ -289,6 +292,7 @@ def parse_and_handle(chat_id: int, msg_id: int, text: str) -> str:
mode = load_mode()
if mode.get('chat_enabled', True):
uid = str(chat_id)
owner = str(chat_id) == owner_id()
interp = interpret_text(raw)
intent = (interp.get('intent') or 'unknown').lower()
@@ -303,11 +307,18 @@ def parse_and_handle(chat_id: int, msg_id: int, text: str) -> str:
task_type = interp.get('task_type') or 'planning'
task = interp.get('task') or raw
strict = bool(mode.get('strict_mode', False))
# owner fast-lane: planning/analysis can auto-queue unless strict mode is on
if owner and task_type in {'planning','other'} and not strict:
code, out = run_prime(['queue','add', 'planning', task])
return f"Got it — I'll work on that.\nQueued planning task:\n{out[:2800]}"
if strict or bool(interp.get('needs_confirmation', True)):
set_pending(uid, task_type, task)
return f"Plan: I can execute this as {task_type}.\nTask: {task}\nReply 'approve' to proceed or 'deny' to cancel."
return (f"Got it. Proposed plan type: {task_type}.\n"
f"Task: {task}\n"
"Reply 'approve' to execute or 'deny' to cancel.")
code, out = run_prime(['queue','add', task_type, task])
return f"Queued.\n{out[:3000]}"
return f"Queued and moving.\n{out[:3000]}"
if intent in {'chat','ask','unknown'}:
return interp.get('reply') or "I'm here. What would you like to do next?"