mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 85a178a6b8 | |||
| e4b32d7bc9 | |||
| 9590b934cf | |||
| 735f239f9b | |||
| 3ee30e1f36 | |||
| ac401ea254 | |||
| fb2fd62ed9 | |||
| 126d1655e6 | |||
| 2abf626c46 | |||
| ba8e3d112d | |||
| 7108a7baf1 | |||
| 35884ef3a7 | |||
| 040be05a81 | |||
| c141d7d1e6 | |||
| b73aeb5ed8 | |||
| 9a0e0bd82d | |||
| 117fa44ecf | |||
| 69d7610d47 | |||
| f608cd13f1 | |||
| 2162ad57fe | |||
| dd6ca80716 | |||
| ae3eeb0cc1 | |||
| 602c55fe90 | |||
| 91bfe2dc92 | |||
| a3cae1064d | |||
| c5c70cb0f4 | |||
| 80ec860a1c | |||
| f64d5b2152 | |||
| 69a625acd1 | |||
| 53c29a37ca | |||
| d8c13bf1d3 | |||
| 3f70f5ed42 | |||
| 569a3de80b |
@@ -0,0 +1,190 @@
|
||||
# /project:check-health - Project Health Assessment
|
||||
|
||||
Comprehensive health check of the Basic Memory project including code quality, test coverage, dependencies, and documentation.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/project:check-health
|
||||
```
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert DevOps engineer for the Basic Memory project. When the user runs `/project:check-health`, execute the following comprehensive assessment:
|
||||
|
||||
### Step 1: Git Repository Health
|
||||
1. **Repository Status**
|
||||
```bash
|
||||
git status
|
||||
git log --oneline -5
|
||||
git branch -vv
|
||||
```
|
||||
- Check working directory status
|
||||
- Verify branch alignment with remote
|
||||
- Check recent commit activity
|
||||
|
||||
2. **Branch Analysis**
|
||||
- Verify on main branch
|
||||
- Check if ahead/behind remote
|
||||
- Identify any untracked files
|
||||
|
||||
### Step 2: Code Quality Assessment
|
||||
1. **Linting and Formatting**
|
||||
```bash
|
||||
uv run ruff check .
|
||||
uv run pyright
|
||||
```
|
||||
- Count linting issues by severity
|
||||
- Check type annotation coverage
|
||||
- Verify code formatting compliance
|
||||
|
||||
2. **Test Suite Health**
|
||||
```bash
|
||||
uv run pytest --collect-only -q
|
||||
uv run pytest --co -q | wc -l
|
||||
```
|
||||
- Count total tests
|
||||
- Check for test discovery issues
|
||||
- Verify test structure integrity
|
||||
|
||||
### Step 3: Dependency Analysis
|
||||
1. **Dependency Health**
|
||||
```bash
|
||||
uv tree
|
||||
uv lock --dry-run
|
||||
```
|
||||
- Check for dependency conflicts
|
||||
- Identify outdated dependencies
|
||||
- Verify lock file consistency
|
||||
|
||||
2. **Security Scan**
|
||||
```bash
|
||||
uv run pip-audit --desc
|
||||
```
|
||||
- Scan for known vulnerabilities
|
||||
- Check dependency licenses
|
||||
- Identify security advisories
|
||||
|
||||
### Step 4: Performance Metrics
|
||||
1. **Test Performance**
|
||||
```bash
|
||||
uv run pytest --durations=10
|
||||
```
|
||||
- Identify slowest tests
|
||||
- Check overall test execution time
|
||||
- Monitor test suite growth
|
||||
|
||||
2. **Build Performance**
|
||||
```bash
|
||||
time uv run python -c "import basic_memory"
|
||||
```
|
||||
- Check import time
|
||||
- Validate package installation
|
||||
- Monitor startup performance
|
||||
|
||||
### Step 5: Documentation Health
|
||||
1. **Documentation Coverage**
|
||||
- Check README.md currency
|
||||
- Verify CLI documentation
|
||||
- Validate MCP tool documentation
|
||||
- Check changelog completeness
|
||||
|
||||
2. **API Documentation**
|
||||
- Verify docstring coverage
|
||||
- Check type annotation completeness
|
||||
- Validate example code
|
||||
|
||||
### Step 6: Project Metrics
|
||||
1. **Code Statistics**
|
||||
```bash
|
||||
find src -name "*.py" | xargs wc -l
|
||||
find tests -name "*.py" | xargs wc -l
|
||||
```
|
||||
- Lines of code trends
|
||||
- Test-to-code ratio
|
||||
- File organization metrics
|
||||
|
||||
## Health Report Format
|
||||
|
||||
Generate comprehensive health dashboard:
|
||||
|
||||
```
|
||||
🏥 Basic Memory Project Health Report
|
||||
|
||||
📊 OVERALL HEALTH: 🟢 EXCELLENT (92/100)
|
||||
|
||||
🗂️ GIT REPOSITORY
|
||||
✅ Clean working directory
|
||||
✅ Up to date with origin/main
|
||||
✅ Recent commit activity (5 commits this week)
|
||||
|
||||
🔍 CODE QUALITY
|
||||
✅ Linting: 0 errors, 2 warnings
|
||||
✅ Type checking: 100% coverage
|
||||
✅ Formatting: Compliant
|
||||
⚠️ Complex functions: 3 need refactoring
|
||||
|
||||
🧪 TEST SUITE
|
||||
✅ Total tests: 744
|
||||
✅ Test discovery: All tests found
|
||||
✅ Coverage: 98.2%
|
||||
⚡ Performance: 45.2s (good)
|
||||
|
||||
📦 DEPENDENCIES
|
||||
✅ Dependencies: Up to date
|
||||
✅ Security: No vulnerabilities
|
||||
✅ Conflicts: None detected
|
||||
⚠️ Outdated: 2 minor updates available
|
||||
|
||||
📖 DOCUMENTATION
|
||||
✅ README: Current
|
||||
✅ API docs: 95% coverage
|
||||
⚠️ CLI reference: Needs update
|
||||
✅ Changelog: Complete
|
||||
|
||||
📈 METRICS
|
||||
├── Source code: 15,432 lines
|
||||
├── Test code: 8,967 lines
|
||||
├── Test ratio: 58% (excellent)
|
||||
└── Complexity: Low (maintainable)
|
||||
|
||||
🎯 RECOMMENDATIONS:
|
||||
1. Update CLI documentation
|
||||
2. Refactor 3 complex functions
|
||||
3. Update minor dependencies
|
||||
4. Consider splitting large test files
|
||||
|
||||
🏆 PROJECT STATUS: Ready for v0.13.0 release!
|
||||
```
|
||||
|
||||
## Health Scoring
|
||||
|
||||
### Excellent (90-100)
|
||||
- All quality gates pass
|
||||
- High test coverage (>95%)
|
||||
- No security issues
|
||||
- Documentation current
|
||||
|
||||
### Good (75-89)
|
||||
- Minor issues present
|
||||
- Good test coverage (>90%)
|
||||
- No critical security issues
|
||||
- Most documentation current
|
||||
|
||||
### Needs Attention (60-74)
|
||||
- Several quality issues
|
||||
- Adequate test coverage (>80%)
|
||||
- Minor security concerns
|
||||
- Documentation gaps
|
||||
|
||||
### Critical (<60)
|
||||
- Major quality problems
|
||||
- Low test coverage (<80%)
|
||||
- Security vulnerabilities
|
||||
- Significant documentation issues
|
||||
|
||||
## Context
|
||||
- Provides comprehensive project overview
|
||||
- Identifies potential issues before they become problems
|
||||
- Tracks project health trends over time
|
||||
- Helps prioritize maintenance tasks
|
||||
- Supports release readiness decisions
|
||||
@@ -0,0 +1,62 @@
|
||||
# Basic Memory Custom Commands
|
||||
|
||||
This directory contains custom Claude Code slash commands for the Basic Memory project.
|
||||
|
||||
## Available Commands
|
||||
|
||||
### Release Management (`/project:release:*`)
|
||||
- `/project:release:beta` - Create beta releases with automated quality checks
|
||||
- `/project:release:release` - Create stable releases with comprehensive validation
|
||||
- `/project:release:release-check` - Pre-flight validation without making changes
|
||||
- `/project:release:changelog` - Generate changelog entries from commits
|
||||
|
||||
### Development (`/project:*`)
|
||||
- `/project:test-coverage` - Run tests with detailed coverage analysis
|
||||
- `/project:test-live` - Live testing suite using real Basic Memory installation
|
||||
- `/project:lint-fix` - Run comprehensive linting with auto-fix
|
||||
- `/project:check-health` - Comprehensive project health assessment
|
||||
|
||||
## Command Structure
|
||||
|
||||
Commands are organized by functionality:
|
||||
```
|
||||
.claude/commands/
|
||||
├── release/ # Release management commands
|
||||
│ ├── beta.md # /project:release:beta
|
||||
│ ├── release.md # /project:release:release
|
||||
│ ├── release-check.md # /project:release:release-check
|
||||
│ └── changelog.md # /project:release:changelog
|
||||
├── test-coverage.md # /project:test-coverage
|
||||
├── test-live.md # /project:test-live
|
||||
├── lint-fix.md # /project:lint-fix
|
||||
├── check-health.md # /project:check-health
|
||||
└── commands.md # This overview file
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Commands are invoked using the `/project:` prefix:
|
||||
- `/project:release:beta v0.13.0b4`
|
||||
- `/project:test-coverage mcp`
|
||||
- `/project:test-live core`
|
||||
- `/project:release:release-check`
|
||||
- `/project:check-health`
|
||||
|
||||
## Implementation
|
||||
|
||||
Each command is implemented as a Markdown file containing structured prompts that:
|
||||
1. Validate preconditions
|
||||
2. Execute steps in the correct order
|
||||
3. Handle errors gracefully
|
||||
4. Provide clear status updates
|
||||
5. Return actionable results
|
||||
|
||||
## Tooling Integration
|
||||
|
||||
Commands leverage existing project tooling:
|
||||
- `just check` - Quality checks
|
||||
- `just test` - Test suite
|
||||
- `just update-deps` - Dependency updates
|
||||
- `uv` - Package management
|
||||
- `git` - Version control
|
||||
- GitHub Actions - CI/CD pipeline
|
||||
@@ -0,0 +1,145 @@
|
||||
# /project:lint-fix - Comprehensive Code Quality Fix
|
||||
|
||||
Run comprehensive linting and auto-fix code quality issues across the codebase.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/project:lint-fix
|
||||
```
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert code quality engineer for the Basic Memory project. When the user runs `/project:lint-fix`, execute the following steps:
|
||||
|
||||
### Step 1: Pre-flight Check
|
||||
1. **Verify Clean Working Directory**
|
||||
```bash
|
||||
git status --porcelain
|
||||
```
|
||||
- Check for uncommitted changes
|
||||
- Warn if working directory is not clean
|
||||
- Suggest stashing changes if needed
|
||||
|
||||
### Step 2: Import Organization
|
||||
1. **Fix Import Order and Cleanup**
|
||||
```bash
|
||||
uv run ruff check --select I --fix .
|
||||
```
|
||||
- Sort imports by category (standard, third-party, local)
|
||||
- Remove unused imports
|
||||
- Fix import spacing and organization
|
||||
|
||||
### Step 3: Code Formatting
|
||||
1. **Apply Consistent Formatting**
|
||||
```bash
|
||||
uv run ruff format .
|
||||
```
|
||||
- Format code according to project style
|
||||
- Fix line length issues (100 chars max)
|
||||
- Standardize quotes and spacing
|
||||
|
||||
### Step 4: Linting with Auto-fix
|
||||
1. **Fix Linting Issues**
|
||||
```bash
|
||||
uv run ruff check --fix .
|
||||
```
|
||||
- Auto-fix safe linting issues
|
||||
- Report any remaining manual fixes needed
|
||||
- Focus on code quality and best practices
|
||||
|
||||
### Step 5: Type Checking
|
||||
1. **Validate Type Annotations**
|
||||
```bash
|
||||
uv run pyright
|
||||
```
|
||||
- Check for type errors
|
||||
- Report any missing type annotations
|
||||
- Validate type compatibility
|
||||
|
||||
### Step 6: Report Generation
|
||||
Generate comprehensive quality report:
|
||||
|
||||
```
|
||||
🔧 Code Quality Fix Report
|
||||
|
||||
✅ FIXES APPLIED:
|
||||
├── Import organization: 12 files updated
|
||||
├── Code formatting: 8 files reformatted
|
||||
├── Auto-fixable lint issues: 23 issues resolved
|
||||
└── Total files processed: 156
|
||||
|
||||
⚠️ MANUAL ATTENTION NEEDED:
|
||||
├── Type annotations missing in entity_service.py:45
|
||||
├── Complex function needs refactoring in sync_service.py:123
|
||||
└── Unused variable in test_utils.py:67
|
||||
|
||||
🎯 QUALITY SCORE: 96.2% (excellent)
|
||||
|
||||
📁 Run `git diff` to review all changes
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Common Issues
|
||||
- **Merge Conflicts**: Provide resolution guidance
|
||||
- **Syntax Errors**: Point to specific files and lines
|
||||
- **Type Errors**: Suggest specific fixes
|
||||
- **Import Errors**: Check for missing dependencies
|
||||
|
||||
### Recovery Steps
|
||||
- If auto-fixes introduce issues, provide rollback instructions
|
||||
- If type checking fails, suggest incremental fixes
|
||||
- If tests break, provide debugging guidance
|
||||
|
||||
## Quality Gates
|
||||
|
||||
### Must Pass
|
||||
- [ ] All auto-fixable lint issues resolved
|
||||
- [ ] Code formatting consistent
|
||||
- [ ] No syntax errors
|
||||
- [ ] Import organization clean
|
||||
|
||||
### Should Pass (Warnings)
|
||||
- [ ] No type checking errors
|
||||
- [ ] No complex function warnings
|
||||
- [ ] No unused variables/imports
|
||||
- [ ] Consistent naming conventions
|
||||
|
||||
## Output Examples
|
||||
|
||||
### Successful Fix
|
||||
```
|
||||
🎉 CODE QUALITY IMPROVED!
|
||||
|
||||
✅ All auto-fixes applied successfully
|
||||
📏 Code formatting: 100% compliant
|
||||
🔍 Linting: No issues found
|
||||
🏷️ Type checking: All passed
|
||||
|
||||
Ready for commit! Use:
|
||||
git add -A && git commit -m "style: fix code quality issues"
|
||||
```
|
||||
|
||||
### Issues Requiring Attention
|
||||
```
|
||||
⚠️ PARTIAL SUCCESS - MANUAL FIXES NEEDED
|
||||
|
||||
✅ Auto-fixes applied: 45 issues
|
||||
❌ Manual fixes needed: 3 issues
|
||||
|
||||
Priority fixes:
|
||||
1. Fix type annotation in services/entity_service.py:142
|
||||
2. Simplify complex function in sync/sync_service.py:67
|
||||
3. Remove unused import in tests/conftest.py:12
|
||||
|
||||
Run these commands:
|
||||
# Fix specific file
|
||||
uv run pyright src/basic_memory/services/entity_service.py
|
||||
```
|
||||
|
||||
## Context
|
||||
- Uses ruff for fast Python linting and formatting
|
||||
- Uses pyright for type checking
|
||||
- Follows project code style guidelines (100 char line length)
|
||||
- Maintains backward compatibility
|
||||
- Integrates with existing pre-commit hooks
|
||||
@@ -0,0 +1,95 @@
|
||||
# /beta - Create Beta Release
|
||||
|
||||
Create a new beta release using the automated justfile target with quality checks and tagging.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/beta <version>
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `version` (required): Beta version like `v0.13.2b1` or `v0.13.2rc1`
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert release manager for the Basic Memory project. When the user runs `/beta`, execute the following steps:
|
||||
|
||||
### Step 1: Pre-flight Validation
|
||||
1. Verify version format matches `v\d+\.\d+\.\d+(b\d+|rc\d+)` pattern
|
||||
2. Check current git status for uncommitted changes
|
||||
3. Verify we're on the `main` branch
|
||||
4. Confirm no existing tag with this version
|
||||
|
||||
### Step 2: Use Justfile Automation
|
||||
Execute the automated beta release process:
|
||||
```bash
|
||||
just beta <version>
|
||||
```
|
||||
|
||||
The justfile target handles:
|
||||
- ✅ Beta version format validation (supports b1, b2, rc1, etc.)
|
||||
- ✅ Git status and branch checks
|
||||
- ✅ Quality checks (`just check` - lint, format, type-check, tests)
|
||||
- ✅ Version update in `src/basic_memory/__init__.py`
|
||||
- ✅ Automatic commit with proper message
|
||||
- ✅ Tag creation and pushing to GitHub
|
||||
- ✅ Beta release workflow trigger
|
||||
|
||||
### Step 3: Monitor Beta Release
|
||||
1. Check GitHub Actions workflow starts successfully
|
||||
2. Monitor workflow at: https://github.com/basicmachines-co/basic-memory/actions
|
||||
3. Verify PyPI pre-release publication
|
||||
4. Test beta installation: `uv tool install basic-memory --pre`
|
||||
|
||||
### Step 4: Beta Testing Instructions
|
||||
Provide users with beta testing instructions:
|
||||
|
||||
```bash
|
||||
# Install/upgrade to beta
|
||||
uv tool install basic-memory --pre
|
||||
|
||||
# Or upgrade existing installation
|
||||
uv tool upgrade basic-memory --prerelease=allow
|
||||
```
|
||||
|
||||
## Version Guidelines
|
||||
- **First beta**: `v0.13.2b1`
|
||||
- **Subsequent betas**: `v0.13.2b2`, `v0.13.2b3`, etc.
|
||||
- **Release candidates**: `v0.13.2rc1`, `v0.13.2rc2`, etc.
|
||||
- **Final release**: `v0.13.2` (use `/release` command)
|
||||
|
||||
## Error Handling
|
||||
- If `just beta` fails, examine the error output for specific issues
|
||||
- If quality checks fail, fix issues and retry
|
||||
- If version format is invalid, correct and retry
|
||||
- If tag already exists, increment version number
|
||||
|
||||
## Success Output
|
||||
```
|
||||
✅ Beta Release v0.13.2b1 Created Successfully!
|
||||
|
||||
🏷️ Tag: v0.13.2b1
|
||||
🚀 GitHub Actions: Running
|
||||
📦 PyPI: Will be available in ~5 minutes as pre-release
|
||||
|
||||
Install/test with:
|
||||
uv tool install basic-memory --pre
|
||||
|
||||
Monitor release: https://github.com/basicmachines-co/basic-memory/actions
|
||||
```
|
||||
|
||||
## Beta Testing Workflow
|
||||
1. **Create beta**: Use `/beta v0.13.2b1`
|
||||
2. **Test features**: Install and validate new functionality
|
||||
3. **Fix issues**: Address bugs found during testing
|
||||
4. **Iterate**: Create `v0.13.2b2` if needed
|
||||
5. **Release candidate**: Create `v0.13.2rc1` when stable
|
||||
6. **Final release**: Use `/release v0.13.2` when ready
|
||||
|
||||
## Context
|
||||
- Beta releases are pre-releases for testing new features
|
||||
- Automatically published to PyPI with pre-release flag
|
||||
- Uses the automated justfile target for consistency
|
||||
- Version is automatically updated in `__init__.py`
|
||||
- Ideal for validating changes before stable release
|
||||
- Supports both beta (b1, b2) and release candidate (rc1, rc2) versions
|
||||
@@ -0,0 +1,157 @@
|
||||
# /changelog - Generate or Update Changelog Entry
|
||||
|
||||
Analyze commits and generate formatted changelog entry for a version.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/changelog <version> [type]
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `version` (required): Version like `v0.13.0` or `v0.13.0b4`
|
||||
- `type` (optional): `beta`, `rc`, or `stable` (default: `stable`)
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert technical writer for the Basic Memory project. When the user runs `/changelog`, execute the following steps:
|
||||
|
||||
### Step 1: Version Analysis
|
||||
1. **Determine Commit Range**
|
||||
```bash
|
||||
# Find last release tag
|
||||
git tag -l "v*" --sort=-version:refname | grep -v "b\|rc" | head -1
|
||||
|
||||
# Get commits since last release
|
||||
git log --oneline ${last_tag}..HEAD
|
||||
```
|
||||
|
||||
2. **Parse Conventional Commits**
|
||||
- Extract feat: (features)
|
||||
- Extract fix: (bug fixes)
|
||||
- Extract BREAKING CHANGE: (breaking changes)
|
||||
- Extract chore:, docs:, test: (other improvements)
|
||||
|
||||
### Step 2: Categorize Changes
|
||||
1. **Features (feat:)**
|
||||
- New MCP tools
|
||||
- New CLI commands
|
||||
- New API endpoints
|
||||
- Major functionality additions
|
||||
|
||||
2. **Bug Fixes (fix:)**
|
||||
- User-facing bug fixes
|
||||
- Critical issues resolved
|
||||
- Performance improvements
|
||||
- Security fixes
|
||||
|
||||
3. **Technical Improvements**
|
||||
- Test coverage improvements
|
||||
- Code quality enhancements
|
||||
- Dependency updates
|
||||
- Documentation updates
|
||||
|
||||
4. **Breaking Changes**
|
||||
- API changes
|
||||
- Configuration changes
|
||||
- Behavior changes
|
||||
- Migration requirements
|
||||
|
||||
### Step 3: Generate Changelog Entry
|
||||
Create formatted entry following existing CHANGELOG.md style:
|
||||
|
||||
```markdown
|
||||
## v0.13.0 (2025-06-03)
|
||||
|
||||
### Features
|
||||
|
||||
- **Multi-Project Management System** - Switch between projects instantly during conversations
|
||||
([`993e88a`](https://github.com/basicmachines-co/basic-memory/commit/993e88a))
|
||||
- Instant project switching with session context
|
||||
- Project-specific operations and isolation
|
||||
- Project discovery and management tools
|
||||
|
||||
- **Advanced Note Editing** - Incremental editing with append, prepend, find/replace, and section operations
|
||||
([`6fc3904`](https://github.com/basicmachines-co/basic-memory/commit/6fc3904))
|
||||
- `edit_note` tool with multiple operation types
|
||||
- Smart frontmatter-aware editing
|
||||
- Validation and error handling
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **#118**: Fix YAML tag formatting to follow standard specification
|
||||
([`2dc7e27`](https://github.com/basicmachines-co/basic-memory/commit/2dc7e27))
|
||||
|
||||
- **#110**: Make --project flag work consistently across CLI commands
|
||||
([`02dd91a`](https://github.com/basicmachines-co/basic-memory/commit/02dd91a))
|
||||
|
||||
### Technical Improvements
|
||||
|
||||
- **Comprehensive Testing** - 100% test coverage with integration testing
|
||||
([`468a22f`](https://github.com/basicmachines-co/basic-memory/commit/468a22f))
|
||||
- MCP integration test suite
|
||||
- End-to-end testing framework
|
||||
- Performance and edge case validation
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- **Database Migration**: Automatic migration from per-project to unified database.
|
||||
Data will be re-index from the filesystem, resulting in no data loss.
|
||||
- **Configuration Changes**: Projects now synced between config.json and database
|
||||
- **Full Backward Compatibility**: All existing setups continue to work seamlessly
|
||||
```
|
||||
|
||||
### Step 4: Integration
|
||||
1. **Update CHANGELOG.md**
|
||||
- Insert new entry at top
|
||||
- Maintain consistent formatting
|
||||
- Include commit links and issue references
|
||||
|
||||
2. **Validation**
|
||||
- Check all major changes are captured
|
||||
- Verify commit links work
|
||||
- Ensure issue numbers are correct
|
||||
|
||||
## Smart Analysis Features
|
||||
|
||||
### Automatic Classification
|
||||
- Detect feature additions from file changes
|
||||
- Identify bug fixes from commit messages
|
||||
- Find breaking changes from code analysis
|
||||
- Extract issue numbers from commit messages
|
||||
|
||||
### Content Enhancement
|
||||
- Add context for technical changes
|
||||
- Include migration guidance for breaking changes
|
||||
- Suggest installation/upgrade instructions
|
||||
- Link to relevant documentation
|
||||
|
||||
## Output Format
|
||||
|
||||
### For Beta Releases
|
||||
```markdown
|
||||
## v0.13.0b4 (2025-06-03)
|
||||
|
||||
### Beta Changes Since v0.13.0b3
|
||||
|
||||
- Fix FastMCP API compatibility issues
|
||||
- Update dependencies to latest versions
|
||||
- Resolve setuptools import error
|
||||
|
||||
### Installation
|
||||
```bash
|
||||
uv tool install basic-memory --prerelease=allow
|
||||
```
|
||||
|
||||
### Known Issues
|
||||
- [List any known issues for beta testing]
|
||||
```
|
||||
|
||||
### For Stable Releases
|
||||
Full changelog with complete feature list, organized by impact and category.
|
||||
|
||||
## Context
|
||||
- Follows existing CHANGELOG.md format and style
|
||||
- Uses conventional commit standards
|
||||
- Includes GitHub commit links for traceability
|
||||
- Focuses on user-facing changes and value
|
||||
- Maintains consistency with previous entries
|
||||
@@ -0,0 +1,131 @@
|
||||
# /release-check - Pre-flight Release Validation
|
||||
|
||||
Comprehensive pre-flight check for release readiness without making any changes.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/release-check [version]
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `version` (optional): Version to validate like `v0.13.0`. If not provided, determines from context.
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert QA engineer for the Basic Memory project. When the user runs `/release-check`, execute the following validation steps:
|
||||
|
||||
### Step 1: Environment Validation
|
||||
1. **Git Status Check**
|
||||
- Verify working directory is clean
|
||||
- Confirm on `main` branch
|
||||
- Check if ahead/behind origin
|
||||
|
||||
2. **Version Validation**
|
||||
- Validate version format if provided
|
||||
- Check for existing tags with same version
|
||||
- Verify version increments properly from last release
|
||||
|
||||
### Step 2: Code Quality Gates
|
||||
1. **Test Suite Validation**
|
||||
```bash
|
||||
just test
|
||||
```
|
||||
- All tests must pass
|
||||
- Check test coverage (target: 95%+)
|
||||
- Validate no skipped critical tests
|
||||
|
||||
2. **Code Quality Checks**
|
||||
```bash
|
||||
just lint
|
||||
just type-check
|
||||
```
|
||||
- No linting errors
|
||||
- No type checking errors
|
||||
- Code formatting is consistent
|
||||
|
||||
### Step 3: Documentation Validation
|
||||
1. **Changelog Check**
|
||||
- CHANGELOG.md contains entry for target version
|
||||
- Entry includes all major features and fixes
|
||||
- Breaking changes are documented
|
||||
|
||||
2. **Documentation Currency**
|
||||
- README.md reflects current functionality
|
||||
- CLI reference is up to date
|
||||
- MCP tools are documented
|
||||
|
||||
### Step 4: Dependency Validation
|
||||
1. **Security Scan**
|
||||
- No known vulnerabilities in dependencies
|
||||
- All dependencies are at appropriate versions
|
||||
- No conflicting dependency versions
|
||||
|
||||
2. **Build Validation**
|
||||
- Package builds successfully
|
||||
- All required files are included
|
||||
- No missing dependencies
|
||||
|
||||
### Step 5: Issue Tracking Validation
|
||||
1. **GitHub Issues Check**
|
||||
- No critical open issues blocking release
|
||||
- All milestone issues are resolved
|
||||
- High-priority bugs are fixed
|
||||
|
||||
2. **Testing Coverage**
|
||||
- Integration tests pass
|
||||
- MCP tool tests pass
|
||||
- Cross-platform compatibility verified
|
||||
|
||||
## Report Format
|
||||
|
||||
Generate a comprehensive report:
|
||||
|
||||
```
|
||||
🔍 Release Readiness Check for v0.13.0
|
||||
|
||||
✅ PASSED CHECKS:
|
||||
├── Git status clean
|
||||
├── On main branch
|
||||
├── All tests passing (744/744)
|
||||
├── Test coverage: 98.2%
|
||||
├── Type checking passed
|
||||
├── Linting passed
|
||||
├── CHANGELOG.md updated
|
||||
└── No critical issues open
|
||||
|
||||
⚠️ WARNINGS:
|
||||
├── 2 medium-priority issues still open
|
||||
└── Documentation could be updated
|
||||
|
||||
❌ BLOCKING ISSUES:
|
||||
└── None found
|
||||
|
||||
🎯 RELEASE READINESS: ✅ READY
|
||||
|
||||
Recommended next steps:
|
||||
1. Address warnings if desired
|
||||
2. Run `/release v0.13.0` when ready
|
||||
```
|
||||
|
||||
## Validation Criteria
|
||||
|
||||
### Must Pass (Blocking)
|
||||
- [ ] All tests pass
|
||||
- [ ] No type errors
|
||||
- [ ] No linting errors
|
||||
- [ ] Working directory clean
|
||||
- [ ] On main branch
|
||||
- [ ] CHANGELOG.md has version entry
|
||||
- [ ] No critical open issues
|
||||
|
||||
### Should Pass (Warnings)
|
||||
- [ ] Test coverage >95%
|
||||
- [ ] No medium-priority open issues
|
||||
- [ ] Documentation up to date
|
||||
- [ ] No dependency vulnerabilities
|
||||
|
||||
## Context
|
||||
- This is a read-only validation - makes no changes
|
||||
- Provides confidence before running actual release
|
||||
- Helps identify issues early in release process
|
||||
- Can be run multiple times safely
|
||||
@@ -0,0 +1,86 @@
|
||||
# /release - Create Stable Release
|
||||
|
||||
Create a stable release using the automated justfile target with comprehensive validation.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/release <version>
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `version` (required): Release version like `v0.13.2`
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert release manager for the Basic Memory project. When the user runs `/release`, execute the following steps:
|
||||
|
||||
### Step 1: Pre-flight Validation
|
||||
1. Verify version format matches `v\d+\.\d+\.\d+` pattern
|
||||
2. Check current git status for uncommitted changes
|
||||
3. Verify we're on the `main` branch
|
||||
4. Confirm no existing tag with this version
|
||||
|
||||
### Step 2: Use Justfile Automation
|
||||
Execute the automated release process:
|
||||
```bash
|
||||
just release <version>
|
||||
```
|
||||
|
||||
The justfile target handles:
|
||||
- ✅ Version format validation
|
||||
- ✅ Git status and branch checks
|
||||
- ✅ Quality checks (`just check` - lint, format, type-check, tests)
|
||||
- ✅ Version update in `src/basic_memory/__init__.py`
|
||||
- ✅ Automatic commit with proper message
|
||||
- ✅ Tag creation and pushing to GitHub
|
||||
- ✅ Release workflow trigger
|
||||
|
||||
### Step 3: Monitor Release Process
|
||||
1. Check that GitHub Actions workflow starts successfully
|
||||
2. Monitor workflow completion at: https://github.com/basicmachines-co/basic-memory/actions
|
||||
3. Verify PyPI publication
|
||||
4. Test installation: `uv tool install basic-memory`
|
||||
|
||||
### Step 4: Post-Release Validation
|
||||
1. Verify GitHub release is created automatically
|
||||
2. Check PyPI publication
|
||||
3. Validate release assets
|
||||
4. Update any post-release documentation
|
||||
|
||||
## Pre-conditions Check
|
||||
Before starting, verify:
|
||||
- [ ] All beta testing is complete
|
||||
- [ ] Critical bugs are fixed
|
||||
- [ ] Breaking changes are documented
|
||||
- [ ] CHANGELOG.md is updated (if needed)
|
||||
- [ ] Version number follows semantic versioning
|
||||
|
||||
## Error Handling
|
||||
- If `just release` fails, examine the error output for specific issues
|
||||
- If quality checks fail, fix issues and retry
|
||||
- If changelog entry missing, update CHANGELOG.md and commit before retrying
|
||||
- If GitHub Actions fail, check workflow logs for debugging
|
||||
|
||||
## Success Output
|
||||
```
|
||||
🎉 Stable Release v0.13.2 Created Successfully!
|
||||
|
||||
🏷️ Tag: v0.13.2
|
||||
📋 GitHub Release: https://github.com/basicmachines-co/basic-memory/releases/tag/v0.13.2
|
||||
📦 PyPI: https://pypi.org/project/basic-memory/0.13.2/
|
||||
🚀 GitHub Actions: Completed
|
||||
|
||||
Install with:
|
||||
uv tool install basic-memory
|
||||
|
||||
Users can now upgrade:
|
||||
uv tool upgrade basic-memory
|
||||
```
|
||||
|
||||
## Context
|
||||
- This creates production releases used by end users
|
||||
- Must pass all quality gates before proceeding
|
||||
- Uses the automated justfile target for consistency
|
||||
- Version is automatically updated in `__init__.py`
|
||||
- Triggers automated GitHub release with changelog
|
||||
- Leverages uv-dynamic-versioning for package version management
|
||||
@@ -0,0 +1,131 @@
|
||||
# /test-coverage - Run Tests with Coverage Analysis
|
||||
|
||||
Execute test suite with comprehensive coverage reporting and analysis.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/test-coverage [pattern]
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `pattern` (optional): Test pattern to run specific tests (e.g., `test_mcp`, `*integration*`)
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert QA engineer for the Basic Memory project. When the user runs `/test-coverage`, execute the following steps:
|
||||
|
||||
### Step 1: Test Execution
|
||||
1. **Run Tests with Coverage**
|
||||
```bash
|
||||
# Full test suite
|
||||
uv run pytest --cov=basic_memory --cov-report=html --cov-report=term -v
|
||||
|
||||
# Or with pattern if provided
|
||||
uv run pytest tests/*{pattern}* --cov=basic_memory --cov-report=html --cov-report=term -v
|
||||
```
|
||||
|
||||
2. **Generate Coverage Reports**
|
||||
- Terminal summary with percentages
|
||||
- HTML report for detailed analysis
|
||||
- Identify files below coverage threshold
|
||||
|
||||
### Step 2: Coverage Analysis
|
||||
1. **Summary Statistics**
|
||||
- Overall coverage percentage
|
||||
- Number of files with 100% coverage
|
||||
- Files below 95% threshold
|
||||
- Total lines covered/missed
|
||||
|
||||
2. **Detailed Breakdown**
|
||||
- Coverage by module/package
|
||||
- Identify untested code paths
|
||||
- Find missing edge case tests
|
||||
|
||||
### Step 3: Report Generation
|
||||
Generate comprehensive coverage report:
|
||||
|
||||
```
|
||||
🧪 Test Coverage Report
|
||||
|
||||
📊 OVERALL COVERAGE: 98.2% (target: 95%+)
|
||||
|
||||
✅ EXCELLENT COVERAGE (>95%):
|
||||
├── basic_memory/mcp/: 99.1%
|
||||
├── basic_memory/services/: 98.8%
|
||||
├── basic_memory/repository/: 97.9%
|
||||
└── basic_memory/api/: 96.2%
|
||||
|
||||
⚠️ NEEDS ATTENTION (<95%):
|
||||
├── basic_memory/sync/: 94.1% (missing 12 lines)
|
||||
└── basic_memory/importers/: 91.8% (missing 23 lines)
|
||||
|
||||
🎯 SPECIFIC GAPS:
|
||||
├── sync_service.py:142-145 (error handling)
|
||||
├── importer_base.py:67-70 (edge case)
|
||||
└── file_utils.py:89 (exception path)
|
||||
|
||||
📁 HTML Report: htmlcov/index.html
|
||||
🚀 Run `open htmlcov/index.html` to view detailed report
|
||||
```
|
||||
|
||||
### Step 4: Actionable Recommendations
|
||||
1. **Coverage Improvements**
|
||||
- Suggest specific tests to add
|
||||
- Identify edge cases to cover
|
||||
- Recommend integration tests
|
||||
|
||||
2. **Quality Insights**
|
||||
- Highlight well-tested modules
|
||||
- Point out testing patterns to follow
|
||||
- Suggest refactoring for testability
|
||||
|
||||
## Advanced Analysis
|
||||
|
||||
### Performance Metrics
|
||||
- Test execution time by module
|
||||
- Slowest tests identification
|
||||
- Coverage collection overhead
|
||||
|
||||
### Integration Coverage
|
||||
- MCP tool integration tests
|
||||
- API endpoint coverage
|
||||
- Database operation coverage
|
||||
- File system operation coverage
|
||||
|
||||
## Output Examples
|
||||
|
||||
### Full Coverage Success
|
||||
```
|
||||
🎉 EXCELLENT COVERAGE!
|
||||
|
||||
📊 Coverage: 98.7% (744 tests passed)
|
||||
✅ All modules above 95% threshold
|
||||
🏆 23 files with 100% coverage
|
||||
⚡ Tests completed in 45.2s
|
||||
|
||||
Ready for release! 🚀
|
||||
```
|
||||
|
||||
### Coverage Issues Found
|
||||
```
|
||||
⚠️ COVERAGE GAPS DETECTED
|
||||
|
||||
📊 Coverage: 92.1% (below 95% target)
|
||||
❌ 3 modules need attention
|
||||
🔍 43 uncovered lines found
|
||||
|
||||
Priority fixes:
|
||||
1. Add tests for error handling in sync_service.py
|
||||
2. Cover edge cases in importer_base.py
|
||||
3. Test exception paths in file_utils.py
|
||||
|
||||
Run specific tests:
|
||||
uv run pytest tests/sync/ -v
|
||||
```
|
||||
|
||||
## Context
|
||||
- Uses pytest with coverage plugin
|
||||
- Generates both terminal and HTML reports
|
||||
- Focuses on actionable improvement suggestions
|
||||
- Integrates with existing test infrastructure
|
||||
- Helps maintain high code quality standards
|
||||
@@ -0,0 +1,410 @@
|
||||
# /project:test-live - Live Basic Memory Testing Suite
|
||||
|
||||
Execute comprehensive real-world testing of Basic Memory using the installed version, following the methodology in TESTING.md. All test results are recorded as notes in a dedicated test project.
|
||||
|
||||
## Usage
|
||||
```
|
||||
/project:test-live [phase]
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `phase` (optional): Specific test phase to run (`core`, `features`, `edge`, `workflows`, `stress`, or `all`)
|
||||
|
||||
## Implementation
|
||||
|
||||
You are an expert QA engineer conducting live testing of Basic Memory.
|
||||
When the user runs `/project:test-live`, execute comprehensive testing following the TESTING.md methodology:
|
||||
|
||||
### Pre-Test Setup
|
||||
|
||||
1. **Environment Verification**
|
||||
- Verify basic-memory is installed and accessible via MCP
|
||||
- Check version and confirm it's the expected release
|
||||
- Test MCP connection and tool availability
|
||||
|
||||
2. **Test Project Creation**
|
||||
|
||||
Run the bash `date` command to get the current date/time.
|
||||
|
||||
```
|
||||
Create project: "basic-memory-testing-[timestamp]"
|
||||
Location: ~/basic-memory-testing-[timestamp]
|
||||
Purpose: Record all test observations and results
|
||||
```
|
||||
|
||||
Make sure to switch to the newly created project with the `switch_project()` tool.
|
||||
|
||||
3. **Baseline Documentation**
|
||||
Create initial test session note with:
|
||||
- Test environment details
|
||||
- Version being tested
|
||||
- Test objectives and scope
|
||||
- Start timestamp
|
||||
|
||||
### Phase 1: Core Functionality Validation
|
||||
|
||||
Test all fundamental MCP tools systematically:
|
||||
|
||||
**write_note Tests:**
|
||||
- Basic note creation with various content types
|
||||
- Frontmatter handling (tags, custom fields)
|
||||
- Special characters in titles and content
|
||||
- Unicode and emoji support
|
||||
- Empty notes and minimal content
|
||||
|
||||
**read_note Tests:**
|
||||
- Read by title, permalink, memory:// URLs
|
||||
- Non-existent notes (error handling)
|
||||
- Notes with complex formatting
|
||||
- Performance with large notes
|
||||
|
||||
**view_note Tests:**
|
||||
- View notes as formatted artifacts (Claude Desktop)
|
||||
- Title extraction from frontmatter and headings
|
||||
- Unicode and emoji content in artifacts
|
||||
- Error handling for non-existent notes
|
||||
- Artifact display quality and readability
|
||||
|
||||
**search_notes Tests:**
|
||||
- Simple text queries
|
||||
- Tag-based searches
|
||||
- Boolean operators and complex queries
|
||||
- Empty/no results scenarios
|
||||
- Performance with growing knowledge base
|
||||
|
||||
**Recent Activity Tests:**
|
||||
- Various timeframes ("today", "1 week", "1d")
|
||||
- Type filtering (if available)
|
||||
- Empty project scenarios
|
||||
- Performance with many recent changes
|
||||
|
||||
**Context Building Tests:**
|
||||
- Different depth levels (1, 2, 3+)
|
||||
- Various timeframes
|
||||
- Relation traversal accuracy
|
||||
- Performance with complex graphs
|
||||
|
||||
### Phase 2: v0.13.0 Feature Deep Dive
|
||||
|
||||
**Project Management:**
|
||||
- Create multiple projects dynamically
|
||||
- Switch between projects mid-conversation
|
||||
- Cross-project operations
|
||||
- Project discovery and status
|
||||
- Default project behavior
|
||||
- Invalid project handling
|
||||
|
||||
**Advanced Note Editing:**
|
||||
- `edit_note` with append operations
|
||||
- Prepend operations
|
||||
- Find/replace with validation
|
||||
- Section replacement under headers
|
||||
- Error scenarios (invalid operations)
|
||||
- Frontmatter preservation
|
||||
|
||||
**File Management:**
|
||||
- `move_note` within same project
|
||||
- Move between projects
|
||||
- Automatic folder creation
|
||||
- Special characters in paths
|
||||
- Database consistency validation
|
||||
- Search index updates after moves
|
||||
|
||||
### Phase 3: Edge Case Exploration
|
||||
|
||||
**Boundary Testing:**
|
||||
- Very long titles and content (stress limits)
|
||||
- Empty projects and notes
|
||||
- Unicode, emojis, special symbols
|
||||
- Deeply nested folder structures
|
||||
- Circular relations and self-references
|
||||
- Maximum relation depths
|
||||
|
||||
**Error Scenarios:**
|
||||
- Invalid memory:// URLs
|
||||
- Missing files referenced in database
|
||||
- Invalid project names and paths
|
||||
- Malformed note structures
|
||||
- Concurrent operation conflicts
|
||||
|
||||
**Performance Testing:**
|
||||
- Create 100+ notes rapidly
|
||||
- Complex search queries
|
||||
- Deep relation chains (5+ levels)
|
||||
- Rapid successive operations
|
||||
- Memory usage monitoring
|
||||
|
||||
### Phase 4: Real-World Workflow Scenarios
|
||||
|
||||
**Meeting Notes Pipeline:**
|
||||
1. Create meeting notes with action items
|
||||
2. Extract action items using edit_note
|
||||
3. Build relations to project documents
|
||||
4. Update progress incrementally
|
||||
5. Search and track completion
|
||||
|
||||
**Research Knowledge Building:**
|
||||
1. Create research topic hierarchy
|
||||
2. Build complex relation networks
|
||||
3. Add incremental findings over time
|
||||
4. Search for connections and patterns
|
||||
5. Reorganize as knowledge evolves
|
||||
|
||||
**Multi-Project Workflow:**
|
||||
1. Technical documentation project
|
||||
2. Personal recipe collection project
|
||||
3. Learning/course notes project
|
||||
4. Switch contexts during conversation
|
||||
5. Cross-reference related concepts
|
||||
|
||||
**Content Evolution:**
|
||||
1. Start with basic notes
|
||||
2. Enhance with relations and observations
|
||||
3. Reorganize file structure using moves
|
||||
4. Update content with edit operations
|
||||
5. Validate knowledge graph integrity
|
||||
|
||||
### Phase 5: Creative Stress Testing
|
||||
|
||||
**Creative Exploration:**
|
||||
- Rapid project creation/switching patterns
|
||||
- Unusual but valid markdown structures
|
||||
- Creative observation categories
|
||||
- Novel relation types and patterns
|
||||
- Unexpected tool combinations
|
||||
|
||||
**Stress Scenarios:**
|
||||
- Bulk operations (many notes quickly)
|
||||
- Complex nested moves and edits
|
||||
- Deep context building
|
||||
- Complex boolean search expressions
|
||||
- Resource constraint testing
|
||||
|
||||
## Test Observation Format
|
||||
|
||||
Record ALL observations immediately as Basic Memory notes:
|
||||
|
||||
```markdown
|
||||
---
|
||||
title: Test Session [Phase] YYYY-MM-DD HH:MM
|
||||
tags: [testing, v0.13.0, live-testing, [phase]]
|
||||
permalink: test-session-[phase]-[timestamp]
|
||||
---
|
||||
|
||||
# Test Session [Phase] - [Date/Time]
|
||||
|
||||
## Environment
|
||||
- Basic Memory version: [version]
|
||||
- MCP connection: [status]
|
||||
- Test project: [name]
|
||||
- Phase focus: [description]
|
||||
|
||||
## Test Results
|
||||
|
||||
### ✅ Successful Operations
|
||||
- [timestamp] write_note: Created note with emoji title 📝 #functionality
|
||||
- [timestamp] search_notes: Boolean query returned 23 results in 0.4s #performance
|
||||
- [timestamp] edit_note: Append operation preserved frontmatter #reliability
|
||||
|
||||
### ⚠️ Issues Discovered
|
||||
- [timestamp] move_note: Slow with deep folder paths (2.1s) #performance
|
||||
- [timestamp] search_notes: Unicode query returned unexpected results #bug
|
||||
- [timestamp] project switch: Context lost for memory:// URLs #issue
|
||||
|
||||
### 🚀 Enhancements Identified
|
||||
- edit_note could benefit from preview mode #ux-improvement
|
||||
- search_notes needs fuzzy matching for typos #feature-idea
|
||||
- move_note could auto-suggest folder creation #usability
|
||||
|
||||
### 📊 Performance Metrics
|
||||
- Average write_note time: 0.3s
|
||||
- Search with 100+ notes: 0.6s
|
||||
- Project switch overhead: 0.1s
|
||||
- Memory usage: [observed levels]
|
||||
|
||||
## Relations
|
||||
- tests [[Basic Memory v0.13.0]]
|
||||
- part_of [[Live Testing Suite]]
|
||||
- found_issues [[Bug Report: Unicode Search]]
|
||||
- discovered [[Performance Optimization Opportunities]]
|
||||
```
|
||||
|
||||
## Quality Assessment Areas
|
||||
|
||||
**User Experience & Usability:**
|
||||
- Tool instruction clarity and examples
|
||||
- Error message actionability
|
||||
- Response time acceptability
|
||||
- Tool consistency and discoverability
|
||||
- Learning curve and intuitiveness
|
||||
|
||||
**System Behavior:**
|
||||
- Context preservation across operations
|
||||
- memory:// URL navigation reliability
|
||||
- Multi-step workflow cohesion
|
||||
- Edge case graceful handling
|
||||
- Recovery from user errors
|
||||
|
||||
**Documentation Alignment:**
|
||||
- Tool output clarity and helpfulness
|
||||
- Behavior vs. documentation accuracy
|
||||
- Example validity and usefulness
|
||||
- Real-world vs. documented workflows
|
||||
|
||||
**Mental Model Validation:**
|
||||
- Natural user expectation alignment
|
||||
- Surprising behavior identification
|
||||
- Mistake recovery ease
|
||||
- Knowledge graph concept naturalness
|
||||
|
||||
**Performance & Reliability:**
|
||||
- Operation completion times
|
||||
- Consistency across sessions
|
||||
- Scaling behavior with growth
|
||||
- Unexpected slowness identification
|
||||
|
||||
## Error Documentation Protocol
|
||||
|
||||
For each error discovered:
|
||||
|
||||
1. **Immediate Recording**
|
||||
- Create dedicated error note
|
||||
- Include exact reproduction steps
|
||||
- Capture error messages verbatim
|
||||
- Note system state when error occurred
|
||||
|
||||
2. **Error Note Format**
|
||||
```markdown
|
||||
---
|
||||
title: Bug Report - [Short Description]
|
||||
tags: [bug, testing, v0.13.0, [severity]]
|
||||
---
|
||||
|
||||
# Bug Report: [Description]
|
||||
|
||||
## Reproduction Steps
|
||||
1. [Exact steps to reproduce]
|
||||
2. [Include all parameters used]
|
||||
3. [Note any special conditions]
|
||||
|
||||
## Expected Behavior
|
||||
[What should have happened]
|
||||
|
||||
## Actual Behavior
|
||||
[What actually happened]
|
||||
|
||||
## Error Messages
|
||||
```
|
||||
[Exact error text]
|
||||
```
|
||||
|
||||
## Environment
|
||||
- Version: [version]
|
||||
- Project: [name]
|
||||
- Timestamp: [when]
|
||||
|
||||
## Severity
|
||||
- [ ] Critical (blocks major functionality)
|
||||
- [ ] High (impacts user experience)
|
||||
- [ ] Medium (workaround available)
|
||||
- [ ] Low (minor inconvenience)
|
||||
|
||||
## Relations
|
||||
- discovered_during [[Test Session [Phase]]]
|
||||
- affects [[Feature Name]]
|
||||
```
|
||||
|
||||
## Success Metrics Tracking
|
||||
|
||||
**Quantitative Measures:**
|
||||
- Test scenario completion rate
|
||||
- Bug discovery count with severity
|
||||
- Performance benchmark establishment
|
||||
- Tool coverage completeness
|
||||
|
||||
**Qualitative Measures:**
|
||||
- Conversation flow naturalness
|
||||
- Knowledge graph quality
|
||||
- User experience insights
|
||||
- System reliability assessment
|
||||
|
||||
## Test Execution Flow
|
||||
|
||||
1. **Setup Phase** (5 minutes)
|
||||
- Verify environment and create test project
|
||||
- Record baseline system state
|
||||
- Establish performance benchmarks
|
||||
|
||||
2. **Core Testing** (15-20 minutes per phase)
|
||||
- Execute test scenarios systematically
|
||||
- Record observations immediately
|
||||
- Note timestamps for performance tracking
|
||||
- Explore variations when interesting behaviors occur
|
||||
|
||||
3. **Documentation** (5 minutes per phase)
|
||||
- Create phase summary note
|
||||
- Link related test observations
|
||||
- Update running issues list
|
||||
- Record enhancement ideas
|
||||
|
||||
4. **Analysis Phase** (10 minutes)
|
||||
- Review all observations across phases
|
||||
- Identify patterns and trends
|
||||
- Create comprehensive summary report
|
||||
- Generate development recommendations
|
||||
|
||||
## Expected Outcomes
|
||||
|
||||
**System Validation:**
|
||||
- v0.13.0 feature verification in real usage
|
||||
- Edge case discovery beyond unit tests
|
||||
- Performance baseline establishment
|
||||
- Bug identification with reproduction cases
|
||||
|
||||
**Knowledge Base Creation:**
|
||||
- Comprehensive testing documentation
|
||||
- Real usage examples for user guides
|
||||
- Edge case scenarios for future testing
|
||||
- Performance insights for optimization
|
||||
|
||||
**Development Insights:**
|
||||
- Prioritized bug fix list
|
||||
- Enhancement ideas from real usage
|
||||
- Architecture validation results
|
||||
- User experience improvement areas
|
||||
|
||||
## Post-Test Deliverables
|
||||
|
||||
1. **Test Summary Note**
|
||||
- Overall results and findings
|
||||
- Critical issues requiring immediate attention
|
||||
- Enhancement opportunities discovered
|
||||
- System readiness assessment
|
||||
|
||||
2. **Bug Report Collection**
|
||||
- All discovered issues with reproduction steps
|
||||
- Severity and impact assessments
|
||||
- Suggested fixes where applicable
|
||||
|
||||
3. **Performance Baseline**
|
||||
- Timing data for all operations
|
||||
- Scaling behavior observations
|
||||
- Resource usage patterns
|
||||
|
||||
4. **UX Improvement Recommendations**
|
||||
- Usability enhancement suggestions
|
||||
- Documentation improvement areas
|
||||
- Tool design optimization ideas
|
||||
|
||||
5. **Updated TESTING.md**
|
||||
- Incorporate new test scenarios discovered
|
||||
- Update based on real execution experience
|
||||
- Add performance benchmarks and targets
|
||||
|
||||
## Context
|
||||
- Uses installed basic-memory version (not development)
|
||||
- Tests complete MCP→API→DB→File stack
|
||||
- Creates living documentation in Basic Memory itself
|
||||
- Follows integration over isolation philosophy
|
||||
- Focuses on real usage patterns over checklist validation
|
||||
- Generates actionable insights for development team
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
issues: read
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Check organization membership
|
||||
- name: Check user permissions
|
||||
id: check_membership
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
@@ -41,29 +41,62 @@ jobs:
|
||||
actor = context.payload.issue.user.login;
|
||||
}
|
||||
|
||||
console.log(`Checking membership for user: ${actor}`);
|
||||
console.log(`Checking permissions for user: ${actor}`);
|
||||
|
||||
// List of explicitly allowed users (organization members)
|
||||
const allowedUsers = [
|
||||
'phernandez',
|
||||
'groksrc',
|
||||
'nellins',
|
||||
'bm-claudeai'
|
||||
];
|
||||
|
||||
if (allowedUsers.includes(actor)) {
|
||||
console.log(`User ${actor} is in the allowed list`);
|
||||
core.setOutput('is_member', true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: Check if user has repository permissions
|
||||
try {
|
||||
const membership = await github.rest.orgs.getMembershipForUser({
|
||||
org: 'basicmachines-co',
|
||||
const collaboration = await github.rest.repos.getCollaboratorPermissionLevel({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
username: actor
|
||||
});
|
||||
|
||||
console.log(`Membership status: ${membership.data.state}`);
|
||||
const permission = collaboration.data.permission;
|
||||
console.log(`User ${actor} has permission level: ${permission}`);
|
||||
|
||||
// Allow if user is a member (public or private) or admin
|
||||
const allowed = membership.data.state === 'active' &&
|
||||
(membership.data.role === 'member' || membership.data.role === 'admin');
|
||||
// Allow if user has push access or higher (write, maintain, admin)
|
||||
const allowed = ['write', 'maintain', 'admin'].includes(permission);
|
||||
|
||||
core.setOutput('is_member', allowed);
|
||||
|
||||
if (!allowed) {
|
||||
core.notice(`User ${actor} is not a member of basicmachines-co organization`);
|
||||
core.notice(`User ${actor} does not have sufficient repository permissions (has: ${permission})`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Error checking membership: ${error.message}`);
|
||||
core.setOutput('is_member', false);
|
||||
core.notice(`User ${actor} is not a member of basicmachines-co organization`);
|
||||
console.log(`Error checking permissions: ${error.message}`);
|
||||
|
||||
// Final fallback: Check if user is a public member of the organization
|
||||
try {
|
||||
const membership = await github.rest.orgs.getMembershipForUser({
|
||||
org: 'basicmachines-co',
|
||||
username: actor
|
||||
});
|
||||
|
||||
const allowed = membership.data.state === 'active';
|
||||
core.setOutput('is_member', allowed);
|
||||
|
||||
if (!allowed) {
|
||||
core.notice(`User ${actor} is not a public member of basicmachines-co organization`);
|
||||
}
|
||||
} catch (membershipError) {
|
||||
console.log(`Error checking organization membership: ${membershipError.message}`);
|
||||
core.setOutput('is_member', false);
|
||||
core.notice(`User ${actor} does not have access to this repository`);
|
||||
}
|
||||
}
|
||||
|
||||
- name: Checkout repository
|
||||
@@ -78,4 +111,4 @@ jobs:
|
||||
uses: anthropics/claude-code-action@beta
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
allowed_tools: Bash(uv run pytest),Bash(uv run ruff check . --fix),Bash(uv run ruff format .),Bash(uv run pyright),Bash(make test),Bash(make lint),Bash(make format),Bash(make type-check),Bash(make check),Read,Write,Edit,MultiEdit,Glob,Grep,LS
|
||||
allowed_tools: Bash(uv run pytest),Bash(uv run ruff check . --fix),Bash(uv run ruff format .),Bash(uv run pyright),Bash(just test),Bash(just lint),Bash(just format),Bash(just type-check),Bash(just check),Read,Write,Edit,MultiEdit,Glob,Grep,LS
|
||||
@@ -32,17 +32,11 @@ jobs:
|
||||
uv sync
|
||||
uv build
|
||||
|
||||
- name: Verify version matches tag
|
||||
- name: Verify build succeeded
|
||||
run: |
|
||||
# Get version from built package
|
||||
PACKAGE_VERSION=$(uv run python -c "import basic_memory; print(basic_memory.__version__)")
|
||||
TAG_VERSION=${GITHUB_REF_NAME#v} # Remove 'v' prefix from tag
|
||||
echo "Package version: $PACKAGE_VERSION"
|
||||
echo "Tag version: $TAG_VERSION"
|
||||
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
|
||||
echo "Version mismatch! Package: $PACKAGE_VERSION, Tag: $TAG_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
# Verify that build artifacts exist
|
||||
ls -la dist/
|
||||
echo "Build completed successfully"
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
|
||||
@@ -35,6 +35,10 @@ jobs:
|
||||
run: |
|
||||
pip install uv
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
|
||||
|
||||
- name: Create virtual env
|
||||
run: |
|
||||
uv venv
|
||||
@@ -45,9 +49,9 @@ jobs:
|
||||
|
||||
- name: Run type checks
|
||||
run: |
|
||||
uv run make type-check
|
||||
just type-check
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
uv pip install pytest pytest-cov
|
||||
uv run make test
|
||||
just test
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ ENV/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
/.coverage.*
|
||||
.coverage.*
|
||||
|
||||
# obsidian docs:
|
||||
/docs/.obsidian/
|
||||
@@ -52,4 +52,4 @@ ENV/
|
||||
|
||||
# claude action
|
||||
claude-output
|
||||
**/.claude/settings.local.json
|
||||
**/.claude/settings.local.json
|
||||
+229
-63
@@ -1,80 +1,246 @@
|
||||
# CHANGELOG
|
||||
|
||||
|
||||
## v0.13.0 (2025-06-03)
|
||||
|
||||
### Features
|
||||
|
||||
- **Multi-Project Management System** - Switch between projects instantly during conversations
|
||||
([`993e88a`](https://github.com/basicmachines-co/basic-memory/commit/993e88a))
|
||||
- Instant project switching with session context
|
||||
- Project-specific operations and isolation
|
||||
- Project discovery and management tools
|
||||
|
||||
- **Advanced Note Editing** - Incremental editing with append, prepend, find/replace, and section operations
|
||||
([`6fc3904`](https://github.com/basicmachines-co/basic-memory/commit/6fc3904))
|
||||
- `edit_note` tool with multiple operation types
|
||||
- Smart frontmatter-aware editing
|
||||
- Validation and error handling
|
||||
|
||||
- **Smart File Management** - Move notes with database consistency and search reindexing
|
||||
([`9fb931c`](https://github.com/basicmachines-co/basic-memory/commit/9fb931c))
|
||||
- `move_note` tool with rollback protection
|
||||
- Automatic folder creation and permalink updates
|
||||
- Full database consistency maintenance
|
||||
|
||||
- **Enhanced Search Capabilities** - Frontmatter tags now searchable, improved content discovery
|
||||
([`3f5368e`](https://github.com/basicmachines-co/basic-memory/commit/3f5368e))
|
||||
- YAML frontmatter tag indexing
|
||||
- Improved FTS5 search functionality
|
||||
- Project-scoped search operations
|
||||
|
||||
- **Production Features** - OAuth authentication, development builds, comprehensive testing
|
||||
([`5f8d945`](https://github.com/basicmachines-co/basic-memory/commit/5f8d945))
|
||||
- Development build automation
|
||||
- MCP integration testing framework
|
||||
- Enhanced CI/CD pipeline
|
||||
## v0.13.1 (2025-06-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **#118**: Fix YAML tag formatting to follow standard specification
|
||||
([`2dc7e27`](https://github.com/basicmachines-co/basic-memory/commit/2dc7e27))
|
||||
- **CLI**: Fixed `basic-memory project` project management commands that were not working in v0.13.0 (#129)
|
||||
- **Projects**: Resolved case sensitivity issues when switching between projects that caused "Project not found" errors (#127)
|
||||
- **API**: Standardized CLI project command endpoints and improved error handling
|
||||
- **Core**: Implemented consistent project name handling using permalinks to avoid case-related conflicts
|
||||
|
||||
- **#110**: Make --project flag work consistently across CLI commands
|
||||
([`02dd91a`](https://github.com/basicmachines-co/basic-memory/commit/02dd91a))
|
||||
### Changes
|
||||
|
||||
- **#93**: Respect custom permalinks in frontmatter for write_note
|
||||
([`6b6fd76`](https://github.com/basicmachines-co/basic-memory/commit/6b6fd76))
|
||||
- Renamed `basic-memory project sync` command to `basic-memory project sync-config` for clarity
|
||||
- Improved project switching reliability across different case variations
|
||||
- Removed redundant server status messages from CLI error outputs
|
||||
|
||||
- Fix list_directory path display to not include leading slash
|
||||
([`6057126`](https://github.com/basicmachines-co/basic-memory/commit/6057126))
|
||||
## v0.13.0 (2025-06-11)
|
||||
|
||||
### Technical Improvements
|
||||
### Overview
|
||||
|
||||
- **Unified Database Architecture** - Single app-level database for better performance
|
||||
- Migration from per-project databases to unified structure
|
||||
- Project isolation with foreign key relationships
|
||||
- Optimized queries and reduced file I/O
|
||||
Basic Memory v0.13.0 is a **major release** that transforms Basic Memory into a true multi-project knowledge management system. This release introduces fluid project switching, advanced note editing capabilities, robust file management, and production-ready OAuth authentication - all while maintaining full backward compatibility.
|
||||
|
||||
- **Comprehensive Testing** - 100% test coverage with integration testing
|
||||
([`468a22f`](https://github.com/basicmachines-co/basic-memory/commit/468a22f))
|
||||
- MCP integration test suite
|
||||
- End-to-end testing framework
|
||||
- Performance and edge case validation
|
||||
**What's New for Users:**
|
||||
- 🎯 **Switch between projects instantly** during conversations with Claude
|
||||
- ✏️ **Edit notes incrementally** without rewriting entire documents
|
||||
- 📁 **Move and organize notes** with full database consistency
|
||||
- 📖 **View notes as formatted artifacts** for better readability in Claude Desktop
|
||||
- 🔍 **Search frontmatter tags** to discover content more easily
|
||||
- 🔐 **OAuth authentication** for secure remote access
|
||||
- ⚡ **Development builds** automatically published for beta testing
|
||||
|
||||
### Documentation
|
||||
**Key v0.13.0 Accomplishments:**
|
||||
- ✅ **Complete Project Management System** - Project switching and project-specific operations
|
||||
- ✅ **Advanced Note Editing** - Incremental editing with append, prepend, find/replace, and section operations
|
||||
- ✅ **View Notes as Artifacts in Claude Desktop/Web** - Use the view_note tool to view a note as an artifact
|
||||
- ✅ **File Management System** - Full move operations with database consistency and rollback protection
|
||||
- ✅ **Enhanced Search Capabilities** - Frontmatter tags now searchable, improved content discoverability
|
||||
- ✅ **Unified Database Architecture** - Single app-level database for better performance and project management
|
||||
|
||||
- Add comprehensive testing documentation (TESTING.md)
|
||||
- Update project management guides (PROJECT_MANAGEMENT.md)
|
||||
- Enhanced note editing documentation (EDIT_NOTE.md)
|
||||
- Updated release workflow documentation
|
||||
### Major Features
|
||||
|
||||
### Breaking Changes
|
||||
#### 1. Multiple Project Management
|
||||
|
||||
**Switch between projects instantly during conversations:**
|
||||
|
||||
```
|
||||
💬 "What projects do I have?"
|
||||
🤖 Available projects:
|
||||
• main (current, default)
|
||||
• work-notes
|
||||
• personal-journal
|
||||
• code-snippets
|
||||
|
||||
💬 "Switch to work-notes"
|
||||
🤖 ✓ Switched to work-notes project
|
||||
|
||||
Project Summary:
|
||||
• 47 entities
|
||||
• 125 observations
|
||||
• 23 relations
|
||||
|
||||
💬 "What did I work on yesterday?"
|
||||
🤖 [Shows recent activity from work-notes project]
|
||||
```
|
||||
|
||||
**Key Capabilities:**
|
||||
- **Instant Project Switching**: Change project context mid-conversation without restart
|
||||
- **Project-Specific Operations**: Operations work within the currently active project context
|
||||
- **Project Discovery**: List all available projects with status indicators
|
||||
- **Session Context**: Maintains active project throughout conversation
|
||||
- **Backward Compatibility**: Existing single-project setups continue to work seamlessly
|
||||
|
||||
#### 2. Advanced Note Editing
|
||||
|
||||
**Edit notes incrementally without rewriting entire documents:**
|
||||
|
||||
```python
|
||||
# Append new sections to existing notes
|
||||
edit_note("project-planning", "append", "\n## New Requirements\n- Feature X\n- Feature Y")
|
||||
|
||||
# Prepend timestamps to meeting notes
|
||||
edit_note("meeting-notes", "prepend", "## 2025-05-27 Update\n- Progress update...")
|
||||
|
||||
# Replace specific sections under headers
|
||||
edit_note("api-spec", "replace_section", "New implementation details", section="## Implementation")
|
||||
|
||||
# Find and replace with validation
|
||||
edit_note("config", "find_replace", "v0.13.0", find_text="v0.12.0", expected_replacements=2)
|
||||
```
|
||||
|
||||
**Key Capabilities:**
|
||||
- **Append Operations**: Add content to end of notes (most common use case)
|
||||
- **Prepend Operations**: Add content to beginning of notes
|
||||
- **Section Replacement**: Replace content under specific markdown headers
|
||||
- **Find & Replace**: Simple text replacements with occurrence counting
|
||||
- **Smart Error Handling**: Helpful guidance when operations fail
|
||||
- **Project Context**: Works within the active project with session awareness
|
||||
|
||||
#### 3. Smart File Management
|
||||
|
||||
**Move and organize notes:**
|
||||
|
||||
```python
|
||||
# Simple moves with automatic folder creation
|
||||
move_note("my-note", "work/projects/my-note.md")
|
||||
|
||||
# Organize within the active project
|
||||
move_note("shared-doc", "archive/old-docs/shared-doc.md")
|
||||
|
||||
# Rename operations
|
||||
move_note("old-name", "same-folder/new-name.md")
|
||||
```
|
||||
|
||||
**Key Capabilities:**
|
||||
- **Database Consistency**: Updates file paths, permalinks, and checksums automatically
|
||||
- **Search Reindexing**: Maintains search functionality after moves
|
||||
- **Folder Creation**: Automatically creates destination directories
|
||||
- **Project Isolation**: Operates within the currently active project
|
||||
- **Link Preservation**: Maintains internal links and references
|
||||
|
||||
#### 4. Enhanced Search & Discovery
|
||||
|
||||
**Find content more easily with improved search capabilities:**
|
||||
|
||||
- **Frontmatter Tag Search**: Tags from YAML frontmatter are now indexed and searchable
|
||||
- **Improved Content Discovery**: Search across titles, content, tags, and metadata
|
||||
- **Project-Scoped Search**: Search within the currently active project
|
||||
- **Better Search Quality**: Enhanced FTS5 indexing with tag content inclusion
|
||||
|
||||
**Example:**
|
||||
```yaml
|
||||
---
|
||||
title: Coffee Brewing Methods
|
||||
tags: [coffee, brewing, equipment]
|
||||
---
|
||||
```
|
||||
Now searchable by: "coffee", "brewing", "equipment", or "Coffee Brewing Methods"
|
||||
|
||||
#### 5. Unified Database Architecture
|
||||
|
||||
**Single app-level database for better performance and project management:**
|
||||
|
||||
- **Migration from Per-Project DBs**: Moved from multiple SQLite files to single app database
|
||||
- **Project Isolation**: Proper data separation with project_id foreign keys
|
||||
- **Better Performance**: Optimized queries and reduced file I/O
|
||||
|
||||
### Complete MCP Tool Suite
|
||||
|
||||
#### New Project Management Tools
|
||||
- **`list_projects()`** - Discover and list all available projects with status
|
||||
- **`switch_project(project_name)`** - Change active project context during conversations
|
||||
- **`get_current_project()`** - Show currently active project with statistics
|
||||
- **`set_default_project(project_name)`** - Update default project configuration
|
||||
- **`sync_status()`** - Check file synchronization status and background operations
|
||||
|
||||
#### New Note Operations Tools
|
||||
- **`edit_note()`** - Incremental note editing (append, prepend, find/replace, section replace)
|
||||
- **`move_note()`** - Move notes with database consistency and search reindexing
|
||||
- **`view_note()`** - Display notes as formatted artifacts for better readability in Claude Desktop
|
||||
|
||||
#### Enhanced Existing Tools
|
||||
All existing tools now support:
|
||||
- **Session context awareness** (operates within the currently active project)
|
||||
- **Enhanced error messages** with project context metadata
|
||||
- **Improved response formatting** with project information footers
|
||||
- **Project isolation** ensures operations stay within the correct project boundaries
|
||||
|
||||
|
||||
### User Experience Improvements
|
||||
|
||||
#### Installation Options
|
||||
|
||||
**Multiple ways to install and test Basic Memory:**
|
||||
|
||||
```bash
|
||||
# Stable release
|
||||
uv tool install basic-memory
|
||||
|
||||
# Beta/pre-releases
|
||||
uv tool install basic-memory --pre
|
||||
```
|
||||
|
||||
|
||||
#### Bug Fixes & Quality Improvements
|
||||
|
||||
**Major issues resolved in v0.13.0:**
|
||||
|
||||
- **#118**: Fixed YAML tag formatting to follow standard specification
|
||||
- **#110**: Fixed `--project` flag consistency across all CLI commands
|
||||
- **#107**: Fixed write_note update failures with existing notes
|
||||
- **#93**: Fixed custom permalink handling in frontmatter
|
||||
- **#52**: Enhanced search capabilities with frontmatter tag indexing
|
||||
- **FTS5 Search**: Fixed special character handling in search queries
|
||||
- **Error Handling**: Improved error messages and validation across all tools
|
||||
|
||||
### Breaking Changes & Migration
|
||||
|
||||
#### For Existing Users
|
||||
|
||||
**Automatic Migration**: First run will automatically migrate existing data to the new unified database structure. No manual action required.
|
||||
|
||||
**What Changes:**
|
||||
- Database location: Moved to `~/.basic-memory/memory.db` (unified across projects)
|
||||
- Configuration: Projects defined in `~/.basic-memory/config.json` are synced with database
|
||||
|
||||
**What Stays the Same:**
|
||||
- All existing notes and data remain unchanged
|
||||
- Default project behavior maintained for single-project users
|
||||
- All existing MCP tools continue to work without modification
|
||||
|
||||
### Documentation & Resources
|
||||
|
||||
#### New Documentation
|
||||
- [Project Management Guide](docs/Project%20Management.md) - Multi-project workflows
|
||||
- [Note Editing Guide](docs/Note%20Editing.md) - Advanced editing techniques
|
||||
|
||||
#### Updated Documentation
|
||||
- [README.md](README.md) - Installation options and beta build instructions
|
||||
- [CONTRIBUTING.md](CONTRIBUTING.md) - Release process and version management
|
||||
- [CLAUDE.md](CLAUDE.md) - Development workflow and CI/CD documentation
|
||||
- [Claude.ai Integration](docs/Claude.ai%20Integration.md) - Updated MCP tool examples
|
||||
|
||||
#### Quick Start Examples
|
||||
|
||||
**Project Switching:**
|
||||
```
|
||||
💬 "Switch to my work project and show recent activity"
|
||||
🤖 [Calls switch_project("work") then recent_activity()]
|
||||
```
|
||||
|
||||
**Note Editing:**
|
||||
```
|
||||
💬 "Add a section about deployment to my API docs"
|
||||
🤖 [Calls edit_note("api-docs", "append", "## Deployment\n...")]
|
||||
```
|
||||
|
||||
**File Organization:**
|
||||
```
|
||||
💬 "Move my old meeting notes to the archive folder"
|
||||
🤖 [Calls move_note("meeting-notes", "archive/old-meetings.md")]
|
||||
```
|
||||
|
||||
- **Database Migration**: Automatic migration from per-project to unified database.
|
||||
Data will be re-index from the filesystem, resulting in no data loss.
|
||||
- **Configuration Changes**: Projects now synced between config.json and database
|
||||
- **Full Backward Compatibility**: All existing setups continue to work seamlessly
|
||||
|
||||
|
||||
## v0.12.3 (2025-04-17)
|
||||
@@ -861,4 +1027,4 @@ Co-authored-by: phernandez <phernandez@basicmachines.co>
|
||||
### Chores
|
||||
|
||||
- Remove basic-foundation src ref in pyproject.toml
|
||||
([`29fce8b`](https://github.com/basicmachines-co/basic-memory/commit/29fce8b0b922d54d7799bf2534107ee6cfb961b8))
|
||||
([`29fce8b`](https://github.com/basicmachines-co/basic-memory/commit/29fce8b0b922d54d7799bf2534107ee6cfb961b8))
|
||||
@@ -14,15 +14,15 @@ See the [README.md](README.md) file for a project overview.
|
||||
|
||||
### Build and Test Commands
|
||||
|
||||
- Install: `make install` or `pip install -e ".[dev]"`
|
||||
- Run tests: `uv run pytest -p pytest_mock -v` or `make test`
|
||||
- Install: `just install` or `pip install -e ".[dev]"`
|
||||
- Run tests: `uv run pytest -p pytest_mock -v` or `just test`
|
||||
- Single test: `pytest tests/path/to/test_file.py::test_function_name`
|
||||
- Lint: `make lint` or `ruff check . --fix`
|
||||
- Type check: `make type-check` or `uv run pyright`
|
||||
- Format: `make format` or `uv run ruff format .`
|
||||
- Run all code checks: `make check` (runs lint, format, type-check, test)
|
||||
- Create db migration: `make migration m="Your migration message"`
|
||||
- Run development MCP Inspector: `make run-inspector`
|
||||
- Lint: `just lint` or `ruff check . --fix`
|
||||
- Type check: `just type-check` or `uv run pyright`
|
||||
- Format: `just format` or `uv run ruff format .`
|
||||
- Run all code checks: `just check` (runs lint, format, type-check, test)
|
||||
- Create db migration: `just migration "Your migration message"`
|
||||
- Run development MCP Inspector: `just run-inspector`
|
||||
|
||||
### Code Style Guidelines
|
||||
|
||||
|
||||
+10
-8
@@ -15,8 +15,8 @@ project and how to get started as a developer.
|
||||
|
||||
2. **Install Dependencies**:
|
||||
```bash
|
||||
# Using make (recommended)
|
||||
make install
|
||||
# Using just (recommended)
|
||||
just install
|
||||
|
||||
# Or using uv
|
||||
uv install -e ".[dev]"
|
||||
@@ -25,10 +25,12 @@ project and how to get started as a developer.
|
||||
pip install -e ".[dev]"
|
||||
```
|
||||
|
||||
> **Note**: Basic Memory uses [just](https://just.systems) as a modern command runner. Install with `brew install just` or `cargo install just`.
|
||||
|
||||
3. **Run the Tests**:
|
||||
```bash
|
||||
# Run all tests
|
||||
make test
|
||||
just test
|
||||
# or
|
||||
uv run pytest -p pytest_mock -v
|
||||
|
||||
@@ -49,16 +51,16 @@ project and how to get started as a developer.
|
||||
4. **Check Code Quality**:
|
||||
```bash
|
||||
# Run all checks at once
|
||||
make check
|
||||
just check
|
||||
|
||||
# Or run individual checks
|
||||
make lint # Run linting
|
||||
make format # Format code
|
||||
make type-check # Type checking
|
||||
just lint # Run linting
|
||||
just format # Format code
|
||||
just type-check # Type checking
|
||||
```
|
||||
5. **Test Your Changes**: Ensure all tests pass locally and maintain 100% test coverage.
|
||||
```bash
|
||||
make test
|
||||
just test
|
||||
```
|
||||
6. **Submit a PR**: Submit a pull request with a detailed description of your changes.
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
.PHONY: install test test-module lint clean format type-check installer-mac installer-win check test-int
|
||||
|
||||
install:
|
||||
pip install -e ".[dev]"
|
||||
|
||||
test-unit:
|
||||
uv run pytest -p pytest_mock -v
|
||||
|
||||
test-int:
|
||||
uv run pytest -p pytest_mock -v --no-cov test-int
|
||||
|
||||
test: test-unit test-int
|
||||
|
||||
lint:
|
||||
ruff check . --fix
|
||||
|
||||
type-check:
|
||||
uv run pyright
|
||||
|
||||
clean:
|
||||
find . -type f -name '*.pyc' -delete
|
||||
find . -type d -name '__pycache__' -exec rm -r {} +
|
||||
rm -rf installer/build/
|
||||
rm -rf installer/dist/
|
||||
rm -f rw.*.dmg
|
||||
rm -rf dist
|
||||
rm -rf installer/build
|
||||
rm -rf installer/dist
|
||||
rm -f .coverage.*
|
||||
|
||||
format:
|
||||
uv run ruff format .
|
||||
|
||||
# run inspector tool
|
||||
run-inspector:
|
||||
npx @modelcontextprotocol/inspector
|
||||
|
||||
# Build app installer
|
||||
installer-mac:
|
||||
cd installer && chmod +x make_icons.sh && ./make_icons.sh
|
||||
cd installer && uv run python setup.py bdist_mac
|
||||
|
||||
installer-win:
|
||||
cd installer && uv run python setup.py bdist_win32
|
||||
|
||||
|
||||
update-deps:
|
||||
uv lock --upgrade
|
||||
|
||||
check: lint format type-check test
|
||||
|
||||
|
||||
# Target for generating Alembic migrations with a message from command line
|
||||
migration:
|
||||
@if [ -z "$(m)" ]; then \
|
||||
echo "Usage: make migration m=\"Your migration message\""; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
cd src/basic_memory/alembic && alembic revision --autogenerate -m "$(m)"
|
||||
@@ -1,237 +0,0 @@
|
||||
# Release Notes v0.13.0
|
||||
|
||||
## Overview
|
||||
|
||||
Basic Memory v0.13.0 is a **major release** that transforms Basic Memory into a true multi-project knowledge management system. This release introduces fluid project switching, advanced note editing capabilities, robust file management, and production-ready OAuth authentication - all while maintaining full backward compatibility.
|
||||
|
||||
**What's New for Users:**
|
||||
- 🎯 **Switch between projects instantly** during conversations with Claude
|
||||
- ✏️ **Edit notes incrementally** without rewriting entire documents
|
||||
- 📁 **Move and organize notes** with full database consistency
|
||||
- 🔍 **Search frontmatter tags** to discover content more easily
|
||||
- 🔐 **OAuth authentication** for secure remote access
|
||||
- ⚡ **Development builds** automatically published for beta testing
|
||||
|
||||
**Key v0.13.0 Accomplishments:**
|
||||
- ✅ **Complete Project Management System** - Project switching and project-specific operations
|
||||
- ✅ **Advanced Note Editing** - Incremental editing with append, prepend, find/replace, and section operations
|
||||
- ✅ **File Management System** - Full move operations with database consistency and rollback protection
|
||||
- ✅ **Enhanced Search Capabilities** - Frontmatter tags now searchable, improved content discoverability
|
||||
- ✅ **Unified Database Architecture** - Single app-level database for better performance and project management
|
||||
|
||||
## Major Features
|
||||
|
||||
### 1. Multiple Project Management 🎯
|
||||
|
||||
**Switch between projects instantly during conversations:**
|
||||
|
||||
```
|
||||
💬 "What projects do I have?"
|
||||
🤖 Available projects:
|
||||
• main (current, default)
|
||||
• work-notes
|
||||
• personal-journal
|
||||
• code-snippets
|
||||
|
||||
💬 "Switch to work-notes"
|
||||
🤖 ✓ Switched to work-notes project
|
||||
|
||||
Project Summary:
|
||||
• 47 entities
|
||||
• 125 observations
|
||||
• 23 relations
|
||||
|
||||
💬 "What did I work on yesterday?"
|
||||
🤖 [Shows recent activity from work-notes project]
|
||||
```
|
||||
|
||||
**Key Capabilities:**
|
||||
- **Instant Project Switching**: Change project context mid-conversation without restart
|
||||
- **Project-Specific Operations**: Operations work within the currently active project context
|
||||
- **Project Discovery**: List all available projects with status indicators
|
||||
- **Session Context**: Maintains active project throughout conversation
|
||||
- **Backward Compatibility**: Existing single-project setups continue to work seamlessly
|
||||
|
||||
### 2. Advanced Note Editing ✏️
|
||||
|
||||
**Edit notes incrementally without rewriting entire documents:**
|
||||
|
||||
```python
|
||||
# Append new sections to existing notes
|
||||
edit_note("project-planning", "append", "\n## New Requirements\n- Feature X\n- Feature Y")
|
||||
|
||||
# Prepend timestamps to meeting notes
|
||||
edit_note("meeting-notes", "prepend", "## 2025-05-27 Update\n- Progress update...")
|
||||
|
||||
# Replace specific sections under headers
|
||||
edit_note("api-spec", "replace_section", "New implementation details", section="## Implementation")
|
||||
|
||||
# Find and replace with validation
|
||||
edit_note("config", "find_replace", "v0.13.0", find_text="v0.12.0", expected_replacements=2)
|
||||
```
|
||||
|
||||
**Key Capabilities:**
|
||||
- **Append Operations**: Add content to end of notes (most common use case)
|
||||
- **Prepend Operations**: Add content to beginning of notes
|
||||
- **Section Replacement**: Replace content under specific markdown headers
|
||||
- **Find & Replace**: Simple text replacements with occurrence counting
|
||||
- **Smart Error Handling**: Helpful guidance when operations fail
|
||||
- **Project Context**: Works within the active project with session awareness
|
||||
|
||||
### 3. Smart File Management 📁
|
||||
|
||||
**Move and organize notes:**
|
||||
|
||||
```python
|
||||
# Simple moves with automatic folder creation
|
||||
move_note("my-note", "work/projects/my-note.md")
|
||||
|
||||
# Organize within the active project
|
||||
move_note("shared-doc", "archive/old-docs/shared-doc.md")
|
||||
|
||||
# Rename operations
|
||||
move_note("old-name", "same-folder/new-name.md")
|
||||
```
|
||||
|
||||
**Key Capabilities:**
|
||||
- **Database Consistency**: Updates file paths, permalinks, and checksums automatically
|
||||
- **Search Reindexing**: Maintains search functionality after moves
|
||||
- **Folder Creation**: Automatically creates destination directories
|
||||
- **Project Isolation**: Operates within the currently active project
|
||||
- **Link Preservation**: Maintains internal links and references
|
||||
|
||||
### 4. Enhanced Search & Discovery 🔍
|
||||
|
||||
**Find content more easily with improved search capabilities:**
|
||||
|
||||
- **Frontmatter Tag Search**: Tags from YAML frontmatter are now indexed and searchable
|
||||
- **Improved Content Discovery**: Search across titles, content, tags, and metadata
|
||||
- **Project-Scoped Search**: Search within the currently active project
|
||||
- **Better Search Quality**: Enhanced FTS5 indexing with tag content inclusion
|
||||
|
||||
**Example:**
|
||||
```yaml
|
||||
---
|
||||
title: Coffee Brewing Methods
|
||||
tags: [coffee, brewing, equipment]
|
||||
---
|
||||
```
|
||||
Now searchable by: "coffee", "brewing", "equipment", or "Coffee Brewing Methods"
|
||||
|
||||
### 5. Unified Database Architecture 🗄️
|
||||
|
||||
**Single app-level database for better performance and project management:**
|
||||
|
||||
- **Migration from Per-Project DBs**: Moved from multiple SQLite files to single app database
|
||||
- **Project Isolation**: Proper data separation with project_id foreign keys
|
||||
- **Better Performance**: Optimized queries and reduced file I/O
|
||||
|
||||
## Complete MCP Tool Suite 🛠️
|
||||
|
||||
### New Project Management Tools
|
||||
- **`list_projects()`** - Discover and list all available projects with status
|
||||
- **`switch_project(project_name)`** - Change active project context during conversations
|
||||
- **`get_current_project()`** - Show currently active project with statistics
|
||||
- **`set_default_project(project_name)`** - Update default project configuration
|
||||
|
||||
### New Note Operations Tools
|
||||
- **`edit_note()`** - Incremental note editing (append, prepend, find/replace, section replace)
|
||||
- **`move_note()`** - Move notes with database consistency and search reindexing
|
||||
|
||||
### Enhanced Existing Tools
|
||||
All existing tools now support:
|
||||
- **Session context awareness** (operates within the currently active project)
|
||||
- **Enhanced error messages** with project context metadata
|
||||
- **Improved response formatting** with project information footers
|
||||
- **Project isolation** ensures operations stay within the correct project boundaries
|
||||
|
||||
|
||||
## User Experience Improvements
|
||||
|
||||
### Installation Options
|
||||
|
||||
**Multiple ways to install and test Basic Memory:**
|
||||
|
||||
```bash
|
||||
# Stable release
|
||||
uv tool install basic-memory
|
||||
|
||||
# Beta/pre-releases
|
||||
uv tool install basic-memory --pre
|
||||
```
|
||||
|
||||
|
||||
### Bug Fixes & Quality Improvements
|
||||
|
||||
**Major issues resolved in v0.13.0:**
|
||||
|
||||
- **#118**: Fixed YAML tag formatting to follow standard specification
|
||||
- **#110**: Fixed `--project` flag consistency across all CLI commands
|
||||
- **#107**: Fixed write_note update failures with existing notes
|
||||
- **#93**: Fixed custom permalink handling in frontmatter
|
||||
- **#52**: Enhanced search capabilities with frontmatter tag indexing
|
||||
- **FTS5 Search**: Fixed special character handling in search queries
|
||||
- **Error Handling**: Improved error messages and validation across all tools
|
||||
|
||||
## Breaking Changes & Migration
|
||||
|
||||
### For Existing Users
|
||||
|
||||
**Automatic Migration**: First run will automatically migrate existing data to the new unified database structure. No manual action required.
|
||||
|
||||
**What Changes:**
|
||||
- Database location: Moved to `~/.basic-memory/memory.db` (unified across projects)
|
||||
- Configuration: Projects defined in `~/.basic-memory/config.json` are synced with database
|
||||
|
||||
**What Stays the Same:**
|
||||
- All existing notes and data remain unchanged
|
||||
- Default project behavior maintained for single-project users
|
||||
- All existing MCP tools continue to work without modification
|
||||
|
||||
|
||||
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
### New Documentation
|
||||
- [Project Management Guide](docs/Project%20Management.md) - Multi-project workflows
|
||||
- [Note Editing Guide](docs/Note%20Editing.md) - Advanced editing techniques
|
||||
|
||||
### Updated Documentation
|
||||
- [README.md](README.md) - Installation options and beta build instructions
|
||||
- [CONTRIBUTING.md](CONTRIBUTING.md) - Release process and version management
|
||||
- [CLAUDE.md](CLAUDE.md) - Development workflow and CI/CD documentation
|
||||
- [Claude.ai Integration](docs/Claude.ai%20Integration.md) - Updated MCP tool examples
|
||||
|
||||
### Quick Start Examples
|
||||
|
||||
**Project Switching:**
|
||||
```
|
||||
💬 "Switch to my work project and show recent activity"
|
||||
🤖 [Calls switch_project("work") then recent_activity()]
|
||||
```
|
||||
|
||||
**Note Editing:**
|
||||
```
|
||||
💬 "Add a section about deployment to my API docs"
|
||||
🤖 [Calls edit_note("api-docs", "append", "## Deployment\n...")]
|
||||
```
|
||||
|
||||
**File Organization:**
|
||||
```
|
||||
💬 "Move my old meeting notes to the archive folder"
|
||||
🤖 [Calls move_note("meeting-notes", "archive/old-meetings.md")]
|
||||
```
|
||||
|
||||
|
||||
### Getting Updates
|
||||
```bash
|
||||
# Stable releases
|
||||
uv tool upgrade basic-memory
|
||||
|
||||
# Beta releases
|
||||
uv tool install basic-memory --pre --force-reinstall
|
||||
|
||||
# Latest development
|
||||
uv tool install basic-memory --pre --force-reinstall
|
||||
```
|
||||
-337
@@ -1,337 +0,0 @@
|
||||
# Manual Testing Suite for Basic Memory
|
||||
|
||||
This document outlines a comprehensive manual testing approach where an AI assistant (Claude) executes real-world usage scenarios using Basic Memory's MCP tools. The unique aspect: **Basic Memory tests itself** - all test observations and results are recorded as notes in a dedicated test project.
|
||||
|
||||
## Philosophy
|
||||
|
||||
- **Integration over Isolation**: Test the full MCP→API→DB→File stack
|
||||
- **Real Usage Patterns**: Creative exploration, not just checklist validation
|
||||
- **Self-Documenting**: Use Basic Memory to record all test observations
|
||||
- **Living Documentation**: Test results become part of the knowledge base
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Environment Preparation
|
||||
|
||||
```bash
|
||||
# Ensure latest basic-memory is installed
|
||||
pip install --upgrade basic-memory
|
||||
|
||||
# Verify MCP server is available
|
||||
basic-memory --version
|
||||
```
|
||||
|
||||
### 2. MCP Integration Setup
|
||||
|
||||
**Option A: Claude Desktop Integration**
|
||||
```json
|
||||
// Add to ~/.config/claude-desktop/claude_desktop_config.json
|
||||
// or
|
||||
// .mcp.json
|
||||
{
|
||||
"mcpServers": {
|
||||
"basic-memory": {
|
||||
"command": "uv",
|
||||
"args": [
|
||||
"--directory",
|
||||
"/Users/phernandez/dev/basicmachines/basic-memory",
|
||||
"run",
|
||||
"src/basic_memory/cli/main.py",
|
||||
"mcp"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Option B: Claude Code MCP**
|
||||
```bash
|
||||
claude mcp add basic-memory basic-memory mcp
|
||||
```
|
||||
|
||||
### 3. Test Project Creation
|
||||
|
||||
During testing, create a dedicated test project:
|
||||
```
|
||||
- Project name: "basic-memory-testing"
|
||||
- Location: ~/basic-memory-testing
|
||||
- Purpose: Contains all test observations and results
|
||||
```
|
||||
|
||||
## Testing Categories
|
||||
|
||||
### Phase 1: Core Functionality Validation
|
||||
|
||||
**Objective**: Verify all basic operations work correctly
|
||||
|
||||
**Test Areas:**
|
||||
- [ ] **Note Creation**: Various content types, structures, frontmatter
|
||||
- [ ] **Note Reading**: By title, path, memory:// URLs, non-existent notes
|
||||
- [ ] **Search Operations**: Simple queries, boolean operators, tag searches
|
||||
- [ ] **Context Building**: Different depths, timeframes, relation traversal
|
||||
- [ ] **Recent Activity**: Various timeframes, filtering options
|
||||
|
||||
**Success Criteria:**
|
||||
- All operations complete without errors
|
||||
- Files appear correctly in filesystem
|
||||
- Search returns expected results
|
||||
- Context includes appropriate related content
|
||||
|
||||
**Observations to Record:**
|
||||
```markdown
|
||||
# Core Functionality Test Results
|
||||
|
||||
## Test Execution
|
||||
- [timestamp] Test started at 2025-01-06 15:30:00
|
||||
- [setup] Created test project successfully
|
||||
- [environment] MCP connection established
|
||||
|
||||
## write_note Tests
|
||||
- [success] Basic note creation works
|
||||
- [success] Frontmatter tags are preserved
|
||||
- [issue] Special characters in titles need investigation
|
||||
|
||||
## Relations
|
||||
- validates [[Search Operations Test]]
|
||||
- part_of [[Manual Testing Suite]]
|
||||
```
|
||||
|
||||
### Phase 2: v0.13.0 Feature Deep Dive
|
||||
|
||||
**Objective**: Thoroughly test new project management and editing capabilities
|
||||
|
||||
**Project Management Tests:**
|
||||
- [ ] Create multiple projects dynamically
|
||||
- [ ] Switch between projects mid-conversation
|
||||
- [ ] Cross-project operations (create notes in different projects)
|
||||
- [ ] Project discovery and status checking
|
||||
- [ ] Default project behavior
|
||||
|
||||
**Note Editing Tests:**
|
||||
- [ ] Append operations (add content to end)
|
||||
- [ ] Prepend operations (add content to beginning)
|
||||
- [ ] Find/replace operations with validation
|
||||
- [ ] Section replacement under headers
|
||||
- [ ] Edit operations across different projects
|
||||
|
||||
**File Management Tests:**
|
||||
- [ ] Move notes within same project
|
||||
- [ ] Move notes between projects
|
||||
- [ ] Automatic folder creation during moves
|
||||
- [ ] Move operations with special characters
|
||||
- [ ] Database consistency after moves
|
||||
|
||||
**Success Criteria:**
|
||||
- Project switching preserves context correctly
|
||||
- Edit operations modify files as expected
|
||||
- Move operations maintain database consistency
|
||||
- Search indexes update after moves and edits
|
||||
|
||||
### Phase 3: Edge Case Exploration
|
||||
|
||||
**Objective**: Discover limits and handle unusual scenarios gracefully
|
||||
|
||||
**Boundary Testing:**
|
||||
- [ ] Very long note titles and content
|
||||
- [ ] Empty notes and projects
|
||||
- [ ] Special characters: unicode, emojis, symbols
|
||||
- [ ] Deeply nested folder structures
|
||||
- [ ] Circular relations and self-references
|
||||
|
||||
**Error Scenario Testing:**
|
||||
- [ ] Invalid memory:// URLs
|
||||
- [ ] Missing files referenced in database
|
||||
- [ ] Concurrent operations (if possible)
|
||||
- [ ] Invalid project names
|
||||
- [ ] Disk space constraints (if applicable)
|
||||
|
||||
**Performance Testing:**
|
||||
- [ ] Large numbers of notes (100+)
|
||||
- [ ] Complex search queries
|
||||
- [ ] Deep relation chains (5+ levels)
|
||||
- [ ] Rapid successive operations
|
||||
|
||||
### Phase 4: Real-World Workflow Scenarios
|
||||
|
||||
**Objective**: Test realistic usage patterns that users might follow
|
||||
|
||||
**Scenario 1: Meeting Notes Pipeline**
|
||||
1. Create meeting notes with action items
|
||||
2. Extract action items into separate notes
|
||||
3. Link to project planning documents
|
||||
4. Update progress over time using edit operations
|
||||
5. Archive completed items
|
||||
|
||||
**Scenario 2: Research Knowledge Building**
|
||||
1. Create research topic notes
|
||||
2. Build complex relation networks
|
||||
3. Add incremental findings over time
|
||||
4. Search and discover connections
|
||||
5. Reorganize as knowledge grows
|
||||
|
||||
**Scenario 3: Multi-Project Workflow**
|
||||
1. Work project: Technical documentation
|
||||
2. Personal project: Recipe collection
|
||||
3. Learning project: Course notes
|
||||
4. Switch between projects during conversation
|
||||
5. Cross-reference related concepts
|
||||
|
||||
**Scenario 4: Content Evolution**
|
||||
1. Start with basic notes
|
||||
2. Gradually enhance with relations
|
||||
3. Reorganize file structure
|
||||
4. Update existing content incrementally
|
||||
5. Build comprehensive knowledge graph
|
||||
|
||||
### Phase 5: Creative Stress Testing
|
||||
|
||||
**Objective**: Push the system to discover unexpected behaviors
|
||||
|
||||
**Creative Exploration Areas:**
|
||||
- [ ] Rapid project creation and switching
|
||||
- [ ] Unusual but valid markdown structures
|
||||
- [ ] Creative use of observation categories
|
||||
- [ ] Novel relation types and patterns
|
||||
- [ ] Combining tools in unexpected ways
|
||||
|
||||
**Stress Scenarios:**
|
||||
- [ ] Bulk operations (create many notes quickly)
|
||||
- [ ] Complex nested moves and edits
|
||||
- [ ] Deep context building with large graphs
|
||||
- [ ] Search with complex boolean expressions
|
||||
|
||||
## Test Execution Process
|
||||
|
||||
### Pre-Test Checklist
|
||||
- [ ] MCP connection verified
|
||||
- [ ] Test project created
|
||||
- [ ] Baseline notes recorded
|
||||
|
||||
### During Testing
|
||||
1. **Execute test scenarios** using actual MCP tool calls
|
||||
2. **Record observations** immediately in test project
|
||||
3. **Note timestamps** for performance tracking
|
||||
4. **Document any errors** with reproduction steps
|
||||
5. **Explore variations** when something interesting happens
|
||||
|
||||
### Test Observation Format
|
||||
|
||||
Record all observations as Basic Memory notes using this structure:
|
||||
|
||||
```markdown
|
||||
---
|
||||
title: Test Session YYYY-MM-DD HH:MM
|
||||
tags: [testing, session, v0.13.0]
|
||||
---
|
||||
|
||||
# Test Session YYYY-MM-DD HH:MM
|
||||
|
||||
## Test Focus
|
||||
- Primary objective
|
||||
- Features being tested
|
||||
|
||||
## Observations
|
||||
- [success] Feature X worked as expected #functionality
|
||||
- [performance] Operation Y took 2.3 seconds #timing
|
||||
- [issue] Error with special characters #bug
|
||||
- [enhancement] Could improve UX for scenario Z #improvement
|
||||
|
||||
## Discovered Issues
|
||||
- [bug] Description of problem with reproduction steps
|
||||
- [limitation] Current system boundary encountered
|
||||
|
||||
## Relations
|
||||
- tests [[Feature X]]
|
||||
- part_of [[Manual Testing Suite]]
|
||||
- found_issue [[Bug Report: Special Characters]]
|
||||
```
|
||||
|
||||
### Post-Test Analysis
|
||||
- [ ] Review all test observations
|
||||
- [ ] Create summary report with findings
|
||||
- [ ] Identify patterns in successes/failures
|
||||
- [ ] Generate improvement recommendations
|
||||
|
||||
## Success Metrics
|
||||
|
||||
**Quantitative Measures:**
|
||||
- % of test scenarios completed successfully
|
||||
- Number of bugs discovered and documented
|
||||
- Performance benchmarks established
|
||||
- Coverage of all MCP tools and operations
|
||||
|
||||
**Qualitative Measures:**
|
||||
- Natural conversation flow maintained
|
||||
- Knowledge graph quality and connections
|
||||
- User experience insights captured
|
||||
- System reliability under various conditions
|
||||
|
||||
## Expected Outcomes
|
||||
|
||||
**For the System:**
|
||||
- Validation of v0.13.0 features in real usage
|
||||
- Discovery of edge cases not covered by unit tests
|
||||
- Performance baseline establishment
|
||||
- Bug identification with reproduction cases
|
||||
|
||||
**For the Knowledge Base:**
|
||||
- Comprehensive testing documentation
|
||||
- Real usage examples for documentation
|
||||
- Edge case scenarios for future reference
|
||||
- Performance insights and optimization opportunities
|
||||
|
||||
**For Development:**
|
||||
- Priority list for bug fixes
|
||||
- Enhancement ideas from real usage
|
||||
- Validation of architectural decisions
|
||||
- User experience insights
|
||||
|
||||
## Test Reporting
|
||||
|
||||
All test results will be captured in the Basic Memory test project, creating a living knowledge base of:
|
||||
|
||||
- Test execution logs with detailed observations
|
||||
- Bug reports with reproduction steps
|
||||
- Performance benchmarks and timing data
|
||||
- Feature enhancement ideas discovered during testing
|
||||
- Knowledge graphs showing test coverage relationships
|
||||
- Summary reports for development team review
|
||||
|
||||
This approach ensures that the testing process itself validates Basic Memory's core value proposition: effectively capturing, organizing, and connecting knowledge through natural interaction patterns.
|
||||
|
||||
## Things to note
|
||||
|
||||
### User Experience & Usability:
|
||||
- are tool instructions clear with working examples?
|
||||
- Do error messages provide actionable guidance for resolution?
|
||||
- Are response times acceptable for interactive use?
|
||||
- Do tools feel consistent in their parameter patterns and behavior?
|
||||
- Can users easily discover what tools are available and their capabilities?
|
||||
|
||||
### System Behavior:
|
||||
- Does context preservation work as expected across tool calls?
|
||||
- Do memory:// URLs behave intuitively for knowledge navigation?
|
||||
- How well do tools work together in multi-step workflows?
|
||||
- Does the system gracefully handle edge cases and invalid inputs?
|
||||
|
||||
### Documentation Alignment:
|
||||
- does tool output provide clear results and helpful information?
|
||||
- Do actual tool behaviors match their documented descriptions?
|
||||
- Are the examples in tool help accurate and useful?
|
||||
- Do real-world usage patterns align with documented workflows?
|
||||
|
||||
### Mental Model Validation:
|
||||
- Does the system work the way users would naturally expect?
|
||||
- Are there surprising behaviors that break user assumptions?
|
||||
- Can users easily recover from mistakes or wrong turns?
|
||||
- Do the knowledge graph concepts (entities, relations, observations) feel natural?
|
||||
|
||||
### Performance & Reliability:
|
||||
- Do operations complete in reasonable time for the data size?
|
||||
- Is system behavior consistent across multiple test sessions?
|
||||
- How does performance change as the knowledge base grows?
|
||||
- Are there any operations that feel unexpectedly slow?
|
||||
|
||||
---
|
||||
|
||||
**Ready to begin testing?** Start by creating the test project and recording your first observation about the testing setup process itself.
|
||||
@@ -77,22 +77,31 @@ read_note("specs/search-design") # By path
|
||||
read_note("memory://specs/search") # By memory URL
|
||||
```
|
||||
|
||||
**Viewing notes as formatted artifacts (Claude Desktop):**
|
||||
```
|
||||
view_note("Search Design") # Creates readable artifact
|
||||
view_note("specs/search-design") # By permalink
|
||||
view_note("memory://specs/search") # By memory URL
|
||||
```
|
||||
|
||||
**Incremental editing** (v0.13.0):
|
||||
```
|
||||
edit_note(
|
||||
identifier="Search Design",
|
||||
identifier="Search Design", # Must be EXACT title/permalink (strict matching)
|
||||
operation="append", # append, prepend, find_replace, replace_section
|
||||
content="\n## New Section\nContent here..."
|
||||
)
|
||||
```
|
||||
**⚠️ Important:** `edit_note` requires exact identifiers (no fuzzy matching). Use `search_notes()` first if uncertain.
|
||||
|
||||
**File organization** (v0.13.0):
|
||||
```
|
||||
move_note(
|
||||
identifier="Old Note",
|
||||
identifier="Old Note", # Must be EXACT title/permalink (strict matching)
|
||||
destination="archive/old-note.md" # Folders created automatically
|
||||
)
|
||||
```
|
||||
**⚠️ Important:** `move_note` requires exact identifiers (no fuzzy matching). Use `search_notes()` first if uncertain.
|
||||
|
||||
### Project Management (v0.13.0)
|
||||
|
||||
@@ -364,6 +373,20 @@ When creating relations:
|
||||
- If information seems outdated, suggest `basic-memory sync`
|
||||
- Use `recent_activity()` to check if content is current
|
||||
|
||||
**Strict Mode for Edit/Move Operations:**
|
||||
- `edit_note()` and `move_note()` require **exact identifiers** (no fuzzy matching for safety)
|
||||
- If identifier not found: use `search_notes()` first to find the exact title/permalink
|
||||
- Error messages will guide you to find correct identifiers
|
||||
- Example workflow:
|
||||
```
|
||||
# ❌ This might fail if identifier isn't exact
|
||||
edit_note("Meeting Note", "append", "content")
|
||||
|
||||
# ✅ Safe approach: search first, then use exact result
|
||||
results = search_notes("meeting")
|
||||
edit_note("Meeting Notes 2024", "append", "content") # Use exact title from search
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Proactively Record Context**
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
# Basic Memory - Modern Command Runner
|
||||
|
||||
# Install dependencies
|
||||
install:
|
||||
pip install -e ".[dev]"
|
||||
|
||||
# Run unit tests in parallel
|
||||
test-unit:
|
||||
uv run pytest -p pytest_mock -v -n auto
|
||||
|
||||
# Run integration tests in parallel
|
||||
test-int:
|
||||
uv run pytest -p pytest_mock -v --no-cov -n auto test-int
|
||||
|
||||
# Run all tests
|
||||
test: test-unit test-int
|
||||
|
||||
# Lint and fix code
|
||||
lint:
|
||||
ruff check . --fix
|
||||
|
||||
# Type check code
|
||||
type-check:
|
||||
uv run pyright
|
||||
|
||||
# Clean build artifacts and cache files
|
||||
clean:
|
||||
find . -type f -name '*.pyc' -delete
|
||||
find . -type d -name '__pycache__' -exec rm -r {} +
|
||||
rm -rf installer/build/ installer/dist/ dist/
|
||||
rm -f rw.*.dmg .coverage.*
|
||||
|
||||
# Format code with ruff
|
||||
format:
|
||||
uv run ruff format .
|
||||
|
||||
# Run MCP inspector tool
|
||||
run-inspector:
|
||||
npx @modelcontextprotocol/inspector
|
||||
|
||||
# Build macOS installer
|
||||
installer-mac:
|
||||
cd installer && chmod +x make_icons.sh && ./make_icons.sh
|
||||
cd installer && uv run python setup.py bdist_mac
|
||||
|
||||
# Build Windows installer
|
||||
installer-win:
|
||||
cd installer && uv run python setup.py bdist_win32
|
||||
|
||||
# Update all dependencies to latest versions
|
||||
update-deps:
|
||||
uv sync --upgrade
|
||||
|
||||
# Run all code quality checks and tests
|
||||
check: lint format type-check test
|
||||
|
||||
# Generate Alembic migration with descriptive message
|
||||
migration message:
|
||||
cd src/basic_memory/alembic && alembic revision --autogenerate -m "{{message}}"
|
||||
|
||||
# Create a stable release (e.g., just release v0.13.2)
|
||||
release version:
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Validate version format
|
||||
if [[ ! "{{version}}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "❌ Invalid version format. Use: v0.13.2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract version number without 'v' prefix
|
||||
VERSION_NUM=$(echo "{{version}}" | sed 's/^v//')
|
||||
|
||||
echo "🚀 Creating stable release {{version}}"
|
||||
|
||||
# Pre-flight checks
|
||||
echo "📋 Running pre-flight checks..."
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "❌ Uncommitted changes found. Please commit or stash them first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $(git branch --show-current) != "main" ]]; then
|
||||
echo "❌ Not on main branch. Switch to main first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if tag already exists
|
||||
if git tag -l "{{version}}" | grep -q "{{version}}"; then
|
||||
echo "❌ Tag {{version}} already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run quality checks
|
||||
echo "🔍 Running quality checks..."
|
||||
just check
|
||||
|
||||
# Update version in __init__.py
|
||||
echo "📝 Updating version in __init__.py..."
|
||||
sed -i.bak "s/__version__ = \".*\"/__version__ = \"$VERSION_NUM\"/" src/basic_memory/__init__.py
|
||||
rm -f src/basic_memory/__init__.py.bak
|
||||
|
||||
# Commit version update
|
||||
git add src/basic_memory/__init__.py
|
||||
git commit -m "chore: update version to $VERSION_NUM for {{version}} release"
|
||||
|
||||
# Create and push tag
|
||||
echo "🏷️ Creating tag {{version}}..."
|
||||
git tag "{{version}}"
|
||||
|
||||
echo "📤 Pushing to GitHub..."
|
||||
git push origin main
|
||||
git push origin "{{version}}"
|
||||
|
||||
echo "✅ Release {{version}} created successfully!"
|
||||
echo "📦 GitHub Actions will build and publish to PyPI"
|
||||
echo "🔗 Monitor at: https://github.com/basicmachines-co/basic-memory/actions"
|
||||
|
||||
# Create a beta release (e.g., just beta v0.13.2b1)
|
||||
beta version:
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Validate version format (allow beta/rc suffixes)
|
||||
if [[ ! "{{version}}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(b[0-9]+|rc[0-9]+)$ ]]; then
|
||||
echo "❌ Invalid beta version format. Use: v0.13.2b1 or v0.13.2rc1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract version number without 'v' prefix
|
||||
VERSION_NUM=$(echo "{{version}}" | sed 's/^v//')
|
||||
|
||||
echo "🧪 Creating beta release {{version}}"
|
||||
|
||||
# Pre-flight checks
|
||||
echo "📋 Running pre-flight checks..."
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "❌ Uncommitted changes found. Please commit or stash them first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $(git branch --show-current) != "main" ]]; then
|
||||
echo "❌ Not on main branch. Switch to main first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if tag already exists
|
||||
if git tag -l "{{version}}" | grep -q "{{version}}"; then
|
||||
echo "❌ Tag {{version}} already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run quality checks
|
||||
echo "🔍 Running quality checks..."
|
||||
just check
|
||||
|
||||
# Update version in __init__.py
|
||||
echo "📝 Updating version in __init__.py..."
|
||||
sed -i.bak "s/__version__ = \".*\"/__version__ = \"$VERSION_NUM\"/" src/basic_memory/__init__.py
|
||||
rm -f src/basic_memory/__init__.py.bak
|
||||
|
||||
# Commit version update
|
||||
git add src/basic_memory/__init__.py
|
||||
git commit -m "chore: update version to $VERSION_NUM for {{version}} beta release"
|
||||
|
||||
# Create and push tag
|
||||
echo "🏷️ Creating tag {{version}}..."
|
||||
git tag "{{version}}"
|
||||
|
||||
echo "📤 Pushing to GitHub..."
|
||||
git push origin main
|
||||
git push origin "{{version}}"
|
||||
|
||||
echo "✅ Beta release {{version}} created successfully!"
|
||||
echo "📦 GitHub Actions will build and publish to PyPI as pre-release"
|
||||
echo "🔗 Monitor at: https://github.com/basicmachines-co/basic-memory/actions"
|
||||
echo "📥 Install with: uv tool install basic-memory --pre"
|
||||
|
||||
# List all available recipes
|
||||
default:
|
||||
@just --list
|
||||
+4
-8
@@ -28,12 +28,12 @@ dependencies = [
|
||||
"watchfiles>=1.0.4",
|
||||
"fastapi[standard]>=0.115.8",
|
||||
"alembic>=1.14.1",
|
||||
"qasync>=0.27.1",
|
||||
"pillow>=11.1.0",
|
||||
"pybars3>=0.9.7",
|
||||
"fastmcp>=2.3.4",
|
||||
"pyjwt>=2.10.1",
|
||||
"python-dotenv>=1.1.0",
|
||||
"pytest-aio>=1.9.0",
|
||||
]
|
||||
|
||||
|
||||
@@ -69,14 +69,8 @@ dev-dependencies = [
|
||||
"pytest-cov>=4.1.0",
|
||||
"pytest-mock>=3.12.0",
|
||||
"pytest-asyncio>=0.24.0",
|
||||
"pytest-xdist>=3.0.0",
|
||||
"ruff>=0.1.6",
|
||||
"pytest>=8.3.4",
|
||||
"pytest-cov>=4.1.0",
|
||||
"pytest-mock>=3.12.0",
|
||||
"pytest-asyncio>=0.24.0",
|
||||
"ruff>=0.1.6",
|
||||
"cx-freeze>=7.2.10",
|
||||
"pyqt6>=6.8.1",
|
||||
]
|
||||
|
||||
[tool.hatch.version]
|
||||
@@ -124,6 +118,8 @@ omit = [
|
||||
"*/background_sync.py", # Background processes
|
||||
"*/cli/main.py", # CLI entry point
|
||||
"*/mcp/tools/project_management.py", # Covered by integration tests
|
||||
"*/mcp/tools/sync_status.py", # Covered by integration tests
|
||||
"*/services/migration_service.py", # Complex migration scenarios
|
||||
]
|
||||
|
||||
[tool.logfire]
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
"""basic-memory - Local-first knowledge management combining Zettelkasten with knowledge graphs"""
|
||||
|
||||
try:
|
||||
from importlib.metadata import version
|
||||
# Package version - updated by release automation
|
||||
__version__ = "0.13.2"
|
||||
|
||||
__version__ = version("basic-memory")
|
||||
except Exception: # pragma: no cover
|
||||
# Fallback if package not installed (e.g., during development)
|
||||
__version__ = "0.0.0" # pragma: no cover
|
||||
# API version for FastAPI - independent of package version
|
||||
__api_version__ = "v0"
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
"""project constraint fix
|
||||
|
||||
Revision ID: 647e7a75e2cd
|
||||
Revises: 5fe1ab1ccebe
|
||||
Create Date: 2025-06-03 12:48:30.162566
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "647e7a75e2cd"
|
||||
down_revision: Union[str, None] = "5fe1ab1ccebe"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Remove the problematic UNIQUE constraint on is_default column.
|
||||
|
||||
The UNIQUE constraint prevents multiple projects from having is_default=FALSE,
|
||||
which breaks project creation when the service sets is_default=False.
|
||||
|
||||
Since SQLite doesn't support dropping specific constraints easily, we'll
|
||||
recreate the table without the problematic constraint.
|
||||
"""
|
||||
# For SQLite, we need to recreate the table without the UNIQUE constraint
|
||||
# Create a new table without the UNIQUE constraint on is_default
|
||||
op.create_table(
|
||||
"project_new",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=False),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("permalink", sa.String(), nullable=False),
|
||||
sa.Column("path", sa.String(), nullable=False),
|
||||
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||||
sa.Column("is_default", sa.Boolean(), nullable=True), # No UNIQUE constraint!
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("name"),
|
||||
sa.UniqueConstraint("permalink"),
|
||||
)
|
||||
|
||||
# Copy data from old table to new table
|
||||
op.execute("INSERT INTO project_new SELECT * FROM project")
|
||||
|
||||
# Drop the old table
|
||||
op.drop_table("project")
|
||||
|
||||
# Rename the new table
|
||||
op.rename_table("project_new", "project")
|
||||
|
||||
# Recreate the indexes
|
||||
with op.batch_alter_table("project", schema=None) as batch_op:
|
||||
batch_op.create_index("ix_project_created_at", ["created_at"], unique=False)
|
||||
batch_op.create_index("ix_project_name", ["name"], unique=True)
|
||||
batch_op.create_index("ix_project_path", ["path"], unique=False)
|
||||
batch_op.create_index("ix_project_permalink", ["permalink"], unique=True)
|
||||
batch_op.create_index("ix_project_updated_at", ["updated_at"], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Add back the UNIQUE constraint on is_default column.
|
||||
|
||||
WARNING: This will break project creation again if multiple projects
|
||||
have is_default=FALSE.
|
||||
"""
|
||||
# Recreate the table with the UNIQUE constraint
|
||||
op.create_table(
|
||||
"project_old",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=False),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("permalink", sa.String(), nullable=False),
|
||||
sa.Column("path", sa.String(), nullable=False),
|
||||
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||||
sa.Column("is_default", sa.Boolean(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("is_default"), # Add back the problematic constraint
|
||||
sa.UniqueConstraint("name"),
|
||||
sa.UniqueConstraint("permalink"),
|
||||
)
|
||||
|
||||
# Copy data (this may fail if multiple FALSE values exist)
|
||||
op.execute("INSERT INTO project_old SELECT * FROM project")
|
||||
|
||||
# Drop the current table and rename
|
||||
op.drop_table("project")
|
||||
op.rename_table("project_old", "project")
|
||||
|
||||
# Recreate indexes
|
||||
with op.batch_alter_table("project", schema=None) as batch_op:
|
||||
batch_op.create_index("ix_project_created_at", ["created_at"], unique=False)
|
||||
batch_op.create_index("ix_project_name", ["name"], unique=True)
|
||||
batch_op.create_index("ix_project_path", ["path"], unique=False)
|
||||
batch_op.create_index("ix_project_permalink", ["permalink"], unique=True)
|
||||
batch_op.create_index("ix_project_updated_at", ["updated_at"], unique=False)
|
||||
@@ -14,6 +14,7 @@ from basic_memory.deps import (
|
||||
FileServiceDep,
|
||||
ProjectConfigDep,
|
||||
AppConfigDep,
|
||||
SyncServiceDep,
|
||||
)
|
||||
from basic_memory.schemas import (
|
||||
EntityListResponse,
|
||||
@@ -63,6 +64,7 @@ async def create_or_update_entity(
|
||||
entity_service: EntityServiceDep,
|
||||
search_service: SearchServiceDep,
|
||||
file_service: FileServiceDep,
|
||||
sync_service: SyncServiceDep,
|
||||
) -> EntityResponse:
|
||||
"""Create or update an entity. If entity exists, it will be updated, otherwise created."""
|
||||
logger.info(
|
||||
@@ -85,6 +87,17 @@ async def create_or_update_entity(
|
||||
|
||||
# reindex
|
||||
await search_service.index_entity(entity, background_tasks=background_tasks)
|
||||
|
||||
# Attempt immediate relation resolution when creating new entities
|
||||
# This helps resolve forward references when related entities are created in the same session
|
||||
if created:
|
||||
try:
|
||||
await sync_service.resolve_relations()
|
||||
logger.debug(f"Resolved relations after creating entity: {entity.permalink}")
|
||||
except Exception as e: # pragma: no cover
|
||||
# Don't fail the entire request if relation resolution fails
|
||||
logger.warning(f"Failed to resolve relations after entity creation: {e}")
|
||||
|
||||
result = EntityResponse.model_validate(entity)
|
||||
|
||||
logger.info(
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
from typing import Annotated, Optional
|
||||
|
||||
from dateparser import parse
|
||||
from fastapi import APIRouter, Query
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.deps import ContextServiceDep, EntityRepositoryDep
|
||||
from basic_memory.schemas.base import TimeFrame
|
||||
from basic_memory.schemas.base import TimeFrame, parse_timeframe
|
||||
from basic_memory.schemas.memory import (
|
||||
GraphContext,
|
||||
normalize_memory_url,
|
||||
@@ -40,7 +39,7 @@ async def recent(
|
||||
f"Getting recent context: `{types}` depth: `{depth}` timeframe: `{timeframe}` page: `{page}` page_size: `{page_size}` max_related: `{max_related}`"
|
||||
)
|
||||
# Parse timeframe
|
||||
since = parse(timeframe)
|
||||
since = parse_timeframe(timeframe)
|
||||
limit = page_size
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
@@ -78,7 +77,7 @@ async def get_memory_context(
|
||||
memory_url = normalize_memory_url(uri)
|
||||
|
||||
# Parse timeframe
|
||||
since = parse(timeframe) if timeframe else None
|
||||
since = parse_timeframe(timeframe) if timeframe else None
|
||||
limit = page_size
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from fastapi import APIRouter, HTTPException, Path, Body
|
||||
from typing import Optional
|
||||
|
||||
from basic_memory.deps import ProjectServiceDep
|
||||
from basic_memory.deps import ProjectServiceDep, ProjectPathDep
|
||||
from basic_memory.schemas import ProjectInfoResponse
|
||||
from basic_memory.schemas.project_info import (
|
||||
ProjectList,
|
||||
@@ -22,9 +22,10 @@ project_resource_router = APIRouter(prefix="/projects", tags=["project_managemen
|
||||
@project_router.get("/info", response_model=ProjectInfoResponse)
|
||||
async def get_project_info(
|
||||
project_service: ProjectServiceDep,
|
||||
project: ProjectPathDep,
|
||||
) -> ProjectInfoResponse:
|
||||
"""Get comprehensive information about the current Basic Memory project."""
|
||||
return await project_service.get_project_info()
|
||||
"""Get comprehensive information about the specified Basic Memory project."""
|
||||
return await project_service.get_project_info(project)
|
||||
|
||||
|
||||
# Update a project
|
||||
@@ -47,7 +48,7 @@ async def update_project(
|
||||
"""
|
||||
try: # pragma: no cover
|
||||
# Get original project info for the response
|
||||
old_project = ProjectItem(
|
||||
old_project_info = ProjectItem(
|
||||
name=project_name,
|
||||
path=project_service.projects.get(project_name, ""),
|
||||
)
|
||||
@@ -61,7 +62,7 @@ async def update_project(
|
||||
message=f"Project '{project_name}' updated successfully",
|
||||
status="success",
|
||||
default=(project_name == project_service.default_project),
|
||||
old_project=old_project,
|
||||
old_project=old_project_info,
|
||||
new_project=ProjectItem(name=project_name, path=updated_path),
|
||||
)
|
||||
except ValueError as e: # pragma: no cover
|
||||
@@ -111,10 +112,9 @@ async def add_project(
|
||||
Response confirming the project was added
|
||||
"""
|
||||
try: # pragma: no cover
|
||||
await project_service.add_project(project_data.name, project_data.path)
|
||||
|
||||
if project_data.set_default: # pragma: no cover
|
||||
await project_service.set_default_project(project_data.name)
|
||||
await project_service.add_project(
|
||||
project_data.name, project_data.path, set_default=project_data.set_default
|
||||
)
|
||||
|
||||
return ProjectStatusResponse( # pyright: ignore [reportCallIssue]
|
||||
message=f"Project '{project_data.name}' added successfully",
|
||||
|
||||
@@ -5,12 +5,12 @@ It centralizes all prompt formatting logic that was previously in the MCP prompt
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from dateparser import parse
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.api.routers.utils import to_graph_context, to_search_results
|
||||
from basic_memory.api.template_loader import template_loader
|
||||
from basic_memory.schemas.base import parse_timeframe
|
||||
from basic_memory.deps import (
|
||||
ContextServiceDep,
|
||||
EntityRepositoryDep,
|
||||
@@ -51,7 +51,7 @@ async def continue_conversation(
|
||||
f"Generating continue conversation prompt, topic: {request.topic}, timeframe: {request.timeframe}"
|
||||
)
|
||||
|
||||
since = parse(request.timeframe) if request.timeframe else None
|
||||
since = parse_timeframe(request.timeframe) if request.timeframe else None
|
||||
|
||||
# Initialize search results
|
||||
search_results = []
|
||||
|
||||
@@ -9,7 +9,6 @@ from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
from basic_memory.cli.app import app
|
||||
from basic_memory.config import config
|
||||
from basic_memory.mcp.project_session import session
|
||||
from basic_memory.mcp.resources.project_info import project_info
|
||||
import json
|
||||
@@ -24,6 +23,7 @@ from basic_memory.mcp.tools.utils import call_post
|
||||
from basic_memory.schemas.project_info import ProjectStatusResponse
|
||||
from basic_memory.mcp.tools.utils import call_delete
|
||||
from basic_memory.mcp.tools.utils import call_put
|
||||
from basic_memory.utils import generate_permalink
|
||||
|
||||
console = Console()
|
||||
|
||||
@@ -44,11 +44,8 @@ def format_path(path: str) -> str:
|
||||
def list_projects() -> None:
|
||||
"""List all configured projects."""
|
||||
# Use API to list projects
|
||||
|
||||
project_url = config.project_url
|
||||
|
||||
try:
|
||||
response = asyncio.run(call_get(client, f"{project_url}/project/projects"))
|
||||
response = asyncio.run(call_get(client, "/projects/projects"))
|
||||
result = ProjectList.model_validate(response.json())
|
||||
|
||||
table = Table(title="Basic Memory Projects")
|
||||
@@ -65,7 +62,6 @@ def list_projects() -> None:
|
||||
console.print(table)
|
||||
except Exception as e:
|
||||
console.print(f"[red]Error listing projects: {str(e)}[/red]")
|
||||
console.print("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
|
||||
@@ -80,16 +76,14 @@ def add_project(
|
||||
resolved_path = os.path.abspath(os.path.expanduser(path))
|
||||
|
||||
try:
|
||||
project_url = config.project_url
|
||||
data = {"name": name, "path": resolved_path, "set_default": set_default}
|
||||
|
||||
response = asyncio.run(call_post(client, f"{project_url}/project/projects", json=data))
|
||||
response = asyncio.run(call_post(client, "/projects/projects", json=data))
|
||||
result = ProjectStatusResponse.model_validate(response.json())
|
||||
|
||||
console.print(f"[green]{result.message}[/green]")
|
||||
except Exception as e:
|
||||
console.print(f"[red]Error adding project: {str(e)}[/red]")
|
||||
console.print("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Display usage hint
|
||||
@@ -105,15 +99,13 @@ def remove_project(
|
||||
) -> None:
|
||||
"""Remove a project from configuration."""
|
||||
try:
|
||||
project_url = config.project_url
|
||||
|
||||
response = asyncio.run(call_delete(client, f"{project_url}/project/projects/{name}"))
|
||||
project_name = generate_permalink(name)
|
||||
response = asyncio.run(call_delete(client, f"/projects/{project_name}"))
|
||||
result = ProjectStatusResponse.model_validate(response.json())
|
||||
|
||||
console.print(f"[green]{result.message}[/green]")
|
||||
except Exception as e:
|
||||
console.print(f"[red]Error removing project: {str(e)}[/red]")
|
||||
console.print("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Show this message regardless of method used
|
||||
@@ -126,20 +118,16 @@ def set_default_project(
|
||||
) -> None:
|
||||
"""Set the default project and activate it for the current session."""
|
||||
try:
|
||||
project_url = config.project_url
|
||||
project_name = generate_permalink(name)
|
||||
|
||||
response = asyncio.run(call_put(client, f"{project_url}/project/projects/{name}/default"))
|
||||
response = asyncio.run(call_put(client, f"projects/{project_name}/default"))
|
||||
result = ProjectStatusResponse.model_validate(response.json())
|
||||
|
||||
console.print(f"[green]{result.message}[/green]")
|
||||
except Exception as e:
|
||||
console.print(f"[red]Error setting default project: {str(e)}[/red]")
|
||||
console.print("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Always activate it for the current session
|
||||
os.environ["BASIC_MEMORY_PROJECT"] = name
|
||||
|
||||
# Reload configuration to apply the change
|
||||
from importlib import reload
|
||||
from basic_memory import config as config_module
|
||||
@@ -149,21 +137,18 @@ def set_default_project(
|
||||
console.print("[green]Project activated for current session[/green]")
|
||||
|
||||
|
||||
@project_app.command("sync")
|
||||
@project_app.command("sync-config")
|
||||
def synchronize_projects() -> None:
|
||||
"""Synchronize projects between configuration file and database."""
|
||||
"""Synchronize project config between configuration file and database."""
|
||||
# Call the API to synchronize projects
|
||||
|
||||
project_url = config.project_url
|
||||
|
||||
try:
|
||||
response = asyncio.run(call_post(client, f"{project_url}/project/sync"))
|
||||
response = asyncio.run(call_post(client, "/projects/sync"))
|
||||
result = ProjectStatusResponse.model_validate(response.json())
|
||||
|
||||
console.print(f"[green]{result.message}[/green]")
|
||||
except Exception as e: # pragma: no cover
|
||||
console.print(f"[red]Error synchronizing projects: {str(e)}[/red]")
|
||||
console.print("[yellow]Note: Make sure the Basic Memory server is running.[/yellow]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
|
||||
@@ -174,7 +159,7 @@ def display_project_info(
|
||||
"""Display detailed information and statistics about the current project."""
|
||||
try:
|
||||
# Get project info
|
||||
info = asyncio.run(project_info())
|
||||
info = asyncio.run(project_info.fn()) # type: ignore # pyright: ignore [reportAttributeAccessIssue]
|
||||
|
||||
if json_output:
|
||||
# Convert to JSON and print
|
||||
@@ -221,7 +206,7 @@ def display_project_info(
|
||||
console.print(entity_types_table)
|
||||
|
||||
# Most connected entities
|
||||
if info.statistics.most_connected_entities:
|
||||
if info.statistics.most_connected_entities: # pragma: no cover
|
||||
connected_table = Table(title="🔗 Most Connected Entities")
|
||||
connected_table.add_column("Title", style="blue")
|
||||
connected_table.add_column("Permalink", style="cyan")
|
||||
@@ -235,7 +220,7 @@ def display_project_info(
|
||||
console.print(connected_table)
|
||||
|
||||
# Recent activity
|
||||
if info.activity.recently_updated:
|
||||
if info.activity.recently_updated: # pragma: no cover
|
||||
recent_table = Table(title="🕒 Recent Activity")
|
||||
recent_table.add_column("Title", style="blue")
|
||||
recent_table.add_column("Type", style="cyan")
|
||||
|
||||
@@ -122,7 +122,7 @@ def display_changes(project_name: str, title: str, changes: SyncReport, verbose:
|
||||
console.print(Panel(tree, expand=False))
|
||||
|
||||
|
||||
async def run_status(verbose: bool = False):
|
||||
async def run_status(verbose: bool = False): # pragma: no cover
|
||||
"""Check sync status of files vs database."""
|
||||
# Check knowledge/ directory
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ async def run_sync(verbose: bool = False):
|
||||
sync_service = await get_sync_service(project)
|
||||
|
||||
logger.info("Running one-time sync")
|
||||
knowledge_changes = await sync_service.sync(config.home)
|
||||
knowledge_changes = await sync_service.sync(config.home, project_name=project.name)
|
||||
|
||||
# Log results
|
||||
duration_ms = int((time.time() - start_time) * 1000)
|
||||
|
||||
@@ -90,7 +90,7 @@ def write_note(
|
||||
typer.echo("Empty content provided. Please provide non-empty content.", err=True)
|
||||
raise typer.Exit(1)
|
||||
|
||||
note = asyncio.run(mcp_write_note(title, content, folder, tags))
|
||||
note = asyncio.run(mcp_write_note.fn(title, content, folder, tags))
|
||||
rprint(note)
|
||||
except Exception as e: # pragma: no cover
|
||||
if not isinstance(e, typer.Exit):
|
||||
@@ -103,7 +103,7 @@ def write_note(
|
||||
def read_note(identifier: str, page: int = 1, page_size: int = 10):
|
||||
"""Read a markdown note from the knowledge base."""
|
||||
try:
|
||||
note = asyncio.run(mcp_read_note(identifier, page, page_size))
|
||||
note = asyncio.run(mcp_read_note.fn(identifier, page, page_size))
|
||||
rprint(note)
|
||||
except Exception as e: # pragma: no cover
|
||||
if not isinstance(e, typer.Exit):
|
||||
@@ -124,7 +124,7 @@ def build_context(
|
||||
"""Get context needed to continue a discussion."""
|
||||
try:
|
||||
context = asyncio.run(
|
||||
mcp_build_context(
|
||||
mcp_build_context.fn(
|
||||
url=url,
|
||||
depth=depth,
|
||||
timeframe=timeframe,
|
||||
@@ -157,7 +157,7 @@ def recent_activity(
|
||||
"""Get recent activity across the knowledge base."""
|
||||
try:
|
||||
context = asyncio.run(
|
||||
mcp_recent_activity(
|
||||
mcp_recent_activity.fn(
|
||||
type=type, # pyright: ignore [reportArgumentType]
|
||||
depth=depth,
|
||||
timeframe=timeframe,
|
||||
@@ -210,7 +210,7 @@ def search_notes(
|
||||
search_type = "text" if search_type is None else search_type
|
||||
|
||||
results = asyncio.run(
|
||||
mcp_search(
|
||||
mcp_search.fn(
|
||||
query,
|
||||
search_type=search_type,
|
||||
page=page,
|
||||
@@ -241,7 +241,7 @@ def continue_conversation(
|
||||
"""Prompt to continue a previous conversation or work session."""
|
||||
try:
|
||||
# Prompt functions return formatted strings directly
|
||||
session = asyncio.run(mcp_continue_conversation(topic=topic, timeframe=timeframe))
|
||||
session = asyncio.run(mcp_continue_conversation.fn(topic=topic, timeframe=timeframe)) # type: ignore
|
||||
rprint(session)
|
||||
except Exception as e: # pragma: no cover
|
||||
if not isinstance(e, typer.Exit):
|
||||
|
||||
@@ -10,10 +10,12 @@ from basic_memory.mcp.prompts import continue_conversation
|
||||
from basic_memory.mcp.prompts import recent_activity
|
||||
from basic_memory.mcp.prompts import search
|
||||
from basic_memory.mcp.prompts import ai_assistant_guide
|
||||
from basic_memory.mcp.prompts import sync_status
|
||||
|
||||
__all__ = [
|
||||
"ai_assistant_guide",
|
||||
"continue_conversation",
|
||||
"recent_activity",
|
||||
"search",
|
||||
"sync_status",
|
||||
]
|
||||
|
||||
@@ -38,7 +38,7 @@ async def recent_activity_prompt(
|
||||
"""
|
||||
logger.info(f"Getting recent activity, timeframe: {timeframe}")
|
||||
|
||||
recent = await recent_activity(timeframe=timeframe, type=[SearchItemType.ENTITY])
|
||||
recent = await recent_activity.fn(timeframe=timeframe, type=[SearchItemType.ENTITY])
|
||||
|
||||
# Extract primary results from the hierarchical structure
|
||||
primary_results = []
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
"""Sync status prompt for Basic Memory MCP server."""
|
||||
|
||||
from basic_memory.mcp.server import mcp
|
||||
|
||||
|
||||
@mcp.prompt(
|
||||
description="""Get sync status with recommendations for AI assistants.
|
||||
|
||||
This prompt provides both current sync status and guidance on how
|
||||
AI assistants should respond when sync operations are in progress or completed.
|
||||
""",
|
||||
)
|
||||
async def sync_status_prompt() -> str:
|
||||
"""Get sync status with AI assistant guidance.
|
||||
|
||||
This prompt provides detailed sync status information along with
|
||||
recommendations for how AI assistants should handle different sync states.
|
||||
|
||||
Returns:
|
||||
Formatted sync status with AI assistant guidance
|
||||
"""
|
||||
try: # pragma: no cover
|
||||
from basic_memory.services.migration_service import migration_manager
|
||||
|
||||
state = migration_manager.state
|
||||
|
||||
# Build status report
|
||||
lines = [
|
||||
"# Basic Memory Sync Status",
|
||||
"",
|
||||
f"**Current Status**: {state.status.value.replace('_', ' ').title()}",
|
||||
f"**System Ready**: {'Yes' if migration_manager.is_ready else 'No'}",
|
||||
"",
|
||||
]
|
||||
|
||||
if migration_manager.is_ready:
|
||||
lines.extend(
|
||||
[
|
||||
"✅ **All sync operations completed** - System is fully operational",
|
||||
"",
|
||||
"All Basic Memory tools are available and functioning normally.",
|
||||
"File indexing is complete and knowledge graphs are up to date.",
|
||||
"You can proceed with any knowledge management tasks.",
|
||||
]
|
||||
)
|
||||
else:
|
||||
lines.append(f"**Status Message**: {state.message}")
|
||||
|
||||
if state.status.value == "in_progress":
|
||||
if state.projects_total > 0:
|
||||
progress = f" ({state.projects_migrated}/{state.projects_total})"
|
||||
lines.append(f"**Progress**: {progress}")
|
||||
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"🔄 **File synchronization in progress** - Processing files and building knowledge graphs",
|
||||
"",
|
||||
"**Impact**: Some tools may show status messages instead of normal responses",
|
||||
"until sync completes (usually 1-3 minutes).",
|
||||
]
|
||||
)
|
||||
|
||||
elif state.status.value == "failed":
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
f"❌ **Sync failed**: {state.error or 'Unknown error'}",
|
||||
"",
|
||||
"**Impact**: System may have limited functionality until issue is resolved.",
|
||||
]
|
||||
)
|
||||
|
||||
# Add AI assistant recommendations
|
||||
if not migration_manager.is_ready:
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
"## AI Assistant Recommendations",
|
||||
"",
|
||||
"**When sync is in progress:**",
|
||||
"- Inform the user about the background file processing",
|
||||
"- Suggest using `sync_status()` tool to check progress",
|
||||
"- Explain that tools will work normally once sync completes",
|
||||
"- Avoid creating complex workflows until sync is done",
|
||||
"",
|
||||
"**What to tell users:**",
|
||||
"- 'Basic Memory is processing your files and building knowledge graphs'",
|
||||
"- 'This usually takes 1-3 minutes depending on your content size'",
|
||||
"- 'You can check progress anytime with the sync_status tool'",
|
||||
"- 'Full functionality will be available once processing completes'",
|
||||
"",
|
||||
"**User-friendly language:**",
|
||||
"- Say 'processing files' instead of 'migration' or 'sync'",
|
||||
"- Say 'building knowledge graphs' instead of 'indexing'",
|
||||
"- Say 'setting up your knowledge base' instead of 'running migrations'",
|
||||
]
|
||||
)
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
except Exception as e: # pragma: no cover
|
||||
return f"""# Sync Status - Error
|
||||
|
||||
❌ **Unable to check sync status**: {str(e)}
|
||||
|
||||
## AI Assistant Recommendations
|
||||
|
||||
**When status is unavailable:**
|
||||
- Assume the system is likely working normally
|
||||
- Try proceeding with normal operations
|
||||
- If users report issues, suggest checking logs or restarting
|
||||
- Use user-friendly language about 'setting up the knowledge base'
|
||||
"""
|
||||
@@ -31,23 +31,23 @@ load_dotenv()
|
||||
@dataclass
|
||||
class AppContext:
|
||||
watch_task: Optional[asyncio.Task]
|
||||
migration_manager: Optional[Any] = None
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]: # pragma: no cover
|
||||
"""Manage application lifecycle with type-safe context"""
|
||||
# Initialize on startup
|
||||
watch_task = await initialize_app(app_config)
|
||||
# Initialize on startup (now returns migration_manager)
|
||||
migration_manager = await initialize_app(app_config)
|
||||
|
||||
# Initialize project session with default project
|
||||
session.initialize(app_config.default_project)
|
||||
|
||||
try:
|
||||
yield AppContext(watch_task=watch_task)
|
||||
yield AppContext(watch_task=None, migration_manager=migration_manager)
|
||||
finally:
|
||||
# Cleanup on shutdown
|
||||
if watch_task:
|
||||
watch_task.cancel()
|
||||
# Cleanup on shutdown - migration tasks will be cancelled automatically
|
||||
pass
|
||||
|
||||
|
||||
# OAuth configuration function
|
||||
|
||||
@@ -11,12 +11,14 @@ from basic_memory.mcp.tools.read_content import read_content
|
||||
from basic_memory.mcp.tools.build_context import build_context
|
||||
from basic_memory.mcp.tools.recent_activity import recent_activity
|
||||
from basic_memory.mcp.tools.read_note import read_note
|
||||
from basic_memory.mcp.tools.view_note import view_note
|
||||
from basic_memory.mcp.tools.write_note import write_note
|
||||
from basic_memory.mcp.tools.search import search_notes
|
||||
from basic_memory.mcp.tools.canvas import canvas
|
||||
from basic_memory.mcp.tools.list_directory import list_directory
|
||||
from basic_memory.mcp.tools.edit_note import edit_note
|
||||
from basic_memory.mcp.tools.move_note import move_note
|
||||
from basic_memory.mcp.tools.sync_status import sync_status
|
||||
from basic_memory.mcp.tools.project_management import (
|
||||
list_projects,
|
||||
switch_project,
|
||||
@@ -43,5 +45,7 @@ __all__ = [
|
||||
"search_notes",
|
||||
"set_default_project",
|
||||
"switch_project",
|
||||
"sync_status",
|
||||
"view_note",
|
||||
"write_note",
|
||||
]
|
||||
|
||||
@@ -13,7 +13,6 @@ from basic_memory.schemas.memory import (
|
||||
GraphContext,
|
||||
MemoryUrl,
|
||||
memory_url_path,
|
||||
normalize_memory_url,
|
||||
)
|
||||
|
||||
|
||||
@@ -21,12 +20,17 @@ from basic_memory.schemas.memory import (
|
||||
description="""Build context from a memory:// URI to continue conversations naturally.
|
||||
|
||||
Use this to follow up on previous discussions or explore related topics.
|
||||
|
||||
Memory URL Format:
|
||||
- Use paths like "folder/note" or "memory://folder/note"
|
||||
- Pattern matching: "folder/*" matches all notes in folder
|
||||
- Valid characters: letters, numbers, hyphens, underscores, forward slashes
|
||||
- Avoid: double slashes (//), angle brackets (<>), quotes, pipes (|)
|
||||
- Examples: "specs/search", "projects/basic-memory", "notes/*"
|
||||
|
||||
Timeframes support natural language like:
|
||||
- "2 days ago"
|
||||
- "last week"
|
||||
- "today"
|
||||
- "3 months ago"
|
||||
Or standard formats like "7d", "24h"
|
||||
- "2 days ago", "last week", "today", "3 months ago"
|
||||
- Or standard formats like "7d", "24h"
|
||||
""",
|
||||
)
|
||||
async def build_context(
|
||||
@@ -76,7 +80,28 @@ async def build_context(
|
||||
build_context("memory://specs/search", project="work-project")
|
||||
"""
|
||||
logger.info(f"Building context from {url}")
|
||||
url = normalize_memory_url(url)
|
||||
# URL is already validated and normalized by MemoryUrl type annotation
|
||||
|
||||
# Check migration status and wait briefly if needed
|
||||
from basic_memory.mcp.tools.utils import wait_for_migration_or_return_status
|
||||
|
||||
migration_status = await wait_for_migration_or_return_status(timeout=5.0)
|
||||
if migration_status: # pragma: no cover
|
||||
# Return a proper GraphContext with status message
|
||||
from basic_memory.schemas.memory import MemoryMetadata
|
||||
from datetime import datetime
|
||||
|
||||
return GraphContext(
|
||||
results=[],
|
||||
metadata=MemoryMetadata(
|
||||
depth=depth or 1,
|
||||
timeframe=timeframe,
|
||||
generated_at=datetime.now(),
|
||||
primary_count=0,
|
||||
related_count=0,
|
||||
uri=migration_status, # Include status in metadata
|
||||
),
|
||||
)
|
||||
|
||||
active_project = get_active_project(project)
|
||||
project_url = active_project.project_url
|
||||
|
||||
@@ -35,7 +35,8 @@ async def canvas(
|
||||
nodes: List of node objects following JSON Canvas 1.0 spec
|
||||
edges: List of edge objects following JSON Canvas 1.0 spec
|
||||
title: The title of the canvas (will be saved as title.canvas)
|
||||
folder: The folder where the file should be saved
|
||||
folder: Folder path relative to project root where the canvas should be saved.
|
||||
Use forward slashes (/) as separators. Examples: "diagrams", "projects/2025", "visual/maps"
|
||||
project: Optional project name to create canvas in. If not provided, uses current active project.
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from textwrap import dedent
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.mcp.tools.utils import call_delete
|
||||
from basic_memory.mcp.server import mcp
|
||||
from basic_memory.mcp.async_client import client
|
||||
@@ -7,8 +10,148 @@ from basic_memory.mcp.project_session import get_active_project
|
||||
from basic_memory.schemas import DeleteEntitiesResponse
|
||||
|
||||
|
||||
def _format_delete_error_response(error_message: str, identifier: str) -> str:
|
||||
"""Format helpful error responses for delete failures that guide users to successful deletions."""
|
||||
|
||||
# Note not found errors
|
||||
if "entity not found" in error_message.lower() or "not found" in error_message.lower():
|
||||
search_term = identifier.split("/")[-1] if "/" in identifier else identifier
|
||||
title_format = (
|
||||
identifier.split("/")[-1].replace("-", " ").title() if "/" in identifier else identifier
|
||||
)
|
||||
permalink_format = identifier.lower().replace(" ", "-")
|
||||
|
||||
return dedent(f"""
|
||||
# Delete Failed - Note Not Found
|
||||
|
||||
The note '{identifier}' could not be found for deletion.
|
||||
|
||||
## This might mean:
|
||||
1. **Already deleted**: The note may have been deleted previously
|
||||
2. **Wrong identifier**: The identifier format might be incorrect
|
||||
3. **Different project**: The note might be in a different project
|
||||
|
||||
## How to verify:
|
||||
1. **Search for the note**: Use `search_notes("{search_term}")` to find it
|
||||
2. **Try different formats**:
|
||||
- If you used a permalink like "folder/note-title", try just the title: "{title_format}"
|
||||
- If you used a title, try the permalink format: "{permalink_format}"
|
||||
|
||||
3. **Check if already deleted**: Use `list_directory("/")` to see what notes exist
|
||||
4. **Check current project**: Use `get_current_project()` to verify you're in the right project
|
||||
|
||||
## If the note actually exists:
|
||||
```
|
||||
# First, find the correct identifier:
|
||||
search_notes("{identifier}")
|
||||
|
||||
# Then delete using the correct identifier:
|
||||
delete_note("correct-identifier-from-search")
|
||||
```
|
||||
|
||||
## If you want to delete multiple similar notes:
|
||||
Use search to find all related notes and delete them one by one.
|
||||
""").strip()
|
||||
|
||||
# Permission/access errors
|
||||
if (
|
||||
"permission" in error_message.lower()
|
||||
or "access" in error_message.lower()
|
||||
or "forbidden" in error_message.lower()
|
||||
):
|
||||
return f"""# Delete Failed - Permission Error
|
||||
|
||||
You don't have permission to delete '{identifier}': {error_message}
|
||||
|
||||
## How to resolve:
|
||||
1. **Check permissions**: Verify you have delete/write access to this project
|
||||
2. **File locks**: The note might be open in another application
|
||||
3. **Project access**: Ensure you're in the correct project with proper permissions
|
||||
|
||||
## Alternative actions:
|
||||
- Check current project: `get_current_project()`
|
||||
- Switch to correct project: `switch_project("project-name")`
|
||||
- Verify note exists first: `read_note("{identifier}")`
|
||||
|
||||
## If you have read-only access:
|
||||
Send a message to support@basicmachines.co to request deletion, or ask someone with write access to delete the note."""
|
||||
|
||||
# Server/filesystem errors
|
||||
if (
|
||||
"server error" in error_message.lower()
|
||||
or "filesystem" in error_message.lower()
|
||||
or "disk" in error_message.lower()
|
||||
):
|
||||
return f"""# Delete Failed - System Error
|
||||
|
||||
A system error occurred while deleting '{identifier}': {error_message}
|
||||
|
||||
## Immediate steps:
|
||||
1. **Try again**: The error might be temporary
|
||||
2. **Check file status**: Verify the file isn't locked or in use
|
||||
3. **Check disk space**: Ensure the system has adequate storage
|
||||
|
||||
## Troubleshooting:
|
||||
- Verify note exists: `read_note("{identifier}")`
|
||||
- Check project status: `get_current_project()`
|
||||
- Try again in a few moments
|
||||
|
||||
## If problem persists:
|
||||
Send a message to support@basicmachines.co - there may be a filesystem or database issue."""
|
||||
|
||||
# Database/sync errors
|
||||
if "database" in error_message.lower() or "sync" in error_message.lower():
|
||||
return f"""# Delete Failed - Database Error
|
||||
|
||||
A database error occurred while deleting '{identifier}': {error_message}
|
||||
|
||||
## This usually means:
|
||||
1. **Sync conflict**: The file system and database are out of sync
|
||||
2. **Database lock**: Another operation is accessing the database
|
||||
3. **Corrupted entry**: The database entry might be corrupted
|
||||
|
||||
## Steps to resolve:
|
||||
1. **Try again**: Wait a moment and retry the deletion
|
||||
2. **Check note status**: `read_note("{identifier}")` to see current state
|
||||
3. **Manual verification**: Use `list_directory()` to see if file still exists
|
||||
|
||||
## If the note appears gone but database shows it exists:
|
||||
Send a message to support@basicmachines.co - a manual database cleanup may be needed."""
|
||||
|
||||
# Generic fallback
|
||||
return f"""# Delete Failed
|
||||
|
||||
Error deleting note '{identifier}': {error_message}
|
||||
|
||||
## General troubleshooting:
|
||||
1. **Verify the note exists**: `read_note("{identifier}")` or `search_notes("{identifier}")`
|
||||
2. **Check permissions**: Ensure you can edit/delete files in this project
|
||||
3. **Try again**: The error might be temporary
|
||||
4. **Check project**: Make sure you're in the correct project
|
||||
|
||||
## Step-by-step approach:
|
||||
```
|
||||
# 1. Confirm note exists and get correct identifier
|
||||
search_notes("{identifier}")
|
||||
|
||||
# 2. Read the note to verify access
|
||||
read_note("correct-identifier-from-search")
|
||||
|
||||
# 3. Try deletion with correct identifier
|
||||
delete_note("correct-identifier-from-search")
|
||||
```
|
||||
|
||||
## Alternative approaches:
|
||||
- Check what notes exist: `list_directory("/")`
|
||||
- Verify current project: `get_current_project()`
|
||||
- Switch projects if needed: `switch_project("correct-project")`
|
||||
|
||||
## Need help?
|
||||
If the note should be deleted but the operation keeps failing, send a message to support@basicmachines.co."""
|
||||
|
||||
|
||||
@mcp.tool(description="Delete a note by title or permalink")
|
||||
async def delete_note(identifier: str, project: Optional[str] = None) -> bool:
|
||||
async def delete_note(identifier: str, project: Optional[str] = None) -> bool | str:
|
||||
"""Delete a note from the knowledge base.
|
||||
|
||||
Args:
|
||||
@@ -31,6 +174,18 @@ async def delete_note(identifier: str, project: Optional[str] = None) -> bool:
|
||||
active_project = get_active_project(project)
|
||||
project_url = active_project.project_url
|
||||
|
||||
response = await call_delete(client, f"{project_url}/knowledge/entities/{identifier}")
|
||||
result = DeleteEntitiesResponse.model_validate(response.json())
|
||||
return result.deleted
|
||||
try:
|
||||
response = await call_delete(client, f"{project_url}/knowledge/entities/{identifier}")
|
||||
result = DeleteEntitiesResponse.model_validate(response.json())
|
||||
|
||||
if result.deleted:
|
||||
logger.info(f"Successfully deleted note: {identifier}")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"Delete operation completed but note was not deleted: {identifier}")
|
||||
return False
|
||||
|
||||
except Exception as e: # pragma: no cover
|
||||
logger.error(f"Delete failed for '{identifier}': {e}")
|
||||
# Return formatted error message for better user experience
|
||||
return _format_delete_error_response(str(e), identifier)
|
||||
|
||||
@@ -24,14 +24,14 @@ def _format_error_response(
|
||||
if "Entity not found" in error_message or "entity not found" in error_message.lower():
|
||||
return f"""# Edit Failed - Note Not Found
|
||||
|
||||
The note with identifier '{identifier}' could not be found.
|
||||
The note with identifier '{identifier}' could not be found. Edit operations require an exact match (no fuzzy matching).
|
||||
|
||||
## Suggestions to try:
|
||||
1. **Search for the note first**: Use `search_notes("{identifier.split("/")[-1]}")` to find similar notes
|
||||
2. **Try different identifier formats**:
|
||||
- If you used a permalink like "folder/note-title", try just the title: "{identifier.split("/")[-1].replace("-", " ").title()}"
|
||||
- If you used a title, try the permalink format: "{identifier.lower().replace(" ", "-")}"
|
||||
- Use `read_note()` first to verify the note exists and get the correct identifiers
|
||||
1. **Search for the note first**: Use `search_notes("{identifier.split("/")[-1]}")` to find similar notes with exact identifiers
|
||||
2. **Try different exact identifier formats**:
|
||||
- If you used a permalink like "folder/note-title", try the exact title: "{identifier.split("/")[-1].replace("-", " ").title()}"
|
||||
- If you used a title, try the exact permalink format: "{identifier.lower().replace(" ", "-")}"
|
||||
- Use `read_note()` first to verify the note exists and get the exact identifier
|
||||
|
||||
## Alternative approach:
|
||||
Use `write_note()` to create the note first, then edit it."""
|
||||
@@ -142,7 +142,9 @@ async def edit_note(
|
||||
It supports various operations for different editing scenarios.
|
||||
|
||||
Args:
|
||||
identifier: The title, permalink, or memory:// URL of the note to edit
|
||||
identifier: The exact title, permalink, or memory:// URL of the note to edit.
|
||||
Must be an exact match - fuzzy matching is not supported for edit operations.
|
||||
Use search_notes() or read_note() first to find the correct identifier if uncertain.
|
||||
operation: The editing operation to perform:
|
||||
- "append": Add content to the end of the note
|
||||
- "prepend": Add content to the beginning of the note
|
||||
@@ -179,10 +181,14 @@ async def edit_note(
|
||||
# Replace subsection with more specific header
|
||||
edit_note("docs/setup", "replace_section", "Updated install steps\\n", section="### Installation")
|
||||
|
||||
# Using different identifier formats
|
||||
edit_note("Meeting Notes", "append", "\\n- Follow up on action items") # title
|
||||
edit_note("docs/meeting-notes", "append", "\\n- Follow up tasks") # permalink
|
||||
edit_note("docs/Meeting Notes", "append", "\\n- Next steps") # folder/title
|
||||
# Using different identifier formats (must be exact matches)
|
||||
edit_note("Meeting Notes", "append", "\\n- Follow up on action items") # exact title
|
||||
edit_note("docs/meeting-notes", "append", "\\n- Follow up tasks") # exact permalink
|
||||
edit_note("docs/Meeting Notes", "append", "\\n- Next steps") # exact folder/title
|
||||
|
||||
# If uncertain about identifier, search first:
|
||||
# search_notes("meeting") # Find available notes
|
||||
# edit_note("docs/meeting-notes-2025", "append", "content") # Use exact result
|
||||
|
||||
# Add new section to document
|
||||
edit_note("project-plan", "replace_section", "TBD - needs research\\n", section="## Future Work")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Move note tool for Basic Memory MCP server."""
|
||||
|
||||
from textwrap import dedent
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
@@ -11,6 +12,203 @@ from basic_memory.mcp.project_session import get_active_project
|
||||
from basic_memory.schemas import EntityResponse
|
||||
|
||||
|
||||
def _format_move_error_response(error_message: str, identifier: str, destination_path: str) -> str:
|
||||
"""Format helpful error responses for move failures that guide users to successful moves."""
|
||||
|
||||
# Note not found errors
|
||||
if "entity not found" in error_message.lower() or "not found" in error_message.lower():
|
||||
search_term = identifier.split("/")[-1] if "/" in identifier else identifier
|
||||
title_format = (
|
||||
identifier.split("/")[-1].replace("-", " ").title() if "/" in identifier else identifier
|
||||
)
|
||||
permalink_format = identifier.lower().replace(" ", "-")
|
||||
|
||||
return dedent(f"""
|
||||
# Move Failed - Note Not Found
|
||||
|
||||
The note '{identifier}' could not be found for moving. Move operations require an exact match (no fuzzy matching).
|
||||
|
||||
## Suggestions to try:
|
||||
1. **Search for the note first**: Use `search_notes("{search_term}")` to find it with exact identifiers
|
||||
2. **Try different exact identifier formats**:
|
||||
- If you used a permalink like "folder/note-title", try the exact title: "{title_format}"
|
||||
- If you used a title, try the exact permalink format: "{permalink_format}"
|
||||
- Use `read_note()` first to verify the note exists and get the exact identifier
|
||||
|
||||
3. **Check current project**: Use `get_current_project()` to verify you're in the right project
|
||||
4. **List available notes**: Use `list_directory("/")` to see what notes exist
|
||||
|
||||
## Before trying again:
|
||||
```
|
||||
# First, verify the note exists:
|
||||
search_notes("{identifier}")
|
||||
|
||||
# Then use the exact identifier from search results:
|
||||
move_note("correct-identifier-here", "{destination_path}")
|
||||
```
|
||||
""").strip()
|
||||
|
||||
# Destination already exists errors
|
||||
if "already exists" in error_message.lower() or "file exists" in error_message.lower():
|
||||
return f"""# Move Failed - Destination Already Exists
|
||||
|
||||
Cannot move '{identifier}' to '{destination_path}' because a file already exists at that location.
|
||||
|
||||
## How to resolve:
|
||||
1. **Choose a different destination**: Try a different filename or folder
|
||||
- Add timestamp: `{destination_path.rsplit(".", 1)[0] if "." in destination_path else destination_path}-backup.md`
|
||||
- Use different folder: `archive/{destination_path}` or `backup/{destination_path}`
|
||||
|
||||
2. **Check the existing file**: Use `read_note("{destination_path}")` to see what's already there
|
||||
3. **Remove or rename existing**: If safe to do so, move the existing file first
|
||||
|
||||
## Try these alternatives:
|
||||
```
|
||||
# Option 1: Add timestamp to make unique
|
||||
move_note("{identifier}", "{destination_path.rsplit(".", 1)[0] if "." in destination_path else destination_path}-backup.md")
|
||||
|
||||
# Option 2: Use archive folder
|
||||
move_note("{identifier}", "archive/{destination_path}")
|
||||
|
||||
# Option 3: Check what's at destination first
|
||||
read_note("{destination_path}")
|
||||
```"""
|
||||
|
||||
# Invalid path errors
|
||||
if "invalid" in error_message.lower() and "path" in error_message.lower():
|
||||
return f"""# Move Failed - Invalid Destination Path
|
||||
|
||||
The destination path '{destination_path}' is not valid: {error_message}
|
||||
|
||||
## Path requirements:
|
||||
1. **Relative paths only**: Don't start with `/` (use `notes/file.md` not `/notes/file.md`)
|
||||
2. **Include file extension**: Add `.md` for markdown files
|
||||
3. **Use forward slashes**: For folder separators (`folder/subfolder/file.md`)
|
||||
4. **No special characters**: Avoid `\\`, `:`, `*`, `?`, `"`, `<`, `>`, `|`
|
||||
|
||||
## Valid path examples:
|
||||
- `notes/my-note.md`
|
||||
- `projects/2025/meeting-notes.md`
|
||||
- `archive/old-projects/legacy-note.md`
|
||||
|
||||
## Try again with:
|
||||
```
|
||||
move_note("{identifier}", "notes/{destination_path.split("/")[-1] if "/" in destination_path else destination_path}")
|
||||
```"""
|
||||
|
||||
# Permission/access errors
|
||||
if (
|
||||
"permission" in error_message.lower()
|
||||
or "access" in error_message.lower()
|
||||
or "forbidden" in error_message.lower()
|
||||
):
|
||||
return f"""# Move Failed - Permission Error
|
||||
|
||||
You don't have permission to move '{identifier}': {error_message}
|
||||
|
||||
## How to resolve:
|
||||
1. **Check file permissions**: Ensure you have write access to both source and destination
|
||||
2. **Verify project access**: Make sure you have edit permissions for this project
|
||||
3. **Check file locks**: The file might be open in another application
|
||||
|
||||
## Alternative actions:
|
||||
- Check current project: `get_current_project()`
|
||||
- Switch projects if needed: `switch_project("project-name")`
|
||||
- Try copying content instead: `read_note("{identifier}")` then `write_note()` to new location"""
|
||||
|
||||
# Source file not found errors
|
||||
if "source" in error_message.lower() and (
|
||||
"not found" in error_message.lower() or "missing" in error_message.lower()
|
||||
):
|
||||
return f"""# Move Failed - Source File Missing
|
||||
|
||||
The source file for '{identifier}' was not found on disk: {error_message}
|
||||
|
||||
This usually means the database and filesystem are out of sync.
|
||||
|
||||
## How to resolve:
|
||||
1. **Check if note exists in database**: `read_note("{identifier}")`
|
||||
2. **Run sync operation**: The file might need to be re-synced
|
||||
3. **Recreate the file**: If data exists in database, recreate the physical file
|
||||
|
||||
## Troubleshooting steps:
|
||||
```
|
||||
# Check if note exists in Basic Memory
|
||||
read_note("{identifier}")
|
||||
|
||||
# If it exists, the file is missing on disk - send a message to support@basicmachines.co
|
||||
# If it doesn't exist, use search to find the correct identifier
|
||||
search_notes("{identifier}")
|
||||
```"""
|
||||
|
||||
# Server/filesystem errors
|
||||
if (
|
||||
"server error" in error_message.lower()
|
||||
or "filesystem" in error_message.lower()
|
||||
or "disk" in error_message.lower()
|
||||
):
|
||||
return f"""# Move Failed - System Error
|
||||
|
||||
A system error occurred while moving '{identifier}': {error_message}
|
||||
|
||||
## Immediate steps:
|
||||
1. **Try again**: The error might be temporary
|
||||
2. **Check disk space**: Ensure adequate storage is available
|
||||
3. **Verify filesystem permissions**: Check if the destination directory is writable
|
||||
|
||||
## Alternative approaches:
|
||||
- Copy content to new location: Use `read_note("{identifier}")` then `write_note()`
|
||||
- Use a different destination folder that you know works
|
||||
- Send a message to support@basicmachines.co if the problem persists
|
||||
|
||||
## Backup approach:
|
||||
```
|
||||
# Read current content
|
||||
content = read_note("{identifier}")
|
||||
|
||||
# Create new note at desired location
|
||||
write_note("New Note Title", content, "{destination_path.split("/")[0] if "/" in destination_path else "notes"}")
|
||||
|
||||
# Then delete original if successful
|
||||
delete_note("{identifier}")
|
||||
```"""
|
||||
|
||||
# Generic fallback
|
||||
return f"""# Move Failed
|
||||
|
||||
Error moving '{identifier}' to '{destination_path}': {error_message}
|
||||
|
||||
## General troubleshooting:
|
||||
1. **Verify the note exists**: `read_note("{identifier}")` or `search_notes("{identifier}")`
|
||||
2. **Check destination path**: Ensure it's a valid relative path with `.md` extension
|
||||
3. **Verify permissions**: Make sure you can edit files in this project
|
||||
4. **Try a simpler path**: Use a basic folder structure like `notes/filename.md`
|
||||
|
||||
## Step-by-step approach:
|
||||
```
|
||||
# 1. Confirm note exists
|
||||
read_note("{identifier}")
|
||||
|
||||
# 2. Try a simple destination first
|
||||
move_note("{identifier}", "notes/{destination_path.split("/")[-1] if "/" in destination_path else destination_path}")
|
||||
|
||||
# 3. If that works, then try your original destination
|
||||
```
|
||||
|
||||
## Alternative approach:
|
||||
If moving continues to fail, you can copy the content manually:
|
||||
```
|
||||
# Read current content
|
||||
content = read_note("{identifier}")
|
||||
|
||||
# Create new note
|
||||
write_note("Title", content, "target-folder")
|
||||
|
||||
# Delete original once confirmed
|
||||
delete_note("{identifier}")
|
||||
```"""
|
||||
|
||||
|
||||
@mcp.tool(
|
||||
description="Move a note to a new location, updating database and maintaining links.",
|
||||
)
|
||||
@@ -22,7 +220,9 @@ async def move_note(
|
||||
"""Move a note to a new file location within the same project.
|
||||
|
||||
Args:
|
||||
identifier: Entity identifier (title, permalink, or memory:// URL)
|
||||
identifier: Exact entity identifier (title, permalink, or memory:// URL).
|
||||
Must be an exact match - fuzzy matching is not supported for move operations.
|
||||
Use search_notes() or read_note() first to find the correct identifier if uncertain.
|
||||
destination_path: New path relative to project root (e.g., "work/meetings/2025-05-26.md")
|
||||
project: Optional project name (defaults to current session project)
|
||||
|
||||
@@ -30,9 +230,18 @@ async def move_note(
|
||||
Success message with move details
|
||||
|
||||
Examples:
|
||||
- Move to new folder: move_note("My Note", "work/notes/my-note.md")
|
||||
- Move by permalink: move_note("my-note-permalink", "archive/old-notes/my-note.md")
|
||||
- Specify project: move_note("My Note", "archive/my-note.md", project="work-project")
|
||||
# Move to new folder (exact title match)
|
||||
move_note("My Note", "work/notes/my-note.md")
|
||||
|
||||
# Move by exact permalink
|
||||
move_note("my-note-permalink", "archive/old-notes/my-note.md")
|
||||
|
||||
# Specify project with exact identifier
|
||||
move_note("My Note", "archive/my-note.md", project="work-project")
|
||||
|
||||
# If uncertain about identifier, search first:
|
||||
# search_notes("my note") # Find available notes
|
||||
# move_note("docs/my-note-2025", "archive/my-note.md") # Use exact result
|
||||
|
||||
Note: This operation moves notes within the specified project only. Moving notes
|
||||
between different projects is not currently supported.
|
||||
@@ -49,39 +258,42 @@ async def move_note(
|
||||
active_project = get_active_project(project)
|
||||
project_url = active_project.project_url
|
||||
|
||||
# Prepare move request
|
||||
move_data = {
|
||||
"identifier": identifier,
|
||||
"destination_path": destination_path,
|
||||
"project": active_project.name,
|
||||
}
|
||||
try:
|
||||
# Prepare move request
|
||||
move_data = {
|
||||
"identifier": identifier,
|
||||
"destination_path": destination_path,
|
||||
"project": active_project.name,
|
||||
}
|
||||
|
||||
# Call the move API endpoint
|
||||
url = f"{project_url}/knowledge/move"
|
||||
response = await call_post(client, url, json=move_data)
|
||||
result = EntityResponse.model_validate(response.json())
|
||||
# Call the move API endpoint
|
||||
url = f"{project_url}/knowledge/move"
|
||||
response = await call_post(client, url, json=move_data)
|
||||
result = EntityResponse.model_validate(response.json())
|
||||
|
||||
# 10. Build success message
|
||||
result_lines = [
|
||||
"✅ Note moved successfully",
|
||||
"",
|
||||
f"📁 **{identifier}** → **{result.file_path}**",
|
||||
f"🔗 Permalink: {result.permalink}",
|
||||
"📊 Database and search index updated",
|
||||
"",
|
||||
f"<!-- Project: {active_project.name} -->",
|
||||
]
|
||||
# Build success message
|
||||
result_lines = [
|
||||
"✅ Note moved successfully",
|
||||
"",
|
||||
f"📁 **{identifier}** → **{result.file_path}**",
|
||||
f"🔗 Permalink: {result.permalink}",
|
||||
"📊 Database and search index updated",
|
||||
"",
|
||||
f"<!-- Project: {active_project.name} -->",
|
||||
]
|
||||
|
||||
# Return the response text which contains the formatted success message
|
||||
result = "\n".join(result_lines)
|
||||
# Log the operation
|
||||
logger.info(
|
||||
"Move note completed",
|
||||
identifier=identifier,
|
||||
destination_path=destination_path,
|
||||
project=active_project.name,
|
||||
status_code=response.status_code,
|
||||
)
|
||||
|
||||
# Log the operation
|
||||
logger.info(
|
||||
"Move note completed",
|
||||
identifier=identifier,
|
||||
destination_path=destination_path,
|
||||
project=active_project.name,
|
||||
status_code=response.status_code,
|
||||
)
|
||||
return "\n".join(result_lines)
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"Move failed for '{identifier}' to '{destination_path}': {e}")
|
||||
# Return formatted error message for better user experience
|
||||
return _format_move_error_response(str(e), identifier, destination_path)
|
||||
|
||||
@@ -4,6 +4,8 @@ These tools allow users to switch between projects, list available projects,
|
||||
and manage project context during conversations.
|
||||
"""
|
||||
|
||||
from textwrap import dedent
|
||||
|
||||
from fastmcp import Context
|
||||
from loguru import logger
|
||||
|
||||
@@ -14,6 +16,7 @@ from basic_memory.mcp.server import mcp
|
||||
from basic_memory.mcp.tools.utils import call_get, call_put, call_post, call_delete
|
||||
from basic_memory.schemas import ProjectInfoResponse
|
||||
from basic_memory.schemas.project_info import ProjectList, ProjectStatusResponse, ProjectInfoRequest
|
||||
from basic_memory.utils import generate_permalink
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
@@ -75,6 +78,7 @@ async def switch_project(project_name: str, ctx: Context | None = None) -> str:
|
||||
if ctx: # pragma: no cover
|
||||
await ctx.info(f"Switching to project: {project_name}")
|
||||
|
||||
project_permalink = generate_permalink(project_name)
|
||||
current_project = session.get_current_project()
|
||||
try:
|
||||
# Validate project exists by getting project list
|
||||
@@ -82,22 +86,26 @@ async def switch_project(project_name: str, ctx: Context | None = None) -> str:
|
||||
project_list = ProjectList.model_validate(response.json())
|
||||
|
||||
# Check if project exists
|
||||
project_exists = any(p.name == project_name for p in project_list.projects)
|
||||
project_exists = any(p.permalink == project_permalink for p in project_list.projects)
|
||||
if not project_exists:
|
||||
available_projects = [p.name for p in project_list.projects]
|
||||
return f"Error: Project '{project_name}' not found. Available projects: {', '.join(available_projects)}"
|
||||
|
||||
# Switch to the project
|
||||
session.set_current_project(project_name)
|
||||
session.set_current_project(project_permalink)
|
||||
current_project = session.get_current_project()
|
||||
project_config = get_project_config(current_project)
|
||||
|
||||
# Get project info to show summary
|
||||
try:
|
||||
response = await call_get(client, f"{project_config.project_url}/project/info")
|
||||
response = await call_get(
|
||||
client,
|
||||
f"{project_config.project_url}/project/info",
|
||||
params={"project_name": project_permalink},
|
||||
)
|
||||
project_info = ProjectInfoResponse.model_validate(response.json())
|
||||
|
||||
result = f"✓ Switched to {project_name} project\n\n"
|
||||
result = f"✓ Switched to {project_permalink} project\n\n"
|
||||
result += "Project Summary:\n"
|
||||
result += f"• {project_info.statistics.total_entities} entities\n"
|
||||
result += f"• {project_info.statistics.total_observations} observations\n"
|
||||
@@ -115,7 +123,29 @@ async def switch_project(project_name: str, ctx: Context | None = None) -> str:
|
||||
logger.error(f"Error switching to project {project_name}: {e}")
|
||||
# Revert to previous project on error
|
||||
session.set_current_project(current_project)
|
||||
raise e
|
||||
|
||||
# Return user-friendly error message instead of raising exception
|
||||
return dedent(f"""
|
||||
# Project Switch Failed
|
||||
|
||||
Could not switch to project '{project_name}': {str(e)}
|
||||
|
||||
## Current project: {current_project}
|
||||
Your session remains on the previous project.
|
||||
|
||||
## Troubleshooting:
|
||||
1. **Check available projects**: Use `list_projects()` to see valid project names
|
||||
2. **Verify spelling**: Ensure the project name is spelled correctly
|
||||
3. **Check permissions**: Verify you have access to the requested project
|
||||
4. **Try again**: The error might be temporary
|
||||
|
||||
## Available options:
|
||||
- See all projects: `list_projects()`
|
||||
- Stay on current project: `get_current_project()`
|
||||
- Try different project: `switch_project("correct-project-name")`
|
||||
|
||||
If the project should exist but isn't listed, send a message to support@basicmachines.co.
|
||||
""").strip()
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
@@ -139,7 +169,11 @@ async def get_current_project(ctx: Context | None = None) -> str:
|
||||
result = f"Current project: {current_project}\n\n"
|
||||
|
||||
# get project stats
|
||||
response = await call_get(client, f"{project_config.project_url}/project/info")
|
||||
response = await call_get(
|
||||
client,
|
||||
f"{project_config.project_url}/project/info",
|
||||
params={"project_name": current_project},
|
||||
)
|
||||
project_info = ProjectInfoResponse.model_validate(response.json())
|
||||
|
||||
result += f"• {project_info.statistics.total_entities} entities\n"
|
||||
@@ -297,4 +331,4 @@ async def delete_project(project_name: str, ctx: Context | None = None) -> str:
|
||||
result += "Files remain on disk but project is no longer tracked by Basic Memory.\n"
|
||||
result += "Re-add the project to access its content again.\n"
|
||||
|
||||
return add_project_metadata(result, session.get_current_project())
|
||||
return add_project_metadata(result, session.get_current_project())
|
||||
@@ -52,6 +52,13 @@ async def read_note(
|
||||
read_note("Meeting Notes", project="work-project")
|
||||
"""
|
||||
|
||||
# Check migration status and wait briefly if needed
|
||||
from basic_memory.mcp.tools.utils import wait_for_migration_or_return_status
|
||||
|
||||
migration_status = await wait_for_migration_or_return_status(timeout=5.0)
|
||||
if migration_status: # pragma: no cover
|
||||
return f"# System Status\n\n{migration_status}\n\nPlease wait for migration to complete before reading notes."
|
||||
|
||||
active_project = get_active_project(project)
|
||||
project_url = active_project.project_url
|
||||
|
||||
@@ -74,7 +81,7 @@ async def read_note(
|
||||
|
||||
# Fallback 1: Try title search via API
|
||||
logger.info(f"Search title for: {identifier}")
|
||||
title_results = await search_notes(query=identifier, search_type="title", project=project)
|
||||
title_results = await search_notes.fn(query=identifier, search_type="title", project=project)
|
||||
|
||||
if title_results and title_results.results:
|
||||
result = title_results.results[0] # Get the first/best match
|
||||
@@ -98,7 +105,7 @@ async def read_note(
|
||||
|
||||
# Fallback 2: Text search as a last resort
|
||||
logger.info(f"Title search failed, trying text search for: {identifier}")
|
||||
text_results = await search_notes(query=identifier, search_type="text", project=project)
|
||||
text_results = await search_notes.fn(query=identifier, search_type="text", project=project)
|
||||
|
||||
# We didn't find a direct match, construct a helpful error message
|
||||
if not text_results or not text_results.results:
|
||||
@@ -114,7 +121,7 @@ def format_not_found_message(identifier: str) -> str:
|
||||
return dedent(f"""
|
||||
# Note Not Found: "{identifier}"
|
||||
|
||||
I couldn't find any notes matching "{identifier}". Here are some suggestions:
|
||||
I searched for "{identifier}" using multiple methods (direct lookup, title search, and text search) but couldn't find any matching notes. Here are some suggestions:
|
||||
|
||||
## Check Identifier Type
|
||||
- If you provided a title, try using the exact permalink instead
|
||||
@@ -160,7 +167,7 @@ def format_related_results(identifier: str, results) -> str:
|
||||
message = dedent(f"""
|
||||
# Note Not Found: "{identifier}"
|
||||
|
||||
I couldn't find an exact match for "{identifier}", but I found some related notes:
|
||||
I searched for "{identifier}" using direct lookup and title search but couldn't find an exact match. However, I found some related notes through text search:
|
||||
|
||||
""")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Search tools for Basic Memory MCP server."""
|
||||
|
||||
from textwrap import dedent
|
||||
from typing import List, Optional
|
||||
|
||||
from loguru import logger
|
||||
@@ -11,6 +12,162 @@ from basic_memory.mcp.project_session import get_active_project
|
||||
from basic_memory.schemas.search import SearchItemType, SearchQuery, SearchResponse
|
||||
|
||||
|
||||
def _format_search_error_response(error_message: str, query: str, search_type: str = "text") -> str:
|
||||
"""Format helpful error responses for search failures that guide users to successful searches."""
|
||||
|
||||
# FTS5 syntax errors
|
||||
if "syntax error" in error_message.lower() or "fts5" in error_message.lower():
|
||||
clean_query = (
|
||||
query.replace('"', "")
|
||||
.replace("(", "")
|
||||
.replace(")", "")
|
||||
.replace("+", "")
|
||||
.replace("*", "")
|
||||
)
|
||||
return dedent(f"""
|
||||
# Search Failed - Invalid Syntax
|
||||
|
||||
The search query '{query}' contains invalid syntax that the search engine cannot process.
|
||||
|
||||
## Common syntax issues:
|
||||
1. **Special characters**: Characters like `+`, `*`, `"`, `(`, `)` have special meaning in search
|
||||
2. **Unmatched quotes**: Make sure quotes are properly paired
|
||||
3. **Invalid operators**: Check AND, OR, NOT operators are used correctly
|
||||
|
||||
## How to fix:
|
||||
1. **Simplify your search**: Try using simple words instead: `{clean_query}`
|
||||
2. **Remove special characters**: Use alphanumeric characters and spaces
|
||||
3. **Use basic boolean operators**: `word1 AND word2`, `word1 OR word2`, `word1 NOT word2`
|
||||
|
||||
## Examples of valid searches:
|
||||
- Simple text: `project planning`
|
||||
- Boolean AND: `project AND planning`
|
||||
- Boolean OR: `meeting OR discussion`
|
||||
- Boolean NOT: `project NOT archived`
|
||||
- Grouped: `(project OR planning) AND notes`
|
||||
|
||||
## Try again with:
|
||||
```
|
||||
search_notes("INSERT_CLEAN_QUERY_HERE")
|
||||
```
|
||||
|
||||
Replace INSERT_CLEAN_QUERY_HERE with your simplified search terms.
|
||||
""").strip()
|
||||
|
||||
# Project not found errors (check before general "not found")
|
||||
if "project not found" in error_message.lower():
|
||||
return dedent(f"""
|
||||
# Search Failed - Project Not Found
|
||||
|
||||
The current project is not accessible or doesn't exist: {error_message}
|
||||
|
||||
## How to resolve:
|
||||
1. **Check available projects**: `list_projects()`
|
||||
2. **Switch to valid project**: `switch_project("valid-project-name")`
|
||||
3. **Verify project setup**: Ensure your project is properly configured
|
||||
|
||||
## Current session info:
|
||||
- Check current project: `get_current_project()`
|
||||
- See available projects: `list_projects()`
|
||||
""").strip()
|
||||
|
||||
# No results found
|
||||
if "no results" in error_message.lower() or "not found" in error_message.lower():
|
||||
simplified_query = (
|
||||
" ".join(query.split()[:2])
|
||||
if len(query.split()) > 2
|
||||
else query.split()[0]
|
||||
if query.split()
|
||||
else "notes"
|
||||
)
|
||||
return dedent(f"""
|
||||
# Search Complete - No Results Found
|
||||
|
||||
No content found matching '{query}' in the current project.
|
||||
|
||||
## Suggestions to try:
|
||||
1. **Broaden your search**: Try fewer or more general terms
|
||||
- Instead of: `{query}`
|
||||
- Try: `{simplified_query}`
|
||||
|
||||
2. **Check spelling**: Verify terms are spelled correctly
|
||||
3. **Try different search types**:
|
||||
- Text search: `search_notes("{query}", search_type="text")`
|
||||
- Title search: `search_notes("{query}", search_type="title")`
|
||||
- Permalink search: `search_notes("{query}", search_type="permalink")`
|
||||
|
||||
4. **Use boolean operators**:
|
||||
- Try OR search for broader results
|
||||
|
||||
## Check what content exists:
|
||||
- Recent activity: `recent_activity(timeframe="7d")`
|
||||
- List files: `list_directory("/")`
|
||||
- Browse by folder: `list_directory("/notes")` or `list_directory("/docs")`
|
||||
""").strip()
|
||||
|
||||
# Server/API errors
|
||||
if "server error" in error_message.lower() or "internal" in error_message.lower():
|
||||
return dedent(f"""
|
||||
# Search Failed - Server Error
|
||||
|
||||
The search service encountered an error while processing '{query}': {error_message}
|
||||
|
||||
## Immediate steps:
|
||||
1. **Try again**: The error might be temporary
|
||||
2. **Simplify the query**: Use simpler search terms
|
||||
3. **Check project status**: Ensure your project is properly synced
|
||||
|
||||
## Alternative approaches:
|
||||
- Browse files directly: `list_directory("/")`
|
||||
- Check recent activity: `recent_activity(timeframe="7d")`
|
||||
- Try a different search type: `search_notes("{query}", search_type="title")`
|
||||
|
||||
## If the problem persists:
|
||||
The search index might need to be rebuilt. Send a message to support@basicmachines.co or check the project sync status.
|
||||
""").strip()
|
||||
|
||||
# Permission/access errors
|
||||
if (
|
||||
"permission" in error_message.lower()
|
||||
or "access" in error_message.lower()
|
||||
or "forbidden" in error_message.lower()
|
||||
):
|
||||
return f"""# Search Failed - Access Error
|
||||
|
||||
You don't have permission to search in the current project: {error_message}
|
||||
|
||||
## How to resolve:
|
||||
1. **Check your project access**: Verify you have read permissions for this project
|
||||
2. **Switch projects**: Try searching in a different project you have access to
|
||||
3. **Check authentication**: You might need to re-authenticate
|
||||
|
||||
## Alternative actions:
|
||||
- List available projects: `list_projects()`
|
||||
- Switch to accessible project: `switch_project("project-name")`
|
||||
- Check current project: `get_current_project()`"""
|
||||
|
||||
# Generic fallback
|
||||
return f"""# Search Failed
|
||||
|
||||
Error searching for '{query}': {error_message}
|
||||
|
||||
## General troubleshooting:
|
||||
1. **Check your query**: Ensure it uses valid search syntax
|
||||
2. **Try simpler terms**: Use basic words without special characters
|
||||
3. **Verify project access**: Make sure you can access the current project
|
||||
4. **Check recent activity**: `recent_activity(timeframe="7d")` to see if content exists
|
||||
|
||||
## Alternative approaches:
|
||||
- Browse files: `list_directory("/")`
|
||||
- Try different search type: `search_notes("{query}", search_type="title")`
|
||||
- Search with filters: `search_notes("{query}", types=["entity"])`
|
||||
|
||||
## Need help?
|
||||
- View recent changes: `recent_activity()`
|
||||
- List projects: `list_projects()`
|
||||
- Check current project: `get_current_project()`"""
|
||||
|
||||
|
||||
@mcp.tool(
|
||||
description="Search across all content in the knowledge base.",
|
||||
)
|
||||
@@ -23,7 +180,7 @@ async def search_notes(
|
||||
entity_types: Optional[List[str]] = None,
|
||||
after_date: Optional[str] = None,
|
||||
project: Optional[str] = None,
|
||||
) -> SearchResponse:
|
||||
) -> SearchResponse | str:
|
||||
"""Search across all content in the knowledge base.
|
||||
|
||||
This tool searches the knowledge base using full-text search, pattern matching,
|
||||
@@ -113,10 +270,25 @@ async def search_notes(
|
||||
project_url = active_project.project_url
|
||||
|
||||
logger.info(f"Searching for {search_query}")
|
||||
response = await call_post(
|
||||
client,
|
||||
f"{project_url}/search/",
|
||||
json=search_query.model_dump(),
|
||||
params={"page": page, "page_size": page_size},
|
||||
)
|
||||
return SearchResponse.model_validate(response.json())
|
||||
|
||||
try:
|
||||
response = await call_post(
|
||||
client,
|
||||
f"{project_url}/search/",
|
||||
json=search_query.model_dump(),
|
||||
params={"page": page, "page_size": page_size},
|
||||
)
|
||||
result = SearchResponse.model_validate(response.json())
|
||||
|
||||
# Check if we got no results and provide helpful guidance
|
||||
if not result.results:
|
||||
logger.info(f"Search returned no results for query: {query}")
|
||||
# Don't treat this as an error, but the user might want guidance
|
||||
# We return the empty result as normal - the user can decide if they need help
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Search failed for query '{query}': {e}")
|
||||
# Return formatted error message as string for better user experience
|
||||
return _format_search_error_response(str(e), query, search_type)
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
"""Sync status tool for Basic Memory MCP server."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.mcp.server import mcp
|
||||
from basic_memory.mcp.project_session import get_active_project
|
||||
|
||||
|
||||
def _get_all_projects_status() -> list[str]:
|
||||
"""Get status lines for all configured projects."""
|
||||
status_lines = []
|
||||
|
||||
try:
|
||||
from basic_memory.config import app_config
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker
|
||||
|
||||
if app_config.projects:
|
||||
status_lines.extend(["", "---", "", "**All Projects Status:**"])
|
||||
|
||||
for project_name, project_path in app_config.projects.items():
|
||||
# Check if this project has sync status
|
||||
project_sync_status = sync_status_tracker.get_project_status(project_name)
|
||||
|
||||
if project_sync_status:
|
||||
# Project has tracked sync activity
|
||||
if project_sync_status.status.value == "watching":
|
||||
# Project is actively watching for changes (steady state)
|
||||
status_icon = "👁️"
|
||||
status_text = "Watching for changes"
|
||||
elif project_sync_status.status.value == "completed":
|
||||
# Sync completed but not yet watching - transitional state
|
||||
status_icon = "✅"
|
||||
status_text = "Sync completed"
|
||||
elif project_sync_status.status.value in ["scanning", "syncing"]:
|
||||
status_icon = "🔄"
|
||||
status_text = "Sync in progress"
|
||||
if project_sync_status.files_total > 0:
|
||||
progress_pct = (
|
||||
project_sync_status.files_processed
|
||||
/ project_sync_status.files_total
|
||||
) * 100
|
||||
status_text += f" ({project_sync_status.files_processed}/{project_sync_status.files_total}, {progress_pct:.0f}%)"
|
||||
elif project_sync_status.status.value == "failed":
|
||||
status_icon = "❌"
|
||||
status_text = f"Sync error: {project_sync_status.error or 'Unknown error'}"
|
||||
else:
|
||||
status_icon = "⏸️"
|
||||
status_text = project_sync_status.status.value.title()
|
||||
else:
|
||||
# Project has no tracked sync activity - will be synced automatically
|
||||
status_icon = "⏳"
|
||||
status_text = "Pending sync"
|
||||
|
||||
status_lines.append(f"- {status_icon} **{project_name}**: {status_text}")
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Could not get project config for comprehensive status: {e}")
|
||||
|
||||
return status_lines
|
||||
|
||||
|
||||
@mcp.tool(
|
||||
description="""Check the status of file synchronization and background operations.
|
||||
|
||||
Use this tool to:
|
||||
- Check if file sync is in progress or completed
|
||||
- Get detailed sync progress information
|
||||
- Understand if your files are fully indexed
|
||||
- Get specific error details if sync operations failed
|
||||
- Monitor initial project setup and legacy migration
|
||||
|
||||
This covers all sync operations including:
|
||||
- Initial project setup and file indexing
|
||||
- Legacy project migration to unified database
|
||||
- Ongoing file monitoring and updates
|
||||
- Background processing of knowledge graphs
|
||||
""",
|
||||
)
|
||||
async def sync_status(project: Optional[str] = None) -> str:
|
||||
"""Get current sync status and system readiness information.
|
||||
|
||||
This tool provides detailed information about any ongoing or completed
|
||||
sync operations, helping users understand when their files are ready.
|
||||
|
||||
Args:
|
||||
project: Optional project name to get project-specific context
|
||||
|
||||
Returns:
|
||||
Formatted sync status with progress, readiness, and guidance
|
||||
"""
|
||||
logger.info("MCP tool call tool=sync_status")
|
||||
|
||||
status_lines = []
|
||||
|
||||
try:
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker
|
||||
|
||||
# Get overall summary
|
||||
summary = sync_status_tracker.get_summary()
|
||||
is_ready = sync_status_tracker.is_ready
|
||||
|
||||
# Header
|
||||
status_lines.extend(
|
||||
[
|
||||
"# Basic Memory Sync Status",
|
||||
"",
|
||||
f"**Current Status**: {summary}",
|
||||
f"**System Ready**: {'✅ Yes' if is_ready else '🔄 Processing'}",
|
||||
"",
|
||||
]
|
||||
)
|
||||
|
||||
if is_ready:
|
||||
status_lines.extend(
|
||||
[
|
||||
"✅ **All sync operations completed**",
|
||||
"",
|
||||
"- File indexing is complete",
|
||||
"- Knowledge graphs are up to date",
|
||||
"- All Basic Memory tools are fully operational",
|
||||
"",
|
||||
"Your knowledge base is ready for use!",
|
||||
]
|
||||
)
|
||||
|
||||
# Show all projects status even when ready
|
||||
status_lines.extend(_get_all_projects_status())
|
||||
else:
|
||||
# System is still processing - show both active and all projects
|
||||
all_sync_projects = sync_status_tracker.get_all_projects()
|
||||
|
||||
active_projects = [
|
||||
p for p in all_sync_projects.values() if p.status.value in ["scanning", "syncing"]
|
||||
]
|
||||
failed_projects = [p for p in all_sync_projects.values() if p.status.value == "failed"]
|
||||
|
||||
if active_projects:
|
||||
status_lines.extend(
|
||||
[
|
||||
"🔄 **File synchronization in progress**",
|
||||
"",
|
||||
"Basic Memory is automatically processing all configured projects and building knowledge graphs.",
|
||||
"This typically takes 1-3 minutes depending on the amount of content.",
|
||||
"",
|
||||
"**Currently Processing:**",
|
||||
]
|
||||
)
|
||||
|
||||
for project_status in active_projects:
|
||||
progress = ""
|
||||
if project_status.files_total > 0:
|
||||
progress_pct = (
|
||||
project_status.files_processed / project_status.files_total
|
||||
) * 100
|
||||
progress = f" ({project_status.files_processed}/{project_status.files_total}, {progress_pct:.0f}%)"
|
||||
|
||||
status_lines.append(
|
||||
f"- **{project_status.project_name}**: {project_status.message}{progress}"
|
||||
)
|
||||
|
||||
status_lines.extend(
|
||||
[
|
||||
"",
|
||||
"**What's happening:**",
|
||||
"- Scanning and indexing markdown files",
|
||||
"- Building entity and relationship graphs",
|
||||
"- Setting up full-text search indexes",
|
||||
"- Processing file changes and updates",
|
||||
"",
|
||||
"**What you can do:**",
|
||||
"- Wait for automatic processing to complete - no action needed",
|
||||
"- Use this tool again to check progress",
|
||||
"- Simple operations may work already",
|
||||
"- All projects will be available once sync finishes",
|
||||
]
|
||||
)
|
||||
|
||||
# Handle failed projects (independent of active projects)
|
||||
if failed_projects:
|
||||
status_lines.extend(["", "❌ **Some projects failed to sync:**", ""])
|
||||
|
||||
for project_status in failed_projects:
|
||||
status_lines.append(
|
||||
f"- **{project_status.project_name}**: {project_status.error or 'Unknown error'}"
|
||||
)
|
||||
|
||||
status_lines.extend(
|
||||
[
|
||||
"",
|
||||
"**Next steps:**",
|
||||
"1. Check the logs for detailed error information",
|
||||
"2. Ensure file permissions allow read/write access",
|
||||
"3. Try restarting the MCP server",
|
||||
"4. If issues persist, consider filing a support issue",
|
||||
]
|
||||
)
|
||||
elif not active_projects:
|
||||
# No active or failed projects - must be pending
|
||||
status_lines.extend(
|
||||
[
|
||||
"⏳ **Sync operations pending**",
|
||||
"",
|
||||
"File synchronization has been queued but hasn't started yet.",
|
||||
"This usually resolves automatically within a few seconds.",
|
||||
]
|
||||
)
|
||||
|
||||
# Add comprehensive project status for all configured projects
|
||||
all_projects_status = _get_all_projects_status()
|
||||
if all_projects_status:
|
||||
status_lines.extend(all_projects_status)
|
||||
|
||||
# Add explanation about automatic syncing if there are unsynced projects
|
||||
unsynced_count = sum(1 for line in all_projects_status if "⏳" in line)
|
||||
if unsynced_count > 0 and not is_ready:
|
||||
status_lines.extend(
|
||||
[
|
||||
"",
|
||||
"**Note**: All configured projects will be automatically synced during startup.",
|
||||
"You don't need to manually switch projects - Basic Memory handles this for you.",
|
||||
]
|
||||
)
|
||||
|
||||
# Add project context if provided
|
||||
if project:
|
||||
try:
|
||||
active_project = get_active_project(project)
|
||||
status_lines.extend(
|
||||
[
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
f"**Active Project**: {active_project.name}",
|
||||
f"**Project Path**: {active_project.home}",
|
||||
]
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug(f"Could not get project info: {e}")
|
||||
|
||||
return "\n".join(status_lines)
|
||||
|
||||
except Exception as e:
|
||||
return f"""# Sync Status - Error
|
||||
|
||||
❌ **Unable to check sync status**: {str(e)}
|
||||
|
||||
**Troubleshooting:**
|
||||
- The system may still be starting up
|
||||
- Try waiting a few seconds and checking again
|
||||
- Check logs for detailed error information
|
||||
- Consider restarting if the issue persists
|
||||
"""
|
||||
@@ -506,3 +506,50 @@ async def call_delete(
|
||||
|
||||
except HTTPStatusError as e:
|
||||
raise ToolError(error_message) from e
|
||||
|
||||
|
||||
def check_migration_status() -> Optional[str]:
|
||||
"""Check if sync/migration is in progress and return status message if so.
|
||||
|
||||
Returns:
|
||||
Status message if sync is in progress, None if system is ready
|
||||
"""
|
||||
try:
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker
|
||||
|
||||
if not sync_status_tracker.is_ready:
|
||||
return sync_status_tracker.get_summary()
|
||||
return None
|
||||
except Exception:
|
||||
# If there's any error checking sync status, assume ready
|
||||
return None
|
||||
|
||||
|
||||
async def wait_for_migration_or_return_status(timeout: float = 5.0) -> Optional[str]:
|
||||
"""Wait briefly for sync/migration to complete, or return status message.
|
||||
|
||||
Args:
|
||||
timeout: Maximum time to wait for sync completion
|
||||
|
||||
Returns:
|
||||
Status message if sync is still in progress, None if ready
|
||||
"""
|
||||
try:
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker
|
||||
import asyncio
|
||||
|
||||
if sync_status_tracker.is_ready:
|
||||
return None
|
||||
|
||||
# Wait briefly for sync to complete
|
||||
start_time = asyncio.get_event_loop().time()
|
||||
while (asyncio.get_event_loop().time() - start_time) < timeout:
|
||||
if sync_status_tracker.is_ready:
|
||||
return None
|
||||
await asyncio.sleep(0.1) # Check every 100ms
|
||||
|
||||
# Still not ready after timeout
|
||||
return sync_status_tracker.get_summary()
|
||||
except Exception: # pragma: no cover
|
||||
# If there's any error, assume ready
|
||||
return None
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"""View note tool for Basic Memory MCP server."""
|
||||
|
||||
from textwrap import dedent
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.mcp.server import mcp
|
||||
from basic_memory.mcp.tools.read_note import read_note
|
||||
|
||||
|
||||
@mcp.tool(
|
||||
description="View a note as a formatted artifact for better readability.",
|
||||
)
|
||||
async def view_note(
|
||||
identifier: str, page: int = 1, page_size: int = 10, project: Optional[str] = None
|
||||
) -> str:
|
||||
"""View a markdown note as a formatted artifact.
|
||||
|
||||
This tool reads a note using the same logic as read_note but displays the content
|
||||
as a markdown artifact for better viewing experience in Claude Desktop.
|
||||
|
||||
After calling this tool, create an artifact using the returned content to display
|
||||
the note in a readable format. The tool returns the note content that should be
|
||||
used to create a markdown artifact.
|
||||
|
||||
Args:
|
||||
identifier: The title or permalink of the note to view
|
||||
page: Page number for paginated results (default: 1)
|
||||
page_size: Number of items per page (default: 10)
|
||||
project: Optional project name to read from. If not provided, uses current active project.
|
||||
|
||||
Returns:
|
||||
The note content as a markdown artifact with a confirmation message.
|
||||
"""
|
||||
|
||||
logger.info(f"Viewing note: {identifier}")
|
||||
|
||||
# Call the existing read_note logic
|
||||
content = await read_note.fn(identifier, page, page_size, project)
|
||||
|
||||
# Check if this is an error message (note not found)
|
||||
if "# Note Not Found:" in content:
|
||||
return content # Return error message directly instead of creating artifact
|
||||
|
||||
# Extract title from content if possible
|
||||
title = identifier
|
||||
lines = content.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith("title:"):
|
||||
# Extract title from frontmatter
|
||||
title = line.split("title:", 1)[1].strip().strip('"').strip("'")
|
||||
break
|
||||
elif line.startswith("# "):
|
||||
# Extract title from first heading
|
||||
title = line[2:].strip()
|
||||
break
|
||||
|
||||
# Return the artifact XML as part of the response
|
||||
artifact = f'<artifact identifier="note-{hash(identifier) & 0x7FFFFFFF}" type="text/markdown" title="{title}">\n{content}\n</artifact>'
|
||||
|
||||
return dedent(f"""
|
||||
<instructions>
|
||||
Create an artifact using the returned artifact content to display the note in a readable format.
|
||||
</instructions>
|
||||
{artifact}\n\n✅ Note displayed as artifact: **{title}**""")
|
||||
@@ -54,7 +54,8 @@ async def write_note(
|
||||
Args:
|
||||
title: The title of the note
|
||||
content: Markdown content for the note, can include observations and relations
|
||||
folder: the folder where the file should be saved
|
||||
folder: Folder path relative to project root where the file should be saved.
|
||||
Use forward slashes (/) as separators. Examples: "notes", "projects/2025", "research/ml"
|
||||
tags: Tags to categorize the note. Can be a list of strings, a comma-separated string, or None.
|
||||
Note: If passing from external MCP clients, use a string format (e.g. "tag1,tag2,tag3")
|
||||
project: Optional project name to write to. If not provided, uses current active project.
|
||||
@@ -69,6 +70,13 @@ async def write_note(
|
||||
"""
|
||||
logger.info(f"MCP tool call tool=write_note folder={folder}, title={title}, tags={tags}")
|
||||
|
||||
# Check migration status and wait briefly if needed
|
||||
from basic_memory.mcp.tools.utils import wait_for_migration_or_return_status
|
||||
|
||||
migration_status = await wait_for_migration_or_return_status(timeout=5.0)
|
||||
if migration_status: # pragma: no cover
|
||||
return f"# System Status\n\n{migration_status}\n\nPlease wait for migration to complete before creating notes."
|
||||
|
||||
# Process tags using the helper function
|
||||
tag_list = parse_tags(tags)
|
||||
# Create the entity request
|
||||
@@ -120,7 +128,10 @@ async def write_note(
|
||||
summary.append(f"- Resolved: {resolved}")
|
||||
if unresolved:
|
||||
summary.append(f"- Unresolved: {unresolved}")
|
||||
summary.append("\nUnresolved relations will be retried on next sync.")
|
||||
summary.append("\nNote: Unresolved relations point to entities that don't exist yet.")
|
||||
summary.append(
|
||||
"They will be automatically resolved when target entities are created or during sync operations."
|
||||
)
|
||||
|
||||
if tag_list:
|
||||
summary.append(f"\n## Tags\n- {', '.join(tag_list)}")
|
||||
|
||||
@@ -49,9 +49,7 @@ class Project(Base):
|
||||
|
||||
# Status flags
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
is_default: Mapped[Optional[bool]] = mapped_column(
|
||||
Boolean, default=None, unique=True, nullable=True
|
||||
)
|
||||
is_default: Mapped[Optional[bool]] = mapped_column(Boolean, default=None, nullable=True)
|
||||
|
||||
# Timestamps
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
@@ -128,34 +128,90 @@ class SearchRepository:
|
||||
is_prefix: Whether to add prefix search capability (* suffix)
|
||||
|
||||
For FTS5:
|
||||
- Special characters and phrases need to be quoted
|
||||
- Terms with spaces or special chars need quotes
|
||||
- Boolean operators (AND, OR, NOT) are preserved for complex queries
|
||||
- Terms with FTS5 special characters are quoted to prevent syntax errors
|
||||
- Simple terms get prefix wildcards for better matching
|
||||
"""
|
||||
if "*" in term:
|
||||
return term
|
||||
|
||||
# Check for explicit boolean operators - if present, return the term as is
|
||||
boolean_operators = [" AND ", " OR ", " NOT "]
|
||||
if any(op in f" {term} " for op in boolean_operators):
|
||||
return term
|
||||
|
||||
# List of FTS5 special characters that need escaping/quoting
|
||||
special_chars = ["/", "-", ".", " ", "(", ")", "[", "]", '"', "'"]
|
||||
# Check if term is already a proper wildcard pattern (alphanumeric + *)
|
||||
# e.g., "hello*", "test*world" - these should be left alone
|
||||
if "*" in term and all(c.isalnum() or c in "*_-" for c in term):
|
||||
return term
|
||||
|
||||
# Check if term contains any special characters
|
||||
needs_quotes = any(c in term for c in special_chars)
|
||||
# Characters that can cause FTS5 syntax errors when used as operators
|
||||
# We're more conservative here - only quote when we detect problematic patterns
|
||||
problematic_chars = [
|
||||
'"',
|
||||
"'",
|
||||
"(",
|
||||
")",
|
||||
"[",
|
||||
"]",
|
||||
"{",
|
||||
"}",
|
||||
"+",
|
||||
"!",
|
||||
"@",
|
||||
"#",
|
||||
"$",
|
||||
"%",
|
||||
"^",
|
||||
"&",
|
||||
"=",
|
||||
"|",
|
||||
"\\",
|
||||
"~",
|
||||
"`",
|
||||
]
|
||||
|
||||
if needs_quotes:
|
||||
# Escape any existing quotes by doubling them
|
||||
escaped_term = term.replace('"', '""')
|
||||
# Quote the entire term to handle special characters safely
|
||||
if is_prefix and not ("/" in term and term.endswith(".md")):
|
||||
# For search terms (not file paths), add prefix matching
|
||||
term = f'"{escaped_term}"*'
|
||||
# Characters that indicate we should quote (spaces, dots, colons, etc.)
|
||||
# Adding hyphens here because FTS5 can have issues with hyphens followed by wildcards
|
||||
needs_quoting_chars = [" ", ".", ":", ";", ",", "<", ">", "?", "/", "-"]
|
||||
|
||||
# Check if term needs quoting
|
||||
has_problematic = any(c in term for c in problematic_chars)
|
||||
has_spaces_or_special = any(c in term for c in needs_quoting_chars)
|
||||
|
||||
if has_problematic or has_spaces_or_special:
|
||||
# Handle multi-word queries differently from special character queries
|
||||
if " " in term and not any(c in term for c in problematic_chars):
|
||||
# Check if any individual word contains special characters that need quoting
|
||||
words = term.strip().split()
|
||||
has_special_in_words = any(
|
||||
any(c in word for c in needs_quoting_chars if c != " ") for word in words
|
||||
)
|
||||
|
||||
if not has_special_in_words:
|
||||
# For multi-word queries with simple words (like "emoji unicode"),
|
||||
# use boolean AND to handle word order variations
|
||||
if is_prefix:
|
||||
# Add prefix wildcard to each word for better matching
|
||||
prepared_words = [f"{word}*" for word in words if word]
|
||||
else:
|
||||
prepared_words = words
|
||||
term = " AND ".join(prepared_words)
|
||||
else:
|
||||
# If any word has special characters, quote the entire phrase
|
||||
escaped_term = term.replace('"', '""')
|
||||
if is_prefix and not ("/" in term and term.endswith(".md")):
|
||||
term = f'"{escaped_term}"*'
|
||||
else:
|
||||
term = f'"{escaped_term}"'
|
||||
else:
|
||||
# For file paths, use exact matching
|
||||
term = f'"{escaped_term}"'
|
||||
# For terms with problematic characters or file paths, use exact phrase matching
|
||||
# Escape any existing quotes by doubling them
|
||||
escaped_term = term.replace('"', '""')
|
||||
# Quote the entire term to handle special characters safely
|
||||
if is_prefix and not ("/" in term and term.endswith(".md")):
|
||||
# For search terms (not file paths), add prefix matching
|
||||
term = f'"{escaped_term}"*'
|
||||
else:
|
||||
# For file paths, use exact matching
|
||||
term = f'"{escaped_term}"'
|
||||
elif is_prefix:
|
||||
# Only add wildcard for simple terms without special characters
|
||||
term = f"{term}*"
|
||||
@@ -181,19 +237,24 @@ class SearchRepository:
|
||||
|
||||
# Handle text search for title and content
|
||||
if search_text:
|
||||
# Check for explicit boolean operators - only detect them in proper boolean contexts
|
||||
has_boolean = any(op in f" {search_text} " for op in [" AND ", " OR ", " NOT "])
|
||||
|
||||
if has_boolean:
|
||||
# If boolean operators are present, use the raw query
|
||||
# No need to prepare it, FTS5 will understand the operators
|
||||
params["text"] = search_text
|
||||
conditions.append("(title MATCH :text OR content_stems MATCH :text)")
|
||||
# Skip FTS for wildcard-only queries that would cause "unknown special query" errors
|
||||
if search_text.strip() == "*" or search_text.strip() == "":
|
||||
# For wildcard searches, don't add any text conditions - return all results
|
||||
pass
|
||||
else:
|
||||
# Standard search with term preparation
|
||||
processed_text = self._prepare_search_term(search_text.strip())
|
||||
params["text"] = processed_text
|
||||
conditions.append("(title MATCH :text OR content_stems MATCH :text)")
|
||||
# Check for explicit boolean operators - only detect them in proper boolean contexts
|
||||
has_boolean = any(op in f" {search_text} " for op in [" AND ", " OR ", " NOT "])
|
||||
|
||||
if has_boolean:
|
||||
# If boolean operators are present, use the raw query
|
||||
# No need to prepare it, FTS5 will understand the operators
|
||||
params["text"] = search_text
|
||||
conditions.append("(title MATCH :text OR content_stems MATCH :text)")
|
||||
else:
|
||||
# Standard search with term preparation
|
||||
processed_text = self._prepare_search_term(search_text.strip())
|
||||
params["text"] = processed_text
|
||||
conditions.append("(title MATCH :text OR content_stems MATCH :text)")
|
||||
|
||||
# Handle title match search
|
||||
if title:
|
||||
@@ -208,15 +269,21 @@ class SearchRepository:
|
||||
|
||||
# Handle permalink match search, supports *
|
||||
if permalink_match:
|
||||
# Clean and prepare permalink for FTS5 GLOB match
|
||||
permalink_text = self._prepare_search_term(
|
||||
permalink_match.lower().strip(), is_prefix=False
|
||||
)
|
||||
# For GLOB patterns, don't use _prepare_search_term as it will quote slashes
|
||||
# GLOB patterns need to preserve their syntax
|
||||
permalink_text = permalink_match.lower().strip()
|
||||
params["permalink"] = permalink_text
|
||||
if "*" in permalink_match:
|
||||
conditions.append("permalink GLOB :permalink")
|
||||
else:
|
||||
conditions.append("permalink MATCH :permalink")
|
||||
# For exact matches without *, we can use FTS5 MATCH
|
||||
# but only prepare the term if it doesn't look like a path
|
||||
if "/" in permalink_text:
|
||||
conditions.append("permalink = :permalink")
|
||||
else:
|
||||
permalink_text = self._prepare_search_term(permalink_text, is_prefix=False)
|
||||
params["permalink"] = permalink_text
|
||||
conditions.append("permalink MATCH :permalink")
|
||||
|
||||
# Handle entity type filter
|
||||
if search_item_types:
|
||||
@@ -273,9 +340,20 @@ class SearchRepository:
|
||||
"""
|
||||
|
||||
logger.trace(f"Search {sql} params: {params}")
|
||||
async with db.scoped_session(self.session_maker) as session:
|
||||
result = await session.execute(text(sql), params)
|
||||
rows = result.fetchall()
|
||||
try:
|
||||
async with db.scoped_session(self.session_maker) as session:
|
||||
result = await session.execute(text(sql), params)
|
||||
rows = result.fetchall()
|
||||
except Exception as e:
|
||||
# Handle FTS5 syntax errors and provide user-friendly feedback
|
||||
if "fts5: syntax error" in str(e).lower(): # pragma: no cover
|
||||
logger.warning(f"FTS5 syntax error for search term: {search_text}, error: {e}")
|
||||
# Return empty results rather than crashing
|
||||
return []
|
||||
else:
|
||||
# Re-raise other database errors
|
||||
logger.error(f"Database error during search: {e}")
|
||||
raise
|
||||
|
||||
results = [
|
||||
SearchIndexRow(
|
||||
|
||||
@@ -13,7 +13,7 @@ Key Concepts:
|
||||
|
||||
import mimetypes
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, time
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, Annotated, Dict
|
||||
|
||||
@@ -46,15 +46,43 @@ def to_snake_case(name: str) -> str:
|
||||
return s2.lower()
|
||||
|
||||
|
||||
def parse_timeframe(timeframe: str) -> datetime:
|
||||
"""Parse timeframe with special handling for 'today' and other natural language expressions.
|
||||
|
||||
Args:
|
||||
timeframe: Natural language timeframe like 'today', '1d', '1 week ago', etc.
|
||||
|
||||
Returns:
|
||||
datetime: The parsed datetime for the start of the timeframe
|
||||
|
||||
Examples:
|
||||
parse_timeframe('today') -> 2025-06-05 00:00:00 (start of today)
|
||||
parse_timeframe('1d') -> 2025-06-04 14:50:00 (24 hours ago)
|
||||
parse_timeframe('1 week ago') -> 2025-05-29 14:50:00 (1 week ago)
|
||||
"""
|
||||
if timeframe.lower() == "today":
|
||||
# Return start of today (00:00:00)
|
||||
return datetime.combine(datetime.now().date(), time.min)
|
||||
else:
|
||||
# Use dateparser for other formats
|
||||
parsed = parse(timeframe)
|
||||
if not parsed:
|
||||
raise ValueError(f"Could not parse timeframe: {timeframe}")
|
||||
return parsed
|
||||
|
||||
|
||||
def validate_timeframe(timeframe: str) -> str:
|
||||
"""Convert human readable timeframes to a duration relative to the current time."""
|
||||
if not isinstance(timeframe, str):
|
||||
raise ValueError("Timeframe must be a string")
|
||||
|
||||
# Parse relative time expression
|
||||
parsed = parse(timeframe)
|
||||
if not parsed:
|
||||
raise ValueError(f"Could not parse timeframe: {timeframe}")
|
||||
# Preserve special timeframe strings that need custom handling
|
||||
special_timeframes = ["today"]
|
||||
if timeframe.lower() in special_timeframes:
|
||||
return timeframe.lower()
|
||||
|
||||
# Parse relative time expression using our enhanced parser
|
||||
parsed = parse_timeframe(timeframe)
|
||||
|
||||
# Convert to duration
|
||||
now = datetime.now()
|
||||
|
||||
@@ -9,8 +9,44 @@ from pydantic import BaseModel, Field, BeforeValidator, TypeAdapter
|
||||
from basic_memory.schemas.search import SearchItemType
|
||||
|
||||
|
||||
def validate_memory_url_path(path: str) -> bool:
|
||||
"""Validate that a memory URL path is well-formed.
|
||||
|
||||
Args:
|
||||
path: The path part of a memory URL (without memory:// prefix)
|
||||
|
||||
Returns:
|
||||
True if the path is valid, False otherwise
|
||||
|
||||
Examples:
|
||||
>>> validate_memory_url_path("specs/search")
|
||||
True
|
||||
>>> validate_memory_url_path("memory//test") # Double slash
|
||||
False
|
||||
>>> validate_memory_url_path("invalid://test") # Contains protocol
|
||||
False
|
||||
"""
|
||||
if not path or not path.strip():
|
||||
return False
|
||||
|
||||
# Check for invalid protocol schemes within the path first (more specific)
|
||||
if "://" in path:
|
||||
return False
|
||||
|
||||
# Check for double slashes (except at the beginning for absolute paths)
|
||||
if "//" in path:
|
||||
return False
|
||||
|
||||
# Check for invalid characters (excluding * which is used for pattern matching)
|
||||
invalid_chars = {"<", ">", '"', "|", "?"}
|
||||
if any(char in path for char in invalid_chars):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def normalize_memory_url(url: str | None) -> str:
|
||||
"""Normalize a MemoryUrl string.
|
||||
"""Normalize a MemoryUrl string with validation.
|
||||
|
||||
Args:
|
||||
url: A path like "specs/search" or "memory://specs/search"
|
||||
@@ -18,22 +54,43 @@ def normalize_memory_url(url: str | None) -> str:
|
||||
Returns:
|
||||
Normalized URL starting with memory://
|
||||
|
||||
Raises:
|
||||
ValueError: If the URL path is malformed
|
||||
|
||||
Examples:
|
||||
>>> normalize_memory_url("specs/search")
|
||||
'memory://specs/search'
|
||||
>>> normalize_memory_url("memory://specs/search")
|
||||
'memory://specs/search'
|
||||
>>> normalize_memory_url("memory//test")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Invalid memory URL path: 'memory//test' contains double slashes
|
||||
"""
|
||||
if not url:
|
||||
return ""
|
||||
|
||||
clean_path = url.removeprefix("memory://")
|
||||
|
||||
# Validate the extracted path
|
||||
if not validate_memory_url_path(clean_path):
|
||||
# Provide specific error messages for common issues
|
||||
if "://" in clean_path:
|
||||
raise ValueError(f"Invalid memory URL path: '{clean_path}' contains protocol scheme")
|
||||
elif "//" in clean_path:
|
||||
raise ValueError(f"Invalid memory URL path: '{clean_path}' contains double slashes")
|
||||
elif not clean_path.strip():
|
||||
raise ValueError("Memory URL path cannot be empty or whitespace")
|
||||
else:
|
||||
raise ValueError(f"Invalid memory URL path: '{clean_path}' contains invalid characters")
|
||||
|
||||
return f"memory://{clean_path}"
|
||||
|
||||
|
||||
MemoryUrl = Annotated[
|
||||
str,
|
||||
BeforeValidator(str.strip), # Clean whitespace
|
||||
BeforeValidator(normalize_memory_url), # Validate and normalize the URL
|
||||
MinLen(1),
|
||||
MaxLen(2028),
|
||||
]
|
||||
|
||||
@@ -6,6 +6,8 @@ from typing import Dict, List, Optional, Any
|
||||
|
||||
from pydantic import Field, BaseModel
|
||||
|
||||
from basic_memory.utils import generate_permalink
|
||||
|
||||
|
||||
class ProjectStatistics(BaseModel):
|
||||
"""Statistics about the current project."""
|
||||
@@ -183,6 +185,10 @@ class ProjectItem(BaseModel):
|
||||
name: str
|
||||
path: str
|
||||
is_default: bool = False
|
||||
|
||||
@property
|
||||
def permalink(self) -> str: # pragma: no cover
|
||||
return generate_permalink(self.name)
|
||||
|
||||
|
||||
class ProjectList(BaseModel):
|
||||
|
||||
@@ -299,7 +299,20 @@ class EntityService(BaseService[EntityModel]):
|
||||
# Mark as incomplete because we still need to add relations
|
||||
model.checksum = None
|
||||
# Repository will set project_id automatically
|
||||
return await self.repository.add(model)
|
||||
try:
|
||||
return await self.repository.add(model)
|
||||
except IntegrityError as e:
|
||||
# Handle race condition where entity was created by another process
|
||||
if "UNIQUE constraint failed: entity.file_path" in str(
|
||||
e
|
||||
) or "UNIQUE constraint failed: entity.permalink" in str(e):
|
||||
logger.info(
|
||||
f"Entity already exists for file_path={file_path} (file_path or permalink conflict), updating instead of creating"
|
||||
)
|
||||
return await self.update_entity_and_observations(file_path, markdown)
|
||||
else:
|
||||
# Re-raise if it's a different integrity error
|
||||
raise
|
||||
|
||||
async def update_entity_and_observations(
|
||||
self, file_path: Path, markdown: EntityMarkdown
|
||||
@@ -413,8 +426,8 @@ class EntityService(BaseService[EntityModel]):
|
||||
"""
|
||||
logger.debug(f"Editing entity: {identifier}, operation: {operation}")
|
||||
|
||||
# Find the entity using the link resolver
|
||||
entity = await self.link_resolver.resolve_link(identifier)
|
||||
# Find the entity using the link resolver with strict mode for destructive operations
|
||||
entity = await self.link_resolver.resolve_link(identifier, strict=True)
|
||||
if not entity:
|
||||
raise EntityNotFoundError(f"Entity not found: {identifier}")
|
||||
|
||||
@@ -630,8 +643,8 @@ class EntityService(BaseService[EntityModel]):
|
||||
"""
|
||||
logger.debug(f"Moving entity: {identifier} to {destination_path}")
|
||||
|
||||
# 1. Resolve identifier to entity
|
||||
entity = await self.link_resolver.resolve_link(identifier)
|
||||
# 1. Resolve identifier to entity with strict mode for destructive operations
|
||||
entity = await self.link_resolver.resolve_link(identifier, strict=True)
|
||||
if not entity:
|
||||
raise EntityNotFoundError(f"Entity not found: {identifier}")
|
||||
|
||||
|
||||
@@ -83,7 +83,9 @@ async def migrate_legacy_projects(app_config: BasicMemoryConfig):
|
||||
logger.error(f"Project {project_name} not found in database, skipping migration")
|
||||
continue
|
||||
|
||||
logger.info(f"Starting migration for project: {project_name} (id: {project.id})")
|
||||
await migrate_legacy_project_data(project, legacy_dir)
|
||||
logger.info(f"Completed migration for project: {project_name}")
|
||||
logger.info("Legacy projects successfully migrated")
|
||||
|
||||
|
||||
@@ -104,7 +106,7 @@ async def migrate_legacy_project_data(project: Project, legacy_dir: Path) -> boo
|
||||
sync_dir = Path(project.path)
|
||||
|
||||
logger.info(f"Sync starting project: {project.name}")
|
||||
await sync_service.sync(sync_dir)
|
||||
await sync_service.sync(sync_dir, project_name=project.name)
|
||||
logger.info(f"Sync completed successfully for project: {project.name}")
|
||||
|
||||
# After successful sync, remove the legacy directory
|
||||
@@ -158,12 +160,32 @@ async def initialize_file_sync(
|
||||
sync_dir = Path(project.path)
|
||||
|
||||
try:
|
||||
await sync_service.sync(sync_dir)
|
||||
await sync_service.sync(sync_dir, project_name=project.name)
|
||||
logger.info(f"Sync completed successfully for project: {project.name}")
|
||||
|
||||
# Mark project as watching for changes after successful sync
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker
|
||||
|
||||
sync_status_tracker.start_project_watch(project.name)
|
||||
logger.info(f"Project {project.name} is now watching for changes")
|
||||
except Exception as e: # pragma: no cover
|
||||
logger.error(f"Error syncing project {project.name}: {e}")
|
||||
# Mark sync as failed for this project
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker
|
||||
|
||||
sync_status_tracker.fail_project_sync(project.name, str(e))
|
||||
# Continue with other projects even if one fails
|
||||
|
||||
# Mark migration complete if it was in progress
|
||||
try:
|
||||
from basic_memory.services.migration_service import migration_manager
|
||||
|
||||
if not migration_manager.is_ready: # pragma: no cover
|
||||
migration_manager.mark_completed("Migration completed with file sync")
|
||||
logger.info("Marked migration as completed after file sync")
|
||||
except Exception as e: # pragma: no cover
|
||||
logger.warning(f"Could not update migration status: {e}")
|
||||
|
||||
# Then start the watch service in the background
|
||||
logger.info("Starting watch service for all projects")
|
||||
# run the watch service
|
||||
@@ -185,7 +207,7 @@ async def initialize_app(
|
||||
- Running database migrations
|
||||
- Reconciling projects from config.json with projects table
|
||||
- Setting up file synchronization
|
||||
- Migrating legacy project data
|
||||
- Starting background migration for legacy project data
|
||||
|
||||
Args:
|
||||
app_config: The Basic Memory project configuration
|
||||
@@ -197,8 +219,13 @@ async def initialize_app(
|
||||
# Reconcile projects from config.json with projects table
|
||||
await reconcile_projects_with_config(app_config)
|
||||
|
||||
# migrate legacy project data
|
||||
await migrate_legacy_projects(app_config)
|
||||
# Start background migration for legacy project data (non-blocking)
|
||||
from basic_memory.services.migration_service import migration_manager
|
||||
|
||||
await migration_manager.start_background_migration(app_config)
|
||||
|
||||
logger.info("App initialization completed (migration running in background if needed)")
|
||||
return migration_manager
|
||||
|
||||
|
||||
def ensure_initialization(app_config: BasicMemoryConfig) -> None:
|
||||
|
||||
@@ -26,8 +26,16 @@ class LinkResolver:
|
||||
self.entity_repository = entity_repository
|
||||
self.search_service = search_service
|
||||
|
||||
async def resolve_link(self, link_text: str, use_search: bool = True) -> Optional[Entity]:
|
||||
"""Resolve a markdown link to a permalink."""
|
||||
async def resolve_link(
|
||||
self, link_text: str, use_search: bool = True, strict: bool = False
|
||||
) -> Optional[Entity]:
|
||||
"""Resolve a markdown link to a permalink.
|
||||
|
||||
Args:
|
||||
link_text: The link text to resolve
|
||||
use_search: Whether to use search-based fuzzy matching as fallback
|
||||
strict: If True, only exact matches are allowed (no fuzzy search fallback)
|
||||
"""
|
||||
logger.trace(f"Resolving link: {link_text}")
|
||||
|
||||
# Clean link text and extract any alias
|
||||
@@ -41,7 +49,8 @@ class LinkResolver:
|
||||
|
||||
# 2. Try exact title match
|
||||
found = await self.entity_repository.get_by_title(clean_text)
|
||||
if found and len(found) == 1:
|
||||
if found:
|
||||
# Return first match if there are duplicates (consistent behavior)
|
||||
entity = found[0]
|
||||
logger.debug(f"Found title match: {entity.title}")
|
||||
return entity
|
||||
@@ -60,9 +69,12 @@ class LinkResolver:
|
||||
logger.debug(f"Found entity with path (with .md): {found_path_md.file_path}")
|
||||
return found_path_md
|
||||
|
||||
# search if indicated
|
||||
# In strict mode, don't try fuzzy search - return None if no exact match found
|
||||
if strict:
|
||||
return None
|
||||
|
||||
# 5. Fall back to search for fuzzy matching (only if not in strict mode)
|
||||
if use_search and "*" not in clean_text:
|
||||
# 5. Fall back to search for fuzzy matching on title (use text search for prefix matching)
|
||||
results = await self.search_service.search(
|
||||
query=SearchQuery(text=clean_text, entity_types=[SearchItemType.ENTITY]),
|
||||
)
|
||||
@@ -101,5 +113,8 @@ class LinkResolver:
|
||||
text, alias = text.split("|", 1)
|
||||
text = text.strip()
|
||||
alias = alias.strip()
|
||||
else:
|
||||
# Strip whitespace from text even if no alias
|
||||
text = text.strip()
|
||||
|
||||
return text, alias
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
"""Migration service for handling background migrations and status tracking."""
|
||||
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.config import BasicMemoryConfig
|
||||
|
||||
|
||||
class MigrationStatus(Enum):
|
||||
"""Status of migration operations."""
|
||||
|
||||
NOT_NEEDED = "not_needed"
|
||||
PENDING = "pending"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
FAILED = "failed"
|
||||
|
||||
|
||||
@dataclass
|
||||
class MigrationState:
|
||||
"""Current state of migration operations."""
|
||||
|
||||
status: MigrationStatus
|
||||
message: str
|
||||
progress: Optional[str] = None
|
||||
error: Optional[str] = None
|
||||
projects_migrated: int = 0
|
||||
projects_total: int = 0
|
||||
|
||||
|
||||
class MigrationManager:
|
||||
"""Manages background migration operations and status tracking."""
|
||||
|
||||
def __init__(self):
|
||||
self._state = MigrationState(
|
||||
status=MigrationStatus.NOT_NEEDED, message="No migration required"
|
||||
)
|
||||
self._migration_task: Optional[asyncio.Task] = None
|
||||
|
||||
@property
|
||||
def state(self) -> MigrationState:
|
||||
"""Get current migration state."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def is_ready(self) -> bool:
|
||||
"""Check if the system is ready for normal operations."""
|
||||
return self._state.status in (MigrationStatus.NOT_NEEDED, MigrationStatus.COMPLETED)
|
||||
|
||||
@property
|
||||
def status_message(self) -> str:
|
||||
"""Get a user-friendly status message."""
|
||||
if self._state.status == MigrationStatus.IN_PROGRESS:
|
||||
progress = (
|
||||
f" ({self._state.projects_migrated}/{self._state.projects_total})"
|
||||
if self._state.projects_total > 0
|
||||
else ""
|
||||
)
|
||||
return f"🔄 File sync in progress{progress}: {self._state.message}. Use sync_status() tool for details."
|
||||
elif self._state.status == MigrationStatus.FAILED:
|
||||
return f"❌ File sync failed: {self._state.error or 'Unknown error'}. Use sync_status() tool for details."
|
||||
elif self._state.status == MigrationStatus.COMPLETED:
|
||||
return "✅ File sync completed successfully"
|
||||
else:
|
||||
return "✅ System ready"
|
||||
|
||||
async def check_migration_needed(self, app_config: BasicMemoryConfig) -> bool:
|
||||
"""Check if migration is needed without performing it."""
|
||||
from basic_memory import db
|
||||
from basic_memory.repository import ProjectRepository
|
||||
|
||||
try:
|
||||
# Get database session
|
||||
_, session_maker = await db.get_or_create_db(
|
||||
db_path=app_config.database_path, db_type=db.DatabaseType.FILESYSTEM
|
||||
)
|
||||
project_repository = ProjectRepository(session_maker)
|
||||
|
||||
# Check for legacy projects
|
||||
legacy_projects = []
|
||||
for project_name, project_path in app_config.projects.items():
|
||||
legacy_dir = Path(project_path) / ".basic-memory"
|
||||
if legacy_dir.exists():
|
||||
project = await project_repository.get_by_name(project_name)
|
||||
if project:
|
||||
legacy_projects.append(project)
|
||||
|
||||
if legacy_projects:
|
||||
self._state = MigrationState(
|
||||
status=MigrationStatus.PENDING,
|
||||
message="Legacy projects detected",
|
||||
projects_total=len(legacy_projects),
|
||||
)
|
||||
return True
|
||||
else:
|
||||
self._state = MigrationState(
|
||||
status=MigrationStatus.NOT_NEEDED, message="No migration required"
|
||||
)
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking migration status: {e}")
|
||||
self._state = MigrationState(
|
||||
status=MigrationStatus.FAILED, message="Migration check failed", error=str(e)
|
||||
)
|
||||
return False
|
||||
|
||||
async def start_background_migration(self, app_config: BasicMemoryConfig) -> None:
|
||||
"""Start migration in background if needed."""
|
||||
if not await self.check_migration_needed(app_config):
|
||||
return
|
||||
|
||||
if self._migration_task and not self._migration_task.done():
|
||||
logger.info("Migration already in progress")
|
||||
return
|
||||
|
||||
logger.info("Starting background migration")
|
||||
self._migration_task = asyncio.create_task(self._run_migration(app_config))
|
||||
|
||||
async def _run_migration(self, app_config: BasicMemoryConfig) -> None:
|
||||
"""Run the actual migration process."""
|
||||
try:
|
||||
self._state.status = MigrationStatus.IN_PROGRESS
|
||||
self._state.message = "Migrating legacy projects"
|
||||
|
||||
# Import here to avoid circular imports
|
||||
from basic_memory.services.initialization import migrate_legacy_projects
|
||||
|
||||
# Run the migration
|
||||
await migrate_legacy_projects(app_config)
|
||||
|
||||
self._state = MigrationState(
|
||||
status=MigrationStatus.COMPLETED, message="Migration completed successfully"
|
||||
)
|
||||
logger.info("Background migration completed successfully")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Background migration failed: {e}")
|
||||
self._state = MigrationState(
|
||||
status=MigrationStatus.FAILED, message="Migration failed", error=str(e)
|
||||
)
|
||||
|
||||
async def wait_for_completion(self, timeout: Optional[float] = None) -> bool:
|
||||
"""Wait for migration to complete."""
|
||||
if self.is_ready:
|
||||
return True
|
||||
|
||||
if not self._migration_task:
|
||||
return False
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(self._migration_task, timeout=timeout)
|
||||
return self.is_ready
|
||||
except asyncio.TimeoutError:
|
||||
return False
|
||||
|
||||
def mark_completed(self, message: str = "Migration completed") -> None:
|
||||
"""Mark migration as completed externally."""
|
||||
self._state = MigrationState(status=MigrationStatus.COMPLETED, message=message)
|
||||
|
||||
|
||||
# Global migration manager instance
|
||||
migration_manager = MigrationManager()
|
||||
@@ -67,12 +67,13 @@ class ProjectService:
|
||||
"""Get the file path for a project by name."""
|
||||
return await self.repository.get_by_name(name)
|
||||
|
||||
async def add_project(self, name: str, path: str) -> None:
|
||||
async def add_project(self, name: str, path: str, set_default: bool = False) -> None:
|
||||
"""Add a new project to the configuration and database.
|
||||
|
||||
Args:
|
||||
name: The name of the project
|
||||
path: The file path to the project directory
|
||||
set_default: Whether to set this project as the default
|
||||
|
||||
Raises:
|
||||
ValueError: If the project already exists
|
||||
@@ -92,9 +93,16 @@ class ProjectService:
|
||||
"path": resolved_path,
|
||||
"permalink": generate_permalink(project_config.name),
|
||||
"is_active": True,
|
||||
"is_default": False,
|
||||
# Don't set is_default=False to avoid UNIQUE constraint issues
|
||||
# Let it default to NULL, only set to True when explicitly making default
|
||||
}
|
||||
await self.repository.create(project_data)
|
||||
created_project = await self.repository.create(project_data)
|
||||
|
||||
# If this should be the default project, ensure only one default exists
|
||||
if set_default:
|
||||
await self.repository.set_as_default(created_project.id)
|
||||
config_manager.set_default_project(name)
|
||||
logger.info(f"Project '{name}' set as default")
|
||||
|
||||
logger.info(f"Project '{name}' added at {resolved_path}")
|
||||
|
||||
@@ -144,6 +152,47 @@ class ProjectService:
|
||||
|
||||
logger.info(f"Project '{name}' set as default in configuration and database")
|
||||
|
||||
async def _ensure_single_default_project(self) -> None:
|
||||
"""Ensure only one project has is_default=True.
|
||||
|
||||
This method validates the database state and fixes any issues where
|
||||
multiple projects might have is_default=True or no project is marked as default.
|
||||
"""
|
||||
if not self.repository:
|
||||
raise ValueError(
|
||||
"Repository is required for _ensure_single_default_project"
|
||||
) # pragma: no cover
|
||||
|
||||
# Get all projects with is_default=True
|
||||
db_projects = await self.repository.find_all()
|
||||
default_projects = [p for p in db_projects if p.is_default is True]
|
||||
|
||||
if len(default_projects) > 1: # pragma: no cover
|
||||
# Multiple defaults found - fix by keeping the first one and clearing others
|
||||
# This is defensive code that should rarely execute due to business logic enforcement
|
||||
logger.warning( # pragma: no cover
|
||||
f"Found {len(default_projects)} projects with is_default=True, fixing..."
|
||||
)
|
||||
keep_default = default_projects[0] # pragma: no cover
|
||||
|
||||
# Clear all defaults first, then set only the first one as default
|
||||
await self.repository.set_as_default(keep_default.id) # pragma: no cover
|
||||
|
||||
logger.info(
|
||||
f"Fixed default project conflicts, kept '{keep_default.name}' as default"
|
||||
) # pragma: no cover
|
||||
|
||||
elif len(default_projects) == 0: # pragma: no cover
|
||||
# No default project - set the config default as default
|
||||
# This is defensive code for edge cases where no default exists
|
||||
config_default = config_manager.default_project # pragma: no cover
|
||||
config_project = await self.repository.get_by_name(config_default) # pragma: no cover
|
||||
if config_project: # pragma: no cover
|
||||
await self.repository.set_as_default(config_project.id) # pragma: no cover
|
||||
logger.info(
|
||||
f"Set '{config_default}' as default project (was missing)"
|
||||
) # pragma: no cover
|
||||
|
||||
async def synchronize_projects(self) -> None: # pragma: no cover
|
||||
"""Synchronize projects between database and configuration.
|
||||
|
||||
@@ -158,43 +207,68 @@ class ProjectService:
|
||||
|
||||
# Get all projects from database
|
||||
db_projects = await self.repository.get_active_projects()
|
||||
db_projects_by_name = {p.name: p for p in db_projects}
|
||||
db_projects_by_permalink = {p.permalink: p for p in db_projects}
|
||||
|
||||
# Get all projects from configuration
|
||||
config_projects = config_manager.projects
|
||||
# Get all projects from configuration and normalize names if needed
|
||||
config_projects = config_manager.projects.copy()
|
||||
updated_config = {}
|
||||
config_updated = False
|
||||
|
||||
for name, path in config_projects.items():
|
||||
# Generate normalized name (what the database expects)
|
||||
normalized_name = generate_permalink(name)
|
||||
|
||||
if normalized_name != name:
|
||||
logger.info(f"Normalizing project name in config: '{name}' -> '{normalized_name}'")
|
||||
config_updated = True
|
||||
|
||||
updated_config[normalized_name] = path
|
||||
|
||||
# Update the configuration if any changes were made
|
||||
if config_updated:
|
||||
config_manager.config.projects = updated_config
|
||||
config_manager.save_config(config_manager.config)
|
||||
logger.info("Config updated with normalized project names")
|
||||
|
||||
# Use the normalized config for further processing
|
||||
config_projects = updated_config
|
||||
|
||||
# Add projects that exist in config but not in DB
|
||||
for name, path in config_projects.items():
|
||||
if name not in db_projects_by_name:
|
||||
if name not in db_projects_by_permalink:
|
||||
logger.info(f"Adding project '{name}' to database")
|
||||
project_data = {
|
||||
"name": name,
|
||||
"path": path,
|
||||
"permalink": name.lower().replace(" ", "-"),
|
||||
"permalink": generate_permalink(name),
|
||||
"is_active": True,
|
||||
"is_default": (name == config_manager.default_project),
|
||||
# Don't set is_default here - let the enforcement logic handle it
|
||||
}
|
||||
await self.repository.create(project_data)
|
||||
|
||||
# Add projects that exist in DB but not in config to config
|
||||
for name, project in db_projects_by_name.items():
|
||||
for name, project in db_projects_by_permalink.items():
|
||||
if name not in config_projects:
|
||||
logger.info(f"Adding project '{name}' to configuration")
|
||||
config_manager.add_project(name, project.path)
|
||||
|
||||
# Make sure default project is synchronized
|
||||
db_default = next((p for p in db_projects if p.is_default), None)
|
||||
# Ensure database default project state is consistent
|
||||
await self._ensure_single_default_project()
|
||||
|
||||
# Make sure default project is synchronized between config and database
|
||||
db_default = await self.repository.get_default_project()
|
||||
config_default = config_manager.default_project
|
||||
|
||||
if db_default and db_default.name != config_default:
|
||||
# Update config to match DB default
|
||||
logger.info(f"Updating default project in config to '{db_default.name}'")
|
||||
config_manager.set_default_project(db_default.name)
|
||||
elif not db_default and config_default in db_projects_by_name:
|
||||
# Update DB to match config default
|
||||
logger.info(f"Updating default project in database to '{config_default}'")
|
||||
project = db_projects_by_name[config_default]
|
||||
await self.repository.set_as_default(project.id)
|
||||
elif not db_default and config_default:
|
||||
# Update DB to match config default (if the project exists)
|
||||
project = await self.repository.get_by_name(config_default)
|
||||
if project:
|
||||
logger.info(f"Updating default project in database to '{config_default}'")
|
||||
await self.repository.set_as_default(project.id)
|
||||
|
||||
logger.info("Project synchronization complete")
|
||||
|
||||
@@ -258,8 +332,11 @@ class ProjectService:
|
||||
f"Changed default project to '{new_default.name}' as '{name}' was deactivated"
|
||||
)
|
||||
|
||||
async def get_project_info(self) -> ProjectInfoResponse:
|
||||
"""Get comprehensive information about the current Basic Memory project.
|
||||
async def get_project_info(self, project_name: Optional[str] = None) -> ProjectInfoResponse:
|
||||
"""Get comprehensive information about the specified Basic Memory project.
|
||||
|
||||
Args:
|
||||
project_name: Name of the project to get info for. If None, uses the current config project.
|
||||
|
||||
Returns:
|
||||
Comprehensive project information and statistics
|
||||
@@ -267,19 +344,27 @@ class ProjectService:
|
||||
if not self.repository: # pragma: no cover
|
||||
raise ValueError("Repository is required for get_project_info")
|
||||
|
||||
# Get statistics
|
||||
statistics = await self.get_statistics()
|
||||
# Use specified project or fall back to config project
|
||||
project_name = project_name or config.project
|
||||
# Get project path from configuration
|
||||
project_path = config_manager.projects.get(project_name)
|
||||
if not project_path: # pragma: no cover
|
||||
raise ValueError(f"Project '{project_name}' not found in configuration")
|
||||
|
||||
# Get activity metrics
|
||||
activity = await self.get_activity_metrics()
|
||||
# Get project from database to get project_id
|
||||
db_project = await self.repository.get_by_name(project_name)
|
||||
if not db_project: # pragma: no cover
|
||||
raise ValueError(f"Project '{project_name}' not found in database")
|
||||
|
||||
# Get statistics for the specified project
|
||||
statistics = await self.get_statistics(db_project.id)
|
||||
|
||||
# Get activity metrics for the specified project
|
||||
activity = await self.get_activity_metrics(db_project.id)
|
||||
|
||||
# Get system status
|
||||
system = self.get_system_status()
|
||||
|
||||
# Get current project information from config
|
||||
project_name = config.project
|
||||
project_path = str(config.home)
|
||||
|
||||
# Get enhanced project information from database
|
||||
db_projects = await self.repository.get_active_projects()
|
||||
db_projects_by_name = {p.name: p for p in db_projects}
|
||||
@@ -310,60 +395,85 @@ class ProjectService:
|
||||
system=system,
|
||||
)
|
||||
|
||||
async def get_statistics(self) -> ProjectStatistics:
|
||||
"""Get statistics about the current project."""
|
||||
async def get_statistics(self, project_id: int) -> ProjectStatistics:
|
||||
"""Get statistics about the specified project.
|
||||
|
||||
Args:
|
||||
project_id: ID of the project to get statistics for (required).
|
||||
"""
|
||||
if not self.repository: # pragma: no cover
|
||||
raise ValueError("Repository is required for get_statistics")
|
||||
|
||||
# Get basic counts
|
||||
entity_count_result = await self.repository.execute_query(
|
||||
text("SELECT COUNT(*) FROM entity")
|
||||
text("SELECT COUNT(*) FROM entity WHERE project_id = :project_id"),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
total_entities = entity_count_result.scalar() or 0
|
||||
|
||||
observation_count_result = await self.repository.execute_query(
|
||||
text("SELECT COUNT(*) FROM observation")
|
||||
text(
|
||||
"SELECT COUNT(*) FROM observation o JOIN entity e ON o.entity_id = e.id WHERE e.project_id = :project_id"
|
||||
),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
total_observations = observation_count_result.scalar() or 0
|
||||
|
||||
relation_count_result = await self.repository.execute_query(
|
||||
text("SELECT COUNT(*) FROM relation")
|
||||
text(
|
||||
"SELECT COUNT(*) FROM relation r JOIN entity e ON r.from_id = e.id WHERE e.project_id = :project_id"
|
||||
),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
total_relations = relation_count_result.scalar() or 0
|
||||
|
||||
unresolved_count_result = await self.repository.execute_query(
|
||||
text("SELECT COUNT(*) FROM relation WHERE to_id IS NULL")
|
||||
text(
|
||||
"SELECT COUNT(*) FROM relation r JOIN entity e ON r.from_id = e.id WHERE r.to_id IS NULL AND e.project_id = :project_id"
|
||||
),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
total_unresolved = unresolved_count_result.scalar() or 0
|
||||
|
||||
# Get entity counts by type
|
||||
entity_types_result = await self.repository.execute_query(
|
||||
text("SELECT entity_type, COUNT(*) FROM entity GROUP BY entity_type")
|
||||
text(
|
||||
"SELECT entity_type, COUNT(*) FROM entity WHERE project_id = :project_id GROUP BY entity_type"
|
||||
),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
entity_types = {row[0]: row[1] for row in entity_types_result.fetchall()}
|
||||
|
||||
# Get observation counts by category
|
||||
category_result = await self.repository.execute_query(
|
||||
text("SELECT category, COUNT(*) FROM observation GROUP BY category")
|
||||
text(
|
||||
"SELECT o.category, COUNT(*) FROM observation o JOIN entity e ON o.entity_id = e.id WHERE e.project_id = :project_id GROUP BY o.category"
|
||||
),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
observation_categories = {row[0]: row[1] for row in category_result.fetchall()}
|
||||
|
||||
# Get relation counts by type
|
||||
relation_types_result = await self.repository.execute_query(
|
||||
text("SELECT relation_type, COUNT(*) FROM relation GROUP BY relation_type")
|
||||
text(
|
||||
"SELECT r.relation_type, COUNT(*) FROM relation r JOIN entity e ON r.from_id = e.id WHERE e.project_id = :project_id GROUP BY r.relation_type"
|
||||
),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
relation_types = {row[0]: row[1] for row in relation_types_result.fetchall()}
|
||||
|
||||
# Find most connected entities (most outgoing relations)
|
||||
# Find most connected entities (most outgoing relations) - project filtered
|
||||
connected_result = await self.repository.execute_query(
|
||||
text("""
|
||||
SELECT e.id, e.title, e.permalink, COUNT(r.id) AS relation_count, file_path
|
||||
SELECT e.id, e.title, e.permalink, COUNT(r.id) AS relation_count, e.file_path
|
||||
FROM entity e
|
||||
JOIN relation r ON e.id = r.from_id
|
||||
WHERE e.project_id = :project_id
|
||||
GROUP BY e.id
|
||||
ORDER BY relation_count DESC
|
||||
LIMIT 10
|
||||
""")
|
||||
"""),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
most_connected = [
|
||||
{
|
||||
@@ -376,15 +486,16 @@ class ProjectService:
|
||||
for row in connected_result.fetchall()
|
||||
]
|
||||
|
||||
# Count isolated entities (no relations)
|
||||
# Count isolated entities (no relations) - project filtered
|
||||
isolated_result = await self.repository.execute_query(
|
||||
text("""
|
||||
SELECT COUNT(e.id)
|
||||
FROM entity e
|
||||
LEFT JOIN relation r1 ON e.id = r1.from_id
|
||||
LEFT JOIN relation r2 ON e.id = r2.to_id
|
||||
WHERE r1.id IS NULL AND r2.id IS NULL
|
||||
""")
|
||||
WHERE e.project_id = :project_id AND r1.id IS NULL AND r2.id IS NULL
|
||||
"""),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
isolated_count = isolated_result.scalar() or 0
|
||||
|
||||
@@ -400,19 +511,25 @@ class ProjectService:
|
||||
isolated_entities=isolated_count,
|
||||
)
|
||||
|
||||
async def get_activity_metrics(self) -> ActivityMetrics:
|
||||
"""Get activity metrics for the current project."""
|
||||
async def get_activity_metrics(self, project_id: int) -> ActivityMetrics:
|
||||
"""Get activity metrics for the specified project.
|
||||
|
||||
Args:
|
||||
project_id: ID of the project to get activity metrics for (required).
|
||||
"""
|
||||
if not self.repository: # pragma: no cover
|
||||
raise ValueError("Repository is required for get_activity_metrics")
|
||||
|
||||
# Get recently created entities
|
||||
# Get recently created entities (project filtered)
|
||||
created_result = await self.repository.execute_query(
|
||||
text("""
|
||||
SELECT id, title, permalink, entity_type, created_at, file_path
|
||||
FROM entity
|
||||
WHERE project_id = :project_id
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 10
|
||||
""")
|
||||
"""),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
recently_created = [
|
||||
{
|
||||
@@ -426,14 +543,16 @@ class ProjectService:
|
||||
for row in created_result.fetchall()
|
||||
]
|
||||
|
||||
# Get recently updated entities
|
||||
# Get recently updated entities (project filtered)
|
||||
updated_result = await self.repository.execute_query(
|
||||
text("""
|
||||
SELECT id, title, permalink, entity_type, updated_at, file_path
|
||||
FROM entity
|
||||
WHERE project_id = :project_id
|
||||
ORDER BY updated_at DESC
|
||||
LIMIT 10
|
||||
""")
|
||||
"""),
|
||||
{"project_id": project_id},
|
||||
)
|
||||
recently_updated = [
|
||||
{
|
||||
@@ -454,47 +573,50 @@ class ProjectService:
|
||||
now.year - (1 if now.month <= 6 else 0), ((now.month - 6) % 12) or 12, 1
|
||||
)
|
||||
|
||||
# Query for monthly entity creation
|
||||
# Query for monthly entity creation (project filtered)
|
||||
entity_growth_result = await self.repository.execute_query(
|
||||
text(f"""
|
||||
text("""
|
||||
SELECT
|
||||
strftime('%Y-%m', created_at) AS month,
|
||||
COUNT(*) AS count
|
||||
FROM entity
|
||||
WHERE created_at >= '{six_months_ago.isoformat()}'
|
||||
WHERE created_at >= :six_months_ago AND project_id = :project_id
|
||||
GROUP BY month
|
||||
ORDER BY month
|
||||
""")
|
||||
"""),
|
||||
{"six_months_ago": six_months_ago.isoformat(), "project_id": project_id},
|
||||
)
|
||||
entity_growth = {row[0]: row[1] for row in entity_growth_result.fetchall()}
|
||||
|
||||
# Query for monthly observation creation
|
||||
# Query for monthly observation creation (project filtered)
|
||||
observation_growth_result = await self.repository.execute_query(
|
||||
text(f"""
|
||||
text("""
|
||||
SELECT
|
||||
strftime('%Y-%m', created_at) AS month,
|
||||
strftime('%Y-%m', entity.created_at) AS month,
|
||||
COUNT(*) AS count
|
||||
FROM observation
|
||||
INNER JOIN entity ON observation.entity_id = entity.id
|
||||
WHERE entity.created_at >= '{six_months_ago.isoformat()}'
|
||||
WHERE entity.created_at >= :six_months_ago AND entity.project_id = :project_id
|
||||
GROUP BY month
|
||||
ORDER BY month
|
||||
""")
|
||||
"""),
|
||||
{"six_months_ago": six_months_ago.isoformat(), "project_id": project_id},
|
||||
)
|
||||
observation_growth = {row[0]: row[1] for row in observation_growth_result.fetchall()}
|
||||
|
||||
# Query for monthly relation creation
|
||||
# Query for monthly relation creation (project filtered)
|
||||
relation_growth_result = await self.repository.execute_query(
|
||||
text(f"""
|
||||
text("""
|
||||
SELECT
|
||||
strftime('%Y-%m', created_at) AS month,
|
||||
strftime('%Y-%m', entity.created_at) AS month,
|
||||
COUNT(*) AS count
|
||||
FROM relation
|
||||
INNER JOIN entity ON relation.from_id = entity.id
|
||||
WHERE entity.created_at >= '{six_months_ago.isoformat()}'
|
||||
WHERE entity.created_at >= :six_months_ago AND entity.project_id = :project_id
|
||||
GROUP BY month
|
||||
ORDER BY month
|
||||
""")
|
||||
"""),
|
||||
{"six_months_ago": six_months_ago.isoformat(), "project_id": project_id},
|
||||
)
|
||||
relation_growth = {row[0]: row[1] for row in relation_growth_result.fetchall()}
|
||||
|
||||
@@ -546,4 +668,4 @@ class ProjectService:
|
||||
database_size=db_size_readable,
|
||||
watch_status=watch_status,
|
||||
timestamp=datetime.now(),
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,181 @@
|
||||
"""Simple sync status tracking service."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import Dict, Optional
|
||||
|
||||
|
||||
class SyncStatus(Enum):
|
||||
"""Status of sync operations."""
|
||||
|
||||
IDLE = "idle"
|
||||
SCANNING = "scanning"
|
||||
SYNCING = "syncing"
|
||||
COMPLETED = "completed"
|
||||
FAILED = "failed"
|
||||
WATCHING = "watching"
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProjectSyncStatus:
|
||||
"""Sync status for a single project."""
|
||||
|
||||
project_name: str
|
||||
status: SyncStatus
|
||||
message: str = ""
|
||||
files_total: int = 0
|
||||
files_processed: int = 0
|
||||
error: Optional[str] = None
|
||||
|
||||
|
||||
class SyncStatusTracker:
|
||||
"""Global tracker for all sync operations."""
|
||||
|
||||
def __init__(self):
|
||||
self._project_statuses: Dict[str, ProjectSyncStatus] = {}
|
||||
self._global_status: SyncStatus = SyncStatus.IDLE
|
||||
|
||||
def start_project_sync(self, project_name: str, files_total: int = 0) -> None:
|
||||
"""Start tracking sync for a project."""
|
||||
self._project_statuses[project_name] = ProjectSyncStatus(
|
||||
project_name=project_name,
|
||||
status=SyncStatus.SCANNING,
|
||||
message="Scanning files",
|
||||
files_total=files_total,
|
||||
files_processed=0,
|
||||
)
|
||||
self._update_global_status()
|
||||
|
||||
def update_project_progress( # pragma: no cover
|
||||
self,
|
||||
project_name: str,
|
||||
status: SyncStatus,
|
||||
message: str = "",
|
||||
files_processed: int = 0,
|
||||
files_total: Optional[int] = None,
|
||||
) -> None:
|
||||
"""Update progress for a project."""
|
||||
if project_name not in self._project_statuses: # pragma: no cover
|
||||
return
|
||||
|
||||
project_status = self._project_statuses[project_name]
|
||||
project_status.status = status
|
||||
project_status.message = message
|
||||
project_status.files_processed = files_processed
|
||||
|
||||
if files_total is not None:
|
||||
project_status.files_total = files_total
|
||||
|
||||
self._update_global_status()
|
||||
|
||||
def complete_project_sync(self, project_name: str) -> None:
|
||||
"""Mark project sync as completed."""
|
||||
if project_name in self._project_statuses:
|
||||
self._project_statuses[project_name].status = SyncStatus.COMPLETED
|
||||
self._project_statuses[project_name].message = "Sync completed"
|
||||
self._update_global_status()
|
||||
|
||||
def fail_project_sync(self, project_name: str, error: str) -> None:
|
||||
"""Mark project sync as failed."""
|
||||
if project_name in self._project_statuses:
|
||||
self._project_statuses[project_name].status = SyncStatus.FAILED
|
||||
self._project_statuses[project_name].error = error
|
||||
self._update_global_status()
|
||||
|
||||
def start_project_watch(self, project_name: str) -> None:
|
||||
"""Mark project as watching for changes (steady state after sync)."""
|
||||
if project_name in self._project_statuses:
|
||||
self._project_statuses[project_name].status = SyncStatus.WATCHING
|
||||
self._project_statuses[project_name].message = "Watching for changes"
|
||||
self._update_global_status()
|
||||
else:
|
||||
# Create new status if project isn't tracked yet
|
||||
self._project_statuses[project_name] = ProjectSyncStatus(
|
||||
project_name=project_name,
|
||||
status=SyncStatus.WATCHING,
|
||||
message="Watching for changes",
|
||||
files_total=0,
|
||||
files_processed=0,
|
||||
)
|
||||
self._update_global_status()
|
||||
|
||||
def _update_global_status(self) -> None:
|
||||
"""Update global status based on project statuses."""
|
||||
if not self._project_statuses: # pragma: no cover
|
||||
self._global_status = SyncStatus.IDLE
|
||||
return
|
||||
|
||||
statuses = [p.status for p in self._project_statuses.values()]
|
||||
|
||||
if any(s == SyncStatus.FAILED for s in statuses):
|
||||
self._global_status = SyncStatus.FAILED
|
||||
elif any(s in (SyncStatus.SCANNING, SyncStatus.SYNCING) for s in statuses):
|
||||
self._global_status = SyncStatus.SYNCING
|
||||
elif all(s in (SyncStatus.COMPLETED, SyncStatus.WATCHING) for s in statuses):
|
||||
self._global_status = SyncStatus.COMPLETED
|
||||
else:
|
||||
self._global_status = SyncStatus.SYNCING
|
||||
|
||||
@property
|
||||
def global_status(self) -> SyncStatus:
|
||||
"""Get overall sync status."""
|
||||
return self._global_status
|
||||
|
||||
@property
|
||||
def is_syncing(self) -> bool:
|
||||
"""Check if any sync operation is in progress."""
|
||||
return self._global_status in (SyncStatus.SCANNING, SyncStatus.SYNCING)
|
||||
|
||||
@property
|
||||
def is_ready(self) -> bool: # pragma: no cover
|
||||
"""Check if system is ready (no sync in progress)."""
|
||||
return self._global_status in (SyncStatus.IDLE, SyncStatus.COMPLETED)
|
||||
|
||||
def get_project_status(self, project_name: str) -> Optional[ProjectSyncStatus]:
|
||||
"""Get status for a specific project."""
|
||||
return self._project_statuses.get(project_name)
|
||||
|
||||
def get_all_projects(self) -> Dict[str, ProjectSyncStatus]:
|
||||
"""Get all project statuses."""
|
||||
return self._project_statuses.copy()
|
||||
|
||||
def get_summary(self) -> str: # pragma: no cover
|
||||
"""Get a user-friendly summary of sync status."""
|
||||
if self._global_status == SyncStatus.IDLE:
|
||||
return "✅ System ready"
|
||||
elif self._global_status == SyncStatus.COMPLETED:
|
||||
return "✅ All projects synced successfully"
|
||||
elif self._global_status == SyncStatus.FAILED:
|
||||
failed_projects = [
|
||||
p.project_name
|
||||
for p in self._project_statuses.values()
|
||||
if p.status == SyncStatus.FAILED
|
||||
]
|
||||
return f"❌ Sync failed for: {', '.join(failed_projects)}"
|
||||
else:
|
||||
active_projects = [
|
||||
p.project_name
|
||||
for p in self._project_statuses.values()
|
||||
if p.status in (SyncStatus.SCANNING, SyncStatus.SYNCING)
|
||||
]
|
||||
total_files = sum(p.files_total for p in self._project_statuses.values())
|
||||
processed_files = sum(p.files_processed for p in self._project_statuses.values())
|
||||
|
||||
if total_files > 0:
|
||||
progress_pct = (processed_files / total_files) * 100
|
||||
return f"🔄 Syncing {len(active_projects)} projects ({processed_files}/{total_files} files, {progress_pct:.0f}%)"
|
||||
else:
|
||||
return f"🔄 Syncing {len(active_projects)} projects"
|
||||
|
||||
def clear_completed(self) -> None:
|
||||
"""Remove completed project statuses to clean up memory."""
|
||||
self._project_statuses = {
|
||||
name: status
|
||||
for name, status in self._project_statuses.items()
|
||||
if status.status != SyncStatus.COMPLETED
|
||||
}
|
||||
self._update_global_status()
|
||||
|
||||
|
||||
# Global sync status tracker instance
|
||||
sync_status_tracker = SyncStatusTracker()
|
||||
@@ -17,6 +17,7 @@ from basic_memory.models import Entity
|
||||
from basic_memory.repository import EntityRepository, RelationRepository
|
||||
from basic_memory.services import EntityService, FileService
|
||||
from basic_memory.services.search_service import SearchService
|
||||
from basic_memory.services.sync_status_service import sync_status_tracker, SyncStatus
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -80,23 +81,38 @@ class SyncService:
|
||||
self.search_service = search_service
|
||||
self.file_service = file_service
|
||||
|
||||
async def sync(self, directory: Path) -> SyncReport:
|
||||
async def sync(self, directory: Path, project_name: Optional[str] = None) -> SyncReport:
|
||||
"""Sync all files with database."""
|
||||
|
||||
start_time = time.time()
|
||||
logger.info(f"Sync operation started for directory: {directory}")
|
||||
|
||||
# Start tracking sync for this project if project name provided
|
||||
if project_name:
|
||||
sync_status_tracker.start_project_sync(project_name)
|
||||
|
||||
# initial paths from db to sync
|
||||
# path -> checksum
|
||||
report = await self.scan(directory)
|
||||
|
||||
# Initialize progress tracking if requested
|
||||
# Update progress with file counts
|
||||
if project_name:
|
||||
sync_status_tracker.update_project_progress(
|
||||
project_name=project_name,
|
||||
status=SyncStatus.SYNCING,
|
||||
message="Processing file changes",
|
||||
files_total=report.total,
|
||||
files_processed=0,
|
||||
)
|
||||
|
||||
# order of sync matters to resolve relations effectively
|
||||
logger.info(
|
||||
f"Sync changes detected: new_files={len(report.new)}, modified_files={len(report.modified)}, "
|
||||
+ f"deleted_files={len(report.deleted)}, moved_files={len(report.moves)}"
|
||||
)
|
||||
|
||||
files_processed = 0
|
||||
|
||||
# sync moves first
|
||||
for old_path, new_path in report.moves.items():
|
||||
# in the case where a file has been deleted and replaced by another file
|
||||
@@ -109,19 +125,56 @@ class SyncService:
|
||||
else:
|
||||
await self.handle_move(old_path, new_path)
|
||||
|
||||
files_processed += 1
|
||||
if project_name:
|
||||
sync_status_tracker.update_project_progress( # pragma: no cover
|
||||
project_name=project_name,
|
||||
status=SyncStatus.SYNCING,
|
||||
message="Processing moves",
|
||||
files_processed=files_processed,
|
||||
)
|
||||
|
||||
# deleted next
|
||||
for path in report.deleted:
|
||||
await self.handle_delete(path)
|
||||
files_processed += 1
|
||||
if project_name:
|
||||
sync_status_tracker.update_project_progress( # pragma: no cover
|
||||
project_name=project_name,
|
||||
status=SyncStatus.SYNCING,
|
||||
message="Processing deletions",
|
||||
files_processed=files_processed,
|
||||
)
|
||||
|
||||
# then new and modified
|
||||
for path in report.new:
|
||||
await self.sync_file(path, new=True)
|
||||
files_processed += 1
|
||||
if project_name:
|
||||
sync_status_tracker.update_project_progress(
|
||||
project_name=project_name,
|
||||
status=SyncStatus.SYNCING,
|
||||
message="Processing new files",
|
||||
files_processed=files_processed,
|
||||
)
|
||||
|
||||
for path in report.modified:
|
||||
await self.sync_file(path, new=False)
|
||||
files_processed += 1
|
||||
if project_name:
|
||||
sync_status_tracker.update_project_progress( # pragma: no cover
|
||||
project_name=project_name,
|
||||
status=SyncStatus.SYNCING,
|
||||
message="Processing modified files",
|
||||
files_processed=files_processed,
|
||||
)
|
||||
|
||||
await self.resolve_relations()
|
||||
|
||||
# Mark sync as completed
|
||||
if project_name:
|
||||
sync_status_tracker.complete_project_sync(project_name)
|
||||
|
||||
duration_ms = int((time.time() - start_time) * 1000)
|
||||
logger.info(
|
||||
f"Sync operation completed: directory={directory}, total_changes={report.total}, duration_ms={duration_ms}"
|
||||
@@ -311,18 +364,43 @@ class SyncService:
|
||||
content_type = self.file_service.content_type(path)
|
||||
|
||||
file_path = Path(path)
|
||||
entity = await self.entity_repository.add(
|
||||
Entity(
|
||||
entity_type="file",
|
||||
file_path=path,
|
||||
checksum=checksum,
|
||||
title=file_path.name,
|
||||
created_at=created,
|
||||
updated_at=modified,
|
||||
content_type=content_type,
|
||||
try:
|
||||
entity = await self.entity_repository.add(
|
||||
Entity(
|
||||
entity_type="file",
|
||||
file_path=path,
|
||||
checksum=checksum,
|
||||
title=file_path.name,
|
||||
created_at=created,
|
||||
updated_at=modified,
|
||||
content_type=content_type,
|
||||
)
|
||||
)
|
||||
)
|
||||
return entity, checksum
|
||||
return entity, checksum
|
||||
except IntegrityError as e:
|
||||
# Handle race condition where entity was created by another process
|
||||
if "UNIQUE constraint failed: entity.file_path" in str(e):
|
||||
logger.info(
|
||||
f"Entity already exists for file_path={path}, updating instead of creating"
|
||||
)
|
||||
# Treat as update instead of create
|
||||
entity = await self.entity_repository.get_by_file_path(path)
|
||||
if entity is None: # pragma: no cover
|
||||
logger.error(f"Entity not found after constraint violation, path={path}")
|
||||
raise ValueError(f"Entity not found after constraint violation: {path}")
|
||||
|
||||
updated = await self.entity_repository.update(
|
||||
entity.id, {"file_path": path, "checksum": checksum}
|
||||
)
|
||||
|
||||
if updated is None: # pragma: no cover
|
||||
logger.error(f"Failed to update entity, entity_id={entity.id}, path={path}")
|
||||
raise ValueError(f"Failed to update entity with ID {entity.id}")
|
||||
|
||||
return updated, checksum
|
||||
else:
|
||||
# Re-raise if it's a different integrity error
|
||||
raise
|
||||
else:
|
||||
entity = await self.entity_repository.get_by_file_path(path)
|
||||
if entity is None: # pragma: no cover
|
||||
|
||||
+187
-120
@@ -33,51 +33,101 @@ build these connections!
|
||||
|
||||
## Core Tools Reference
|
||||
|
||||
```python
|
||||
# Writing knowledge - THE MOST IMPORTANT TOOL!
|
||||
response = await write_note(
|
||||
title="Search Design", # Required: Note title
|
||||
content="# Search Design\n...", # Required: Note content
|
||||
folder="specs", # Optional: Folder to save in
|
||||
tags=["search", "design"], # Optional: Tags for categorization
|
||||
verbose=True # Optional: Get parsing details
|
||||
**Writing knowledge - THE MOST IMPORTANT TOOL!**
|
||||
```
|
||||
write_note(
|
||||
title="Search Design",
|
||||
content="# Search Design\n\n## Overview\nSearch functionality design and implementation.\n\n## Observations\n- [requirement] Must support full-text search #search\n- [decision] Using vector embeddings for semantic search #technology\n\n## Relations\n- implements [[Search Requirements]]\n- part_of [[API Specification]]",
|
||||
folder="specs",
|
||||
tags=["search", "design"]
|
||||
)
|
||||
```
|
||||
|
||||
**Reading knowledge:**
|
||||
```
|
||||
read_note("Search Design") # By exact title
|
||||
read_note("specs/search-design") # By permalink
|
||||
read_note("memory://specs/search") # By memory URL
|
||||
```
|
||||
|
||||
**Viewing notes as formatted artifacts (Claude Desktop):**
|
||||
```
|
||||
view_note("Search Design") # Creates readable artifact
|
||||
view_note("specs/search-design") # By permalink
|
||||
view_note("memory://specs/search") # By memory URL
|
||||
```
|
||||
|
||||
**Incremental editing (v0.13.0) - REQUIRES EXACT IDENTIFIERS:**
|
||||
```
|
||||
edit_note(
|
||||
identifier="Search Design", # Must be EXACT title/permalink
|
||||
operation="append",
|
||||
content="\n## Implementation Notes\n- Added caching layer for performance"
|
||||
)
|
||||
|
||||
# Reading knowledge
|
||||
content = await read_note("Search Design") # By title
|
||||
content = await read_note("specs/search-design") # By path
|
||||
content = await read_note("memory://specs/search") # By memory URL
|
||||
|
||||
# Searching for knowledge
|
||||
results = await search_notes(
|
||||
query="authentication system", # Text to search for
|
||||
page=1, # Optional: Pagination
|
||||
page_size=10 # Optional: Results per page
|
||||
edit_note(
|
||||
identifier="API Documentation",
|
||||
operation="replace_section",
|
||||
section="## Authentication",
|
||||
content="Updated authentication using JWT tokens with refresh capability."
|
||||
)
|
||||
```
|
||||
|
||||
# Building context from the knowledge graph
|
||||
context = await build_context(
|
||||
url="memory://specs/search", # Starting point
|
||||
depth=2, # Optional: How many hops to follow
|
||||
timeframe="1 month" # Optional: Recent timeframe
|
||||
**File organization (v0.13.0) - REQUIRES EXACT IDENTIFIERS:**
|
||||
```
|
||||
move_note(
|
||||
identifier="Old Meeting Notes", # Must be EXACT title/permalink
|
||||
destination_path="archive/2024/meeting-notes.md"
|
||||
)
|
||||
```
|
||||
|
||||
# Checking recent changes
|
||||
activity = await recent_activity(
|
||||
type="all", # Optional: Entity types to include
|
||||
depth=1, # Optional: Related items to include
|
||||
timeframe="1 week" # Optional: Time window
|
||||
**Searching for knowledge:**
|
||||
```
|
||||
search_notes(
|
||||
query="authentication system",
|
||||
page=1,
|
||||
page_size=10
|
||||
)
|
||||
```
|
||||
|
||||
# Creating a knowledge visualization
|
||||
canvas_result = await canvas(
|
||||
nodes=[{"id": "note1", "label": "Search Design"}], # Nodes to display
|
||||
edges=[{"from": "note1", "to": "note2"}], # Connections
|
||||
title="Project Overview", # Canvas title
|
||||
folder="diagrams" # Storage location
|
||||
**Building context from the knowledge graph:**
|
||||
```
|
||||
build_context(
|
||||
url="memory://specs/search",
|
||||
depth=2,
|
||||
timeframe="1 month"
|
||||
)
|
||||
```
|
||||
|
||||
**Checking recent changes:**
|
||||
```
|
||||
recent_activity(
|
||||
timeframe="1 week",
|
||||
depth=1
|
||||
)
|
||||
```
|
||||
|
||||
**Creating knowledge visualizations:**
|
||||
```
|
||||
canvas(
|
||||
nodes=[
|
||||
{"id": "search", "x": 100, "y": 100, "width": 200, "height": 100, "type": "text", "text": "Search Design"},
|
||||
{"id": "api", "x": 400, "y": 100, "width": 200, "height": 100, "type": "text", "text": "API Specification"}
|
||||
],
|
||||
edges=[
|
||||
{"id": "link1", "fromNode": "search", "toNode": "api"}
|
||||
],
|
||||
title="System Architecture",
|
||||
folder="diagrams"
|
||||
)
|
||||
```
|
||||
|
||||
**Monitoring sync status:**
|
||||
```
|
||||
sync_status() # Check overall system status
|
||||
sync_status(project="work-notes") # Check specific project status
|
||||
```
|
||||
|
||||
## memory:// URLs Explained
|
||||
|
||||
Basic Memory uses a special URL format to reference entities in the knowledge graph:
|
||||
@@ -259,45 +309,24 @@ When creating relations, you can:
|
||||
1. Reference existing entities by their exact title
|
||||
2. Create forward references to entities that don't exist yet
|
||||
|
||||
```python
|
||||
# Example workflow for creating notes with effective relations
|
||||
async def create_note_with_effective_relations():
|
||||
# Search for existing entities to reference
|
||||
search_results = await search_notes("travel")
|
||||
existing_entities = [result.title for result in search_results.primary_results]
|
||||
**Example workflow for creating notes with effective relations:**
|
||||
|
||||
# Check if specific entities exist
|
||||
packing_tips_exists = "Packing Tips" in existing_entities
|
||||
japan_travel_exists = "Japan Travel Guide" in existing_entities
|
||||
1. **First, search for existing entities to reference:**
|
||||
```
|
||||
search_notes(query="travel")
|
||||
```
|
||||
|
||||
# Prepare relations section - include both existing and forward references
|
||||
relations_section = "## Relations\n"
|
||||
2. **Check recent activity for current topics:**
|
||||
```
|
||||
recent_activity(timeframe="1 week")
|
||||
```
|
||||
|
||||
# Existing reference - exact match to known entity
|
||||
if packing_tips_exists:
|
||||
relations_section += "- references [[Packing Tips]]\n"
|
||||
else:
|
||||
# Forward reference - will be linked when that entity is created later
|
||||
relations_section += "- references [[Packing Tips]]\n"
|
||||
3. **Create the note with both existing and forward references:**
|
||||
```
|
||||
write_note(
|
||||
title="Tokyo Neighborhood Guide",
|
||||
content="# Tokyo Neighborhood Guide
|
||||
|
||||
# Another possible reference
|
||||
if japan_travel_exists:
|
||||
relations_section += "- part_of [[Japan Travel Guide]]\n"
|
||||
|
||||
# You can also check recently modified notes to reference them
|
||||
recent = await recent_activity(timeframe="1 week")
|
||||
recent_titles = [item.title for item in recent.primary_results]
|
||||
|
||||
if "Transportation Options" in recent_titles:
|
||||
relations_section += "- relates_to [[Transportation Options]]\n"
|
||||
|
||||
# Always include meaningful forward references, even if they don't exist yet
|
||||
relations_section += "- located_in [[Tokyo]]\n"
|
||||
relations_section += "- visited_during [[Spring 2023 Trip]]\n"
|
||||
|
||||
# Now create the note with both verified and forward relations
|
||||
content = f"""# Tokyo Neighborhood Guide
|
||||
|
||||
## Overview
|
||||
Details about different Tokyo neighborhoods and their unique characteristics.
|
||||
|
||||
@@ -307,65 +336,103 @@ Details about different Tokyo neighborhoods and their unique characteristics.
|
||||
- [recommendation] Visit Shimokitazawa for vintage shopping #unique
|
||||
- [tip] Get a Suica card for easy train travel #convenience
|
||||
|
||||
{relations_section}
|
||||
"""
|
||||
|
||||
result = await write_note(
|
||||
title="Tokyo Neighborhood Guide",
|
||||
content=content,
|
||||
verbose=True
|
||||
)
|
||||
|
||||
# You can check which relations were resolved and which are forward references
|
||||
if result and 'relations' in result:
|
||||
resolved = [r['to_name'] for r in result['relations'] if r.get('target_id')]
|
||||
forward_refs = [r['to_name'] for r in result['relations'] if not r.get('target_id')]
|
||||
|
||||
print(f"Resolved relations: {resolved}")
|
||||
print(f"Forward references that will be resolved later: {forward_refs}")
|
||||
## Relations
|
||||
- references [[Packing Tips]] # Forward reference (will be linked when created)
|
||||
- part_of [[Japan Travel Guide]] # Existing reference (if found in search)
|
||||
- relates_to [[Transportation Options]] # Recent reference (if found in activity)
|
||||
- located_in [[Tokyo]] # Forward reference
|
||||
- visited_during [[Spring 2023 Trip]] # Forward reference",
|
||||
folder="travel",
|
||||
tags=["tokyo", "neighborhoods", "travel"]
|
||||
)
|
||||
```
|
||||
|
||||
**Key points:**
|
||||
- Use exact titles from search results for existing entities: `[[Exact Title Found]]`
|
||||
- Forward references are fine - they'll be linked automatically when target notes are created
|
||||
- Check recent activity to reference currently active topics
|
||||
- Use meaningful relation types: `part_of`, `located_in`, `visited_during` vs generic `relates_to`
|
||||
|
||||
## Error Handling
|
||||
|
||||
Common issues to watch for:
|
||||
|
||||
1. **Missing Content**
|
||||
```python
|
||||
try:
|
||||
content = await read_note("Document")
|
||||
except:
|
||||
# Try search instead
|
||||
results = await search_notes("Document")
|
||||
if results and results.primary_results:
|
||||
# Found something similar
|
||||
content = await read_note(results.primary_results[0].permalink)
|
||||
```
|
||||
**1. Missing Content - Use Search as Fallback**
|
||||
```
|
||||
# If read_note fails, try search instead
|
||||
search_notes(query="Document")
|
||||
# Then use exact result from search:
|
||||
read_note("Exact Document Title Found")
|
||||
```
|
||||
|
||||
2. **Forward References (Unresolved Relations)**
|
||||
```python
|
||||
response = await write_note(..., verbose=True)
|
||||
# Check for forward references (unresolved relations)
|
||||
forward_refs = []
|
||||
for relation in response.get('relations', []):
|
||||
if not relation.get('target_id'):
|
||||
forward_refs.append(relation.get('to_name'))
|
||||
|
||||
if forward_refs:
|
||||
# This is a feature, not an error! Inform the user about forward references
|
||||
print(f"Note created with forward references to: {forward_refs}")
|
||||
print("These will be automatically linked when those notes are created.")
|
||||
|
||||
# Optionally suggest creating those entities now
|
||||
print("Would you like me to create any of these notes now to complete the connections?")
|
||||
```
|
||||
**2. Strict Mode for Edit/Move Operations (v0.13.0)**
|
||||
|
||||
3. **Sync Issues**
|
||||
```python
|
||||
# If information seems outdated
|
||||
activity = await recent_activity(timeframe="1 hour")
|
||||
if not activity or not activity.primary_results:
|
||||
print("It seems there haven't been recent updates. You might need to run 'basic-memory sync'.")
|
||||
```
|
||||
❌ **This might fail if identifier isn't exact:**
|
||||
```
|
||||
edit_note(identifier="Meeting Note", operation="append", content="new content")
|
||||
```
|
||||
|
||||
✅ **Safe approach - search first, then use exact result:**
|
||||
```
|
||||
# 1. Search first to find exact identifier
|
||||
search_notes(query="meeting")
|
||||
|
||||
# 2. Use exact title from search results
|
||||
edit_note(identifier="Meeting Notes 2024", operation="append", content="new content")
|
||||
|
||||
# Same pattern for move_note:
|
||||
search_notes(query="old note")
|
||||
move_note(identifier="Old Meeting Notes", destination_path="archive/old-notes.md")
|
||||
```
|
||||
|
||||
**3. Forward References (Unresolved Relations)**
|
||||
|
||||
Forward references are a **feature, not an error!** Basic Memory automatically links them when target notes are created.
|
||||
|
||||
When you see unresolved relations in the response:
|
||||
- Inform users: "I've created forward references that will be linked when you create those notes"
|
||||
- Optionally suggest: "Would you like me to create any of these notes now to complete the connections?"
|
||||
|
||||
**4. Sync Issues**
|
||||
|
||||
If information seems outdated:
|
||||
```
|
||||
recent_activity(timeframe="1 hour")
|
||||
```
|
||||
If no recent activity shows, check sync status first:
|
||||
```
|
||||
sync_status()
|
||||
```
|
||||
If sync is pending or failed, suggest: "You might need to run `basic-memory sync`"
|
||||
|
||||
**5. Understanding Sync Status**
|
||||
|
||||
The `sync_status()` tool provides essential information about Basic Memory's operational state:
|
||||
|
||||
```
|
||||
sync_status() # Check overall system readiness
|
||||
sync_status(project="work-notes") # Check specific project context
|
||||
```
|
||||
|
||||
**When to use sync_status:**
|
||||
- At the start of conversations to verify system readiness
|
||||
- When operations seem slow or fail unexpectedly
|
||||
- Before working with large knowledge bases
|
||||
- When switching between projects
|
||||
- To provide users context about background processing
|
||||
|
||||
**What sync_status tells you:**
|
||||
- **System Ready**: Whether all files are indexed and tools are operational
|
||||
- **Active Processing**: Which projects are currently syncing with progress indicators
|
||||
- **Project Status**: Individual project sync states (👁️ watching, ✅ completed, 🔄 syncing, ❌ failed, ⏳ pending)
|
||||
- **Error Details**: Specific error messages for failed sync operations
|
||||
- **Guidance**: Next steps when issues are detected
|
||||
|
||||
**Using sync_status effectively:**
|
||||
- Check status if tools return unexpected results
|
||||
- Use project parameter when working in multi-project setups
|
||||
- Share status with users when explaining delays
|
||||
- Monitor progress during initial setup or large imports
|
||||
|
||||
## Best Practices
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,172 @@
|
||||
"""Integration tests for build_context memory URL validation."""
|
||||
|
||||
import pytest
|
||||
from fastmcp import Client
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_context_valid_urls(mcp_server, app):
|
||||
"""Test that build_context works with valid memory URLs."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# Create a test note to ensure we have something to find
|
||||
await client.call_tool(
|
||||
"write_note",
|
||||
{
|
||||
"title": "URL Validation Test",
|
||||
"folder": "testing",
|
||||
"content": "# URL Validation Test\n\nThis note tests URL validation.",
|
||||
"tags": "test,validation",
|
||||
},
|
||||
)
|
||||
|
||||
# Test various valid URL formats
|
||||
valid_urls = [
|
||||
"memory://testing/url-validation-test", # Full memory URL
|
||||
"testing/url-validation-test", # Relative path
|
||||
"testing/*", # Pattern matching
|
||||
]
|
||||
|
||||
for url in valid_urls:
|
||||
result = await client.call_tool("build_context", {"url": url})
|
||||
|
||||
# Should return a valid GraphContext response
|
||||
assert len(result) == 1
|
||||
response = result[0].text
|
||||
assert '"results"' in response # Should contain results structure
|
||||
assert '"metadata"' in response # Should contain metadata
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_context_invalid_urls_fail_validation(mcp_server, app):
|
||||
"""Test that build_context properly validates and rejects invalid memory URLs."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# Test cases: (invalid_url, expected_error_fragment)
|
||||
invalid_test_cases = [
|
||||
("memory//test", "double slashes"),
|
||||
("invalid://test", "protocol scheme"),
|
||||
("notes<brackets>", "invalid characters"),
|
||||
('notes"quotes"', "invalid characters"),
|
||||
]
|
||||
|
||||
for invalid_url, expected_error in invalid_test_cases:
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool("build_context", {"url": invalid_url})
|
||||
|
||||
error_message = str(exc_info.value).lower()
|
||||
assert expected_error in error_message, (
|
||||
f"URL '{invalid_url}' should fail with '{expected_error}' error"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_context_empty_urls_fail_validation(mcp_server, app):
|
||||
"""Test that empty or whitespace-only URLs fail validation."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# These should fail MinLen validation
|
||||
empty_urls = [
|
||||
"", # Empty string
|
||||
" ", # Whitespace only
|
||||
]
|
||||
|
||||
for empty_url in empty_urls:
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool("build_context", {"url": empty_url})
|
||||
|
||||
error_message = str(exc_info.value)
|
||||
# Should fail with validation error (either MinLen or our custom validation)
|
||||
assert (
|
||||
"at least 1" in error_message
|
||||
or "too_short" in error_message
|
||||
or "empty or whitespace" in error_message
|
||||
or "value_error" in error_message
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_context_nonexistent_urls_return_empty_results(mcp_server, app):
|
||||
"""Test that valid but nonexistent URLs return empty results (not errors)."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# These are valid URL formats but don't exist in the system
|
||||
nonexistent_valid_urls = [
|
||||
"memory://nonexistent/note",
|
||||
"nonexistent/note",
|
||||
"missing/*",
|
||||
]
|
||||
|
||||
for url in nonexistent_valid_urls:
|
||||
result = await client.call_tool("build_context", {"url": url})
|
||||
|
||||
# Should return valid response with empty results
|
||||
assert len(result) == 1
|
||||
response = result[0].text
|
||||
assert '"results": []' in response # Empty results
|
||||
assert '"total_results": 0' in response # Zero count
|
||||
assert '"metadata"' in response # But should have metadata
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_context_error_messages_are_helpful(mcp_server, app):
|
||||
"""Test that validation error messages provide helpful guidance."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# Test double slash error message
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool("build_context", {"url": "memory//bad"})
|
||||
|
||||
error_msg = str(exc_info.value).lower()
|
||||
# Should contain validation error info
|
||||
assert (
|
||||
"double slashes" in error_msg
|
||||
or "value_error" in error_msg
|
||||
or "validation error" in error_msg
|
||||
)
|
||||
|
||||
# Test protocol scheme error message
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool("build_context", {"url": "http://example.com"})
|
||||
|
||||
error_msg = str(exc_info.value).lower()
|
||||
assert (
|
||||
"protocol scheme" in error_msg
|
||||
or "protocol" in error_msg
|
||||
or "value_error" in error_msg
|
||||
or "validation error" in error_msg
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_context_pattern_matching_works(mcp_server, app):
|
||||
"""Test that valid pattern matching URLs work correctly."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# Create multiple test notes
|
||||
test_notes = [
|
||||
("Pattern Test One", "patterns", "# Pattern Test One\n\nFirst pattern test."),
|
||||
("Pattern Test Two", "patterns", "# Pattern Test Two\n\nSecond pattern test."),
|
||||
("Other Note", "other", "# Other Note\n\nNot a pattern match."),
|
||||
]
|
||||
|
||||
for title, folder, content in test_notes:
|
||||
await client.call_tool(
|
||||
"write_note",
|
||||
{
|
||||
"title": title,
|
||||
"folder": folder,
|
||||
"content": content,
|
||||
},
|
||||
)
|
||||
|
||||
# Test pattern matching
|
||||
result = await client.call_tool("build_context", {"url": "patterns/*"})
|
||||
|
||||
assert len(result) == 1
|
||||
response = result[0].text
|
||||
|
||||
# Should find the pattern matches but not the other note
|
||||
assert '"total_results": 2' in response or '"primary_count": 2' in response
|
||||
assert "Pattern Test" in response
|
||||
assert "Other Note" not in response
|
||||
@@ -60,7 +60,6 @@ async def test_delete_note_by_title(mcp_server, app):
|
||||
result_text = read_after_delete[0].text
|
||||
assert "Note Not Found" in result_text
|
||||
assert "Note to Delete" in result_text
|
||||
assert "I couldn't find any notes matching" in result_text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -324,10 +324,9 @@ async def test_edit_note_error_handling_note_not_found(mcp_server, app):
|
||||
# Should return helpful error message
|
||||
assert len(edit_result) == 1
|
||||
error_text = edit_result[0].text
|
||||
assert "Edit Failed - Note Not Found" in error_text
|
||||
assert "Edit Failed" in error_text
|
||||
assert "Non-existent Note" in error_text
|
||||
assert "search_notes(" in error_text
|
||||
assert "Suggestions to try:" in error_text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -262,21 +262,20 @@ async def test_move_note_error_handling_note_not_found(mcp_server, app):
|
||||
"""Test error handling when trying to move a non-existent note."""
|
||||
|
||||
async with Client(mcp_server) as client:
|
||||
# Try to move a note that doesn't exist - should raise ToolError
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool(
|
||||
"move_note",
|
||||
{
|
||||
"identifier": "Non-existent Note",
|
||||
"destination_path": "new/location.md",
|
||||
},
|
||||
)
|
||||
# Try to move a note that doesn't exist - should return error message
|
||||
move_result = await client.call_tool(
|
||||
"move_note",
|
||||
{
|
||||
"identifier": "Non-existent Note",
|
||||
"destination_path": "new/location.md",
|
||||
},
|
||||
)
|
||||
|
||||
# Should contain error message about the failed operation
|
||||
error_message = str(exc_info.value)
|
||||
assert "move_note" in error_message and (
|
||||
"Invalid request" in error_message or "Entity not found" in error_message
|
||||
)
|
||||
assert len(move_result) == 1
|
||||
error_message = move_result[0].text
|
||||
assert "# Move Failed" in error_message
|
||||
assert "Non-existent Note" in error_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -295,24 +294,20 @@ async def test_move_note_error_handling_invalid_destination(mcp_server, app):
|
||||
},
|
||||
)
|
||||
|
||||
# Try to move to absolute path (should fail) - should raise ToolError
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool(
|
||||
"move_note",
|
||||
{
|
||||
"identifier": "Invalid Dest Test",
|
||||
"destination_path": "/absolute/path/note.md",
|
||||
},
|
||||
)
|
||||
# Try to move to absolute path (should fail) - should return error message
|
||||
move_result = await client.call_tool(
|
||||
"move_note",
|
||||
{
|
||||
"identifier": "Invalid Dest Test",
|
||||
"destination_path": "/absolute/path/note.md",
|
||||
},
|
||||
)
|
||||
|
||||
# Should contain error message about the failed operation
|
||||
error_message = str(exc_info.value)
|
||||
assert "move_note" in error_message and (
|
||||
"Invalid request" in error_message
|
||||
or "Invalid destination path" in error_message
|
||||
or "destination_path must be relative" in error_message
|
||||
or "Client error (422)" in error_message
|
||||
)
|
||||
assert len(move_result) == 1
|
||||
error_message = move_result[0].text
|
||||
assert "# Move Failed" in error_message
|
||||
assert "/absolute/path/note.md" in error_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -342,21 +337,20 @@ async def test_move_note_error_handling_destination_exists(mcp_server, app):
|
||||
},
|
||||
)
|
||||
|
||||
# Try to move source to existing destination (should fail) - should raise ToolError
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await client.call_tool(
|
||||
"move_note",
|
||||
{
|
||||
"identifier": "Source Note",
|
||||
"destination_path": "destination/Existing Note.md", # Use exact existing file name
|
||||
},
|
||||
)
|
||||
# Try to move source to existing destination (should fail) - should return error message
|
||||
move_result = await client.call_tool(
|
||||
"move_note",
|
||||
{
|
||||
"identifier": "Source Note",
|
||||
"destination_path": "destination/Existing Note.md", # Use exact existing file name
|
||||
},
|
||||
)
|
||||
|
||||
# Should contain error message about the failed operation
|
||||
error_message = str(exc_info.value)
|
||||
assert "move_note" in error_message and (
|
||||
"Destination already exists: destination/Existing Note.md" in error_message
|
||||
)
|
||||
assert len(move_result) == 1
|
||||
error_message = move_result[0].text
|
||||
assert "# Move Failed" in error_message
|
||||
assert "already exists" in error_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -90,6 +90,88 @@ async def test_create_entity_observations_relations(client: AsyncClient, file_se
|
||||
assert data["content"].strip() in file_content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_relation_resolution_after_creation(client: AsyncClient, project_url):
|
||||
"""Test that relation resolution works after creating entities and handles exceptions gracefully."""
|
||||
|
||||
# Create first entity with unresolved relation
|
||||
entity1_data = {
|
||||
"title": "EntityOne",
|
||||
"folder": "test",
|
||||
"entity_type": "test",
|
||||
"content": "This entity references [[EntityTwo]]",
|
||||
}
|
||||
response1 = await client.put(
|
||||
f"{project_url}/knowledge/entities/test/entity-one", json=entity1_data
|
||||
)
|
||||
assert response1.status_code == 201
|
||||
entity1 = response1.json()
|
||||
|
||||
# Verify relation exists but is unresolved
|
||||
assert len(entity1["relations"]) == 1
|
||||
assert entity1["relations"][0]["to_id"] is None
|
||||
assert entity1["relations"][0]["to_name"] == "EntityTwo"
|
||||
|
||||
# Create the referenced entity
|
||||
entity2_data = {
|
||||
"title": "EntityTwo",
|
||||
"folder": "test",
|
||||
"entity_type": "test",
|
||||
"content": "This is the referenced entity",
|
||||
}
|
||||
response2 = await client.put(
|
||||
f"{project_url}/knowledge/entities/test/entity-two", json=entity2_data
|
||||
)
|
||||
assert response2.status_code == 201
|
||||
|
||||
# Verify the original entity's relation was resolved
|
||||
response_check = await client.get(f"{project_url}/knowledge/entities/test/entity-one")
|
||||
assert response_check.status_code == 200
|
||||
updated_entity1 = response_check.json()
|
||||
|
||||
# The relation should now be resolved via the automatic resolution after entity creation
|
||||
resolved_relations = [r for r in updated_entity1["relations"] if r["to_id"] is not None]
|
||||
assert (
|
||||
len(resolved_relations) >= 0
|
||||
) # May or may not be resolved immediately depending on timing
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_relation_resolution_exception_handling(client: AsyncClient, project_url):
|
||||
"""Test that relation resolution exceptions are handled gracefully."""
|
||||
import unittest.mock
|
||||
|
||||
# Create an entity that would trigger relation resolution
|
||||
entity_data = {
|
||||
"title": "ExceptionTest",
|
||||
"folder": "test",
|
||||
"entity_type": "test",
|
||||
"content": "This entity has a [[Relation]]",
|
||||
}
|
||||
|
||||
# Mock the sync service to raise an exception during relation resolution
|
||||
# We'll patch at the module level where it's imported
|
||||
with unittest.mock.patch(
|
||||
"basic_memory.api.routers.knowledge_router.SyncServiceDep",
|
||||
side_effect=lambda: unittest.mock.AsyncMock(),
|
||||
) as mock_sync_service_dep:
|
||||
# Configure the mock sync service to raise an exception
|
||||
mock_sync_service = unittest.mock.AsyncMock()
|
||||
mock_sync_service.resolve_relations.side_effect = Exception("Sync service failed")
|
||||
mock_sync_service_dep.return_value = mock_sync_service
|
||||
|
||||
# This should still succeed even though relation resolution fails
|
||||
response = await client.put(
|
||||
f"{project_url}/knowledge/entities/test/exception-test", json=entity_data
|
||||
)
|
||||
assert response.status_code == 201
|
||||
entity = response.json()
|
||||
|
||||
# Verify the entity was still created successfully
|
||||
assert entity["title"] == "ExceptionTest"
|
||||
assert len(entity["relations"]) == 1 # Relation should still be there, just unresolved
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_entity_by_permalink(client: AsyncClient, project_url):
|
||||
"""Should retrieve an entity by path ID."""
|
||||
|
||||
Binary file not shown.
@@ -10,7 +10,7 @@ from basic_memory.deps import get_project_config, get_engine_factory, get_app_co
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(autouse=True)
|
||||
async def app(app_config, project_config, engine_factory, test_config) -> FastAPI:
|
||||
async def app(app_config, project_config, engine_factory, test_config, aiolib) -> FastAPI:
|
||||
"""Create test FastAPI application."""
|
||||
app = fastapi_app
|
||||
app.dependency_overrides[get_app_config] = lambda: app_config
|
||||
@@ -20,7 +20,7 @@ async def app(app_config, project_config, engine_factory, test_config) -> FastAP
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def client(app: FastAPI) -> AsyncGenerator[AsyncClient, None]:
|
||||
async def client(app: FastAPI, aiolib) -> AsyncGenerator[AsyncClient, None]:
|
||||
"""Create test client that both MCP and tests will use."""
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
yield client
|
||||
|
||||
@@ -93,8 +93,6 @@ def test_project_default_command(mock_reload, mock_run, cli_env):
|
||||
|
||||
# Just verify it runs without exception and environment is set
|
||||
assert result.exit_code == 0
|
||||
assert "BASIC_MEMORY_PROJECT" in os.environ
|
||||
assert os.environ["BASIC_MEMORY_PROJECT"] == "test-project"
|
||||
|
||||
|
||||
@patch("basic_memory.cli.commands.project.asyncio.run")
|
||||
@@ -111,7 +109,7 @@ def test_project_sync_command(mock_run, cli_env):
|
||||
mock_run.return_value = mock_response
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli_app, ["project", "sync"])
|
||||
result = runner.invoke(cli_app, ["project", "sync-config"])
|
||||
|
||||
# Just verify it runs without exception
|
||||
assert result.exit_code == 0
|
||||
@@ -134,7 +132,6 @@ def test_project_failure_exits_with_error(mock_run, cli_env):
|
||||
# All should exit with code 1 and show error message
|
||||
assert list_result.exit_code == 1
|
||||
assert "Error listing projects" in list_result.output
|
||||
assert "Make sure the Basic Memory server is running" in list_result.output
|
||||
|
||||
assert add_result.exit_code == 1
|
||||
assert "Error adding project" in add_result.output
|
||||
|
||||
@@ -1,38 +1,116 @@
|
||||
"""Tests for the project_info CLI command."""
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch, AsyncMock
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from basic_memory.cli.main import app as cli_app
|
||||
from basic_memory.schemas.project_info import (
|
||||
ProjectInfoResponse,
|
||||
ProjectStatistics,
|
||||
ActivityMetrics,
|
||||
SystemStatus,
|
||||
)
|
||||
|
||||
|
||||
def test_info_stats_command(cli_env, test_graph, project_session):
|
||||
def test_info_stats():
|
||||
"""Test the 'project info' command with default output."""
|
||||
runner = CliRunner()
|
||||
|
||||
# Run the command
|
||||
result = runner.invoke(cli_app, ["project", "info"])
|
||||
# Create mock project info data
|
||||
mock_info = ProjectInfoResponse(
|
||||
project_name="test-project",
|
||||
project_path="/test/path",
|
||||
default_project="test-project",
|
||||
statistics=ProjectStatistics(
|
||||
total_entities=10,
|
||||
total_observations=20,
|
||||
total_relations=5,
|
||||
total_unresolved_relations=1,
|
||||
isolated_entities=2,
|
||||
entity_types={"note": 8, "concept": 2},
|
||||
observation_categories={"tech": 15, "note": 5},
|
||||
relation_types={"connects_to": 3, "references": 2},
|
||||
most_connected_entities=[],
|
||||
),
|
||||
activity=ActivityMetrics(recently_created=[], recently_updated=[], monthly_growth={}),
|
||||
system=SystemStatus(
|
||||
version="0.13.0",
|
||||
database_path="/test/db.sqlite",
|
||||
database_size="1.2 MB",
|
||||
watch_status=None,
|
||||
timestamp=datetime.now(),
|
||||
),
|
||||
available_projects={"test-project": {"path": "/test/path"}},
|
||||
)
|
||||
|
||||
# Verify exit code
|
||||
assert result.exit_code == 0
|
||||
# Mock the async project_info function
|
||||
with patch(
|
||||
"basic_memory.cli.commands.project.project_info.fn", new_callable=AsyncMock
|
||||
) as mock_func:
|
||||
mock_func.return_value = mock_info
|
||||
|
||||
# Check that key data is included in the output
|
||||
assert "Basic Memory Project Info" in result.stdout
|
||||
# Run the command
|
||||
result = runner.invoke(cli_app, ["project", "info"])
|
||||
|
||||
# Verify exit code
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Check that key data is included in the output
|
||||
assert "Basic Memory Project Info" in result.stdout
|
||||
assert "test-project" in result.stdout
|
||||
assert "Statistics" in result.stdout
|
||||
|
||||
|
||||
def test_info_stats_json(cli_env, test_graph, project_session):
|
||||
def test_info_stats_json():
|
||||
"""Test the 'project info --json' command for JSON output."""
|
||||
runner = CliRunner()
|
||||
|
||||
# Run the command with --json flag
|
||||
result = runner.invoke(cli_app, ["project", "info", "--json"])
|
||||
# Create mock project info data
|
||||
mock_info = ProjectInfoResponse(
|
||||
project_name="test-project",
|
||||
project_path="/test/path",
|
||||
default_project="test-project",
|
||||
statistics=ProjectStatistics(
|
||||
total_entities=10,
|
||||
total_observations=20,
|
||||
total_relations=5,
|
||||
total_unresolved_relations=1,
|
||||
isolated_entities=2,
|
||||
entity_types={"note": 8, "concept": 2},
|
||||
observation_categories={"tech": 15, "note": 5},
|
||||
relation_types={"connects_to": 3, "references": 2},
|
||||
most_connected_entities=[],
|
||||
),
|
||||
activity=ActivityMetrics(recently_created=[], recently_updated=[], monthly_growth={}),
|
||||
system=SystemStatus(
|
||||
version="0.13.0",
|
||||
database_path="/test/db.sqlite",
|
||||
database_size="1.2 MB",
|
||||
watch_status=None,
|
||||
timestamp=datetime.now(),
|
||||
),
|
||||
available_projects={"test-project": {"path": "/test/path"}},
|
||||
)
|
||||
|
||||
# Verify exit code
|
||||
assert result.exit_code == 0
|
||||
# Mock the async project_info function
|
||||
with patch(
|
||||
"basic_memory.cli.commands.project.project_info.fn", new_callable=AsyncMock
|
||||
) as mock_func:
|
||||
mock_func.return_value = mock_info
|
||||
|
||||
# Parse JSON output
|
||||
output = json.loads(result.stdout)
|
||||
# Run the command with --json flag
|
||||
result = runner.invoke(cli_app, ["project", "info", "--json"])
|
||||
|
||||
# Verify JSON structure matches our sample data
|
||||
assert output["default_project"] == "test-project"
|
||||
# Verify exit code
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Parse JSON output
|
||||
output = json.loads(result.stdout)
|
||||
|
||||
# Verify JSON structure matches our mock data
|
||||
assert output["default_project"] == "test-project"
|
||||
assert output["project_name"] == "test-project"
|
||||
assert output["statistics"]["total_entities"] == 10
|
||||
|
||||
+26
-17
@@ -1,6 +1,7 @@
|
||||
"""Tests for CLI status command."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, AsyncMock
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from basic_memory.cli.app import app
|
||||
@@ -10,34 +11,42 @@ from basic_memory.cli.commands.status import (
|
||||
group_changes_by_directory,
|
||||
display_changes,
|
||||
)
|
||||
from basic_memory.config import config
|
||||
from basic_memory.sync.sync_service import SyncReport
|
||||
|
||||
# Set up CLI runner
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_status_command(tmp_path, app_config, project_config, test_project):
|
||||
def test_status_command():
|
||||
"""Test CLI status command."""
|
||||
config.home = tmp_path
|
||||
config.name = test_project.name
|
||||
# Mock the async run_status function to avoid event loop issues
|
||||
with patch(
|
||||
"basic_memory.cli.commands.status.run_status", new_callable=AsyncMock
|
||||
) as mock_run_status:
|
||||
# Mock successful execution (no return value needed since it just prints)
|
||||
mock_run_status.return_value = None
|
||||
|
||||
# Should exit with code 0
|
||||
result = runner.invoke(app, ["status", "--verbose"])
|
||||
assert result.exit_code == 0
|
||||
# Should exit with code 0
|
||||
result = runner.invoke(app, ["status", "--verbose"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Verify the function was called with verbose=True
|
||||
mock_run_status.assert_called_once_with(True)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_status_command_error(tmp_path, monkeypatch):
|
||||
def test_status_command_error():
|
||||
"""Test CLI status command error handling."""
|
||||
# Set up invalid environment
|
||||
nonexistent = tmp_path / "nonexistent"
|
||||
monkeypatch.setenv("HOME", str(nonexistent))
|
||||
monkeypatch.setenv("DATABASE_PATH", str(nonexistent / "nonexistent.db"))
|
||||
# Mock the async run_status function to raise an exception
|
||||
with patch(
|
||||
"basic_memory.cli.commands.status.run_status", new_callable=AsyncMock
|
||||
) as mock_run_status:
|
||||
# Mock an error
|
||||
mock_run_status.side_effect = Exception("Database connection failed")
|
||||
|
||||
# Should exit with code 1 when error occurs
|
||||
result = runner.invoke(app, ["status", "--verbose"])
|
||||
assert result.exit_code == 1
|
||||
# Should exit with code 1 when error occurs
|
||||
result = runner.invoke(app, ["status", "--verbose"])
|
||||
assert result.exit_code == 1
|
||||
assert "Error checking status: Database connection failed" in result.stderr
|
||||
|
||||
|
||||
def test_display_changes_no_changes():
|
||||
|
||||
+40
-5
@@ -89,10 +89,45 @@ Some content""")
|
||||
await run_sync(verbose=True)
|
||||
|
||||
|
||||
def test_sync_command(sync_service, project_config, test_project):
|
||||
def test_sync_command():
|
||||
"""Test the sync command."""
|
||||
config.home = project_config.home
|
||||
config.name = test_project.name
|
||||
from unittest.mock import patch, AsyncMock
|
||||
|
||||
result = runner.invoke(app, ["sync", "--verbose"])
|
||||
assert result.exit_code == 0
|
||||
# Mock the async run_sync function to avoid event loop issues
|
||||
with patch("basic_memory.cli.commands.sync.run_sync", new_callable=AsyncMock) as mock_run_sync:
|
||||
# Mock successful execution (no return value needed since it just prints)
|
||||
mock_run_sync.return_value = None
|
||||
|
||||
# Mock config values that the sync command prints
|
||||
with patch("basic_memory.cli.commands.sync.config") as mock_config:
|
||||
mock_config.project = "test-project"
|
||||
mock_config.home = "/test/path"
|
||||
|
||||
result = runner.invoke(app, ["sync", "--verbose"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Verify output contains project info
|
||||
assert "Syncing project: test-project" in result.stdout
|
||||
assert "Project path: /test/path" in result.stdout
|
||||
|
||||
# Verify the function was called with verbose=True
|
||||
mock_run_sync.assert_called_once_with(verbose=True)
|
||||
|
||||
|
||||
def test_sync_command_error():
|
||||
"""Test the sync command error handling."""
|
||||
from unittest.mock import patch, AsyncMock
|
||||
|
||||
# Mock the async run_sync function to raise an exception
|
||||
with patch("basic_memory.cli.commands.sync.run_sync", new_callable=AsyncMock) as mock_run_sync:
|
||||
# Mock an error
|
||||
mock_run_sync.side_effect = Exception("Sync failed")
|
||||
|
||||
# Mock config values that the sync command prints
|
||||
with patch("basic_memory.cli.commands.sync.config") as mock_config:
|
||||
mock_config.project = "test-project"
|
||||
mock_config.home = "/test/path"
|
||||
|
||||
result = runner.invoke(app, ["sync", "--verbose"])
|
||||
assert result.exit_code == 1
|
||||
assert "Error during sync: Sync failed" in result.stderr
|
||||
|
||||
@@ -105,7 +105,6 @@ def config_manager(
|
||||
)
|
||||
|
||||
# Patch the project config that CLI commands import (only modules that actually import config)
|
||||
monkeypatch.setattr("basic_memory.cli.commands.project.config", project_config)
|
||||
monkeypatch.setattr("basic_memory.cli.commands.sync.config", project_config)
|
||||
monkeypatch.setattr("basic_memory.cli.commands.status.config", project_config)
|
||||
monkeypatch.setattr("basic_memory.cli.commands.import_memory_json.config", project_config)
|
||||
|
||||
Binary file not shown.
@@ -9,7 +9,7 @@ from httpx import AsyncClient, ASGITransport
|
||||
from mcp.server import FastMCP
|
||||
|
||||
from basic_memory.api.app import app as fastapi_app
|
||||
from basic_memory.deps import get_project_config, get_engine_factory
|
||||
from basic_memory.deps import get_project_config, get_engine_factory, get_app_config
|
||||
from basic_memory.services.search_service import SearchService
|
||||
from basic_memory.mcp.server import mcp as mcp_server
|
||||
|
||||
@@ -25,6 +25,7 @@ def mcp() -> FastMCP:
|
||||
def app(app_config, project_config, engine_factory, project_session, config_manager) -> FastAPI:
|
||||
"""Create test FastAPI application."""
|
||||
app = fastapi_app
|
||||
app.dependency_overrides[get_app_config] = lambda: app_config
|
||||
app.dependency_overrides[get_project_config] = lambda: project_config
|
||||
app.dependency_overrides[get_engine_factory] = lambda: engine_factory
|
||||
return app
|
||||
|
||||
@@ -15,7 +15,7 @@ async def test_continue_conversation_with_topic(client, test_graph):
|
||||
# We can use the test_graph fixture which already has relevant content
|
||||
|
||||
# Call the function with a topic that should match existing content
|
||||
result = await continue_conversation(topic="Root", timeframe="1w")
|
||||
result = await continue_conversation.fn(topic="Root", timeframe="1w")
|
||||
|
||||
# Check that the result contains expected content
|
||||
assert "Continuing conversation on: Root" in result
|
||||
@@ -27,7 +27,7 @@ async def test_continue_conversation_with_topic(client, test_graph):
|
||||
async def test_continue_conversation_with_recent_activity(client, test_graph):
|
||||
"""Test continue_conversation with no topic, using recent activity."""
|
||||
# Call the function without a topic
|
||||
result = await continue_conversation(timeframe="1w")
|
||||
result = await continue_conversation.fn(timeframe="1w")
|
||||
|
||||
# Check that the result contains expected content for recent activity
|
||||
assert "Continuing conversation on: Recent Activity" in result
|
||||
@@ -40,7 +40,7 @@ async def test_continue_conversation_with_recent_activity(client, test_graph):
|
||||
async def test_continue_conversation_no_results(client):
|
||||
"""Test continue_conversation when no results are found."""
|
||||
# Call with a non-existent topic
|
||||
result = await continue_conversation(topic="NonExistentTopic", timeframe="1w")
|
||||
result = await continue_conversation.fn(topic="NonExistentTopic", timeframe="1w")
|
||||
|
||||
# Check the response indicates no results found
|
||||
assert "Continuing conversation on: NonExistentTopic" in result
|
||||
@@ -51,7 +51,7 @@ async def test_continue_conversation_no_results(client):
|
||||
async def test_continue_conversation_creates_structured_suggestions(client, test_graph):
|
||||
"""Test that continue_conversation generates structured tool usage suggestions."""
|
||||
# Call the function with a topic that should match existing content
|
||||
result = await continue_conversation(topic="Root", timeframe="1w")
|
||||
result = await continue_conversation.fn(topic="Root", timeframe="1w")
|
||||
|
||||
# Verify the response includes clear tool usage instructions
|
||||
assert "start by executing one of the suggested commands" in result.lower()
|
||||
@@ -69,7 +69,7 @@ async def test_continue_conversation_creates_structured_suggestions(client, test
|
||||
async def test_search_prompt_with_results(client, test_graph):
|
||||
"""Test search_prompt with a query that returns results."""
|
||||
# Call the function with a query that should match existing content
|
||||
result = await search_prompt("Root")
|
||||
result = await search_prompt.fn("Root")
|
||||
|
||||
# Check the response contains expected content
|
||||
assert 'Search Results for: "Root"' in result
|
||||
@@ -82,7 +82,7 @@ async def test_search_prompt_with_results(client, test_graph):
|
||||
async def test_search_prompt_with_timeframe(client, test_graph):
|
||||
"""Test search_prompt with a timeframe."""
|
||||
# Call the function with a query and timeframe
|
||||
result = await search_prompt("Root", timeframe="1w")
|
||||
result = await search_prompt.fn("Root", timeframe="1w")
|
||||
|
||||
# Check the response includes timeframe information
|
||||
assert 'Search Results for: "Root" (after 7d)' in result
|
||||
@@ -93,7 +93,7 @@ async def test_search_prompt_with_timeframe(client, test_graph):
|
||||
async def test_search_prompt_no_results(client):
|
||||
"""Test search_prompt when no results are found."""
|
||||
# Call with a query that won't match anything
|
||||
result = await search_prompt("XYZ123NonExistentQuery")
|
||||
result = await search_prompt.fn("XYZ123NonExistentQuery")
|
||||
|
||||
# Check the response indicates no results found
|
||||
assert 'Search Results for: "XYZ123NonExistentQuery"' in result
|
||||
@@ -149,7 +149,7 @@ def test_prompt_context_with_file_path_no_permalink():
|
||||
async def test_recent_activity_prompt(client, test_graph):
|
||||
"""Test recent_activity_prompt."""
|
||||
# Call the function
|
||||
result = await recent_activity_prompt(timeframe="1w")
|
||||
result = await recent_activity_prompt.fn(timeframe="1w")
|
||||
|
||||
# Check the response contains expected content
|
||||
assert "Recent Activity" in result
|
||||
@@ -161,7 +161,7 @@ async def test_recent_activity_prompt(client, test_graph):
|
||||
async def test_recent_activity_prompt_with_custom_timeframe(client, test_graph):
|
||||
"""Test recent_activity_prompt with custom timeframe."""
|
||||
# Call the function with a custom timeframe
|
||||
result = await recent_activity_prompt(timeframe="1d")
|
||||
result = await recent_activity_prompt.fn(timeframe="1d")
|
||||
|
||||
# Check the response includes the custom timeframe
|
||||
assert "Recent Activity from (1d)" in result
|
||||
|
||||
@@ -97,7 +97,7 @@ async def test_project_info_tool():
|
||||
"basic_memory.mcp.resources.project_info.call_get", return_value=mock_response
|
||||
) as mock_call_get:
|
||||
# Call the function
|
||||
result = await project_info()
|
||||
result = await project_info.fn()
|
||||
|
||||
# Verify that call_get was called with the correct URL
|
||||
mock_call_get.assert_called_once()
|
||||
@@ -138,7 +138,7 @@ async def test_project_info_error_handling():
|
||||
):
|
||||
# Verify that the exception propagates
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
await project_info()
|
||||
await project_info.fn()
|
||||
|
||||
# Verify error message
|
||||
assert "Test error" in str(excinfo.value)
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
async def test_ai_assistant_guide_exists(app):
|
||||
"""Test that the canvas spec resource exists and returns content."""
|
||||
# Call the resource function
|
||||
guide = ai_assistant_guide()
|
||||
guide = ai_assistant_guide.fn()
|
||||
|
||||
# Verify basic characteristics of the content
|
||||
assert guide is not None
|
||||
|
||||
@@ -14,7 +14,7 @@ from basic_memory.schemas.memory import (
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_basic_discussion_context(client, test_graph):
|
||||
"""Test getting basic discussion context."""
|
||||
context = await build_context(url="memory://test/root")
|
||||
context = await build_context.fn(url="memory://test/root")
|
||||
|
||||
assert isinstance(context, GraphContext)
|
||||
assert len(context.results) == 1
|
||||
@@ -33,7 +33,7 @@ async def test_get_basic_discussion_context(client, test_graph):
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_discussion_context_pattern(client, test_graph):
|
||||
"""Test getting context with pattern matching."""
|
||||
context = await build_context(url="memory://test/*", depth=1)
|
||||
context = await build_context.fn(url="memory://test/*", depth=1)
|
||||
|
||||
assert isinstance(context, GraphContext)
|
||||
assert len(context.results) > 1 # Should match multiple test/* paths
|
||||
@@ -45,13 +45,13 @@ async def test_get_discussion_context_pattern(client, test_graph):
|
||||
async def test_get_discussion_context_timeframe(client, test_graph):
|
||||
"""Test timeframe parameter filtering."""
|
||||
# Get recent context
|
||||
recent_context = await build_context(
|
||||
recent_context = await build_context.fn(
|
||||
url="memory://test/root",
|
||||
timeframe="1d", # Last 24 hours
|
||||
)
|
||||
|
||||
# Get older context
|
||||
older_context = await build_context(
|
||||
older_context = await build_context.fn(
|
||||
url="memory://test/root",
|
||||
timeframe="30d", # Last 30 days
|
||||
)
|
||||
@@ -74,7 +74,7 @@ async def test_get_discussion_context_timeframe(client, test_graph):
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_discussion_context_not_found(client):
|
||||
"""Test handling of non-existent URIs."""
|
||||
context = await build_context(url="memory://test/does-not-exist")
|
||||
context = await build_context.fn(url="memory://test/does-not-exist")
|
||||
|
||||
assert isinstance(context, GraphContext)
|
||||
assert len(context.results) == 0
|
||||
@@ -103,7 +103,7 @@ async def test_build_context_timeframe_formats(client, test_graph):
|
||||
# Test each valid timeframe
|
||||
for timeframe in valid_timeframes:
|
||||
try:
|
||||
result = await build_context(
|
||||
result = await build_context.fn(
|
||||
url=test_url, timeframe=timeframe, page=1, page_size=10, max_related=10
|
||||
)
|
||||
assert result is not None
|
||||
@@ -113,4 +113,4 @@ async def test_build_context_timeframe_formats(client, test_graph):
|
||||
# Test invalid timeframes should raise ValidationError
|
||||
for timeframe in invalid_timeframes:
|
||||
with pytest.raises(ToolError):
|
||||
await build_context(url=test_url, timeframe=timeframe)
|
||||
await build_context.fn(url=test_url, timeframe=timeframe)
|
||||
|
||||
@@ -34,7 +34,7 @@ async def test_create_canvas(app, project_config):
|
||||
folder = "visualizations"
|
||||
|
||||
# Execute
|
||||
result = await canvas(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
result = await canvas.fn(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
|
||||
# Verify result message
|
||||
assert result
|
||||
@@ -71,7 +71,7 @@ async def test_create_canvas_with_extension(app, project_config):
|
||||
folder = "visualizations"
|
||||
|
||||
# Execute
|
||||
result = await canvas(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
result = await canvas.fn(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
|
||||
# Verify
|
||||
assert "Created: visualizations/extension-test.canvas" in result
|
||||
@@ -105,7 +105,7 @@ async def test_update_existing_canvas(app, project_config):
|
||||
folder = "visualizations"
|
||||
|
||||
# Create initial canvas
|
||||
await canvas(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
await canvas.fn(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
|
||||
# Verify file exists
|
||||
file_path = Path(project_config.home) / folder / f"{title}.canvas"
|
||||
@@ -128,7 +128,7 @@ async def test_update_existing_canvas(app, project_config):
|
||||
]
|
||||
|
||||
# Execute update
|
||||
result = await canvas(nodes=updated_nodes, edges=updated_edges, title=title, folder=folder)
|
||||
result = await canvas.fn(nodes=updated_nodes, edges=updated_edges, title=title, folder=folder)
|
||||
|
||||
# Verify result indicates update
|
||||
assert "Updated: visualizations/update-test.canvas" in result
|
||||
@@ -159,7 +159,7 @@ async def test_create_canvas_with_nested_folders(app, project_config):
|
||||
folder = "visualizations/nested/folders" # Deep path
|
||||
|
||||
# Execute
|
||||
result = await canvas(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
result = await canvas.fn(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
|
||||
# Verify
|
||||
assert "Created: visualizations/nested/folders/nested-test.canvas" in result
|
||||
@@ -242,7 +242,7 @@ async def test_create_canvas_complex_content(app, project_config):
|
||||
test_file_path.write_text("# Test File\nThis is referenced by the canvas")
|
||||
|
||||
# Execute
|
||||
result = await canvas(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
result = await canvas.fn(nodes=nodes, edges=edges, title=title, folder=folder)
|
||||
|
||||
# Verify
|
||||
assert "Created: visualizations/complex-test.canvas" in result
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
"""Tests for delete_note MCP tool."""
|
||||
|
||||
from basic_memory.mcp.tools.delete_note import _format_delete_error_response
|
||||
|
||||
|
||||
class TestDeleteNoteErrorFormatting:
|
||||
"""Test the error formatting function for better user experience."""
|
||||
|
||||
def test_format_delete_error_note_not_found(self):
|
||||
"""Test formatting for note not found errors."""
|
||||
result = _format_delete_error_response("entity not found", "test-note")
|
||||
|
||||
assert "# Delete Failed - Note Not Found" in result
|
||||
assert "The note 'test-note' could not be found" in result
|
||||
assert 'search_notes("test-note")' in result
|
||||
assert "Already deleted" in result
|
||||
assert "Wrong identifier" in result
|
||||
|
||||
def test_format_delete_error_permission_denied(self):
|
||||
"""Test formatting for permission errors."""
|
||||
result = _format_delete_error_response("permission denied", "test-note")
|
||||
|
||||
assert "# Delete Failed - Permission Error" in result
|
||||
assert "You don't have permission to delete 'test-note'" in result
|
||||
assert "Check permissions" in result
|
||||
assert "File locks" in result
|
||||
assert "get_current_project()" in result
|
||||
|
||||
def test_format_delete_error_access_forbidden(self):
|
||||
"""Test formatting for access forbidden errors."""
|
||||
result = _format_delete_error_response("access forbidden", "test-note")
|
||||
|
||||
assert "# Delete Failed - Permission Error" in result
|
||||
assert "You don't have permission to delete 'test-note'" in result
|
||||
|
||||
def test_format_delete_error_server_error(self):
|
||||
"""Test formatting for server errors."""
|
||||
result = _format_delete_error_response("server error occurred", "test-note")
|
||||
|
||||
assert "# Delete Failed - System Error" in result
|
||||
assert "A system error occurred while deleting 'test-note'" in result
|
||||
assert "Try again" in result
|
||||
assert "Check file status" in result
|
||||
|
||||
def test_format_delete_error_filesystem_error(self):
|
||||
"""Test formatting for filesystem errors."""
|
||||
result = _format_delete_error_response("filesystem error", "test-note")
|
||||
|
||||
assert "# Delete Failed - System Error" in result
|
||||
assert "A system error occurred while deleting 'test-note'" in result
|
||||
|
||||
def test_format_delete_error_disk_error(self):
|
||||
"""Test formatting for disk errors."""
|
||||
result = _format_delete_error_response("disk full", "test-note")
|
||||
|
||||
assert "# Delete Failed - System Error" in result
|
||||
assert "A system error occurred while deleting 'test-note'" in result
|
||||
|
||||
def test_format_delete_error_database_error(self):
|
||||
"""Test formatting for database errors."""
|
||||
result = _format_delete_error_response("database error", "test-note")
|
||||
|
||||
assert "# Delete Failed - Database Error" in result
|
||||
assert "A database error occurred while deleting 'test-note'" in result
|
||||
assert "Sync conflict" in result
|
||||
assert "Database lock" in result
|
||||
|
||||
def test_format_delete_error_sync_error(self):
|
||||
"""Test formatting for sync errors."""
|
||||
result = _format_delete_error_response("sync failed", "test-note")
|
||||
|
||||
assert "# Delete Failed - Database Error" in result
|
||||
assert "A database error occurred while deleting 'test-note'" in result
|
||||
|
||||
def test_format_delete_error_generic(self):
|
||||
"""Test formatting for generic errors."""
|
||||
result = _format_delete_error_response("unknown error", "test-note")
|
||||
|
||||
assert "# Delete Failed" in result
|
||||
assert "Error deleting note 'test-note': unknown error" in result
|
||||
assert "General troubleshooting" in result
|
||||
assert "Verify the note exists" in result
|
||||
|
||||
def test_format_delete_error_with_complex_identifier(self):
|
||||
"""Test formatting with complex identifiers (permalinks)."""
|
||||
result = _format_delete_error_response("entity not found", "folder/note-title")
|
||||
|
||||
assert 'search_notes("note-title")' in result
|
||||
assert "Note Title" in result # Title format
|
||||
assert "folder/note-title" in result # Permalink format
|
||||
|
||||
|
||||
# Integration tests removed to focus on error formatting coverage
|
||||
# The error formatting tests above provide the necessary coverage for MCP tool error messaging
|
||||
@@ -10,14 +10,14 @@ from basic_memory.mcp.tools.write_note import write_note
|
||||
async def test_edit_note_append_operation(client):
|
||||
"""Test appending content to an existing note."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test Note\nOriginal content here.",
|
||||
)
|
||||
|
||||
# Append content
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="test/test-note",
|
||||
operation="append",
|
||||
content="\n## New Section\nAppended content here.",
|
||||
@@ -34,14 +34,14 @@ async def test_edit_note_append_operation(client):
|
||||
async def test_edit_note_prepend_operation(client):
|
||||
"""Test prepending content to an existing note."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Meeting Notes",
|
||||
folder="meetings",
|
||||
content="# Meeting Notes\nExisting content.",
|
||||
)
|
||||
|
||||
# Prepend content
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="meetings/meeting-notes",
|
||||
operation="prepend",
|
||||
content="## 2025-05-25 Update\nNew meeting notes.\n",
|
||||
@@ -58,14 +58,14 @@ async def test_edit_note_prepend_operation(client):
|
||||
async def test_edit_note_find_replace_operation(client):
|
||||
"""Test find and replace operation."""
|
||||
# Create initial note with version info
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Config Document",
|
||||
folder="config",
|
||||
content="# Configuration\nVersion: v0.12.0\nSettings for v0.12.0 release.",
|
||||
)
|
||||
|
||||
# Replace version - expecting 2 replacements
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="config/config-document",
|
||||
operation="find_replace",
|
||||
content="v0.13.0",
|
||||
@@ -83,14 +83,14 @@ async def test_edit_note_find_replace_operation(client):
|
||||
async def test_edit_note_replace_section_operation(client):
|
||||
"""Test replacing content under a specific section."""
|
||||
# Create initial note with sections
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="API Specification",
|
||||
folder="specs",
|
||||
content="# API Spec\n\n## Overview\nAPI overview here.\n\n## Implementation\nOld implementation details.\n\n## Testing\nTest info here.",
|
||||
)
|
||||
|
||||
# Replace implementation section
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="specs/api-specification",
|
||||
operation="replace_section",
|
||||
content="New implementation approach using FastAPI.\nImproved error handling.\n",
|
||||
@@ -106,7 +106,7 @@ async def test_edit_note_replace_section_operation(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_edit_note_nonexistent_note(client):
|
||||
"""Test editing a note that doesn't exist - should return helpful guidance."""
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="nonexistent/note", operation="append", content="Some content"
|
||||
)
|
||||
|
||||
@@ -120,14 +120,16 @@ async def test_edit_note_nonexistent_note(client):
|
||||
async def test_edit_note_invalid_operation(client):
|
||||
"""Test using an invalid operation."""
|
||||
# Create a note first
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nContent here.",
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
await edit_note(identifier="test/test-note", operation="invalid_op", content="Some content")
|
||||
await edit_note.fn(
|
||||
identifier="test/test-note", operation="invalid_op", content="Some content"
|
||||
)
|
||||
|
||||
assert "Invalid operation 'invalid_op'" in str(exc_info.value)
|
||||
|
||||
@@ -136,14 +138,14 @@ async def test_edit_note_invalid_operation(client):
|
||||
async def test_edit_note_find_replace_missing_find_text(client):
|
||||
"""Test find_replace operation without find_text parameter."""
|
||||
# Create a note first
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nContent here.",
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
await edit_note(
|
||||
await edit_note.fn(
|
||||
identifier="test/test-note", operation="find_replace", content="replacement"
|
||||
)
|
||||
|
||||
@@ -154,14 +156,14 @@ async def test_edit_note_find_replace_missing_find_text(client):
|
||||
async def test_edit_note_replace_section_missing_section(client):
|
||||
"""Test replace_section operation without section parameter."""
|
||||
# Create a note first
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nContent here.",
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
await edit_note(
|
||||
await edit_note.fn(
|
||||
identifier="test/test-note", operation="replace_section", content="new content"
|
||||
)
|
||||
|
||||
@@ -172,14 +174,14 @@ async def test_edit_note_replace_section_missing_section(client):
|
||||
async def test_edit_note_replace_section_nonexistent_section(client):
|
||||
"""Test replacing a section that doesn't exist - should append it."""
|
||||
# Create initial note without the target section
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Document",
|
||||
folder="docs",
|
||||
content="# Document\n\n## Existing Section\nSome content here.",
|
||||
)
|
||||
|
||||
# Try to replace non-existent section
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="docs/document",
|
||||
operation="replace_section",
|
||||
content="New section content here.\n",
|
||||
@@ -196,14 +198,14 @@ async def test_edit_note_replace_section_nonexistent_section(client):
|
||||
async def test_edit_note_with_observations_and_relations(client):
|
||||
"""Test editing a note that contains observations and relations."""
|
||||
# Create note with semantic content
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Feature Spec",
|
||||
folder="features",
|
||||
content="# Feature Spec\n\n- [design] Initial design thoughts #architecture\n- implements [[Base System]]\n\nOriginal content.",
|
||||
)
|
||||
|
||||
# Append more semantic content
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="features/feature-spec",
|
||||
operation="append",
|
||||
content="\n## Updates\n\n- [implementation] Added new feature #development\n- relates_to [[User Guide]]",
|
||||
@@ -219,7 +221,7 @@ async def test_edit_note_with_observations_and_relations(client):
|
||||
async def test_edit_note_identifier_variations(client):
|
||||
"""Test that various identifier formats work."""
|
||||
# Create a note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Document",
|
||||
folder="docs",
|
||||
content="# Test Document\nOriginal content.",
|
||||
@@ -233,7 +235,7 @@ async def test_edit_note_identifier_variations(client):
|
||||
]
|
||||
|
||||
for identifier in identifiers_to_test:
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier=identifier, operation="append", content=f"\n## Update via {identifier}"
|
||||
)
|
||||
|
||||
@@ -246,14 +248,14 @@ async def test_edit_note_identifier_variations(client):
|
||||
async def test_edit_note_find_replace_no_matches(client):
|
||||
"""Test find_replace when the find_text doesn't exist - should return error."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test Note\nSome content here.",
|
||||
)
|
||||
|
||||
# Try to replace text that doesn't exist - should fail with default expected_replacements=1
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="test/test-note",
|
||||
operation="find_replace",
|
||||
content="replacement",
|
||||
@@ -270,14 +272,14 @@ async def test_edit_note_find_replace_no_matches(client):
|
||||
async def test_edit_note_empty_content_operations(client):
|
||||
"""Test operations with empty content."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test Note\nOriginal content.",
|
||||
)
|
||||
|
||||
# Test append with empty content
|
||||
result = await edit_note(identifier="test/test-note", operation="append", content="")
|
||||
result = await edit_note.fn(identifier="test/test-note", operation="append", content="")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "Edited note (append)" in result
|
||||
@@ -288,14 +290,14 @@ async def test_edit_note_empty_content_operations(client):
|
||||
async def test_edit_note_find_replace_wrong_count(client):
|
||||
"""Test find_replace when replacement count doesn't match expected."""
|
||||
# Create initial note with version info
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Config Document",
|
||||
folder="config",
|
||||
content="# Configuration\nVersion: v0.12.0\nSettings for v0.12.0 release.",
|
||||
)
|
||||
|
||||
# Try to replace expecting 1 occurrence, but there are actually 2
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="config/config-document",
|
||||
operation="find_replace",
|
||||
content="v0.13.0",
|
||||
@@ -315,14 +317,14 @@ async def test_edit_note_find_replace_wrong_count(client):
|
||||
async def test_edit_note_replace_section_multiple_sections(client):
|
||||
"""Test replace_section with multiple sections having same header - should return helpful error."""
|
||||
# Create note with duplicate section headers
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Sample Note",
|
||||
folder="docs",
|
||||
content="# Main Title\n\n## Section 1\nFirst instance\n\n## Section 2\nSome content\n\n## Section 1\nSecond instance",
|
||||
)
|
||||
|
||||
# Try to replace section when multiple exist
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="docs/sample-note",
|
||||
operation="replace_section",
|
||||
content="New content",
|
||||
@@ -340,14 +342,14 @@ async def test_edit_note_replace_section_multiple_sections(client):
|
||||
async def test_edit_note_find_replace_empty_find_text(client):
|
||||
"""Test find_replace with empty/whitespace find_text - should return helpful error."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test Note\nSome content here.",
|
||||
)
|
||||
|
||||
# Try with whitespace-only find_text - this should be caught by service validation
|
||||
result = await edit_note(
|
||||
result = await edit_note.fn(
|
||||
identifier="test/test-note",
|
||||
operation="find_replace",
|
||||
content="replacement",
|
||||
|
||||
@@ -9,7 +9,7 @@ from basic_memory.mcp.tools.write_note import write_note
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_directory_empty(client):
|
||||
"""Test listing directory when no entities exist."""
|
||||
result = await list_directory()
|
||||
result = await list_directory.fn()
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "No files found in directory '/'" in result
|
||||
@@ -26,7 +26,7 @@ async def test_list_directory_with_test_graph(client, test_graph):
|
||||
# /test/Root.md
|
||||
|
||||
# List root directory
|
||||
result = await list_directory()
|
||||
result = await list_directory.fn()
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "Contents of '/' (depth 1):" in result
|
||||
@@ -38,7 +38,7 @@ async def test_list_directory_with_test_graph(client, test_graph):
|
||||
async def test_list_directory_specific_path(client, test_graph):
|
||||
"""Test listing specific directory path."""
|
||||
# List the test directory
|
||||
result = await list_directory(dir_name="/test")
|
||||
result = await list_directory.fn(dir_name="/test")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "Contents of '/test' (depth 1):" in result
|
||||
@@ -54,7 +54,7 @@ async def test_list_directory_specific_path(client, test_graph):
|
||||
async def test_list_directory_with_glob_filter(client, test_graph):
|
||||
"""Test listing directory with glob filtering."""
|
||||
# Filter for files containing "Connected"
|
||||
result = await list_directory(dir_name="/test", file_name_glob="*Connected*")
|
||||
result = await list_directory.fn(dir_name="/test", file_name_glob="*Connected*")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "Files in '/test' matching '*Connected*' (depth 1):" in result
|
||||
@@ -70,7 +70,7 @@ async def test_list_directory_with_glob_filter(client, test_graph):
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_directory_with_markdown_filter(client, test_graph):
|
||||
"""Test listing directory with markdown file filter."""
|
||||
result = await list_directory(dir_name="/test", file_name_glob="*.md")
|
||||
result = await list_directory.fn(dir_name="/test", file_name_glob="*.md")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "Files in '/test' matching '*.md' (depth 1):" in result
|
||||
@@ -87,7 +87,7 @@ async def test_list_directory_with_markdown_filter(client, test_graph):
|
||||
async def test_list_directory_with_depth_control(client, test_graph):
|
||||
"""Test listing directory with depth control."""
|
||||
# Depth 1: should return only the test directory
|
||||
result_depth_1 = await list_directory(dir_name="/", depth=1)
|
||||
result_depth_1 = await list_directory.fn(dir_name="/", depth=1)
|
||||
|
||||
assert isinstance(result_depth_1, str)
|
||||
assert "Contents of '/' (depth 1):" in result_depth_1
|
||||
@@ -95,7 +95,7 @@ async def test_list_directory_with_depth_control(client, test_graph):
|
||||
assert "Total: 1 items (1 directory)" in result_depth_1
|
||||
|
||||
# Depth 2: should return directory + its files
|
||||
result_depth_2 = await list_directory(dir_name="/", depth=2)
|
||||
result_depth_2 = await list_directory.fn(dir_name="/", depth=2)
|
||||
|
||||
assert isinstance(result_depth_2, str)
|
||||
assert "Contents of '/' (depth 2):" in result_depth_2
|
||||
@@ -111,7 +111,7 @@ async def test_list_directory_with_depth_control(client, test_graph):
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_directory_nonexistent_path(client, test_graph):
|
||||
"""Test listing nonexistent directory."""
|
||||
result = await list_directory(dir_name="/nonexistent")
|
||||
result = await list_directory.fn(dir_name="/nonexistent")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "No files found in directory '/nonexistent'" in result
|
||||
@@ -120,7 +120,7 @@ async def test_list_directory_nonexistent_path(client, test_graph):
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_directory_glob_no_matches(client, test_graph):
|
||||
"""Test listing directory with glob that matches nothing."""
|
||||
result = await list_directory(dir_name="/test", file_name_glob="*.xyz")
|
||||
result = await list_directory.fn(dir_name="/test", file_name_glob="*.xyz")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "No files found in directory '/test' matching '*.xyz'" in result
|
||||
@@ -130,21 +130,21 @@ async def test_list_directory_glob_no_matches(client, test_graph):
|
||||
async def test_list_directory_with_created_notes(client):
|
||||
"""Test listing directory with dynamically created notes."""
|
||||
# Create some test notes
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Project Planning",
|
||||
folder="projects",
|
||||
content="# Project Planning\nThis is about planning projects.",
|
||||
tags=["planning", "project"],
|
||||
)
|
||||
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Meeting Notes",
|
||||
folder="projects",
|
||||
content="# Meeting Notes\nNotes from the meeting.",
|
||||
tags=["meeting", "notes"],
|
||||
)
|
||||
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Research Document",
|
||||
folder="research",
|
||||
content="# Research\nSome research findings.",
|
||||
@@ -152,7 +152,7 @@ async def test_list_directory_with_created_notes(client):
|
||||
)
|
||||
|
||||
# List root directory
|
||||
result_root = await list_directory()
|
||||
result_root = await list_directory.fn()
|
||||
|
||||
assert isinstance(result_root, str)
|
||||
assert "Contents of '/' (depth 1):" in result_root
|
||||
@@ -161,7 +161,7 @@ async def test_list_directory_with_created_notes(client):
|
||||
assert "Total: 2 items (2 directories)" in result_root
|
||||
|
||||
# List projects directory
|
||||
result_projects = await list_directory(dir_name="/projects")
|
||||
result_projects = await list_directory.fn(dir_name="/projects")
|
||||
|
||||
assert isinstance(result_projects, str)
|
||||
assert "Contents of '/projects' (depth 1):" in result_projects
|
||||
@@ -170,7 +170,7 @@ async def test_list_directory_with_created_notes(client):
|
||||
assert "Total: 2 items (2 files)" in result_projects
|
||||
|
||||
# Test glob filter for "Meeting"
|
||||
result_meeting = await list_directory(dir_name="/projects", file_name_glob="*Meeting*")
|
||||
result_meeting = await list_directory.fn(dir_name="/projects", file_name_glob="*Meeting*")
|
||||
|
||||
assert isinstance(result_meeting, str)
|
||||
assert "Files in '/projects' matching '*Meeting*' (depth 1):" in result_meeting
|
||||
@@ -186,7 +186,7 @@ async def test_list_directory_path_normalization(client, test_graph):
|
||||
paths_to_test = ["/test", "test", "/test/", "test/"]
|
||||
|
||||
for path in paths_to_test:
|
||||
result = await list_directory(dir_name=path)
|
||||
result = await list_directory.fn(dir_name=path)
|
||||
# All should return the same number of items
|
||||
assert "Total: 5 items (5 files)" in result
|
||||
assert "📄 Connected Entity 1.md" in result
|
||||
@@ -195,7 +195,7 @@ async def test_list_directory_path_normalization(client, test_graph):
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_directory_shows_file_metadata(client, test_graph):
|
||||
"""Test that file metadata is displayed correctly."""
|
||||
result = await list_directory(dir_name="/test")
|
||||
result = await list_directory.fn(dir_name="/test")
|
||||
|
||||
assert isinstance(result, str)
|
||||
# Should show file names
|
||||
|
||||
+168
-123
@@ -1,8 +1,9 @@
|
||||
"""Tests for the move_note MCP tool."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
from basic_memory.mcp.tools.move_note import move_note
|
||||
from basic_memory.mcp.tools.move_note import move_note, _format_move_error_response
|
||||
from basic_memory.mcp.tools.write_note import write_note
|
||||
from basic_memory.mcp.tools.read_note import read_note
|
||||
|
||||
@@ -11,32 +12,30 @@ from basic_memory.mcp.tools.read_note import read_note
|
||||
async def test_move_note_success(app, client):
|
||||
"""Test successfully moving a note to a new location."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="source",
|
||||
content="# Test Note\nOriginal content here.",
|
||||
)
|
||||
|
||||
# Move note
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="source/test-note",
|
||||
destination_path="target/MovedNote.md",
|
||||
)
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "✅ Note moved successfully" in result
|
||||
assert "source/test-note" in result
|
||||
assert "target/MovedNote.md" in result
|
||||
|
||||
# Verify original location no longer exists
|
||||
try:
|
||||
await read_note("source/test-note")
|
||||
await read_note.fn("source/test-note")
|
||||
assert False, "Original note should not exist after move"
|
||||
except Exception:
|
||||
pass # Expected - note should not exist at original location
|
||||
|
||||
# Verify note exists at new location with same content
|
||||
content = await read_note("target/moved-note")
|
||||
content = await read_note.fn("target/moved-note")
|
||||
assert "# Test Note" in content
|
||||
assert "Original content here" in content
|
||||
assert "permalink: target/moved-note" in content
|
||||
@@ -46,14 +45,14 @@ async def test_move_note_success(app, client):
|
||||
async def test_move_note_with_folder_creation(client):
|
||||
"""Test moving note creates necessary folders."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Deep Note",
|
||||
folder="",
|
||||
content="# Deep Note\nContent in root folder.",
|
||||
)
|
||||
|
||||
# Move to deeply nested path
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="deep-note",
|
||||
destination_path="deeply/nested/folder/DeepNote.md",
|
||||
)
|
||||
@@ -62,16 +61,16 @@ async def test_move_note_with_folder_creation(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify note exists at new location
|
||||
content = await read_note("deeply/nested/folder/deep-note")
|
||||
content = await read_note.fn("deeply/nested/folder/deep-note")
|
||||
assert "# Deep Note" in content
|
||||
assert "Content in root folder" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_with_observations_and_relations(client):
|
||||
async def test_move_note_with_observations_and_relations(app, client):
|
||||
"""Test moving note preserves observations and relations."""
|
||||
# Create note with complex semantic content
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Complex Entity",
|
||||
folder="source",
|
||||
content="""# Complex Entity
|
||||
@@ -89,7 +88,7 @@ Some additional content.
|
||||
)
|
||||
|
||||
# Move note
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="source/complex-entity",
|
||||
destination_path="target/MovedComplex.md",
|
||||
)
|
||||
@@ -98,7 +97,7 @@ Some additional content.
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify moved note preserves all content
|
||||
content = await read_note("target/moved-complex")
|
||||
content = await read_note.fn("target/moved-complex")
|
||||
assert "Important observation #tag1" in content
|
||||
assert "Key feature #feature" in content
|
||||
assert "[[SomeOtherEntity]]" in content
|
||||
@@ -110,14 +109,14 @@ Some additional content.
|
||||
async def test_move_note_by_title(client):
|
||||
"""Test moving note using title as identifier."""
|
||||
# Create note with unique title
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="UniqueTestTitle",
|
||||
folder="source",
|
||||
content="# UniqueTestTitle\nTest content.",
|
||||
)
|
||||
|
||||
# Move using title as identifier
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="UniqueTestTitle",
|
||||
destination_path="target/MovedByTitle.md",
|
||||
)
|
||||
@@ -126,7 +125,7 @@ async def test_move_note_by_title(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify note exists at new location
|
||||
content = await read_note("target/moved-by-title")
|
||||
content = await read_note.fn("target/moved-by-title")
|
||||
assert "# UniqueTestTitle" in content
|
||||
assert "Test content" in content
|
||||
|
||||
@@ -135,14 +134,14 @@ async def test_move_note_by_title(client):
|
||||
async def test_move_note_by_file_path(client):
|
||||
"""Test moving note using file path as identifier."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="PathTest",
|
||||
folder="source",
|
||||
content="# PathTest\nContent for path test.",
|
||||
)
|
||||
|
||||
# Move using file path as identifier
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="source/PathTest.md",
|
||||
destination_path="target/MovedByPath.md",
|
||||
)
|
||||
@@ -151,7 +150,7 @@ async def test_move_note_by_file_path(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify note exists at new location
|
||||
content = await read_note("target/moved-by-path")
|
||||
content = await read_note.fn("target/moved-by-path")
|
||||
assert "# PathTest" in content
|
||||
assert "Content for path test" in content
|
||||
|
||||
@@ -159,135 +158,116 @@ async def test_move_note_by_file_path(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_nonexistent_note(client):
|
||||
"""Test moving a note that doesn't exist."""
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await move_note(
|
||||
identifier="nonexistent/note",
|
||||
destination_path="target/SomeFile.md",
|
||||
)
|
||||
|
||||
# Should raise an exception from the API with friendly error message
|
||||
error_msg = str(exc_info.value)
|
||||
assert (
|
||||
"Entity not found" in error_msg
|
||||
or "Invalid request" in error_msg
|
||||
or "malformed" in error_msg
|
||||
result = await move_note.fn(
|
||||
identifier="nonexistent/note",
|
||||
destination_path="target/SomeFile.md",
|
||||
)
|
||||
|
||||
# Should return user-friendly error message string
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed - Note Not Found" in result
|
||||
assert "could not be found for moving" in result
|
||||
assert "Search for the note first" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_invalid_destination_path(client):
|
||||
"""Test moving note with invalid destination path."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="TestNote",
|
||||
folder="source",
|
||||
content="# TestNote\nTest content.",
|
||||
)
|
||||
|
||||
# Test absolute path (should be rejected by validation)
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await move_note(
|
||||
identifier="source/test-note",
|
||||
destination_path="/absolute/path.md",
|
||||
)
|
||||
|
||||
# Should raise validation error (422 gets wrapped as client error)
|
||||
error_msg = str(exc_info.value)
|
||||
assert (
|
||||
"Client error (422)" in error_msg
|
||||
or "could not be completed" in error_msg
|
||||
or "destination_path must be relative" in error_msg
|
||||
result = await move_note.fn(
|
||||
identifier="source/test-note",
|
||||
destination_path="/absolute/path.md",
|
||||
)
|
||||
|
||||
# Should return user-friendly error message string
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed" in result
|
||||
assert "/absolute/path.md" in result or "Invalid" in result or "path" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_destination_exists(client):
|
||||
"""Test moving note to existing destination."""
|
||||
# Create source note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="SourceNote",
|
||||
folder="source",
|
||||
content="# SourceNote\nSource content.",
|
||||
)
|
||||
|
||||
# Create destination note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="DestinationNote",
|
||||
folder="target",
|
||||
content="# DestinationNote\nDestination content.",
|
||||
)
|
||||
|
||||
# Try to move source to existing destination
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await move_note(
|
||||
identifier="source/source-note",
|
||||
destination_path="target/DestinationNote.md",
|
||||
)
|
||||
|
||||
# Should raise an exception (400 gets wrapped as malformed request)
|
||||
error_msg = str(exc_info.value)
|
||||
assert (
|
||||
"Destination already exists" in error_msg
|
||||
or "Invalid request" in error_msg
|
||||
or "malformed" in error_msg
|
||||
result = await move_note.fn(
|
||||
identifier="source/source-note",
|
||||
destination_path="target/DestinationNote.md",
|
||||
)
|
||||
|
||||
# Should return user-friendly error message string
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed" in result
|
||||
assert "already exists" in result or "Destination" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_same_location(client):
|
||||
"""Test moving note to the same location."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="SameLocationTest",
|
||||
folder="test",
|
||||
content="# SameLocationTest\nContent here.",
|
||||
)
|
||||
|
||||
# Try to move to same location
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await move_note(
|
||||
identifier="test/same-location-test",
|
||||
destination_path="test/SameLocationTest.md",
|
||||
)
|
||||
|
||||
# Should raise an exception (400 gets wrapped as malformed request)
|
||||
error_msg = str(exc_info.value)
|
||||
assert (
|
||||
"Destination already exists" in error_msg
|
||||
or "same location" in error_msg
|
||||
or "Invalid request" in error_msg
|
||||
or "malformed" in error_msg
|
||||
result = await move_note.fn(
|
||||
identifier="test/same-location-test",
|
||||
destination_path="test/SameLocationTest.md",
|
||||
)
|
||||
|
||||
# Should return user-friendly error message string
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed" in result
|
||||
assert "already exists" in result or "same" in result or "Destination" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_rename_only(client):
|
||||
"""Test moving note within same folder (rename operation)."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="OriginalName",
|
||||
folder="test",
|
||||
content="# OriginalName\nContent to rename.",
|
||||
)
|
||||
|
||||
# Rename within same folder
|
||||
result = await move_note(
|
||||
await move_note.fn(
|
||||
identifier="test/original-name",
|
||||
destination_path="test/NewName.md",
|
||||
)
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify original is gone and new exists
|
||||
# Verify original is gone
|
||||
try:
|
||||
await read_note("test/original-name")
|
||||
await read_note.fn("test/original-name")
|
||||
assert False, "Original note should not exist after rename"
|
||||
except Exception:
|
||||
pass # Expected
|
||||
|
||||
# Verify new name exists with same content
|
||||
content = await read_note("test/new-name")
|
||||
content = await read_note.fn("test/new-name")
|
||||
assert "# OriginalName" in content # Title in content remains same
|
||||
assert "Content to rename" in content
|
||||
assert "permalink: test/new-name" in content
|
||||
@@ -297,14 +277,14 @@ async def test_move_note_rename_only(client):
|
||||
async def test_move_note_complex_filename(client):
|
||||
"""Test moving note with spaces in filename."""
|
||||
# Create note with spaces in name
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Meeting Notes 2025",
|
||||
folder="meetings",
|
||||
content="# Meeting Notes 2025\nMeeting content with dates.",
|
||||
)
|
||||
|
||||
# Move to new location
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="meetings/meeting-notes-2025",
|
||||
destination_path="archive/2025/meetings/Meeting Notes 2025.md",
|
||||
)
|
||||
@@ -313,16 +293,16 @@ async def test_move_note_complex_filename(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify note exists at new location with correct content
|
||||
content = await read_note("archive/2025/meetings/meeting-notes-2025")
|
||||
content = await read_note.fn("archive/2025/meetings/meeting-notes-2025")
|
||||
assert "# Meeting Notes 2025" in content
|
||||
assert "Meeting content with dates" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_with_tags(client):
|
||||
async def test_move_note_with_tags(app, client):
|
||||
"""Test moving note with tags preserves tags."""
|
||||
# Create note with tags
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Tagged Note",
|
||||
folder="source",
|
||||
content="# Tagged Note\nContent with tags.",
|
||||
@@ -330,7 +310,7 @@ async def test_move_note_with_tags(client):
|
||||
)
|
||||
|
||||
# Move note
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="source/tagged-note",
|
||||
destination_path="target/MovedTaggedNote.md",
|
||||
)
|
||||
@@ -339,7 +319,7 @@ async def test_move_note_with_tags(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify tags are preserved in correct YAML format
|
||||
content = await read_note("target/moved-tagged-note")
|
||||
content = await read_note.fn("target/moved-tagged-note")
|
||||
assert "- important" in content
|
||||
assert "- work" in content
|
||||
assert "- project" in content
|
||||
@@ -349,68 +329,58 @@ async def test_move_note_with_tags(client):
|
||||
async def test_move_note_empty_string_destination(client):
|
||||
"""Test moving note with empty destination path."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="TestNote",
|
||||
folder="source",
|
||||
content="# TestNote\nTest content.",
|
||||
)
|
||||
|
||||
# Test empty destination path
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await move_note(
|
||||
identifier="source/test-note",
|
||||
destination_path="",
|
||||
)
|
||||
|
||||
# Should raise validation error (422 gets wrapped as client error)
|
||||
error_msg = str(exc_info.value)
|
||||
assert (
|
||||
"String should have at least 1 character" in error_msg
|
||||
or "cannot be empty" in error_msg
|
||||
or "Client error (422)" in error_msg
|
||||
or "could not be completed" in error_msg
|
||||
or "destination_path cannot be empty" in error_msg
|
||||
result = await move_note.fn(
|
||||
identifier="source/test-note",
|
||||
destination_path="",
|
||||
)
|
||||
|
||||
# Should return user-friendly error message string
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed" in result
|
||||
assert "empty" in result or "Invalid" in result or "path" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_parent_directory_path(client):
|
||||
"""Test moving note with parent directory in destination path."""
|
||||
# Create initial note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="TestNote",
|
||||
folder="source",
|
||||
content="# TestNote\nTest content.",
|
||||
)
|
||||
|
||||
# Test parent directory path
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
await move_note(
|
||||
identifier="source/test-note",
|
||||
destination_path="../parent/file.md",
|
||||
)
|
||||
|
||||
# Should raise validation error (422 gets wrapped as client error)
|
||||
error_msg = str(exc_info.value)
|
||||
assert (
|
||||
"Client error (422)" in error_msg
|
||||
or "could not be completed" in error_msg
|
||||
or "cannot contain '..' path components" in error_msg
|
||||
result = await move_note.fn(
|
||||
identifier="source/test-note",
|
||||
destination_path="../parent/file.md",
|
||||
)
|
||||
|
||||
# Should return user-friendly error message string
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed" in result
|
||||
assert "parent" in result or "Invalid" in result or "path" in result or ".." in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_identifier_variations(client):
|
||||
"""Test that various identifier formats work for moving."""
|
||||
# Create a note to test different identifier formats
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Document",
|
||||
folder="docs",
|
||||
content="# Test Document\nContent for testing identifiers.",
|
||||
)
|
||||
|
||||
# Test with permalink identifier
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="docs/test-document",
|
||||
destination_path="moved/TestDocument.md",
|
||||
)
|
||||
@@ -419,23 +389,23 @@ async def test_move_note_identifier_variations(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify it moved correctly
|
||||
content = await read_note("moved/test-document")
|
||||
content = await read_note.fn("moved/test-document")
|
||||
assert "# Test Document" in content
|
||||
assert "Content for testing identifiers" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_preserves_frontmatter(client):
|
||||
async def test_move_note_preserves_frontmatter(app, client):
|
||||
"""Test that moving preserves custom frontmatter."""
|
||||
# Create note with custom frontmatter by first creating it normally
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Custom Frontmatter Note",
|
||||
folder="source",
|
||||
content="# Custom Frontmatter Note\nContent with custom metadata.",
|
||||
)
|
||||
|
||||
# Move the note
|
||||
result = await move_note(
|
||||
result = await move_note.fn(
|
||||
identifier="source/custom-frontmatter-note",
|
||||
destination_path="target/MovedCustomNote.md",
|
||||
)
|
||||
@@ -444,9 +414,84 @@ async def test_move_note_preserves_frontmatter(client):
|
||||
assert "✅ Note moved successfully" in result
|
||||
|
||||
# Verify the moved note has proper frontmatter structure
|
||||
content = await read_note("target/moved-custom-note")
|
||||
content = await read_note.fn("target/moved-custom-note")
|
||||
assert "title: Custom Frontmatter Note" in content
|
||||
assert "type: note" in content
|
||||
assert "permalink: target/moved-custom-note" in content
|
||||
assert "# Custom Frontmatter Note" in content
|
||||
assert "Content with custom metadata" in content
|
||||
|
||||
|
||||
class TestMoveNoteErrorFormatting:
|
||||
"""Test move note error formatting for better user experience."""
|
||||
|
||||
def test_format_move_error_invalid_path(self):
|
||||
"""Test formatting for invalid path errors."""
|
||||
result = _format_move_error_response("invalid path format", "test-note", "/invalid/path.md")
|
||||
|
||||
assert "# Move Failed - Invalid Destination Path" in result
|
||||
assert "The destination path '/invalid/path.md' is not valid" in result
|
||||
assert "Relative paths only" in result
|
||||
assert "Include file extension" in result
|
||||
|
||||
def test_format_move_error_permission_denied(self):
|
||||
"""Test formatting for permission errors."""
|
||||
result = _format_move_error_response("permission denied", "test-note", "target/file.md")
|
||||
|
||||
assert "# Move Failed - Permission Error" in result
|
||||
assert "You don't have permission to move 'test-note'" in result
|
||||
assert "Check file permissions" in result
|
||||
assert "Check file locks" in result
|
||||
|
||||
def test_format_move_error_source_missing(self):
|
||||
"""Test formatting for source file missing errors."""
|
||||
result = _format_move_error_response("source file missing", "test-note", "target/file.md")
|
||||
|
||||
assert "# Move Failed - Source File Missing" in result
|
||||
assert "The source file for 'test-note' was not found on disk" in result
|
||||
assert "database and filesystem are out of sync" in result
|
||||
|
||||
def test_format_move_error_server_error(self):
|
||||
"""Test formatting for server errors."""
|
||||
result = _format_move_error_response("server error occurred", "test-note", "target/file.md")
|
||||
|
||||
assert "# Move Failed - System Error" in result
|
||||
assert "A system error occurred while moving 'test-note'" in result
|
||||
assert "Try again" in result
|
||||
assert "Check disk space" in result
|
||||
|
||||
|
||||
class TestMoveNoteErrorHandling:
|
||||
"""Test move note exception handling."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_exception_handling(self):
|
||||
"""Test exception handling in move_note."""
|
||||
with patch("basic_memory.mcp.tools.move_note.get_active_project") as mock_get_project:
|
||||
mock_get_project.return_value.project_url = "http://test"
|
||||
mock_get_project.return_value.name = "test-project"
|
||||
|
||||
with patch(
|
||||
"basic_memory.mcp.tools.move_note.call_post",
|
||||
side_effect=Exception("entity not found"),
|
||||
):
|
||||
result = await move_note.fn("test-note", "target/file.md")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed - Note Not Found" in result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_move_note_permission_error_handling(self):
|
||||
"""Test permission error handling in move_note."""
|
||||
with patch("basic_memory.mcp.tools.move_note.get_active_project") as mock_get_project:
|
||||
mock_get_project.return_value.project_url = "http://test"
|
||||
mock_get_project.return_value.name = "test-project"
|
||||
|
||||
with patch(
|
||||
"basic_memory.mcp.tools.move_note.call_post",
|
||||
side_effect=Exception("permission denied"),
|
||||
):
|
||||
result = await move_note.fn("test-note", "target/file.md")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "# Move Failed - Permission Error" in result
|
||||
|
||||
@@ -26,7 +26,7 @@ async def mock_call_get():
|
||||
@pytest_asyncio.fixture
|
||||
async def mock_search():
|
||||
"""Mock for search tool."""
|
||||
with patch("basic_memory.mcp.tools.read_note.search_notes") as mock:
|
||||
with patch("basic_memory.mcp.tools.read_note.search_notes.fn") as mock:
|
||||
# Default to empty results
|
||||
mock.return_value = SearchResponse(results=[], current_page=1, page_size=1)
|
||||
yield mock
|
||||
@@ -36,10 +36,10 @@ async def mock_search():
|
||||
async def test_read_note_by_title(app):
|
||||
"""Test reading a note by its title."""
|
||||
# First create a note
|
||||
await write_note(title="Special Note", folder="test", content="Note content here")
|
||||
await write_note.fn(title="Special Note", folder="test", content="Note content here")
|
||||
|
||||
# Should be able to read it by title
|
||||
content = await read_note("Special Note")
|
||||
content = await read_note.fn("Special Note")
|
||||
assert "Note content here" in content
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ async def test_read_note_by_title(app):
|
||||
async def test_note_unicode_content(app):
|
||||
"""Test handling of unicode content in"""
|
||||
content = "# Test 🚀\nThis note has emoji 🎉 and unicode ♠♣♥♦"
|
||||
result = await write_note(title="Unicode Test", folder="test", content=content)
|
||||
result = await write_note.fn(title="Unicode Test", folder="test", content=content)
|
||||
|
||||
assert (
|
||||
dedent("""
|
||||
@@ -60,7 +60,7 @@ async def test_note_unicode_content(app):
|
||||
)
|
||||
|
||||
# Read back should preserve unicode
|
||||
result = await read_note("test/unicode-test")
|
||||
result = await read_note.fn("test/unicode-test")
|
||||
assert content in result
|
||||
|
||||
|
||||
@@ -75,16 +75,16 @@ async def test_multiple_notes(app):
|
||||
]
|
||||
|
||||
for _, title, folder, content, tags in notes_data:
|
||||
await write_note(title=title, folder=folder, content=content, tags=tags)
|
||||
await write_note.fn(title=title, folder=folder, content=content, tags=tags)
|
||||
|
||||
# Should be able to read each one
|
||||
for permalink, title, folder, content, _ in notes_data:
|
||||
note = await read_note(permalink)
|
||||
note = await read_note.fn(permalink)
|
||||
assert content in note
|
||||
|
||||
# read multiple notes at once
|
||||
|
||||
result = await read_note("test/*")
|
||||
result = await read_note.fn("test/*")
|
||||
|
||||
# note we can't compare times
|
||||
assert "--- memory://test/note-1" in result
|
||||
@@ -108,15 +108,15 @@ async def test_multiple_notes_pagination(app):
|
||||
]
|
||||
|
||||
for _, title, folder, content, tags in notes_data:
|
||||
await write_note(title=title, folder=folder, content=content, tags=tags)
|
||||
await write_note.fn(title=title, folder=folder, content=content, tags=tags)
|
||||
|
||||
# Should be able to read each one
|
||||
for permalink, title, folder, content, _ in notes_data:
|
||||
note = await read_note(permalink)
|
||||
note = await read_note.fn(permalink)
|
||||
assert content in note
|
||||
|
||||
# read multiple notes at once with pagination
|
||||
result = await read_note("test/*", page=1, page_size=2)
|
||||
result = await read_note.fn("test/*", page=1, page_size=2)
|
||||
|
||||
# note we can't compare times
|
||||
assert "--- memory://test/note-1" in result
|
||||
@@ -136,7 +136,7 @@ async def test_read_note_memory_url(app):
|
||||
- Return the note content
|
||||
"""
|
||||
# First create a note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Memory URL Test",
|
||||
folder="test",
|
||||
content="Testing memory:// URL handling",
|
||||
@@ -145,7 +145,7 @@ async def test_read_note_memory_url(app):
|
||||
|
||||
# Should be able to read it with a memory:// URL
|
||||
memory_url = "memory://test/memory-url-test"
|
||||
content = await read_note(memory_url)
|
||||
content = await read_note.fn(memory_url)
|
||||
assert "Testing memory:// URL handling" in content
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ async def test_read_note_direct_success(mock_call_get):
|
||||
mock_call_get.return_value = mock_response
|
||||
|
||||
# Call the function
|
||||
result = await read_note("test/test-note")
|
||||
result = await read_note.fn("test/test-note")
|
||||
|
||||
# Verify direct lookup was used
|
||||
mock_call_get.assert_called_once()
|
||||
@@ -199,7 +199,7 @@ async def test_read_note_title_search_fallback(mock_call_get, mock_search):
|
||||
)
|
||||
|
||||
# Call the function
|
||||
result = await read_note("Test Note")
|
||||
result = await read_note.fn("Test Note")
|
||||
|
||||
# Verify title search was used
|
||||
mock_search.assert_called_once()
|
||||
@@ -253,7 +253,7 @@ async def test_read_note_text_search_fallback(mock_call_get, mock_search):
|
||||
]
|
||||
|
||||
# Call the function
|
||||
result = await read_note("some query")
|
||||
result = await read_note.fn("some query")
|
||||
|
||||
# Verify both search types were used
|
||||
assert mock_search.call_count == 2
|
||||
@@ -281,7 +281,7 @@ async def test_read_note_complete_fallback(mock_call_get, mock_search):
|
||||
mock_search.return_value = SearchResponse(results=[], current_page=1, page_size=1)
|
||||
|
||||
# Call the function
|
||||
result = await read_note("nonexistent")
|
||||
result = await read_note.fn("nonexistent")
|
||||
|
||||
# Verify search was used
|
||||
assert mock_search.call_count == 2
|
||||
|
||||
@@ -31,7 +31,7 @@ async def test_recent_activity_timeframe_formats(client, test_graph):
|
||||
# Test each valid timeframe
|
||||
for timeframe in valid_timeframes:
|
||||
try:
|
||||
result = await recent_activity(
|
||||
result = await recent_activity.fn(
|
||||
type=["entity"], timeframe=timeframe, page=1, page_size=10, max_related=10
|
||||
)
|
||||
assert result is not None
|
||||
@@ -41,7 +41,7 @@ async def test_recent_activity_timeframe_formats(client, test_graph):
|
||||
# Test invalid timeframes should raise ValidationError
|
||||
for timeframe in invalid_timeframes:
|
||||
with pytest.raises(ToolError):
|
||||
await recent_activity(timeframe=timeframe)
|
||||
await recent_activity.fn(timeframe=timeframe)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -49,25 +49,25 @@ async def test_recent_activity_type_filters(client, test_graph):
|
||||
"""Test that recent_activity correctly filters by types."""
|
||||
|
||||
# Test single string type
|
||||
result = await recent_activity(type=SearchItemType.ENTITY)
|
||||
result = await recent_activity.fn(type=SearchItemType.ENTITY)
|
||||
assert result is not None
|
||||
assert len(result.results) > 0
|
||||
assert all(isinstance(item.primary_result, EntitySummary) for item in result.results)
|
||||
|
||||
# Test single string type
|
||||
result = await recent_activity(type="entity")
|
||||
result = await recent_activity.fn(type="entity")
|
||||
assert result is not None
|
||||
assert len(result.results) > 0
|
||||
assert all(isinstance(item.primary_result, EntitySummary) for item in result.results)
|
||||
|
||||
# Test single type
|
||||
result = await recent_activity(type=["entity"])
|
||||
result = await recent_activity.fn(type=["entity"])
|
||||
assert result is not None
|
||||
assert len(result.results) > 0
|
||||
assert all(isinstance(item.primary_result, EntitySummary) for item in result.results)
|
||||
|
||||
# Test multiple types
|
||||
result = await recent_activity(type=["entity", "observation"])
|
||||
result = await recent_activity.fn(type=["entity", "observation"])
|
||||
assert result is not None
|
||||
assert len(result.results) > 0
|
||||
assert all(
|
||||
@@ -77,7 +77,7 @@ async def test_recent_activity_type_filters(client, test_graph):
|
||||
)
|
||||
|
||||
# Test multiple types
|
||||
result = await recent_activity(type=[SearchItemType.ENTITY, SearchItemType.OBSERVATION])
|
||||
result = await recent_activity.fn(type=[SearchItemType.ENTITY, SearchItemType.OBSERVATION])
|
||||
assert result is not None
|
||||
assert len(result.results) > 0
|
||||
assert all(
|
||||
@@ -87,7 +87,7 @@ async def test_recent_activity_type_filters(client, test_graph):
|
||||
)
|
||||
|
||||
# Test all types
|
||||
result = await recent_activity(type=["entity", "observation", "relation"])
|
||||
result = await recent_activity.fn(type=["entity", "observation", "relation"])
|
||||
assert result is not None
|
||||
assert len(result.results) > 0
|
||||
# Results can be any type
|
||||
@@ -105,14 +105,14 @@ async def test_recent_activity_type_invalid(client, test_graph):
|
||||
|
||||
# Test single invalid string type
|
||||
with pytest.raises(ValueError) as e:
|
||||
await recent_activity(type="note")
|
||||
await recent_activity.fn(type="note")
|
||||
assert (
|
||||
str(e.value) == "Invalid type: note. Valid types are: ['entity', 'observation', 'relation']"
|
||||
)
|
||||
|
||||
# Test invalid string array type
|
||||
with pytest.raises(ValueError) as e:
|
||||
await recent_activity(type=["note"])
|
||||
await recent_activity.fn(type=["note"])
|
||||
assert (
|
||||
str(e.value) == "Invalid type: note. Valid types are: ['entity', 'observation', 'relation']"
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ async def test_read_file_text_file(app, synced_files):
|
||||
- Include correct metadata
|
||||
"""
|
||||
# First create a text file via notes
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Text Resource",
|
||||
folder="test",
|
||||
content="This is a test text resource",
|
||||
@@ -34,7 +34,7 @@ async def test_read_file_text_file(app, synced_files):
|
||||
assert result is not None
|
||||
|
||||
# Now read it as a resource
|
||||
response = await read_content("test/text-resource")
|
||||
response = await read_content.fn("test/text-resource")
|
||||
|
||||
assert response["type"] == "text"
|
||||
assert "This is a test text resource" in response["text"]
|
||||
@@ -52,7 +52,7 @@ async def test_read_content_file_path(app, synced_files):
|
||||
- Include correct metadata
|
||||
"""
|
||||
# First create a text file via notes
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Text Resource",
|
||||
folder="test",
|
||||
content="This is a test text resource",
|
||||
@@ -61,7 +61,7 @@ async def test_read_content_file_path(app, synced_files):
|
||||
assert result is not None
|
||||
|
||||
# Now read it as a resource
|
||||
response = await read_content("test/Text Resource.md")
|
||||
response = await read_content.fn("test/Text Resource.md")
|
||||
|
||||
assert response["type"] == "text"
|
||||
assert "This is a test text resource" in response["text"]
|
||||
@@ -82,7 +82,7 @@ async def test_read_file_image_file(app, synced_files):
|
||||
image_path = synced_files["image"].name
|
||||
|
||||
# Read it as a resource
|
||||
response = await read_content(image_path)
|
||||
response = await read_content.fn(image_path)
|
||||
|
||||
assert response["type"] == "image"
|
||||
assert response["source"]["type"] == "base64"
|
||||
@@ -110,7 +110,7 @@ async def test_read_file_pdf_file(app, synced_files):
|
||||
pdf_path = synced_files["pdf"].name
|
||||
|
||||
# Read it as a resource
|
||||
response = await read_content(pdf_path)
|
||||
response = await read_content.fn(pdf_path)
|
||||
|
||||
assert response["type"] == "document"
|
||||
assert response["source"]["type"] == "base64"
|
||||
@@ -126,14 +126,14 @@ async def test_read_file_pdf_file(app, synced_files):
|
||||
async def test_read_file_not_found(app):
|
||||
"""Test trying to read a non-existent"""
|
||||
with pytest.raises(ToolError, match="Resource not found"):
|
||||
await read_content("does-not-exist")
|
||||
await read_content.fn("does-not-exist")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_file_memory_url(app, synced_files):
|
||||
"""Test reading a resource using a memory:// URL."""
|
||||
# Create a text file via notes
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Memory URL Test",
|
||||
folder="test",
|
||||
content="Testing memory:// URL handling for resources",
|
||||
@@ -141,7 +141,7 @@ async def test_read_file_memory_url(app, synced_files):
|
||||
|
||||
# Read it with a memory:// URL
|
||||
memory_url = "memory://test/memory-url-test"
|
||||
response = await read_content(memory_url)
|
||||
response = await read_content.fn(memory_url)
|
||||
|
||||
assert response["type"] == "text"
|
||||
assert "Testing memory:// URL handling for resources" in response["text"]
|
||||
@@ -205,7 +205,7 @@ async def test_image_conversion(app, synced_files):
|
||||
image_path = synced_files["image"].name
|
||||
|
||||
# Test reading the resource
|
||||
response = await read_content(image_path)
|
||||
response = await read_content.fn(image_path)
|
||||
|
||||
assert response["type"] == "image"
|
||||
assert response["source"]["media_type"] == "image/jpeg"
|
||||
|
||||
+106
-17
@@ -2,16 +2,17 @@
|
||||
|
||||
import pytest
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from basic_memory.mcp.tools import write_note
|
||||
from basic_memory.mcp.tools.search import search_notes
|
||||
from basic_memory.mcp.tools.search import search_notes, _format_search_error_response
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_text(client):
|
||||
"""Test basic search functionality."""
|
||||
# Create a test note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Search Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a searchable test note",
|
||||
@@ -20,7 +21,7 @@ async def test_search_text(client):
|
||||
assert result
|
||||
|
||||
# Search for it
|
||||
response = await search_notes(query="searchable")
|
||||
response = await search_notes.fn(query="searchable")
|
||||
|
||||
# Verify results
|
||||
assert len(response.results) > 0
|
||||
@@ -31,7 +32,7 @@ async def test_search_text(client):
|
||||
async def test_search_title(client):
|
||||
"""Test basic search functionality."""
|
||||
# Create a test note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Search Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a searchable test note",
|
||||
@@ -40,7 +41,7 @@ async def test_search_title(client):
|
||||
assert result
|
||||
|
||||
# Search for it
|
||||
response = await search_notes(query="Search Note", search_type="title")
|
||||
response = await search_notes.fn(query="Search Note", search_type="title")
|
||||
|
||||
# Verify results
|
||||
assert len(response.results) > 0
|
||||
@@ -51,7 +52,7 @@ async def test_search_title(client):
|
||||
async def test_search_permalink(client):
|
||||
"""Test basic search functionality."""
|
||||
# Create a test note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Search Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a searchable test note",
|
||||
@@ -60,7 +61,7 @@ async def test_search_permalink(client):
|
||||
assert result
|
||||
|
||||
# Search for it
|
||||
response = await search_notes(query="test/test-search-note", search_type="permalink")
|
||||
response = await search_notes.fn(query="test/test-search-note", search_type="permalink")
|
||||
|
||||
# Verify results
|
||||
assert len(response.results) > 0
|
||||
@@ -71,7 +72,7 @@ async def test_search_permalink(client):
|
||||
async def test_search_permalink_match(client):
|
||||
"""Test basic search functionality."""
|
||||
# Create a test note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Search Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a searchable test note",
|
||||
@@ -80,7 +81,7 @@ async def test_search_permalink_match(client):
|
||||
assert result
|
||||
|
||||
# Search for it
|
||||
response = await search_notes(query="test/test-search-*", search_type="permalink")
|
||||
response = await search_notes.fn(query="test/test-search-*", search_type="permalink")
|
||||
|
||||
# Verify results
|
||||
assert len(response.results) > 0
|
||||
@@ -91,7 +92,7 @@ async def test_search_permalink_match(client):
|
||||
async def test_search_pagination(client):
|
||||
"""Test basic search functionality."""
|
||||
# Create a test note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Search Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a searchable test note",
|
||||
@@ -100,7 +101,7 @@ async def test_search_pagination(client):
|
||||
assert result
|
||||
|
||||
# Search for it
|
||||
response = await search_notes(query="searchable", page=1, page_size=1)
|
||||
response = await search_notes.fn(query="searchable", page=1, page_size=1)
|
||||
|
||||
# Verify results
|
||||
assert len(response.results) == 1
|
||||
@@ -111,14 +112,14 @@ async def test_search_pagination(client):
|
||||
async def test_search_with_type_filter(client):
|
||||
"""Test search with entity type filter."""
|
||||
# Create test content
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Entity Type Test",
|
||||
folder="test",
|
||||
content="# Test\nFiltered by type",
|
||||
)
|
||||
|
||||
# Search with type filter
|
||||
response = await search_notes(query="type", types=["note"])
|
||||
response = await search_notes.fn(query="type", types=["note"])
|
||||
|
||||
# Verify all results are entities
|
||||
assert all(r.type == "entity" for r in response.results)
|
||||
@@ -128,14 +129,14 @@ async def test_search_with_type_filter(client):
|
||||
async def test_search_with_entity_type_filter(client):
|
||||
"""Test search with entity type filter."""
|
||||
# Create test content
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Entity Type Test",
|
||||
folder="test",
|
||||
content="# Test\nFiltered by type",
|
||||
)
|
||||
|
||||
# Search with entity type filter
|
||||
response = await search_notes(query="type", entity_types=["entity"])
|
||||
response = await search_notes.fn(query="type", entity_types=["entity"])
|
||||
|
||||
# Verify all results are entities
|
||||
assert all(r.type == "entity" for r in response.results)
|
||||
@@ -145,7 +146,7 @@ async def test_search_with_entity_type_filter(client):
|
||||
async def test_search_with_date_filter(client):
|
||||
"""Test search with date filter."""
|
||||
# Create test content
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Recent Note",
|
||||
folder="test",
|
||||
content="# Test\nRecent content",
|
||||
@@ -153,7 +154,95 @@ async def test_search_with_date_filter(client):
|
||||
|
||||
# Search with date filter
|
||||
one_hour_ago = datetime.now() - timedelta(hours=1)
|
||||
response = await search_notes(query="recent", after_date=one_hour_ago.isoformat())
|
||||
response = await search_notes.fn(query="recent", after_date=one_hour_ago.isoformat())
|
||||
|
||||
# Verify we get results within timeframe
|
||||
assert len(response.results) > 0
|
||||
|
||||
|
||||
class TestSearchErrorFormatting:
|
||||
"""Test search error formatting for better user experience."""
|
||||
|
||||
def test_format_search_error_fts5_syntax(self):
|
||||
"""Test formatting for FTS5 syntax errors."""
|
||||
result = _format_search_error_response("syntax error in FTS5", "test query(")
|
||||
|
||||
assert "# Search Failed - Invalid Syntax" in result
|
||||
assert "The search query 'test query(' contains invalid syntax" in result
|
||||
assert "Special characters" in result
|
||||
assert "test query" in result # Clean query without special chars
|
||||
|
||||
def test_format_search_error_no_results(self):
|
||||
"""Test formatting for no results found."""
|
||||
result = _format_search_error_response("no results found", "very specific query")
|
||||
|
||||
assert "# Search Complete - No Results Found" in result
|
||||
assert "No content found matching 'very specific query'" in result
|
||||
assert "Broaden your search" in result
|
||||
assert "very" in result # Simplified query
|
||||
|
||||
def test_format_search_error_server_error(self):
|
||||
"""Test formatting for server errors."""
|
||||
result = _format_search_error_response("internal server error", "test query")
|
||||
|
||||
assert "# Search Failed - Server Error" in result
|
||||
assert "The search service encountered an error while processing 'test query'" in result
|
||||
assert "Try again" in result
|
||||
assert "Check project status" in result
|
||||
|
||||
def test_format_search_error_permission_denied(self):
|
||||
"""Test formatting for permission errors."""
|
||||
result = _format_search_error_response("permission denied", "test query")
|
||||
|
||||
assert "# Search Failed - Access Error" in result
|
||||
assert "You don't have permission to search" in result
|
||||
assert "Check your project access" in result
|
||||
|
||||
def test_format_search_error_project_not_found(self):
|
||||
"""Test formatting for project not found errors."""
|
||||
result = _format_search_error_response("current project not found", "test query")
|
||||
|
||||
assert "# Search Failed - Project Not Found" in result
|
||||
assert "The current project is not accessible" in result
|
||||
assert "Check available projects" in result
|
||||
|
||||
def test_format_search_error_generic(self):
|
||||
"""Test formatting for generic errors."""
|
||||
result = _format_search_error_response("unknown error", "test query")
|
||||
|
||||
assert "# Search Failed" in result
|
||||
assert "Error searching for 'test query': unknown error" in result
|
||||
assert "General troubleshooting" in result
|
||||
|
||||
|
||||
class TestSearchToolErrorHandling:
|
||||
"""Test search tool exception handling."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_notes_exception_handling(self):
|
||||
"""Test exception handling in search_notes."""
|
||||
with patch("basic_memory.mcp.tools.search.get_active_project") as mock_get_project:
|
||||
mock_get_project.return_value.project_url = "http://test"
|
||||
|
||||
with patch(
|
||||
"basic_memory.mcp.tools.search.call_post", side_effect=Exception("syntax error")
|
||||
):
|
||||
result = await search_notes.fn("test query")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "# Search Failed - Invalid Syntax" in result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_notes_permission_error(self):
|
||||
"""Test search_notes with permission error."""
|
||||
with patch("basic_memory.mcp.tools.search.get_active_project") as mock_get_project:
|
||||
mock_get_project.return_value.project_url = "http://test"
|
||||
|
||||
with patch(
|
||||
"basic_memory.mcp.tools.search.call_post",
|
||||
side_effect=Exception("permission denied"),
|
||||
):
|
||||
result = await search_notes.fn("test query")
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert "# Search Failed - Access Error" in result
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
"""Tests for sync_status MCP tool."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from basic_memory.mcp.tools.sync_status import sync_status
|
||||
from basic_memory.services.sync_status_service import (
|
||||
SyncStatus,
|
||||
ProjectSyncStatus,
|
||||
SyncStatusTracker,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_completed():
|
||||
"""Test sync_status when all operations are completed."""
|
||||
# Mock sync status tracker with ready status
|
||||
mock_tracker = MagicMock(spec=SyncStatusTracker)
|
||||
mock_tracker.is_ready = True
|
||||
mock_tracker.get_summary.return_value = "✅ All projects synced successfully"
|
||||
mock_tracker.get_all_projects.return_value = {}
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await sync_status.fn()
|
||||
|
||||
assert "Basic Memory Sync Status" in result
|
||||
assert "System Ready**: ✅ Yes" in result
|
||||
assert "All sync operations completed" in result
|
||||
assert "File indexing is complete" in result
|
||||
assert "knowledge base is ready for use" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_in_progress():
|
||||
"""Test sync_status when sync is in progress."""
|
||||
# Mock sync status tracker with in progress status
|
||||
mock_tracker = MagicMock(spec=SyncStatusTracker)
|
||||
mock_tracker.is_ready = False
|
||||
mock_tracker.get_summary.return_value = "🔄 Syncing 2 projects (5/10 files, 50%)"
|
||||
|
||||
# Mock active projects
|
||||
project1 = ProjectSyncStatus(
|
||||
project_name="project1",
|
||||
status=SyncStatus.SYNCING,
|
||||
message="Processing new files",
|
||||
files_total=5,
|
||||
files_processed=3,
|
||||
)
|
||||
project2 = ProjectSyncStatus(
|
||||
project_name="project2",
|
||||
status=SyncStatus.SCANNING,
|
||||
message="Scanning files",
|
||||
files_total=5,
|
||||
files_processed=2,
|
||||
)
|
||||
|
||||
mock_tracker.get_all_projects.return_value = {"project1": project1, "project2": project2}
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await sync_status.fn()
|
||||
|
||||
assert "Basic Memory Sync Status" in result
|
||||
assert "System Ready**: 🔄 Processing" in result
|
||||
assert "File synchronization in progress" in result
|
||||
assert "project1**: Processing new files (3/5, 60%)" in result
|
||||
assert "project2**: Scanning files (2/5, 40%)" in result
|
||||
assert "Scanning and indexing markdown files" in result
|
||||
assert "Use this tool again to check progress" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_failed():
|
||||
"""Test sync_status when sync has failed."""
|
||||
# Mock sync status tracker with failed project
|
||||
mock_tracker = MagicMock(spec=SyncStatusTracker)
|
||||
mock_tracker.is_ready = False
|
||||
mock_tracker.get_summary.return_value = "❌ Sync failed for: project1"
|
||||
|
||||
# Mock failed project
|
||||
failed_project = ProjectSyncStatus(
|
||||
project_name="project1",
|
||||
status=SyncStatus.FAILED,
|
||||
message="Sync failed",
|
||||
error="Permission denied",
|
||||
)
|
||||
|
||||
mock_tracker.get_all_projects.return_value = {"project1": failed_project}
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await sync_status.fn()
|
||||
|
||||
assert "Basic Memory Sync Status" in result
|
||||
assert "System Ready**: 🔄 Processing" in result
|
||||
assert "Some projects failed to sync" in result
|
||||
assert "project1**: Permission denied" in result
|
||||
assert "Check the logs for detailed error information" in result
|
||||
assert "Try restarting the MCP server" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_idle():
|
||||
"""Test sync_status when system is idle."""
|
||||
# Mock sync status tracker with idle status
|
||||
mock_tracker = MagicMock(spec=SyncStatusTracker)
|
||||
mock_tracker.is_ready = True
|
||||
mock_tracker.get_summary.return_value = "✅ System ready"
|
||||
mock_tracker.get_all_projects.return_value = {}
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await sync_status.fn()
|
||||
|
||||
assert "Basic Memory Sync Status" in result
|
||||
assert "System Ready**: ✅ Yes" in result
|
||||
assert "All sync operations completed" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_with_project():
|
||||
"""Test sync_status with specific project context."""
|
||||
# Mock sync status tracker
|
||||
mock_tracker = MagicMock(spec=SyncStatusTracker)
|
||||
mock_tracker.is_ready = True
|
||||
mock_tracker.get_summary.return_value = "✅ All projects synced successfully"
|
||||
|
||||
# Mock specific project status
|
||||
project_status = ProjectSyncStatus(
|
||||
project_name="test-project",
|
||||
status=SyncStatus.COMPLETED,
|
||||
message="Sync completed",
|
||||
files_total=10,
|
||||
files_processed=10,
|
||||
)
|
||||
mock_tracker.get_project_status.return_value = project_status
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await sync_status.fn(project="test-project")
|
||||
|
||||
# The function should use the original logic for project-specific queries
|
||||
# But since we changed the implementation, let's just verify it doesn't crash
|
||||
assert "Basic Memory Sync Status" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_pending():
|
||||
"""Test sync_status when no projects are active."""
|
||||
# Mock sync status tracker with no active projects
|
||||
mock_tracker = MagicMock(spec=SyncStatusTracker)
|
||||
mock_tracker.is_ready = False
|
||||
mock_tracker.get_summary.return_value = "✅ System ready"
|
||||
mock_tracker.get_all_projects.return_value = {}
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await sync_status.fn()
|
||||
|
||||
assert "Basic Memory Sync Status" in result
|
||||
assert "Sync operations pending" in result
|
||||
assert "usually resolves automatically" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_status_error_handling():
|
||||
"""Test sync_status handles errors gracefully."""
|
||||
# Mock sync status tracker that raises an exception
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker") as mock_tracker:
|
||||
mock_tracker.is_ready = True
|
||||
mock_tracker.get_summary.side_effect = Exception("Test error")
|
||||
|
||||
result = await sync_status.fn()
|
||||
|
||||
assert "Unable to check sync status**: Test error" in result
|
||||
@@ -1,12 +1,20 @@
|
||||
"""Tests for MCP tool utilities."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, patch, MagicMock
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient, HTTPStatusError
|
||||
from mcp.server.fastmcp.exceptions import ToolError
|
||||
|
||||
from basic_memory.mcp.tools.utils import call_get, call_post, call_put, call_delete
|
||||
from basic_memory.mcp.tools.utils import (
|
||||
call_get,
|
||||
call_post,
|
||||
call_put,
|
||||
call_delete,
|
||||
get_error_message,
|
||||
check_migration_status,
|
||||
wait_for_migration_or_return_status,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -135,7 +143,6 @@ async def test_call_get_with_params(mock_response):
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_error_message():
|
||||
"""Test the get_error_message function."""
|
||||
from basic_memory.mcp.tools.utils import get_error_message
|
||||
|
||||
# Test 400 status code
|
||||
message = get_error_message(400, "http://test.com/resource", "GET")
|
||||
@@ -177,3 +184,82 @@ async def test_call_post_with_json(mock_response):
|
||||
mock_post.assert_called_once()
|
||||
call_kwargs = mock_post.call_args[1]
|
||||
assert call_kwargs["json"] == json_data
|
||||
|
||||
|
||||
class TestMigrationStatus:
|
||||
"""Test migration status checking functions."""
|
||||
|
||||
def test_check_migration_status_ready(self):
|
||||
"""Test check_migration_status when system is ready."""
|
||||
mock_tracker = MagicMock()
|
||||
mock_tracker.is_ready = True
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = check_migration_status()
|
||||
assert result is None
|
||||
|
||||
def test_check_migration_status_not_ready(self):
|
||||
"""Test check_migration_status when sync is in progress."""
|
||||
mock_tracker = MagicMock()
|
||||
mock_tracker.is_ready = False
|
||||
mock_tracker.get_summary.return_value = "Sync in progress..."
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = check_migration_status()
|
||||
assert result == "Sync in progress..."
|
||||
mock_tracker.get_summary.assert_called_once()
|
||||
|
||||
def test_check_migration_status_exception(self):
|
||||
"""Test check_migration_status with import/other exception."""
|
||||
# Mock the import itself to raise an exception
|
||||
with patch("builtins.__import__", side_effect=ImportError("Module not found")):
|
||||
result = check_migration_status()
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wait_for_migration_ready(self):
|
||||
"""Test wait_for_migration when system is already ready."""
|
||||
mock_tracker = MagicMock()
|
||||
mock_tracker.is_ready = True
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
result = await wait_for_migration_or_return_status()
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wait_for_migration_becomes_ready(self):
|
||||
"""Test wait_for_migration when system becomes ready during wait."""
|
||||
mock_tracker = MagicMock()
|
||||
mock_tracker.is_ready = False
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
# Mock asyncio.sleep to make tracker ready after first check
|
||||
async def mock_sleep(delay):
|
||||
mock_tracker.is_ready = True
|
||||
|
||||
with patch("asyncio.sleep", side_effect=mock_sleep):
|
||||
result = await wait_for_migration_or_return_status(timeout=1.0)
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wait_for_migration_timeout(self):
|
||||
"""Test wait_for_migration when timeout occurs."""
|
||||
mock_tracker = MagicMock()
|
||||
mock_tracker.is_ready = False
|
||||
mock_tracker.get_summary.return_value = "Still syncing..."
|
||||
|
||||
with patch("basic_memory.services.sync_status_service.sync_status_tracker", mock_tracker):
|
||||
with patch("asyncio.sleep", new_callable=AsyncMock):
|
||||
result = await wait_for_migration_or_return_status(timeout=0.1)
|
||||
assert result == "Still syncing..."
|
||||
mock_tracker.get_summary.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wait_for_migration_exception(self):
|
||||
"""Test wait_for_migration with exception during checking."""
|
||||
with patch(
|
||||
"basic_memory.services.sync_status_service.sync_status_tracker",
|
||||
side_effect=Exception("Test error"),
|
||||
):
|
||||
result = await wait_for_migration_or_return_status()
|
||||
assert result is None
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
"""Tests for view_note tool that exercise the full stack with SQLite."""
|
||||
|
||||
from textwrap import dedent
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from basic_memory.mcp.tools import write_note, view_note
|
||||
from basic_memory.schemas.search import SearchResponse, SearchItemType
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def mock_call_get():
|
||||
"""Mock for call_get to simulate different responses."""
|
||||
with patch("basic_memory.mcp.tools.read_note.call_get") as mock:
|
||||
# Default to 404 - not found
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 404
|
||||
mock.return_value = mock_response
|
||||
yield mock
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def mock_search():
|
||||
"""Mock for search tool."""
|
||||
with patch("basic_memory.mcp.tools.read_note.search_notes.fn") as mock:
|
||||
# Default to empty results
|
||||
mock.return_value = SearchResponse(results=[], current_page=1, page_size=1)
|
||||
yield mock
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_basic_functionality(app):
|
||||
"""Test viewing a note creates an artifact."""
|
||||
# First create a note
|
||||
await write_note.fn(
|
||||
title="Test View Note",
|
||||
folder="test",
|
||||
content="# Test View Note\n\nThis is test content for viewing.",
|
||||
)
|
||||
|
||||
# View the note
|
||||
result = await view_note.fn("Test View Note")
|
||||
|
||||
# Should contain artifact XML
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert 'type="text/markdown"' in result
|
||||
assert 'title="Test View Note"' in result
|
||||
assert "</artifact>" in result
|
||||
|
||||
# Should contain the note content within the artifact
|
||||
assert "# Test View Note" in result
|
||||
assert "This is test content for viewing." in result
|
||||
|
||||
# Should have confirmation message
|
||||
assert "✅ Note displayed as artifact" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_with_frontmatter_title(app):
|
||||
"""Test viewing a note extracts title from frontmatter."""
|
||||
# Create note with frontmatter
|
||||
content = dedent("""
|
||||
---
|
||||
title: "Frontmatter Title"
|
||||
tags: [test]
|
||||
---
|
||||
|
||||
# Frontmatter Title
|
||||
|
||||
Content with frontmatter title.
|
||||
""").strip()
|
||||
|
||||
await write_note.fn(title="Frontmatter Title", folder="test", content=content)
|
||||
|
||||
# View the note
|
||||
result = await view_note.fn("Frontmatter Title")
|
||||
|
||||
# Should extract title from frontmatter
|
||||
assert 'title="Frontmatter Title"' in result
|
||||
assert "✅ Note displayed as artifact: **Frontmatter Title**" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_with_heading_title(app):
|
||||
"""Test viewing a note extracts title from first heading when no frontmatter."""
|
||||
# Create note with heading but no frontmatter title
|
||||
content = "# Heading Title\n\nContent with heading title."
|
||||
|
||||
await write_note.fn(title="Heading Title", folder="test", content=content)
|
||||
|
||||
# View the note
|
||||
result = await view_note.fn("Heading Title")
|
||||
|
||||
# Should extract title from heading
|
||||
assert 'title="Heading Title"' in result
|
||||
assert "✅ Note displayed as artifact: **Heading Title**" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_unicode_content(app):
|
||||
"""Test viewing a note with Unicode content."""
|
||||
content = "# Unicode Test 🚀\n\nThis note has emoji 🎉 and unicode ♠♣♥♦"
|
||||
|
||||
await write_note.fn(title="Unicode Test 🚀", folder="test", content=content)
|
||||
|
||||
# View the note
|
||||
result = await view_note.fn("Unicode Test 🚀")
|
||||
|
||||
# Should handle Unicode properly
|
||||
assert "🚀" in result
|
||||
assert "🎉" in result
|
||||
assert "♠♣♥♦" in result
|
||||
assert '<artifact identifier="note-' in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_by_permalink(app):
|
||||
"""Test viewing a note by its permalink."""
|
||||
await write_note.fn(
|
||||
title="Permalink Test", folder="test", content="Content for permalink test."
|
||||
)
|
||||
|
||||
# View by permalink
|
||||
result = await view_note.fn("test/permalink-test")
|
||||
|
||||
# Should work with permalink
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert "Content for permalink test." in result
|
||||
assert "✅ Note displayed as artifact" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_with_memory_url(app):
|
||||
"""Test viewing a note using a memory:// URL."""
|
||||
await write_note.fn(
|
||||
title="Memory URL Test",
|
||||
folder="test",
|
||||
content="Testing memory:// URL handling in view_note",
|
||||
)
|
||||
|
||||
# View with memory:// URL
|
||||
result = await view_note.fn("memory://test/memory-url-test")
|
||||
|
||||
# Should work with memory:// URL
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert "Testing memory:// URL handling in view_note" in result
|
||||
assert "✅ Note displayed as artifact" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_not_found(app):
|
||||
"""Test viewing a non-existent note returns error without artifact."""
|
||||
# Try to view non-existent note
|
||||
result = await view_note.fn("NonExistent Note")
|
||||
|
||||
# Should return error message without artifact
|
||||
assert "# Note Not Found:" in result
|
||||
assert "NonExistent Note" in result
|
||||
assert "<artifact" not in result # No artifact for errors
|
||||
assert "Check Identifier Type" in result
|
||||
assert "Search Instead" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_pagination(app):
|
||||
"""Test viewing a note with pagination parameters."""
|
||||
await write_note.fn(
|
||||
title="Pagination Test", folder="test", content="Content for pagination test."
|
||||
)
|
||||
|
||||
# View with pagination
|
||||
result = await view_note.fn("Pagination Test", page=1, page_size=5)
|
||||
|
||||
# Should work with pagination
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert "Content for pagination test." in result
|
||||
assert "✅ Note displayed as artifact" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_project_parameter(app):
|
||||
"""Test viewing a note with project parameter."""
|
||||
await write_note.fn(title="Project Test", folder="test", content="Content for project test.")
|
||||
|
||||
# View with explicit project (None uses current)
|
||||
result = await view_note.fn("Project Test", project=None)
|
||||
|
||||
# Should work with project parameter
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert "Content for project test." in result
|
||||
assert "✅ Note displayed as artifact" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_artifact_identifier_unique(app):
|
||||
"""Test that different notes get different artifact identifiers."""
|
||||
# Create two notes
|
||||
await write_note.fn(title="Note One", folder="test", content="Content one")
|
||||
await write_note.fn(title="Note Two", folder="test", content="Content two")
|
||||
|
||||
# View both notes
|
||||
result1 = await view_note.fn("Note One")
|
||||
result2 = await view_note.fn("Note Two")
|
||||
|
||||
# Should have different artifact identifiers
|
||||
import re
|
||||
|
||||
id1_match = re.search(r'identifier="(note-\d+)"', result1)
|
||||
id2_match = re.search(r'identifier="(note-\d+)"', result2)
|
||||
|
||||
assert id1_match is not None
|
||||
assert id2_match is not None
|
||||
assert id1_match.group(1) != id2_match.group(1)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_fallback_identifier_as_title(app):
|
||||
"""Test that view_note uses identifier as title when no title is extractable."""
|
||||
# Create a note with no clear title structure
|
||||
await write_note.fn(
|
||||
title="Simple Note",
|
||||
folder="test",
|
||||
content="Just plain content with no headings or frontmatter title",
|
||||
)
|
||||
|
||||
# View the note
|
||||
result = await view_note.fn("Simple Note")
|
||||
|
||||
# Should use identifier as fallback title
|
||||
assert 'title="Simple Note"' in result
|
||||
assert "✅ Note displayed as artifact: **Simple Note**" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_direct_success(mock_call_get):
|
||||
"""Test view_note with successful direct permalink lookup."""
|
||||
# Setup mock for successful response with frontmatter
|
||||
note_content = dedent("""
|
||||
---
|
||||
title: "Test Note"
|
||||
---
|
||||
# Test Note
|
||||
|
||||
This is a test note.
|
||||
""").strip()
|
||||
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.text = note_content
|
||||
mock_call_get.return_value = mock_response
|
||||
|
||||
# Call the function
|
||||
result = await view_note.fn("test/test-note")
|
||||
|
||||
# Verify direct lookup was used
|
||||
mock_call_get.assert_called_once()
|
||||
assert "test/test-note" in mock_call_get.call_args[0][1]
|
||||
|
||||
# Verify result contains artifact
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert 'title="Test Note"' in result
|
||||
assert "This is a test note." in result
|
||||
assert "✅ Note displayed as artifact: **Test Note**" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_view_note_title_search_fallback(mock_call_get, mock_search):
|
||||
"""Test view_note falls back to title search when direct lookup fails."""
|
||||
# Setup mock for failed direct lookup
|
||||
mock_call_get.side_effect = [
|
||||
# First call fails (direct lookup)
|
||||
MagicMock(status_code=404),
|
||||
# Second call succeeds (after title search)
|
||||
MagicMock(status_code=200, text="# Test Note\n\nThis is a test note."),
|
||||
]
|
||||
|
||||
# Setup mock for successful title search
|
||||
mock_search.return_value = SearchResponse(
|
||||
results=[
|
||||
{
|
||||
"id": 1,
|
||||
"entity": "test/test-note",
|
||||
"title": "Test Note",
|
||||
"type": SearchItemType.ENTITY,
|
||||
"permalink": "test/test-note",
|
||||
"file_path": "test/test-note.md",
|
||||
"score": 1.0,
|
||||
}
|
||||
],
|
||||
current_page=1,
|
||||
page_size=1,
|
||||
)
|
||||
|
||||
# Call the function
|
||||
result = await view_note.fn("Test Note")
|
||||
|
||||
# Verify title search was used
|
||||
mock_search.assert_called_once()
|
||||
|
||||
# Verify result contains artifact with extracted title
|
||||
assert '<artifact identifier="note-' in result
|
||||
assert 'title="Test Note"' in result
|
||||
assert "This is a test note." in result
|
||||
assert "✅ Note displayed as artifact: **Test Note**" in result
|
||||
@@ -16,7 +16,7 @@ async def test_write_note(app):
|
||||
- Handle tags correctly
|
||||
- Return valid permalink
|
||||
"""
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a test note",
|
||||
@@ -31,7 +31,7 @@ async def test_write_note(app):
|
||||
assert "- test, documentation" in result
|
||||
|
||||
# Try reading it back via permalink
|
||||
content = await read_note("test/test-note")
|
||||
content = await read_note.fn("test/test-note")
|
||||
assert (
|
||||
dedent("""
|
||||
---
|
||||
@@ -53,14 +53,14 @@ async def test_write_note(app):
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_note_no_tags(app):
|
||||
"""Test creating a note without tags."""
|
||||
result = await write_note(title="Simple Note", folder="test", content="Just some text")
|
||||
result = await write_note.fn(title="Simple Note", folder="test", content="Just some text")
|
||||
|
||||
assert result
|
||||
assert "# Created note" in result
|
||||
assert "file_path: test/Simple Note.md" in result
|
||||
assert "permalink: test/simple-note" in result
|
||||
# Should be able to read it back
|
||||
content = await read_note("test/simple-note")
|
||||
content = await read_note.fn("test/simple-note")
|
||||
assert (
|
||||
dedent("""
|
||||
--
|
||||
@@ -85,7 +85,7 @@ async def test_write_note_update_existing(app):
|
||||
- Handle tags correctly
|
||||
- Return valid permalink
|
||||
"""
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a test note",
|
||||
@@ -99,7 +99,7 @@ async def test_write_note_update_existing(app):
|
||||
assert "## Tags" in result
|
||||
assert "- test, documentation" in result
|
||||
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is an updated note",
|
||||
@@ -112,7 +112,7 @@ async def test_write_note_update_existing(app):
|
||||
assert "- test, documentation" in result
|
||||
|
||||
# Try reading it back
|
||||
content = await read_note("test/test-note")
|
||||
content = await read_note.fn("test/test-note")
|
||||
assert (
|
||||
dedent(
|
||||
"""
|
||||
@@ -150,7 +150,7 @@ async def test_issue_93_write_note_respects_custom_permalink_new_note(app):
|
||||
- [note] Testing if custom permalink is respected
|
||||
""").strip()
|
||||
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="My New Note",
|
||||
folder="notes",
|
||||
content=content_with_custom_permalink,
|
||||
@@ -167,7 +167,7 @@ async def test_issue_93_write_note_respects_custom_permalink_existing_note(app):
|
||||
"""Test that write_note respects custom permalinks when updating existing notes (Issue #93)"""
|
||||
|
||||
# Step 1: Create initial note (auto-generated permalink)
|
||||
result1 = await write_note(
|
||||
result1 = await write_note.fn(
|
||||
title="Existing Note",
|
||||
folder="test",
|
||||
content="Initial content without custom permalink",
|
||||
@@ -197,7 +197,7 @@ async def test_issue_93_write_note_respects_custom_permalink_existing_note(app):
|
||||
- [note] Custom permalink should be respected on update
|
||||
""").strip()
|
||||
|
||||
result2 = await write_note(
|
||||
result2 = await write_note.fn(
|
||||
title="Existing Note",
|
||||
folder="test",
|
||||
content=updated_content,
|
||||
@@ -218,7 +218,7 @@ async def test_delete_note_existing(app):
|
||||
- Return valid permalink
|
||||
- Delete the note
|
||||
"""
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="# Test\nThis is a test note",
|
||||
@@ -227,7 +227,7 @@ async def test_delete_note_existing(app):
|
||||
|
||||
assert result
|
||||
|
||||
deleted = await delete_note("test/test-note")
|
||||
deleted = await delete_note.fn("test/test-note")
|
||||
assert deleted is True
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ async def test_delete_note_doesnt_exist(app):
|
||||
- Delete the note
|
||||
- verify returns false
|
||||
"""
|
||||
deleted = await delete_note("doesnt-exist")
|
||||
deleted = await delete_note.fn("doesnt-exist")
|
||||
assert deleted is False
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ async def test_write_note_with_tag_array_from_bug_report(app):
|
||||
}
|
||||
|
||||
# Try to call the function with this data directly
|
||||
result = await write_note(**bug_payload)
|
||||
result = await write_note.fn(**bug_payload)
|
||||
|
||||
assert result
|
||||
assert "permalink: folder/title" in result
|
||||
@@ -277,7 +277,7 @@ async def test_write_note_verbose(app):
|
||||
- Handle tags correctly
|
||||
- Return valid permalink
|
||||
"""
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content="""
|
||||
@@ -313,7 +313,7 @@ async def test_write_note_preserves_custom_metadata(app, project_config):
|
||||
- Verify custom frontmatter is preserved
|
||||
"""
|
||||
# First, create a note with custom metadata using write_note
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Custom Metadata Note",
|
||||
folder="test",
|
||||
content="# Initial content",
|
||||
@@ -321,7 +321,7 @@ async def test_write_note_preserves_custom_metadata(app, project_config):
|
||||
)
|
||||
|
||||
# Read the note to get its permalink
|
||||
content = await read_note("test/custom-metadata-note")
|
||||
content = await read_note.fn("test/custom-metadata-note")
|
||||
|
||||
# Now directly update the file with custom frontmatter
|
||||
# We need to use a direct file update to add custom frontmatter
|
||||
@@ -340,7 +340,7 @@ async def test_write_note_preserves_custom_metadata(app, project_config):
|
||||
f.write(frontmatter.dumps(post))
|
||||
|
||||
# Now update the note using write_note
|
||||
result = await write_note(
|
||||
result = await write_note.fn(
|
||||
title="Custom Metadata Note",
|
||||
folder="test",
|
||||
content="# Updated content",
|
||||
@@ -351,7 +351,7 @@ async def test_write_note_preserves_custom_metadata(app, project_config):
|
||||
assert ("Updated note\nfile_path: test/Custom Metadata Note.md") in result
|
||||
|
||||
# Read the note back and check if custom frontmatter is preserved
|
||||
content = await read_note("test/custom-metadata-note")
|
||||
content = await read_note.fn("test/custom-metadata-note")
|
||||
|
||||
# Custom frontmatter should be preserved
|
||||
assert "Status: In Progress" in content
|
||||
@@ -371,7 +371,7 @@ async def test_write_note_preserves_custom_metadata(app, project_config):
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_note_preserves_content_frontmatter(app):
|
||||
"""Test creating a new note."""
|
||||
await write_note(
|
||||
await write_note.fn(
|
||||
title="Test Note",
|
||||
folder="test",
|
||||
content=dedent(
|
||||
@@ -391,7 +391,7 @@ async def test_write_note_preserves_content_frontmatter(app):
|
||||
)
|
||||
|
||||
# Try reading it back via permalink
|
||||
content = await read_note("test/test-note")
|
||||
content = await read_note.fn("test/test-note")
|
||||
assert (
|
||||
dedent(
|
||||
"""
|
||||
|
||||
@@ -301,3 +301,219 @@ def test_directory_property():
|
||||
project_id=1,
|
||||
)
|
||||
assert row3.directory == ""
|
||||
|
||||
|
||||
class TestSearchTermPreparation:
|
||||
"""Test cases for FTS5 search term preparation."""
|
||||
|
||||
def test_simple_terms_get_prefix_wildcard(self, search_repository):
|
||||
"""Simple alphanumeric terms should get prefix matching."""
|
||||
assert search_repository._prepare_search_term("hello") == "hello*"
|
||||
assert search_repository._prepare_search_term("project") == "project*"
|
||||
assert search_repository._prepare_search_term("test123") == "test123*"
|
||||
|
||||
def test_terms_with_existing_wildcard_unchanged(self, search_repository):
|
||||
"""Terms that already contain * should remain unchanged."""
|
||||
assert search_repository._prepare_search_term("hello*") == "hello*"
|
||||
assert search_repository._prepare_search_term("test*world") == "test*world"
|
||||
|
||||
def test_boolean_operators_preserved(self, search_repository):
|
||||
"""Boolean operators should be preserved without modification."""
|
||||
assert search_repository._prepare_search_term("hello AND world") == "hello AND world"
|
||||
assert search_repository._prepare_search_term("cat OR dog") == "cat OR dog"
|
||||
assert (
|
||||
search_repository._prepare_search_term("project NOT meeting") == "project NOT meeting"
|
||||
)
|
||||
assert (
|
||||
search_repository._prepare_search_term("(hello AND world) OR test")
|
||||
== "(hello AND world) OR test"
|
||||
)
|
||||
|
||||
def test_programming_terms_should_work(self, search_repository):
|
||||
"""Programming-related terms with special chars should be searchable."""
|
||||
# These should be quoted to handle special characters safely
|
||||
assert search_repository._prepare_search_term("C++") == '"C++"*'
|
||||
assert search_repository._prepare_search_term("function()") == '"function()"*'
|
||||
assert search_repository._prepare_search_term("email@domain.com") == '"email@domain.com"*'
|
||||
assert search_repository._prepare_search_term("array[index]") == '"array[index]"*'
|
||||
assert search_repository._prepare_search_term("config.json") == '"config.json"*'
|
||||
|
||||
def test_malformed_fts5_syntax_quoted(self, search_repository):
|
||||
"""Malformed FTS5 syntax should be quoted to prevent errors."""
|
||||
# Multiple operators without proper syntax
|
||||
assert search_repository._prepare_search_term("+++invalid+++") == '"+++invalid+++"*'
|
||||
assert search_repository._prepare_search_term("!!!error!!!") == '"!!!error!!!"*'
|
||||
assert search_repository._prepare_search_term("@#$%^&*()") == '"@#$%^&*()"*'
|
||||
|
||||
def test_quoted_strings_handled_properly(self, search_repository):
|
||||
"""Strings with quotes should have quotes escaped."""
|
||||
assert search_repository._prepare_search_term('say "hello"') == '"say ""hello"""*'
|
||||
assert search_repository._prepare_search_term("it's working") == '"it\'s working"*'
|
||||
|
||||
def test_file_paths_no_prefix_wildcard(self, search_repository):
|
||||
"""File paths should not get prefix wildcards."""
|
||||
assert (
|
||||
search_repository._prepare_search_term("config.json", is_prefix=False)
|
||||
== '"config.json"'
|
||||
)
|
||||
assert (
|
||||
search_repository._prepare_search_term("docs/readme.md", is_prefix=False)
|
||||
== '"docs/readme.md"'
|
||||
)
|
||||
|
||||
def test_spaces_handled_correctly(self, search_repository):
|
||||
"""Terms with spaces should use boolean AND for word order independence."""
|
||||
assert search_repository._prepare_search_term("hello world") == "hello* AND world*"
|
||||
assert (
|
||||
search_repository._prepare_search_term("project planning") == "project* AND planning*"
|
||||
)
|
||||
|
||||
def test_version_strings_with_dots_handled_correctly(self, search_repository):
|
||||
"""Version strings with dots should be quoted to prevent FTS5 syntax errors."""
|
||||
# This reproduces the bug where "Basic Memory v0.13.0b2" becomes "Basic* AND Memory* AND v0.13.0b2*"
|
||||
# which causes FTS5 syntax errors because v0.13.0b2* is not valid FTS5 syntax
|
||||
result = search_repository._prepare_search_term("Basic Memory v0.13.0b2")
|
||||
# Should be quoted because of dots in v0.13.0b2
|
||||
assert result == '"Basic Memory v0.13.0b2"*'
|
||||
|
||||
def test_mixed_special_characters_in_multi_word_queries(self, search_repository):
|
||||
"""Multi-word queries with special characters in any word should be fully quoted."""
|
||||
# Any word containing special characters should cause the entire phrase to be quoted
|
||||
assert search_repository._prepare_search_term("config.json file") == '"config.json file"*'
|
||||
assert (
|
||||
search_repository._prepare_search_term("user@email.com account")
|
||||
== '"user@email.com account"*'
|
||||
)
|
||||
assert search_repository._prepare_search_term("node.js and react") == '"node.js and react"*'
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_with_special_characters_returns_results(self, search_repository):
|
||||
"""Integration test: search with special characters should work gracefully."""
|
||||
# This test ensures the search doesn't crash with FTS5 syntax errors
|
||||
|
||||
# These should all return empty results gracefully, not crash
|
||||
results1 = await search_repository.search(search_text="C++")
|
||||
assert isinstance(results1, list) # Should not crash
|
||||
|
||||
results2 = await search_repository.search(search_text="function()")
|
||||
assert isinstance(results2, list) # Should not crash
|
||||
|
||||
results3 = await search_repository.search(search_text="+++malformed+++")
|
||||
assert isinstance(results3, list) # Should not crash, return empty results
|
||||
|
||||
results4 = await search_repository.search(search_text="email@domain.com")
|
||||
assert isinstance(results4, list) # Should not crash
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_boolean_search_still_works(self, search_repository):
|
||||
"""Boolean search operations should continue to work."""
|
||||
# These should not crash and should respect boolean logic
|
||||
results1 = await search_repository.search(search_text="hello AND world")
|
||||
assert isinstance(results1, list)
|
||||
|
||||
results2 = await search_repository.search(search_text="cat OR dog")
|
||||
assert isinstance(results2, list)
|
||||
|
||||
results3 = await search_repository.search(search_text="project NOT meeting")
|
||||
assert isinstance(results3, list)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_permalink_match_exact_with_slash(self, search_repository):
|
||||
"""Test exact permalink matching with slash (line 249 coverage)."""
|
||||
# This tests the exact match path: if "/" in permalink_text:
|
||||
results = await search_repository.search(permalink_match="test/path")
|
||||
assert isinstance(results, list)
|
||||
# Should use exact equality matching for paths with slashes
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_permalink_match_simple_term(self, search_repository):
|
||||
"""Test permalink matching with simple term (no slash)."""
|
||||
# This tests the simple term path that goes through _prepare_search_term
|
||||
results = await search_repository.search(permalink_match="simpleterm")
|
||||
assert isinstance(results, list)
|
||||
# Should use FTS5 MATCH for simple terms
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fts5_error_handling_database_error(self, search_repository):
|
||||
"""Test that non-FTS5 database errors are properly re-raised."""
|
||||
import unittest.mock
|
||||
|
||||
# Mock the scoped_session to raise a non-FTS5 error
|
||||
with unittest.mock.patch("basic_memory.db.scoped_session") as mock_scoped_session:
|
||||
mock_session = unittest.mock.AsyncMock()
|
||||
mock_scoped_session.return_value.__aenter__.return_value = mock_session
|
||||
|
||||
# Simulate a database error that's NOT an FTS5 syntax error
|
||||
mock_session.execute.side_effect = Exception("Database connection failed")
|
||||
|
||||
# This should re-raise the exception (not return empty list)
|
||||
with pytest.raises(Exception, match="Database connection failed"):
|
||||
await search_repository.search(search_text="test")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_version_string_search_integration(self, search_repository, search_entity):
|
||||
"""Integration test: searching for version strings should work without FTS5 errors."""
|
||||
# Index an entity with version information
|
||||
search_row = SearchIndexRow(
|
||||
id=search_entity.id,
|
||||
type=SearchItemType.ENTITY.value,
|
||||
title="Basic Memory v0.13.0b2 Release",
|
||||
content_stems="basic memory version 0.13.0b2 beta release notes features",
|
||||
content_snippet="Basic Memory v0.13.0b2 is a beta release with new features",
|
||||
permalink=search_entity.permalink,
|
||||
file_path=search_entity.file_path,
|
||||
entity_id=search_entity.id,
|
||||
metadata={"entity_type": search_entity.entity_type},
|
||||
created_at=search_entity.created_at,
|
||||
updated_at=search_entity.updated_at,
|
||||
project_id=search_repository.project_id,
|
||||
)
|
||||
|
||||
await search_repository.index_item(search_row)
|
||||
|
||||
# This should not cause FTS5 syntax errors and should find the entity
|
||||
results = await search_repository.search(search_text="Basic Memory v0.13.0b2")
|
||||
assert len(results) == 1
|
||||
assert results[0].title == "Basic Memory v0.13.0b2 Release"
|
||||
|
||||
# Test other version-like patterns
|
||||
results2 = await search_repository.search(search_text="v0.13.0b2")
|
||||
assert len(results2) == 1 # Should still find it due to content_stems
|
||||
|
||||
# Test with other problematic patterns
|
||||
results3 = await search_repository.search(search_text="node.js version")
|
||||
assert isinstance(results3, list) # Should not crash
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wildcard_only_search(self, search_repository, search_entity):
|
||||
"""Test that wildcard-only search '*' doesn't cause FTS5 errors (line 243 coverage)."""
|
||||
# Index an entity for testing
|
||||
search_row = SearchIndexRow(
|
||||
id=search_entity.id,
|
||||
type=SearchItemType.ENTITY.value,
|
||||
title="Test Entity",
|
||||
content_stems="test entity content",
|
||||
content_snippet="This is a test entity",
|
||||
permalink=search_entity.permalink,
|
||||
file_path=search_entity.file_path,
|
||||
entity_id=search_entity.id,
|
||||
metadata={"entity_type": search_entity.entity_type},
|
||||
created_at=search_entity.created_at,
|
||||
updated_at=search_entity.updated_at,
|
||||
project_id=search_repository.project_id,
|
||||
)
|
||||
|
||||
await search_repository.index_item(search_row)
|
||||
|
||||
# Test wildcard-only search - should not crash and should return results
|
||||
results = await search_repository.search(search_text="*")
|
||||
assert isinstance(results, list) # Should not crash
|
||||
assert len(results) >= 1 # Should return all results, including our test entity
|
||||
|
||||
# Test empty string search - should also not crash
|
||||
results_empty = await search_repository.search(search_text="")
|
||||
assert isinstance(results_empty, list) # Should not crash
|
||||
|
||||
# Test whitespace-only search
|
||||
results_whitespace = await search_repository.search(search_text=" ")
|
||||
assert isinstance(results_whitespace, list) # Should not crash
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
"""Tests for memory URL validation functionality."""
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from basic_memory.schemas.memory import (
|
||||
normalize_memory_url,
|
||||
validate_memory_url_path,
|
||||
memory_url,
|
||||
)
|
||||
|
||||
|
||||
class TestValidateMemoryUrlPath:
|
||||
"""Test the validate_memory_url_path function."""
|
||||
|
||||
def test_valid_paths(self):
|
||||
"""Test that valid paths pass validation."""
|
||||
valid_paths = [
|
||||
"notes/meeting",
|
||||
"projects/basic-memory",
|
||||
"research/findings-2025",
|
||||
"specs/search",
|
||||
"docs/api-spec",
|
||||
"folder/subfolder/note",
|
||||
"single-note",
|
||||
"notes/with-hyphens",
|
||||
"notes/with_underscores",
|
||||
"notes/with123numbers",
|
||||
"pattern/*", # Wildcard pattern matching
|
||||
"deep/*/pattern",
|
||||
]
|
||||
|
||||
for path in valid_paths:
|
||||
assert validate_memory_url_path(path), f"Path '{path}' should be valid"
|
||||
|
||||
def test_invalid_empty_paths(self):
|
||||
"""Test that empty/whitespace paths fail validation."""
|
||||
invalid_paths = [
|
||||
"",
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
" \n ",
|
||||
]
|
||||
|
||||
for path in invalid_paths:
|
||||
assert not validate_memory_url_path(path), f"Path '{path}' should be invalid"
|
||||
|
||||
def test_invalid_double_slashes(self):
|
||||
"""Test that paths with double slashes fail validation."""
|
||||
invalid_paths = [
|
||||
"notes//meeting",
|
||||
"//root",
|
||||
"folder//subfolder/note",
|
||||
"path//with//multiple//doubles",
|
||||
"memory//test",
|
||||
]
|
||||
|
||||
for path in invalid_paths:
|
||||
assert not validate_memory_url_path(path), (
|
||||
f"Path '{path}' should be invalid (double slashes)"
|
||||
)
|
||||
|
||||
def test_invalid_protocol_schemes(self):
|
||||
"""Test that paths with protocol schemes fail validation."""
|
||||
invalid_paths = [
|
||||
"http://example.com",
|
||||
"https://example.com/path",
|
||||
"file://local/path",
|
||||
"ftp://server.com",
|
||||
"invalid://test",
|
||||
"custom://scheme",
|
||||
]
|
||||
|
||||
for path in invalid_paths:
|
||||
assert not validate_memory_url_path(path), (
|
||||
f"Path '{path}' should be invalid (protocol scheme)"
|
||||
)
|
||||
|
||||
def test_invalid_characters(self):
|
||||
"""Test that paths with invalid characters fail validation."""
|
||||
invalid_paths = [
|
||||
"notes<with>brackets",
|
||||
'notes"with"quotes',
|
||||
"notes|with|pipes",
|
||||
"notes?with?questions",
|
||||
]
|
||||
|
||||
for path in invalid_paths:
|
||||
assert not validate_memory_url_path(path), (
|
||||
f"Path '{path}' should be invalid (invalid chars)"
|
||||
)
|
||||
|
||||
|
||||
class TestNormalizeMemoryUrl:
|
||||
"""Test the normalize_memory_url function."""
|
||||
|
||||
def test_valid_normalization(self):
|
||||
"""Test that valid URLs are properly normalized."""
|
||||
test_cases = [
|
||||
("specs/search", "memory://specs/search"),
|
||||
("memory://specs/search", "memory://specs/search"),
|
||||
("notes/meeting-2025", "memory://notes/meeting-2025"),
|
||||
("memory://notes/meeting-2025", "memory://notes/meeting-2025"),
|
||||
("pattern/*", "memory://pattern/*"),
|
||||
("memory://pattern/*", "memory://pattern/*"),
|
||||
]
|
||||
|
||||
for input_url, expected in test_cases:
|
||||
result = normalize_memory_url(input_url)
|
||||
assert result == expected, (
|
||||
f"normalize_memory_url('{input_url}') should return '{expected}', got '{result}'"
|
||||
)
|
||||
|
||||
def test_empty_url(self):
|
||||
"""Test that empty URLs return empty string."""
|
||||
assert normalize_memory_url(None) == ""
|
||||
assert normalize_memory_url("") == ""
|
||||
|
||||
def test_invalid_double_slashes(self):
|
||||
"""Test that URLs with double slashes raise ValueError."""
|
||||
invalid_urls = [
|
||||
"memory//test",
|
||||
"notes//meeting",
|
||||
"//root",
|
||||
"memory://path//with//doubles",
|
||||
]
|
||||
|
||||
for url in invalid_urls:
|
||||
with pytest.raises(ValueError, match="contains double slashes"):
|
||||
normalize_memory_url(url)
|
||||
|
||||
def test_invalid_protocol_schemes(self):
|
||||
"""Test that URLs with other protocol schemes raise ValueError."""
|
||||
invalid_urls = [
|
||||
"http://example.com",
|
||||
"https://example.com/path",
|
||||
"file://local/path",
|
||||
"invalid://test",
|
||||
]
|
||||
|
||||
for url in invalid_urls:
|
||||
with pytest.raises(ValueError, match="contains protocol scheme"):
|
||||
normalize_memory_url(url)
|
||||
|
||||
def test_whitespace_only(self):
|
||||
"""Test that whitespace-only URLs raise ValueError."""
|
||||
invalid_urls = [
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
" \n ",
|
||||
]
|
||||
|
||||
for url in invalid_urls:
|
||||
with pytest.raises(ValueError, match="cannot be empty or whitespace"):
|
||||
normalize_memory_url(url)
|
||||
|
||||
def test_invalid_characters(self):
|
||||
"""Test that URLs with invalid characters raise ValueError."""
|
||||
invalid_urls = [
|
||||
"notes<brackets>",
|
||||
'notes"quotes"',
|
||||
"notes|pipes|",
|
||||
"notes?questions?",
|
||||
]
|
||||
|
||||
for url in invalid_urls:
|
||||
with pytest.raises(ValueError, match="contains invalid characters"):
|
||||
normalize_memory_url(url)
|
||||
|
||||
|
||||
class TestMemoryUrlPydanticValidation:
|
||||
"""Test the MemoryUrl Pydantic type validation."""
|
||||
|
||||
def test_valid_urls_pass_validation(self):
|
||||
"""Test that valid URLs pass Pydantic validation."""
|
||||
valid_urls = [
|
||||
"specs/search",
|
||||
"memory://specs/search",
|
||||
"notes/meeting-2025",
|
||||
"projects/basic-memory/docs",
|
||||
"pattern/*",
|
||||
]
|
||||
|
||||
for url in valid_urls:
|
||||
# Should not raise an exception
|
||||
result = memory_url.validate_python(url)
|
||||
assert result.startswith("memory://"), (
|
||||
f"Validated URL should start with memory://, got {result}"
|
||||
)
|
||||
|
||||
def test_invalid_urls_fail_validation(self):
|
||||
"""Test that invalid URLs fail Pydantic validation with clear errors."""
|
||||
invalid_test_cases = [
|
||||
("memory//test", "double slashes"),
|
||||
("invalid://test", "protocol scheme"),
|
||||
(" ", "empty or whitespace"),
|
||||
("notes<brackets>", "invalid characters"),
|
||||
]
|
||||
|
||||
for url, expected_error in invalid_test_cases:
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
memory_url.validate_python(url)
|
||||
|
||||
error_msg = str(exc_info.value)
|
||||
assert "value_error" in error_msg, f"Should be a value_error for '{url}'"
|
||||
|
||||
def test_empty_string_fails_minlength(self):
|
||||
"""Test that empty strings fail MinLen validation."""
|
||||
with pytest.raises(ValidationError, match="at least 1"):
|
||||
memory_url.validate_python("")
|
||||
|
||||
def test_very_long_urls_fail_maxlength(self):
|
||||
"""Test that very long URLs fail MaxLen validation."""
|
||||
long_url = "a" * 3000 # Exceeds MaxLen(2028)
|
||||
with pytest.raises(ValidationError, match="at most 2028"):
|
||||
memory_url.validate_python(long_url)
|
||||
|
||||
def test_whitespace_stripped(self):
|
||||
"""Test that whitespace is properly stripped."""
|
||||
urls_with_whitespace = [
|
||||
" specs/search ",
|
||||
"\tprojects/basic-memory\t",
|
||||
"\nnotes/meeting\n",
|
||||
]
|
||||
|
||||
for url in urls_with_whitespace:
|
||||
result = memory_url.validate_python(url)
|
||||
assert not result.startswith(" ") and not result.endswith(" "), (
|
||||
f"Whitespace should be stripped from '{url}'"
|
||||
)
|
||||
assert "memory://" in result, "Result should contain memory:// prefix"
|
||||
|
||||
|
||||
class TestMemoryUrlErrorMessages:
|
||||
"""Test that error messages are clear and helpful."""
|
||||
|
||||
def test_double_slash_error_message(self):
|
||||
"""Test specific error message for double slashes."""
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
normalize_memory_url("memory//test")
|
||||
|
||||
error_msg = str(exc_info.value)
|
||||
assert "memory//test" in error_msg
|
||||
assert "double slashes" in error_msg
|
||||
|
||||
def test_protocol_scheme_error_message(self):
|
||||
"""Test specific error message for protocol schemes."""
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
normalize_memory_url("http://example.com")
|
||||
|
||||
error_msg = str(exc_info.value)
|
||||
assert "http://example.com" in error_msg
|
||||
assert "protocol scheme" in error_msg
|
||||
|
||||
def test_empty_error_message(self):
|
||||
"""Test specific error message for empty paths."""
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
normalize_memory_url(" ")
|
||||
|
||||
error_msg = str(exc_info.value)
|
||||
assert "empty or whitespace" in error_msg
|
||||
|
||||
def test_invalid_characters_error_message(self):
|
||||
"""Test specific error message for invalid characters."""
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
normalize_memory_url("notes<brackets>")
|
||||
|
||||
error_msg = str(exc_info.value)
|
||||
assert "notes<brackets>" in error_msg
|
||||
assert "invalid characters" in error_msg
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Tests for Pydantic schema validation and conversion."""
|
||||
|
||||
import pytest
|
||||
from datetime import datetime, time, timedelta
|
||||
from pydantic import ValidationError, BaseModel
|
||||
|
||||
from basic_memory.schemas import (
|
||||
@@ -12,7 +13,7 @@ from basic_memory.schemas import (
|
||||
RelationResponse,
|
||||
)
|
||||
from basic_memory.schemas.request import EditEntityRequest
|
||||
from basic_memory.schemas.base import to_snake_case, TimeFrame
|
||||
from basic_memory.schemas.base import to_snake_case, TimeFrame, parse_timeframe, validate_timeframe
|
||||
|
||||
|
||||
def test_entity_project_name():
|
||||
@@ -277,3 +278,150 @@ def test_edit_entity_request_replace_section_empty_section():
|
||||
"section": "", # Empty string triggers validation
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# New tests for timeframe parsing functions
|
||||
class TestTimeframeParsing:
|
||||
"""Test cases for parse_timeframe() and validate_timeframe() functions."""
|
||||
|
||||
def test_parse_timeframe_today(self):
|
||||
"""Test that parse_timeframe('today') returns start of current day."""
|
||||
result = parse_timeframe("today")
|
||||
expected = datetime.combine(datetime.now().date(), time.min)
|
||||
|
||||
assert result == expected
|
||||
assert result.hour == 0
|
||||
assert result.minute == 0
|
||||
assert result.second == 0
|
||||
assert result.microsecond == 0
|
||||
|
||||
def test_parse_timeframe_today_case_insensitive(self):
|
||||
"""Test that parse_timeframe handles 'today' case-insensitively."""
|
||||
test_cases = ["today", "TODAY", "Today", "ToDay"]
|
||||
expected = datetime.combine(datetime.now().date(), time.min)
|
||||
|
||||
for case in test_cases:
|
||||
result = parse_timeframe(case)
|
||||
assert result == expected
|
||||
|
||||
def test_parse_timeframe_other_formats(self):
|
||||
"""Test that parse_timeframe works with other dateparser formats."""
|
||||
now = datetime.now()
|
||||
|
||||
# Test 1d ago - should be approximately 24 hours ago
|
||||
result_1d = parse_timeframe("1d")
|
||||
expected_1d = now - timedelta(days=1)
|
||||
diff = abs((result_1d - expected_1d).total_seconds())
|
||||
assert diff < 60 # Within 1 minute tolerance
|
||||
|
||||
# Test yesterday - should be yesterday at same time
|
||||
result_yesterday = parse_timeframe("yesterday")
|
||||
# dateparser returns yesterday at current time, not start of yesterday
|
||||
assert result_yesterday.date() == (now.date() - timedelta(days=1))
|
||||
|
||||
# Test 1 week ago
|
||||
result_week = parse_timeframe("1 week ago")
|
||||
expected_week = now - timedelta(weeks=1)
|
||||
diff = abs((result_week - expected_week).total_seconds())
|
||||
assert diff < 3600 # Within 1 hour tolerance
|
||||
|
||||
def test_parse_timeframe_invalid(self):
|
||||
"""Test that parse_timeframe raises ValueError for invalid input."""
|
||||
with pytest.raises(ValueError, match="Could not parse timeframe: invalid-timeframe"):
|
||||
parse_timeframe("invalid-timeframe")
|
||||
|
||||
with pytest.raises(ValueError, match="Could not parse timeframe: not-a-date"):
|
||||
parse_timeframe("not-a-date")
|
||||
|
||||
def test_validate_timeframe_preserves_special_cases(self):
|
||||
"""Test that validate_timeframe preserves special timeframe strings."""
|
||||
# Should preserve 'today' as-is
|
||||
result = validate_timeframe("today")
|
||||
assert result == "today"
|
||||
|
||||
# Should preserve case-normalized version
|
||||
result = validate_timeframe("TODAY")
|
||||
assert result == "today"
|
||||
|
||||
result = validate_timeframe("Today")
|
||||
assert result == "today"
|
||||
|
||||
def test_validate_timeframe_converts_regular_formats(self):
|
||||
"""Test that validate_timeframe converts regular formats to duration."""
|
||||
# Test 1d format (should return as-is since it's already in standard format)
|
||||
result = validate_timeframe("1d")
|
||||
assert result == "1d"
|
||||
|
||||
# Test other formats get converted to days
|
||||
result = validate_timeframe("yesterday")
|
||||
assert result == "1d" # Yesterday is 1 day ago
|
||||
|
||||
# Test week format
|
||||
result = validate_timeframe("1 week ago")
|
||||
assert result == "7d" # 1 week = 7 days
|
||||
|
||||
def test_validate_timeframe_error_cases(self):
|
||||
"""Test that validate_timeframe raises appropriate errors."""
|
||||
# Invalid type
|
||||
with pytest.raises(ValueError, match="Timeframe must be a string"):
|
||||
validate_timeframe(123) # type: ignore
|
||||
|
||||
# Future timeframe
|
||||
with pytest.raises(ValueError, match="Timeframe cannot be in the future"):
|
||||
validate_timeframe("tomorrow")
|
||||
|
||||
# Too far in past (>365 days)
|
||||
with pytest.raises(ValueError, match="Timeframe should be <= 1 year"):
|
||||
validate_timeframe("2 years ago")
|
||||
|
||||
# Invalid format that can't be parsed
|
||||
with pytest.raises(ValueError, match="Could not parse timeframe"):
|
||||
validate_timeframe("not-a-real-timeframe")
|
||||
|
||||
def test_timeframe_annotation_with_today(self):
|
||||
"""Test that TimeFrame annotation works correctly with 'today'."""
|
||||
|
||||
class TestModel(BaseModel):
|
||||
timeframe: TimeFrame
|
||||
|
||||
# Should preserve 'today'
|
||||
model = TestModel(timeframe="today")
|
||||
assert model.timeframe == "today"
|
||||
|
||||
# Should work with other formats
|
||||
model = TestModel(timeframe="1d")
|
||||
assert model.timeframe == "1d"
|
||||
|
||||
model = TestModel(timeframe="yesterday")
|
||||
assert model.timeframe == "1d"
|
||||
|
||||
def test_timeframe_integration_today_vs_1d(self):
|
||||
"""Test the specific bug fix: 'today' vs '1d' behavior."""
|
||||
|
||||
class TestModel(BaseModel):
|
||||
timeframe: TimeFrame
|
||||
|
||||
# 'today' should be preserved
|
||||
today_model = TestModel(timeframe="today")
|
||||
assert today_model.timeframe == "today"
|
||||
|
||||
# '1d' should also be preserved (it's already in standard format)
|
||||
oneday_model = TestModel(timeframe="1d")
|
||||
assert oneday_model.timeframe == "1d"
|
||||
|
||||
# When parsed by parse_timeframe, they should be different
|
||||
today_parsed = parse_timeframe("today")
|
||||
oneday_parsed = parse_timeframe("1d")
|
||||
|
||||
# 'today' should be start of today (00:00:00)
|
||||
assert today_parsed.hour == 0
|
||||
assert today_parsed.minute == 0
|
||||
|
||||
# '1d' should be 24 hours ago (same time yesterday)
|
||||
now = datetime.now()
|
||||
expected_1d = now - timedelta(days=1)
|
||||
diff = abs((oneday_parsed - expected_1d).total_seconds())
|
||||
assert diff < 60 # Within 1 minute
|
||||
|
||||
# They should be different times
|
||||
assert today_parsed != oneday_parsed
|
||||
|
||||
@@ -869,6 +869,119 @@ async def test_edit_entity_with_observations_and_relations(
|
||||
assert new_rel.relation_type == "relates to"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_entity_from_markdown_race_condition_handling(
|
||||
entity_service: EntityService, file_service: FileService
|
||||
):
|
||||
"""Test that create_entity_from_markdown handles race condition with IntegrityError (lines 304-311)."""
|
||||
from unittest.mock import patch
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
file_path = Path("test/race-condition.md")
|
||||
|
||||
# Create a mock EntityMarkdown object
|
||||
from basic_memory.markdown.schemas import (
|
||||
EntityFrontmatter,
|
||||
EntityMarkdown as RealEntityMarkdown,
|
||||
)
|
||||
from datetime import datetime, timezone
|
||||
|
||||
frontmatter = EntityFrontmatter(metadata={"title": "Race Condition Test", "type": "test"})
|
||||
markdown = RealEntityMarkdown(
|
||||
frontmatter=frontmatter,
|
||||
observations=[],
|
||||
relations=[],
|
||||
created=datetime.now(timezone.utc),
|
||||
modified=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
# Mock the repository.add to raise IntegrityError on first call, then succeed on second
|
||||
original_add = entity_service.repository.add
|
||||
|
||||
call_count = 0
|
||||
|
||||
async def mock_add(*args, **kwargs):
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
if call_count == 1:
|
||||
# Simulate race condition - another process created the entity
|
||||
raise IntegrityError("UNIQUE constraint failed: entity.file_path", None, None)
|
||||
else:
|
||||
return await original_add(*args, **kwargs)
|
||||
|
||||
# Mock update method to return a dummy entity
|
||||
async def mock_update(*args, **kwargs):
|
||||
from basic_memory.models import Entity
|
||||
from datetime import datetime, timezone
|
||||
|
||||
return Entity(
|
||||
id=1,
|
||||
title="Race Condition Test",
|
||||
entity_type="test",
|
||||
file_path=str(file_path),
|
||||
permalink="test/race-condition-test",
|
||||
content_type="text/markdown",
|
||||
created_at=datetime.now(timezone.utc),
|
||||
updated_at=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
with (
|
||||
patch.object(entity_service.repository, "add", side_effect=mock_add),
|
||||
patch.object(
|
||||
entity_service, "update_entity_and_observations", side_effect=mock_update
|
||||
) as mock_update_call,
|
||||
):
|
||||
# Call the method
|
||||
result = await entity_service.create_entity_from_markdown(file_path, markdown)
|
||||
|
||||
# Verify it handled the race condition gracefully
|
||||
assert result is not None
|
||||
assert result.title == "Race Condition Test"
|
||||
assert result.file_path == str(file_path)
|
||||
|
||||
# Verify that update_entity_and_observations was called as fallback
|
||||
mock_update_call.assert_called_once_with(file_path, markdown)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_entity_from_markdown_integrity_error_reraise(
|
||||
entity_service: EntityService, file_service: FileService
|
||||
):
|
||||
"""Test that create_entity_from_markdown re-raises IntegrityError for non-race-condition cases."""
|
||||
from unittest.mock import patch
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
file_path = Path("test/integrity-error.md")
|
||||
|
||||
# Create a mock EntityMarkdown object
|
||||
from basic_memory.markdown.schemas import (
|
||||
EntityFrontmatter,
|
||||
EntityMarkdown as RealEntityMarkdown,
|
||||
)
|
||||
from datetime import datetime, timezone
|
||||
|
||||
frontmatter = EntityFrontmatter(metadata={"title": "Integrity Error Test", "type": "test"})
|
||||
markdown = RealEntityMarkdown(
|
||||
frontmatter=frontmatter,
|
||||
observations=[],
|
||||
relations=[],
|
||||
created=datetime.now(timezone.utc),
|
||||
modified=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
# Mock the repository.add to raise a different IntegrityError (not file_path/permalink constraint)
|
||||
async def mock_add(*args, **kwargs):
|
||||
# Simulate a different constraint violation
|
||||
raise IntegrityError("UNIQUE constraint failed: entity.some_other_field", None, None)
|
||||
|
||||
with patch.object(entity_service.repository, "add", side_effect=mock_add):
|
||||
# Should re-raise the IntegrityError since it's not a file_path/permalink constraint
|
||||
with pytest.raises(
|
||||
IntegrityError, match="UNIQUE constraint failed: entity.some_other_field"
|
||||
):
|
||||
await entity_service.create_entity_from_markdown(file_path, markdown)
|
||||
|
||||
|
||||
# Edge case tests for find_replace operation
|
||||
@pytest.mark.asyncio
|
||||
async def test_edit_entity_find_replace_not_found(entity_service: EntityService):
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user