Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xK3vin MegaMemory Merge CLI

From Leeroopedia
Knowledge Sources
Domains CLI, Merge_Conflict_Resolution
Last Updated 2026-10-27 12:00 GMT

Overview

Concrete CLI commands for merging knowledge graphs and manually resolving merge conflicts provided by the MegaMemory library.

Description

The Merge CLI (src/merge-cli.ts) implements three terminal commands: runMerge, runConflicts, and runResolve. These are the manual complement to the AI-assisted MCP merge tools. runMerge invokes MergeEngine.merge and prints a summary. runConflicts lists unresolved conflicts in human or JSON format. runResolve resolves a conflict by keeping left, right, or both — distinct from the MCP resolveConflict path, which writes agent-verified content.

Key behaviors:

  • runMerge defaults to overwriting file1 via a temp file + rename for safety
  • runConflicts --json emits the same ListConflictsOutput structure as the MCP tool
  • runResolve --keep both renames each side to originalId-branch as separate concepts; --keep left|right deletes the loser, renames the winner to the clean ID, and clears merge flags

Usage

Import these handlers when you need to:

  • Merge from the shell: megamemory merge main.db feature.db --into merged.db
  • List conflicts: megamemory conflicts --db merged.db --json
  • Resolve manually: megamemory resolve <merge_group> --keep left|right|both

Code Reference

Source Location

  • Repository: 0xK3vin_MegaMemory
  • File: src/merge-cli.ts
  • Key functions:
    • runMerge: L45-108
    • runConflicts: L112-200
    • runResolve: L204-288
    • getDefaultDbPath: L292-296

Signature

export async function runMerge(args: string[]): Promise<void>;
// Usage: megamemory merge <file1> <file2> [--into <output>] [--left-label <name>] [--right-label <name>]

export async function runConflicts(args: string[]): Promise<void>;
// Usage: megamemory conflicts [--db <path>] [--json]

export async function runResolve(args: string[]): Promise<void>;
// Usage: megamemory resolve <merge_group> --keep <left|right|both> [--db <path>]

Import

import { runMerge, runConflicts, runResolve } from "./merge-cli.js";

I/O Contract

Inputs

Name Type Required Description
file1, file2 string (positional) Yes (merge) Paths to the two DBs to merge
--into string (flag) No (merge) Output DB path; defaults to overwriting file1
--left-label string (flag) No (merge) Label for left side; default "left"
--right-label string (flag) No (merge) Label for right side; default "right"
--db string (flag) No (conflicts/resolve) DB path; default cwd/.megamemory/knowledge.db or MEGAMEMORY_DB_PATH
--json flag No (conflicts) Emit JSON instead of human-readable output
merge_group string (positional) Yes (resolve) Conflict group UUID
--keep "right" | "both" Yes (resolve) Which version(s) to keep

Outputs

Name Type Description
runMerge() void (console) Prints Merged: N clean, N conflicts or 0 conflicts
runConflicts() void (console) Human: grouped conflict listing; JSON: { conflicts: [...] }
runResolve() void (console) Resolved "id" — kept left version. or Kept both versions...

Usage Examples

Merge Two DBs

# Merge feature branch DB into main, writing to merged.db
megamemory merge main.db feature.db --into merged.db --left-label main --right-label feature
# => Merged: 42 clean, 3 conflicts (2 concepts, 1 edge)

# Default: overwrite file1 (safe temp file + rename)
megamemory merge main.db feature.db

List Conflicts

# Human-readable
megamemory conflicts --db merged.db
# 3 unresolved conflicts:
#   ── merge-engine [a1b2c3d4...]
#      main: Two-pass graph merge with conflict tracking
#      feature: Two-pass merge with edge remapping
# Resolve with: megamemory resolve <group> --keep <left|right|both>

# Machine-readable JSON
megamemory conflicts --db merged.db --json

Resolve Manually

# Keep the left (main) version
megamemory resolve a1b2c3d4-... --keep left --db merged.db
# => Resolved "merge-engine" — kept main version.

# Keep both as separate concepts
megamemory resolve a1b2c3d4-... --keep both --db merged.db
# => Kept both versions of "merge-engine" as separate concepts.

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment