Skip to content
Skills Library
AI & agents · Review & audit

memory-gate

/memory-gate

Memory-First Gate (BLOCKING) and the Chesterton's Fence investigation protocol, split out of the memory router per ADR-063. Forces a memory search before you change existing code, constraints, or protocol, so the "why" is recovered before the fence comes down. Use when you say `memory-first gate`, `search memory before changing`, or `chesterton fence check`. Do NOT use for plain Tier 1 lookups (use memory-search) or recording a session (use memory-reflexion).

Repository
ai-agents ↗
Licence
MIT
Last repository change
25.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
3
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Memory-First Gate (BLOCKING) and the Chesterton's Fence investigation protocol, split out of the memory router per ADR-063. Forces a memory search before you change existing code, constraints, or protocol, so the "why" is recovered before the fence comes down. Use when you say `memory-first gate`, `search memory before changing`, or `chesterton fence check`. Do NOT use for plain Tier 1 lookups (use memory-search) or recording a session (use memory-reflexion).

Triggers from the description

why
Original author description

Memory-First Gate (BLOCKING) and the Chesterton's Fence investigation protocol, split out of the memory router per ADR-063. Forces a memory search before you change existing code, constraints, or protocol, so the "why" is recovered before the fence comes down. Use when you say `memory-first gate`, `search memory before changing`, or `chesterton fence check`. Do NOT use for plain Tier 1 lookups (use memory-search) or recording a session (use memory-reflexion).

How it works

  1. Triggers
  2. Memory-First Gate (BLOCKING)
  3. Memory-First as Chesterton's Fence
  4. Investigation Protocol
  5. Escalation
  6. Verification
  7. Anti-Patterns
  8. Process
  9. Related Skills
  10. References
Original SKILL.md headings · 183 lines, 1,082 words
SKILL.md preview
---
name: memory-gate
version: 0.1.0
description: Memory-First Gate (BLOCKING) and the Chesterton's Fence investigation
  protocol, split out of the memory router per ADR-063. Forces a memory search
  before you change existing code, constraints, or protocol, so the "why" is
  recovered before the fence comes down. Use when you say `memory-first gate`,
  `search memory before changing`, or `chesterton fence check`. Do NOT use for
  plain Tier 1 lookups (use memory-search) or recording a session (use
  memory-reflexion).
license: MIT
metadata:
  adr: ADR-063, ADR-070, ADR-106
  capability:
    kind: reusable-primitive
    status: active
  parent: memory
  routing:
    role: lifecycle
    invoker: spec
    trigger: spec Step 0 routes to the memory-first gate before changing an existing system
    user-facing: false
---

# Memory Gate

The Memory-First Gate and its investigation protocol, extracted from the
`memory` router per ADR-063 (memory-skill decomposition). `memory` still routes
here; an agent about to change an existing system loads this sub-skill instead
of the full memory surface.

The gate is one operation with a single rule: before you change something that
already exists, search memory for why it exists. The search uses the canonical
Tier 1 script; this sub-skill owns the enforcement semantics (ADR-070) and the
Chesterton's Fence framing, not the search implementation.

## Triggers

Use this skill when the user says:

- `memory-first gate` to apply the BLOCKING pre-change check
- `search memory before changing` to recover historical context first
- `chesterton fence check` to investigate why a system exists before removing it

## Memory-First Gate (BLOCKING)

Before changing existing systems, you MUST:

1. Search memory for the topic you are about to change.
2. Review results for historical context.
3. If Tier 1 is insufficient, escalate to Tier 2 (episodes).
4. Document findings in your decision rationale.
5. Only then proceed with the change.

```bash
# Recover the "why" before you change the "what"
SCRIPTS_DIR="${COPILOT_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-.claude}}/skills/memory/scripts"
python3 "$SCRIPTS_DIR/search_memory.py" "[topic]"
```

**Why BLOCKING**: under 50% compliance with "check memory first" guidance when it
is advisory. Making it BLOCKING achieves 100% compliance, the same pattern as
the session protocol gates (ADR-070 gate semantics).

**Verification**: the transcript, pull request, handoff, Serena memory, or an
optional log must show the search before the decision.

The canonical Tier 1 script is `search_memory.py`. It is shared with the
`memory` router and lives at
`skills/memory/scripts/search_memory.py` under the plugin root (`COPILOT_PLUGIN_ROOT`, then
`CLAUDE_PLUGIN_ROOT`, falling back to `.claude`). This sub-skill delegates to it
and does not reimplement search.

## Memory-First as Chesterton's Fence

**Core insight**: memory-first architecture implements the Chesterton's Fence
principle for AI agents.

> "Do not remove a fence until you know why it was put up" (G.K. Chesterton)

**Translation for agents**: do not change code, architecture, or protocol until
you search memory for why it exists.

### Why this matters

**Without memory search** (removing the fence without investigation):

- Agent meets complex code, thinks "this is ugly, I will refactor it".
- Removes validation logic that guards an edge case.
- A production incident follows.
- Memory held the past incident that explained why the validation existed.

