mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 13:00:45 +08:00
补齐本地 public 工具的 P1/P2/P3 能力。
新增目录列举、文件/目录操作、内容搜索、cwd/env 管理与进程管理工具,并在本地适配层统一实现与测试覆盖,保持风险门控策略一致。 Made-with: Cursor
This commit is contained in:
parent
d8e2f4cacc
commit
75aec2abe4
14 changed files with 684 additions and 4 deletions
47
runtime/tools/public/search_files_tool.py
Normal file
47
runtime/tools/public/search_files_tool.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from oclaw.runtime.tools.base import ToolSpec
|
||||
from oclaw.runtime.tools.local_sdk import get_local_adapter
|
||||
|
||||
|
||||
def search_files_tool() -> ToolSpec:
|
||||
def _handler(args: dict[str, Any]) -> dict[str, Any]:
|
||||
pattern = str(args.get("pattern") or "").strip()
|
||||
root = str(args.get("root") or ".").strip() or "."
|
||||
file_glob = str(args.get("file_glob") or "**/*").strip() or "**/*"
|
||||
regex = bool(args.get("regex", True))
|
||||
max_matches = int(args.get("max_matches") or 200)
|
||||
return get_local_adapter().search_files(
|
||||
root=root,
|
||||
pattern=pattern,
|
||||
file_glob=file_glob,
|
||||
regex=regex,
|
||||
max_matches=max_matches,
|
||||
)
|
||||
|
||||
return ToolSpec(
|
||||
name="search_files",
|
||||
description="Search file contents under a directory (regex or substring).",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"pattern": {"type": "string", "description": "Regex or substring pattern."},
|
||||
"root": {"type": "string", "default": ".", "description": "Root directory to search."},
|
||||
"file_glob": {"type": "string", "default": "**/*", "description": "File glob under root."},
|
||||
"regex": {"type": "boolean", "default": True, "description": "Treat pattern as regex if true."},
|
||||
"max_matches": {"type": "integer", "default": 200, "description": "Max matches to return."},
|
||||
},
|
||||
"required": ["pattern"],
|
||||
"additionalProperties": False,
|
||||
},
|
||||
handler=_handler,
|
||||
tags=frozenset({"public", "local", "workspace", "read"}),
|
||||
risk_level="low",
|
||||
read_only=True,
|
||||
timeout_s=20.0,
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["search_files_tool"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue