1033 Commits

Author SHA1 Message Date
nanobot b25c09f5ed feat: extract facts with main agent LLM, bypass mem0 GPT-nano
Build Nanobot OAuth / build (pull_request) Successful in 6m5s
Build Nanobot OAuth / cleanup (pull_request) Has been skipped
Uses the main agent's existing LLM provider to extract facts from
conversations, then stores them with infer=False — bypassing mem0's
default GPT-nano call.

- extract_facts(): sends conversation to provider.chat() with one-liner prompt
- store_facts(): stores each fact via mem0 with infer=False
- consolidate(): calls extract_facts + store_facts instead of add_conversation
2026-03-04 13:50:02 +01:00
code-server 9e8c910ab1 feat: extract facts with main agent LLM, bypass mem0 GPT-nano
Build Nanobot OAuth / build (pull_request) Successful in 6m11s
Build Nanobot OAuth / cleanup (pull_request) Has been skipped
Instead of hacking mem0's provider system, use the main agent's
existing LLM (already running, already paid for) to extract facts
from conversations, then store them with infer=False.

- extract_facts(): sends conversation to provider.chat() with extraction prompt
- store_facts(): stores each fact via mem0 with infer=False
- consolidate(): calls extract_facts + store_facts instead of add_conversation
- No new files, no Dockerfile changes, no mem0 package patches
2026-03-04 13:36:07 +01:00
code-server cc10e20a47 Fix prompt caching: save mem0 to session and add 4-breakpoint strategy
Build Nanobot OAuth / build (push) Successful in 6m10s
Build Nanobot OAuth / cleanup (push) Successful in 0s
**Root cause**: mem0 was being regenerated fresh each turn but never saved
to session, causing it to appear at different positions in the message
history and invalidating the cache prefix.

**Changes**:
1. Save mem0 injections to session (loop.py lines 574-581, 772-781)
   - Fixed array indices: mem0 is at turn_start-3 and turn_start-2
   - Makes mem0 part of immutable history at stable position
2. Add 4th cache breakpoint on message history (anthropic_oauth.py lines 340-368)
   - BP3: Second-to-last user message (reuses BP4 from previous turn)
   - BP4: Last user message (becomes BP3 next turn)
3. Raise clear_tool_uses trigger to 195k tokens (loop.py lines 52-57)
   - Avoids premature cache invalidation for low-tool-use conversations

**Impact**: Cache writes dropped from ~30k to ~300 tokens per turn,
cache reads increased from 12k to 44k (reading full message history).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-04 12:15:53 +00:00
code-server 34ed4345fc fix(bash): use newline separator for sentinel to fix heredoc hangs
Build Nanobot OAuth / build (push) Successful in 6m35s
Build Nanobot OAuth / cleanup (push) Successful in 1s
When the LLM sends heredoc commands (cat << 'EOF'), the semicolon
sentinel (EOF; echo '<<exit>>') prevents bash from recognizing the
terminator, causing the session to hang until the 120s timeout.
Confirmed in production logs: the exact command that caused the hang.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 10:14:13 +00:00
code-server 1a85333e4c fix(provider): add connection diagnostics and client recovery
Build Nanobot OAuth / build (push) Successful in 24m38s
Build Nanobot OAuth / cleanup (push) Successful in 4s
- Add pool timeout (30s) to httpx client
- Add _reset_client() for connection error recovery
- Add _diagnose_connectivity() for ConnectTimeout debugging
- Catch ConnectTimeout/PoolTimeout specifically with diagnostics

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 09:42:51 +00:00
code-server 3c587c788a feat(mem0): expose memory tools to agent + fix consolidation
- Add 6 mem0 tools: memory_search, memory_list, memory_add, memory_update,
  memory_delete, memory_consolidate
- Register conditionally in loop.py when mem0 is enabled
- Inject user context per-message via set_context()
- Add deferred session trim to avoid orphaning tool_use IDs mid-turn
- Fix consolidation: skip tool results (raw output misinterpreted as interests)
- Add time-sensitive fact extraction guidance to custom prompt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 09:42:45 +00:00
code-server 303d123527 fix(bash): rewrite BashTool to use async subprocess, fix thread pool exhaustion
The old implementation used subprocess.Popen with asyncio.to_thread(readline)
in a loop with 1s timeouts. Each timed-out readline leaked a thread into the
default ThreadPoolExecutor. After ~20 leaked threads (from slow commands like
ffmpeg), the pool was completely exhausted — blocking DNS resolution and all
httpx connections indefinitely.

