Expand description
Context-Generic Programming (CGP) substrate for VT Code
Applies the provider-trait pattern from CGP to decouple tool runtime
composition from coherence restrictions. Instead of relying on blanket
impls or adapter newtypes, each capability (approval, sandboxing,
execution, metadata, etc.) is expressed as a provider trait with an
explicit Context parameter. A lightweight wiring step maps named
components to concrete providers per context type.
§Key ideas (from the RustLab 2025 CGP talk)
- Provider traits move
Selfto an explicit generic parameter, bypassing Rust’s coherence/orphan restrictions. - Component names are zero-sized marker types that act as keys in a type-level lookup table.
delegate_components!wires component names to provider types for a given context, producingHasComponentimplementations.- Consumer code depends only on the component name, not the concrete provider, enabling the same tool/request to run under different policies by simply switching the context.
§Dictionary-passing interpretation
This module intentionally mirrors dictionary-passing style for Rust traits.
HasComponent<Name>::Provider is the elaborated “dictionary” selected for a
capability, while the blanket consumer impls (CanApproveTool,
CanExecuteTool, etc.) are the point where the compiler proves that the
selected provider implements the required provider trait for the current
context. That keeps the capability wiring explicit and avoids depending on
deeper associated-type reasoning at call sites.
§Example
use vtcode_core::components::*;
// Define a context for interactive sessions
struct InteractiveCtx { /* ... */ }
// Wire components to providers
delegate_components!(InteractiveCtx {
ApprovalComponent => PromptApproval,
SandboxComponent => WorkspaceSandbox,
ExecuteComponent => DefaultExecutor,
});
// Define a CI context with different providers
struct CiCtx { /* ... */ }
delegate_components!(CiCtx {
ApprovalComponent => AutoApproval,
SandboxComponent => StrictSandbox,
ExecuteComponent => DefaultExecutor,
});Structs§
- Auto
Approval - Always-approve provider for CI/test contexts.
- Bench
Ctx - Benchmark runtime context — auto-approves, no sandbox, no static middleware.
- Cached
Results - Cache provider backed by
UnifiedCache. - CiCtx
- CI/automation runtime context — auto-approves, strict sandbox.
- Composable
Runtime - A generic tool runtime that composes approval + sandbox + execution through CGP component wiring.
- Default
Metadata - Default metadata provider for contexts that do not customize tool metadata.
- Deny
AllApproval - Provider that denies all operations (useful for read-only/audit contexts).
- Exponential
Backoff Retry - Exponential-backoff retry provider.
- Handler
Facade - A facade that projects a CGP-wired context as a
ToolHandlertrait object. - Interactive
Ctx - Interactive runtime context — used during normal TUI sessions.
- NoCache
- No-op cache provider for contexts that should always execute directly.
- NoLogging
- No-op logging provider for contexts that don’t need telemetry.
- NoRetry
- No-op retry provider for contexts that should fail fast.
- NoSandbox
- No-sandbox provider for trusted/test contexts.
- Passthrough
Executor - Passthrough executor — delegates to a stored
Arc<dyn Tool>. - Passthrough
Metadata - Metadata provider that delegates to an inner
Tool. - Prompt
Approval - Prompt-based approval provider for interactive sessions.
- Retry
Policy - Retry policy shared by CGP retry providers.
- Tool
Bridge Ctx - Bridge context: combines a runtime context with shared tool ownership.
- Tool
Execution Cache Key - Cache key for tool execution results.
- Tool
Facade - A facade that projects a CGP-wired context as a
Tooltrait object. - Tracing
Logging - Logging provider that traces tool execution lifecycle.
- Typed
Tool Ctx - Typed CGP context that carries a concrete tool instance plus runtime policy.
- Typed
Tool Executor - Execute provider that dispatches directly to a typed tool instance.
- Typed
Tool Metadata - Metadata provider that dispatches directly to a typed tool instance.
- Workspace
Sandbox - Workspace-scoped sandbox provider.
Enums§
- Approval
Component - Component for approval/permission checks before tool execution.
- Cache
Component - Component for cached tool results.
- Execute
Component - Component for the core tool execution logic.
- Logging
Component - Component for execution logging and telemetry.
- Metadata
Component - Component for tool metadata (name, description, schemas).
- Output
MapComponent - Component for mapping between output formats (JSON ↔ dual-channel, etc.).
- Retry
Component - Component for retry policy around tool execution.
- Sandbox
Component - Component for sandbox policy selection and enforcement.
- Session
Component - Component for session/turn context creation.
Traits§
- Approval
Provider - Provider trait for approval/permission checks.
- Cache
Provider - Provider trait for cached tool results.
- CanApprove
Tool - CanExecute
Tool - CanProvide
Tool Metadata - CanResolve
Sandbox - Execute
Provider - Provider trait for tool execution (the core “handle” operation).
- HasComponent
- Type-level lookup: maps a component Name to a concrete Provider type for a given implementor (the “context”).
- HasExecution
Caches - Trait for contexts that expose JSON and dual-result caches.
- HasInner
Tool - Trait for contexts that can borrow an inner
Toolfor passthrough. - HasRetry
Policy - Trait for contexts that expose retry configuration.
- HasTool
Instance - Trait for contexts that carry a concrete tool instance.
- HasTool
Ref - Trait for contexts that can expose a tool reference for delegated metadata, validation, and execution.
- HasWorkspace
Root - Trait for contexts that expose a workspace root path.
- Logging
Provider - Provider trait for execution logging and telemetry.
- Metadata
Provider - Provider trait for tool metadata.
- Output
MapProvider - Provider trait for output format mapping.
- Retry
Provider - Provider trait for retry behavior around tool execution.
- Sandbox
Provider - Provider trait for sandbox policy resolution.
Functions§
- wrap_
native_ tool_ ci - Wrap a concrete tool instance in a CI CGP facade without
erasing it to
Arc<dyn Tool>first. - wrap_
native_ tool_ interactive - Wrap a concrete tool instance in an interactive CGP facade without
erasing it to
Arc<dyn Tool>first. - wrap_
tool_ ci - Create a
ToolFacadethat wraps an existingArc<dyn Tool>with CGP-wired auto-approval and no middleware for CI contexts. - wrap_
tool_ interactive - Create a
ToolFacadethat wraps an existingArc<dyn Tool>with CGP-wired approval, sandbox, and middleware for interactive sessions.
Type Aliases§
- Component
Provider - The elaborated provider/dictionary selected by
Ctxfor componentName. - Strict
Workspace Sandbox - Strict sandbox that enforces workspace boundaries in CI.