Install
openclaw skills install @oliguo/mem-skillSelf-evolving memory and knowledge accumulation system for AI agents. Acts as a persistent 'second brain' that automatically retrieves past experiences, captures best practices, and proactively records successful solutions to a private knowledge base. Use this skill whenever starting any task, opening a new conversation, or triggering any other skill. Supports memory engines (default: built-in JSON/Markdown index; optional: QMD semantic search). Initialize with: /mem-skill init [--mem-engine=qmd].
openclaw skills install @oliguo/mem-skillWhen the user runs /mem-skill init, execute the following setup:
<workspace>/
├── knowledge-base/
│ └── _index.json
├── experience/
│ └── _index.json
└── log.md
knowledge-base/_index.json with the starter template (see "Knowledge Base Index Format" below).experience/_index.json with the starter template (see "Experience Index Format" below).log.md with the starter template (see "Log Format" below).log.md: ## [YYYY-MM-DD] init | mem-skill initialized (engine: default)When the user runs /mem-skill init --mem-engine=qmd, optionally with extra --qmd-* flags:
Supported flags (all optional):
| Flag | Values | Default |
|---|---|---|
--qmd-scope=<scope> | project, global | (ask user) |
--qmd-knowledge=<name> | any string | (ask user) |
--qmd-experience=<name> | any string | (ask user) |
--qmd-mask=<pattern> | glob pattern | **/*.md |
Examples:
/mem-skill init --mem-engine=qmd
/mem-skill init --mem-engine=qmd --qmd-scope=project
/mem-skill init --mem-engine=qmd --qmd-scope=global --qmd-knowledge=my-kb --qmd-experience=my-exp
/mem-skill init --mem-engine=qmd --qmd-mask="**/*.md,**/*.txt"
Init procedure:
which qmd or npx @tobilu/qmd status."QMD is not installed. Install it now with
npm install -g @tobilu/qmd? (QMD requires Node.js >= 22)"
--qmd-scope was provided, use that value."Where should QMD collections be stored?
- Project — scoped to this workspace (recommended for multi-project setups)
- Global — shared across all workspaces"
my-app → prefix my-app).mem.--qmd-knowledge was provided, use that value.--qmd-experience was provided, use that value."What name for the knowledge collection? (default:
<prefix>-knowledge)" "What name for the experience collection? (default:<prefix>-experience)"
--qmd-mask was provided, use that value.**/*.md.qmd collection add <workspace>/knowledge-base --name <knowledge-name> --mask "<mask>"
qmd collection add <workspace>/experience --name <experience-name> --mask "<mask>"
qmd context add qmd://<knowledge-name> "General knowledge base: reusable workflows, preferences, best practices"
qmd context add qmd://<experience-name> "Skill-specific experience: pitfalls, parameters, solutions"
qmd embed
.mem-skill.config.json at the workspace root:
{
"engine": "qmd",
"version": "1.0.0",
"scope": "<project|global>",
"mask": "<mask>",
"collections": {
"knowledge": "<knowledge-name>",
"experience": "<experience-name>"
}
}
log.md: ## [YYYY-MM-DD] init | mem-skill initialized (engine: qmd, scope: <scope>, collections: <knowledge-name>, <experience-name>)IMPORTANT: Never silently create QMD collections without confirming scope and names with the user. If no --qmd-* flags were provided, every question above MUST be asked interactively.
For the default engine (no --mem-engine flag), create .mem-skill.config.json with:
{
"engine": "default",
"version": "1.0.0"
}
For detailed engine-specific behavior, see references/qmd-engine.md and references/engines.md.
When the user runs /mem-skill upgrade, migrate an existing mem-skill workspace to the latest version. This is safe to run multiple times — it only adds what's missing.
Procedure:
Check prerequisites:
knowledge-base/_index.json and experience/_index.json exist. If not, tell the user to run /mem-skill init instead..mem-skill.config.json to determine current engine and version.Create log.md if it doesn't exist:
# mem-skill Activity Log
Chronological record of all mem-skill operations. Each entry is parseable with `grep "^## \[" log.md`.
## [YYYY-MM-DD] upgrade | Migrated from v<old> to v1.2.0
If log.md already exists, just append the upgrade log entry.
Backfill **Source:** field on existing entries:
.md files in knowledge-base/ and experience/.## [Title]) that is missing **Source:**, insert **Source:** conversation after the **Date:** line.Backfill **Related:** field on existing entries:
**Related:**, insert an empty **Related:** line before **Keywords:**./mem-skill lint.Update .mem-skill.config.json version to 1.2.0.
QMD engine post-upgrade (if engine is qmd):
qmd update && qmd embed to re-index the backfilled entries.Confirm:
"Upgrade complete (v → v1.2.0):
- Created log.md ✓ (or: log.md already existed)
- Backfilled Source on entries ✓
- Added Related placeholder to entries ✓
- Updated config version ✓
Run
/mem-skill lintto discover cross-reference opportunities between your existing entries."
When the user runs /mem-skill recordnow, immediately trigger the recording flow for the current conversation — even if Step 5 was not triggered automatically.
This is useful when:
Procedure:
"I found these completed tasks worth recording:
- [summary of task 1] → knowledge-base
- [summary of task 2] → knowledge-base
- [summary of skill usage] → experience
Which ones should I record? (all / 1,2 / none)"
log.md: ## [YYYY-MM-DD] recordnow | Manually recorded <N> entriesWhen the user runs /mem-skill lint, perform a comprehensive health-check of the knowledge base and experience store.
Checks performed:
Duplicate detection — Scan all entries for similar titles, overlapping keywords (>= 70% overlap), or near-identical content. Flag entries that should be merged.
Stale entries — Flag entries older than 6 months (based on **Date:** field) that have no **Updated:** timestamp. These may contain outdated practices.
Contradiction detection — Within the same category, look for entries that give conflicting advice on the same topic. Flag with both entries quoted.
Orphan detection:
_index.json with no corresponding .md file..md files in knowledge-base/ or experience/ with no _index.json entry.**Related:** links pointing to non-existent entries.Missing cross-references — Entries in the same category or with overlapping keywords that have no **Related:** links between them.
Knowledge gaps — Categories with fewer than 2 entries. Suggest whether to merge into a broader category or to actively build out.
Index consistency — Verify totalEntries and per-category count values match the actual entry count in each .md file.
Output format:
mem-skill Health Check — YYYY-MM-DD
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ 24 entries across 5 categories
✓ 8 experience entries across 3 skills
⚠ STALE (2):
- knowledge-base/frontend-dev.md#"React Class Components" (2025-08-12, 8 months old)
- experience/skill-webpack.md#"Loader Order Fix" (2025-06-03, 10 months old)
⚠ DUPLICATE (1 pair):
- knowledge-base/workflow.md#"CI Pipeline Setup" ↔ knowledge-base/backend-dev.md#"CI/CD Best Practices"
→ Keywords overlap 75%. Consider merging.
⚠ MISSING CROSS-REFS (3):
- knowledge-base/frontend-dev.md#"Responsive Grid" ↔ knowledge-base/design-layout.md#"CSS Grid Patterns"
- ...
✓ No contradictions detected
✓ No orphans detected
✓ Index counts consistent
Summary: 6 issues found (0 critical, 6 warnings)
After lint:
**Related:** links.log.md: ## [YYYY-MM-DD] lint | Health-check completed: <N> issues foundQMD engine: After any fixes that modify .md files, run qmd update && qmd embed.
When the user runs /mem-skill ingest <source>, process an external source into knowledge base entries.
Source types:
| Source | Example |
|---|---|
| Local file | /mem-skill ingest ./docs/api-guide.md |
| URL | /mem-skill ingest https://example.com/best-practices |
| Directory | /mem-skill ingest ./docs/ (processes all markdown files) |
Procedure:
Read the source:
.md files and process each.Extract key knowledge points:
Match against existing categories:
knowledge-base/_index.json.Check for compounding opportunities:
Present to the user:
"I extracted these knowledge points from [source]:
- [insight 1] → knowledge-base/.md (new)
- [insight 2] → knowledge-base/.md (update existing: '')
- [insight 3] → knowledge-base/.md (new)
Which ones should I record? (all / 1,3 / none)"
Write on approval:
**Source:** to file:<path> or url:<link>.**Related:** cross-references between related entries._index.json counts and timestamps.Log: Append to log.md: ## [YYYY-MM-DD] ingest | Processed <source> → <N> entries created/updated
QMD engine post-write: Run qmd update && qmd embed.
IMPORTANT: Ingest does NOT blindly copy source content. It extracts actionable knowledge that fits the recording criteria, re-formats it into the standard entry format, and integrates it with existing knowledge.
Execute these steps on every conversation turn. Do not display internal cache state to the user.
Maintain these variables silently within the conversation:
last_keywords — keywords from the previous turnlast_topic_fingerprint — top 3 keywords as a fingerprintlast_index_lastUpdated — timestamp of last index readlast_matched_categories — categories matched on last readlast_used_skills — non-mem-skill skills used this turnmissing_experience_skills — skills with no experience entryloaded_experience_skills — skills whose experience has been loaded this sessiontopic_fingerprint from the top 3 keywords.A topic switch occurs when any of these conditions are met:
last_keywords by >= 40%Whenever a non-mem-skill skill is used this turn:
skill-id is already in loaded_experience_skills, skip (do not re-read or re-announce).experience/_index.json.skill-id entry exists, load experience/skill-<skill-id>.md.skill-id to loaded_experience_skills."Loaded experience: skill-<skill-id>.md"log.md: ## [YYYY-MM-DD] read | Retrieved experience: skill-<skill-id>.mdmissing_experience_skills.Engine-specific retrieval:
experience/_index.json and match by skillId..mem-skill.config.json, then run qmd search "<skill-id>" -c <experience-collection> --json -n 5 for keyword match, or qmd query "<skill-id> <context>" -c <experience-collection> --json -n 5 for deeper retrieval.Execute only on the first turn of the conversation or when a topic switch is detected:
Default engine:
knowledge-base/_index.json.keywords arrays."Loaded knowledge: <file1>.md, <file2>.md"log.md: ## [YYYY-MM-DD] read | Loaded knowledge: <file1>.md, <file2>.mdIf no topic switch occurred, reuse last_matched_categories without re-reading.
QMD engine:
.mem-skill.config.json.qmd query "<keywords joined by space>" -c <knowledge-collection> --json -n 10 --min-score 0.3."Retrieved knowledge via QMD: <titles>"Trigger conditions:
Recording procedure:
knowledge-base/_index.json and relevant .md files for entries with overlapping keywords or similar topics.qmd query "<summary>" -c <knowledge-collection> --json -n 3 --min-score 0.5 to find related entries."I found an existing entry '[[#]]' that's related. Should I update it with the new information, or create a separate entry?"
**Updated:** YYYY-MM-DD below the original date, and add cross-references.**Related:** links to the existing one (and update the existing entry's **Related:** too)."We solved [problem description]. I'd like to record this experience so I can reference it next time. Is that okay?"
experience/skill-<skill-id>.md and update experience/_index.json.knowledge-base/<category>.md and update knowledge-base/_index.json.**Source:** field (default: conversation).**Related:** cross-references to any related entries found in step 3.log.md:
## [YYYY-MM-DD] write | Recorded to <path>: "<title>"## [YYYY-MM-DD] update | Updated <path>: "<title>" (merged new info)Filing valuable answers back: If the agent produces a valuable synthesis (comparison table, analysis, architectural decision) during a query — not just task completion — proactively offer:
"This [comparison/analysis/summary] seems valuable beyond this conversation. Want me to save it to the knowledge base?"
This ensures knowledge is captured from exploration and research, not just from building things.
QMD engine post-write:
After writing any .md file, run:
qmd update
qmd embed
Forced rule — always ask when experience is missing:
If a non-mem-skill skill was used this turn and that skill has no entry in experience/_index.json, you must ask at task completion:
"We used this time, but there's no experience record yet. Can I record this session's approach for future reference?"
If Step 5 was not triggered (e.g., multi-task sessions where satisfaction signals were missed), the user can run /mem-skill recordnow at any time to manually trigger recording. See "Manual Recording Command" above.
knowledge-base/_index.json:
{
"lastUpdated": "YYYY-MM-DD",
"version": "1.0.0",
"totalEntries": 0,
"categories": [
{
"id": "category-id",
"name": "Category Name",
"keywords": ["keyword1", "keyword2"],
"file": "category-id.md",
"count": 0
}
]
}
experience/_index.json:
{
"lastUpdated": "YYYY-MM-DD",
"version": "1.0.0",
"skills": [
{
"skillId": "skill-id",
"file": "skill-<skill-id>.md",
"keywords": ["keyword1", "keyword2"],
"count": 0
}
]
}
log.md:
# mem-skill Activity Log
Chronological record of all mem-skill operations. Each entry is parseable with `grep "^## \[" log.md`.
## [YYYY-MM-DD] init | mem-skill initialized (engine: <engine>)
## [YYYY-MM-DD] read | Loaded knowledge: <file1>.md, <file2>.md
## [YYYY-MM-DD] read | Retrieved experience: skill-<id>.md
## [YYYY-MM-DD] write | Recorded to knowledge-base/<category>.md: "<entry-title>"
## [YYYY-MM-DD] write | Recorded to experience/skill-<id>.md: "<entry-title>"
## [YYYY-MM-DD] update | Updated knowledge-base/<category>.md: "<entry-title>" (merged new info)
## [YYYY-MM-DD] lint | Health-check completed: <N> issues found
## [YYYY-MM-DD] ingest | Processed <source> → <N> entries created/updated
## [YYYY-MM-DD] recordnow | Manually recorded <N> entries
Logging rules:
log.md on every write, update, lint, ingest, and recordnow operation.## [Short Title]
**Date:** YYYY-MM-DD
**Source:** conversation | file:<path> | url:<link>
**Context:** One-line description of the use case
**Best Practice:**
- Key point 1
- Key point 2 — parameter notes and tuning guidance
**Related:** [[<category>#<entry-title>]], [[<category2>#<entry-title2>]]
**Keywords:** keyword1, keyword2, keyword3
## [Problem/Technique Title]
**Date:** YYYY-MM-DD
**Skill:** <skill-id>
**Source:** conversation | file:<path> | url:<link>
**Context:** One-line description of the issue
**Solution:**
- Concrete step 1
- Concrete step 2
**Key Files/Paths:**
- /path/to/relevant/file
**Related:** [[skill-<other-id>#<entry-title>]], [[<kb-category>#<entry-title>]]
**Keywords:** keyword1, keyword2, keyword3
| Value | When to Use |
|---|---|
conversation | Learned from a chat session (default) |
file:<path> | Ingested from a local file |
url:<link> | Ingested from a web URL |
Cross-references use [[file#heading]] format (compatible with Obsidian-style wikilinks):
[[<category>#<entry-title>]][[skill-<id>#<entry-title>]]**Related:** field too).When user keywords do not match any existing category:
<category-id>.md file and update knowledge-base/_index.json.Core question: Will this save the user time next time?
knowledge-base/_index.jsonknowledge-base/<category-id>.mdexperience/_index.jsonexperience/skill-<skill-id>.md.mem-skill.config.jsonWhen the knowledge base exceeds 50 entries, proactively suggest upgrading to QMD:
"Your knowledge base has grown to [N] entries. For faster semantic search, consider upgrading to QMD: run
/mem-skill init --mem-engine=qmd."
For full QMD engine details, see references/qmd-engine.md. For the engine abstraction and adding new engines, see references/engines.md.