Skip to content

Agent Zero AI framework

rename chat_compaction plugin to match convention

Nicolas Leão9fc2d9570f99
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 08f0c097c..5538ba148 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -9,7 +9,7 @@
"program": "./run_ui.py",
"console": "integratedTerminal",
"justMyCode": false,
- "args": ["--development=true", "-Xfrozen_modules=off"]
+ "args": ["--development=true", "--port=5555", "-Xfrozen_modules=off"]
},
{
"name": "Debug current file",
diff --git a/plugins/chat_compaction/.toggle-1 b/plugins/_chat_compaction/.toggle-1
similarity index 100%
rename from plugins/chat_compaction/.toggle-1
rename to plugins/_chat_compaction/.toggle-1
diff --git a/plugins/chat_compaction/api/compact_chat.py b/plugins/_chat_compaction/api/compact_chat.py
similarity index 63%
rename from plugins/chat_compaction/api/compact_chat.py
rename to plugins/_chat_compaction/api/compact_chat.py
index a9829a6c1..94569fb30 100644
--- a/plugins/chat_compaction/api/compact_chat.py
+++ b/plugins/_chat_compaction/api/compact_chat.py
@@ -1,7 +1,10 @@
"""API handler for chat compaction."""
-import importlib
from helpers.api import ApiHandler, Input, Output, Request, Response
from agent import AgentContext
+from plugins._chat_compaction.helpers.compactor import (
+ get_compaction_stats,
+ run_compaction,
+)
class CompactChat(ApiHandler):
@@ -18,33 +21,23 @@ class CompactChat(ApiHandler):
if not context:
return Response("Context not found", 404)
- # Validate context is not running
if context.is_running():
return Response("Cannot compact while agent is running", 409)
- # Check if there's enough content to compact
- # Count user-visible log items (what the user sees in the UI)
visible_count = len(context.log.logs)
if visible_count <= 1:
return Response("Not enough messages to compact", 400)
- # Force reload compactor module to pick up latest changes
- import usr.plugins.compaction.helpers.compactor as _compactor_mod
- importlib.reload(_compactor_mod)
-
if action == "stats":
- # Return statistics for confirmation modal
- stats = await _compactor_mod.get_compaction_stats(context)
+ stats = await get_compaction_stats(context)
return {"ok": True, "stats": stats}
elif action == "compact":
- # Get plugin config for model choice
from helpers.plugins import get_plugin_config
agent = context.agent0
- plugin_config = get_plugin_config("compaction", agent=agent) or {}
+ plugin_config = get_plugin_config("_chat_compaction", agent=agent) or {}
use_chat_model = plugin_config.get("use_chat_model", True)
- # Start compaction as a deferred task
context.run_task(_run_compaction_task, context, use_chat_model)
return {"ok": True, "message": "Compaction started"}
@@ -56,16 +49,12 @@ class CompactChat(ApiHandler):
async def _run_compaction_task(context, use_chat_model: bool):
"""Wrapper to run compaction and handle errors."""
try:
- import importlib
- import usr.plugins.compaction.helpers.compactor as _compactor_mod
- importlib.reload(_compactor_mod)
- await _compactor_mod.run_compaction(context, use_chat_model)
+ await run_compaction(context, use_chat_model)
except Exception as e:
- # Log error but don't crash the task
context.log.log(
type="error",
heading="Compaction Failed",
content=str(e),
)
from helpers.state_monitor_integration import mark_dirty_all
- mark_dirty_all(reason="plugins.compaction.compact_chat_error")
+ mark_dirty_all(reason="plugins._chat_compaction.compact_chat_error")
diff --git a/plugins/chat_compaction/compaction/default_config.yaml b/plugins/_chat_compaction/default_config.yaml
similarity index 100%
rename from plugins/chat_compaction/compaction/default_config.yaml
rename to plugins/_chat_compaction/default_config.yaml
diff --git a/plugins/chat_compaction/compaction/extensions/webui/chat-input-bottom-actions-start/compact-button.html b/plugins/_chat_compaction/extensions/webui/chat-input-bottom-actions-start/compact-button.html
similarity index 98%
rename from plugins/chat_compaction/compaction/extensions/webui/chat-input-bottom-actions-start/compact-button.html
rename to plugins/_chat_compaction/extensions/webui/chat-input-bottom-actions-start/compact-button.html
index 04326c683..7f7007546 100644
--- a/plugins/chat_compaction/compaction/extensions/webui/chat-input-bottom-actions-start/compact-button.html
+++ b/plugins/_chat_compaction/extensions/webui/chat-input-bottom-actions-start/compact-button.html
@@ -1,7 +1,7 @@
<html>
<head>
<title>Compact Button Extension</title>
- <script type="module" src="/plugins/compaction/webui/compact-store.js"></script>
+ <script type="module" src="/plugins/_chat_compaction/webui/compact-store.js"></script>
</head>
<body>
<div x-data="{
diff --git a/plugins/chat_compaction/compaction/helpers/compactor.py b/plugins/_chat_compaction/helpers/compactor.py
similarity index 100%
rename from plugins/chat_compaction/compaction/helpers/compactor.py
rename to plugins/_chat_compaction/helpers/compactor.py
diff --git a/plugins/chat_compaction/plugin.yaml b/plugins/_chat_compaction/plugin.yaml
similarity index 89%
rename from plugins/chat_compaction/plugin.yaml
rename to plugins/_chat_compaction/plugin.yaml
index 2c4351b3a..9425c5678 100644
--- a/plugins/chat_compaction/plugin.yaml
+++ b/plugins/_chat_compaction/plugin.yaml
@@ -1,4 +1,4 @@
-name: compaction
+name: _chat_compaction
title: Chat Compaction
description: Compact entire chat history into a single optimized summary message.
version: 1.0.0
diff --git a/plugins/chat_compaction/compaction/prompts/compact.msg.md b/plugins/_chat_compaction/prompts/compact.msg.md
similarity index 100%
rename from plugins/chat_compaction/compaction/prompts/compact.msg.md
rename to plugins/_chat_compaction/prompts/compact.msg.md
diff --git a/plugins/chat_compaction/compaction/prompts/compact.sys.md b/plugins/_chat_compaction/prompts/compact.sys.md
similarity index 100%
rename from plugins/chat_compaction/compaction/prompts/compact.sys.md
rename to plugins/_chat_compaction/prompts/compact.sys.md
diff --git a/plugins/chat_compaction/compaction/webui/compact-modal.html b/plugins/_chat_compaction/webui/compact-modal.html
similarity index 98%
rename from plugins/chat_compaction/compaction/webui/compact-modal.html
rename to plugins/_chat_compaction/webui/compact-modal.html
index d19ffc52b..840b6db04 100644
--- a/plugins/chat_compaction/compaction/webui/compact-modal.html
+++ b/plugins/_chat_compaction/webui/compact-modal.html
@@ -255,7 +255,7 @@
</style>
<script type="module">
- import { store } from "/plugins/compaction/webui/compact-store.js";
+ import { store } from "/plugins/_chat_compaction/webui/compact-store.js";
</script>
</body>
</html>
diff --git a/plugins/chat_compaction/compaction/webui/compact-store.js b/plugins/_chat_compaction/webui/compact-store.js
similarity index 89%
rename from plugins/chat_compaction/compaction/webui/compact-store.js
rename to plugins/_chat_compaction/webui/compact-store.js
index 22f0f7692..2a059ffa0 100644
--- a/plugins/chat_compaction/compaction/webui/compact-store.js
+++ b/plugins/_chat_compaction/webui/compact-store.js
@@ -18,7 +18,7 @@ export const store = createStore("compactStore", {
return;
}
- const res = await callJsonApi("/plugins/compaction/compact_chat", {
+ const res = await callJsonApi("/plugins/_chat_compaction/compact_chat", {
context: ctxid,
action: "stats",
});
@@ -42,7 +42,7 @@ export const store = createStore("compactStore", {
throw new Error("No active chat");
}
- const res = await callJsonApi("/plugins/compaction/compact_chat", {
+ const res = await callJsonApi("/plugins/_chat_compaction/compact_chat", {
context: ctxid,
action: "compact",
});
diff --git a/plugins/chat_compaction/compaction/webui/config.html b/plugins/_chat_compaction/webui/config.html
similarity index 100%
rename from plugins/chat_compaction/compaction/webui/config.html
rename to plugins/_chat_compaction/webui/config.html
diff --git a/plugins/chat_compaction/compaction/.toggle-1 b/plugins/chat_compaction/compaction/.toggle-1
deleted file mode 100644
index e69de29bb..000000000
diff --git a/plugins/chat_compaction/compaction/api/compact_chat.py b/plugins/chat_compaction/compaction/api/compact_chat.py
deleted file mode 100644
index a9829a6c1..000000000
--- a/plugins/chat_compaction/compaction/api/compact_chat.py
+++ /dev/null
@@ -1,71 +0,0 @@
-"""API handler for chat compaction."""
-import importlib
-from helpers.api import ApiHandler, Input, Output, Request, Response
-from agent import AgentContext
-
-
-class CompactChat(ApiHandler):
- """Compact the current chat history into a summarized message."""
-
- async def process(self, input: Input, request: Request) -> Output:
- ctxid = input.get("context", "")
- action = input.get("action", "compact")
-
- if not ctxid:
- return Response("Missing context id", 400)
-
- context = AgentContext.get(ctxid)
- if not context:
- return Response("Context not found", 404)
-
- # Validate context is not running
- if context.is_running():
- return Response("Cannot compact while agent is running", 409)
-
- # Check if there's enough content to compact
- # Count user-visible log items (what the user sees in the UI)
- visible_count = len(context.log.logs)
- if visible_count <= 1:
- return Response("Not enough messages to compact", 400)
-
- # Force reload compactor module to pick up latest changes
- import usr.plugins.compaction.helpers.compactor as _compactor_mod
- importlib.reload(_compactor_mod)
-
- if action == "stats":
- # Return statistics for confirmation modal
- stats = await _compactor_mod.get_compaction_stats(context)
- return {"ok": True, "stats": stats}
-
- elif action == "compact":
- # Get plugin config for model choice
- from helpers.plugins import get_plugin_config
- agent = context.agent0
- plugin_config = get_plugin_config("compaction", agent=agent) or {}
- use_chat_model = plugin_config.get("use_chat_model", True)
-
- # Start compaction as a deferred task
- context.run_task(_run_compaction_task, context, use_chat_model)
-
- return {"ok": True, "message": "Compaction started"}
-
- else:
- return Response(f"Unknown action: {action}", 400)
-
-
-async def _run_compaction_task(context, use_chat_model: bool):
- """Wrapper to run compaction and handle errors."""
- try:
- import importlib
- import usr.plugins.compaction.helpers.compactor as _compactor_mod
- importlib.reload(_compactor_mod)
- await _compactor_mod.run_compaction(context, use_chat_model)
- except Exception as e:
- # Log error but don't crash the task
- context.log.log(
- type="error",
- heading="Compaction Failed",
- content=str(e),
- )
- from helpers.state_monitor_integration import mark_dirty_all
- mark_dirty_all(reason="plugins.compaction.compact_chat_error")
diff --git a/plugins/chat_compaction/compaction/plugin.yaml b/plugins/chat_compaction/compaction/plugin.yaml
deleted file mode 100644
index 2c4351b3a..000000000
--- a/plugins/chat_compaction/compaction/plugin.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-name: compaction
-title: Chat Compaction
-description: Compact entire chat history into a single optimized summary message.
-version: 1.0.0
-settings_sections:
- - agent
-per_project_config: false
-per_agent_config: false
diff --git a/plugins/chat_compaction/default_config.yaml b/plugins/chat_compaction/default_config.yaml
deleted file mode 100644
index 87b090a6f..000000000
--- a/plugins/chat_compaction/default_config.yaml
+++ /dev/null
@@ -1 +0,0 @@
-use_chat_model: true
diff --git a/plugins/chat_compaction/prompts/compact.msg.md b/plugins/chat_compaction/prompts/compact.msg.md
deleted file mode 100644
index e0142b996..000000000
--- a/plugins/chat_compaction/prompts/compact.msg.md
+++ /dev/null
@@ -1,5 +0,0 @@
-Compact this conversation to its essential facts. Be maximally concise.
-
----
-{{conversation}}
----
diff --git a/plugins/chat_compaction/prompts/compact.sys.md b/plugins/chat_compaction/prompts/compact.sys.md
deleted file mode 100644
index 15868d6fc..000000000
--- a/plugins/chat_compaction/prompts/compact.sys.md
+++ /dev/null
@@ -1,17 +0,0 @@
-You are a conversation compactor. Produce the most concise summary possible while preserving critical information.
-
-Rules:
-- Extract only: key decisions, final outcomes, actionable facts, unresolved items
-- Discard: intermediate reasoning, failed attempts, redundant exchanges, pleasantries
-- Use terse bullet points, not prose
-- Collapse related items into single lines
-- Keep exact values: file paths, config values, code identifiers, credentials, URLs
-- Omit anything that can be re-derived from context
-- Group by topic, not chronology
-- No meta-commentary about the summarization
-- Target: 10-20% of original length
-
-Output format:
-- Markdown with short section headers
-- Bullet lists, no paragraphs
-- Code/paths in backticks inline, not fenced blocks unless multi-line
diff --git a/plugins/chat_compaction/webui/compact-modal.html b/plugins/chat_compaction/webui/compact-modal.html
deleted file mode 100644
index d19ffc52b..000000000
--- a/plugins/chat_compaction/webui/compact-modal.html
+++ /dev/null
@@ -1,261 +0,0 @@
-<html>
-<head>
- <title>Compact Chat</title>
-</head>
-<body>
- <div x-data x-show="$store.compactStore?.showModal" style="display: none;">
- <div class="modal-overlay" @click="$store.compactStore?.closeModal()">
- <div class="modal-container" @click.stop>
- <div class="modal-header">
- <h3>Compact Chat History</h3>
- <button class="modal-close" @click="$store.compactStore?.closeModal()">
- <span class="material-symbols-outlined">close</span>
- </button>
- </div>
-
- <div class="modal-content">
- <template x-if="$store.compactStore?.stats">
- <div class="stats-container">
- <p class="stats-description">
- This will summarize your entire conversation into a single optimized message.
- </p>
-
- <div class="stats-grid">
- <div class="stat-item">
- <span class="stat-label">Messages</span>
- <span class="stat-value" x-text="$store.compactStore?.stats?.message_count"></span>
- </div>
- <div class="stat-item">
- <span class="stat-label">Tokens</span>
- <span class="stat-value" x-text="$store.compactStore?.stats?.token_count?.toLocaleString()"></span>
- </div>
- <div class="stat-item">
- <span class="stat-label">Model</span>
- <span class="stat-value" x-text="$store.compactStore?.stats?.model_name"></span>
- </div>
- </div>
-
- <div class="stats-warning">
- <span class="material-symbols-outlined">warning</span>
- <span>This action cannot be undone. The original conversation will be replaced with a summary.</span>
- </div>
- </div>
- </template>
-
- <template x-if="!$store.compactStore?.stats">
- <div class="stats-loading">
- <span class="loading-spinner"></span>
- <span>Loading statistics...</span>
- </div>
- </template>
- </div>
-
- <div class="modal-footer">
- <button class="button secondary" @click="$store.compactStore?.closeModal()">
- Cancel
- </button>
- <button
- class="button primary danger"
- @click="$store.compactStore?.compact()"
- :disabled="$store.compactStore?.compacting || !$store.compactStore?.stats"
- >
- <template x-if="$store.compactStore?.compacting">
- <span class="loading-spinner"></span>
- </template>
- <span>Compact</span>
- </button>
- </div>
- </div>
- </div>
- </div>
-
- <style>
- .modal-overlay {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: rgba(0, 0, 0, 0.5);
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 1000;
- }
-
- .modal-container {
- background: var(--color-background-elevated);
- border-radius: var(--border-radius-md);
- box-shadow: var(--shadow-lg);
- width: 90%;
- max-width: 500px;
- max-height: 90vh;
- overflow-y: auto;
- }
-
- .modal-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: var(--spacing-md) var(--spacing-lg);
- border-bottom: 1px solid var(--color-border);
- }
-
- .modal-header h3 {
- margin: 0;
- font-size: 1.1rem;
- font-weight: 600;
- }
-
- .modal-close {
- background: transparent;
- border: none;
- cursor: pointer;
- padding: var(--spacing-xs);
- border-radius: var(--border-radius-sm);
- color: var(--color-text-secondary);
- transition: color 0.2s;
- }
-
- .modal-close:hover {
- color: var(--color-text);
- }
-
- .modal-content {
- padding: var(--spacing-lg);
- }
-
- .stats-description {
- margin: 0 0 var(--spacing-md) 0;
- color: var(--color-text-secondary);
- font-size: 0.9rem;
- }
-
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: var(--spacing-md);
- margin-bottom: var(--spacing-lg);
- }
-
- .stat-item {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: var(--spacing-md);
- background: var(--color-background-muted);
- border-radius: var(--border-radius-md);
- }
-
- .stat-label {
- font-size: 0.75rem;
- color: var(--color-text-secondary);
- text-transform: uppercase;
- letter-spacing: 0.05em;
- margin-bottom: var(--spacing-xs);
- }
-
- .stat-value {
- font-size: 1.25rem;
- font-weight: 600;
- color: var(--color-text);
- }
-
- .stats-warning {
- display: flex;
- align-items: flex-start;
- gap: var(--spacing-sm);
- padding: var(--spacing-md);
- background: var(--color-warning-bg, rgba(245, 158, 11, 0.1));
- border: 1px solid var(--color-warning-border, rgba(245, 158, 11, 0.3));
- border-radius: var(--border-radius-md);
- color: var(--color-warning-text, #92400e);
- font-size: 0.85rem;
- }
-
- .stats-warning .material-symbols-outlined {
- font-size: 1.2rem;
- flex-shrink: 0;
- }
-
- .stats-loading {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: var(--spacing-sm);
- padding: var(--spacing-xl);
- color: var(--color-text-secondary);
- }
-
- .modal-footer {
- display: flex;
- justify-content: flex-end;
- gap: var(--spacing-sm);
- padding: var(--spacing-md) var(--spacing-lg);
- border-top: 1px solid var(--color-border);
- }
-
- .button {
- padding: var(--spacing-sm) var(--spacing-md);
- border-radius: var(--border-radius-md);
- font-size: 0.9rem;
- font-weight: 500;
- cursor: pointer;
- transition: all 0.2s;
- display: flex;
- align-items: center;
- gap: var(--spacing-xs);
- }
-
- .button:disabled {
- opacity: 0.6;
- cursor: not-allowed;
- }
-
- .button.secondary {
- background: var(--color-background-muted);
- border: 1px solid var(--color-border);
- color: var(--color-text);
- }
-
- .button.secondary:hover:not(:disabled) {
- background: var(--color-background-hover);
- }
-
- .button.primary {
- background: var(--color-primary);
- border: none;
- color: white;
- }
-
- .button.primary:hover:not(:disabled) {
- background: var(--color-primary-hover);
- }
-
- .button.danger {
- background: var(--color-danger, #dc2626);
- }
-
- .button.danger:hover:not(:disabled) {
- background: var(--color-danger-hover, #b91c1c);
- }
-
- .loading-spinner {
- width: 16px;
- height: 16px;
- border: 2px solid currentColor;
- border-top-color: transparent;
- border-radius: 50%;
- animation: spin 0.8s linear infinite;
- }
-
- @keyframes spin {
- to { transform: rotate(360deg); }
- }
- </style>
-
- <script type="module">
- import { store } from "/plugins/compaction/webui/compact-store.js";
- </script>
-</body>
-</html>
diff --git a/plugins/chat_compaction/webui/compact-store.js b/plugins/chat_compaction/webui/compact-store.js
deleted file mode 100644
index 22f0f7692..000000000
--- a/plugins/chat_compaction/webui/compact-store.js
+++ /dev/null
@@ -1,67 +0,0 @@
-import { createStore } from "/js/AlpineStore.js";
-import { callJsonApi } from "/js/api.js";
-import {
- toastFrontendSuccess,
- toastFrontendError,
-} from "/components/notifications/notification-store.js";
-
-export const store = createStore("compactStore", {
- compacting: false,
- stats: null,
- showModal: false,
-
- async fetchStats() {
- try {
- const ctxid = globalThis.getContext?.();
- if (!ctxid) {
- toastFrontendError("No active chat", "Compaction");
- return;
- }
-
- const res = await callJsonApi("/plugins/compaction/compact_chat", {
- context: ctxid,
- action: "stats",
- });
-
- if (!res?.ok) {
- throw new Error(res?.message || "Failed to fetch stats");
- }
-
- this.stats = res.stats;
- this.showModal = true;
- } catch (e) {
- toastFrontendError(e.message, "Compaction");
- }
- },
-
- async compact() {
- this.compacting = true;
- try {
- const ctxid = globalThis.getContext?.();
- if (!ctxid) {
- throw new Error("No active chat");
- }
-
- const res = await callJsonApi("/plugins/compaction/compact_chat", {
- context: ctxid,
- action: "compact",
- });
-
- if (!res?.ok) {
- throw new Error(res?.message || "Compaction failed");
- }
-
- toastFrontendSuccess("Compaction started", "Compaction");
- this.showModal = false;
- } catch (e) {
- toastFrontendError(e.message, "Compaction");
- } finally {
- this.compacting = false;
- }
- },
-
- closeModal() {
- this.showModal = false;
- this.stats = null;
- },
-});
diff --git a/plugins/chat_compaction/webui/config.html b/plugins/chat_compaction/webui/config.html
deleted file mode 100644
index 3590e2d10..000000000
--- a/plugins/chat_compaction/webui/config.html
+++ /dev/null
@@ -1,104 +0,0 @@
-<html>
-<head>
- <title>Compaction Plugin Settings</title>
-</head>
-<body>
- <div x-data>
- <template x-if="config">
- <div>
- <div class="section-title">Compaction Configuration</div>
- <div class="section-description">
- Configure how the chat compaction feature works.
- </div>
-
- <div class="field">
- <div class="field-label">
- <div class="field-title">Use chat model</div>
- <div class="field-description">
- When enabled, uses the currently selected chat model for compaction.
- When disabled, uses the utility model (usually faster and cheaper).
- </div>
- </div>
- <div class="field-control">
- <label class="toggle">
- <input type="checkbox" x-model="config.use_chat_model" />
- <span class="toggler"></span>
- </label>
- </div>
- </div>
- </div>
- </template>
- </div>
-
- <style>
- .section-title {
- font-size: 1rem;
- font-weight: 600;
- margin-bottom: 8px;
- color: var(--color-text, #e5e5e5);
- }
- .section-description {
- font-size: 0.85rem;
- color: var(--color-text-secondary, #999);
- margin-bottom: 20px;
- line-height: 1.5;
- }
- .field {
- margin-bottom: 20px;
- }
- .field-label {
- margin-bottom: 8px;
- }
- .field-title {
- font-weight: 500;
- color: var(--color-text, #e5e5e5);
- margin-bottom: 4px;
- }
- .field-description {
- font-size: 0.8rem;
- color: var(--color-text-secondary, #999);
- line-height: 1.4;
- }
- .field-control {
- margin-top: 8px;
- }
- .toggle {
- display: inline-flex;
- align-items: center;
- cursor: pointer;
- }
- .toggle input {
- display: none;
- }
- .toggler {
- width: 44px;
- height: 24px;
- background: var(--color-border, #444);
- border-radius: 12px;
- position: relative;
- transition: background 0.2s;
- }
- .toggler::after {
- content: '';
- position: absolute;
- width: 20px;
- height: 20px;
- background: white;
- border-radius: 50%;
- top: 2px;
- left: 2px;
- transition: transform 0.2s;
- }
- .toggle input:checked + .toggler {
- background: var(--color-primary, #3b82f6);
- }
- .toggle input:checked + .toggler::after {
- transform: translateX(20px);
- }
- </style>
-
- <script type="module">
- import { store } from "/components/plugins/plugin-settings-store.js";
- </script>
-</body>
-</html>