**With memory search** (Chesterton's Fence investigation):

- Agent meets complex code.
- Searches memory: `search_memory.py "validation logic edge case"`.
- Finds the past incident that explains why the code exists.
- Makes an informed decision: preserve, modify, or replace with equal safety.

## Investigation Protocol

When you want to change something that already exists, match the change type to
the required search:

| Change Type | Memory Search Required |
|-------------|------------------------|
| Remove ADR constraint | `search_memory.py "[constraint name]"` |
| Bypass protocol | `search_memory.py "[protocol name] why"` |
| Delete more than 100 lines | `search_memory.py "[component] purpose"` |
| Refactor complex code | `search_memory.py "[component] edge case"` |
| Change workflow | `search_memory.py "[workflow] rationale"` |

### What memory contains (git archaeology)

**Tier 1 (Semantic)**: facts, patterns, constraints.

- Why is Python the default for new internal automation? (ADR-042, which superseded the PowerShell-only ADR-005 but keeps PowerShell for quick fixes to existing PowerShell scripts and PowerShell-specific operations)
- Why did the PowerShell-only constraint exist, before it was superseded? (ADR-005, superseded by ADR-042)
- Why do skills exist instead of raw CLI? (usage-mandatory)
- What incidents led to BLOCKING gates? (protocol-blocking-gates)

**Tier 2 (Episodic)**: past session outcomes.

- What happened when we tried approach X? (session replay)
- What edge cases did we hit? (failure episodes)

Memory is your investigation tool. It holds the "why" that Chesterton's Fence
requires you to discover before you act. For the full four-phase decision
framework (Investigation, Understanding, Evaluation, Action) and the decision
matrix for when to investigate, use the [chestertons-fence
skill](../chestertons-fence/SKILL.md).

## Escalation

Tier 1 answers most "why does this exist" questions. Escalate when it does not:

```text
Change target identified?
│
├─► Tier 1: search_memory.py "[topic]"
│   └─► Facts, constraints, ADR rationale. Enough? Proceed.
│
└─► Not enough context? Escalate to Tier 2 (episodes)
    └─► What happened last time we touched this, and how did it end?
```

Escalate only when the cheaper tier is insufficient. Starting at Tier 1 keeps
the token cost low; most gate checks resolve there.

## Verification

| Operation | Verification |
|-----------|--------------|
| Gate search ran | Result count greater than 0 OR logged "no results" |
| Ordering correct | Search appears before the change in accepted evidence |
| Escalation justified | Tier 2 used only after Tier 1 came back thin |
| Rationale recorded | Decision rationale cites the memory findings |

## Anti-Patterns

| Anti-Pattern | Do This Instead |
|--------------|-----------------|
| Changing first, searching after | Search BEFORE the decision; log it before you act |
| Treating the gate as advisory | The gate is BLOCKING; a skipped search is a failure |
| Refactoring complex code blind | Search the component's edge cases before you touch it |
| Removing a constraint on sight | Search the constraint name; recover why it was set |
| Escalating straight to Tier 2 | Start at Tier 1; escalate only when it is thin |

## Process

### Phase 1: Identify

Name the existing system you intend to change and the change type. Match it to a
row in the Investigation Protocol table.

### Phase 2: Search

Run `search_memory.py` for the topic. Escalate to Tier 2 only when
Tier 1 is insufficient.

### Phase 3: Decide

Record the findings in your decision rationale, then preserve, modify, or replace
with equal safety. Never proceed with the change before the search is logged.

## Related Skills

| Skill | When to Use Instead |
|-------|---------------------|
| `memory` | Router for search, reflexion, or maintenance operations |
| `memory-search` | Plain Tier 1 lookup with no pre-change gate semantics |
| `memory-reflexion` | Record a completed session as an episode |
| `chestertons-fence` | The full four-phase investigation framework and matrix |

## References

- ADR-007: Memory-first architecture (the posture this gate enforces)
- ADR-037: Memory router architecture (the router this sub-skill delegates from)
- ADR-063: Memory skill decomposition (this extraction)
- ADR-070: Gate semantics (why the gate is BLOCKING, not advisory)
- [references/agent-integration.md](references/agent-integration.md): multi-agent
  integration patterns, including the Memory-First Decision Making workflow this
  gate enforces
- [references/contradiction-log.md](references/contradiction-log.md): when and how
  to log a first-principles finding that contradicts conventional wisdom
Files in this package (3)
  • SKILL.md 8 KB
  • references/agent-integration.md 16 KB
  • references/contradiction-log.md 2 KB

Versions

RepositoryScoreLicence
This page · rjmurillo/ai-agents100MIT
rjmurillo/ai-agents100MIT

Identical content appears in 3 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version 8ebe82f8db4d (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100dx-simplify
    Simplify working code without changing its behavior — Chesterton's Fence, Rule of 500. Use for 'simplify', 'reduce complexity', 'refactor for clarity'.
  • 100memory-reflexion
    Tier 2 episode extraction, the reflexion write path split out of the memory router per ADR-063. Extracts an episode from a completed session log so later sessions can replay what was tried and what it cost. Use when you say `extract episode from session`, `record what happened…
  • 100memory-search
    Tier 1 semantic memory search across the Serena corpus with progressive disclosure and token-budget warnings. The focused search operation split out of the memory router per ADR-063. Use when you say `search memory`, `what do we know about X`, or `recall prior context`. Do NOT…
  • 100code-review
    Review a PR (pull request), a branch, a diff, or a set of files with a structured 3-pass method (architecture, logic, expressiveness), five questions in pass 2, a Chesterton's Fence provenance check, and ICE-prefixed findings under a summary-first report. Use when asked to…
  • 100chesterton
    Use before deleting, simplifying, or "cleaning up" code that looks unnecessary, odd, or redundant (sleeps, retries, special cases for specific IDs or dates, magic numbers, swallowed exceptions, duplicate-looking code, version checks, comments like "do not remove" or…
  • 95memory-search
    Search this agent's long-term memory of past sessions: decisions, facts, corrections, and what depends on an entity. Use when a task touches something with history (a repo, service, environment or decision from earlier sessions), before deploying, moving, deleting or…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.