Repository navigation
refactor: clear the remaining code-shape baseline (18 → 0) - #23
Merged
Merged
Conversation
- mcp_bridge: track whether the listening socket was handed over with a flag instead of setting the local to None, so it keeps its socket type. - claude: claude_models types the effort levels as the SDK's Literal and sdk_effort() narrows a stored level to it before ClaudeAgentOptions.
tools.py (575 lines) held every tool's schema, code and progress label in three parallel lists. Now each kind of tool has its own module (memory, images, files, reminders) listing its tools as Tool records (definition, handler, step label); catalog.py puts them in the same order, so TOOL_DEFINITIONS is unchanged (byte-identical JSON), and executor.py runs a call. ToolExecutor takes a single ToolContext (config, store, index, search, found_images, platform, scheduler, chat_id) instead of seven arguments. The reminder tools get the scheduler and chat from one helper, which also removes their type: ignore comments. Adds tests/test_tools.py pinning every tool's replies (passes on the old and the new code), a tools-via-package import contract, and an upgrading note for the new constructor.
… collector The run-stream loop kept the latest text, the running tool calls and the reported steps in locals; _RunStream now holds them, with one method per step (handle a message, report a step once, warn about unfinished calls), and _count_turns works out the turn count and its warning. New tests pin the logged lines, the text chosen and the turn count; they pass on the old and the new code.
cursor.py (590 lines, a 406-line class with 13 attributes) becomes a package, with the Cursor-only modules moved in beside it: - backend.py: CursorAgentBackend (lifecycle, model selection, turns) - bridge.py: CursorBridge, the shared bridge process (launch, relaunch when it died, drop), and bridge_failed / drain_stderr - agents.py: ChatAgent, one chat's agent (open/resume, send, close), the options and messages it gets, and prompt_once for one-shot calls - configure.py: the memclaw configure questions and the hook install - hooks.py, sdk_adapter.py: moved from cursor_hooks.py and cursor_sdk_adapter.py unchanged Behaviour, prompts, log lines and errors are unchanged. The wizard output with a fake HOME is byte-identical to 89f6ca8 for every scenario tried; a new test pins the hook status logged at start (passes on old and new).
claude.py (762 lines, a 488-line class) becomes a package: - backend.py: ClaudeAgentBackend (settings, /model and /effort, and the turn and one-shot entry points), now 162 lines - cli.py: ClaudeCli, running the CLI: the locked-down options, one connection per chat (connect/resume, reconnect after a model change, reset, shutdown), one-shot calls and the in-process MCP server - replies.py: the stream-json image prompt, and the message loops with one handler per message type (_TurnReply for a turn, OneShotReply for a one-shot call) in place of the nested branches in _query and run_one_shot - settings.py: credential, env, model and effort resolution - cost.py: SessionCosts and the price table - configure.py: the wizard, one function per question (auth mode, credential, model, effort) - models.py: moved from claude_models.py unchanged Prompts, options, log lines and errors are unchanged. New tests pin the turn and one-shot reply reading (pass on 89f6ca8 and now), and the wizard output with a fake HOME is byte-identical to 89f6ca8 in every scenario. The code-shape baseline is now empty.
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
Clears the last 18 code-shape baseline entries.
.code-shape/baseline.jsonis now"entries": {}, with no suppressions, raised limits ortype: ignore.New contract: other code imports
memclaw.tools, not its modules. The backend-internals contract lists the two new packages.Evidence
code-shape checkbaseline 18 entries (file too long 3, class too long 2, cyclomatic 2, cognitive 3, args/positional 2, branches 1, locals 2, attributes 1, mypy 2).After: 0 entries; max file 467 lines, max fan-out 8, mypy 0 errors.
TOOL_DEFINITIONS+ step labels serialized: byte-identical to 89f6ca8.pytest: 603 passed, 20 skipped (was 567).ruff,lint-imports(12 contracts),code-shape checkclean.Merge Danger
Door: two-way
Blast Radius: backends + tools
docs/upgrading.md):ToolExecutor(ToolContext(...)),executor.context.chat_id;claude_models,cursor_hooks,cursor_sdk_adaptermoved inside their packages.ClaudeAgentBackend/CursorAgentBackendimport paths unchanged.tests/e2e/test_retrieval_e2e.pyconstructor update is unverified here (needs real API keys).test_claude.py,test_cursor.py,test_tools.py.🤖 Generated with Claude Code