Skip to content

feat(mcp): add metadata param to edit_note for frontmatter updates#1090

Open
phernandez wants to merge 1 commit into
mainfrom
claude/issue-1011-20260716-2019
Open

feat(mcp): add metadata param to edit_note for frontmatter updates#1090
phernandez wants to merge 1 commit into
mainfrom
claude/issue-1011-20260716-2019

Conversation

@phernandez

Copy link
Copy Markdown
Member

Implements #1011. Generated by the @claude workflow; opened for review — not yet verified by a human (the run intentionally did not execute the test suite; CI does — see note below).

Summary

Adds an optional metadata: dict param to edit_note that merges into a note's YAML frontmatter independent of operation, so an agent can update structured fields (e.g. status, closed_at) without a fragile find_replace on an exact frontmatter line. Mirrors write_note's existing metadata param.

edit_note(identifier="tickets/...", operation="append", content="",
          metadata={"status": "resolved", "closed_at": "2026-06-18T10:42:00Z"})
  • Merge semantics: set/overwrite provided keys; other frontmatter + the body untouched. Key deletion out of scope for v1.
  • Identity fields (title/type/permalink) are dropped from the merge (they have dedicated resolution paths).
  • Threaded through EditEntityRequest → the accepted-note-mutation pipeline → EntityService.

Review checklist

  • frontmatter merge preserves unrelated keys + body
  • identity-field guard behaves as intended
  • auto-create path (append/prepend on missing note) accepts metadata

Note

This branch was produced without running just/pytest locally — just/uv aren't installed on the Actions runner, and the first run timed out trying to install them. Rely on this PR's CI run for verification. (Follow-up: add a uv/just setup step to claude.yml so future runs can self-verify.)

Closes #1011

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e45ba820a8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/services/entity_service.py Outdated
@phernandez

Copy link
Copy Markdown
Member Author

Local validation

CI didn't auto-run on this branch (bot-token push + test.yml is push-only, so GitHub doesn't fire it). Ran the added/affected tests locally:

uv run pytest test-int/mcp/test_edit_note_integration.py \
  tests/api/v2/test_knowledge_router.py \
  tests/services/test_entity_service_prepare.py \
  tests/indexing/test_accepted_note_mutation_runner.py \
  tests/indexing/test_accepted_note_write_runner.py
→ 143 passed, 1 failed

The one failure is a test-assertion bug, not a feature bug. The metadata merge and the identity-field guard both work — status: resolved was merged, and title/permalink were correctly left untouched. The test just hardcoded the wrong expected permalink (missing the fixture's test-project/ prefix):

  • test_edit_note_metadata_ignores_identity_fields
    assert frontmatter["permalink"] == "tickets/identity-guard-note" → actual test-project/tickets/identity-guard-note

Fix: expect the project-prefixed permalink.

phernandez added a commit that referenced this pull request Jul 16, 2026
Anthropic's OIDC exchange is broken for the pull_request_target event
(401 'Invalid OIDC token'; anthropics/claude-code-action#713). The workflow
invoked that path whenever a PR body contained '@claude' — and bot-authored PR
descriptions carry attribution text ('Generated by the @claude workflow'), so
opening #1088/#1089/#1090/#1091 self-triggered the broken path and each failed
its 'claude' check with a 401. A normal issue_comment run succeeded with the
same secret in between, so the OAuth token is valid and needs no rotation.

Remove the pull_request_target trigger and its PR-body '@claude' clause, so
attribution text can never be read as a command and no event routes into the
broken OIDC path. Explicit '@claude' mentions in issues, issue comments, PR
reviews, and PR review comments remain the trigger. Also drop the now-dead
pull_request.author_association gate clauses (reviewer identity is covered by
sender.author_association) and the pull_request_target-only checkout ref.

If automatic PR-open review is wanted later, it should be a dedicated workflow
with a fixed prompt, not a PR-body mention.

Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86d8093d73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/services/entity_service.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1adec0b040

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/services/entity_service.py Outdated
Rebuilt against main after the note-preparation extraction: the metadata
merge now lives in services/note_preparation.py and threads through the
entity-service wrapper, the accepted-note write/mutation runners, the
EditEntityRequest schema, and the edit_note MCP tool.

Addresses all three review findings:

- Frontmatter-only rewrites no longer reflow the note body. The merge
  extracts the body with the new remove_frontmatter(strip=False) and
  drops exactly one separator newline, so leading blank lines, trailing
  hard-break spaces, and a missing final newline round-trip byte-exact.
- Null metadata values are rejected with a ValueError (surfaced as a
  bad request) instead of silently dropping the field after the
  normalize step filtered the YAML null out of indexed metadata.
- The documented metadata-only pattern (empty append/prepend plus
  metadata) skips the content operation entirely, so it no longer
  appends "\n" to bodies without a trailing newline.

Issue #1011.

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A2bgrGfWiL4izcjj66u9R8
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez force-pushed the claude/issue-1011-20260716-2019 branch from 1adec0b to 74b12a5 Compare July 21, 2026 02:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74b12a55b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


post = frontmatter.Post(body)
post.metadata.update(merged_metadata)
return dump_frontmatter(post)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve separatorless frontmatter bodies

Fresh evidence after the prior body-preservation fix: for notes whose closing frontmatter fence is followed immediately by content, e.g. ---\nstatus: draft\n---\nBody, body is "Body" here but dump_frontmatter() always serializes frontmatter as ---\n\n{post.content}. A metadata-only edit therefore inserts a blank line before the existing body even though the new contract says unrelated frontmatter and the note body are left untouched; preserve whether the original body had that separator instead of always using the canonical dumper output for this path.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add a way to update frontmatter fields via edit_note

1 participant