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
31 changes: 1 addition & 30 deletions .code-shape/baseline.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
{
"about": "Known shape violations. Shrink it with `code-shape tighten`; never edit by hand to add.",
"entries": {
"complexipy": {
"cognitive-complexity|memclaw/backends/claude.py|ClaudeAgentBackend._query": 39,
"cognitive-complexity|memclaw/backends/claude.py|ClaudeAgentBackend.run_one_shot": 23,
"cognitive-complexity|memclaw/backends/cursor_sdk_adapter.py|collect_run_result": 24
},
"mypy": {
"type-errors|memclaw/backends/claude.py|": 1,
"type-errors|memclaw/backends/mcp_bridge.py|": 1
},
"pylint": {
"class-attributes|memclaw/backends/cursor.py|CursorAgentBackend": 13,
"too-many-locals|memclaw/backends/claude.py|ClaudeAgentBackend.wizard_setup": 17,
"too-many-locals|memclaw/backends/cursor_sdk_adapter.py|collect_run_result": 19
},
"ruff": {
"function-complexity|memclaw/backends/claude.py|ClaudeAgentBackend._query": 13,
"function-complexity|memclaw/backends/cursor_sdk_adapter.py|collect_run_result": 11,
"too-many-args|memclaw/tools.py|ToolExecutor.__init__": 7,
"too-many-branches|memclaw/backends/claude.py|ClaudeAgentBackend._query": 13,
"too-many-positional|memclaw/tools.py|ToolExecutor.__init__": 7
},
"sizes": {
"class-lines|memclaw/backends/claude.py|ClaudeAgentBackend": 488,
"class-lines|memclaw/backends/cursor.py|CursorAgentBackend": 406,
"file-lines|memclaw/backends/claude.py|": 762,
"file-lines|memclaw/backends/cursor.py|": 590,
"file-lines|memclaw/tools.py|": 575
}
},
"entries": {},
"version": 1
}
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ Claude Code uses `.claude/settings.json` automatically: when Claude runs `git co
- **Chat SDKs stay in their platform module**: only the three chat-app 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 (`MemoryStore`, `MemoryIndex`, `HybridSearch`, `Consolidator`, `MemoryVault`, …), not the modules inside (`notes.py`, `index.py`, `search.py`, …). Inside, `vault` (what the one-off `memclaw` commands call) sits on top, `consolidation` and `search` build on `notes` and `index`, never the other way round, and only `index.py` runs SQL on the search index. `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`.
- **Tools through their package**: other code uses what `memclaw.tools` exports (`TOOL_DEFINITIONS`, `ToolExecutor`, `ToolContext`, `describe_tool_call`). Inside, there is one module per kind of tool (`memory.py`, `images.py`, `files.py`, `reminders.py`), each holding its tools' definitions and code; `catalog.py` lists them in order and `executor.py` runs a call.
- **Setup through its package**: other code uses what `memclaw.setup` exports (`run_setup`, `needs_setup`, `print_logo`, `run_doctor`), not `setup/wizard.py` or `setup/doctor.py`.
- **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`.
- **Backends are swappable**: only `memclaw.backends` itself imports the concrete backends (the `claude/` and `cursor/` packages). 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.

If a new dependency between modules is legitimate, move the module to another layer in the same PR; don't add an ignore line.
Expand Down
4 changes: 4 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The store, index and search moved into the `memclaw.memory` package: `from memcl

A custom agent backend's `run_turn` now takes `run_turn(request, tool_executor)`, where `request` is a `memclaw.backends.TurnRequest` holding the fields that used to be keyword arguments (`system_prompt`, `context`, `user_message`, `session_key`, `resume_session_id`, ...). `ModelInfo` lives in `memclaw.backends.model_selection`.

The Claude and Cursor backends are packages now: `ClaudeAgentBackend` and `CursorAgentBackend` import from `memclaw.backends` (or `memclaw.backends.claude` / `memclaw.backends.cursor`) as before. Their internal modules moved inside: `memclaw.backends.claude_models` is `memclaw.backends.claude.models`, `memclaw.backends.cursor_hooks` is `memclaw.backends.cursor.hooks`, and `memclaw.backends.cursor_sdk_adapter` is `memclaw.backends.cursor.sdk_adapter`.

`memclaw.tools` is now a package. `TOOL_DEFINITIONS`, `ToolExecutor` and `describe_tool_call` import from it as before, but `ToolExecutor` takes one `ToolContext` holding what it used to take as arguments: `ToolExecutor(config, store, index, search, found_images, platform=..., scheduler=...)` is now `ToolExecutor(ToolContext(config, store, index, search, found_images, platform=..., scheduler=...))`, and the current chat is `executor.context.chat_id` (was `executor.chat_id`).

## From 2.x to 3.0

```bash
Expand Down
8 changes: 4 additions & 4 deletions memclaw/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .memory import Consolidator, HybridSearch, MemoryIndex, MemoryStore
from .reminders import ReminderScheduler
from .sessions import ChatSessions
from .tools import ToolExecutor
from .tools import ToolContext, ToolExecutor

# Per-turn memory search results. Kept small because every context block
# stays in the session transcript.
Expand Down Expand Up @@ -63,15 +63,15 @@ def __init__(
self.index = MemoryIndex(config)
self.search = HybridSearch(config, self.index)
self._found_images: list[dict] = []
self._tools = ToolExecutor(
self._tools = ToolExecutor(ToolContext(
config=config,
store=self.store,
index=self.index,
search=self.search,
found_images=self._found_images,
platform=platform,
scheduler=scheduler,
)
))
self.backend: AgentBackend = backend or build_backend(config)
self._backend_started = False
self.sessions = ChatSessions(
Expand Down Expand Up @@ -217,7 +217,7 @@ async def _handle(
on_tool: ProgressCallback | None,
) -> tuple[str, list[dict]]:
self._found_images.clear()
self._tools.chat_id = chat_id
self._tools.context.chat_id = chat_id
turn = self.sessions.begin(chat_id)

agent_instructions = load_agent_instructions(self.config)
Expand Down
2 changes: 1 addition & 1 deletion memclaw/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Agent-backend registry.

Each backend module (e.g. `claude.py`) exposes a class that satisfies the
Each backend package (e.g. `claude/`) exposes a class that satisfies the
`AgentBackend` protocol. To register one, add it to `REGISTRY` below.

Selection at runtime is driven by the `AGENT_BACKEND` env var (mirrored on
Expand Down
Loading
Loading