Skip to content

Your lightweight open-source personal agent.

refactor: remove unused runtime and WebUI helpers (#5999)

chengyongru6ecb74aea964
diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py
index 92e597980..567d213c4 100644
--- a/nanobot/agent/memory.py
+++ b/nanobot/agent/memory.py
@@ -249,9 +249,8 @@ class MemoryStore:
def write_user(self, content: str) -> None:
self.user_file.write_text(content, encoding="utf-8")
- # -- context injection (used by context.py) ------------------------------
-
def get_memory_context(self) -> str:
+ """Return long-term memory formatted for context injection."""
long_term = self.read_memory()
return f"## Long-term Memory\n{long_term}" if long_term else ""
diff --git a/nanobot/agent/subagent.py b/nanobot/agent/subagent.py
index 0a363876f..e41fd166a 100644
--- a/nanobot/agent/subagent.py
+++ b/nanobot/agent/subagent.py
@@ -166,7 +166,7 @@ class SubagentManager:
self._session_tasks: dict[str, set[str]] = {} # session_key -> {task_id, ...}
def runtime_statuses(self) -> Mapping[str, SubagentStatus]:
- """Return the observable task statuses used by runtime-control snapshots."""
+ """Return the observable statuses of all active tasks."""
return self._task_statuses
def statuses_for_session(self, session_key: str | None) -> Mapping[str, SubagentStatus]:
diff --git a/nanobot/channels/websocket/runtime.py b/nanobot/channels/websocket/runtime.py
index 288e88447..05df43843 100644
--- a/nanobot/channels/websocket/runtime.py
+++ b/nanobot/channels/websocket/runtime.py
@@ -877,10 +877,6 @@ class WebSocketChannel(BaseChannel):
return
await self._commands.dispatch(connection, client_id, envelope)
- def _prune_webui_request_operations(self) -> None:
- """Compatibility hook for request-cache boundary tests."""
- self._commands.prune_request_operations()
-
# -- Outbound WebSocket events -----------------------------------------
async def stop(self) -> None:
diff --git a/nanobot/channels/websocket/tests/test_websocket_channel.py b/nanobot/channels/websocket/tests/test_websocket_channel.py
index 803436257..c1f6da937 100644
--- a/nanobot/channels/websocket/tests/test_websocket_channel.py
+++ b/nanobot/channels/websocket/tests/test_websocket_channel.py
@@ -1360,7 +1360,7 @@ def test_webui_request_cache_prunes_expired_completed_but_keeps_pending(
)
operations["fresh"] = SimpleNamespace(completed_at=now - 1)
- channel._prune_webui_request_operations()
+ channel._commands.prune_request_operations()
assert "pending" in operations
assert "expired" not in operations
@@ -1383,7 +1383,7 @@ def test_webui_request_cache_prunes_oldest_completed_at_capacity(
completed_at=now - 1 + index / 1_000
)
- channel._prune_webui_request_operations()
+ channel._commands.prune_request_operations()
assert "pending" in operations
assert "completed-0" not in operations
diff --git a/nanobot/channels/weixin/runtime.py b/nanobot/channels/weixin/runtime.py
index a61e65780..dacd9fe18 100644
--- a/nanobot/channels/weixin/runtime.py
+++ b/nanobot/channels/weixin/runtime.py
@@ -677,23 +677,6 @@ class WeixinChannel(BaseChannel):
return WeixinChannel._is_retryable_http_status(status_code)
return False
- async def _api_get(
- self,
- endpoint: str,
- params: dict[str, Any] | None = None,
- *,
- auth: bool = True,
- extra_headers: dict[str, str] | None = None,
- ) -> dict[str, Any]:
- assert self._client is not None
- url = f"{self.config.base_url}/{endpoint}"
- hdrs = self._make_headers(auth=auth)
- if extra_headers:
- hdrs.update(extra_headers)
- return await self._request_json(
- "GET", url, endpoint=endpoint, params=params, headers=hdrs,
- )
-
async def _api_get_with_base(
self,
*,
diff --git a/nanobot/channels/weixin/tests/test_weixin_channel.py b/nanobot/channels/weixin/tests/test_weixin_channel.py
index 8b5379837..c16db87cb 100644
--- a/nanobot/channels/weixin/tests/test_weixin_channel.py
+++ b/nanobot/channels/weixin/tests/test_weixin_channel.py
@@ -895,7 +895,6 @@ async def test_qr_login_switches_polling_base_url_on_redirect_status(
"ilink_user_id": "wx-user",
},
]
- channel._api_get = AsyncMock(side_effect=list(status_side_effect))
channel._api_get_with_base = AsyncMock(side_effect=list(status_side_effect))
ok = await channel._qr_login()
@@ -929,7 +928,6 @@ async def test_qr_login_redirect_without_host_keeps_current_polling_base_url(
"ilink_user_id": "wx-user",
},
]
- channel._api_get = AsyncMock(side_effect=list(status_side_effect))
channel._api_get_with_base = AsyncMock(side_effect=list(status_side_effect))
ok = await channel._qr_login()
diff --git a/nanobot/utils/file_edit_events.py b/nanobot/utils/file_edit_events.py
index 75ed9b785..0b7287c4a 100644
--- a/nanobot/utils/file_edit_events.py
+++ b/nanobot/utils/file_edit_events.py
@@ -179,14 +179,6 @@ def read_file_snapshot(path: Path, *, max_bytes: int = _MAX_SNAPSHOT_BYTES) -> F
return FileSnapshot(path=path, exists=True, text=text.replace("\r\n", "\n"))
-def line_diff_stats(before: str | None, after: str | None) -> tuple[int, int]:
- """Return ``(added, deleted)`` for a UTF-8 text line-level diff."""
- if before is None or after is None:
- return 0, 0
- diff = FileDiff.from_text(before, after)
- return diff.added, diff.deleted
-
-
def build_unified_diff_payload(
before: str | None,
after: str | None,
diff --git a/nanobot/webui/settings_routes.py b/nanobot/webui/settings_routes.py
index 3512756e6..c04693a2b 100644
--- a/nanobot/webui/settings_routes.py
+++ b/nanobot/webui/settings_routes.py
@@ -583,40 +583,6 @@ class WebUISettingsRouter:
)
)
- _coerce_channel_value = staticmethod(system_domain.coerce_channel_value)
- _assign_channel_config_value = staticmethod(
- system_domain.assign_channel_config_value
- )
-
- def _nanobot_features_payload(self) -> dict[str, Any]:
- return nanobot_features_payload(config_path=self.settings.config.path)
-
- def _nanobot_features_action(
- self,
- action: str,
- query: QueryParams,
- *,
- allow_install: bool = True,
- ) -> dict[str, Any]:
- return self.settings.mutate(
- nanobot_features_action,
- action,
- query,
- allow_install=allow_install,
- )
-
- def _allow_feature_package_install(
- self,
- connection: Any,
- request: WsRequest,
- ) -> bool:
- domain_request = self._domain_request(
- connection,
- request,
- needs_local_browser=True,
- )
- return self._system.allow_feature_package_install(domain_request)
-
async def _handle_mcp_oauth_start(self, request: WsRequest) -> Response:
if not self._authorized(request):
return self._unauthorized()
diff --git a/tests/agent/test_auto_compact.py b/tests/agent/test_auto_compact.py
index ccb5a6dd5..fa2dd72bb 100644
--- a/tests/agent/test_auto_compact.py
+++ b/tests/agent/test_auto_compact.py
@@ -81,7 +81,6 @@ def _make_fake_compact(
summary: str = "Summary.",
on_archive=None,
track_archived: list | None = None,
- track_count: bool = False,
):
state = {"count": 0}
diff --git a/tests/agent/test_subagent_lifecycle.py b/tests/agent/test_subagent_lifecycle.py
index 04da1e767..22d05eda5 100644
--- a/tests/agent/test_subagent_lifecycle.py
+++ b/tests/agent/test_subagent_lifecycle.py
@@ -214,10 +214,14 @@ class TestSpawn:
sm.runner.run = AsyncMock(return_value=AgentRunResult(
final_content="done", messages=[], stop_reason="completed",
))
+ statuses = sm.runtime_statuses()
+ assert not statuses
await sm.spawn("my task", runtime=_runtime())
+ assert len(statuses) == 1
+ assert next(iter(statuses.values())).task_description == "my task"
await _drain_subagent_tasks(sm)
# Status cleaned up after task completes
- assert len(sm._task_statuses) == 0
+ assert not statuses
@pytest.mark.asyncio
async def test_registers_in_session_tasks(self, tmp_path):
diff --git a/tests/utils/test_file_edit_events.py b/tests/utils/test_file_edit_events.py
index 37aceae05..6eb251b03 100644
--- a/tests/utils/test_file_edit_events.py
+++ b/tests/utils/test_file_edit_events.py
@@ -14,7 +14,6 @@ from nanobot.utils.file_edit_events import (
build_file_edit_end_event,
build_file_edit_start_event,
build_unified_diff_payload,
- line_diff_stats,
prepare_file_edit_trackers,
read_file_snapshot,
)
@@ -32,17 +31,19 @@ def _patch_tool(workspace: Path) -> ApplyPatchTool:
return ApplyPatchTool(workspace=workspace)
-def test_line_diff_stats_counts_replacements_insertions_and_deletions() -> None:
- added, deleted = line_diff_stats("a\nb\nc\n", "a\nB\nc\nd\n")
- assert (added, deleted) == (2, 1)
+def test_file_diff_counts_replacements_insertions_and_deletions() -> None:
+ diff = FileDiff.from_text("a\nb\nc\n", "a\nB\nc\nd\n")
+ assert (diff.added, diff.deleted) == (2, 1)
-def test_line_diff_stats_normalizes_crlf() -> None:
- assert line_diff_stats("a\r\nb\r\n", "a\nb\nc\n") == (1, 0)
+def test_file_diff_normalizes_crlf() -> None:
+ diff = FileDiff.from_text("a\r\nb\r\n", "a\nb\nc\n")
+ assert (diff.added, diff.deleted) == (1, 0)
-def test_line_diff_stats_counts_new_file_crlf_lines_once() -> None:
- assert line_diff_stats("", "a\r\nb\r\n") == (2, 0)
+def test_file_diff_counts_new_file_crlf_lines_once() -> None:
+ diff = FileDiff.from_text("", "a\r\nb\r\n")
+ assert (diff.added, diff.deleted) == (2, 0)
@pytest.mark.parametrize("position", [0, 3000, 6000])
@@ -50,19 +51,21 @@ def test_line_diff_stats_counts_new_file_crlf_lines_once() -> None:
("before_text", "after_text", "expected"),
[("old\n", "new\n", (1, 1)), ("", "new\n", (1, 0)), ("old\n", "", (0, 1))],
)
-def test_line_diff_stats_small_edit_in_repeated_lines(
+def test_file_diff_small_edit_in_repeated_lines(
position: int, before_text: str, after_text: str, expected: tuple[int, int],
) -> None:
prefix = "same\n" * position
suffix = "same\n" * (6000 - position)
- assert line_diff_stats(prefix + before_text + suffix, prefix + after_text + suffix) == expected
+ diff = FileDiff.from_text(prefix + before_text + suffix, prefix + after_text + suffix)
+ assert (diff.added, diff.deleted) == expected
def test_sparse_edits_in_repeated_lines_have_compact_diff() -> None:
middle = "same,0\n" * 6000
before = "obsolete,1\n" + middle + "obsolete,2\n"
after = "current,1\n" + middle + "current,2\n"
- assert line_diff_stats(before, after) == (2, 2)
+ diff = FileDiff.from_text(before, after)
+ assert (diff.added, diff.deleted) == (2, 2)
payload = build_unified_diff_payload(before, after)
assert payload is not None and not payload["truncated"]
body = payload["text"].splitlines()[2:]
diff --git a/webui/src/components/workbench/PaneWorkbench.tsx b/webui/src/components/workbench/PaneWorkbench.tsx
index 6fea15564..106d6292a 100644
--- a/webui/src/components/workbench/PaneWorkbench.tsx
+++ b/webui/src/components/workbench/PaneWorkbench.tsx
@@ -688,7 +688,7 @@ export function PaneWorkbench({
className={cn(
"thread-workspace relative flex h-full min-h-0 flex-col overflow-hidden bg-background",
chrome && displayedPanes.length > 1
- && "[--thread-header-position:relative] [--thread-prompt-inset:1rem]",
+ && "[--thread-header-position:relative]",
)}
>
<TooltipProvider>
diff --git a/webui/src/globals.css b/webui/src/globals.css
index a14a7607c..812909c68 100644
--- a/webui/src/globals.css
+++ b/webui/src/globals.css
@@ -37,9 +37,7 @@
--session-handle-lightness: 0.5;
--session-handle-chroma: 0.12;
--temporary-control-active: #ef8e30;
- --temporary-accent: 24 95% 53%;
--temporary-foreground: 17 88% 32%;
- --temporary-border: 17 88% 40%;
--radius: 0.4375rem;
/* Shared shape scale: marks, compact content, controls, and progressively larger surfaces. */
--radius-mark: 0.25rem;
@@ -91,9 +89,7 @@
--session-handle-lightness: 0.75;
--session-handle-chroma: 0.11;
--temporary-control-active: #ef8e30;
- --temporary-accent: 24 95% 53%;
--temporary-foreground: 32 98% 73%;
- --temporary-border: 27 96% 61%;
--sidebar: var(--card);
--sidebar-foreground: 0 0% 98%;
--sidebar-content: 240 3% 84%;
@@ -637,13 +633,11 @@
/* Split content leaves no margin for floating conversation controls. */
.thread-workspace:has([data-file-preview-panel]) > * {
--thread-header-position: relative;
- --thread-prompt-inset: 1rem;
}
/* Keep room for the 49.5rem message column and controls in the side margin. */
@container thread-workspace (max-width: 72rem) {
.thread-workspace > * {
--thread-header-position: relative;
- --thread-prompt-inset: 1rem;
}
}
@@ -1127,7 +1121,6 @@
desktop, 4 columns / 16px gutter on mobile. Rows share the same tracks. */
@layer components {
.settings-grid {
- --settings-baseline: 4px;
--settings-columns: 4;
--settings-gutter: 16px;
--settings-margin: 16px;
diff --git a/webui/src/hooks/useSessions.ts b/webui/src/hooks/useSessions.ts
index f6bc3a821..402800f18 100644
--- a/webui/src/hooks/useSessions.ts
+++ b/webui/src/hooks/useSessions.ts
@@ -1,7 +1,6 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { useClient } from "@/providers/ClientProvider";
-import i18n from "@/i18n";
import {
ApiError,
deleteSession as apiDeleteSession,
@@ -10,7 +9,6 @@ import {
listSessions,
} from "@/lib/api";
import { hasPendingAgentActivity } from "@/lib/activity-timeline";
-import { deriveTitle } from "@/lib/format";
import { projectThreadEvents } from "@/lib/thread-event-projection";
import { webuiThreadCache } from "@/lib/webui-thread-cache";
import { readReloadSessions, writeReloadCache } from "@/lib/reload-cache";
@@ -707,14 +705,3 @@ export function useSessionHistory(key: string | null): {
activeTurnId: state.activeTurnId,
};
}
-
-/** Produce a compact display title for a session. */
-export function sessionTitle(
- session: ChatSummary,
- firstUserMessage?: string,
-): string {
- return deriveTitle(
- session.title || firstUserMessage || session.preview,
- i18n.t("chat.newChat"),
- );
-}
diff --git a/webui/src/lib/api.ts b/webui/src/lib/api.ts
index 6e3d8425a..4551868c1 100644
--- a/webui/src/lib/api.ts
+++ b/webui/src/lib/api.ts
@@ -1088,13 +1088,6 @@ export async function fetchSidebarState(
);
}
-export async function updateSidebarState(
- transport: WebUIMutationTransport,
- state: SidebarStatePayload,
-): Promise<SidebarStatePayload> {
- return mutation<SidebarStatePayload>(transport, "sidebar.update", { state });
-}
-
function modelGenerationSettingsPayload(
configuration: Pick<
ModelConfigurationCreate,
diff --git a/webui/src/tests/api.test.ts b/webui/src/tests/api.test.ts
index 4538c52a3..71a15b6bd 100644
--- a/webui/src/tests/api.test.ts
+++ b/webui/src/tests/api.test.ts
@@ -52,7 +52,6 @@ import {
pollChannelConnect,
startChannelConnect,
updateAutomation,
- updateSidebarState,
updateImageGenerationSettings,
updateModelCallOrder,
updateModelConfiguration,
@@ -1158,7 +1157,7 @@ describe("webui API helpers", () => {
);
});
- it("reads and writes persisted sidebar state", async () => {
+ it("reads persisted sidebar state", async () => {
const state = {
schema_version: 1,
pinned_keys: ["websocket:chat-1"],
@@ -1189,13 +1188,6 @@ describe("webui API helpers", () => {
headers: { Authorization: "Bearer tok" },
}),
);
-
- await updateSidebarState(mutationTransport, state);
- expect(requestMutation).toHaveBeenCalledWith(
- "sidebar.update",
- { state },
- 20_000,
- );
});
it("fetches workspace project state", async () => {
diff --git a/webui/src/tests/useSessions.test.tsx b/webui/src/tests/useSessions.test.tsx
index 3c9357c45..1bd091a07 100644
--- a/webui/src/tests/useSessions.test.tsx
+++ b/webui/src/tests/useSessions.test.tsx
@@ -2,7 +2,7 @@ import { act, renderHook, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
-import { sessionTitle, useSessionHistory, useSessions } from "@/hooks/useSessions";
+import { useSessionHistory, useSessions } from "@/hooks/useSessions";
import * as api from "@/lib/api";
import { webuiThreadCache } from "@/lib/webui-thread-cache";
import { activateReloadCache, clearReloadCache, writeReloadCache } from "@/lib/reload-cache";
@@ -130,28 +130,6 @@ describe("useSessions", () => {
webuiThreadCache.clear();
});
- it("does not use low-information greetings as fallback session titles", () => {
- expect(sessionTitle({
- key: "websocket:chat-hi",
- channel: "websocket",
- chatId: "chat-hi",
- createdAt: "2026-04-16T10:00:00Z",
- updatedAt: "2026-04-16T10:00:00Z",
- title: "",
- preview: "hi",
- })).toBe("New topic");
-
- expect(sessionTitle({
- key: "websocket:chat-work",
- channel: "websocket",
- chatId: "chat-work",
- createdAt: "2026-04-16T10:00:00Z",
- updatedAt: "2026-04-16T10:00:00Z",
- title: "",
- preview: "帮我优化 WebUI 性能",
- })).toBe("帮我优化 WebUI 性能");
- });
-
it("removes a session from the local list after delete succeeds", async () => {
vi.mocked(api.listSessions).mockResolvedValue([
{