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
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ dev = [

[tool.coverage.run]
source = ["src/mitocode"]
omit = [
"src/mitocode/tui/*",
"src/mitocode/__main__.py",
"src/mitocode/backend/chat_provider/scenario_provider.py",
]

[tool.pyright]
typeCheckingMode = "standard"
Expand Down
2 changes: 1 addition & 1 deletion src/mitocode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
APP_VERSION = 2
MITOCODE_CONFIG_PATH = ".mitocode"

from mitocode.backend.agent import SessionFactory, AgentOrchestrator
from mitocode.core.agent import SessionFactory, AgentOrchestrator

__all__ = [
"APP_VERSION",
Expand Down
8 changes: 4 additions & 4 deletions src/mitocode/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from httpx import stream

from mitocode.backend.agent.agent_orchestrator import AgentOrchestrator
from mitocode.backend.chat_provider.scenario_provider import ScenarioProvider
from mitocode.backend.chat_provider.chat_provider_openai import ChatProviderOpenAI
from mitocode.backend.tool.tool_manager import ToolManager
from mitocode.core.agent.agent_orchestrator import AgentOrchestrator
from mitocode.core.chat_provider.scenario_provider import ScenarioProvider
from mitocode.core.chat_provider.chat_provider_openai import ChatProviderOpenAI
from mitocode.core.tool.tool_manager import ToolManager
from mitocode.tui.ui_main import VibeFrontend


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Backend layer for MitoCode"""

from mitocode.backend.agent import (
from mitocode.core.agent import (
AgentNode,
AgentOrchestrator,
AgentRuntime,
Expand All @@ -11,7 +11,7 @@
ToolSpec,
declare_tool,
)
from mitocode.backend.bridge import EventBridge
from mitocode.core.bridge import EventBridge

__all__ = [
"AgentNode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
and the session factory used to build agent sessions.
"""

from mitocode.backend.tool.tool_manager import ToolManager, ToolSpec, declare_tool
from mitocode.core.tool.tool_manager import ToolManager, ToolSpec, declare_tool
from .agent_node import AgentNode
from .agent_orchestrator import AgentOrchestrator
from .agent_runtime import AgentRuntime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from loguru import logger as loguru_logger

from mitocode.backend.tool.tool_manager import ToolManager
from mitocode.core.tool.tool_manager import ToolManager

from .agent_node import AgentNode
from .agent_state import AgentState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from openai.pagination import AsyncPage
from openai.types import Model

from mitocode.backend.exception.mitocode_exception import (
from mitocode.core.exception.mitocode_exception import (
MitoCodeChatProviderModelError,
)
from .sample_chat_provider import _SampleChatProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from abc import abstractmethod, ABC
from typing import List, Dict, Optional, Any, AsyncGenerator

from mitocode.backend.exception.mitocode_exception import (
from mitocode.core.exception.mitocode_exception import (
MitoCodeChatProviderConfigError,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from types import SimpleNamespace
from typing import Any, Dict, List, Optional, AsyncGenerator

from mitocode.backend.chat_provider.sample_chat_provider import _SampleChatProvider
from mitocode.core.chat_provider.sample_chat_provider import _SampleChatProvider


def _make_chunk(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MitoCodeMcpConnectionError(MitoCodeMcpError):
"""Reserved for when an MCP connection cannot be established or is lost.

Nothing raises it yet, and that is deliberate rather than an oversight:
:class:`~mitocode.backend.mcp.mcp_client.McpClient` records a failed
:class:`~mitocode.core.mcp.mcp_client.McpClient` records a failed
connection in ``state``/``last_error`` and returns ``False``, because one
unreachable server must not abort the startup of the servers that work.
Turning that into an exception belongs to whichever layer turns connection
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from fastmcp import Client
from fastmcp.exceptions import ToolError

from mitocode.backend.exception.mitocode_exception import MitoCodeMcpToolCallError
from mitocode.backend.mcp.mcp_config import McpServerConfig
from mitocode.core.exception.mitocode_exception import MitoCodeMcpToolCallError
from mitocode.core.mcp.mcp_config import McpServerConfig

#: Stands in for an argument payload that has been cut out of error text.
_REDACTED = "<redacted>"
Expand Down Expand Up @@ -113,7 +113,7 @@ def _scrub_endpoint(text: str) -> str:

A remote MCP endpoint may legitimately carry a secret in its userinfo, its
query string or its fragment — ``?access_token=…`` is common enough that
:class:`~mitocode.backend.mcp.mcp_config.McpServerConfig` has to accept it
:class:`~mitocode.core.mcp.mcp_config.McpServerConfig` has to accept it
— and a handshake failure routinely quotes the endpoint it was made
against, in text that reaches the TUI error pane and the log. The MCP SDK
strips the same parts from the URLs *it* builds, but nothing strips them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from enum import Enum
from typing import Any, Dict, List, NoReturn

from mitocode.backend.exception.mitocode_exception import MitoCodeMcpConfigError
from mitocode.core.exception.mitocode_exception import MitoCodeMcpConfigError

try:
from fastmcp.client.transports import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Lifecycle management for the set of configured MCP servers.

:class:`McpManager` owns one :class:`~mitocode.backend.mcp.mcp_client.McpClient`
:class:`McpManager` owns one :class:`~mitocode.core.mcp.mcp_client.McpClient`
per configured server and decides when each of them starts, refreshes and
stops. It takes no interest in what those tools look like: registration is
delegated to :meth:`ToolManager.register_mcp_client`, which namespaces each
Expand Down Expand Up @@ -33,18 +33,18 @@

from loguru import logger as loguru_logger

from mitocode.backend.exception.mitocode_exception import MitoCodeMcpConfigError
from mitocode.backend.mcp.mcp_client import McpClient, _scrub_endpoint
from mitocode.backend.mcp.mcp_config import McpServerConfig
from mitocode.core.exception.mitocode_exception import MitoCodeMcpConfigError
from mitocode.core.mcp.mcp_client import McpClient, _scrub_endpoint
from mitocode.core.mcp.mcp_config import McpServerConfig

if TYPE_CHECKING:
# The tool layer is reached only through the object handed in, never by
# importing it: the dependency runs one way, tool_manager -> mcp. A runtime
# import here would make mitocode.backend.mcp unimportable on its own and
# import here would make mitocode.core.mcp unimportable on its own and
# would break the symmetry with tool_manager's own TYPE_CHECKING guard for
# McpClient. The annotation is quoted because this module has no
# `from __future__ import annotations`, so annotations are evaluated.
from mitocode.backend.tool.tool_manager import ToolManager
from mitocode.core.tool.tool_manager import ToolManager

logger = loguru_logger.bind(name=__name__)

Expand Down Expand Up @@ -185,8 +185,8 @@ def __init__(

The tool registry is held as a duck-typed object: the module never
imports the tool layer, so any object exposing
:meth:`~mitocode.backend.tool.tool_manager.ToolManager.register_mcp_client`
and :meth:`~mitocode.backend.tool.tool_manager.ToolManager.unregister`
:meth:`~mitocode.core.tool.tool_manager.ToolManager.register_mcp_client`
and :meth:`~mitocode.core.tool.tool_manager.ToolManager.unregister`
will do.

Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
types = None
UnionType = Union

from mitocode.backend.exception.mitocode_exception import MitoCodeToolDefinitionError
from mitocode.core.exception.mitocode_exception import MitoCodeToolDefinitionError

if TYPE_CHECKING:
# Imported for type checking only. The runtime stays on duck typing so
# this module keeps importing in an environment without fastmcp installed.
from mitocode.backend.mcp.mcp_client import McpClient
from mitocode.core.mcp.mcp_client import McpClient

logger = loguru_logger.bind(name=__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from typing import Union, Callable, Awaitable
from mitocode import APP_VERSION, MITOCODE_CONFIG_PATH
from mitocode.backend.exception.mitocode_exception import (
from mitocode.core.exception.mitocode_exception import (
MitoCodeWorkspaceInitError,
MitoCodePathConvertError,
MitoCodeMigrateError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Union, Awaitable

from mitocode import MITOCODE_CONFIG_PATH, APP_VERSION
from mitocode.backend.exception.mitocode_exception import (
from mitocode.core.exception.mitocode_exception import (
MitoCodePathConvertError,
MitoCodeWorkspaceInitError,
MitoCodeWorkspaceDumpError,
Expand Down
2 changes: 1 addition & 1 deletion src/mitocode/tui/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from textual.widgets import Tree
from textual.widgets._tree import TreeNode

from mitocode.backend.agent.agent_orchestrator import AgentOrchestrator
from mitocode.core.agent.agent_orchestrator import AgentOrchestrator

STATUS_ICONS = {
"idle": "\u26aa",
Expand Down
8 changes: 4 additions & 4 deletions test/test_agent_runtime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""AgentRuntime 模块单元测试套件。

覆盖 src/mitocode/backend/agent/agent_runtime.py 的全部行为分支:
覆盖 src/mitocode/core/agent/agent_runtime.py 的全部行为分支:
_invoke_tool / _invoke_on_end 的协程与线程分发规则、run() 主循环的
文本流式事件、按 index 聚合并行工具调用、分片 id/name 同步、
工具执行五分支(解析失败/未注册/TypeError/异常/成功)、on_end 回调时序、
Expand All @@ -18,9 +18,9 @@

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))

from mitocode.backend.agent.agent_runtime import AgentRuntime
from mitocode.backend.agent.agent_session import AgentSession
from mitocode.backend.chat_provider.sample_chat_provider import _SampleChatProvider
from mitocode.core.agent.agent_runtime import AgentRuntime
from mitocode.core.agent.agent_session import AgentSession
from mitocode.core.chat_provider.sample_chat_provider import _SampleChatProvider

# ──────────────────────────────────────────────
# 常量
Expand Down
12 changes: 6 additions & 6 deletions test/test_agent_session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""AgentSession 模块单元测试套件。

覆盖 src/mitocode/backend/agent/agent_session.py 的全部行为分支:
覆盖 src/mitocode/core/agent/agent_session.py 的全部行为分支:
消息块三兄弟(文本/工具调用/工具结果)的构造与转换、AgentSession 构造校验、
托管/用户工具合并规则、文档查询委托、协作式取消、流式增量聚合、
标准上下文编译以及 TUI 节点快照映射。
Expand All @@ -14,24 +14,24 @@

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))

from mitocode.backend.agent.agent_session import (
from mitocode.core.agent.agent_session import (
AgentSession,
_MessageBlock,
_PlainTextMessageBlock,
_ToolCallMessageBlock,
_ToolResultMessageBlock,
)
from mitocode.backend.agent.agent_state import AgentState
from mitocode.backend.chat_provider.sample_chat_provider import _SampleChatProvider
from mitocode.backend.tool.tool_manager import ToolManager
from mitocode.core.agent.agent_state import AgentState
from mitocode.core.chat_provider.sample_chat_provider import _SampleChatProvider
from mitocode.core.tool.tool_manager import ToolManager

TOOL_NAME_WEATHER = "get_weather"
CALL_ID_PRIMARY = "call_001"
CALL_ID_SECONDARY = "call_002"
VALID_JSON_ARGS = '{"city": "Beijing"}'
INVALID_JSON_ARGS = "{这不是JSON"
LIST_JSON_ARGS = "[1, 2]"
LOGGER_PATCH_TARGET = "mitocode.backend.agent.agent_session.logger"
LOGGER_PATCH_TARGET = "mitocode.core.agent.agent_session.logger"


# ──────────────────────────────────────────────
Expand Down
8 changes: 4 additions & 4 deletions test/test_mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))

from mitocode.backend.exception.mitocode_exception import MitoCodeMcpToolCallError
from mitocode.backend.mcp.mcp_client import (
from mitocode.core.exception.mitocode_exception import MitoCodeMcpToolCallError
from mitocode.core.mcp.mcp_client import (
McpClient,
McpConnectionState,
_redact_arguments,
_scrub_endpoint,
)
from mitocode.backend.mcp.mcp_config import McpServerConfig
from mitocode.core.mcp.mcp_config import McpServerConfig


def _server() -> FastMCP:
Expand Down Expand Up @@ -323,7 +323,7 @@ async def test_connect_failure_never_echoes_a_credential_in_the_endpoint():
``McpServerConfig`` deliberately permits ``?access_token=…``, and a server
or proxy that fails the handshake routinely quotes the endpoint it was
called on — including its query string. That text ends up in ``last_error``,
which :meth:`~mitocode.backend.mcp.mcp_manager.McpManager.status` publishes
which :meth:`~mitocode.core.mcp.mcp_manager.McpManager.status` publishes
verbatim and the TUI pane an operator reads. The scrubbing is therefore
pinned against a *real* transport, not a hand-written exception: the
assertion has to survive whatever the MCP SDK chooses to put in the message.
Expand Down
10 changes: 5 additions & 5 deletions test/test_mcp_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Unit tests for :mod:`mitocode.backend.mcp.mcp_config`.
"""Unit tests for :mod:`mitocode.core.mcp.mcp_config`.

The module is pure: it normalises a ``{"mcpServers": {...}}`` document into
frozen :class:`McpServerConfig` values and assembles a fastmcp transport
Expand Down Expand Up @@ -63,9 +63,9 @@

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))

from mitocode.backend.exception.mitocode_exception import MitoCodeMcpConfigError
from mitocode.backend.mcp import mcp_config
from mitocode.backend.mcp.mcp_config import McpServerConfig, McpServerKind
from mitocode.core.exception.mitocode_exception import MitoCodeMcpConfigError
from mitocode.core.mcp import mcp_config
from mitocode.core.mcp.mcp_config import McpServerConfig, McpServerKind

# A valid https endpoint used wherever the transport selector is incidental.
HTTP_ENDPOINT = "https://weather.example.com/mcp"
Expand All @@ -79,7 +79,7 @@


def test_mcp_config_error_is_a_mitocode_base_error():
from mitocode.backend.exception.mitocode_exception import MitoCodeMcpError
from mitocode.core.exception.mitocode_exception import MitoCodeMcpError

assert issubclass(MitoCodeMcpConfigError, MitoCodeMcpError)

Expand Down
Loading
Loading