feat: add Gemini CLI / AI Studio session import support#204
Conversation
PR Review: feat: add Gemini CLI / AI Studio session import supportExecutive Summary
Affected Areas: Business Impact: Users importing Gemini CLI sessions via Flow Changes: New Ratings
PR Health
High Priority Issues(Must fix before merge) 🐛 #1: Parser precedence bug —
|
web3guru888
left a comment
There was a problem hiding this comment.
✨ Review of #204 — feat: add Gemini CLI / AI Studio session import support
Scope: +150/−1 · 2 file(s)
mempalace/normalize.py(modified: +68/−1)tests/test_normalize.py(modified: +82/−0)
Strengths
- ✅ Includes test coverage
🟢 Approved — clean, well-structured PR. Good work @FBISiri!
🏛️ Reviewed by MemPalace-AGI · Autonomous research system with perfect memory · Showcase: Truth Palace of Atlantis
|
Hi, thanks for the contribution. This PR has merge conflicts with Could you rebase onto If this change is no longer relevant, feel free to close the PR. (This message is part of a periodic backlog pass, sent to all open PRs that match this state.) |
Adds _try_gemini_json parser to normalize.py for three layouts:
1. Gemini API contents format (~/.gemini/sessions/*.json):
{"contents": [{"role": "user", "parts": [{"text": "..."}]}, ...]}
2. Messages-wrapper variant:
{"messages": [{"role": "user", ...}, {"role": "model", ...}]}
3. Flat top-level list with role="model".
This complements the existing _try_gemini_jsonl parser (which handles
~/.gemini/tmp/<hash>/chats/session-*.jsonl with session_metadata
sentinel) — JSONL covers Gemini CLI runtime sessions, JSON covers
exported / Studio-saved transcripts.
## Review feedback addressed (PR MemPalace#204)
bgauryy review:
- MemPalace#1 Parser-precedence bug: _try_gemini_json runs *before*
_try_claude_ai_json so the {"messages":[..., role=model, ...]}
layout is no longer silently claimed by the Claude parser. The
Gemini parser's has_model_role guard prevents false-positives
against Claude / ChatGPT data.
- MemPalace#2 Layout 2a coverage: TestGeminiJson.test_messages_wrapper_format
+ test_messages_wrapper_does_not_get_claimed_by_claude pin the
fix in place.
- MemPalace#3 Test conflicts with current main: rebased onto develop;
tests restructured into TestGeminiJson class.
- MemPalace#4 tempfile/os.unlink → pytest tmp_path everywhere.
- MemPalace#5 elif not text → else (the elif branch was dead).
- MemPalace#6 Module docstring updated to mention Google AI Studio.
Tests: 9 new cases in TestGeminiJson covering all three layouts,
multi-part text joining, non-text part skipping, has_model_role
disambiguation, dispatch-chain regression for review MemPalace#1.
1ed408a to
a9a2c35
Compare
|
@bgauryy thanks for the thorough review — all six points addressed in the rebase ( High priority
Medium priority
Low priority
@igorls heads up — rebased and force-pushed onto current |
What does this PR do?
Adds Gemini CLI and Google AI Studio session import support to
normalize.py.MemPalace already has a Gemini CLI integration guide, but
normalize.pycouldn't parse Gemini session files. This PR fills that gap.Supported formats
1. Gemini API
contentsformat — used by Gemini CLI session files (~/.gemini/sessions/*.json):{"contents": [{"role": "user", "parts": [{"text": "..."}]}, ...]}2. Flat messages list with
role: "model"(Gemini convention):[{"role": "user", "content": "..."}, {"role": "model", "content": "..."}]Design decisions
role: "model"entry to match. This prevents false positives against Claude/ChatGPT formats that userole: "assistant". Placed after ChatGPT parser and before Slack in the detection chain.inline_data,function_call, etc. are gracefully skipped (onlytextparts are extracted).How to test
6 new test cases:
test_gemini_contents_format— standard Gemini CLI sessiontest_gemini_flat_messages_format— simplified exporttest_gemini_multi_part_text— multiple text blocks in one turntest_gemini_skips_non_text_parts— images/functions ignoredtest_gemini_single_message_returns_none— edge caseChecklist
python -m pytest tests/ -v)_try_claude_ai_json,_try_chatgpt_json)