Rewritten to match Anthropic's reference implementation from
anthropic-quickstarts: asyncio.create_subprocess_shell + direct buffer
polling with asyncio.sleep(0.2). Zero threads used.

Also remove obsolete beta_flag from EditTool (no longer needed).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 09:42:37 +00:00
code-server 61c2cb4ac4 Disable computer tool until VM is restored
Build Nanobot OAuth / build (push) Failing after 29m15s
Build Nanobot OAuth / cleanup (push) Has been skipped
The Windows 11 VM configuration was deleted, causing API requests with
the computer tool to hang indefinitely. Commenting out computer tool
registration until VM is restored.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 21:28:13 +00:00
code-server 3126b99fdb debug: log tool names in API requests for diagnostics
Build Nanobot OAuth / build (push) Successful in 23m51s
Build Nanobot OAuth / cleanup (push) Successful in 2s
2026-03-01 19:51:08 +00:00
code-server b28b647ce3 debug: improve exception logging in anthropic_oauth provider
Build Nanobot OAuth / cleanup (push) Has been cancelled
Build Nanobot OAuth / build (push) Has been cancelled
- Add logger.exception() to capture full traceback
- Show exception type and message in error response
- Handle cases where str(e) is empty

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 19:49:03 +00:00
code-server d736f1cf46 Fix: Import logger in commands.py for diagnostic logging
Build Nanobot OAuth / build (push) Successful in 6m32s
Build Nanobot OAuth / cleanup (push) Successful in 2s
2026-03-01 08:27:25 +00:00
code-server e4402f2f83 Add diagnostic logging for mem0 config investigation
Build Nanobot OAuth / cleanup (push) Has been cancelled
Build Nanobot OAuth / build (push) Has been cancelled
- Log mem0_config keys passed from CLI to AgentLoop
- Log config keys received by Mem0MemoryStore
- Log extracted keys for MemoryConfig
- Log vector store provider after MemoryConfig creation
- Log facts extraction count in add_conversation

This instrumentation will reveal where the config chain breaks.
2026-03-01 08:25:22 +00:00
code-server dc5d8edfec feat(mem0): keep tool results and fix consolidation flow
Build Nanobot OAuth / build (push) Successful in 6m4s
Build Nanobot OAuth / cleanup (push) Successful in 0s
- Keep tool results (truncated to 2000 chars) sent as role: "user"
  instead of skipping them entirely. mem0's parse_messages() ignores
  "tool" role, and tool output often contains useful facts (file
  reads, search results, web pages).
- Fix loop.py to call memory.consolidate() and return early when
  using mem0, preventing fallthrough to old MemoryStore logic.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 07:47:18 +00:00
code-server bdc3be650b Fix TypeError in mem0 config dict comprehension
Build Nanobot OAuth / build (push) Successful in 5m55s
Build Nanobot OAuth / cleanup (push) Successful in 0s
Dict comprehension with dict values fails as unhashable.
Replace with explicit loop to extract config fields.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 07:13:01 +00:00
code-server 119de1f347 Implement mem0 fact extraction improvements
Build Nanobot OAuth / cleanup (push) Has been cancelled
Build Nanobot OAuth / build (push) Has been cancelled
Fix A: Message pre-filtering in consolidate()
- Skip tool result messages (bash output, JSON blobs)
- Skip system messages (boilerplate instructions)
- Normalize Anthropic list-format content to plain text
- Skip trivially short messages (<10 chars like /new)

Fix B: Custom extraction prompt tuned for nanobot
- Extract from BOTH user and assistant messages
- 6 comprehensive examples (3 positive, 3 negative)
- Version 1.0 with date stamp
- Handles research, debugging, and technical work patterns

