Skip to content

feat: integrate mempalace for long-term memory - #27

Merged
dylanneve1 merged 19 commits into
mainfrom
feat/mempalace
Apr 10, 2026
Merged

dylanneve1 merged 19 commits into
mainfrom
feat/mempalace

Conversation

@dylanneve1

Copy link
Copy Markdown
Collaborator

Summary

  • Integrates mempalace as a built-in plugin, giving the agent structured long-term memory via ChromaDB vector search + SQLite knowledge graph
  • New mempalace config section in Talon config (enabled/disabled, python path, palace path)
  • Plugin auto-validates Python venv + mempalace installation on boot, creates palace directory if needed
  • Dream mode Stage 5 updated: mines curated daily notes (not raw logs) into palace, plus writes a personal diary entry after each dream run
  • Full test coverage for plugin lifecycle and config validation

Changes

  • src/plugins/mempalace/index.ts — MCP server plugin (spawns python -m mempalace.mcp_server)
  • src/core/plugin.ts — Extended plugin system to support MCP stdio servers
  • src/bootstrap.ts — Loads mempalace plugin when enabled, passes config to dream
  • src/core/dream.ts — Dream Stage 5 mines memory/daily/ instead of logs/, adds diary writing
  • prompts/dream.md — Updated stage title
  • src/util/config.ts — Added mempalace config schema
  • src/util/paths.ts — Added mempalace-related paths
  • src/__tests__/mempalace-plugin.test.ts — Plugin-specific tests
  • src/__tests__/plugin.test.ts — Extended plugin system tests

Test plan

  • Verify mempalace.enabled: true in config loads the plugin and tools appear in agent sessions
  • Verify mempalace.enabled: false (or omitted) skips plugin entirely
  • Verify dream mode mines daily notes into daily-notes wing (not raw logs)
  • Verify diary writing works during dream runs
  • Run full test suite (npm test)

🤖 Generated with Claude Code

dylanneve1 and others added 2 commits April 9, 2026 21:52
Adds mempalace (Python MCP server) as a first-class memory system.
When enabled, the agent gets semantic search, knowledge graph, and
verbatim memory storage via ChromaDB — all local, zero API calls.

Key changes:
- Extend plugin system with `mcpServer` field for non-Node MCP servers
- Add `registerPlugin()` for built-in plugin registration
- Create mempalace plugin (factory pattern, validates python venv)
- Wire mempalace into dream mode (Stage 5: mine logs into palace)
- Add `mempalace` config schema (enabled, palacePath, pythonPath)
- Add default paths for palace dir and python venv binary

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dream Stage 5 now mines memory/daily/ (curated observations) instead of
raw logs/ directory, eliminating junk chunks (tool JSON, df output, etc).
Added personal diary writing instruction — agent reflects on feelings,
state of mind, learnings, and loose threads after each dream run.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates the MemPalace Python MCP server as an optional built-in plugin to provide structured long-term memory (vector search + KG), and updates dream mode to mine curated daily notes and produce a diary entry.

Changes:

  • Added MemPalace built-in plugin (Python MCP server) plus config + paths wiring.
  • Extended plugin system to support custom MCP server commands/args and direct built-in registration.
  • Updated dream prompt/template + dream agent interpolation for MemPalace mining/diary stage, with accompanying tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/util/paths.ts Adds MemPalace palace dir and default venv python path resolution.
src/util/config.ts Adds mempalace config schema (enabled + optional python/palace paths).
src/plugins/mempalace/index.ts Implements built-in MemPalace plugin with MCP server config, boot validation, and prompt addition.
src/core/plugin.ts Adds mcpServer support (command/args), built-in registerPlugin, and MCP server entry generation.
src/core/dream.ts Injects optional MemPalace mining + diary-writing instructions into dream prompt.
src/bootstrap.ts Loads/registers MemPalace when enabled and passes resolved paths to dream mode.
src/tests/plugin.test.ts Adds tests for mcpServer behavior and built-in registerPlugin.
src/tests/mempalace-plugin.test.ts Adds lifecycle/config tests for the MemPalace plugin.
prompts/dream.md Adds Stage 5 placeholder section for MemPalace mining/diary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/plugin.ts Resolved
Comment thread src/core/dream.ts Resolved
Comment thread src/core/dream.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/util/paths.ts Resolved
Comment thread src/bootstrap.ts Resolved
- plugin.ts: validate mcpServer.args entries are strings and reject empty command
- dream.ts: quote interpolated paths in shell commands, replace mcp_server CLI diary with direct file write
- mempalace/index.ts: platform-agnostic error message for missing python binary
- paths.ts: update comment to reflect platform-dependent venv path
- bootstrap.ts: wrap mempalace init in 30s timeout to match loadSinglePlugin behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot suggested removing the mcp_server CLI invocation for diary
writing but that's the intended mempalace interface. Restored it
with quoted paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bootstrap.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/core/plugin.ts Resolved
Comment thread src/core/dream.ts Resolved
Comment thread prompts/dream.md Resolved
Comment thread src/core/plugin.ts Resolved
dylanneve1 and others added 3 commits April 10, 2026 09:04
- plugin.ts: test rejection of empty mcpServer.command and non-string args elements
- dream.ts: test mempalace section gating — verify mining/diary instructions
  only appear when mempalace is configured, skip message when not
- 1306 tests passing (4 new)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adapted from mempalace SKILL.md (v3.1.0). Key improvements:
- Session protocol (verify before responding, invalidate stale facts)
- Full tool documentation including kg_timeline, traverse, find_tunnels,
  diary_read/write, delete_drawer, graph_stats, check_duplicate
