fix: prevent JSON event leaking to users and reload skills after AI creation

- OpenCode runtime: stop calling _collect_text fallback on non-text events (step_start, step_finish, etc.)
- Both runtimes: guard raw stdout fallback to only apply for non-JSON output
- main.py: reload skills after AI responses containing skill-related keywords
- main.py: return friendly message instead of empty string for tool-only responses
This commit is contained in:
2026-02-18 23:40:15 -05:00
parent 34dea65a07
commit 4e31e77286
3 changed files with 93 additions and 16 deletions

17
main.py
View File

@@ -299,6 +299,18 @@ def ai_handler(msg: IncomingMessage) -> str:
# Parse and execute action tags (reminders, cron, spawn)
reply_text = _process_action_tags(response.text, msg)
# If the AI may have created/modified skills (via file tools), reload them
# so that `skill list` reflects the changes immediately.
if _skills and any(
kw in text_lower
for kw in ("skill", "create a skill", "new skill", "add a skill", "make a skill")
):
try:
_skills.reload()
logger.info("Skills reloaded after potential skill modification")
except Exception as e:
logger.debug(f"Skills reload after AI response failed: {e}")
# Log conversation to memory session log
if _memory:
try:
@@ -311,6 +323,11 @@ def ai_handler(msg: IncomingMessage) -> str:
except Exception as e:
logger.debug(f"Session logging failed: {e}")
# Guard against empty responses (e.g. when AI did tool-only work
# and the parser correctly stripped all non-text events)
if not reply_text or not reply_text.strip():
return "✅ Done — I processed that but had no text to show."
return reply_text