feat(tool): implement BuiltinAdapter class and MCP automatic resource slot creation (#964)
CI / build (push) Successful in 18s
CI / lint (push) Successful in 3m20s
CI / typecheck (push) Successful in 3m56s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m1s
CI / quality (push) Successful in 4m8s
CI / unit_tests (push) Successful in 6m40s
CI / integration_tests (push) Successful in 6m40s
CI / docker (push) Successful in 1m19s
CI / e2e_tests (push) Failing after 17m17s
CI / coverage (push) Failing after 18m20s
CI / benchmark-publish (push) Successful in 31m37s
CI / status-check (push) Failing after 1s

## Summary

Implement `BuiltinAdapter` class and MCP automatic resource slot creation. Two main changes:

### 1. BuiltinAdapter Class (`tool/builtins/adapter.py`)
Formal adapter implementing the tool adapter lifecycle pattern for built-in tools:
- `discover()` — returns all built-in tool descriptors (file, git, subplan tools)
- `register(registry)` — registers all tools in a ToolRegistry, returns registered names
- `activate()`/`deactivate()` — no-ops (built-in tools are always available)
- Wraps existing `ALL_FILE_TOOLS`, `ALL_GIT_TOOLS`, `ALL_SUBPLAN_TOOLS` lists
- Backward compatible — existing registration functions still work

### 2. MCP Resource Slot Inference (`mcp/adapter.py`)
New `infer_resource_slots()` static method on `MCPToolAdapter`:
- Scans MCP tool parameter schemas for file/directory/repo patterns
- Creates `ResourceSlot` objects with appropriate type, access mode, binding mode
- Mapping: `file_path`→file(rw), `directory`→directory(ro), `repo_path`→git-checkout(rw)
- Slots stored in `source_metadata["resource_slots"]` on registered `ToolSpec` objects

### Quality Gates

| Session | Result |
|---|---|
| `nox -s lint` | PASS |
| `nox -s typecheck` | PASS (0 errors) |
| `nox -s unit_tests` | PASS (10,817 scenarios) |
| `nox -s integration_tests` | PASS (6 new tests) |
| `nox -s coverage_report` | 97% (>= 97%) |

Closes #882

Reviewed-on: #964
Co-authored-by: Brent E. Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent E. Edwards <brent.edwards@cleverthis.com>
This commit was merged in pull request #964.
This commit is contained in:
2026-03-21 05:30:01 +00:00
committed by Forgejo
parent b88bc0ec1b
commit 34c6972a05
9 changed files with 779 additions and 4 deletions
+21 -2
View File
@@ -6,6 +6,9 @@ overhead across varying checkpoint counts.
from __future__ import annotations
import shutil
import subprocess
import tempfile
from typing import ClassVar
from cleveragents.application.services.checkpoint_service import CheckpointService
@@ -74,11 +77,27 @@ class RollbackSuite:
"""Benchmark rollback operations."""
def setup(self) -> None:
"""Prepare a service with sandbox and checkpoints."""
"""Prepare a service with a real git sandbox and checkpoints."""
self._tmpdir = tempfile.mkdtemp(prefix="asv-rollback-")
subprocess.run(
["git", "init", self._tmpdir],
check=True,
capture_output=True,
)
subprocess.run(
["git", "commit", "--allow-empty", "-m", "initial"],
check=True,
capture_output=True,
cwd=self._tmpdir,
)
self.svc = CheckpointService()
self.svc.register_sandbox(_PLAN_ID, "sandbox-path")
self.svc.register_sandbox(_PLAN_ID, self._tmpdir)
self.cp = self.svc.create_checkpoint(_PLAN_ID, "commit-abc")
def teardown(self) -> None:
"""Remove temporary sandbox directory."""
shutil.rmtree(self._tmpdir, ignore_errors=True)
def time_rollback(self) -> None:
"""Time a single rollback operation."""
self.svc.rollback_to_checkpoint(_PLAN_ID, self.cp.checkpoint_id)