diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Code/refactor.py b/Brain_O_Codebase/brain_v0_5/Tools/Code/refactor.py new file mode 100644 index 0000000000000000000000000000000000000000..ba95d3543158be68f5ef8afb09bb3401758f7e77 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Code/refactor.py @@ -0,0 +1 @@ +"""Code intelligence: refactor.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Code/reference_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Code/reference_search.py new file mode 100644 index 0000000000000000000000000000000000000000..9837d9ba814d63ee86fa290caed60b709ed7e647 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Code/reference_search.py @@ -0,0 +1 @@ +"""Code intelligence: reference_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Code/rename_symbol.py b/Brain_O_Codebase/brain_v0_5/Tools/Code/rename_symbol.py new file mode 100644 index 0000000000000000000000000000000000000000..2c9d85108d5f8690e926e36ac08ab8159b9ad2a1 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Code/rename_symbol.py @@ -0,0 +1 @@ +"""Code intelligence: rename_symbol.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Code/static_analysis.py b/Brain_O_Codebase/brain_v0_5/Tools/Code/static_analysis.py new file mode 100644 index 0000000000000000000000000000000000000000..6c60db604fb05c56bc0a717a49f09567a32becb9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Code/static_analysis.py @@ -0,0 +1 @@ +"""Code intelligence: static_analysis.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Code/symbol_index.py b/Brain_O_Codebase/brain_v0_5/Tools/Code/symbol_index.py new file mode 100644 index 0000000000000000000000000000000000000000..ddc648f223bba00ef96ee2e844662e82e594a949 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Code/symbol_index.py @@ -0,0 +1 @@ +"""Code intelligence: symbol_index.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Code/test_generator.py b/Brain_O_Codebase/brain_v0_5/Tools/Code/test_generator.py new file mode 100644 index 0000000000000000000000000000000000000000..70b34f61912a23cf73f6a0cf533fdaba6250fccf --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Code/test_generator.py @@ -0,0 +1 @@ +"""Code intelligence: test_generator.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..081e09b69eca9c937e50c09447f8831fcf853db2 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/__init__.py @@ -0,0 +1,12 @@ +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult +def webhook_post(ctx=None, url: str = "", body: str = "", **kw): + try: + import urllib.request + req = urllib.request.Request(url, data=body.encode(), method="POST", headers={"Content-Type":"application/json"}) + with urllib.request.urlopen(req, timeout=20) as r: + return ToolResult("webhook_post", True, r.read(5000).decode("utf-8", errors="ignore")) + except Exception as e: + return ToolResult("webhook_post", False, str(e), error_type="runtime") +def register(registry): + registry.register(make_tool("webhook_post", "POST JSON webhook", {"url":{"type":"string","required":True},"body":{"type":"string","required":True}}, webhook_post, "communication", "net:write", parallel_safe=False)) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/calendar.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/calendar.py new file mode 100644 index 0000000000000000000000000000000000000000..1da9ead3fd02d784f032d34efa1aa6ba5c78de06 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/calendar.py @@ -0,0 +1 @@ +"""Communication: calendar.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/discord.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/discord.py new file mode 100644 index 0000000000000000000000000000000000000000..e55d3a7cc1c140fbfb6224da5b4770eb19aecc2c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/discord.py @@ -0,0 +1 @@ +"""Communication: discord.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/email.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/email.py new file mode 100644 index 0000000000000000000000000000000000000000..55e46bfa74f516e098613e15745e042872c19347 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/email.py @@ -0,0 +1 @@ +"""Communication: email.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/messaging.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/messaging.py new file mode 100644 index 0000000000000000000000000000000000000000..5cc17c97bda3044cf4610c84733ef33d0ae5c237 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/messaging.py @@ -0,0 +1 @@ +"""Communication: messaging.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/notifications.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/notifications.py new file mode 100644 index 0000000000000000000000000000000000000000..2fb1e9ace6ee2dc3f5a8f63b8fd6d066fc73e2cb --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/notifications.py @@ -0,0 +1 @@ +"""Communication: notifications.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/slack.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/slack.py new file mode 100644 index 0000000000000000000000000000000000000000..a949eb9fefc2ed5d51efbdb21ec7ee99bc03d522 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/slack.py @@ -0,0 +1 @@ +"""Communication: slack.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/sms.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/sms.py new file mode 100644 index 0000000000000000000000000000000000000000..3f146f1ca174e6c139655e8da5d0ab061a95c9b8 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/sms.py @@ -0,0 +1 @@ +"""Communication: sms.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/teams.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/teams.py new file mode 100644 index 0000000000000000000000000000000000000000..bb06d885eeae86ce132a3199d87e9d2f11ec8915 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/teams.py @@ -0,0 +1 @@ +"""Communication: teams.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Communication/webhook.py b/Brain_O_Codebase/brain_v0_5/Tools/Communication/webhook.py new file mode 100644 index 0000000000000000000000000000000000000000..c7eb101c614f9a244f413a1723e0d5c81eb8e4a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Communication/webhook.py @@ -0,0 +1 @@ +"""Communication: webhook.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..72c919477fb28616571bbd7d47a1e2dc9b876172 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/__init__.py @@ -0,0 +1,11 @@ +from Tools.Core.tool_engine import ToolEngine +from Tools.Core.tool_manager import ToolManager +from Tools.Core.tool_registry import ToolRegistry, ToolSpec +from Tools.Core.tool_result import ToolResult +from Tools.Core.tool_context import ToolContext +from Tools.Core.tool_router import parse_tool_calls + +__all__ = [ + "ToolEngine", "ToolManager", "ToolRegistry", "ToolSpec", + "ToolResult", "ToolContext", "parse_tool_calls", +] diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/capability_registry.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/capability_registry.py new file mode 100644 index 0000000000000000000000000000000000000000..12c0a74dd8c0ea59c97180be92ce56e81dfe751e --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/capability_registry.py @@ -0,0 +1,14 @@ +"""Map high-level capabilities to tool names.""" +from __future__ import annotations + +CAPABILITIES = { + "read_code": ["read_file", "list_directory", "search_files", "code_search"], + "edit_code": ["write_file", "edit_file", "replace_text"], + "run_tests": ["run_terminal", "python_unit_test"], + "search_web": ["web_search", "web_open"], + "git": ["git_status", "git_diff", "git_commit"], + "docs": ["pdf_read", "docx_read", "xlsx_read"], +} + +def tools_for(capability: str) -> list[str]: + return list(CAPABILITIES.get(capability, [])) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/dependency_manager.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/dependency_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..dc76137cc4a8f31338bd051c8a5eb7b9298a0a05 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/dependency_manager.py @@ -0,0 +1,12 @@ +"""Declare tool dependencies (soft).""" +from __future__ import annotations + +# tool -> required tools that should exist +DEPS = { + "refactor": ["read_file", "write_file"], + "test_generator": ["read_file", "python_unit_test"], + "patch_generator": ["read_file", "git_diff"], +} + +def missing_deps(available: set[str], tool: str) -> list[str]: + return [d for d in DEPS.get(tool, []) if d not in available] diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_cache.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_cache.py new file mode 100644 index 0000000000000000000000000000000000000000..a7c025fa392a2fe519dc49369be3d00cdbe398b1 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_cache.py @@ -0,0 +1,28 @@ +"""Simple in-memory result cache for idempotent tools.""" +from __future__ import annotations +import hashlib, json, time +from typing import Any, Optional +from Tools.Core.tool_result import ToolResult + +class ToolCache: + def __init__(self, ttl_s: float = 300.0): + self.ttl_s = ttl_s + self._store: dict[str, tuple[float, ToolResult]] = {} + + def _key(self, name: str, arguments: dict) -> str: + raw = name + json.dumps(arguments, sort_keys=True, default=str) + return hashlib.sha256(raw.encode()).hexdigest() + + def get(self, name: str, arguments: dict) -> Optional[ToolResult]: + k = self._key(name, arguments) + item = self._store.get(k) + if not item: + return None + ts, res = item + if time.time() - ts > self.ttl_s: + del self._store[k] + return None + return res + + def set(self, name: str, arguments: dict, result: ToolResult) -> None: + self._store[self._key(name, arguments)] = (time.time(), result) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_context.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_context.py new file mode 100644 index 0000000000000000000000000000000000000000..5988e123c700c278e32ef17bf219fd4282f564bf --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_context.py @@ -0,0 +1,18 @@ +"""Execution context passed into every tool call.""" +from __future__ import annotations +from dataclasses import dataclass, field +from pathlib import Path +from typing import Any, Optional + +@dataclass +class ToolContext: + cwd: Path = field(default_factory=lambda: Path.cwd()) + workspace_root: Optional[Path] = None + session_id: str = "default" + user_id: Optional[str] = None + permissions: set[str] = field(default_factory=lambda: {"fs:read", "fs:write", "fs:delete", "terminal:run", "python:eval", "net:read", "net:write", "git:write", "db:write"}) + env: dict[str, str] = field(default_factory=dict) + extra: dict[str, Any] = field(default_factory=dict) + + def has(self, perm: str) -> bool: + return perm in self.permissions or "*" in self.permissions diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_discovery.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_discovery.py new file mode 100644 index 0000000000000000000000000000000000000000..d6e6c78084d34becd4302297469b4b5c47bab18c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_discovery.py @@ -0,0 +1,12 @@ +"""List tools by capability tags.""" +from __future__ import annotations +from Tools.Core.tool_registry import ToolRegistry + +def discover(registry: ToolRegistry, query: str = "") -> list[str]: + q = query.lower().strip() + out = [] + for t in registry.list_tools(): + blob = f"{t.name} {t.description} {t.category}".lower() + if not q or q in blob: + out.append(t.name) + return out diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_engine.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_engine.py new file mode 100644 index 0000000000000000000000000000000000000000..1cb257c78269b19353e092aea69da14753435148 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_engine.py @@ -0,0 +1,27 @@ +"""Top-level tool engine used by agents.""" +from __future__ import annotations +from concurrent.futures import ThreadPoolExecutor, as_completed +from typing import Any +from Tools.Core.tool_manager import ToolManager +from Tools.Core.tool_result import ToolResult +from Tools.Core.tool_context import ToolContext + +class ToolEngine: + def __init__(self, context: ToolContext | None = None): + self.manager = ToolManager(context=context) + + def run(self, name: str, arguments: dict[str, Any] | None = None) -> ToolResult: + return self.manager.executor.run(name, arguments or {}) + + def run_many(self, calls: list[dict[str, Any]], parallel: bool = True) -> list[ToolResult]: + if not parallel or len(calls) <= 1: + return [self.run(c["name"], c.get("arguments") or {}) for c in calls] + results: list[ToolResult | None] = [None] * len(calls) + with ThreadPoolExecutor(max_workers=min(8, len(calls))) as ex: + futs = {ex.submit(self.run, c["name"], c.get("arguments") or {}): i for i, c in enumerate(calls)} + for fut in as_completed(futs): + results[futs[fut]] = fut.result() + return [r for r in results if r is not None] + + def schemas(self) -> str: + return self.manager.prompt_schemas() diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_executor.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_executor.py new file mode 100644 index 0000000000000000000000000000000000000000..79e4d00195d7320e454a7393105d08a9bf77aee9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_executor.py @@ -0,0 +1,48 @@ +"""Execute a single tool call with validation, permissions, timing.""" +from __future__ import annotations +import time +from typing import Any +from Tools.Core.tool_registry import ToolRegistry, ToolSpec +from Tools.Core.tool_result import ToolResult +from Tools.Core.tool_context import ToolContext +from Tools.Core.tool_validator import validate_args + +class ToolExecutor: + def __init__(self, registry: ToolRegistry, context: ToolContext | None = None): + self.registry = registry + self.context = context or ToolContext() + + def run(self, name: str, arguments: dict[str, Any] | None = None) -> ToolResult: + arguments = arguments or {} + t0 = time.perf_counter() + spec = self.registry.get(name) + if spec is None: + known = ", ".join(sorted(self.registry.tools)) or "(none)" + return ToolResult(name, False, f"Unknown tool: {name}. Known: {known}", error_type="unknown_tool") + if spec.required_permission and not self.context.has(spec.required_permission): + return ToolResult(name, False, f"Permission denied: {spec.required_permission}", error_type="permission") + err = validate_args(spec.parameters, arguments) + if err: + return ToolResult(name, False, f"Validation: {err}", error_type="validation") + if spec.handler is None: + return ToolResult(name, False, f"No handler for {name}", error_type="no_handler") + try: + out = spec.handler(ctx=self.context, **arguments) + if isinstance(out, ToolResult): + out.latency_ms = (time.perf_counter() - t0) * 1000 + return out + return ToolResult(name, True, str(out), raw=out, latency_ms=(time.perf_counter() - t0) * 1000) + except TypeError: + # handlers that don't take ctx= + try: + out = spec.handler(**arguments) + if isinstance(out, ToolResult): + out.latency_ms = (time.perf_counter() - t0) * 1000 + return out + return ToolResult(name, True, str(out), raw=out, latency_ms=(time.perf_counter() - t0) * 1000) + except Exception as e: + return ToolResult(name, False, f"Runtime: {e}", error_type="runtime", + latency_ms=(time.perf_counter() - t0) * 1000) + except Exception as e: + return ToolResult(name, False, f"Runtime: {e}", error_type="runtime", + latency_ms=(time.perf_counter() - t0) * 1000) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_factory.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_factory.py new file mode 100644 index 0000000000000000000000000000000000000000..f6b3cc1346a794d213ac1ac911394b5991bebffe --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_factory.py @@ -0,0 +1,19 @@ +"""Build ToolSpec quickly.""" +from __future__ import annotations +from typing import Any, Callable, Optional +from Tools.Core.tool_registry import ToolSpec + +def make_tool( + name: str, + description: str, + parameters: dict[str, Any], + handler: Callable, + category: str = "general", + permission: Optional[str] = None, + parallel_safe: bool = True, +) -> ToolSpec: + return ToolSpec( + name=name, description=description, parameters=parameters, + handler=handler, category=category, required_permission=permission, + parallel_safe=parallel_safe, + ) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_lifecycle.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_lifecycle.py new file mode 100644 index 0000000000000000000000000000000000000000..216c2c100d2f381e6ff96d205db5128dfe257ce1 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_lifecycle.py @@ -0,0 +1,17 @@ +"""Hooks: before/after tool call.""" +from __future__ import annotations +from typing import Callable, Any +from Tools.Core.tool_result import ToolResult + +class LifecycleHooks: + def __init__(self): + self.before: list[Callable] = [] + self.after: list[Callable] = [] + + def run_before(self, name: str, arguments: dict) -> None: + for h in self.before: + h(name, arguments) + + def run_after(self, name: str, arguments: dict, result: ToolResult) -> None: + for h in self.after: + h(name, arguments, result) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_loader.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_loader.py new file mode 100644 index 0000000000000000000000000000000000000000..02650a016266a1a8270e1eefaaa7d21c313b6471 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_loader.py @@ -0,0 +1,30 @@ +"""Discover and register tools from category packages.""" +from __future__ import annotations +from Tools.Core.tool_registry import ToolRegistry + +def load_all_builtin_tools(registry: ToolRegistry) -> ToolRegistry: + loaders = [ + ("Tools.Filesystem", "register"), + ("Tools.Code", "register"), + ("Tools.Terminal", "register"), + ("Tools.Python", "register"), + ("Tools.Search", "register"), + ("Tools.Git", "register"), + ("Tools.Documents", "register"), + ("Tools.Media", "register"), + ("Tools.Security", "register"), + ("Tools.APIs", "register"), + ("Tools.Databases", "register"), + ("Tools.Browser", "register"), + ("Tools.GitHub", "register"), + ("Tools.Cloud", "register"), + ("Tools.Communication", "register"), + ("Tools.Plugins", "register"), + ] + for mod_name, fn_name in loaders: + try: + mod = __import__(mod_name, fromlist=[fn_name]) + getattr(mod, fn_name)(registry) + except Exception: + continue + return registry diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_manager.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..166118d8a34649fc71f158ee5f6bdfd22808b6a1 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_manager.py @@ -0,0 +1,26 @@ +"""High-level facade: load categories, list, run.""" +from __future__ import annotations +from typing import Optional +from Tools.Core.tool_registry import ToolRegistry +from Tools.Core.tool_executor import ToolExecutor +from Tools.Core.tool_context import ToolContext +from Tools.Core.tool_router import ToolRouter +from Tools.Core.tool_loader import load_all_builtin_tools + +class ToolManager: + def __init__(self, context: Optional[ToolContext] = None, auto_load: bool = True): + self.context = context or ToolContext() + self.registry = ToolRegistry() + if auto_load: + load_all_builtin_tools(self.registry) + self.executor = ToolExecutor(self.registry, self.context) + self.router = ToolRouter(self.registry, self.executor) + + def list(self, category: Optional[str] = None): + return self.registry.list_tools(category) + + def run(self, name: str, **kwargs): + return self.executor.run(name, kwargs) + + def prompt_schemas(self) -> str: + return self.registry.schemas_for_prompt() diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_metrics.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_metrics.py new file mode 100644 index 0000000000000000000000000000000000000000..e714a8108a320287fbb1e65ef2de5cb886f00da1 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_metrics.py @@ -0,0 +1,17 @@ +"""Simple counters for success/fail.""" +from __future__ import annotations +from dataclasses import dataclass, field + +@dataclass +class ToolMetrics: + ok: int = 0 + fail: int = 0 + by_tool: dict = field(default_factory=dict) + + def record(self, name: str, ok: bool) -> None: + if ok: + self.ok += 1 + else: + self.fail += 1 + slot = self.by_tool.setdefault(name, {"ok": 0, "fail": 0}) + slot["ok" if ok else "fail"] += 1 diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_permissions.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_permissions.py new file mode 100644 index 0000000000000000000000000000000000000000..fc522310590ec1cb8b42ad80987b37ca46e9b810 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_permissions.py @@ -0,0 +1,18 @@ +"""Permission helpers.""" +from __future__ import annotations +from Tools.Core.tool_context import ToolContext + +PERMISSIONS = { + "fs:read", "fs:write", "fs:delete", + "terminal:run", "python:eval", + "net:read", "net:write", + "git:write", "db:write", "secrets:read", +} + +def grant(ctx: ToolContext, *perms: str) -> ToolContext: + ctx.permissions |= set(perms) + return ctx + +def revoke(ctx: ToolContext, *perms: str) -> ToolContext: + ctx.permissions -= set(perms) + return ctx diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_profiler.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_profiler.py new file mode 100644 index 0000000000000000000000000000000000000000..f2b9188f3b41f26dd8e1f461db57125fb94d38e6 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_profiler.py @@ -0,0 +1,19 @@ +"""Aggregate latency stats per tool.""" +from __future__ import annotations +from collections import defaultdict +from dataclasses import dataclass, field + +@dataclass +class ToolProfiler: + counts: dict[str, int] = field(default_factory=lambda: defaultdict(int)) + total_ms: dict[str, float] = field(default_factory=lambda: defaultdict(float)) + + def record(self, name: str, latency_ms: float) -> None: + self.counts[name] += 1 + self.total_ms[name] += latency_ms + + def summary(self) -> dict[str, dict[str, float]]: + out = {} + for k, n in self.counts.items(): + out[k] = {"count": n, "avg_ms": self.total_ms[k] / max(n, 1)} + return out diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_registry.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_registry.py new file mode 100644 index 0000000000000000000000000000000000000000..575b23385c8f3a81d2ee67a20eea625fa54c24cc --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_registry.py @@ -0,0 +1,43 @@ +"""Central registry of tool specs + handlers.""" +from __future__ import annotations +from dataclasses import dataclass, field +from typing import Any, Callable, Optional +from Tools.Core.tool_result import ToolResult +from Tools.Core.tool_validator import validate_args + +@dataclass +class ToolSpec: + name: str + description: str + parameters: dict[str, Any] + handler: Optional[Callable[..., Any]] = None + category: str = "general" + parallel_safe: bool = True + required_permission: Optional[str] = None + timeout_s: float = 60.0 + +@dataclass +class ToolRegistry: + tools: dict[str, ToolSpec] = field(default_factory=dict) + + def register(self, spec: ToolSpec) -> None: + self.tools[spec.name] = spec + + def get(self, name: str) -> Optional[ToolSpec]: + return self.tools.get(name) + + def list_tools(self, category: Optional[str] = None) -> list[ToolSpec]: + vals = list(self.tools.values()) + if category: + vals = [t for t in vals if t.category == category] + return vals + + def schemas_for_prompt(self) -> str: + lines = [] + for t in sorted(self.tools.values(), key=lambda x: (x.category, x.name)): + params = ", ".join( + f"{k}{'*' if v.get('required') else ''}: {v.get('type','any')}" + for k, v in t.parameters.items() + ) + lines.append(f"- [{t.category}] {t.name}({params}): {t.description}") + return "\n".join(lines) if lines else "(no tools)" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_result.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_result.py new file mode 100644 index 0000000000000000000000000000000000000000..c307f4926fd2480e102f2f798587025e12377de0 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_result.py @@ -0,0 +1,20 @@ +"""Standard tool result envelope.""" +from __future__ import annotations +from dataclasses import dataclass, field +from typing import Any, Optional + +@dataclass +class ToolResult: + name: str + ok: bool + content: str + raw: Any = None + error_type: Optional[str] = None + latency_ms: float = 0.0 + meta: dict = field(default_factory=dict) + + def as_dict(self) -> dict: + return { + "name": self.name, "ok": self.ok, "content": self.content, + "error_type": self.error_type, "latency_ms": self.latency_ms, "meta": self.meta, + } diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_router.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_router.py new file mode 100644 index 0000000000000000000000000000000000000000..a93bd2a41e61f389bf3e902fb5503fb05a919e96 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_router.py @@ -0,0 +1,45 @@ +"""Route natural-language intent or structured calls to tools.""" +from __future__ import annotations +import json, re +from typing import Any +from Tools.Core.tool_registry import ToolRegistry +from Tools.Core.tool_executor import ToolExecutor +from Tools.Core.tool_result import ToolResult + +_BLOCK = re.compile( + r"<\|tool_call\|>\s*(\{.*?\})\s*(?:<\|end_tool_call\|>|(?=<\|tool_call\|>)|$)", + re.DOTALL, +) + +def parse_tool_calls(text: str) -> list[dict[str, Any]]: + calls = [] + for m in _BLOCK.finditer(text or ""): + raw = m.group(1).strip() + raw = re.sub(r",\s*}", "}", raw) + try: + obj = json.loads(raw) + except Exception: + try: + obj = json.loads(raw.replace("'", '"')) + except Exception: + continue + if not isinstance(obj, dict) or "name" not in obj: + continue + args = obj.get("arguments") if "arguments" in obj else obj.get("args") + if args is None: + args = {k: v for k, v in obj.items() if k != "name"} + if not isinstance(args, dict): + args = {} + calls.append({"name": str(obj["name"]), "arguments": args}) + return calls + +class ToolRouter: + def __init__(self, registry: ToolRegistry, executor: ToolExecutor | None = None): + self.registry = registry + self.executor = executor or ToolExecutor(registry) + + def route_text(self, text: str) -> list[ToolResult]: + return [self.executor.run(c["name"], c.get("arguments") or {}) for c in parse_tool_calls(text)] + + def route_call(self, name: str, arguments: dict | None = None) -> ToolResult: + return self.executor.run(name, arguments or {}) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_scheduler.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..257b852b4c40762c5d0815693b52ff2dc8397a45 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_scheduler.py @@ -0,0 +1,26 @@ +"""Order tool calls (serial dependencies vs parallel).""" +from __future__ import annotations +from typing import Any +from Tools.Core.tool_engine import ToolEngine +from Tools.Core.tool_result import ToolResult + +class ToolScheduler: + def __init__(self, engine: ToolEngine): + self.engine = engine + + def run_plan(self, steps: list[dict[str, Any]]) -> list[ToolResult]: + # steps: {name, arguments, parallel_group?} + results = [] + i = 0 + while i < len(steps): + group = [steps[i]] + g = steps[i].get("parallel_group") + j = i + 1 + while g is not None and j < len(steps) and steps[j].get("parallel_group") == g: + group.append(steps[j]); j += 1 + if len(group) > 1: + results.extend(self.engine.run_many(group, parallel=True)) + else: + results.append(self.engine.run(group[0]["name"], group[0].get("arguments"))) + i = j + return results diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_session.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_session.py new file mode 100644 index 0000000000000000000000000000000000000000..2a4bdb9367f70ec711b04785a3752b3bf008e970 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_session.py @@ -0,0 +1,14 @@ +"""Session-scoped tool state (cwd, env, history).""" +from __future__ import annotations +from dataclasses import dataclass, field +from typing import Any +from Tools.Core.tool_context import ToolContext +from Tools.Core.tool_result import ToolResult + +@dataclass +class ToolSession: + context: ToolContext = field(default_factory=ToolContext) + history: list[dict[str, Any]] = field(default_factory=list) + + def record(self, name: str, arguments: dict, result: ToolResult) -> None: + self.history.append({"name": name, "arguments": arguments, "ok": result.ok, "content": result.content[:500]}) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_validator.py b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_validator.py new file mode 100644 index 0000000000000000000000000000000000000000..f627b3ab1490c326591b8606ca7c19748bee71b7 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Core/tool_validator.py @@ -0,0 +1,29 @@ +"""JSON-schema-like argument validation.""" +from __future__ import annotations +from typing import Any, Optional + +def validate_args(schema: dict[str, dict], arguments: dict[str, Any]) -> Optional[str]: + if not isinstance(arguments, dict): + return "arguments must be an object" + for key, meta in schema.items(): + if meta.get("required") and key not in arguments: + return f"missing required argument: {key}" + if key not in arguments: + continue + val = arguments[key] + typ = meta.get("type") + if typ == "string" and not isinstance(val, str): + return f"{key} must be string" + if typ == "integer" and not isinstance(val, int): + return f"{key} must be integer" + if typ == "number" and not isinstance(val, (int, float)): + return f"{key} must be number" + if typ == "boolean" and not isinstance(val, bool): + return f"{key} must be boolean" + if typ == "array" and not isinstance(val, list): + return f"{key} must be array" + if typ == "object" and not isinstance(val, dict): + return f"{key} must be object" + if "enum" in meta and val not in meta["enum"]: + return f"{key} must be one of {meta['enum']}" + return None diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..82309bacab95f33f0b35aca4c5531869b32b9603 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/__init__.py @@ -0,0 +1,16 @@ +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult +def sqlite_query(ctx=None, path: str = "", sql: str = "", **kw): + try: + import sqlite3 + con = sqlite3.connect(path) + cur = con.execute(sql) + if sql.strip().lower().startswith("select"): + rows = cur.fetchmany(100) + return ToolResult("sqlite_query", True, str(rows)) + con.commit() + return ToolResult("sqlite_query", True, f"ok rowcount={cur.rowcount}") + except Exception as e: + return ToolResult("sqlite_query", False, str(e), error_type="runtime") +def register(registry): + registry.register(make_tool("sqlite_query", "Run SQLite SQL", {"path":{"type":"string","required":True},"sql":{"type":"string","required":True}}, sqlite_query, "databases", "db:write", parallel_safe=False)) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/backup.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/backup.py new file mode 100644 index 0000000000000000000000000000000000000000..45d5affecc3d0959dd922f1716827052d93730ed --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/backup.py @@ -0,0 +1 @@ +"""Databases: backup.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/elasticsearch.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/elasticsearch.py new file mode 100644 index 0000000000000000000000000000000000000000..d8a809b829924d2091d9a0c4861ea735d27ccc5a --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/elasticsearch.py @@ -0,0 +1 @@ +"""Databases: elasticsearch.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/migrations.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/migrations.py new file mode 100644 index 0000000000000000000000000000000000000000..d973368410711b65e2494a1febdf6a8764e0990a --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/migrations.py @@ -0,0 +1 @@ +"""Databases: migrations.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/milvus.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/milvus.py new file mode 100644 index 0000000000000000000000000000000000000000..8b7b05d61d1ccad6bcfbedac3da5432393a09311 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/milvus.py @@ -0,0 +1 @@ +"""Databases: milvus.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/mongodb.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/mongodb.py new file mode 100644 index 0000000000000000000000000000000000000000..a84663965da8d48d3f15e6c65e2d737f9f792215 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/mongodb.py @@ -0,0 +1 @@ +"""Databases: mongodb.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/neo4j.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/neo4j.py new file mode 100644 index 0000000000000000000000000000000000000000..4b0abb9514d2834918736945f3c13b085e50d04b --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/neo4j.py @@ -0,0 +1 @@ +"""Databases: neo4j.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/postgres.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/postgres.py new file mode 100644 index 0000000000000000000000000000000000000000..67fc16f3281f889c6ed1362ea79fff3ffd507883 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/postgres.py @@ -0,0 +1 @@ +"""Databases: postgres.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/qdrant.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/qdrant.py new file mode 100644 index 0000000000000000000000000000000000000000..3804b9f7a5b7e1d8c4070b8fe55d89c34370fdba --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/qdrant.py @@ -0,0 +1 @@ +"""Databases: qdrant.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/redis.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/redis.py new file mode 100644 index 0000000000000000000000000000000000000000..e2befcde60c221ab736386653bf074e075da5ec0 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/redis.py @@ -0,0 +1 @@ +"""Databases: redis.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/sql.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/sql.py new file mode 100644 index 0000000000000000000000000000000000000000..ef565cc2dc516ffb90f64d740291b43e26944893 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/sql.py @@ -0,0 +1 @@ +"""Databases: sql.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Databases/sqlite.py b/Brain_O_Codebase/brain_v0_5/Tools/Databases/sqlite.py new file mode 100644 index 0000000000000000000000000000000000000000..8da3bee1f95473a4a2ed18955e743f31c1e83c09 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Databases/sqlite.py @@ -0,0 +1 @@ +"""Databases: sqlite.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c99874348eed7f451aa4bae64e63489170f0304c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/__init__.py @@ -0,0 +1,23 @@ +from __future__ import annotations +from pathlib import Path +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def _ingest(path: str) -> ToolResult: + try: + from brain.experimental.ingest import load_any + r = load_any(path) + return ToolResult("doc_read", True, r.to_prompt(max_chars=12000), meta={"errors": r.errors}) + except Exception as e: + p = Path(path) + if p.suffix.lower() in {".txt", ".md", ".csv", ".json", ".yaml", ".yml", ".html", ".xml"}: + return ToolResult("doc_read", True, p.read_text(encoding="utf-8", errors="ignore")[:12000]) + return ToolResult("doc_read", False, str(e), error_type="runtime") + +def pdf_read(ctx=None, path: str = "", **kw): return _ingest(path) +def docx_read(ctx=None, path: str = "", **kw): return _ingest(path) +def xlsx_read(ctx=None, path: str = "", **kw): return _ingest(path) + +def register(registry): + for name, fn in [("pdf_read", pdf_read), ("docx_read", docx_read), ("xlsx_read", xlsx_read)]: + registry.register(make_tool(name, f"Read {name.split('_')[0].upper()} via ingest", {"path":{"type":"string","required":True}}, fn, "documents", "fs:read")) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/csv.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/csv.py new file mode 100644 index 0000000000000000000000000000000000000000..a19e029b5fede96941aaee11c9ef4d948eb1a33c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/csv.py @@ -0,0 +1 @@ +"""Documents: csv.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/excel.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/excel.py new file mode 100644 index 0000000000000000000000000000000000000000..1898fc953ed2adcb3703be4599e3d8919e3b7f65 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/excel.py @@ -0,0 +1 @@ +"""Documents: excel.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/html.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/html.py new file mode 100644 index 0000000000000000000000000000000000000000..1ff1cfca3d990db7ef7b2cb02851417dac569ed4 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/html.py @@ -0,0 +1 @@ +"""Documents: html.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/json.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/json.py new file mode 100644 index 0000000000000000000000000000000000000000..0f42cb960b3d6bae37079cad0cdb84576fb3af6c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/json.py @@ -0,0 +1 @@ +"""Documents: json.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/markdown.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/markdown.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b2f3bf02780f4eb07bd2472588c2e6d2050c48 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/markdown.py @@ -0,0 +1 @@ +"""Documents: markdown.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/parser.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/parser.py new file mode 100644 index 0000000000000000000000000000000000000000..a5da305d732f255236cdeafde43dc74ff943049b --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/parser.py @@ -0,0 +1 @@ +"""Documents: parser.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/pdf.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/pdf.py new file mode 100644 index 0000000000000000000000000000000000000000..51020cddb0227e31e1a2ae2271abd33dfdaf1c16 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/pdf.py @@ -0,0 +1 @@ +"""Documents: pdf.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/powerpoint.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/powerpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..f2b6c6ab6572df7a21aa82aa9ac4510a1f1b3d76 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/powerpoint.py @@ -0,0 +1 @@ +"""Documents: powerpoint.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/word.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/word.py new file mode 100644 index 0000000000000000000000000000000000000000..6d6ae3efc699100d8c9a5425adeb1dcc92a115e3 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/word.py @@ -0,0 +1 @@ +"""Documents: word.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/xml.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/xml.py new file mode 100644 index 0000000000000000000000000000000000000000..82c46c4d47c42f344c21d9d03e84a4c7d1f9cac7 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/xml.py @@ -0,0 +1 @@ +"""Documents: xml.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Documents/yaml.py b/Brain_O_Codebase/brain_v0_5/Tools/Documents/yaml.py new file mode 100644 index 0000000000000000000000000000000000000000..695eb4d1060962fbbababfbbaa18514633f78a40 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Documents/yaml.py @@ -0,0 +1 @@ +"""Documents: yaml.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..ea912882a83bd8cce6770a61fe6a6ad35c2bf220 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/__init__.py @@ -0,0 +1,199 @@ +from __future__ import annotations +from pathlib import Path +from typing import Any +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def _resolve(ctx, path: str) -> Path: + p = Path(path) + if not p.is_absolute(): + base = ctx.workspace_root or ctx.cwd + p = base / p + return p.resolve() + +def read_file(ctx=None, path: str = "", offset: int = 1, limit: int = 200, **kw) -> ToolResult: + p = _resolve(ctx, path) + if not p.exists(): + return ToolResult("read_file", False, f"not found: {p}", error_type="runtime") + lines = p.read_text(encoding="utf-8", errors="ignore").splitlines() + start = max(int(offset) - 1, 0) + chunk = lines[start:start + int(limit)] + numbered = "\n".join(f"{start+i+1}| {ln}" for i, ln in enumerate(chunk)) + return ToolResult("read_file", True, numbered or "(empty)", meta={"path": str(p), "total_lines": len(lines)}) + +def write_file(ctx=None, path: str = "", content: str = "", **kw) -> ToolResult: + p = _resolve(ctx, path) + p.parent.mkdir(parents=True, exist_ok=True) + p.write_text(content, encoding="utf-8") + return ToolResult("write_file", True, f"wrote {len(content)} chars to {p}") + +def append_file(ctx=None, path: str = "", content: str = "", **kw) -> ToolResult: + p = _resolve(ctx, path) + p.parent.mkdir(parents=True, exist_ok=True) + with p.open("a", encoding="utf-8") as f: + f.write(content) + return ToolResult("append_file", True, f"appended {len(content)} chars to {p}") + +def edit_file(ctx=None, path: str = "", old_string: str = "", new_string: str = "", replace_all: bool = False, **kw) -> ToolResult: + p = _resolve(ctx, path) + text = p.read_text(encoding="utf-8", errors="ignore") + if old_string not in text: + return ToolResult("edit_file", False, "old_string not found", error_type="runtime") + if replace_all: + text2 = text.replace(old_string, new_string) + else: + text2 = text.replace(old_string, new_string, 1) + p.write_text(text2, encoding="utf-8") + return ToolResult("edit_file", True, f"edited {p}") + +def replace_text(ctx=None, path: str = "", old_string: str = "", new_string: str = "", **kw): + return edit_file(ctx=ctx, path=path, old_string=old_string, new_string=new_string, replace_all=True) + +def move_file(ctx=None, src: str = "", dst: str = "", **kw) -> ToolResult: + import shutil + a, b = _resolve(ctx, src), _resolve(ctx, dst) + b.parent.mkdir(parents=True, exist_ok=True) + shutil.move(str(a), str(b)) + return ToolResult("move_file", True, f"{a} -> {b}") + +def copy_file(ctx=None, src: str = "", dst: str = "", **kw) -> ToolResult: + import shutil + a, b = _resolve(ctx, src), _resolve(ctx, dst) + b.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(str(a), str(b)) + return ToolResult("copy_file", True, f"copied {a} -> {b}") + +def delete_file(ctx=None, path: str = "", **kw) -> ToolResult: + p = _resolve(ctx, path) + if p.is_file(): + p.unlink() + return ToolResult("delete_file", True, f"deleted {p}") + return ToolResult("delete_file", False, f"not a file: {p}", error_type="runtime") + +def create_directory(ctx=None, path: str = "", **kw) -> ToolResult: + p = _resolve(ctx, path) + p.mkdir(parents=True, exist_ok=True) + return ToolResult("create_directory", True, f"created {p}") + +def remove_directory(ctx=None, path: str = "", recursive: bool = False, **kw) -> ToolResult: + import shutil + p = _resolve(ctx, path) + if recursive: + shutil.rmtree(p) + else: + p.rmdir() + return ToolResult("remove_directory", True, f"removed {p}") + +def list_directory(ctx=None, path: str = ".", **kw) -> ToolResult: + p = _resolve(ctx, path) + if not p.is_dir(): + return ToolResult("list_directory", False, f"not a directory: {p}", error_type="runtime") + entries = sorted(p.iterdir(), key=lambda x: (not x.is_dir(), x.name.lower())) + lines = [("d " if e.is_dir() else "f ") + e.name for e in entries] + return ToolResult("list_directory", True, "\n".join(lines) or "(empty)", meta={"path": str(p)}) + +def search_files(ctx=None, query: str = "", path: str = ".", max_hits: int = 50, **kw) -> ToolResult: + root = _resolve(ctx, path) + hits = [] + for fp in root.rglob("*"): + if not fp.is_file(): + continue + try: + text = fp.read_text(encoding="utf-8", errors="ignore") + except Exception: + continue + if query in text or query in fp.name: + hits.append(str(fp)) + if len(hits) >= max_hits: + break + return ToolResult("search_files", True, "\n".join(hits) or "(no hits)") + +def tree(ctx=None, path: str = ".", max_depth: int = 3, **kw) -> ToolResult: + root = _resolve(ctx, path) + lines = [] + def walk(d: Path, depth: int, prefix: str): + if depth > max_depth: + return + try: + kids = sorted(d.iterdir(), key=lambda x: (not x.is_dir(), x.name.lower())) + except Exception: + return + for i, k in enumerate(kids): + last = i == len(kids) - 1 + branch = "└── " if last else "├── " + lines.append(prefix + branch + k.name + ("/" if k.is_dir() else "")) + if k.is_dir(): + walk(k, depth + 1, prefix + (" " if last else "│ ")) + lines.append(str(root)) + walk(root, 1, "") + return ToolResult("tree", True, "\n".join(lines)) + +def metadata(ctx=None, path: str = "", **kw) -> ToolResult: + p = _resolve(ctx, path) + if not p.exists(): + return ToolResult("metadata", False, "not found", error_type="runtime") + st = p.stat() + return ToolResult("metadata", True, f"size={st.st_size} mtime={st.st_mtime} path={p}") + +def permissions(ctx=None, path: str = "", **kw) -> ToolResult: + import os, stat + p = _resolve(ctx, path) + mode = stat.filemode(p.stat().st_mode) + return ToolResult("permissions", True, f"{mode} {p}") + +def archive(ctx=None, path: str = "", out: str = "", **kw) -> ToolResult: + import shutil + src = _resolve(ctx, path) + dst = _resolve(ctx, out or (str(src) + ".zip")) + base = str(dst).removesuffix(".zip") + outp = shutil.make_archive(base, "zip", root_dir=str(src if src.is_dir() else src.parent), + base_dir=src.name if src.is_dir() else src.name) + return ToolResult("archive", True, f"created {outp}") + +def extract(ctx=None, path: str = "", out: str = "", **kw) -> ToolResult: + import zipfile, tarfile + src = _resolve(ctx, path) + dest = _resolve(ctx, out or str(src.with_suffix(""))) + dest.mkdir(parents=True, exist_ok=True) + if zipfile.is_zipfile(src): + with zipfile.ZipFile(src) as z: + z.extractall(dest) + elif tarfile.is_tarfile(src): + with tarfile.open(src) as t: + t.extractall(dest) + else: + return ToolResult("extract", False, "unsupported archive", error_type="runtime") + return ToolResult("extract", True, f"extracted to {dest}") + +def checksum(ctx=None, path: str = "", algo: str = "sha256", **kw) -> ToolResult: + import hashlib + p = _resolve(ctx, path) + h = hashlib.new(algo) + with p.open("rb") as f: + for chunk in iter(lambda: f.read(1 << 20), b""): + h.update(chunk) + return ToolResult("checksum", True, f"{algo}={h.hexdigest()} path={p}") + +def register(registry) -> None: + specs = [ + make_tool("read_file", "Read file lines", {"path": {"type":"string","required":True}, "offset":{"type":"integer"}, "limit":{"type":"integer"}}, read_file, "filesystem", "fs:read"), + make_tool("write_file", "Write/overwrite file", {"path":{"type":"string","required":True}, "content":{"type":"string","required":True}}, write_file, "filesystem", "fs:write", parallel_safe=False), + make_tool("append_file", "Append to file", {"path":{"type":"string","required":True}, "content":{"type":"string","required":True}}, append_file, "filesystem", "fs:write", parallel_safe=False), + make_tool("edit_file", "Replace first/all occurrences", {"path":{"type":"string","required":True}, "old_string":{"type":"string","required":True}, "new_string":{"type":"string","required":True}, "replace_all":{"type":"boolean"}}, edit_file, "filesystem", "fs:write", parallel_safe=False), + make_tool("replace_text", "Replace all in file", {"path":{"type":"string","required":True}, "old_string":{"type":"string","required":True}, "new_string":{"type":"string","required":True}}, replace_text, "filesystem", "fs:write", parallel_safe=False), + make_tool("move_file", "Move/rename", {"src":{"type":"string","required":True}, "dst":{"type":"string","required":True}}, move_file, "filesystem", "fs:write", parallel_safe=False), + make_tool("copy_file", "Copy file", {"src":{"type":"string","required":True}, "dst":{"type":"string","required":True}}, copy_file, "filesystem", "fs:write"), + make_tool("delete_file", "Delete file", {"path":{"type":"string","required":True}}, delete_file, "filesystem", "fs:delete", parallel_safe=False), + make_tool("create_directory", "mkdir -p", {"path":{"type":"string","required":True}}, create_directory, "filesystem", "fs:write"), + make_tool("remove_directory", "Remove directory", {"path":{"type":"string","required":True}, "recursive":{"type":"boolean"}}, remove_directory, "filesystem", "fs:delete", parallel_safe=False), + make_tool("list_directory", "List directory", {"path":{"type":"string"}}, list_directory, "filesystem", "fs:read"), + make_tool("search_files", "Search file contents/names", {"query":{"type":"string","required":True}, "path":{"type":"string"}, "max_hits":{"type":"integer"}}, search_files, "filesystem", "fs:read"), + make_tool("tree", "Directory tree", {"path":{"type":"string"}, "max_depth":{"type":"integer"}}, tree, "filesystem", "fs:read"), + make_tool("file_metadata", "File metadata", {"path":{"type":"string","required":True}}, metadata, "filesystem", "fs:read"), + make_tool("file_permissions", "Show permissions", {"path":{"type":"string","required":True}}, permissions, "filesystem", "fs:read"), + make_tool("archive", "Zip a path", {"path":{"type":"string","required":True}, "out":{"type":"string"}}, archive, "filesystem", "fs:write"), + make_tool("extract", "Extract archive", {"path":{"type":"string","required":True}, "out":{"type":"string"}}, extract, "filesystem", "fs:write"), + make_tool("checksum", "File checksum", {"path":{"type":"string","required":True}, "algo":{"type":"string"}}, checksum, "filesystem", "fs:read"), + ] + for s in specs: + registry.register(s) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/append_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/append_file.py new file mode 100644 index 0000000000000000000000000000000000000000..5502a09d10058f49b7057de9d214fccb1750bd15 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/append_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: append_file.""" +from Tools.Filesystem import append_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/archive.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/archive.py new file mode 100644 index 0000000000000000000000000000000000000000..97254adfabf41af6c8e15755a21ac86f257fc249 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/archive.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: archive.""" +from Tools.Filesystem import archive as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/checksum.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/checksum.py new file mode 100644 index 0000000000000000000000000000000000000000..1e4bbe3aaba1c49e161a7517d3891b7066e4db83 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/checksum.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: checksum.""" +from Tools.Filesystem import checksum as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/copy_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/copy_file.py new file mode 100644 index 0000000000000000000000000000000000000000..f030598a6cf3b4c360d5b746fd708bd78da1ff44 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/copy_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: copy_file.""" +from Tools.Filesystem import copy_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/create_directory.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/create_directory.py new file mode 100644 index 0000000000000000000000000000000000000000..1429e3e757feb643650aa1875ac4c43c57508d9c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/create_directory.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: create_directory.""" +from Tools.Filesystem import create_directory as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/delete_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/delete_file.py new file mode 100644 index 0000000000000000000000000000000000000000..40aae41a6a6d3702871825aa0e436ecd0e8bf005 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/delete_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: delete_file.""" +from Tools.Filesystem import delete_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/edit_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/edit_file.py new file mode 100644 index 0000000000000000000000000000000000000000..7ab3b5be7cf11574fc7b76f97a4902801e8a0594 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/edit_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: edit_file.""" +from Tools.Filesystem import edit_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/extract.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/extract.py new file mode 100644 index 0000000000000000000000000000000000000000..39b3219a61be82c84c92f76908a5c91d3a8638d7 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/extract.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: extract.""" +from Tools.Filesystem import extract as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/list_directory.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/list_directory.py new file mode 100644 index 0000000000000000000000000000000000000000..7e157ed41e2ecb7798f875195805abb3035b2b16 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/list_directory.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: list_directory.""" +from Tools.Filesystem import list_directory as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/metadata.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/metadata.py new file mode 100644 index 0000000000000000000000000000000000000000..24526615953ca7649c60a74f5ca43a6e371de1aa --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/metadata.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: metadata.""" +from Tools.Filesystem import metadata as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/move_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/move_file.py new file mode 100644 index 0000000000000000000000000000000000000000..ff999735113eff9b37d8bdc893d3331a24dbdac9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/move_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: move_file.""" +from Tools.Filesystem import move_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/permissions.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/permissions.py new file mode 100644 index 0000000000000000000000000000000000000000..87cf0266d80d9fc0dbb59be9fb343c3f63720de3 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/permissions.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: permissions.""" +from Tools.Filesystem import permissions as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/read_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/read_file.py new file mode 100644 index 0000000000000000000000000000000000000000..47e6f0dd3989bbf5bccade64fc325c02902b68c5 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/read_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: read_file.""" +from Tools.Filesystem import read_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/remove_directory.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/remove_directory.py new file mode 100644 index 0000000000000000000000000000000000000000..3921cfd34af7f658fb7027c4cd9660bac27f95fd --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/remove_directory.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: remove_directory.""" +from Tools.Filesystem import remove_directory as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/replace_text.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/replace_text.py new file mode 100644 index 0000000000000000000000000000000000000000..f4cbcd81bf76bbe685c1bae7d85cf994cddcbf27 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/replace_text.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: replace_text.""" +from Tools.Filesystem import replace_text as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/search_files.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/search_files.py new file mode 100644 index 0000000000000000000000000000000000000000..586f45d301253730d7204b6820509e1891351e0c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/search_files.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: search_files.""" +from Tools.Filesystem import search_files as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/tree.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/tree.py new file mode 100644 index 0000000000000000000000000000000000000000..3b9e996b857b83deb29939bf056f27496643b05b --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/tree.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: tree.""" +from Tools.Filesystem import tree as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/write_file.py b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/write_file.py new file mode 100644 index 0000000000000000000000000000000000000000..997276347eaafea3e0386b82320fb683eddd8c5c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Filesystem/write_file.py @@ -0,0 +1,2 @@ +"""Filesystem tool module: write_file.""" +from Tools.Filesystem import write_file as run diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..ee9ab0e772d770ece4bd9e000f2fc3b99e57aeb2 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/__init__.py @@ -0,0 +1,26 @@ +from __future__ import annotations +import subprocess +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def _git(args, cwd="."): + try: + p = subprocess.run(["git", *args], cwd=cwd, capture_output=True, text=True, timeout=30) + out = (p.stdout or p.stderr or "").strip() + return ToolResult("git_" + args[0], p.returncode == 0, out or f"(exit {p.returncode})") + except Exception as e: + return ToolResult("git", False, str(e), error_type="runtime") + +def git_status(ctx=None, path: str = ".", **kw): + return _git(["status", "--short"], cwd=path) + +def git_diff(ctx=None, path: str = ".", **kw): + return _git(["diff"], cwd=path) + +def git_log(ctx=None, path: str = ".", n: int = 10, **kw): + return _git(["log", f"-{n}", "--oneline"], cwd=path) + +def register(registry): + registry.register(make_tool("git_status", "git status", {"path":{"type":"string"}}, git_status, "git", "fs:read")) + registry.register(make_tool("git_diff", "git diff", {"path":{"type":"string"}}, git_diff, "git", "fs:read")) + registry.register(make_tool("git_log", "git log", {"path":{"type":"string"}, "n":{"type":"integer"}}, git_log, "git", "fs:read")) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/branch.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/branch.py new file mode 100644 index 0000000000000000000000000000000000000000..cb5ddba2c5df478dee3f897f357d2d2f5a0cd967 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/branch.py @@ -0,0 +1 @@ +"""Git: branch.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/clone.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/clone.py new file mode 100644 index 0000000000000000000000000000000000000000..c5de551cb02c6aa0620a06274b2702fc008ff8aa --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/clone.py @@ -0,0 +1 @@ +"""Git: clone.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/commit.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/commit.py new file mode 100644 index 0000000000000000000000000000000000000000..e5ef24c58a46ff47b80afa3b2dcccae8c8ae8283 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/commit.py @@ -0,0 +1 @@ +"""Git: commit.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/diff.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/diff.py new file mode 100644 index 0000000000000000000000000000000000000000..7296ff8e3e5aba925c93675a5188939b5a6ac565 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/diff.py @@ -0,0 +1 @@ +"""Git: diff.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/history.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/history.py new file mode 100644 index 0000000000000000000000000000000000000000..af54e28604273a800f65181e103f374c3d9fb2c4 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/history.py @@ -0,0 +1 @@ +"""Git: history.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/merge.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/merge.py new file mode 100644 index 0000000000000000000000000000000000000000..c3e36135cb18701f4e8636b7c88b9d611aca211e --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/merge.py @@ -0,0 +1 @@ +"""Git: merge.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/release.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/release.py new file mode 100644 index 0000000000000000000000000000000000000000..c95feed96215fb4da23a00454af5318d3229c100 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/release.py @@ -0,0 +1 @@ +"""Git: release.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/repository.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/repository.py new file mode 100644 index 0000000000000000000000000000000000000000..8cf602a04f2a84eadc52441c24a79d96b501acbf --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/repository.py @@ -0,0 +1 @@ +"""Git: repository.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/status.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/status.py new file mode 100644 index 0000000000000000000000000000000000000000..960dfd5571f5970089654b9092413e4598ba3832 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/status.py @@ -0,0 +1 @@ +"""Git: status.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Git/tag.py b/Brain_O_Codebase/brain_v0_5/Tools/Git/tag.py new file mode 100644 index 0000000000000000000000000000000000000000..608c64025ca8d3e0b35a646e335c8ad471c1ff59 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Git/tag.py @@ -0,0 +1 @@ +"""Git: tag.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..95cc155907d0872fa3863ac7cc94f7dd477e2d48 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/__init__.py @@ -0,0 +1,6 @@ +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult +def github_api(ctx=None, path: str = "", **kw): + return ToolResult("github_api", True, f"[stub] GET https://api.github.com{path}") +def register(registry): + registry.register(make_tool("github_api", "GitHub API helper", {"path":{"type":"string","required":True}}, github_api, "github", "net:read")) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/actions.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/actions.py new file mode 100644 index 0000000000000000000000000000000000000000..82defe283f35870eed068df2de92e6adc76f0490 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/actions.py @@ -0,0 +1 @@ +"""GitHub: actions.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/authentication.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/authentication.py new file mode 100644 index 0000000000000000000000000000000000000000..215e754f28c77113aedc8ceb13f5313e0cb4c14a --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/authentication.py @@ -0,0 +1 @@ +"""GitHub: authentication.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/discussions.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/discussions.py new file mode 100644 index 0000000000000000000000000000000000000000..e1d17bfbc611e7ec83625a3c7383d0576f805359 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/discussions.py @@ -0,0 +1 @@ +"""GitHub: discussions.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/github.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/github.py new file mode 100644 index 0000000000000000000000000000000000000000..97a22bffa37b14ebd9cc1a7cde0f8db27b44c0a3 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/github.py @@ -0,0 +1 @@ +"""GitHub: github.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/issues.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/issues.py new file mode 100644 index 0000000000000000000000000000000000000000..3fc1a39cdf5353399c6c9ca11f267484d93f5030 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/issues.py @@ -0,0 +1 @@ +"""GitHub: issues.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/pull_requests.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/pull_requests.py new file mode 100644 index 0000000000000000000000000000000000000000..af3ce15a92daae1942a6d54f1593d01dfe3fd23f --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/pull_requests.py @@ -0,0 +1 @@ +"""GitHub: pull_requests.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/releases.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/releases.py new file mode 100644 index 0000000000000000000000000000000000000000..cc34575f9e9f6c000c487c61d35a229e20ca68a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/releases.py @@ -0,0 +1 @@ +"""GitHub: releases.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/repository.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/repository.py new file mode 100644 index 0000000000000000000000000000000000000000..67ab7f109c44a4c258e91f638eb89fc6f0537133 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/repository.py @@ -0,0 +1 @@ +"""GitHub: repository.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/search.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/search.py new file mode 100644 index 0000000000000000000000000000000000000000..26be9b5b67180093c79278857e3e227a886cc520 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/search.py @@ -0,0 +1 @@ +"""GitHub: search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/GitHub/workflows.py b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/workflows.py new file mode 100644 index 0000000000000000000000000000000000000000..9144dc191e35d89b1a424cbf3d0e925ec749ca0f --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/GitHub/workflows.py @@ -0,0 +1 @@ +"""GitHub: workflows.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..9146bcc470cf60cb428552b3382819d19923dbc6 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/__init__.py @@ -0,0 +1,22 @@ +from __future__ import annotations +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def media_process(ctx=None, path: str = "", **kw) -> ToolResult: + try: + from brain.experimental.multimodal.unified import process_media + b = process_media(path) + return ToolResult("media_process", True, b.prompt[:12000], meta={"kind": b.kind}) + except Exception as e: + return ToolResult("media_process", False, str(e), error_type="runtime") + +def ocr_image(ctx=None, path: str = "", **kw) -> ToolResult: + try: + from brain.experimental.ocr import get_ocr_engine + return ToolResult("ocr_image", True, get_ocr_engine().extract(path)) + except Exception as e: + return ToolResult("ocr_image", False, str(e), error_type="runtime") + +def register(registry): + registry.register(make_tool("media_process", "Process image/audio/video/document", {"path":{"type":"string","required":True}}, media_process, "media", "fs:read")) + registry.register(make_tool("ocr_image", "OCR an image", {"path":{"type":"string","required":True}}, ocr_image, "media", "fs:read")) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/audio.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/audio.py new file mode 100644 index 0000000000000000000000000000000000000000..6627e2846a948520a924b5b825c90abac6abe7b6 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/audio.py @@ -0,0 +1 @@ +"""Media: audio.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/compression.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/compression.py new file mode 100644 index 0000000000000000000000000000000000000000..b575393c5fc5cbe840ad7b011d9f08aefea1ceec --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/compression.py @@ -0,0 +1 @@ +"""Media: compression.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/conversion.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/conversion.py new file mode 100644 index 0000000000000000000000000000000000000000..97330d1d5e0b6419dc2affe422f190bebd51cdcd --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/conversion.py @@ -0,0 +1 @@ +"""Media: conversion.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/image.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/image.py new file mode 100644 index 0000000000000000000000000000000000000000..5139efe40f5f8561b0d3c01ccae46adff39dfe5f --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/image.py @@ -0,0 +1 @@ +"""Media: image.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/metadata.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/metadata.py new file mode 100644 index 0000000000000000000000000000000000000000..f99874aba351bc96fb2f60cb1dcfad9acd6f3602 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/metadata.py @@ -0,0 +1 @@ +"""Media: metadata.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/ocr.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/ocr.py new file mode 100644 index 0000000000000000000000000000000000000000..1b0ea079196fc6ddd7beaa7c5de257d974d47290 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/ocr.py @@ -0,0 +1 @@ +"""Media: ocr.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/speech.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/speech.py new file mode 100644 index 0000000000000000000000000000000000000000..21cacee04c9be12a129e604faedab384be124f6c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/speech.py @@ -0,0 +1 @@ +"""Media: speech.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/transcription.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/transcription.py new file mode 100644 index 0000000000000000000000000000000000000000..b2bb6f125e4ed01da7e384f3ceb035aac90633f0 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/transcription.py @@ -0,0 +1 @@ +"""Media: transcription.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Media/video.py b/Brain_O_Codebase/brain_v0_5/Tools/Media/video.py new file mode 100644 index 0000000000000000000000000000000000000000..f4dad846705b59aa9f01bd628846c3c2f0a6ee72 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Media/video.py @@ -0,0 +1 @@ +"""Media: video.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Plugins/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Plugins/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..cde28247183e0c6909a69adf4ff77d7ab47fd4db --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Plugins/__init__.py @@ -0,0 +1,6 @@ +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult +def list_plugins(ctx=None, **kw): + return ToolResult("list_plugins", True, "core filesystem terminal python search git documents media security") +def register(registry): + registry.register(make_tool("list_plugins", "List plugin groups", {}, list_plugins, "plugins", None)) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Plugins/plugin_loader.py b/Brain_O_Codebase/brain_v0_5/Tools/Plugins/plugin_loader.py new file mode 100644 index 0000000000000000000000000000000000000000..c401df22cc1b57f5c8cff55ba44e4bb2e5208480 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Plugins/plugin_loader.py @@ -0,0 +1 @@ +"""Plugins: plugin_loader.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Plugins/plugin_registry.py b/Brain_O_Codebase/brain_v0_5/Tools/Plugins/plugin_registry.py new file mode 100644 index 0000000000000000000000000000000000000000..3ed3338a30ee12c2e31347e47c8215a43dc95423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Plugins/plugin_registry.py @@ -0,0 +1 @@ +"""Plugins: plugin_registry.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d2ff508971198f043ca34af634736fcc441b38 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/__init__.py @@ -0,0 +1,29 @@ +from __future__ import annotations +import traceback +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def python_eval(ctx=None, code: str = "", **kw) -> ToolResult: + safe_builtins = { + "abs": abs, "min": min, "max": max, "sum": sum, "len": len, "range": range, + "str": str, "int": int, "float": float, "bool": bool, "list": list, "dict": dict, + "print": print, "round": round, "sorted": sorted, "enumerate": enumerate, "zip": zip, + } + ns = {"__builtins__": safe_builtins} + try: + # try eval then exec + try: + val = eval(code, ns, ns) + return ToolResult("python_eval", True, repr(val), raw=val) + except SyntaxError: + exec(code, ns, ns) + return ToolResult("python_eval", True, "ok", raw=ns) + except Exception as e: + return ToolResult("python_eval", False, traceback.format_exc(), error_type="runtime") + +def register(registry): + registry.register(make_tool( + "python_eval", "Evaluate Python in a restricted namespace", + {"code": {"type": "string", "required": True}}, + python_eval, "python", "python:eval", parallel_safe=False, + )) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/benchmark.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/benchmark.py new file mode 100644 index 0000000000000000000000000000000000000000..4bde67563a068d8cd5308f3003ca882e1f9b6b53 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/benchmark.py @@ -0,0 +1 @@ +"""Python tooling: benchmark.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/code_runner.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/code_runner.py new file mode 100644 index 0000000000000000000000000000000000000000..2d869bfbd9904e99d3ad575bf6b6090d7cefbfa6 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/code_runner.py @@ -0,0 +1 @@ +"""Python tooling: code_runner.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/debugger.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/debugger.py new file mode 100644 index 0000000000000000000000000000000000000000..7129579552c8578aeddb06919c8bc46cb4bd8aa2 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/debugger.py @@ -0,0 +1 @@ +"""Python tooling: debugger.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/interpreter.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/interpreter.py new file mode 100644 index 0000000000000000000000000000000000000000..36861cff6d042b999314359f197ec2ada5f99b12 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/interpreter.py @@ -0,0 +1 @@ +"""Python tooling: interpreter.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/notebook.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/notebook.py new file mode 100644 index 0000000000000000000000000000000000000000..36b3c9cc527e773b832b3f47eaefe14db34e0b2c --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/notebook.py @@ -0,0 +1 @@ +"""Python tooling: notebook.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/package_manager.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/package_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..8dad512c1d5752e61e40281ed750765d8916a3b5 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/package_manager.py @@ -0,0 +1 @@ +"""Python tooling: package_manager.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/profiler.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/profiler.py new file mode 100644 index 0000000000000000000000000000000000000000..e1996c8fa39f8551e9d4f0c6a63258f3c1b1b409 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/profiler.py @@ -0,0 +1 @@ +"""Python tooling: profiler.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/result_parser.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/result_parser.py new file mode 100644 index 0000000000000000000000000000000000000000..fad792476eb94847c257dcd75c9cb4cb63a98f9f --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/result_parser.py @@ -0,0 +1 @@ +"""Python tooling: result_parser.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/unit_test.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/unit_test.py new file mode 100644 index 0000000000000000000000000000000000000000..b45e62f08396f99e410a426fa5439110e4663340 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/unit_test.py @@ -0,0 +1 @@ +"""Python tooling: unit_test.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Python/virtualenv.py b/Brain_O_Codebase/brain_v0_5/Tools/Python/virtualenv.py new file mode 100644 index 0000000000000000000000000000000000000000..75991cae301bfd258ac457d443ca5ce8743db2f3 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Python/virtualenv.py @@ -0,0 +1 @@ +"""Python tooling: virtualenv.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/README.md b/Brain_O_Codebase/brain_v0_5/Tools/README.md new file mode 100644 index 0000000000000000000000000000000000000000..40986faedf944d14f99ffc88b9d89e4ca48082a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/README.md @@ -0,0 +1 @@ +# Tools diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..4e54c447dc354a9dfeee168dcf58d7ce2e5c64a1 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/__init__.py @@ -0,0 +1,15 @@ +from __future__ import annotations +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def web_search(ctx=None, query: str = "", num_results: int = 5, **kw) -> ToolResult: + # Host should override; placeholder uses no network assumption + return ToolResult("web_search", True, f"[web_search stub] q={query!r} n={num_results}. Wire Serp/Brave in host.") + +def local_search(ctx=None, query: str = "", path: str = ".", **kw) -> ToolResult: + from Tools.Filesystem import search_files + return search_files(ctx=ctx, query=query, path=path) + +def register(registry): + registry.register(make_tool("web_search", "Search the public web", {"query":{"type":"string","required":True},"num_results":{"type":"integer"}}, web_search, "search", "net:read")) + registry.register(make_tool("local_search", "Search local workspace", {"query":{"type":"string","required":True},"path":{"type":"string"}}, local_search, "search", "fs:read")) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/code_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/code_search.py new file mode 100644 index 0000000000000000000000000000000000000000..1a01802b4fcef9bd9a3871cd5cbfae2534479612 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/code_search.py @@ -0,0 +1 @@ +"""Search: code_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/document_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/document_search.py new file mode 100644 index 0000000000000000000000000000000000000000..37a4c0f25fa406fdfb5c5c4a66862115bb15a0ab --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/document_search.py @@ -0,0 +1 @@ +"""Search: document_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/graph_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/graph_search.py new file mode 100644 index 0000000000000000000000000000000000000000..bf2fbbfd92fbc0f1696e88c07c1a9603f4ac4fbd --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/graph_search.py @@ -0,0 +1 @@ +"""Search: graph_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/local_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/local_search.py new file mode 100644 index 0000000000000000000000000000000000000000..c82e327d3be340bf2e5ac82e63f9d5acb6e3e396 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/local_search.py @@ -0,0 +1 @@ +"""Search: local_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/ranking.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/ranking.py new file mode 100644 index 0000000000000000000000000000000000000000..3e904083eea4a6f9e7e56ce1303ca672bceae8b7 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/ranking.py @@ -0,0 +1 @@ +"""Search: ranking.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/reranking.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/reranking.py new file mode 100644 index 0000000000000000000000000000000000000000..2c2d851e460a2ae21a30b2692114ad99b904c743 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/reranking.py @@ -0,0 +1 @@ +"""Search: reranking.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/search.py new file mode 100644 index 0000000000000000000000000000000000000000..59150f8105c26daa40b053465e135e5787d4867e --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/search.py @@ -0,0 +1 @@ +"""Search: search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/semantic_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/semantic_search.py new file mode 100644 index 0000000000000000000000000000000000000000..61e02b093129dcfed998a21d40ee3203cbf91cf9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/semantic_search.py @@ -0,0 +1 @@ +"""Search: semantic_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/source_validation.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/source_validation.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ba793787617fdf1298366c1eb8d170c386a1ec --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/source_validation.py @@ -0,0 +1 @@ +"""Search: source_validation.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Search/web_search.py b/Brain_O_Codebase/brain_v0_5/Tools/Search/web_search.py new file mode 100644 index 0000000000000000000000000000000000000000..38ac0658eea19f0634fbb9494c590b4b5330ba20 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Search/web_search.py @@ -0,0 +1 @@ +"""Search: web_search.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..a355aaae2e440a9d26de34248351ec5164ab393f --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/__init__.py @@ -0,0 +1,13 @@ +from __future__ import annotations +import re +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult +_DANGEROUS = re.compile(r"(rm\s+-rf\s+/|mkfs.|dd\s+if=)", re.I) + +def command_filter(ctx=None, command: str = "", **kw) -> ToolResult: + if _DANGEROUS.search(command or ""): + return ToolResult("command_filter", False, "blocked dangerous command", error_type="permission") + return ToolResult("command_filter", True, "ok") + +def register(registry): + registry.register(make_tool("command_filter", "Check command safety", {"command":{"type":"string","required":True}}, command_filter, "security", None)) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/audit_log.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/audit_log.py new file mode 100644 index 0000000000000000000000000000000000000000..f9b54fc4a66e5c68142dc5b8155c8ddfceee5859 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/audit_log.py @@ -0,0 +1 @@ +"""Security: audit_log.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/command_filter.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/command_filter.py new file mode 100644 index 0000000000000000000000000000000000000000..d240f4bf7e14213888e8d199c5c65976de2a6f77 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/command_filter.py @@ -0,0 +1 @@ +"""Security: command_filter.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/credential_store.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/credential_store.py new file mode 100644 index 0000000000000000000000000000000000000000..6cdc8cb3d3a9ca21653cfc51a181a4df9d08b8ad --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/credential_store.py @@ -0,0 +1 @@ +"""Security: credential_store.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/encryption.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/encryption.py new file mode 100644 index 0000000000000000000000000000000000000000..71f400d34407d44b4eaba013d619e0b8feb0215b --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/encryption.py @@ -0,0 +1 @@ +"""Security: encryption.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/filesystem_guard.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/filesystem_guard.py new file mode 100644 index 0000000000000000000000000000000000000000..94da7d4ef1fe308fdd010ac8a1f19a6247866840 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/filesystem_guard.py @@ -0,0 +1 @@ +"""Security: filesystem_guard.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/permissions.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/permissions.py new file mode 100644 index 0000000000000000000000000000000000000000..7d7850c403312fc4ea9c92626804b985180398c8 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/permissions.py @@ -0,0 +1 @@ +"""Security: permissions.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/policy_engine.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/policy_engine.py new file mode 100644 index 0000000000000000000000000000000000000000..3cd5b175268ebcba3ea810b49d3a454e579b6d71 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/policy_engine.py @@ -0,0 +1 @@ +"""Security: policy_engine.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/risk_analyzer.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/risk_analyzer.py new file mode 100644 index 0000000000000000000000000000000000000000..090606b99aa4a797c39eeab19c738ae75e722ad2 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/risk_analyzer.py @@ -0,0 +1 @@ +"""Security: risk_analyzer.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/sandbox.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/sandbox.py new file mode 100644 index 0000000000000000000000000000000000000000..1bf1fae9789d2d3fb080e390f59933813117502d --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/sandbox.py @@ -0,0 +1 @@ +"""Security: sandbox.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Security/secrets.py b/Brain_O_Codebase/brain_v0_5/Tools/Security/secrets.py new file mode 100644 index 0000000000000000000000000000000000000000..02984a995d2005cdff8c32fee94ed0905e72eb69 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Security/secrets.py @@ -0,0 +1 @@ +"""Security: secrets.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/__init__.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..995b3932ead04acf851783782a8383d6d8432841 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/__init__.py @@ -0,0 +1,26 @@ +from __future__ import annotations +import os, subprocess, shlex +from Tools.Core.tool_factory import make_tool +from Tools.Core.tool_result import ToolResult + +def run_terminal(ctx=None, command: str = "", cwd: str | None = None, timeout: int = 60, **kw) -> ToolResult: + work = cwd or str(getattr(ctx, "cwd", ".") if ctx else ".") + try: + proc = subprocess.run( + command, shell=True, cwd=work, capture_output=True, text=True, timeout=timeout, + env={**os.environ, **(getattr(ctx, "env", {}) or {})}, + ) + out = (proc.stdout or "") + (("\n" + proc.stderr) if proc.stderr else "") + return ToolResult("run_terminal", proc.returncode == 0, out.strip() or f"(exit {proc.returncode})", + meta={"returncode": proc.returncode}) + except subprocess.TimeoutExpired: + return ToolResult("run_terminal", False, f"timeout after {timeout}s", error_type="runtime") + except Exception as e: + return ToolResult("run_terminal", False, str(e), error_type="runtime") + +def register(registry): + registry.register(make_tool( + "run_terminal", "Run shell command", + {"command": {"type": "string", "required": True}, "cwd": {"type": "string"}, "timeout": {"type": "integer"}}, + run_terminal, "terminal", "terminal:run", parallel_safe=False, + )) diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/command_runner.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/command_runner.py new file mode 100644 index 0000000000000000000000000000000000000000..67fd3502762a485b4680b945404a0a5e8a782d16 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/command_runner.py @@ -0,0 +1 @@ +"""Terminal support: command_runner.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/environment.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/environment.py new file mode 100644 index 0000000000000000000000000000000000000000..148e8b7e8bcbec1f163e967f776768d18a7d0b68 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/environment.py @@ -0,0 +1 @@ +"""Terminal support: environment.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/history.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/history.py new file mode 100644 index 0000000000000000000000000000000000000000..1bc67bd764a2c0620627f21589876dabc671cb69 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/history.py @@ -0,0 +1 @@ +"""Terminal support: history.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/process_manager.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/process_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..9268a7e0806855150c8de84fb454cb36f09cd071 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/process_manager.py @@ -0,0 +1 @@ +"""Terminal support: process_manager.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/sandbox.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/sandbox.py new file mode 100644 index 0000000000000000000000000000000000000000..2a79a1b1ab61132c993ac18193095f501c71b1c6 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/sandbox.py @@ -0,0 +1 @@ +"""Terminal support: sandbox.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/session.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/session.py new file mode 100644 index 0000000000000000000000000000000000000000..241e08ed7cf5b2b2721bb74777d3f14115cc71ca --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/session.py @@ -0,0 +1 @@ +"""Terminal support: session.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/shell.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/shell.py new file mode 100644 index 0000000000000000000000000000000000000000..19c5e959818707792fc7bdfd81ac3ffdd9b63e72 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/shell.py @@ -0,0 +1 @@ +"""Terminal support: shell.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/signals.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/signals.py new file mode 100644 index 0000000000000000000000000000000000000000..7a30e4ca7c64fca00f7e49e723bcc286dc1b0369 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/signals.py @@ -0,0 +1 @@ +"""Terminal support: signals.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/stderr.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/stderr.py new file mode 100644 index 0000000000000000000000000000000000000000..00d016b93216c9e5a98c23a5a3ed3c39a33f2ac4 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/stderr.py @@ -0,0 +1 @@ +"""Terminal support: stderr.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/stdout.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/stdout.py new file mode 100644 index 0000000000000000000000000000000000000000..e8bde38361d6417ee498df7630e0cbcd12f1c274 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/stdout.py @@ -0,0 +1 @@ +"""Terminal support: stdout.""" diff --git a/Brain_O_Codebase/brain_v0_5/Tools/Terminal/terminal.py b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/terminal.py new file mode 100644 index 0000000000000000000000000000000000000000..600b7fa5a725331c6054a976011847cd264686a4 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Tools/Terminal/terminal.py @@ -0,0 +1 @@ +"""Terminal support: terminal.""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/__init__.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7cbbcb84d1e65dd2b3f3b400f5dd69fb6fb228a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/__init__.py @@ -0,0 +1 @@ +"""p""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_cleaner.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_cleaner.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_cleaner.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_converter.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_converter.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_converter.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_loader.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_loader.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_loader.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_merger.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_merger.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_merger.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_metadata.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_metadata.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_metadata.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_saver.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_saver.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_saver.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_validator.py b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_validator.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Checkpoints/checkpoint_validator.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/__init__.py b/Brain_O_Codebase/brain_v0_5/Training/Config/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7cbbcb84d1e65dd2b3f3b400f5dd69fb6fb228a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/__init__.py @@ -0,0 +1 @@ +"""p""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/dataset_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/dataset_config.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/dataset_config.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/distributed_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/distributed_config.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/distributed_config.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/evaluation_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/evaluation_config.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/evaluation_config.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/experiment_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/experiment_config.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/experiment_config.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/optimizer_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/optimizer_config.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/optimizer_config.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/scheduler_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/scheduler_config.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/scheduler_config.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Config/training_config.py b/Brain_O_Codebase/brain_v0_5/Training/Config/training_config.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b111da02b0d5f25781c08685ce4aa25a687308 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Config/training_config.py @@ -0,0 +1,13 @@ +from __future__ import annotations +from dataclasses import dataclass + +@dataclass +class TrainingConfig: + batch_size: int = 32 + seq_len: int = 512 + lr: float = 3e-4 + warmup_steps: int = 500 + max_steps: int = 10000 + grad_clip: float = 1.0 + weight_decay: float = 0.1 + bf16: bool = True diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/__init__.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7cbbcb84d1e65dd2b3f3b400f5dd69fb6fb228a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/__init__.py @@ -0,0 +1 @@ +"""p""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/cached_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/cached_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/cached_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_loader.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_loader.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_loader.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_manager.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_manager.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_registry.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_registry.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_registry.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_splitter.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_splitter.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_splitter.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_statistics.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_statistics.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_statistics.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_validator.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_validator.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/dataset_validator.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/iterable_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/iterable_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/iterable_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/multilingual_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/multilingual_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/multilingual_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/multimodal_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/multimodal_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/multimodal_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/sharded_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/sharded_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/sharded_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/streaming_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/streaming_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/streaming_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Datasets/synthetic_dataset.py b/Brain_O_Codebase/brain_v0_5/Training/Datasets/synthetic_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Datasets/synthetic_dataset.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/__init__.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7cbbcb84d1e65dd2b3f3b400f5dd69fb6fb228a9 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/__init__.py @@ -0,0 +1 @@ +"""p""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/communication.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/communication.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/communication.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/data_parallel.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/data_parallel.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/data_parallel.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/deepspeed.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/deepspeed.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/deepspeed.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/distributed_checkpoint.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/distributed_checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/distributed_checkpoint.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/distributed_manager.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/distributed_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/distributed_manager.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/fsdp.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/fsdp.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/fsdp.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/Distributed/pipeline_parallel.py b/Brain_O_Codebase/brain_v0_5/Training/Distributed/pipeline_parallel.py new file mode 100644 index 0000000000000000000000000000000000000000..5cba5b51ef699207037ba2ecd0110fd259957423 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/Distributed/pipeline_parallel.py @@ -0,0 +1 @@ +"""m""" diff --git a/Brain_O_Codebase/brain_v0_5/Training/__init__.py b/Brain_O_Codebase/brain_v0_5/Training/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c44ff6f57ab67f4971e1fa79b82fc60a24491c19 --- /dev/null +++ b/Brain_O_Codebase/brain_v0_5/Training/__init__.py @@ -0,0 +1,5 @@ +from Training.Engine.training_engine import TrainingEngine, TrainConfig +from Training.Config.training_config import TrainingConfig +from Training.Evaluation.perplexity import perplexity_from_loss +from Training.Utils.seed import set_seed +__all__=["TrainingEngine","TrainConfig","TrainingConfig","perplexity_from_loss","set_seed"]