Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .code-shape/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
"cognitive-complexity|memclaw/search.py|HybridSearch._merge": 17
},
"mypy": {
"type-errors|memclaw/agent.py|": 1,
"type-errors|memclaw/backends/claude.py|": 1,
"type-errors|memclaw/backends/mcp_bridge.py|": 1,
"type-errors|memclaw/cli.py|": 2,
"type-errors|memclaw/setup.py|": 5
},
"pylint": {
"class-attributes|memclaw/agent.py|MemclawAgent": 18,
"class-attributes|memclaw/agent.py|MemclawAgent": 17,
"class-attributes|memclaw/backends/cursor.py|CursorAgentBackend": 13,
"too-many-locals|memclaw/agent.py|MemclawAgent._handle": 19,
"too-many-locals|memclaw/agent.py|MemclawAgent._handle": 18,
"too-many-locals|memclaw/backends/claude.py|ClaudeAgentBackend.wizard_setup": 17,
"too-many-locals|memclaw/backends/cursor.py|CursorAgentBackend.run_turn": 20,
"too-many-locals|memclaw/backends/cursor_sdk_adapter.py|collect_run_result": 19,
Expand All @@ -31,7 +30,6 @@
"function-complexity|memclaw/backends/claude.py|ClaudeAgentBackend._query": 13,
"function-complexity|memclaw/backends/cursor_sdk_adapter.py|collect_run_result": 11,
"function-complexity|memclaw/index.py|MemoryIndex.chunk_text": 12,
"private-access|memclaw/cli.py|_maybe_consolidate in consolidate._run": 1,
"too-many-args|memclaw/backends/base.py|AgentBackend.run_turn": 10,
"too-many-args|memclaw/backends/claude.py|ClaudeAgentBackend.run_turn": 10,
"too-many-args|memclaw/backends/cursor.py|CursorAgentBackend.run_turn": 10,
Expand All @@ -40,11 +38,9 @@
"too-many-positional|memclaw/tools.py|ToolExecutor.__init__": 7
},
"sizes": {
"class-lines|memclaw/agent.py|MemclawAgent": 482,
"class-lines|memclaw/backends/claude.py|ClaudeAgentBackend": 501,
"class-lines|memclaw/backends/cursor.py|CursorAgentBackend": 419,
"class-lines|memclaw/index.py|MemoryIndex": 419,
"file-lines|memclaw/agent.py|": 699,
"file-lines|memclaw/backends/claude.py|": 775,
"file-lines|memclaw/backends/cursor.py|": 604,
"file-lines|memclaw/tools.py|": 577,
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ Claude Code uses `.claude/settings.json` automatically: when Claude runs `git co

**memclaw's layout rules** are the import-linter contracts under `[tool.importlinter]` in `pyproject.toml`. `code-shape check` runs them (on their own: `lint-imports`):

- **Layers**: `cli` → `setup` → `bot` → `agent` → `backends` → `tools` → core modules (`search`, `store`, `reminders`, …) → `index` → `openai_client` → `config`. A module may import from layers below it, never above. A new top-level module must be added to a layer.
- **Layers**: `cli` → `setup` → `bot` → `agent` → `backends` → `tools` → `memory` → core modules (`search`, `store`, `reminders`, …) → `index` → `openai_client` → `config`. A module may import from layers below it, never above. A new top-level module must be added to a layer.
- **No cycles inside subpackages** such as `memclaw.backends` and `memclaw.bot`.
- **Chat platforms are independent**: `bot/telegram.py`, `bot/slack.py` and `bot/whatsapp.py` never import each other. What they share (voice to text, link summaries, the prompts, the agent call, reminders) is in `bot/inbound.py`. A new platform is one module with a `run(config)` plus one line in `PLATFORMS` (`bot/__init__.py`); the CLI and the setup wizard start and list platforms only through that registry.
- **Chat SDKs stay in their platform module**: only those three modules import `telegram`, `slack_bolt` or `neonize`.
- **One OpenAI adapter**: only `openai_client.py` imports `openai`; everyone else calls `OpenAIClient`.
- **Memory through its package**: other code uses what `memclaw.memory` exports (`Consolidator`), not the modules inside. `memory/consolidation.py` is the only code that writes MEMORY.md; it reaches the LLM through the backend the agent hands it, so it doesn't import `memclaw.backends`.
- **Backends are swappable**: only `memclaw.backends` itself imports the concrete backend modules (`claude.py`, `cursor.py`, …). Everyone else goes through `memclaw.backends` / `memclaw.backends.base`.
- **`memclaw.defaults` stands alone**: the Cursor hook script there is copied out and run on its own, so it can't import memclaw.

Expand Down
6 changes: 5 additions & 1 deletion docs/memory-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ The system prompt is **static for a session**, so the backend can prompt-cache i
2. Reply-formatting rules and a description of the per-message context block.
3. **MEMORY.md** — your permanent memory (see Permanent Memory in the Prompt below).

The template, and the fingerprint described above, are in `memclaw/instructions.py`.

Everything that changes per turn goes at the **top of the user message**, in a compact `<context>` block:

- The current local date and time (used for dates and reminders).
Expand Down Expand Up @@ -121,10 +123,12 @@ Today's file is never consolidated: it is still being written to, and marking it
- existing facts and references stay unless updated or expired;
- left out entirely: expired one-offs (verification codes, past events, finished trips' bookings), links saved to read later (they stay searchable), instructions for the assistant (they belong in AGENTS.md), small talk.

A wrapping ```` ``` ```` fence in the reply is stripped, and every reference is checked: one to a note that doesn't exist is dropped, one whose note shares no word with the line is logged as unconfirmed.
A wrapping ```` ``` ```` fence in the reply is stripped, and every reference is checked: one to a note that doesn't exist is dropped, one whose note shares no word with the line is logged as unconfirmed (`memclaw/memory/refs.py`).
4. Saves a dated copy of the previous MEMORY.md in `.history/` (the last 60 are kept; the hidden directory isn't indexed or reachable by the file tools), then overwrites MEMORY.md with the result. Lines appended by hand while the backend was working are carried over below the result; if MEMORY.md was otherwise edited meanwhile, nothing is written and consolidation retries later.
5. Records the date of the last file it included in `meta.json` so those files aren't processed again.

All of this is `Consolidator` in `memclaw/memory/consolidation.py`, the only code that writes MEMORY.md. The agent creates it and calls `schedule()` after each reply; `memclaw consolidate` calls `consolidate(force=True, since=...)`.

The result aims for about 6,000 characters, with absolute dates, in the language MEMORY.md already uses (English when it starts empty).

### Permanent Memory in the Prompt
Expand Down
Loading
Loading