Expected improvement: 0 facts → 15-30 facts per session

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 07:11:19 +00:00
code-server 88f6ecea5a Fix mem0 MemoryConfig initialization
Build Nanobot OAuth / build (push) Successful in 6m4s
Build Nanobot OAuth / cleanup (push) Successful in 1s
- Import MemoryConfig from mem0.configs.base
- Create MemoryConfig object before passing to Memory()
- Fixes AttributeError: 'dict' object has no attribute 'custom_fact_extraction_prompt'

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 06:42:17 +00:00
code-server a0eb6e9dcf Update Dockerfile to install mem0 dependency
Build Nanobot OAuth / build (push) Successful in 22m50s
Build Nanobot OAuth / cleanup (push) Successful in 1s
- Install nanobot with [mem0] extras
- Enables mem0ai and its dependencies in production build

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 05:37:53 +00:00
code-server c987976f82 Add mem0 semantic memory integration
Build Nanobot OAuth / cleanup (push) Has been cancelled
Build Nanobot OAuth / build (push) Has been cancelled
- New Mem0MemoryStore for semantic search with embeddings
- Update ContextBuilder to support mem0 backend
- Add mem0 config to schema
- Pass mem0_config through AgentLoop and CLI
- Add optional dependency mem0ai

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 05:33:09 +00:00
code-server 8116848670 fix: export MemoryTool20250818 from anthropic tools module
Build Nanobot OAuth / build (push) Successful in 48s
Build Nanobot OAuth / cleanup (push) Successful in 0s
The memory.py file was added but not exported in __init__.py,
causing ImportError when enable_memory_tool is True.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-01 00:38:40 +00:00
code-server f6412b8349 feat(config): enable memory tool by default
Build Nanobot OAuth / build (push) Successful in 5m57s
Build Nanobot OAuth / cleanup (push) Successful in 1s
- Change enable_memory_tool default from False to True
- Update tests to reflect new default behavior
- Since this is a personal instance with no other users, opt-out
  makes more sense than opt-in for a requested feature
2026-03-01 00:27:39 +00:00
code-server f1023d9573 feat(cli): wire enable_memory_tool config to AgentLoop
- Pass config.tools.enable_memory_tool to all AgentLoop instances
- Applied to gateway, agent, and cron commands
- Completes config-to-runtime wiring
2026-03-01 00:27:39 +00:00
code-server 39560524f7 feat(agent): add conditional registration for memory tool
- Add enable_memory_tool parameter to AgentLoop.__init__
- Memory tool only registered when flag is True
- 2 new integration tests in test_memory_integration.py, all passing
2026-03-01 00:23:54 +00:00
code-server aec8510d49 feat(config): add enable_memory_tool flag to ToolsConfig
- Add enable_memory_tool field to ToolsConfig (default: False)
- Supports both snake_case and camelCase variants
- 3 new tests in test_memory_config.py, all passing
2026-03-01 00:23:14 +00:00
code-server 9dd9c0a4be feat(memory): implement insert, delete, rename commands
- Insert: add text at specific line number with validation
- Delete: remove files or directories recursively
- Rename: move/rename with collision detection
- All commands follow path security and CLIResult pattern
- 6 new tests in test_memory_commands.py, all passing
- Total 34 memory tests passing
2026-03-01 00:23:14 +00:00
code-server 53391762be feat(memory): implement str_replace command 2026-03-01 00:23:14 +00:00
code-server d2487ec6a3 feat(memory): implement create command 2026-03-01 00:23:14 +00:00
code-server 8e7c6db4b5 feat(memory): implement view command for directories 2026-03-01 00:23:14 +00:00
code-server a16020c4a2 feat(memory): implement view command for files 2026-03-01 00:23:14 +00:00
code-server 83d6e3cd65 feat(memory): implement path security validation 2026-03-01 00:23:06 +00:00
code-server 80e56294f6 fix(bus): add missing typing imports to queue.py
Build Nanobot OAuth / build (push) Successful in 7m16s
Build Nanobot OAuth / cleanup (push) Successful in 1s
Adds missing Callable and Awaitable imports from typing module.
These were referenced in type hints but not imported, causing
NameError at runtime.

Introduced in: e1987c7 (correlation store feature)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:58:18 +00:00
code-server a1823004aa fix(bus): remove orphaned merge conflict marker
Build Nanobot OAuth / cleanup (push) Has been cancelled
Build Nanobot OAuth / build (push) Has been cancelled
Removes leftover git conflict marker from queue.py line 92 that was
preventing module import and container startup.

