Skip to content

Conversation

@divideby0
Copy link
Contributor

Summary

  • Add optional automatic file formatting using external formatters (like Prettier) when Basic Memory writes files
  • Add standalone basic-memory format CLI command for batch formatting existing files
  • Add configuration options: format_on_save, formatter_command, formatters, formatter_timeout
  • Integrate formatting into all file write operations with correct checksum handling

Test plan

  • Unit tests for format_file() function (11 tests)
  • Config tests for formatting settings (12 tests)
  • Type checking passes
  • Linting passes
  • All 143 related tests pass

Closes #466

🤖 Generated with Claude Code

divideby0 and others added 2 commits December 19, 2025 15:42
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 <[email protected]>
Signed-off-by: Cedric Hurst <[email protected]>
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 <[email protected]>
Signed-off-by: Cedric Hurst <[email protected]>
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 <[email protected]>
Signed-off-by: Cedric Hurst <[email protected]>
@divideby0
Copy link
Contributor Author

Updated to default formatter_command to npx prettier --write {file}.

Now users can simply set format_on_save=true in their config and formatting will work out of the box (assuming Node.js is installed). If prettier isn't available, it fails gracefully with a warning log.

@CLAassistant
Copy link

CLAassistant commented Dec 22, 2025

CLA assistant check
All committers have signed the CLA.

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 <[email protected]>
Co-Authored-By: Claude <[email protected]>
Signed-off-by: phernandez <[email protected]>
@phernandez
Copy link
Member

Thank you for this contribution, @divideby0! 🙏

We've incorporated your work into #474 with some modifications:

  • Changed the default formatter from Prettier (Node.js) to mdformat (pure Python)
  • This removes the Node.js dependency, making Basic Memory work out-of-the-box without requiring users to install Node
  • Users who prefer Prettier can still configure it via formatter_command

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!

@phernandez phernandez closed this Dec 24, 2025
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.

[FEATURE] Auto-Format on Save

4 participants