Files
gnoma/internal/tool/tool.go
vikingowl 14b88cadcc feat: M1-M7 gap audit phase 3 — context prefix, deferred tools, compact hooks
Gap 11 (M6): Fixed context prefix
- Window.PrefixMessages stores immutable docs (CLAUDE.md, .gnoma/GNOMA.md)
- Prefix stripped before compaction, prepended after — survives all compaction
- AllMessages() returns prefix + history for provider requests
- main.go loads CLAUDE.md and .gnoma/GNOMA.md at startup as prefix

Gap 12 (M6): Deferred tool loading
- DeferrableTool optional interface: ShouldDefer() bool
- buildRequest() skips deferred tools until activated
- Tools auto-activate on first model request (activatedTools map)
- agent + spawn_elfs marked as deferrable (large schemas, rarely needed early)
- Saves ~800 tokens per deferred tool per request

Gap 13 (M6): Pre/post compact hooks
- OnPreCompact/OnPostCompact callbacks in WindowConfig
- Called in doCompact() (shared by CompactIfNeeded + ForceCompact)
- M8 hooks system will extend these to full protocol
2026-04-04 20:46:50 +02:00

30 lines
960 B
Go

package tool
import (
"context"
"encoding/json"
)
// Tool is the interface every tool must implement.
type Tool interface {
// Name returns the tool's identifier (used in LLM tool schemas).
Name() string
// Description returns a human-readable description for the LLM.
Description() string
// Parameters returns the JSON Schema for the tool's input.
Parameters() json.RawMessage
// Execute runs the tool with the given JSON arguments.
Execute(ctx context.Context, args json.RawMessage) (Result, error)
// IsReadOnly returns true if the tool only reads (safe for concurrent execution).
IsReadOnly() bool
// IsDestructive returns true if the tool can cause irreversible changes.
IsDestructive() bool
}
// DeferrableTool is an optional interface for tools that can be excluded
// from initial requests and loaded on demand. Reduces token overhead
// for rarely-used tools with large schemas.
type DeferrableTool interface {
ShouldDefer() bool
}