feat(desktop): replace PNG persona export with JSON format - #144
Merged
Conversation
- Add encode_persona_json() and parse_json_persona() for the new .persona.json file format (version 1 schema) - Replace export_persona_to_png Tauri command with export_persona_to_json - Remove PNG encoding path: encode_persona_png, generate_placeholder_png, hsl_to_rgb, and chara card encoding - Keep PNG/chara import path for backwards compatibility with existing .persona.png files - Update ZIP parser to accept both .json and .png entries - Update parse_persona_files to detect and handle JSON input - Frontend: single 'Export' button (JSON only), remove PNG export UI - Update drag-and-drop import to accept .persona.json files - Add comprehensive tests for JSON round-trip, validation, and mixed ZIP archives - Update e2eBridge test harness for new command name
- Extract shared extract_sprout_fields() helper to deduplicate validation logic between parse_json_persona() and parse_sprout_payload() - Rename JSON_MAGIC ([u8; 1] array) to JSON_OPEN_BRACE (u8 scalar) for clarity and consistency with the frontend's JSON_FIRST_BYTE pattern
parse_json_persona() now reads the avatarUrl field from the JSON file and passes it through as avatar_data_url in the preview. This ensures base64 data-URI avatars and regular URL avatars survive the export/import round-trip. Adds tests for avatar round-trip with URL, data URI, and no-avatar cases.
Skip __MACOSX/._ entries during ZIP parsing instead of treating them as persona files and reporting confusing parse errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the PNG-based persona export/import format with a clean JSON format for better compatibility with other tools when sharing persona files.
Exported
.persona.jsonformat{ "version": 1, "displayName": "Researcher", "systemPrompt": "You are a research agent...", "avatarUrl": "https://example.com/avatar.png" }The
avatarUrlfield supports three scenarios:"https://example.com/avatar.png""data:image/png;base64,iVBORw0KGgo..."(inline image, round-trips through export → import)What changed
Export: Personas now export as
.persona.jsonfiles instead of.persona.png. Avatars (including base64 data URIs) are preserved in theavatarUrlfield.Import: Accepts
.persona.json,.persona.png(backwards compat), and.zip(containing either format). JSON import readsavatarUrland populates the avatar on the imported persona.Removed: PNG encoding pipeline (
encode_persona_png,generate_placeholder_png,hsl_to_rgb, chara card encoding). PNG decoding kept for backwards-compatible import of old.persona.pngfiles.Changes (9 files, +232/-249)
Rust backend:
persona_card.rs: Addedparse_json_persona()(withavatarUrlsupport),encode_persona_json(), extracted sharedextract_sprout_fields()helper, updated ZIP parser for.jsonentries, removed PNG encoding functionscommands/personas.rs: Replacedexport_persona_to_pngwithexport_persona_to_json, updatedparse_persona_filesfor JSON detectionlib.rs: Updated command registrationTypeScript frontend:
.persona.json,.persona.png, and.zipTesting
.persona.pngfiles still importable