serena-protocol
MANDATORY skill for Serena (MCP) memory, knowledge base, and symbolic code exploration operations. Use whenever the agent needs to: read or write Serena memories, mutate or persist memory, explore code via symbolic MCP tools, resolve contradictions in stored knowledge, or follow memory metadata, naming, and routing conventions.
- License 许可
- BSD-3-Clause
- 所属仓库
- kalaverin/skills
- 最近更新
- 2026-11-15
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- serena-protocol
- version
- 0.1.1
- requires
- [ "entity-protocol", "frontmatter-protocol", "markdown-protocol" ]
- triggers
- { "always": true, "reason": "Memory, knowledge-base, and symbolic code operations may occur in any session; this skill governs their mandatory rules." }
- description
- MANDATORY skill for Serena (MCP) memory, knowledge base, and symbolic code exploration operations. Use whenever the agent needs to: read or write Serena memories, mutate or persist memory, explore code via symbolic MCP tools, resolve contradictions in stored knowledge, or follow memory metadata, naming, and routing conventions.
02 资源文件 2
- 参考文档README.md4.6 KB
- 参考文档references/rules.md18.9 KB
03 SKILL.md 正文
SKILL: Serena Memory & MCP Protocol
You operate within the Serena MCP ecosystem. The canonical rule set lives in references/rules.md (naming, metadata, lifecycle, contradictions, examples, MCP tools) plus the mutation & persistence protocol in this file (§1).
Ownership boundary: the repo (entity) concept, the SINGLE namespace registry, findings routing/evidence, deprecations, card production, and the repos/ layout live in entity-protocol. Type detection and per-type interface exhaustiveness live in repo-audit. Tracking fields, timestamps, git commands, and refresh-on-mutation live in the frontmatter-protocol tracking extension.
1. Memory Mutation & Persistence Protocol (HARD)
[ref: #serena-memory-mutation]
The single recipe for creating, appending, updating, verifying, and persisting memories. Applies to EVERY memory operation, every session.
Tool semantics:
write_memorycompletely overwrites a file. You MUST NEVER use it to append to an existing memory.edit_memoryedits in place (literalorregexmode). Inregexmode the pattern compiles withre.MULTILINE | re.DOTALL: NEVER use bare.*in needles (it eats the rest of the file — use[^\n]*for single lines), andreplis inserted VERBATIM (\1-style backreferences are NOT expanded).
To CREATE a new memory:
- Call
list_memoriesto ensure the name does not exist. - Call
write_memorywith the complete YAML frontmatter ([ref: #tracking-fields]) and body.
To APPEND to an existing memory: call edit_memory with the following EXACT payload:
{
"mode": "regex",
"needle": "\\Z",
"repl": "\n\n## <New Section>\n<new content>"
}
To UPDATE specific lines: use edit_memory with a highly specific regex targeting only the outdated paragraph/table row, or literal mode with the exact old string.
On EVERY mutation:
- Refresh the header per the tracking extension (
[ref: #tracking-refresh],[ref: #tracking-timestamps]): bumpupdated_at, andbranch/commit/committed_atwhen the git state changed. - Read the memory back and verify it was saved correctly.
- Run the configured persistence command (commonly
just serena-checkpoint) from the workspace root. Do not stop until everything is persisted.
Working directory (HARD): every Serena operation that touches .serena/ — including write_memory, edit_memory, list_memories, delete_memory, rename_memory, and the persistence command — MUST be executed from the workspace root (cd <workspace-root>). Before running the command, verify that the target .serena/ directory is the workspace-root .serena/ and not a nested instance inside a subdirectory. Never run Serena commands from within an entity directory or any other nested project that may contain its own .serena/. Exception: reading source code or collecting raw git metadata inside an entity repository is allowed as long as no Serena memory operation is triggered from there.
Bulk import of external documents (carve-out). Raw external documents (standards, specs — bodies NOT authored by the agent) MAY be imported by the file path instead of write_memory, because piping a large raw body through the agent context is waste. The ONLY sanctioned pipeline: (1) download into a scratch path (e.g. .tmp/) via curl/wget/fetch; (2) mv into the target scope under .serena/memories/; (3) a subagent validates and attests the document (type, completeness, cleanliness) and drafts the frontmatter — on attestation failure, delete the moved file, report to the user, and STOP (if no subagent is available, the main agent attests per subagents-protocol §12); (4) stamp the header with edit_memory (needle \A, repl = frontmatter + synthetic # <Title> line) — the raw body below stays untouched; (5) verify the header via the canonical frontmatter extraction (frontmatter-protocol §6); (6) run the persistence command. write_memory remains mandatory for ALL agent-authored content; this carve-out never covers edits, appends, or agent-written text.
Hard fails:
- HARD FAIL: forgetting the persistence command after writing/editing memories.
- HARD FAIL: executing any Serena memory operation or persistence command from anywhere other than the workspace root when a nested
.serena/could be affected. - HARD FAIL: using
write_memoryto append to an existing memory (it overwrites). - Card-specific hard fails live in
entity-protocol[ref: #entity-card-hard-fails].
2. Lazy-Load Protocol (CRITICAL)
You MUST NOT read references/rules.md in full. Use the Routing Index below to extract only the section you need.
Extraction Execution:
- Match your task to a Trigger in the Routing Index below.
- Note the exact Anchor tag.
- Extract ONLY that section per the canonical loader mechanics in
frontmatter-protocol[ref: #lazy-load-routing](bounded extraction — never a blindrg -A Nwindow; the exact command lives there, not here). - Apply the extracted rules strictly.
3. Mandatory Lookups by Task (The Routing Index)
| Trigger / Situation | Where | Anchor |
|---|---|---|
| Any memory create/append/update/persist — the mutation protocol. | THIS FILE §1 | [ref: #serena-memory-mutation] |
| Overview of Serena memory (location, AGENTS.md relationship, language). | rules.md | [ref: #serena-what-is] |
| Namespaces, scopes, findings routing, when-to-record, meta-entity. | entity-protocol/SKILL.md |
[ref: #entity-namespace-registry] |
| Deciding the filename for a new memory entry; normalizing non-compliant names. | rules.md | [ref: #serena-naming] |
| Checking whether a repo is usable before writing repo-scoped memory. | entity-protocol/SKILL.md |
[ref: #entity-prerequisite] |
| Writing or updating the mandatory metadata header. | rules.md | [ref: #serena-metadata] |
MANDATORY for every memory write/edit: tracking fields, field semantics, timestamps, refresh-on-mutation, git commands; repo value semantics in entity-protocol. |
frontmatter-protocol/references/tracking.md |
[ref: #tracking-fields], [ref: #tracking-field-semantics], [ref: #tracking-timestamps], [ref: #tracking-refresh], [ref: #tracking-git-commands]; [ref: #entity-repo-field] |
| Checking freshness of a tracked memory; reconciling a stale one. | frontmatter-protocol/references/tracking.md |
[ref: #tracking-validation-timing], [ref: #tracking-staleness], [ref: #tracking-reconciliation] |
| Checking whether a repo-specific memory is stale against its source repo. | entity-protocol/SKILL.md |
[ref: #entity-freshness] |
| When to record memory; the proactive-population mandate. | rules.md | [ref: #serena-lifecycle] |
| Archiving a completed feature's cross-scope memory footprint (extract → compress → reconcile → recoverable delete). | _on_demand/feature-archival/SKILL.md |
[ref: #fa-pipeline] (on-demand skill) |
| Logging a bug, note, or other finding with proper evidence. | entity-protocol |
[ref: #entity-namespace-registry], [ref: #entity-findings-traceability] |
| Resolving contradictions between memory entries; the contradictions log. | rules.md | [ref: #serena-contradictions] |
| Handling deprecated names and aliases. | entity-protocol/references/repo_memory.md |
[ref: #entity-deprecations] |
| Syntax examples of memory entries per findings domain. | rules.md | [ref: #serena-examples] |
| Producing a repo card: workflow, quality, exclusions, hard fails, header. | entity-protocol/references/card_production.md |
[ref: #entity-card-workflow], [ref: #entity-card-quality], [ref: #entity-card-exclusions], [ref: #entity-card-hard-fails], [ref: #entity-card-header-example] |
| Determining repo type; per-type interface exhaustiveness. | repo-audit/references/analysis/type_detection.md |
[ref: #repo-type-detection], [ref: #repo-interface-exhaustiveness] |
| Symbolic code search/edit via Serena MCP tools. | rules.md | [ref: #serena-mcp-tools] |
4. Master Execution Workflow
- Analyze Task: determine if you need to read memory, write memory, explore code, or create an entity card.
- Consult Index: find the relevant Anchor in the table above.
- Extract & Read: extract the exact section from the referenced file.
- Validate Header: when reading or editing an existing memory, verify that its frontmatter matches the current standard (
[ref: #serena-metadata]). If the header is outdated (plain-text metadata, missing or renamed fields), refresh it to the current YAML frontmatter format without losing information. Prefer direct file editing at.serena/memories/<path>.mdfor header-only updates, preserving all content below the header. - Execute: perform the memory/MCP operation strictly following the extracted guidelines.
- Persist: follow §1 — read back, then run the persistence command from the workspace root.
04 同仓库更多 Skills
todo-protocol
Mandatory protocol for using the SetTodoList tool. Governs when to create a todo list, how to update it without violating immutability rules, how to synchronize item status after every tool call, and the forbidden mutations. Always active.
subagents-protocol
Mandatory protocol for delegating work to built-in subagents (coder, explore, plan), also called our bots by users. Always active. Owns the context-hygiene delegation test (material vs answer, cost balance, warm-instance reuse), launch parameters (mandatory explicit `model`), the single-source model-selection table, answer budgets, degradation handling, the launch checklist, and the role library for delegated review/audit with intent routing (`references/roles.md`).
read-for-comments
Mandatory local standards library and archive. Before fetching any standard from the internet, the agent MUST check the Serena `standard/` archive and this skill's `references/` seed; after ANY standard-body download, the agent MUST archive it per the event-bound Archival Rule. Governs standard lookup, fetch, archival, and the family and full-body rules.
python-lang
MANDATORY skill for Python code. Use when writing, editing, refactoring, or reviewing Python files, modules, packages, classes, functions, type annotations, imports, exceptions, comprehensions, decorators, or docstrings. Enforces Google Python Style Guide and a mandatory, unconditional Ruff format+check pipeline scoped strictly to the agent's own changes.
preflight-checklist
Mandatory session-initialization closer and Startup Gate audit. Always loaded. Runs EXACTLY ONCE at session start, after all skill loading completes: verifies Startup Gate completion with evidence (mirror sync, forced import, discovery, activation, memory priming, MCP declaration, think block), runs dynamic session checks derived from the active skill set (mode states, delegation readiness), and reports a compact evidence-backed verdict table to the user before the first task output. Any FAIL is fixed before proceeding.
markdown-protocol
MANDATORY skill for Markdown authoring rules and the Markdown Headings as a Public API standard. Always active. Governs how the agent writes and edits any Markdown file: line discipline, date format, frontmatter pairing, markers and anchors, heading identity (slugs, renames, uniqueness), section shape and size, deprecation, and the errata conformance queue. The full normative standard lives in references/specification.md with rationale in references/rationale.md.