mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 07:20:44 +08:00
- Rename platform/ to svc/ to avoid shadowing stdlib platform. - Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths. - tests/conftest: prepend repo root to sys.path (no parent-folder package name). - CI: paths and offline_eval script under repo root. - Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup). - Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Iterable
|
|
|
|
from .models import PLAN_MODE_PLAN
|
|
from runtime.tools.base import ToolRegistry, ToolSpec
|
|
|
|
|
|
_DEFAULT_PLAN_ALLOWLIST = frozenset(
|
|
{
|
|
"read_file",
|
|
"search_files",
|
|
"glob",
|
|
"list_directory",
|
|
"list_workspace_tree",
|
|
"search_files_context",
|
|
"system_time",
|
|
# Plan-mode control tools are non-read-only by design, but must stay callable.
|
|
"enter_plan_mode_v2",
|
|
"exit_plan_mode_v2",
|
|
}
|
|
)
|
|
|
|
|
|
def plan_mode_allowed_tool_names(extra_allowed: Iterable[str] | None = None) -> set[str]:
|
|
out = set(_DEFAULT_PLAN_ALLOWLIST)
|
|
for x in (extra_allowed or []):
|
|
n = str(x or "").strip()
|
|
if n:
|
|
out.add(n)
|
|
return out
|
|
|
|
|
|
def filter_tools_for_mode(
|
|
*,
|
|
registry: ToolRegistry,
|
|
mode: str,
|
|
extra_allowed: Iterable[str] | None = None,
|
|
) -> list[ToolSpec]:
|
|
tools = list(registry.list())
|
|
if str(mode or "").strip().lower() != PLAN_MODE_PLAN:
|
|
return tools
|
|
allow = plan_mode_allowed_tool_names(extra_allowed=extra_allowed)
|
|
out: list[ToolSpec] = []
|
|
for t in tools:
|
|
if t.name in allow or bool(t.is_read_only()):
|
|
out.append(t)
|
|
return out
|
|
|
|
|
|
__all__ = ["filter_tools_for_mode", "plan_mode_allowed_tool_names"]
|
|
|