- Semantic search tips (meaning-based, not keyword)
- Knowledge graph temporal validity guidance
- Tests updated to verify all tool names appear in prompt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move system prompt instructions out of TypeScript into a .md file,
matching the pattern used by dream.md and other prompts. Plugin loads
and interpolates {{palacePath}} at runtime with graceful fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Lockfile had resolved URLs pointing to pixi.intel.com (private/corporate
registry) for @Anthropic-AI packages, causing CI to fail with ENOTFOUND.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/util/config.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/__tests__/mempalace-plugin.test.ts Resolved
Comment thread src/core/plugin.ts Resolved
dylanneve1 and others added 2 commits April 10, 2026 09:25
Remove unused imports, variables, and catch bindings across 14 files.
Add yield statements to generator function mocks. Fix prettier formatting.

0 lint warnings, 0 format issues, 1307 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Validate mcpServer.args elements are strings and reject empty command (#1)
- Shell-quote interpolated paths in dream bash commands (#2, #11)
- Replace CLI-based diary write with mempalace_diary_write MCP tool (#3)
- Make validation error message platform-agnostic (#4)
- Update mempalacePython comment for platform-dependent default (#5)
- Wrap mp.init() in Promise.race with 30s timeout (#6)
- Make init conditional on successful validation, pass actual config (#7)
- Move import mempalace check into validateConfig (#8)
- Replace execFileSync with async execFile in init() (#9)
- Document that registerPlugin does NOT call init (#10)
- Update dream prompt header from "4-stage" to "5-stage" (#12)
- Update getPluginMcpServers JSDoc to document mcpServer path (#13, #17)
- Add .min(1) to palacePath/pythonPath zod schemas (#14)
- Distinguish ENOENT/EACCES/EPERM from import failures in validation (#15)
- Fix test name from "logs warning" to match actual behavior (#16)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dylanneve1
dylanneve1 requested a review from Copilot April 10, 2026 09:35
TypeScript type check was failing because 'mempalace' wasn't in the
LogComponent union type used by log/logError/logWarn functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/util/log.ts Resolved
Comment thread prompts/dream.md Resolved
Update tool access statement to permit MCP tools for mempalace
mining stage instead of blanket-blocking all MCP tools.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/plugin.ts Resolved
Comment thread prompts/dream.md Resolved
- registerPlugin now checks for duplicates before setting env vars
  or logging success, preventing misleading logs and env clobbering
- Dream agent now receives mempalace MCP servers when configured,
  so Stage 5 diary/mining tools actually work

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/frontend/telegram/handlers.ts:701

  • ProcessAndReplyParams still includes config, but processAndReply no longer uses it. If it’s no longer needed, removing it from the param type/queue entries will reduce coupling and avoid confusion about which config values affect reply processing.
async function processAndReply(params: ProcessAndReplyParams): Promise<void> {
  const {
    bot,
    chatId,
    numericChatId,
    replyToId,
    messageId,
    prompt,
    senderName,
    isGroup,
    senderUsername,
    senderId,
    chatTitle,
  } = params;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/dream.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/core/dream.ts Resolved
dylanneve1 and others added 2 commits April 10, 2026 10:00
getPluginMcpServers now accepts an optional plugin name filter:
- omitted = all plugins (backwards compatible for chat sessions)
- [] = none
- ["mempalace"] = only mempalace

Dream mode uses ["mempalace"] to load only what it needs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Mempalace prompt now loads from ~/.talon/prompts/mempalace.md
  (user-customisable, seeded on first run) instead of relative to
  source file. Consistent with heartbeat/dream prompt loading.
- Dream systemPrompt now permits MemPalace MCP tools when configured,
  preventing conflict with the markdown prompt's Stage 5 instructions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bootstrap.ts Resolved
Comment thread src/core/plugin.ts Resolved
…istration

- registerPlugin checks for duplicates before running validateConfig,
  avoiding expensive re-validation on accidental double registration
- Dream mempalace integration now gated on getPlugin("mempalace")
  instead of just config.mempalace.enabled, so failed validation
  or registration doesn't cause dream-time MCP tool failures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The --palace flag is a global option that must come before the
subcommand. Wrong order caused the init health check to always
fail with exit 2, logging a misleading "not yet initialized" warning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
Comment thread src/frontend/telegram/handlers.ts Resolved
…sed param

- Validate `import mempalace.mcp_server` (actual spawned module) instead of
  just `import mempalace` in validateConfig
- Add timeout/killed error branching in validateConfig catch block
  (ETIMEDOUT, signal, killed) with specific messages instead of generic
  "not installed"
- Include stderr details in import failure messages for debugging
- Remove unused `config` from ProcessAndReplyParams and all processAndReply
  call sites (flushQueue, retry, callback handler)
- Replace `mempalace status` CLI smoke test in init() with a simple import
  check — fixes false "Palace not yet initialized" warning when palace IS
  initialized but CLI subcommand doesn't exist

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/frontend/telegram/handlers.ts Resolved
Comment thread src/plugins/mempalace/index.ts Resolved
- Remove config from queue entry type, enqueueMessage signature, and
  all 3 call sites — completes the cleanup started in round 8
- Eliminates unnecessary TalonConfig reference (including botToken) from
  queue state
- Update mempalace plugin header comment to document platform-dependent
  pythonPath default (bin/python on Unix, Scripts/python.exe on Windows)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/frontend/telegram/handlers.ts Resolved
Comment thread src/core/plugin.ts Resolved
@dylanneve1
dylanneve1 merged commit d68a3f2 into main Apr 10, 2026
14 checks passed
@dylanneve1
dylanneve1 deleted the feat/mempalace branch April 10, 2026 10:50
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.

2 participants