-
Notifications
You must be signed in to change notification settings - Fork 149
Description
Feature Description
Add optional automatic file formatting using external formatters (like Prettier) when Basic Memory writes files. Includes a standalone basic-memory format command for batch formatting existing files.
Problem This Feature Solves
Basic Memory writes .md, .canvas, and .json files without formatting, leading to:
- Inconsistent file styling across projects
- Noisy version control diffs when users manually format files
- Extra manual steps for users who want formatted output
- No standardized formatting for teams without external tooling
Proposed Solution
Auto-Format on Save
Add configuration options to automatically format files after MCP tools write them:
{
"format_on_save": true,
"formatter_command": "prettier --write {file}",
"formatters": {
"md": "prettier --write {file}",
"json": "prettier --write {file}"
},
"formatter_timeout": 5.0
}Environment variables:
BASIC_MEMORY_FORMAT_ON_SAVE=trueBASIC_MEMORY_FORMATTER_COMMAND="prettier --write {file}"BASIC_MEMORY_FORMATTERS='{"md": "prettier --write {file}"}'
Integration points (where formatting hooks in):
write_noteMCP tooledit_noteMCP toolcanvasMCP tool
Standalone Format Command
# Format all files in current/default project
basic-memory format
# Format files in specific project
basic-memory format --project my-research
# Format specific file or directory
basic-memory format notes/meeting.mdKey Design Decisions
- Disabled by default (opt-in)
- Formatter errors warn but don't fail the write
- Async subprocess execution with configurable timeout
- Re-reads file after formatting to compute correct checksum
- Per-extension formatters with global fallback
Trade-offs
Formatting adds a subprocess call per file write, which has minor performance overhead and requires external tools (like prettier) to be installed. However, the token efficiency impact is likely negligible or even positive - consistent formatting produces predictable patterns that may be easier for LLMs to parse than inconsistently formatted content.
Alternative Solutions
- Claude Code hooks - Users can set up post-tool hooks to run prettier, but this only works in Claude Code, not other MCP clients
- Pre-commit hooks - Requires separate tooling setup and doesn't format on save
- Editor integration - Requires users to open files in an editor with format-on-save
Additional Context
- PRD with full technical details:
.taskmaster/docs/prd.md - Feature branch:
feature/auto-format-on-save - Uses existing
BasicMemoryConfigPydantic model withenv_prefix="BASIC_MEMORY_"
Impact
- Developers: Consistent formatting without manual intervention
- Teams: Standardized output across all team members
- Obsidian users: Properly formatted canvas JSON files
- Version control: Cleaner diffs with consistent styling