Skip to content

feat(ace): ACE Playbook Hooks — Curator Pattern (Spec 18) - #17

Merged
timeleft-- merged 10 commits into
mainfrom
builder/task-mg3z
Mar 10, 2026
Merged

timeleft-- merged 10 commits into
mainfrom
builder/task-mg3z

Conversation

@timeleft--

Copy link
Copy Markdown
Member

Summary

  • Implements the ACE (Agentic Context Engine) Curator pattern as a FAVA Trails protocol hook module (src/fava_trails/protocols/ace/)
  • Pure Python, zero external dependencies — mirrors protocols/secom structure
  • 6 lifecycle hooks: on_startup, on_recall, before_save, after_save, after_propose, after_supersede

Changes

Phase 1 — rules.py: PlaybookRule dataclass with matches() (AND logic: source_type, confidence_lt, tags_include, tags_exclude, age_lt_days) and evaluate() (Laplace-smoothed ratio, clamped to [0.5, 2.0]). _parse_rules() with graceful malformed-entry skip.

Phase 2 — __init__.py: All 6 hooks following SECOM patterns. 5-minute TTL cache per scope. Cache invalidated immediately on after_save/after_propose/after_supersede for ace-playbook tagged thoughts. Telemetry accumulators (_SAVE_TELEMETRY, _SUPERSEDE_STATS) for external Reflector.

Phase 3 — tests/test_ace.py: 64 tests across TestConfigure, TestPlaybookRule, TestParseRules, TestOnStartup, TestOnRecall, TestBeforeSave, TestAfterSave, TestAfterPropose, TestAfterSupersede, TestPipelineIntegration. Includes concurrent cold-cache load test and TTL-expiry reload test.

Phase 4 — README.md + example_rules/: Quick start (module ref + local copy), config contract, all 6 hook lifecycle points, rule authoring guide with scoring formula, 4 example rules demonstrating retrieval_priority, confidence_floor, staleness, and anti_pattern rule types.

Test plan

  • uv run pytest -v — all 446 tests pass (including 64 new ACE tests)
  • uv run ruff check src/ — no linting errors
  • Review example rules in src/fava_trails/protocols/ace/example_rules/

🤖 Generated with Claude Code

timeleft-- and others added 4 commits March 9, 2026 18:11
ASPIR plan for Spec 18 (ACE Curator Pattern). Consulted with
GPT 5.3 Codex (8/10) and Gemini 3.1 Pro (9/10). Key change
from spec: added after_propose hook for cache invalidation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 1+2: rules.py with PlaybookRule dataclass (matches/evaluate with
Laplace smoothing + [0.5,2.0] clamping, age_lt_days support) and _parse_rules
with graceful skip. __init__.py with on_startup, on_recall, before_save,
after_save, after_propose, after_supersede hooks following SECOM patterns.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Phase 3: 64 tests covering TestConfigure, TestPlaybookRule (matches/evaluate
with clamping/Laplace), TestParseRules (malformed skip), TestOnStartup,
TestOnRecall (lazy-load/TTL/rerank/concurrent), TestBeforeSave (anti-pattern
Warn + brevity Advise), TestAfterSave/Propose/Supersede (cache invalidation +
telemetry), TestPipelineIntegration (end-to-end + concurrent cold cache).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
README covers quick start (module ref + local copy), config contract,
all 6 hook lifecycle points, rule authoring guide with match criteria
table and scoring formula, MCP create-and-promote workflow, ACE vs flat
storage comparison, and literature references.

4 example rules: boost-recent-decisions, deprioritize-low-confidence,
anti-pattern-no-terse-decisions, boost-tagged-important (with feedback
counters demonstrating Laplace growth).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread tests/test_ace.py Fixed
timeleft-- and others added 6 commits March 10, 2026 04:11
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…ence 0.0

Three bugs identified during codereview:
- _parse_rules() now validates match/action are dicts before creating PlaybookRule
- evaluate() normalizes helpful/harmful counters to non-negative before ratio computation
- on_recall uses explicit None check for confidence instead of falsy `or 0.5`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eview)

- matches() confidence_lt: use explicit None check instead of falsy `or 0.0`
  (confidence=0.0 was correctly handled by accident, but None was silently
  treated as 0.0 — now explicit)
- _SAVE_TELEMETRY and _SUPERSEDE_STATS: FIFO eviction at configurable cap
  (default 10,000 per scope, ~3MB/scope). Configurable via
  telemetry_max_per_scope in hook config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0.0 is not guaranteed to be older than TTL_SECONDS on systems
with uptime < 5 minutes (e.g. fresh CI containers).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@timeleft--
timeleft-- merged commit 6477af5 into main Mar 10, 2026
7 checks passed
@timeleft--
timeleft-- deleted the builder/task-mg3z branch March 10, 2026 11:29
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