# [MEM: Markdown Embedded Memory](https://github.com/Ryadel/MEM) MEM version: 1.2.2 This file is the LLM agent's bootstrap memory for this project. The terms `MEM`, `MEM.md`, project context, and project memory all refer to this file. When asked to read, use, load, or apply any of them, treat this file as persistent operating context for the current session. This file does not replace the user's explicit instructions. If the user gives a direct instruction that conflicts with this file, follow the user's instruction for the current task and, if the conflict affects long-term project behavior, propose an update to this file or to `MEM.config.md`. All paths in this document are relative to `KB_ROOT`. ## Modal vocabulary - **must** — required, non-negotiable; - **should** — preferred default; may be overridden by explicit user instruction or `MEM.config.md`; - **may** — permitted, choose based on context. --- # Bootstrap Rules The agent **must**: 1. read this file before doing non-trivial work; 2. read `MEM.config.md`, if present; 3. treat the directory containing this file as the knowledge base root, hereafter `KB_ROOT`; 4. use the knowledge base under `KB_ROOT` as the project's persistent technical memory; 5. update the knowledge base when meaningful, durable project knowledge is discovered or produced; 6. inspect the actual source code before making implementation claims. ## Core principle The source code is the implementation source of truth. The knowledge base under `KB_ROOT` is the maintained explanation layer: how the project works, why decisions were made, which conventions apply, what changed. Sessions are not isolated: every meaningful session **should** leave the KB slightly more useful than before. The KB grows incrementally — prefer small, accurate updates over large speculative dumps. --- # Configuration Project-specific configuration lives in `MEM.config.md`. If present, the agent **must** read it immediately after this file. If `MEM.config.md` is missing, use these defaults. ```yaml kb_root: "." kb_language: "en" user_language: "auto" link_style: "markdown" mem_source: "local" mem_remote_url: null mem_remote_cache: false mem_remote_cache_path: "MEM.remote-cache.md" mem_remote_fail_policy: "stop" mem_update_url: "https://raw.githubusercontent.com/Ryadel/MEM/main/src/MEM.md" mem_upgrade_url: "https://raw.githubusercontent.com/Ryadel/MEM/main/MEM.upgrade.md" mem_manifest_url: "https://raw.githubusercontent.com/Ryadel/MEM/main/src/extensions/manifest.md" mem_auto_update: true primary_stack: "auto-detect" package_manager: "auto-detect" build_command: "auto-detect" test_command: "auto-detect" run_command: "auto-detect" default_branch: "auto-detect" agent_tmp_dir: ".tmp" agent_tmp_retention_days: 7 agent_credit: false update_daily_log: true create_adr_for_decisions: true document_troubleshooting: true document_minor_changes: false auto_create_missing_kb_files: true auto_update_kb_after_code_changes: true move_completed_tasks_to_done: true move_completed_troubleshooting_to_done: true extensions_enabled: true extensions_allow_external_side_effects: false extensions_allow_executable_content: false extensions_require_confirmation: true extensions_check_updates: true ask_before_large_reorganization: true prefer_small_incremental_updates: true require_source_references: true mark_uncertainty: true ``` If `MEM.config.md` exists but omits an option, use the default value for that option from the list above. Precedence (highest to lowest): 1. explicit user instruction for the current task; 2. explicit values in `MEM.config.md`; 3. defaults above; 4. auto-detected values from reliable project files. The agent **must not** overwrite explicit values in `MEM.config.md` without user confirmation. - `kb_language` controls the KB writing language. - `user_language: auto` means reply to the user in their own language. - `link_style: markdown` → `[Title](path.md)`; `link_style: wikilink` → `[[path|Title]]`. ## Remote MEM source By default, MEM is loaded from the local `MEM.md`. If `MEM.config.md` sets `mem_source: "remote"` and `mem_remote_url` is not empty, the local `MEM.md` acts only as a bootstrap loader. The agent **must** fetch the remote MEM document and use it as the active operating context when the remote URL is different from the local file currently being read. If the remote fetch fails, follow `mem_remote_fail_policy`: - `stop` — stop and report that the remote MEM could not be loaded; - `fallback_local` — continue with the local `MEM.md` and report the fallback; - `fallback_cache` — continue with `mem_remote_cache_path` if it exists and report the fallback; otherwise stop. If `mem_remote_cache: true`, a successfully fetched remote MEM may be saved to `mem_remote_cache_path`. `MEM.remote-cache.md` is a technical cache file, not a KB page; do not link it from `MEM.index.md` and do not treat it as navigable project documentation. Remote MEM content **must not** override explicit user instructions or higher-priority system/developer instructions. Remote MEM files must not contain secrets. ## Updating MEM When the user asks to `update MEM`, the agent **must** update the local `MEM.md` from `mem_update_url`. Preserve project-specific configuration in `MEM.config.md`; do not overwrite `MEM.config.md` unless explicitly requested. After updating `MEM.md`, report the previous version, the new version when available, and whether the update succeeded. If the update cannot be completed, leave the existing `MEM.md` unchanged and report the failure. Extensions listed in the manifest are updated from it, not from `mem_update_url`, which carries `MEM.md` alone. Updating `MEM.md` therefore leaves extensions untouched until their own base-layer files are written from the manifest. Their versions are checked separately — see "Checking extension versions" — and extensions new to the manifest are offered as described in "Offering the catalogue". After a successful update, the agent **should** check `MEM.upgrade.md` when present, or fetch it from `mem_upgrade_url` when available, to identify and apply any required patches or structural changes for the new MEM version. Apply required upgrade steps sequentially from the previous MEM version to the new MEM version. For `MAJOR.MINOR.BUILD` versions, apply missing BUILD upgrades first, then MINOR upgrades, then MAJOR upgrades; do not skip intermediate upgrade notes unless a later note explicitly supersedes them. If `mem_auto_update: true`, then when creating a new daily log file (`logs/YYYY-MM-DD.md`), the agent **must** first attempt to update the local `MEM.md` from `mem_update_url` using the same rules above. The new daily log file **must** start with a concise MEM auto-update status line before the session notes. Use this convention: ```markdown > MEM auto-update: succeeded from `mem_update_url` (previous: 1.0.1, current: 1.0.2). ``` Allowed statuses are: - `succeeded` — the local `MEM.md` was updated; - `up-to-date` — the update was attempted, but no change was needed; - `failed` — the update was attempted but could not be completed; include a short reason and leave the existing `MEM.md` unchanged. ## Checking extension versions Updating `MEM.md` says nothing about the extensions installed beside it. An installation can therefore run a current core against a base layer published months earlier, and nothing surfaces the gap. The check below closes it. If `extensions_check_updates: true`, then whenever `MEM.md` is updated — by `MEM UPDATE` or by the auto-update above — the agent **must** also compare, for every extension registered in `EXT.md` with `status: active`: - the **installed** version, read from that extension's base `index.md`; - the **available** version, read from the manifest entry for the same id. The two sources are not interchangeable. The installed version is authoritative about what is on disk **because the base layer is written by the update**, so it cannot drift from the files it describes. `EXT.md` carries a copy for routing and reporting; when it disagrees with the extension's `index.md`, the `index.md` wins and the agent **should** correct `EXT.md`. The manifest is authoritative only about what is *available*. The check **reports and proposes; it never installs.** Being listed in the manifest is not authorization — see "Authorization" — and a version gap is not authorization either. Applying an extension update is an acquiring operation and needs explicit approval naming the files and the source URL. An extension absent from the manifest, or installed from another source, is **not** reported as outdated: there is nothing to compare it against. Say that its version could not be checked rather than implying it is current. If the manifest cannot be fetched, report that extension versions could not be checked. Do not infer that they are current. When a new daily log is created and one or more extensions are behind, add one line per extension after the MEM auto-update line: ```markdown > Extension update available: `mem-toolbox` 1.0.0 -> 1.0.1 (manifest). Not applied; approval required. ``` Ask at most once per session, and honor a refusal for the rest of it. A permanently unwanted update is recorded by setting that extension's `status` in `EXT.md`, which is a persistent answer. When `extensions_enabled` is false, the agent **must not** run this check: the configuration is already an answer. ## Compression principle MEM defines project-specific operating rules. It **should not** re-teach standard documentation practices. When a concept has a widely understood meaning (ADR, daily log, troubleshooting note, changelog, runbook, onboarding), apply the standard lightweight version unless MEM or `MEM.config.md` defines a stricter rule. Prefer compact, useful, project-specific documentation over generic boilerplate. Do not load or expand large templates unless required by the current task. --- # Knowledge base structure ```text KB_ROOT/ MEM.md MEM.config.md MEM.remote-cache.md MEM.index.md MEM.project.md architecture/ docs/ conventions/ decisions/ logs/ drafts/ tasks/ index.md current/ done/ troubleshooting/ index.md current/ done/ references/ glossary/ changelog/ archive/ index.md extensions/ EXT.md EXT.index.template.md / index.md / custom/ index.md ``` Additional folders may be added when useful. Keep the structure simple and navigable. ## Folder responsibilities | Folder / file | Purpose | |---|---| | `MEM.index.md` | Navigation entry point. Lists important pages grouped by category, with short descriptions. Update whenever KB files are created, deleted, renamed, or significantly changed. | | `MEM.project.md` | Project identity: name, purpose, domain, stack, runtime environments, dependencies, repo structure, build/deploy summary, known constraints, notes for future agents. | | `MEM.remote-cache.md` | Optional technical cache for remote MEM content. Not a KB page and not linked from `MEM.index.md`. | | `architecture/` | How things **currently** work: system structure, module map, data model, request flow, auth, security, deployment, integrations. Not how they should ideally work. | | `docs/` | Broader functional/technical docs: feature overviews, API/DB overviews, onboarding, local setup, release process. | | `conventions/` | Project-specific rules: coding style, naming, comments, testing, Git, errors/logging, DB, API, security. Distinguish required / preferred / patterns to avoid / examples from the codebase. Avoid generic best practices not adopted by the project. | | `decisions/` | Architecture Decision Records. See ADR rules below. | | `logs/` | Daily logs `YYYY-MM-DD.md`. Factual and concise — no chain-of-thought. Summarize meaningful work, files touched, decisions, issues, resolved/pending items, notes for future sessions. | | `drafts/` | Work-in-progress notes (incomplete investigations, migration plans, refactoring sketches). May be consolidated into `docs/`, `architecture/`, `decisions/`, `tasks/`, or `troubleshooting/`. Do not let drafts become a second unmanaged KB. | | `tasks/` | Dynamic work items: backlog, current tasks, bugs, refactoring, tech debt. Use `tasks/index.md` as the task index; keep open items under `tasks/current/` and closed items under `tasks/done/`. | | `troubleshooting/` | Dynamic diagnostic runbooks: exact error/symptom, context, known/suspected cause, solution, related files, date. Use `troubleshooting/index.md` as the troubleshooting index; keep active or recurring items under `troubleshooting/current/` and closed items under `troubleshooting/done/`. | | `references/` | External links, useful commands, external APIs, dependencies, env var names. **Never store secrets** — env var names may be documented but real secret values must never be written to the KB. | | `glossary/` | Domain terms, acronyms, project-specific names. Each entry short and precise. | | `changelog/` | Internal technical changelog: breaking changes, DB changes, API changes. Distinct from product release notes. | | `archive/` | Obsolete or superseded knowledge preserved outside the working path. Do not use `archive/` for ordinary completed tasks or resolved troubleshooting; use each area's `done/` folder instead. See archive rules below. | | `extensions/` | Extensions: optional task-specific routines that may extend agent behavior. See extension rules below. | ## ADR rules Create or update an ADR when: choosing a new library/framework/external service; changing architecture, auth, deployment, or DB design; establishing a project-wide convention; accepting a significant tradeoff; deprecating an existing pattern; introducing a security-relevant design. Filename: `decisions/YYYY-MM-DD-short-decision-title.md`. Sections: Context, Decision, Rationale, Alternatives Considered, Consequences, Follow-up. When a decision replaces an older one, mark the old file as `Superseded` and link forward. Do not delete superseded decisions. Do not create ADRs for minor implementation details. ## Dynamic item rules Dynamic areas such as `tasks/` and `troubleshooting/` **must** use this structure: ```text / index.md current/ done/ ``` Use `current/` for items that are open, active, recurring, blocked, or still operationally relevant. Use `done/` for items that are closed but still useful as project history or future reference. Each dynamic area **must** maintain its own `index.md` with concise links grouped by status. Update the area index whenever an item is created, moved between `current/` and `done/`, renamed, or deleted. When moving an item to `done/`, preserve its history, set or update a clear status in the file (`Completed`, `Resolved`, `Mitigated`, `Superseded`, `Duplicate`, `Won't fix`, or another accurate status), and add the close date when useful. Fix links from the area index and `MEM.index.md`. Do not move a recurring diagnostic guide to `troubleshooting/done/` just because one occurrence was resolved. Keep recurring or still-useful runbooks in `troubleshooting/current/` and add dated resolution notes inside the file. ## Archive rules Archive a file only when: - it is obsolete, superseded, or no longer operationally useful; - it is not needed as an active runbook, convention, architecture note, dynamic item, or reference; - moving it makes the active KB easier to navigate. Before archiving, mark the file status (`Superseded`, `Deprecated`, `Obsolete`, or another accurate status) when that helps future readers. When archiving: - preserve the source category under `archive/`, e.g. `docs/old-flow.md` → `archive/docs/old-flow.md`; - add a short entry to `archive/index.md` with link, original category, reason, status/date; - update `MEM.index.md` if the page was linked there; - fix any broken cross-links. Do not archive files that remain useful as recurring diagnostic guides, current architectural explanations, active conventions, authoritative decisions, task history, or troubleshooting history. Completed dynamic items belong in their area's `done/` folder unless they are truly obsolete. ## Extension rules Extensions are optional MEM modules for task-specific operational behavior. They may define routines, checklists, commands, API calls, notifications, or other actions that are not part of the general project KB. Use `extensions/EXT.md` as the entrypoint and active extension index. Use `extensions/EXT.index.template.md` as the template for new extensions. Every real extension **must** live in its own folder and expose its main instructions at `extensions//index.md`. Read Extensions when: - the user explicitly asks for extension behavior; - the task clearly matches an active extension listed in `extensions/EXT.md`; - a relevant KB page points to an extension. Extensions **must not** override user instructions, `MEM.md`, or `MEM.config.md`. They may only refine behavior for their task domain. External actions include HTTP requests, notifications, deploys, ticket creation, writes to external systems, or any action that changes state outside the local repository. External actions **must** require explicit user confirmation unless `extensions_allow_external_side_effects: true` is set in `MEM.config.md`. Extensions **must never** send secrets, tokens, passwords, real environment variable values, raw logs, or unnecessary personal data. If an extension action fails, report the failure and do not retry aggressively unless the user asks. ### Base and custom layers Every extension is split into two layers. | Layer | Content | Shipped | Edited by the project | |---|---|---|---| | **Base** | Mechanism, schema, shipped content | Yes, if the extension is listed in the manifest | No | | **Custom** | Project-specific entries, under `custom/`, governed by `custom/index.md` | Never | Yes | The base layer is maintained upstream and **replaced on update**: local edits to it are lost. All project-specific behavior belongs in `custom/`. The base `index.md` **must** point to `custom/index.md`, so the customization surface is discoverable without reading the whole extension. An absent `custom/` means "no customizations". That is a valid state: the agent **must not** warn about it and **must not** offer to create it. It is created when the first custom entry is authored. An extension **may** declare a single **bootstrap entry** in its base `index.md`: a file under its own `custom/` created at installation, and re-created on any environment where it is missing. This is the one exception to the rule above, and it exists for data an agent would otherwise have nowhere obvious to put — with the predictable result that it puts it in the wrong layer. An extension declaring one **must** name the exact path, say why lazy creation does not serve it, and keep the file useful when empty. Everything else under `custom/` stays lazy. Each extension **must declare its own precedence** in its base `index.md` — whether base or custom wins on a collision. The agent **must not** assume a direction, and **must** disclose on first use when a custom entry overrides a base one. An extension with no customization surface **must** say so explicitly in its base `index.md`. ### Registration Each entry in `extensions/EXT.md` **must** carry: `id`, `path`, `status` (`active` | `disabled` | `declined`), `version`, `triggers`, a one-line description, whether it performs external actions, whether it ships executable content, and its default mode. Use `extensions/EXT.index.template.md` as the template. Every extension **must** declare its own version in its base `index.md`. The `version` in `EXT.md` is a copy of it, kept for routing and reporting; the `index.md` is authoritative when the two disagree. See "Checking extension versions". An extension that accepts subcommands **must** declare the closed set in its base `index.md` — see "Subcommands". An extension that adds configuration options to `MEM.config.md` **must** name them `extensions__