From 7e0c1967973585b1b6cb92825913fb543cb7632b Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Sat, 4 Apr 2026 04:49:42 +0000 Subject: [PATCH] fix(memory): repair Dream follow-up paths and move GitStore to utils Made-with: Cursor --- nanobot/agent/memory.py | 3 ++- nanobot/command/builtin.py | 3 ++- nanobot/{agent => utils}/git_store.py | 0 nanobot/utils/helpers.py | 2 +- tests/agent/test_git_store.py | 6 +++--- 5 files changed, 8 insertions(+), 6 deletions(-) rename nanobot/{agent => utils}/git_store.py (100%) diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py index ab7691e86..e2bb9e176 100644 --- a/nanobot/agent/memory.py +++ b/nanobot/agent/memory.py @@ -15,7 +15,7 @@ from nanobot.utils.helpers import ensure_dir, estimate_message_tokens, estimate_ from nanobot.agent.runner import AgentRunSpec, AgentRunner from nanobot.agent.tools.registry import ToolRegistry -from nanobot.agent.git_store import GitStore +from nanobot.utils.git_store import GitStore if TYPE_CHECKING: from nanobot.providers.base import LLMProvider @@ -569,6 +569,7 @@ class Dream: # Git auto-commit (only when there are actual changes) if changelog and self.store.git.is_initialized(): + ts = batch[-1]["timestamp"] sha = self.store.git.auto_commit(f"dream: {ts}, {len(changelog)} change(s)") if sha: logger.info("Dream commit: {}", sha) diff --git a/nanobot/command/builtin.py b/nanobot/command/builtin.py index e961d22b0..206420145 100644 --- a/nanobot/command/builtin.py +++ b/nanobot/command/builtin.py @@ -136,7 +136,8 @@ async def cmd_dream_log(ctx: CommandContext) -> OutboundMessage: content = commit.format(diff) else: # Default: show the latest commit's diff - result = git.show_commit_diff(git.log(max_entries=1)[0].sha) if git.log(max_entries=1) else None + commits = git.log(max_entries=1) + result = git.show_commit_diff(commits[0].sha) if commits else None if result: commit, diff = result content = commit.format(diff) diff --git a/nanobot/agent/git_store.py b/nanobot/utils/git_store.py similarity index 100% rename from nanobot/agent/git_store.py rename to nanobot/utils/git_store.py diff --git a/nanobot/utils/helpers.py b/nanobot/utils/helpers.py index 93f8ce272..d82037c00 100644 --- a/nanobot/utils/helpers.py +++ b/nanobot/utils/helpers.py @@ -457,7 +457,7 @@ def sync_workspace_templates(workspace: Path, silent: bool = False) -> list[str] # Initialize git for memory version control try: - from nanobot.agent.git_store import GitStore + from nanobot.utils.git_store import GitStore gs = GitStore(workspace, tracked_files=[ "SOUL.md", "USER.md", "memory/MEMORY.md", ]) diff --git a/tests/agent/test_git_store.py b/tests/agent/test_git_store.py index 569bf34ab..285e7803b 100644 --- a/tests/agent/test_git_store.py +++ b/tests/agent/test_git_store.py @@ -3,7 +3,7 @@ import pytest from pathlib import Path -from nanobot.agent.git_store import GitStore, CommitInfo +from nanobot.utils.git_store import GitStore, CommitInfo TRACKED = ["SOUL.md", "USER.md", "memory/MEMORY.md"] @@ -181,7 +181,7 @@ class TestShowCommitDiff: class TestCommitInfoFormat: def test_format_with_diff(self): - from nanobot.agent.git_store import CommitInfo + from nanobot.utils.git_store import CommitInfo c = CommitInfo(sha="abcd1234", message="test commit\nsecond line", timestamp="2026-04-02 12:00") result = c.format(diff="some diff") assert "test commit" in result @@ -189,7 +189,7 @@ class TestCommitInfoFormat: assert "some diff" in result def test_format_without_diff(self): - from nanobot.agent.git_store import CommitInfo + from nanobot.utils.git_store import CommitInfo c = CommitInfo(sha="abcd1234", message="test", timestamp="2026-04-02 12:00") result = c.format() assert "(no file changes)" in result