From 17df3b225e349b2aa8a9bf07e4a0752ab09a372d Mon Sep 17 00:00:00 2001 From: phernandez Date: Fri, 4 Dec 2026 16:33:02 -0600 Subject: [PATCH 1/2] fix(mcp): give a note moved across projects a permalink for its new path A cross-project move copied the note's markdown verbatim, frontmatter permalink included. The copy kept the source project's permalink, which resolved in neither project: the source no longer had the note, and the destination refused a memory:// URL naming another project. The note was reachable only by file path. The copy now drops the frontmatter permalink before it is written, so the destination assigns one for the note's new path, as it does for any new note. Only the frontmatter is rewritten; the body keeps its exact bytes. Docs: bm-move(3), the bm_move description and the changelog say the moved note gets a new permalink. A new skills(7) page and the changelog document `bm project skills `, which note skills need: serving them is off by default. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CMYVKz9DguvH7PfmUPwps2 Signed-off-by: phernandez --- CHANGELOG.md | 10 ++- src/basic_memory/man/man3/bm-move(3).md | 5 +- src/basic_memory/man/man7/skills(7).md | 90 +++++++++++++++++++ src/basic_memory/mcp/cross_project_move.py | 39 +++++++- src/basic_memory/mcp/tools/move.py | 4 +- .../mcp/test_tool_bm_move_across_projects.py | 53 ++++++++++- 6 files changed, 189 insertions(+), 12 deletions(-) create mode 100644 src/basic_memory/man/man7/skills(7).md diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f73ea1d0..25266e06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,8 +58,9 @@ installs only patch releases; minor and major releases are announced with - **Move notes and folders between projects.** `bm_move(..., destination_project="research")` moves a note or a directory into another project. - The moved note is new in the target, with a new id and its own history; links are - not rewritten, and a note already at the destination is never replaced (#1842, + The moved note is new in the target, with a new id, a permalink for its new path + and its own history; its old permalink does not follow it, links are not + rewritten, and a note already at the destination is never replaced (#1842, #2048). - **Skills over MCP.** The server serves the bundled `memory-*` skills as @@ -87,7 +88,10 @@ installs only patch releases; minor and major releases are announced with - **Notes as MCP skills.** A note with `type: skill` and Agent Skills `name` and `description` frontmatter is served as `skill:////SKILL.md`, next to - the bundled skills (#2139). + the bundled skills (#2139). Serving is off by default, since any agent that can + write a note could write a skill: turn it on per project with + `bm project skills ` (`--off` to stop). The new `skills(7)` manual page + covers both kinds of skill. - **A person in the web app can unlock a locked note.** `locked: true` still stops agents from changing or unlocking a note; a host-verified person can remove the diff --git a/src/basic_memory/man/man3/bm-move(3).md b/src/basic_memory/man/man3/bm-move(3).md index 320816c07..8bf078486 100644 --- a/src/basic_memory/man/man3/bm-move(3).md +++ b/src/basic_memory/man/man3/bm-move(3).md @@ -39,8 +39,9 @@ revision you read. `destination_project` moves into another project; `destination` is then a path in that project. The note is written there and then deleted here, so it is a -new note: it gets a new id and its own version history, and links in either -project are not rewritten. The original is deleted only after the copy is +new note: it gets a new id, a permalink for its new path, and its own version +history. Its old permalink and `memory://` URL do not follow it, and links in +either project are not rewritten. The original is deleted only after the copy is written, and only if it is still the revision that was copied; if that delete is refused, the copy is removed again and nothing has moved. A note already at the destination is never replaced, and a locked note is refused. A directory diff --git a/src/basic_memory/man/man7/skills(7).md b/src/basic_memory/man/man7/skills(7).md new file mode 100644 index 000000000..8ac6b2bab --- /dev/null +++ b/src/basic_memory/man/man7/skills(7).md @@ -0,0 +1,90 @@ +--- +title: skills(7) +type: manpage +section: 7 +name: skills +summary: Basic Memory skills over MCP - the bundled memory-* skills, and serving your own notes as skills with bm project skills +generated: hand +--- + +# skills(7) + +## NAME + +**skills**: the skills a Basic Memory MCP server serves, and how to serve your own notes as skills + +## DESCRIPTION + +A skill is a `SKILL.md` file of instructions an assistant loads when a task +calls for it. The Basic Memory MCP server serves skills as resources, and +supports the MCP skills extension (SEP-2640), so a client that supports it can +list and load them. + +There are two kinds: + +- **Bundled skills** ship with Basic Memory, such as `memory-notes`, + `memory-capture` and `memory-start`. Each is served as + `skill:///SKILL.md`, with its reference files beside it. They are always + on. +- **Note skills** are notes in your own projects. They are off until you turn + them on for a project. + +## NOTE SKILLS + +A note becomes a skill when its frontmatter has `type: skill` and the Agent +Skills `name` and `description` fields: + +``` +--- +title: Weekly Review +type: skill +name: weekly-review +description: Run a weekly review of open tasks and decisions in this project. +--- + +# Weekly Review + +1. Search for notes tagged #task updated this week. +2. Summarize the decisions. +``` + +Turn note skills on for one project in a shell: + +``` +bm project skills research +``` + +The project's skill notes are then served as +`skill:////SKILL.md`, for example +`skill://research/weekly-review/SKILL.md`. The note's markdown is the skill, +byte for byte. Edits show up on the next request. Clients that cache the skill +list need a restart to see a new skill. + +Turn them off again with: + +``` +bm project skills research --off +``` + +## WHY IT IS OFF BY DEFAULT + +Any agent that can write a note in a project can write a skill note, and other +agents follow skills as instructions. Serving a project's notes as skills is +the user's decision, not the note author's. Turn it on only for projects whose +notes you trust as instructions. + +## GOTCHAS + +- A note with `type: skill` but no `name` or `description`, or with frontmatter + that does not parse, is not served. The server logs the reason. +- Two notes in one project that declare the same `name` are both left out until + one is renamed. +- Skills from different projects never collide: the project is part of the URI. + A client looking for a skill by purpose matches on its `name`. +- A server pinned to one project (`bm mcp --project`) serves only that project's + skills, and only if it is turned on. + +## SEE ALSO + +- see_also [[setup(7)]] +- see_also [[bm-write(3)]] diff --git a/src/basic_memory/mcp/cross_project_move.py b/src/basic_memory/mcp/cross_project_move.py index 3763679e4..a59333b9d 100644 --- a/src/basic_memory/mcp/cross_project_move.py +++ b/src/basic_memory/mcp/cross_project_move.py @@ -1,8 +1,9 @@ """Moving notes into another project (#1842). A move across projects is a write in the target project followed by a delete in -the source project. The moved note is a new note there: it gets a new id and its -own version history, and links in either project are not rewritten. +the source project. The moved note is a new note there: it gets a new id, a +permalink for its new path, and its own version history. Links in either project +are not rewritten. The source is deleted only after the copy is written, and only while it is still the revision that was copied. If that delete is refused (the note changed, or the @@ -16,6 +17,14 @@ from fastmcp.exceptions import ToolError +from basic_memory.file_utils import ( + ParseError, + build_post, + dump_frontmatter, + has_frontmatter, + parse_frontmatter, + remove_frontmatter, +) from basic_memory.markdown.note_lock import LOCKED_NOTE_MESSAGE, note_is_locked from basic_memory.mcp.clients import DirectoryClient, KnowledgeClient from basic_memory.mcp.note_targets import ProjectTarget, resolve_note @@ -151,7 +160,9 @@ async def _move_one( raise refusal("LOCKED", LOCKED_NOTE_MESSAGE, output_format=output_format) # --- Write the copy --- - copy = await _write_copy(target, destination_path, entity.title, content, output_format) + copy = await _write_copy( + target, destination_path, entity.title, _without_permalink(content), output_format + ) # --- Delete the source --- try: @@ -189,6 +200,28 @@ async def _move_one( return MovedNote(previous_file_path=file_path, file_path=copy.file_path) +def _without_permalink(content: str) -> str: + """The note's markdown without its frontmatter `permalink`, body bytes untouched. + + The permalink names the note's path in the source project, so in the target it + would resolve nowhere. Without one, the target assigns a permalink for the + note's new path, as it does for any new note. + """ + if not has_frontmatter(content): + return content + try: + frontmatter = parse_frontmatter(content) + except ParseError: + # Fences around YAML that does not parse are indexed as body text, so the + # note has no permalink of its own to drop. + return content + if "permalink" not in frontmatter: + return content + del frontmatter["permalink"] + body = remove_frontmatter(content, strip=False) + return dump_frontmatter(build_post(body, frontmatter), body_separator="") + + async def _write_copy( target: ProjectTarget, destination_path: str, diff --git a/src/basic_memory/mcp/tools/move.py b/src/basic_memory/mcp/tools/move.py index 05158c6d9..73a6ebc2e 100644 --- a/src/basic_memory/mcp/tools/move.py +++ b/src/basic_memory/mcp/tools/move.py @@ -42,8 +42,8 @@ "its file extension ('.markdown' may become '.md'). Pass `expected_checksum` (from " "bm_read) to move a note only if it is still the revision you read. " "`destination_project` moves into another project: the note is written there as a " - "new note (new id, its own history, links not rewritten) and deleted here; a " - "directory moves note by note." + "new note (new id and permalink, its own history, links not rewritten) and deleted " + "here; a directory moves note by note." ), tags={"notes", WRITES_TAG}, annotations={ diff --git a/tests/mcp/test_tool_bm_move_across_projects.py b/tests/mcp/test_tool_bm_move_across_projects.py index 20c0ab28a..52e8c6aee 100644 --- a/tests/mcp/test_tool_bm_move_across_projects.py +++ b/tests/mcp/test_tool_bm_move_across_projects.py @@ -11,9 +11,14 @@ from fastapi import FastAPI from fastmcp.exceptions import ToolError +from basic_memory.file_utils import remove_frontmatter from basic_memory.index.local_project import LocalProjectIndexRunner from basic_memory.mcp.clients import KnowledgeClient -from basic_memory.mcp.cross_project_move import _files_under, move_note_across +from basic_memory.mcp.cross_project_move import ( + _files_under, + _without_permalink, + move_note_across, +) from basic_memory.mcp.note_targets import ProjectTarget from basic_memory.mcp.project_context import ProjectPathRoute from basic_memory.mcp.tools import bm_move, bm_read, bm_write @@ -83,6 +88,46 @@ async def test_a_note_moves_into_another_project(client, test_project, second_pr assert await _missing(test_project, "notes/plan.md") +@pytest.mark.asyncio +async def test_a_moved_note_gets_a_permalink_in_the_destination( + client, test_project, second_project +): + body = "\n# Plan\n\n indented, trailing spaces \n\tand a tab\n" + await _write(test_project, "notes/plan.md", f"{NOTE[:-1]}{body}") + source = await _read(test_project, "notes/plan.md") + + await bm_move( + identifier="notes/plan.md", + destination="inbox/plan.md", + destination_project=second_project.name, + project=test_project.name, + ) + + moved = await _read(second_project, "inbox/plan.md") + # The source permalink would resolve in neither project; the destination + # assigns one for the note's new path, and it reaches the note. + assert moved["permalink"] != source["permalink"] + assert moved["frontmatter"]["permalink"] == moved["permalink"] + by_permalink = await _read(second_project, f"memory://{moved['permalink']}") + assert by_permalink["checksum"] == moved["checksum"] + # Dropping the permalink rewrites the frontmatter only; the body keeps its bytes. + assert remove_frontmatter(moved["content"], strip=False) == remove_frontmatter( + source["content"], strip=False + ) + + +@pytest.mark.parametrize( + "content", + [ + "# No frontmatter\n", + "---\ntitle: [unclosed\n---\n# Bad YAML\n", + "---\ntitle: Plan\n---\n# No permalink\n", + ], +) +def test_content_without_a_readable_permalink_is_copied_unchanged(content): + assert _without_permalink(content) == content + + @pytest.mark.asyncio async def test_a_renaming_move_keeps_the_title(client, test_project, second_project): await _write(test_project, "notes/plan.md", NOTE.replace("title: Plan", "title: Launch")) @@ -339,7 +384,11 @@ async def test_a_directory_moves_note_by_note(client, test_project, second_proje assert result["destination"] == "imported/drafts" assert sorted(result["moved_files"]) == ["imported/drafts/a.md", "imported/drafts/deep/b.md"] assert result["failed"] == [] - assert "# B" in (await _read(second_project, "imported/drafts/deep/b.md"))["content"] + moved = await _read(second_project, "imported/drafts/deep/b.md") + assert "# B" in moved["content"] + # Each note gets a permalink in the destination, as a single-note move does. + by_permalink = await _read(second_project, f"memory://{moved['permalink']}") + assert by_permalink["checksum"] == moved["checksum"] assert await _missing(test_project, "drafts/a.md") assert await _missing(test_project, "drafts/deep/b.md") From 9965a77dd679af1361c8cecfe24f70bc0fee492b Mon Sep 17 00:00:00 2001 From: phernandez Date: Sun, 6 Dec 2026 11:19:25 -0600 Subject: [PATCH 2/2] fix(mcp): keep the fences when a moved note's permalink was its only field Dropping the only frontmatter field left an empty mapping, which dumps as the bare body. The target then read a YAML-shaped block at the top of that body as the copy's frontmatter. The copy now keeps its fences with the note's title. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CMYVKz9DguvH7PfmUPwps2 Signed-off-by: phernandez --- src/basic_memory/mcp/cross_project_move.py | 14 +++++++-- .../mcp/test_tool_bm_move_across_projects.py | 29 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/basic_memory/mcp/cross_project_move.py b/src/basic_memory/mcp/cross_project_move.py index a59333b9d..77143e35d 100644 --- a/src/basic_memory/mcp/cross_project_move.py +++ b/src/basic_memory/mcp/cross_project_move.py @@ -161,7 +161,11 @@ async def _move_one( # --- Write the copy --- copy = await _write_copy( - target, destination_path, entity.title, _without_permalink(content), output_format + target, + destination_path, + entity.title, + _without_permalink(content, entity.title), + output_format, ) # --- Delete the source --- @@ -200,7 +204,7 @@ async def _move_one( return MovedNote(previous_file_path=file_path, file_path=copy.file_path) -def _without_permalink(content: str) -> str: +def _without_permalink(content: str, title: str) -> str: """The note's markdown without its frontmatter `permalink`, body bytes untouched. The permalink names the note's path in the source project, so in the target it @@ -218,6 +222,12 @@ def _without_permalink(content: str) -> str: if "permalink" not in frontmatter: return content del frontmatter["permalink"] + # Trigger: the permalink was the note's only frontmatter field. + # Why: an empty mapping dumps as the bare body, and the target would read a + # YAML-shaped block at the top of that body as the copy's frontmatter. + # Outcome: the fences stay, holding the title the target writes there anyway. + if not frontmatter: + frontmatter["title"] = title body = remove_frontmatter(content, strip=False) return dump_frontmatter(build_post(body, frontmatter), body_separator="") diff --git a/tests/mcp/test_tool_bm_move_across_projects.py b/tests/mcp/test_tool_bm_move_across_projects.py index 52e8c6aee..e058bbab3 100644 --- a/tests/mcp/test_tool_bm_move_across_projects.py +++ b/tests/mcp/test_tool_bm_move_across_projects.py @@ -116,6 +116,33 @@ async def test_a_moved_note_gets_a_permalink_in_the_destination( ) +@pytest.mark.asyncio +async def test_a_permalink_only_frontmatter_keeps_its_fences( + client, test_project, second_project, project_repository, session_maker +): + # The body opens with a YAML-shaped block. Without the note's own fences it + # would be read as the copy's frontmatter and leave the body. + body = "\n---\nexample: value\n---\nBody\n" + (Path(test_project.path) / "notes").mkdir() + (Path(test_project.path) / "notes/plan.md").write_text( + f"---\npermalink: notes/plan\n---\n{body}", encoding="utf-8" + ) + await LocalProjectIndexRunner( + project_repository=project_repository, session_maker=session_maker + ).index_project(test_project.id) + + await bm_move( + identifier="notes/plan.md", + destination="inbox/plan.md", + destination_project=second_project.name, + project=test_project.name, + ) + + moved = await _read(second_project, "inbox/plan.md") + assert "example" not in moved["frontmatter"] + assert remove_frontmatter(moved["content"], strip=False) == body + + @pytest.mark.parametrize( "content", [ @@ -125,7 +152,7 @@ async def test_a_moved_note_gets_a_permalink_in_the_destination( ], ) def test_content_without_a_readable_permalink_is_copied_unchanged(content): - assert _without_permalink(content) == content + assert _without_permalink(content, "Plan") == content @pytest.mark.asyncio