feat(plugins): move fresh context out of core with provider.cache and composer hooks #52

Closed
gabrielvidal wants to merge 0 commits from fresh-context-plugin into main
pull from: fresh-context-plugin
Owner

Summary

Moves the "fresh context" feature out of ai-agent core into generic plugin extension points so the new fresh-context live plugin (in the companion ai-agent-plugins PR) owns all cache-expiry estimation, nudges, confirmation sheets, compaction instructions, settings, and per-user Auto fresh state. Model provider plugins now declare their own prompt-cache parameters (provider.cache), and thread/composer plugins can read recent conversation feed timestamps and intercept idle resumes generically.

Key changes

  • Provider cache declarations (backend/plugins/typed_manifest.py, backend/plugins/providers.py, backend/fixtures/typed_plugins/provider-*/plugin.json):
    • Added optional provider.cache (defaultTtlSeconds, tiers with ttlSeconds/writeMult, expiryMarginSeconds, warmPrefixTokens), omitted from normalized manifests when undeclared so existing provider approval fingerprints stay unchanged.
    • Exposed vendors[].cache on GET /api/providers, added ProviderRegistry.cache_for(model_id), and added GET /proxy/tools/plugins/{pid}/hub/providers (capability models.read, owner & managed guests).
    • Updated provider-anthropic, provider-openai, and provider-google test fixtures (and frontend mocks) with their declared cache specs.
  • Conversation feed bridge & slot updates (backend/plugins/proxyroutes.py, frontend/src/business/plugins/components/ConversationPluginPlaces.tsx):
    • Added GET /proxy/tools/plugins/{pid}/hub/conversations/{sid}/feed?tail=20 (conversations.read, owner & guest-scoped) returning recent message roles, kinds, timestamps, models, context tokens, and optional cacheTtl hint (never message text).
    • Added generic update.feed (including echoesPending and last 10 {role, kind, ts, model} items) to conversation.threadHeader, conversation.threadEnd, and conversation.threadFooter slots.
  • Generic composer & compaction hooks (backend/plugins/manifest.py, backend/plugins/composer_bridge.py, backend/plugins/routes.py, backend/runs/routes.py, backend/runs/service.py, frontend/src/business/conversations/components/ResumeBox.tsx, SendMenuButton.tsx, useSendSlots.ts):
    • Added composer.beforeSend and runs.compact provides keys and POST /api/plugins/composer/before-send (supporting proceed, modify with resume.compact, or modal on an app.modal slot; failing open to proceed).
    • Extended composer.send slots with optional contexts, guestAllowed, requiresHarnessCap, and directAction (no html required when directAction is set).
    • Updated /api/resume to accept generic compact: {model, instructions} alongside fresh: true (delegated to the active runs.compact provider; gated on the harness's fresh_context capability).
    • Removed hardcoded fresh-context logic and onSendFresh from ResumeBox / SendMenuButton.
  • Core cleanup & one-time carryover:
    • Deleted backend/runs/fresh.py, GET/PUT /api/fresh-context, frontend/src/lib/freshContext.ts, FreshContext.tsx, business/settings/pages/FreshContext.tsx, core users.autoFresh, Extras auto-fresh rows, and freshStrip/cacheCountdown visibility keys.
    • Extracted CompactDivider.tsx for transcript compact_boundary items and dropped compact.saved (gain_prompt/gain_call) from backend/conversations/parse/usage.py so the core parser has zero cache-expiry math.
    • Added carryover.fresh_context to migrate legacy /data/fresh-context.json → plugin shared settings.json and guest users.json autoFresh → managed plugin grants.
    • Redirected /settings/fresh-context and #fresh-context to /plugins/fresh-context/settings; regenerated OpenAPI, orval types, authz matrix, telemetry features, i18n keys, and docs.

Key decisions

  • Validated in ask-form fresh-context-as-a-plugin_rqk199:
    • Full provider.cache descriptor on providers (including expiryMarginSeconds and warmPrefixTokens) rather than keeping provider-specific constants in the plugin.
    • Feed message timestamps + optional cacheTtl tier hint (5m vs 1h), so cache age comes from the conversation feed while respecting Anthropic's explicit cache-write tier.
    • Reused existing conversation.threadFooter and conversation.threadEnd slots rather than introducing a new message-card slot.
    • Kept CompactDivider parsing/rendering in core (since Claude Code emits compact_boundary on auto-compact and terminal /compact without the plugin) and dropped compact.saved math from core.
    • Moved both owner settings and guest Auto fresh into the seeded managed plugin (managed.grantFields) with a one-time carryover migration.
  • Carryover storage alignment: carryover.fresh_context writes migrated owner settings to store.shared_data_dir("fresh-context") / "settings.json" (AIA_PLUGIN_SHARED_DIR/settings.json) so both owner and guest handlers evaluate sends against the migrated thresholds.

Changelog

  • Changed: Moved Fresh context out of core into generic plugin hooks (provider.cache, conversation feed timestamps, composer.beforeSend, runs.compact, and composer.send direct actions) backed by the fresh-context live plugin.
  • Changed: Settings → Extras now focuses on the un-send window; /settings/fresh-context redirects to the fresh-context plugin's Settings page, and guest Auto fresh is managed through plugin grants.
  • Removed: Core compaction savings estimate (saved ≈ $X) from the thread's compaction divider (keeping token reduction, cost, duration, and foldable summary).

Test notes

  • Cross-repo manifest validation: validated provider-anthropic, provider-openai, provider-google, provider-openrouter, provider-evox2, and fresh-context from the companion ai-agent-plugins worktree against the updated core validate_manifest() — all passed, with 100% provider fixture cache parity.
  • Backend: uv run --with-requirements requirements.txt --with pytest python -m pytest test_fresh_context_migration.py → 43 passed (covers provider.cache, hub/providers, hub/conversations/{sid}/feed, composer.beforeSend, runs.compact, composer.send extensions, carryover.fresh_context, and parser cache clock/compaction divider).
  • Frontend: npx tsc --noEmit (0 errors) and npx vitest run → 181 test files passed, 1,179 tests passed.
  • Not deployed from EVOX2: merge together with the companion ai-agent-plugins PR and deploy from the Homelab (ai-agent/deploy.sh).

Screenshots

shot-core-extras.png

## Summary Moves the "fresh context" feature out of `ai-agent` core into generic plugin extension points so the new `fresh-context` live plugin (in the companion `ai-agent-plugins` PR) owns all cache-expiry estimation, nudges, confirmation sheets, compaction instructions, settings, and per-user *Auto fresh* state. Model provider plugins now declare their own prompt-cache parameters (`provider.cache`), and thread/composer plugins can read recent conversation feed timestamps and intercept idle resumes generically. ## Key changes - **Provider cache declarations (`backend/plugins/typed_manifest.py`, `backend/plugins/providers.py`, `backend/fixtures/typed_plugins/provider-*/plugin.json`)**: - Added optional `provider.cache` (`defaultTtlSeconds`, `tiers` with `ttlSeconds`/`writeMult`, `expiryMarginSeconds`, `warmPrefixTokens`), omitted from normalized manifests when undeclared so existing provider approval fingerprints stay unchanged. - Exposed `vendors[].cache` on `GET /api/providers`, added `ProviderRegistry.cache_for(model_id)`, and added `GET /proxy/tools/plugins/{pid}/hub/providers` (capability `models.read`, owner & managed guests). - Updated `provider-anthropic`, `provider-openai`, and `provider-google` test fixtures (and frontend mocks) with their declared cache specs. - **Conversation feed bridge & slot updates (`backend/plugins/proxyroutes.py`, `frontend/src/business/plugins/components/ConversationPluginPlaces.tsx`)**: - Added `GET /proxy/tools/plugins/{pid}/hub/conversations/{sid}/feed?tail=20` (`conversations.read`, owner & guest-scoped) returning recent message roles, kinds, timestamps, models, context tokens, and optional `cacheTtl` hint (never message text). - Added generic `update.feed` (including `echoesPending` and last 10 `{role, kind, ts, model}` items) to `conversation.threadHeader`, `conversation.threadEnd`, and `conversation.threadFooter` slots. - **Generic composer & compaction hooks (`backend/plugins/manifest.py`, `backend/plugins/composer_bridge.py`, `backend/plugins/routes.py`, `backend/runs/routes.py`, `backend/runs/service.py`, `frontend/src/business/conversations/components/ResumeBox.tsx`, `SendMenuButton.tsx`, `useSendSlots.ts`)**: - Added `composer.beforeSend` and `runs.compact` `provides` keys and `POST /api/plugins/composer/before-send` (supporting `proceed`, `modify` with `resume.compact`, or `modal` on an `app.modal` slot; failing open to `proceed`). - Extended `composer.send` slots with optional `contexts`, `guestAllowed`, `requiresHarnessCap`, and `directAction` (no `html` required when `directAction` is set). - Updated `/api/resume` to accept generic `compact: {model, instructions}` alongside `fresh: true` (delegated to the active `runs.compact` provider; gated on the harness's `fresh_context` capability). - Removed hardcoded fresh-context logic and `onSendFresh` from `ResumeBox` / `SendMenuButton`. - **Core cleanup & one-time carryover**: - Deleted `backend/runs/fresh.py`, `GET/PUT /api/fresh-context`, `frontend/src/lib/freshContext.ts`, `FreshContext.tsx`, `business/settings/pages/FreshContext.tsx`, core `users.autoFresh`, `Extras` auto-fresh rows, and `freshStrip`/`cacheCountdown` visibility keys. - Extracted `CompactDivider.tsx` for transcript `compact_boundary` items and dropped `compact.saved` (`gain_prompt`/`gain_call`) from `backend/conversations/parse/usage.py` so the core parser has zero cache-expiry math. - Added `carryover.fresh_context` to migrate legacy `/data/fresh-context.json` → plugin shared `settings.json` and guest `users.json` `autoFresh` → managed plugin grants. - Redirected `/settings/fresh-context` and `#fresh-context` to `/plugins/fresh-context/settings`; regenerated OpenAPI, orval types, authz matrix, telemetry features, i18n keys, and docs. ## Key decisions - **Validated in ask-form `fresh-context-as-a-plugin_rqk199`**: - Full `provider.cache` descriptor on providers (including `expiryMarginSeconds` and `warmPrefixTokens`) rather than keeping provider-specific constants in the plugin. - Feed message timestamps + optional `cacheTtl` tier hint (`5m` vs `1h`), so cache age comes from the conversation feed while respecting Anthropic's explicit cache-write tier. - Reused existing `conversation.threadFooter` and `conversation.threadEnd` slots rather than introducing a new message-card slot. - Kept `CompactDivider` parsing/rendering in core (since Claude Code emits `compact_boundary` on auto-compact and terminal `/compact` without the plugin) and dropped `compact.saved` math from core. - Moved both owner settings and guest *Auto fresh* into the seeded managed plugin (`managed.grantFields`) with a one-time carryover migration. - **Carryover storage alignment**: `carryover.fresh_context` writes migrated owner settings to `store.shared_data_dir("fresh-context") / "settings.json"` (`AIA_PLUGIN_SHARED_DIR/settings.json`) so both owner and guest handlers evaluate sends against the migrated thresholds. ## Changelog - Changed: Moved Fresh context out of core into generic plugin hooks (`provider.cache`, conversation feed timestamps, `composer.beforeSend`, `runs.compact`, and `composer.send` direct actions) backed by the `fresh-context` live plugin. - Changed: Settings → Extras now focuses on the un-send window; `/settings/fresh-context` redirects to the `fresh-context` plugin's Settings page, and guest *Auto fresh* is managed through plugin grants. - Removed: Core compaction savings estimate (`saved ≈ $X`) from the thread's compaction divider (keeping token reduction, cost, duration, and foldable summary). ## Test notes - **Cross-repo manifest validation**: validated `provider-anthropic`, `provider-openai`, `provider-google`, `provider-openrouter`, `provider-evox2`, and `fresh-context` from the companion `ai-agent-plugins` worktree against the updated core `validate_manifest()` — all passed, with 100% provider fixture cache parity. - **Backend**: `uv run --with-requirements requirements.txt --with pytest python -m pytest test_fresh_context_migration.py` → **43 passed** (covers `provider.cache`, `hub/providers`, `hub/conversations/{sid}/feed`, `composer.beforeSend`, `runs.compact`, `composer.send` extensions, `carryover.fresh_context`, and parser cache clock/compaction divider). - **Frontend**: `npx tsc --noEmit` (0 errors) and `npx vitest run` → **181 test files passed, 1,179 tests passed**. - **Not deployed from EVOX2**: merge together with the companion `ai-agent-plugins` PR and deploy from the Homelab (`ai-agent/deploy.sh`). ## Screenshots ![shot-core-extras.png](https://git.gabvdl.xyz/attachments/7554afa7-2fe9-4d45-b31c-06f209071195)
gabrielvidal self-assigned this 2026-12-01 17:09:40 +01:00
gabrielvidal added 1 commit 2026-12-01 17:09:40 +01:00
Author
Owner

Merged into main as 94f808d3 by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/45784aea-fc45-4907-a993-d39db4db6c40

Resolved against main's removal of the Claude Code hooks page (both removals kept); fix-up 8417dfbd for the settings-search test and i18n keys. Deployed 8417dfbd..

Merged into `main` as 94f808d3 by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/45784aea-fc45-4907-a993-d39db4db6c40 Resolved against main's removal of the Claude Code hooks page (both removals kept); fix-up 8417dfbd for the settings-search test and i18n keys. Deployed 8417dfbd..
gabrielvidal closed this pull request 2026-12-01 17:35:31 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#52