AGENT SKILL

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

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_memory completely overwrites a file. You MUST NEVER use it to append to an existing memory.
  • edit_memory edits in place (literal or regex mode). In regex mode the pattern compiles with re.MULTILINE | re.DOTALL: NEVER use bare .* in needles (it eats the rest of the file — use [^\n]* for single lines), and repl is inserted VERBATIM (\1-style backreferences are NOT expanded).

To CREATE a new memory:

  1. Call list_memories to ensure the name does not exist.
  2. Call write_memory with 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:

  1. Refresh the header per the tracking extension ([ref: #tracking-refresh], [ref: #tracking-timestamps]): bump updated_at, and branch/commit/committed_at when the git state changed.
  2. Read the memory back and verify it was saved correctly.
  3. 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_memory to 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:

  1. Match your task to a Trigger in the Routing Index below.
  2. Note the exact Anchor tag.
  3. Extract ONLY that section per the canonical loader mechanics in frontmatter-protocol [ref: #lazy-load-routing] (bounded extraction — never a blind rg -A N window; the exact command lives there, not here).
  4. 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

  1. Analyze Task: determine if you need to read memory, write memory, explore code, or create an entity card.
  2. Consult Index: find the relevant Anchor in the table above.
  3. Extract & Read: extract the exact section from the referenced file.
  4. 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>.md for header-only updates, preserving all content below the header.
  5. Execute: perform the memory/MCP operation strictly following the extracted guidelines.
  6. Persist: follow §1 — read back, then run the persistence command from the workspace root.

04 同仓库更多 Skills

kalaverin
kalaverin/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.

★ 1
kalaverin
kalaverin/skills

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`).

★ 1
kalaverin
kalaverin/skills

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.

★ 1
kalaverin
kalaverin/skills

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.

★ 1
kalaverin
kalaverin/skills

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.

★ 1
kalaverin
kalaverin/skills

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.

★ 1