Repository navigation
refactor(memory): consolidation gets its own home (code-shape 3/5) - #20
Merged
Merged
Conversation
emanuilo
force-pushed
the
refactor/2-chat-pipeline
branch
from
November 22, 2026 19:21
1d6d9c2 to
0ffa834
Compare
emanuilo
force-pushed
the
refactor/3-consolidation
branch
from
November 22, 2026 19:22
9a145e6 to
729be36
Compare
…solidation.py About 245 lines of MemclawAgent were MEMORY.md consolidation. They are now one class, Consolidator, the only code that writes MEMORY.md. It owns the prompt, the daily-text budget, the .history/ copies, the meta.json marker and the background schedule. Its interface: - consolidate(force=False, since=None): run it now. `memclaw consolidate` calls it through agent.consolidator instead of the private agent._maybe_consolidate (`since` was `consolidated_through_override`). - schedule(): run it in the background after a reply (one at a time, an hour's pause after a failure). - aclose() / cancel(): stop a background run at shutdown. It reaches the LLM through the backend the agent hands it (anything with run_one_shot), so it doesn't import memclaw.backends. It lives in a new memclaw/memory/ package because the top-level folder is full; the coming memory/ package move (store, index, search) joins it there. Guards: a `memory` layer between tools and the core modules, and a new contract that other code imports memclaw.memory, not the modules inside. The concept "MEMORY.md + consolidation" now has memory/consolidation.py as its home. Baseline tightened: agent.py is no longer over 500 lines, MemclawAgent is 303 lines (was 482) with 17 attributes (was 18), and the cli -> agent private access is gone. Behaviour is unchanged: same prompt and message text, same files written, same retry, logs and failure handling (a failed one-shot call still leaves MEMORY.md and meta.json alone). The consolidation tests moved to tests/memory/test_consolidation.py and test Consolidator on its own.
- instructions.py holds what a session is started with: the system-prompt template, loading AGENTS.md and MEMORY.md for it (with the 20,000-char cap), the content hash and instructions_fingerprint. agent.py keeps turn handling: the context block, handle() and the session bookkeeping (348 lines, was 699 before the consolidation move; MemclawAgent is under the 300-line class limit). - memory_refs.py becomes memclaw/memory/refs.py, next to consolidation, its only user. That keeps the top-level folder at 13 modules while instructions.py is added. Guards: instructions joins the core layer; memory.refs joins the modules only memclaw.memory may import. Baseline tightened (MemclawAgent class length, _handle's locals 19 -> 18). Same template text, fingerprint, truncation and session hashes, so saved sessions resume as before. Tests: tests/test_instructions.py (was part of test_agent.py), tests/memory/test_refs.py (was test_memory_refs.py).
emanuilo
force-pushed
the
refactor/3-consolidation
branch
from
November 22, 2026 19:27
729be36 to
4756094
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stack 3/5 of the code-shape restructuring (base: #19). MEMORY.md consolidation gets its own home;
agent.pykeeps only turn handling.Consolidatorgets the LLM as any object withrun_one_shot, somemory/never importsbackends. New contract: other code importsmemclaw.memory, not its modules;memoryis a layer betweentoolsand the core modules.Evidence
.history/copies and pruning,meta.json, failing backend leaves MEMORY.md and meta alone, empty reply, edits during a run, budget, corrupt meta, threshold/since, background schedule, 1-hour retry, one-at-a-time, shutdown cancel, system prompt, fingerprint, session hashes, log messages).Before (1d6d9c2) and after each commit: byte-identical output.
memclaw consolidate(with/without--since, bad date) through click with a fake backend: same output, exit codes and files; only the loguru source location changes.agent.py699 → 348 lines;MemclawAgent482 → 298 lines (under 300); private-access findings 1 → 0; baseline 39 → 35.pytest: 514 passed, 20 skipped (was 501); newtests/memory/test_consolidation.pytestsConsolidatorwithout an agent.ruff,code-shape checkclean.Merge Danger
Door: two-way
Blast Radius: memory consolidation
memclaw.memory_refs→memclaw.memory.refs; consolidation methods leaveMemclawAgent).docs/memory-architecture.mdupdated.Consolidator._replace_memory.🤖 Generated with Claude Code