Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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://<project>/<name>/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 <project>` (`--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
Expand Down
5 changes: 3 additions & 2 deletions src/basic_memory/man/man3/bm-move(3).md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
90 changes: 90 additions & 0 deletions src/basic_memory/man/man7/skills(7).md
Original file line number Diff line number Diff line change
@@ -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://<name>/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://<project>/<name>/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)]]
49 changes: 46 additions & 3 deletions src/basic_memory/mcp/cross_project_move.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -151,7 +160,13 @@ 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, entity.title),
output_format,
)

# --- Delete the source ---
try:
Expand Down Expand Up @@ -189,6 +204,34 @@ async def _move_one(
return MovedNote(previous_file_path=file_path, file_path=copy.file_path)


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
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"]
# 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="")
Comment thread
phernandez marked this conversation as resolved.
Resolved


async def _write_copy(
target: ProjectTarget,
destination_path: str,
Expand Down
4 changes: 2 additions & 2 deletions src/basic_memory/mcp/tools/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
80 changes: 78 additions & 2 deletions tests/mcp/test_tool_bm_move_across_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +88,73 @@ 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.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",
[
"# 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, "Plan") == 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"))
Expand Down Expand Up @@ -339,7 +411,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")

Expand Down
Loading