Root cause: Merge conflict in e1987c7 was not fully resolved.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:53:53 +00:00
code-server 54255c89c4 Replace message chunking with upstream's proven implementation
Build Nanobot OAuth / build (push) Successful in 5m52s
Build Nanobot OAuth / cleanup (push) Successful in 1s
- Switch from sentence-boundary splitting to upstream's simpler approach
- Uses max_len=4000 (safer buffer vs 4096 limit)
- Split priority: line breaks → spaces → hard cut
- Battle-tested implementation from HKUDS/nanobot upstream
- Simpler, more maintainable code
- Works better for both prose and code/logs

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:15 +00:00
code-server 9a7596193f Fix Telegram message chunking for messages >4096 chars
- Add _send_text_chunks method to split messages at sentence boundaries
- Messages exceeding Telegram's 4096 character limit now send as multiple messages
- Per design doc: docs/plans/2026-02-27-openclaw-telegram-features-design.md
- All new tests pass (4/4), no regressions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:15 +00:00
code-server 31a889f9fd Snapshot: All native Anthropic tools implemented
Complete implementation of all three native Anthropic tools:
- bash_20250124: Shell command execution
- text_editor_20250124: File editing operations
- computer_20251124: VNC desktop control (all 17 actions)

Includes provider updates, test improvements, and registry changes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:15 +00:00
code-server 6c0d68cfbb Add all 17 native computer_20251124 actions to VNC tool
Implemented missing actions reported by nanobot:
- scroll (with direction, amount, modifier support)
- zoom (region cropping)
- triple_click, double_click, middle_click
- left_mouse_down, left_mouse_up, left_click_drag
- hold_key (with duration)
- paste (VNC clipboard)
- wait (with duration)

All actions tested and working via VNC at 172.17.0.1::5900.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:15 +00:00
code-server 5234e76c40 fix(tools): add duck typing to registry execute() method
Registry now supports executing both native Anthropic tools (via __call__)
and function tools (via execute). Native tools return ToolResult/CLIResult
objects instead of strings.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:15 +00:00
code-server f048e8cbec test(agent): verify native tools registration
Add test confirming BashTool20250124, EditTool20250728, and
ComputerTool20251124 are registered in AgentLoop on initialization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 9e8d2d4a09 test(agent): add test for media tracking
Verify that screenshots from computer tool are tracked in
media_paths_for_turn and included in OutboundMessage.media.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server aa4393b2eb fix(agent): handle ToolResult in system message handler
Apply same result type handling logic to _process_system_message
to support native tools in subagent/system contexts.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 9fcb1dc4c0 feat(tools): remove ExecTool and EditFileTool
Replaced by BashTool20250124 and EditTool20250728 which provide
better functionality via model-trained behaviors.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server c5f78bf17e feat(agent): register native tools in agent loop
BashTool20250124, EditTool20250728, and ComputerTool20251124 are now
automatically registered alongside existing function tools.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 6003777eda feat(agent): add media tracking for screenshots
Screenshots from computer tool are saved to disk and included in
OutboundMessage.media for channel delivery to users.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server bbfb4a0c2c test(agent): add tests for ToolResult handling in agent loop
Comprehensive tests for:
- ToolResult with output field
- ToolResult with error field
- ToolResult with base64_image field
- CLIResult handling
- Legacy string results (backward compatibility)
- Combined output and error fields

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server b44c94c9cf feat(agent): add ToolResult handling to agent loop
Agent loop now processes ToolResult and CLIResult from native tools,
while maintaining backward compatibility with string results.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 0e16f1bc3d fix(tests): update CLIResult test for new signature
CLIResult now requires exit_code, output, and error fields after
EditTool implementation. Update test to match new signature.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 83fc393359 feat(tools): implement ComputerTool20251124
Add computer_20251124 for VNC desktop control. Supports keyboard,
mouse, and screenshots via vncdotool.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 2e63a09150 test(tools): add missing tests for EditTool20250728
Add test_edit_tool_requires_absolute_path and test_edit_tool_to_params
to complete test coverage per specification.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server 16791c9717 feat: implement EditTool20250728 with view/create/str_replace/insert
- Add text_editor_20250728 native tool
- Support 4 commands: view, create, str_replace, insert
- Require absolute paths for all operations
- Enforce str_replace uniqueness (count == 1)
- Format view output with line numbers
- Return CLIResult with exit_code/output/error
- All 5 tests passing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server a770d8b0f9 feat(tools): implement BashTool20250124 with persistent session
Add Anthropic's native bash_20250124 tool with:
- Persistent bash subprocess (_BashSession)
- Sentinel-based output reading (<<BASH_COMMAND_DONE>>)
- 120s timeout per command
- Session restart capability
- Full test coverage (4 tests)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00
code-server f148ffd7a4 test(provider): improve beta flag test assertion
Make test more specific by expecting exact sorted order
instead of checking both permutations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 23:43:02 +00:00