Skip to content

feat!: v0.4.0 — hook redesign + built-in response cache#10

Merged
inhuman merged 4 commits into
mainfrom
010-hooks-cache-redesign
May 11, 2026
Merged

feat!: v0.4.0 — hook redesign + built-in response cache#10
inhuman merged 4 commits into
mainfrom
010-hooks-cache-redesign

Conversation

@inhuman
Copy link
Copy Markdown
Owner

@inhuman inhuman commented May 11, 2026

Summary

  • BREAKING: BeforeCallHook now returns (context.Context, *CallResult, error) — enables context propagation and short-circuit from Before
  • BREAKING: AfterCallHook gains duration time.Duration final param; fires on all code paths (rejections, cache hits, short-circuits)
  • BREAKING: ResultTransformHook receives *CallResult and mutates in place (text + image parts)
  • Built-in bounded LRU response cache (256 entries, 30 s TTL, default ON) with pluggable Cache interface
  • RejectReason enum + OnRejectedCallFunc + WithOnRejectedCall for rejected-call observability
  • OnConnectFunc + WithOnConnect fires once per server after successful connect
  • (*CallResult).Clone() deep-copy method
  • policy/ and examples/ migrated to new signatures

Test plan

  • All existing tests pass (go test -race ./...)
  • ~30 new test cases: BeforeCall short-circuit, ctx propagation, chain semantics, ResultTransform on Parts, AfterCall duration, OnRejectedCall ×4 reasons + panic recovery, cache hit/miss/TTL/eviction/scope/deep-copy, IsCacheHit, WithoutCache, Clone, OnConnect ×2
  • Race detector clean across all modules
  • go vet ./... clean
  • policy/, examples/* compile and tests pass

Ivan Diachenko added 4 commits May 12, 2026 01:46
BREAKING: BeforeCallHook now returns (context.Context, *CallResult, error)
  - non-nil error → abort
  - non-nil result → short-circuit (skips upstream + ResultTransform; AfterCall fires)
  - non-nil ctx → propagated through chain and all downstream steps

BREAKING: AfterCallHook gains duration time.Duration final parameter; fires on
all code paths including rejections, cache hits, and short-circuits.

BREAKING: ResultTransformHook now receives *CallResult and mutates in place;
can sanitize both Text and image Parts.

New: built-in bounded LRU response cache (256 entries, 30s TTL, default ON)
  - Cache interface + KeyFunc for external backends (Redis etc.)
  - WithCache, WithCacheTTL, WithCacheSize, WithoutCache, WithCacheKey options
  - WithCacheScope(ctx, scope) / CacheScope(ctx) / IsCacheHit(ctx)
  - Per-tool TTL via ToolInfo.Custom["cache_ttl"]
  - (*CallResult).Clone() deep-copy method

New: RejectReason enum + OnRejectedCallFunc + WithOnRejectedCall option
New: OnConnectFunc + WithOnConnect option

Migrated: policy/ DenyDestructive, RequireRoles, RateLimit, AuditLog
Updated: examples/policy, examples/redact
@inhuman inhuman merged commit 7cc0d23 into main May 11, 2026
3 checks passed
@inhuman inhuman deleted the 010-hooks-cache-redesign branch May 11, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant