refactor(tools): first-wave simplification of tools/ (file ops split, lazy_deps, code_exec, approval, browser, delegate, mcp, skills, terminal, voice, media)

Behavior-neutral structural pass over tools/*: god-file extractions into
sibling modules (file_operations_common/lint/search, file_tools_paths/
read_tracking/write, code_execution_env/rpc, tool_search_catalog/names/
validation, tts_command_provider, ...), duplicate helper unification,
if/elif -> dispatch tables, dead-code removal, docstring compaction.
Tool schemas (get_tool_definitions) verified byte-identical to base.
This commit is contained in:
Teknium
2026-09-02 09:20:54 -07:00
parent a3d33fe22f
commit d4cec15b47
114 changed files with 18160 additions and 25300 deletions
+18 -26
View File
@@ -33,23 +33,12 @@ BINARY_EXTENSIONS = frozenset({
".lockb", ".dat", ".data",
})
def has_binary_extension(path: str) -> bool:
"""Check if a file path has a binary extension. Pure string check, no I/O."""
dot = path.rfind(".")
if dot == -1:
return False
return path[dot:].lower() in BINARY_EXTENSIONS
# Container document formats (OOXML zip / OLE compound / ODF zip / EPUB zip / RTF)
# that a plain-text write can NEVER produce validly. read_file auto-extracts
# these to readable text (via anydoc for the non-built-in formats), so a model
# that "read" report.docx and then writes the edited text back via
# write_file/patch silently destroys the document.
# PDF is intentionally NOT here: raw PDF syntax is text-authorable, so
# new-file creation is legitimate — only overwrites are dangerous (handled
# separately by the write guard).
# Container document formats (OOXML/ODF/EPUB zips, OLE compound, RTF) that a
# plain-text write can NEVER produce validly. read_file auto-extracts these to
# text, so a model that "read" report.docx and writes the text back via
# write_file/patch silently destroys the document. PDF is deliberately absent:
# raw PDF syntax is text-authorable, so only overwrites are dangerous (handled
# by the write guard via is_pdf_path).
OPAQUE_DOCUMENT_EXTENSIONS = frozenset({
".doc", ".docx", ".docm",
".xls", ".xlsx", ".xlsm", ".xlsb",
@@ -59,17 +48,20 @@ OPAQUE_DOCUMENT_EXTENSIONS = frozenset({
})
def has_opaque_document_extension(path: str) -> bool:
"""True when the path names an opaque container document (.docx etc.).
Pure string check, no I/O.
"""
def _has_extension_in(path: str, extensions: frozenset) -> bool:
"""Pure string check on the final ``.suffix`` (case-insensitive), no I/O."""
dot = path.rfind(".")
if dot == -1:
return False
return path[dot:].lower() in OPAQUE_DOCUMENT_EXTENSIONS
return dot != -1 and path[dot:].lower() in extensions
def has_binary_extension(path: str) -> bool:
return _has_extension_in(path, BINARY_EXTENSIONS)
def has_opaque_document_extension(path: str) -> bool:
"""True when the path names an opaque container document (.docx etc.)."""
return _has_extension_in(path, OPAQUE_DOCUMENT_EXTENSIONS)
def is_pdf_path(path: str) -> bool:
"""True when the path has a .pdf extension. Pure string check, no I/O."""
return path.lower().endswith(".pdf")