with one click
corgispec-memory-init
// Initialize the 3-layer memory structure (memory/ + wiki/) for cross-session AI continuity in an OpenSpec project.
// Initialize the 3-layer memory structure (memory/ + wiki/) for cross-session AI continuity in an OpenSpec project.
| name | corgispec-memory-init |
| description | Initialize the 3-layer memory structure (memory/ + wiki/) for cross-session AI continuity in an OpenSpec project. |
| license | MIT |
| compatibility | Requires openspec CLI. Target project must have openspec/config.yaml. |
| metadata | {"author":"openspec","version":"1.0","generatedBy":"1.0.0"} |
Initialize the 3-layer memory structure for cross-session AI continuity.
Creates memory/ (permanent, agent-focused) and wiki/ (long-term, human+AI) directories with template files, then injects the Session Memory Protocol into the project's agent configuration file.
The result is a structured memory system that:
corgispec-install completes (called automatically unless --no-memory)/corgi-memory-init to add memory to an existing OpenSpec projectmemory/ or wiki/ yetDo not use this skill to modify memory contents, run lint checks, or extract knowledge from changes.
openspec/config.yamlRead the target project's root for context:
README.md exists ā extract project name and purpose (first heading + first paragraph)CLAUDE.md exists ā extract:
AGENTS.md exists ā extract same categories as CLAUDE.md (merge, deduplicate)GEMINI.md exists ā extract same categories (merge, deduplicate)package.json exists ā extract project name from name field, framework info from dependenciesdocs/ exists ā scan top-level .md filenames for architecture clues (don't deep-read, just note presence)Store extracted values for template population:
PROJECT_NAME: from README heading or package.json namePROJECT_PURPOSE: from README first paragraphTECH_STACK: from agent configs + package.json depsHARD_CONSTRAINTS: bullet list from agent configs (max 15)PREFERENCES: bullet list from agent configs (max 10)STABLE_COMPONENTS: well-established tech from stack infoEVOLVING_COMPONENTS: anything described as new/experimental, or "TBD"LEGACY_COMPONENTS: anything described as deprecated/debt, or "None identified"If a file doesn't exist or a value can't be extracted, use placeholder text.
Note: This is a lightweight extraction for initial setup. For deep knowledge migration from existing projects, run /corgi-migrate after init completes.
Create the following files. Skip any file that already exists ā never overwrite.
memory/
āāā MEMORY.md
āāā session-bridge.md
āāā pitfalls.md
---
type: memory
created: <today's date YYYY-MM-DD>
---
# MEMORY ā Hard Constraints
> AI agent must obey these every session. Never expires.
## Project Identity
- **Name**: <extracted from README or package.json, or "Unknown">
- **Purpose**: <extracted from README first paragraph, or "Not specified">
- **Stack**: <extracted from CLAUDE.md/AGENTS.md, or "Not specified">
## Hard Constraints
- <extracted from CLAUDE.md Must-Follow Rules, or "None specified yet">
## Preferences
- <extracted from CLAUDE.md style/convention sections, or "None specified yet">
---
type: memory
updated: <today's date YYYY-MM-DD>
---
# Session Bridge
> AI agent reads this first at startup. Last session's handoff state.
## Active opsx Change
- **Change**: none
- **Phase**: none
- **Branch**: main
## Done (last session completed)
- (initial setup ā memory structure created)
## Waiting (next steps / blockers)
- First change not yet created ā run `/corgi-propose`
## New Pitfalls
- (none yet)
## New Discoveries
- (none yet)
## Next Session Start
1. Read this file ā you are here
2. Read [[wiki/hot]]
3. Read [[wiki/index]]
4. Then docs/ or specs/ as needed
---
type: memory
updated: <today's date YYYY-MM-DD>
---
# Pitfalls
> Cross-change pitfall log. Each entry links to its source change. Max 20 active entries.
## Active
(No pitfalls yet ā these accumulate during opsx apply sessions)
## Archive
(No archived pitfalls yet ā oldest entries rotate here when Active exceeds 20)
Create the following structure. Skip any file that already exists.
wiki/
āāā hot.md
āāā index.md
āāā architecture/
ā āāā _index.md
ā āāā implicit-contracts.md
āāā patterns/
ā āāā _index.md
āāā research/
ā āāā _index.md
āāā sessions/
ā āāā _index.md
āāā decisions/
ā āāā _index.md
āāā questions/
ā āāā _index.md
āāā meta/
āāā _index.md
---
type: wiki
updated: <today's date YYYY-MM-DD>
tags: [hot, entry]
pinned: true
---
# Hot ā <Project Name> Latest
> ~500 words | Hard cap 600 words | Updated every session | First entry point for humans and AI
## Active Changes
- (No active change yet ā run `/corgi-propose`)
## Recent Decisions
- Initialized memory structure
## Architecture Pulse
- **Stable**: <from CLAUDE.md/README or "TBD">
- **Evolving**: <current work focus or "TBD">
- **Legacy**: <known tech debt or "None identified">
## Recent Pitfalls
- (none yet ā see [[memory/pitfalls]])
## Recently Shipped
- (none yet)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# <Project Name> Wiki Index
> AI-maintained long-term knowledge navigation. Hard cap 80 lines. Click wikilinks to jump to source.
## Architecture Insights
- [[wiki/architecture/_index|Architecture Index]]
- [[wiki/architecture/implicit-contracts|Implicit Contracts]]
## Patterns
- [[wiki/patterns/_index|Patterns Index]]
## Research
- [[wiki/research/_index|Research Index]]
## Decisions
- [[wiki/decisions/_index|Decisions Index]]
## Session History
- [[wiki/sessions/_index|Session Index]]
## Questions
- [[wiki/questions/_index|Questions Index]]
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Architecture Index
> Structural insights about the codebase. Add entries as architecture knowledge is discovered.
## Pages
- [[wiki/architecture/implicit-contracts|Implicit Contracts]]
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Implicit Contracts
> Unwritten rules discovered during development. Each entry explains what breaks if violated.
## Contracts
(No implicit contracts discovered yet ā these are added during opsx apply sessions when hidden dependencies or assumptions are found)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Patterns Index
> Reusable approaches extracted from completed changes.
## Patterns
(No patterns extracted yet ā these are created during opsx archive)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Research Index
> Investigation results from opsx explore sessions.
## Topics
(No research topics yet ā these are created during opsx explore)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Session Index
> Summaries of completed changes, extracted at archive time.
## Sessions
(No session summaries yet ā these are created during opsx archive)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Decisions Index
> Key decisions made during reviews and implementation.
## Decisions
(No decisions recorded yet ā these are created when reviews approve significant choices)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Questions Index
> Human questions asked via Obsidian, answered by AI from vault context.
## Questions
(No questions yet ā create a markdown file here with `status: pending` frontmatter to ask a question)
---
type: wiki
updated: <today's date YYYY-MM-DD>
---
# Meta Index
> Lint reports, dashboards, and memory health metrics.
## Reports
(No lint reports yet ā run `/corgi-lint` to generate one)
Check the agent configuration file for an existing ## Session Memory Protocol section:
CLAUDE.md exists ā check for ## Session Memory ProtocolAGENTS.md exists ā check for ## Session Memory ProtocolIf the section already exists ā skip injection, report "Session Memory Protocol already present."
If the section does NOT exist ā append the following block to the end of the primary config file (CLAUDE.md if it exists, otherwise AGENTS.md):
## Session Memory Protocol
### Startup (every session)
Read in order, max 3 files:
1. `memory/session-bridge.md` ā last session's state
2. `wiki/hot.md` ā current project context (~500 words, hard cap 600)
3. `wiki/index.md` ā jump to relevant domain page
Then read `docs/` or code as needed.
### Retrieval Budget
- Startup: max 3 files (session-bridge + hot + index), then on-demand
- Per-question: max 2 wiki pages before answering
- If >5 pages needed: say "this needs a deep session"
### File Size Limits (hard caps)
| File | Target | Hard Cap | Overflow Action |
|------|--------|----------|-----------------|
| wiki/hot.md | 500 words | 600 words | Trim oldest entries |
| wiki/index.md | 40 lines | 80 lines | Archive completed entries |
| memory/pitfalls.md | 10 active | 20 active | Rotate oldest 10 |
| memory/session-bridge.md | 30 lines | 50 lines | Archive old Done items |
### Shutdown (every session end)
Update `memory/session-bridge.md`: Done / Waiting / New Pitfalls / New Discoveries
### opsx Apply ā Long-term Memory
After each Task Group completes:
- New pitfalls ā append to `memory/pitfalls.md` (link source change)
- New implicit rules ā append to `wiki/architecture/implicit-contracts.md`
- Update `wiki/hot.md` Recent Decisions
### Compaction Triggers (agent self-maintains)
- Every archive: compress session-bridge
- pitfalls > 20 entries: rotate oldest 10 to Archive section
- hot.md > 550 words: trim oldest entries
- Every 10 opsx sessions: suggest running /corgi-lint
Throughout all steps, enforce these rules:
## Session Memory Protocol already exists in the config file, do not duplicate it.Print a structured summary:
## Memory Init Complete
**Project**: <name>
**Created**: N files
**Skipped**: M files (already existed)
**Protocol**: Injected into <file> / Already present / No config file
### Created Files
- memory/MEMORY.md
- memory/session-bridge.md
- memory/pitfalls.md
- wiki/hot.md
- wiki/index.md
- wiki/architecture/_index.md
- wiki/architecture/implicit-contracts.md
- wiki/patterns/_index.md
- wiki/research/_index.md
- wiki/sessions/_index.md
- wiki/decisions/_index.md
- wiki/questions/_index.md
- wiki/meta/_index.md
### Next Steps
1. Review `memory/MEMORY.md` ā fill in any placeholders
2. Run `/corgi-propose` to create your first change
3. Memory will auto-update during apply and archive phases
[HINT] Download the complete skill directory including SKILL.md and all related files