Skip to content

feat(memory): add jcode-mempalace-adapter type-conversion layer (#355)#364

Merged
quangdang46 merged 8 commits into
masterfrom
feat/mp-issues-355-359
Jun 5, 2026
Merged

feat(memory): add jcode-mempalace-adapter type-conversion layer (#355)#364
quangdang46 merged 8 commits into
masterfrom
feat/mp-issues-355-359

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

Creates a new crate jcode-mempalace-adapter with bidirectional conversions between jcode's MemoryEntry and mempalace's Drawer types.

Design

Zero dependency on mempalace-core — avoids the libsqlite3-sys version conflict (mempalace uses rusqlite 0.32, jcode uses 0.33 via casr). Instead defines local mirror types (Drawer, DrawerKind, DrawerId, MemoryScope) that match mempalace's public surface exactly.

Conversions

jcode type mempalace type
MemoryCategory DrawerKind (1:1 including Entity, Correction, Custom)
MemoryEntry Drawer (all fields: timestamps, confidence, trust, tags, embeddings, reinforcements)
MemoryScope MemoryScope (Project→Local, Global→Global, All→All)
TrustLevel String

Tests

6 unit tests pass: round-trip content, category↔kind mapping, kind→category mapping, scope round-trip, drawer defaults, half-life parity with jcode.

Issues covered

Next steps

  1. Align rusqlite versions (update mempalace to 0.33 OR pin jcode to 0.32)
  2. Add backend feature to pull in mempalace-core, expose MempalaceAdapter runtime struct
  3. Wire MemoryTool with memory_backend config
  4. Wire prompt injection to bypass MemoryAgent when mempalace backend
  5. Data migration tool for ~/.jcode/memory/*.json

See README for full details.

quangdang46 and others added 8 commits June 4, 2026 08:28
Creates a new crate  with bidirectional
conversions between jcode's MemoryEntry and mempalace's Drawer types.

Key design decision: the crate has ZERO dependency on mempalace-core
to avoid the libsqlite3-sys version conflict (mempalace uses rusqlite
0.32, jcode uses 0.33 via casr).  Instead it defines local mirror
types (Drawer, DrawerKind, DrawerId, MemoryScope) that match
mempalace's public surface exactly.

Conversions provided:
  - MemoryCategory ↔ DrawerKind (1:1 including Entity, Correction, Custom)
  - MemoryEntry ↔ Drawer (all fields, including #25 timestamps, #26
    confidence/strength, tags, trust, reinforcements, embedding)
  - MemoryScope ↔ MemoryScope (Project→Local, Global→Global, All→All)
  - TrustLevel ↔ String

6 unit tests cover: round-trip content, category mapping, kind mapping,
scope mapping, drawer defaults, half-life parity.

Issues covered:
  - #355: Type-conversion layer complete
  - #359: Unit tests + README (part 1)
  - #356-#358 deferred (need Palace runtime = rusqlite alignment)
…ntegration

Issue #356: Data migration tool
- New crates/jcode-mempalace-adapter/src/migrate.rs
- Reads jcode MemoryGraph JSON files (global + per-project)
- Converts MemoryEntry → mempalace Drawer via mirror_drawer_to_real()
- Creates HasTag edges via MemoryProvider::tag()
- Creates RelatesTo/Supersedes edges via link()/supersede()
- Handles legacy MemoryStore (v1 flat Vec) format
- Backup (.bak) files before changes
- Dry-run mode reports counts without writing
- MigrationReport struct with counts + errors + duration

Issue #357: MemoryTool config-gated dispatch
- Added MemoryBackend enum to jcode-config-types (native|mempalace)
- Added memory_backend field to AgentsConfig
- Added 'mempalace-backend' feature to jcode-app-core
- MemoryTool dispatches to MempalaceAdapter when backend=mempalace
- Same 8 actions (remember/recall/search/list/forget/tag/link/related)
- MempalaceAdapter wraps Palace with typed action methods

Issue #358: Mempalace prompt injection pipeline
- In prompting.rs: checks JCODE_MEMORY_BACKEND env var
- When mempalace, spawns mempalace_per_turn_pipeline() per turn
- Pipeline: embed context → search Palace → surface into PENDING_MEMORY
- Writes to same PENDING_MEMORY static so take_pending_memory() unchanged
- Falls back to native MemoryAgent when not configured
- format_context_for_relevance made pub for cross-crate access

Infrastructure:
- mempalace-core added as optional dep to adapter (default-features=false)
- 'backend' feature in adapter gates Palace runtime + migrate + adapter
- mirror_drawer_to_real() converts mirror Drawer → real mempalace Drawer
- Re-exports key mempalace-core types from adapter crate
- rusqlite 0.33 aligned between mempalace and jcode (no conflict)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cargo fix --lib auto-removed 3 unused imports flagged by CI:
- memory.rs: unused  import
- memory.rs: unused  and  imports
- mod.rs: unused  import
- jcode-base/live_tests.rs: collapse nested if (collapsible_if)
- jcode-app-core/tool/mod.rs: restore Mutex import (cargo fix was too aggressive)
- jcode-app-core/tool/memory.rs: remove unused imports
- jcode-tui/helpers.rs, inline_interactive.rs: remove needless borrows on provider_slug
- src/cli/tui_launch.rs: remove needless borrows on provider_slug

All pre-existing clippy errors fixed. CI should now pass.
The Mutex import was only needed when feature 'dcp' is enabled
(the DcpPlugin field is cfg-gated). Make the import conditional
to eliminate the unused-import warning in default builds.
The path dep '../../../mempalace_rust/crates/core' doesn't exist on
CI runners. Switch to git dep pointing at the feat/mp-issues-25-35
branch. This fixes the 'cargo metadata --all-features' failure that
broke all CI jobs.

Also update README to reflect the resolved rusqlite alignment.
# Conflicts:
#	Cargo.toml
#	crates/jcode-app-core/src/tool/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant