feat: add import-memories command for markdown chat exports#149
Open
danielaustralia1 wants to merge 1 commit intoMartian-Engineering:mainfrom
Open
feat: add import-memories command for markdown chat exports#149danielaustralia1 wants to merge 1 commit intoMartian-Engineering:mainfrom
danielaustralia1 wants to merge 1 commit intoMartian-Engineering:mainfrom
Conversation
Add a new `lcm-tui import-memories` CLI command that imports markdown conversation files from external AI chat exports (ChatGPT, Claude, etc.) into the LCM database as searchable conversations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Adds a new
lcm-tui import-memories <path>CLI command that bulk-imports markdown conversation files from external AI chat platforms (ChatGPT, Claude, OpenClaw, etc.) into the LCM database. This enables users to bring their historical AI conversations into LCM's memory system, making them searchable vialcm_grep, inspectable vialcm_describe, and expandable vialcm_expand_query.Motivation
Users accumulate valuable conversation history across multiple AI platforms. Currently, LCM only ingests conversations that happen within OpenClaw sessions. This feature bridges that gap by allowing users to import their existing chat exports — organized as markdown files in folders — directly into LCM's database where they become part of the agent's long-term memory.
What it does
New CLI command
Directory structure mapping
.mdfile → one conversation in the database--agent)Markdown turn parser
Supports 5 marker styles detected automatically per file:
#### You:/#### ChatGPT## User/## Assistant### Human/### Assistant**User:**/**Assistant:**Human:/Assistant:Role mapping: User/Human/You →
user, Assistant/AI/ChatGPT/Claude →assistant, System →systemFallback: Files without recognized markers are imported as a single
assistantmessage (useful for knowledge documents).Timestamp extraction (3-tier fallback)
<time>HTML tags — ChatGPT exports include<time datetime="2025-11-19T05:05:22.247Z">per message. These are parsed for per-message precision and stripped from content.2026-02-18 - Title.mdnaming. TheYYYY-MM-DDprefix is extracted as the conversation date, with messages spaced 1 minute apart.Additional features
---delimited frontmatter (title, source URL). This is stripped before parsing so it doesn't pollute message content.```) are ignored, preventing false splits.--forceflag deletes existing conversation data and re-imports from the source file.--compactflag runs the existing backfill compaction engine on each imported conversation to build the summary DAG immediately.CLI flags
Implementation details
Files changed
tui/import-memories.gotui/import_memories_test.gotui/main.goArchitecture
The implementation reuses the existing backfill infrastructure:
applyBackfillImport()— conversation creation, message insertion, FTS indexing, message part creationinspectBackfillImportPlan()— deduplication checksrunBackfillCompaction()— optional post-import summary DAG constructionbackfillMessagestruct — message representationbackfillSessionInputstruct — import input packagingNew code is limited to:
.mdfile discovery<time>tags and filenames--forcere-importDatabase integration
Imported conversations use the same schema as native backfill:
conversationstable withsession_id = "import:<sha256-hash>"for deterministic dedupmessages+context_items+message_partstables for full message storagemessages_ftsfor full-text search indexingTest plan
44 tests covering:
Parser tests (20)
#### You:/#### ChatGPTand**Human:**/**Assistant:**seqnumberingTimestamp tests (7)
<time datetime="...">tag extraction with nanosecond precision<time>tag stripped from message contentYYYY-MM-DD - Title.md)<time>tags → uses filename dateextractTimeTag()with valid, missing, and malformed tagsextractFilenameDate()with dated and undated filenamesFrontmatter & encoding tests (5)
#### You:markers +<time>tagsInfrastructure tests (12)
memorySessionIDdeterminism and prefixderiveAgentName: nested folders, root-level files, deep nestingdiscoverMarkdownFiles: finds .md, ignores .txt, case-insensitive extensionparseImportMemoriesArgs: valid path, --apply mode, missing path, non-directory, non-existentdeleteConversationData: clears all related tables (messages, context_items, message_parts, FTS)Tested against real data
Successfully dry-run tested against 824 real markdown files (7,120 messages) across multiple folders:
<time>tags and YAML frontmatterYYYY-MM-DDfilename dates🤖 Generated with Claude Code