feat: add auto-format files on save#467
Closed
divideby0 wants to merge 6 commits intobasicmachines-co:mainfrom
Closed
feat: add auto-format files on save#467divideby0 wants to merge 6 commits intobasicmachines-co:mainfrom
divideby0 wants to merge 6 commits intobasicmachines-co:mainfrom
Conversation
Add tests to verify CLI commands (tool, status) exit cleanly without hanging. The tests reproduce a bug where CLI commands hang indefinitely after displaying output. The root cause is that ensure_initialization() creates database connections via asyncio.run() that are not cleaned up before the event loop closes. These tests will fail until the fix is applied. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Cedric Hurst <cedric@spantree.net>
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.
Configuration options:
- format_on_save: Enable/disable auto-formatting (default: false)
- formatter_command: Global formatter command (e.g., "prettier --write {file}")
- formatters: Per-extension formatters (e.g., {"md": "prettier --write {file}"})
- formatter_timeout: Max seconds to wait for formatter (default: 5.0)
Integration points:
- FileService.write_file() and update_frontmatter()
- MarkdownProcessor.write_file()
- All import commands
Closes basicmachines-co#466
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Cedric Hurst <cedric@spantree.net>
Users can now just set format_on_save=true and formatting will work out of the box (assuming Node.js is installed). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Cedric Hurst <cedric@spantree.net>
Contributor
Author
|
Updated to default Now users can simply set |
phernandez
added a commit
that referenced
this pull request
Dec 24, 2025
Add optional automatic file formatting using mdformat (pure Python, no Node.js required): - Add `format_on_save` config option to enable automatic formatting - Use built-in mdformat for markdown files by default (no external dependencies) - Support GFM tables and YAML frontmatter via mdformat plugins - Allow external formatters via `formatter_command` config (e.g., Prettier) - Add per-extension formatter config via `formatters` dict - Add `basic-memory format` CLI command for batch formatting - Use FileService.is_markdown() for cloud compatibility (S3FileService) Based on PR #467 by Cedric Hurst (@divideby0) - refactored to use Python-based mdformat instead of requiring Node.js/Prettier. Closes #466 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Cedric Hurst <cedric@divideby0.io> Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
7 tasks
Member
|
Thank you for this contribution, @divideby0! 🙏 We've incorporated your work into #474 with some modifications:
Your original implementation for the CLI command, config options, and integration points was excellent and is preserved. We've credited you as a co-author in the commit. Closing this PR in favor of #474. Thanks again for the great feature idea and implementation! |
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
basic-memory formatCLI command for batch formatting existing filesformat_on_save,formatter_command,formatters,formatter_timeoutTest plan
format_file()function (11 tests)Closes #466
🤖 Generated with Claude Code