Skip to content

feat(memory): data migration tool — convert jcode JSON MemoryGraph to mempalace [phase-5] #356

@quangdang46

Description

@quangdang46

Problem

jcode stores memories as MemoryGraph in JSON files (~/.jcode/memory/global.json, ~/.jcode/memory/projects/<hash>.json). Each MemoryEntry has inline embeddings, tags, edges, clusters, and metadata. These must be migrated into mempalace's Drawer + KG format.

Scope

Files: New crates/jcode-mempalace-adapter/src/migrate.rs

  1. Migration function:

    pub async fn migrate_to_mempalace(
        jcode_memory_dir: &Path,    // ~/.jcode/memory/
        palace_path: &Path,          // target mempalace path
        dry_run: bool,
    ) -> anyhow::Result<MigrationReport>
  2. Migration steps (for each JSON file):

    a. Memories → Drawers: For each MemoryEntry in the graph:

    • Create Drawer with mapped DrawerKind, content, tags, trust, confidence, strength
    • Map created_at/updated_at timestamps
    • Preserve embedding in Drawer (via metadata or direct vector store insert)
    • Call MemoryProvider::add_drawer()

    b. Tags → KG entities + HasTag edges: For each TagEntry:

    • Create KG entity with name = tag name
    • For each memory with that tag, create HasTag triple

    c. Edges → KG triples with typed edge kinds: For each Edge:

    • RelatesTo { weight } → KG triple with MemoryEdgeKind::RelatesTo
    • Supersedes → MemoryEdgeKind::Supersedes
    • Contradicts → MemoryEdgeKind::Contradicts
    • DerivedFrom → MemoryEdgeKind::DerivedFrom
    • InCluster → MemoryEdgeKind::InCluster

    d. Clusters → KG clusters: For each ClusterEntry:

    • Create cluster with centroid, member_count
    • Create InCluster edges to members

    e. Legacy MemoryStore (v1) format: Also handle the old MemoryStore format (flat Vec) that gets auto-migrated to MemoryGraph.

  3. Safety:

    • Write .bak file before any changes
    • Dry-run mode: report counts without writing
    • Idempotent: running twice produces same result
  4. MigrationReport:

    pub struct MigrationReport {
        pub memories_migrated: usize,
        pub tags_migrated: usize,
        pub edges_migrated: usize,
        pub clusters_migrated: usize,
        pub errors: Vec<String>,
        pub duration: std::time::Duration,
    }
  5. CLI command: jcode memory migrate --to-mempalace [--dry-run] [--palace-path PATH]

Acceptance Criteria

  • A jcode MemoryGraph with N memories, M tags, E edges, C clusters is fully migrated
  • All data round-trips: memories, tags, edges, clusters, embeddings
  • Embeddings are preserved in mempalace vector store
  • .bak files created before migration
  • Dry-run mode reports accurate counts without modifying anything
  • Idempotent: second run is a no-op
  • Legacy v1 MemoryStore format also handled
  • CLI command works end-to-end

Dependencies

Reference

jcode MemoryGraph JSON: ~/.jcode/memory/global.json, ~/.jcode/memory/projects/<hash>.json
jcode MemoryGraph struct: crates/jcode-memory-types/src/graph.rs lines 231-256
jcode MemoryEntry: crates/jcode-memory-types/src/lib.rs lines 233-266
jcode legacy migration: crates/jcode-base/src/memory.rs lines 1529-1577

Metadata

Metadata

Assignees

No one assigned

    Labels

    mp-migrationjcode → mempalace memory migrationphase-5Migration Phase 5 (jcode adapter)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions