cli-agent-orchestrator 2.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cli_agent_orchestrator/__init__.py +0 -0
- cli_agent_orchestrator/agent_store/code_supervisor.md +66 -0
- cli_agent_orchestrator/agent_store/developer.md +55 -0
- cli_agent_orchestrator/agent_store/reviewer.md +60 -0
- cli_agent_orchestrator/api/__init__.py +1 -0
- cli_agent_orchestrator/api/main.py +947 -0
- cli_agent_orchestrator/cli/__init__.py +1 -0
- cli_agent_orchestrator/cli/commands/__init__.py +1 -0
- cli_agent_orchestrator/cli/commands/env.py +60 -0
- cli_agent_orchestrator/cli/commands/flow.py +102 -0
- cli_agent_orchestrator/cli/commands/info.py +57 -0
- cli_agent_orchestrator/cli/commands/init.py +45 -0
- cli_agent_orchestrator/cli/commands/install.py +317 -0
- cli_agent_orchestrator/cli/commands/launch.py +243 -0
- cli_agent_orchestrator/cli/commands/mcp_server.py +12 -0
- cli_agent_orchestrator/cli/commands/session.py +260 -0
- cli_agent_orchestrator/cli/commands/shutdown.py +59 -0
- cli_agent_orchestrator/cli/commands/skills.py +99 -0
- cli_agent_orchestrator/cli/main.py +36 -0
- cli_agent_orchestrator/clients/database.py +415 -0
- cli_agent_orchestrator/clients/tmux.py +516 -0
- cli_agent_orchestrator/constants.py +145 -0
- cli_agent_orchestrator/mcp_server/__init__.py +1 -0
- cli_agent_orchestrator/mcp_server/models.py +14 -0
- cli_agent_orchestrator/mcp_server/server.py +653 -0
- cli_agent_orchestrator/mcp_server/utils.py +15 -0
- cli_agent_orchestrator/models/__init__.py +1 -0
- cli_agent_orchestrator/models/agent_profile.py +37 -0
- cli_agent_orchestrator/models/copilot_agent.py +15 -0
- cli_agent_orchestrator/models/flow.py +23 -0
- cli_agent_orchestrator/models/inbox.py +33 -0
- cli_agent_orchestrator/models/kiro_agent.py +28 -0
- cli_agent_orchestrator/models/opencode_agent.py +23 -0
- cli_agent_orchestrator/models/provider.py +14 -0
- cli_agent_orchestrator/models/q_agent.py +28 -0
- cli_agent_orchestrator/models/session.py +21 -0
- cli_agent_orchestrator/models/skill.py +19 -0
- cli_agent_orchestrator/models/terminal.py +37 -0
- cli_agent_orchestrator/plugins/__init__.py +24 -0
- cli_agent_orchestrator/plugins/base.py +52 -0
- cli_agent_orchestrator/plugins/events.py +75 -0
- cli_agent_orchestrator/plugins/registry.py +87 -0
- cli_agent_orchestrator/providers/__init__.py +0 -0
- cli_agent_orchestrator/providers/base.py +186 -0
- cli_agent_orchestrator/providers/claude_code.py +434 -0
- cli_agent_orchestrator/providers/codex.py +497 -0
- cli_agent_orchestrator/providers/copilot_cli.py +502 -0
- cli_agent_orchestrator/providers/gemini_cli.py +764 -0
- cli_agent_orchestrator/providers/kimi_cli.py +649 -0
- cli_agent_orchestrator/providers/kiro_cli.py +548 -0
- cli_agent_orchestrator/providers/manager.py +181 -0
- cli_agent_orchestrator/providers/opencode_cli.py +369 -0
- cli_agent_orchestrator/providers/q_cli.py +176 -0
- cli_agent_orchestrator/services/cleanup_service.py +58 -0
- cli_agent_orchestrator/services/flow_service.py +235 -0
- cli_agent_orchestrator/services/inbox_service.py +172 -0
- cli_agent_orchestrator/services/plugin_dispatch.py +42 -0
- cli_agent_orchestrator/services/session_service.py +141 -0
- cli_agent_orchestrator/services/settings_service.py +78 -0
- cli_agent_orchestrator/services/terminal_service.py +475 -0
- cli_agent_orchestrator/skills/__init__.py +1 -0
- cli_agent_orchestrator/skills/cao-session-management/SKILL.md +106 -0
- cli_agent_orchestrator/skills/cao-supervisor-protocols/SKILL.md +84 -0
- cli_agent_orchestrator/skills/cao-worker-protocols/SKILL.md +60 -0
- cli_agent_orchestrator/utils/__init__.py +1 -0
- cli_agent_orchestrator/utils/agent_profiles.py +241 -0
- cli_agent_orchestrator/utils/env.py +41 -0
- cli_agent_orchestrator/utils/logging.py +25 -0
- cli_agent_orchestrator/utils/opencode_config.py +169 -0
- cli_agent_orchestrator/utils/opencode_permissions.py +109 -0
- cli_agent_orchestrator/utils/skill_injection.py +240 -0
- cli_agent_orchestrator/utils/skills.py +129 -0
- cli_agent_orchestrator/utils/template.py +30 -0
- cli_agent_orchestrator/utils/terminal.py +145 -0
- cli_agent_orchestrator/utils/tool_mapping.py +158 -0
- cli_agent_orchestrator/web_ui/assets/index-BXMLhBau.css +32 -0
- cli_agent_orchestrator/web_ui/assets/index-BpPHwanT.js +275 -0
- cli_agent_orchestrator/web_ui/index.html +13 -0
- cli_agent_orchestrator-2.1.1.dist-info/METADATA +681 -0
- cli_agent_orchestrator-2.1.1.dist-info/RECORD +84 -0
- cli_agent_orchestrator-2.1.1.dist-info/WHEEL +4 -0
- cli_agent_orchestrator-2.1.1.dist-info/entry_points.txt +4 -0
- cli_agent_orchestrator-2.1.1.dist-info/licenses/LICENSE +175 -0
- cli_agent_orchestrator-2.1.1.dist-info/licenses/NOTICE +1 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Agent profile models."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class McpServer(BaseModel):
|
|
9
|
+
"""MCP server configuration."""
|
|
10
|
+
|
|
11
|
+
type: Optional[str] = None
|
|
12
|
+
command: str
|
|
13
|
+
args: Optional[List[str]] = None
|
|
14
|
+
env: Optional[Dict[str, str]] = None
|
|
15
|
+
timeout: Optional[int] = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AgentProfile(BaseModel):
|
|
19
|
+
"""Agent profile configuration with Q CLI agent fields."""
|
|
20
|
+
|
|
21
|
+
name: str
|
|
22
|
+
description: str
|
|
23
|
+
provider: Optional[str] = None # Provider override (e.g. "claude_code", "kiro_cli")
|
|
24
|
+
system_prompt: Optional[str] = None # The markdown content
|
|
25
|
+
role: Optional[str] = None # "supervisor", "developer", "reviewer"
|
|
26
|
+
|
|
27
|
+
# Q CLI agent fields (all optional, will be passed through to JSON)
|
|
28
|
+
prompt: Optional[str] = None
|
|
29
|
+
mcpServers: Optional[Dict[str, Any]] = None
|
|
30
|
+
tools: Optional[List[str]] = Field(default=None)
|
|
31
|
+
toolAliases: Optional[Dict[str, str]] = None
|
|
32
|
+
allowedTools: Optional[List[str]] = None
|
|
33
|
+
toolsSettings: Optional[Dict[str, Any]] = None
|
|
34
|
+
resources: Optional[List[str]] = None
|
|
35
|
+
hooks: Optional[Dict[str, Any]] = None
|
|
36
|
+
useLegacyMcpJson: Optional[bool] = None
|
|
37
|
+
model: Optional[str] = None
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Copilot CLI agent configuration model."""
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CopilotAgentConfig(BaseModel):
|
|
7
|
+
"""Copilot CLI agent configuration."""
|
|
8
|
+
|
|
9
|
+
name: str
|
|
10
|
+
description: str
|
|
11
|
+
prompt: str
|
|
12
|
+
|
|
13
|
+
class Config:
|
|
14
|
+
# Keep model config style consistent with other provider models.
|
|
15
|
+
exclude_none = True
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Flow model."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
7
|
+
|
|
8
|
+
from cli_agent_orchestrator.constants import DEFAULT_PROVIDER
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Flow(BaseModel):
|
|
12
|
+
"""Flow model - represents a scheduled agent session."""
|
|
13
|
+
|
|
14
|
+
name: str = Field(..., description="Unique flow identifier")
|
|
15
|
+
file_path: str = Field(..., description="Path to flow definition file")
|
|
16
|
+
schedule: str = Field(..., description="Cron expression")
|
|
17
|
+
agent_profile: str = Field(..., description="Agent profile to use")
|
|
18
|
+
provider: str = Field(default=DEFAULT_PROVIDER, description="Provider to use")
|
|
19
|
+
script: str = Field("", description="Path to poll script (optional)")
|
|
20
|
+
last_run: Optional[datetime] = Field(None, description="Last execution time")
|
|
21
|
+
next_run: Optional[datetime] = Field(None, description="Next scheduled execution time")
|
|
22
|
+
enabled: bool = Field(True, description="Whether flow is enabled")
|
|
23
|
+
prompt_template: Optional[str] = Field(None, description="Prompt template text")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Inbox message models."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from enum import Enum
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OrchestrationType(str, Enum):
|
|
10
|
+
"""Orchestration mode for a message delivery."""
|
|
11
|
+
|
|
12
|
+
SEND_MESSAGE = "send_message"
|
|
13
|
+
HANDOFF = "handoff"
|
|
14
|
+
ASSIGN = "assign"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MessageStatus(str, Enum):
|
|
18
|
+
"""Message status enumeration."""
|
|
19
|
+
|
|
20
|
+
PENDING = "pending"
|
|
21
|
+
DELIVERED = "delivered"
|
|
22
|
+
FAILED = "failed"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class InboxMessage(BaseModel):
|
|
26
|
+
"""Inbox message model."""
|
|
27
|
+
|
|
28
|
+
id: int = Field(..., description="Message ID")
|
|
29
|
+
sender_id: str = Field(..., description="Sender terminal ID")
|
|
30
|
+
receiver_id: str = Field(..., description="Receiver terminal ID")
|
|
31
|
+
message: str = Field(..., description="Message content")
|
|
32
|
+
status: MessageStatus = Field(..., description="Message status")
|
|
33
|
+
created_at: datetime = Field(..., description="Creation timestamp")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Kiro CLI agent configuration model."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class KiroAgentConfig(BaseModel):
|
|
9
|
+
"""Kiro CLI agent configuration."""
|
|
10
|
+
|
|
11
|
+
name: str
|
|
12
|
+
description: str
|
|
13
|
+
tools: List[str] = Field(default_factory=lambda: ["*"])
|
|
14
|
+
allowedTools: List[str] = Field(default_factory=list)
|
|
15
|
+
useLegacyMcpJson: bool = False
|
|
16
|
+
resources: List[str] = Field(default_factory=list)
|
|
17
|
+
|
|
18
|
+
# Optional pass-through fields
|
|
19
|
+
prompt: Optional[str] = None
|
|
20
|
+
mcpServers: Optional[Dict[str, Any]] = None
|
|
21
|
+
toolAliases: Optional[Dict[str, str]] = None
|
|
22
|
+
toolsSettings: Optional[Dict[str, Any]] = None
|
|
23
|
+
hooks: Optional[Dict[str, Any]] = None
|
|
24
|
+
model: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
class Config:
|
|
27
|
+
# Exclude None values when serializing to JSON
|
|
28
|
+
exclude_none = True
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""OpenCode CLI agent configuration model."""
|
|
2
|
+
|
|
3
|
+
from typing import Dict, Literal, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OpenCodeAgentConfig(BaseModel):
|
|
9
|
+
"""OpenCode agent frontmatter configuration.
|
|
10
|
+
|
|
11
|
+
Serialized via ``frontmatter.dumps(frontmatter.Post(body, **config.model_dump(exclude_none=True)))``
|
|
12
|
+
to produce a valid OpenCode ``.md`` agent file.
|
|
13
|
+
|
|
14
|
+
The system-prompt body is *not* a field here; it is passed separately as the
|
|
15
|
+
``Post`` body at install time.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
description: str
|
|
19
|
+
mode: Literal["all", "primary", "subagent"] = "all"
|
|
20
|
+
# Flat {tool: "allow"|"deny"} covers all translator output. Widen to
|
|
21
|
+
# Dict[str, Union[str, Dict[str, str]]] if granular per-command bash patterns
|
|
22
|
+
# (e.g. bash: {"git status": "allow"}) are later needed.
|
|
23
|
+
permission: Optional[Dict[str, str]] = None
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ProviderType(str, Enum):
|
|
5
|
+
"""Provider type enumeration."""
|
|
6
|
+
|
|
7
|
+
Q_CLI = "q_cli"
|
|
8
|
+
KIRO_CLI = "kiro_cli"
|
|
9
|
+
CLAUDE_CODE = "claude_code"
|
|
10
|
+
CODEX = "codex"
|
|
11
|
+
KIMI_CLI = "kimi_cli"
|
|
12
|
+
GEMINI_CLI = "gemini_cli"
|
|
13
|
+
COPILOT_CLI = "copilot_cli"
|
|
14
|
+
OPENCODE_CLI = "opencode_cli"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Q CLI agent configuration model."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class QAgentConfig(BaseModel):
|
|
9
|
+
"""Q CLI agent configuration."""
|
|
10
|
+
|
|
11
|
+
name: str
|
|
12
|
+
description: str
|
|
13
|
+
tools: List[str] = Field(default_factory=lambda: ["*"])
|
|
14
|
+
allowedTools: List[str] = Field(default_factory=list)
|
|
15
|
+
useLegacyMcpJson: bool = False
|
|
16
|
+
resources: List[str] = Field(default_factory=list)
|
|
17
|
+
|
|
18
|
+
# Optional pass-through fields
|
|
19
|
+
prompt: Optional[str] = None
|
|
20
|
+
mcpServers: Optional[Dict[str, Any]] = None
|
|
21
|
+
toolAliases: Optional[Dict[str, str]] = None
|
|
22
|
+
toolsSettings: Optional[Dict[str, Any]] = None
|
|
23
|
+
hooks: Optional[Dict[str, Any]] = None
|
|
24
|
+
model: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
class Config:
|
|
27
|
+
# Exclude None values when serializing to JSON
|
|
28
|
+
exclude_none = True
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SessionStatus(str, Enum):
|
|
7
|
+
"""Session status enumeration."""
|
|
8
|
+
|
|
9
|
+
ACTIVE = "active"
|
|
10
|
+
DETACHED = "detached"
|
|
11
|
+
TERMINATED = "terminated"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Session(BaseModel):
|
|
15
|
+
"""Session domain model."""
|
|
16
|
+
|
|
17
|
+
model_config = ConfigDict(use_enum_values=True)
|
|
18
|
+
|
|
19
|
+
id: str = Field(..., description="Unique session identifier")
|
|
20
|
+
name: str = Field(..., description="Human-readable session name")
|
|
21
|
+
status: SessionStatus = Field(..., description="Current session status")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Skill metadata models."""
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, field_validator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SkillMetadata(BaseModel):
|
|
7
|
+
"""Metadata describing an installed skill."""
|
|
8
|
+
|
|
9
|
+
name: str
|
|
10
|
+
description: str
|
|
11
|
+
|
|
12
|
+
@field_validator("name", "description")
|
|
13
|
+
@classmethod
|
|
14
|
+
def validate_required_text(cls, value: str) -> str:
|
|
15
|
+
"""Ensure required string fields are present and not blank."""
|
|
16
|
+
stripped_value = value.strip()
|
|
17
|
+
if not stripped_value:
|
|
18
|
+
raise ValueError("Field must not be empty")
|
|
19
|
+
return stripped_value
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Annotated, List, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field, StringConstraints
|
|
6
|
+
|
|
7
|
+
from cli_agent_orchestrator.models.provider import ProviderType
|
|
8
|
+
|
|
9
|
+
# Terminal ID validation (8 character hex string)
|
|
10
|
+
TerminalId = Annotated[str, StringConstraints(pattern=r"^[a-f0-9]{8}$")]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TerminalStatus(str, Enum):
|
|
14
|
+
"""Terminal status enumeration with provider-aware states."""
|
|
15
|
+
|
|
16
|
+
IDLE = "idle"
|
|
17
|
+
PROCESSING = "processing"
|
|
18
|
+
COMPLETED = "completed"
|
|
19
|
+
WAITING_USER_ANSWER = "waiting_user_answer"
|
|
20
|
+
ERROR = "error"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Terminal(BaseModel):
|
|
24
|
+
"""Terminal model - represents a tmux window."""
|
|
25
|
+
|
|
26
|
+
model_config = ConfigDict(use_enum_values=True)
|
|
27
|
+
|
|
28
|
+
id: str = Field(..., description="Unique terminal identifier")
|
|
29
|
+
name: str = Field(..., description="Terminal/window name")
|
|
30
|
+
provider: ProviderType = Field(..., description="CLI tool provider")
|
|
31
|
+
session_name: str = Field(..., description="Session name")
|
|
32
|
+
agent_profile: Optional[str] = Field(None, description="Agent profile")
|
|
33
|
+
allowed_tools: Optional[List[str]] = Field(None, description="Allowed CAO tools")
|
|
34
|
+
status: Optional[TerminalStatus] = Field(
|
|
35
|
+
None, description="Current terminal status (live only)"
|
|
36
|
+
)
|
|
37
|
+
last_active: Optional[datetime] = Field(None, description="Last active timestamp")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Public API for the CAO plugin system."""
|
|
2
|
+
|
|
3
|
+
from cli_agent_orchestrator.plugins.base import CaoPlugin, hook
|
|
4
|
+
from cli_agent_orchestrator.plugins.events import (
|
|
5
|
+
CaoEvent,
|
|
6
|
+
PostCreateSessionEvent,
|
|
7
|
+
PostCreateTerminalEvent,
|
|
8
|
+
PostKillSessionEvent,
|
|
9
|
+
PostKillTerminalEvent,
|
|
10
|
+
PostSendMessageEvent,
|
|
11
|
+
)
|
|
12
|
+
from cli_agent_orchestrator.plugins.registry import PluginRegistry
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"CaoPlugin",
|
|
16
|
+
"hook",
|
|
17
|
+
"CaoEvent",
|
|
18
|
+
"PostSendMessageEvent",
|
|
19
|
+
"PostCreateSessionEvent",
|
|
20
|
+
"PostKillSessionEvent",
|
|
21
|
+
"PostCreateTerminalEvent",
|
|
22
|
+
"PostKillTerminalEvent",
|
|
23
|
+
"PluginRegistry",
|
|
24
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Plugin base class and hook decorator for CAO plugins.
|
|
2
|
+
|
|
3
|
+
This module defines the marker base class plugin authors subclass and the
|
|
4
|
+
decorator used to associate async plugin methods with CAO event types.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Awaitable, Callable, ParamSpec, TypeVar
|
|
8
|
+
|
|
9
|
+
P = ParamSpec("P")
|
|
10
|
+
R = TypeVar("R")
|
|
11
|
+
AsyncMethodT = Callable[P, Awaitable[R]]
|
|
12
|
+
|
|
13
|
+
_HOOK_EVENT_ATTR = "_cao_hook_event"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CaoPlugin:
|
|
17
|
+
"""Base class for CAO plugins.
|
|
18
|
+
|
|
19
|
+
Subclass this and declare hooks with the @hook decorator.
|
|
20
|
+
Register the subclass via the `cao.plugins` entry point group.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
async def setup(self) -> None:
|
|
24
|
+
"""Called once after instantiation on server startup.
|
|
25
|
+
|
|
26
|
+
Override to open connections, load config, or initialize state.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
async def teardown(self) -> None:
|
|
30
|
+
"""Called once on server shutdown.
|
|
31
|
+
|
|
32
|
+
Override to close connections or flush buffers.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def hook(event_type: str) -> Callable[[AsyncMethodT[P, R]], AsyncMethodT[P, R]]:
|
|
37
|
+
"""Decorator that registers a plugin method as a hook for a CAO event.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
event_type: The CAO event type to listen for (e.g. "post_send_message").
|
|
41
|
+
|
|
42
|
+
Example:
|
|
43
|
+
@hook("post_send_message")
|
|
44
|
+
async def notify(self, event: PostSendMessageEvent) -> None:
|
|
45
|
+
...
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def decorator(fn: AsyncMethodT[P, R]) -> AsyncMethodT[P, R]:
|
|
49
|
+
setattr(fn, _HOOK_EVENT_ATTR, event_type)
|
|
50
|
+
return fn
|
|
51
|
+
|
|
52
|
+
return decorator
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Typed plugin event dataclasses for CAO lifecycle and messaging hooks."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _utc_now() -> datetime:
|
|
8
|
+
"""Return the current UTC time as a timezone-aware datetime."""
|
|
9
|
+
|
|
10
|
+
return datetime.now(timezone.utc)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class CaoEvent:
|
|
15
|
+
"""Base class for all CAO plugin events."""
|
|
16
|
+
|
|
17
|
+
# Empty by default so the base dataclass is zero-arg constructible for Phase 1 tests.
|
|
18
|
+
event_type: str = ""
|
|
19
|
+
timestamp: datetime = field(default_factory=_utc_now)
|
|
20
|
+
session_id: str | None = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class PostSendMessageEvent(CaoEvent):
|
|
25
|
+
"""Emitted after a message is dispatched to an agent's inbox.
|
|
26
|
+
|
|
27
|
+
Fired for all three orchestration methods:
|
|
28
|
+
- send_message: direct message to an existing terminal
|
|
29
|
+
- handoff: message sent as part of a synchronous handoff
|
|
30
|
+
- assign: message sent as part of an asynchronous assign
|
|
31
|
+
|
|
32
|
+
Orchestration methods like assign span multiple steps and may therefore
|
|
33
|
+
emit more than one PostSendMessageEvent across their lifecycle.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
event_type: str = "post_send_message"
|
|
37
|
+
sender: str = ""
|
|
38
|
+
receiver: str = ""
|
|
39
|
+
message: str = ""
|
|
40
|
+
orchestration_type: str = ""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass
|
|
44
|
+
class PostCreateSessionEvent(CaoEvent):
|
|
45
|
+
"""Emitted after a CAO session is created."""
|
|
46
|
+
|
|
47
|
+
event_type: str = "post_create_session"
|
|
48
|
+
session_name: str = ""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass
|
|
52
|
+
class PostKillSessionEvent(CaoEvent):
|
|
53
|
+
"""Emitted after a CAO session is killed."""
|
|
54
|
+
|
|
55
|
+
event_type: str = "post_kill_session"
|
|
56
|
+
session_name: str = ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class PostCreateTerminalEvent(CaoEvent):
|
|
61
|
+
"""Emitted after a CAO terminal is created."""
|
|
62
|
+
|
|
63
|
+
event_type: str = "post_create_terminal"
|
|
64
|
+
terminal_id: str = ""
|
|
65
|
+
agent_name: str | None = None
|
|
66
|
+
provider: str = ""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass
|
|
70
|
+
class PostKillTerminalEvent(CaoEvent):
|
|
71
|
+
"""Emitted after a CAO terminal is killed."""
|
|
72
|
+
|
|
73
|
+
event_type: str = "post_kill_terminal"
|
|
74
|
+
terminal_id: str = ""
|
|
75
|
+
agent_name: str | None = None
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Plugin discovery, registration, dispatch, and lifecycle management."""
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
import inspect
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from cli_agent_orchestrator.plugins.base import _HOOK_EVENT_ATTR, CaoPlugin
|
|
9
|
+
from cli_agent_orchestrator.plugins.events import CaoEvent
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
ENTRY_POINT_GROUP = "cao.plugins"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PluginRegistry:
|
|
17
|
+
"""Registry for discovered CAO plugins and their hook handlers."""
|
|
18
|
+
|
|
19
|
+
def __init__(self) -> None:
|
|
20
|
+
"""Initialize an empty plugin registry."""
|
|
21
|
+
|
|
22
|
+
self._plugins: list[CaoPlugin] = []
|
|
23
|
+
self._dispatch: dict[str, list[Any]] = {}
|
|
24
|
+
|
|
25
|
+
async def load(self) -> None:
|
|
26
|
+
"""Discover, instantiate, and set up all registered CAO plugins."""
|
|
27
|
+
|
|
28
|
+
entry_points = importlib.metadata.entry_points(group=ENTRY_POINT_GROUP)
|
|
29
|
+
for entry_point in entry_points:
|
|
30
|
+
try:
|
|
31
|
+
plugin_class = entry_point.load()
|
|
32
|
+
if not (isinstance(plugin_class, type) and issubclass(plugin_class, CaoPlugin)):
|
|
33
|
+
logger.warning(
|
|
34
|
+
"Plugin entry point '%s' is not a CaoPlugin subclass, skipping",
|
|
35
|
+
entry_point.name,
|
|
36
|
+
)
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
plugin = plugin_class()
|
|
40
|
+
await plugin.setup()
|
|
41
|
+
self._register(plugin)
|
|
42
|
+
logger.info("Loaded CAO plugin: %s", entry_point.name)
|
|
43
|
+
except Exception:
|
|
44
|
+
logger.warning(
|
|
45
|
+
"Failed to load plugin '%s'",
|
|
46
|
+
entry_point.name,
|
|
47
|
+
exc_info=True,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if not self._plugins:
|
|
51
|
+
logger.info("No CAO plugins registered (cao.plugins entry point group is empty)")
|
|
52
|
+
|
|
53
|
+
def _register(self, plugin: CaoPlugin) -> None:
|
|
54
|
+
"""Register a plugin instance and index any decorated hook methods."""
|
|
55
|
+
|
|
56
|
+
self._plugins.append(plugin)
|
|
57
|
+
for _, method in inspect.getmembers(plugin, predicate=inspect.ismethod):
|
|
58
|
+
event_type = getattr(method, _HOOK_EVENT_ATTR, None)
|
|
59
|
+
if event_type is not None:
|
|
60
|
+
self._dispatch.setdefault(event_type, []).append(method)
|
|
61
|
+
|
|
62
|
+
async def dispatch(self, event_type: str, event: CaoEvent) -> None:
|
|
63
|
+
"""Dispatch an event to all matching plugin hook handlers."""
|
|
64
|
+
|
|
65
|
+
for handler in self._dispatch.get(event_type, []):
|
|
66
|
+
try:
|
|
67
|
+
await handler(event)
|
|
68
|
+
except Exception:
|
|
69
|
+
logger.warning(
|
|
70
|
+
"Hook '%s' raised an error for event '%s'",
|
|
71
|
+
handler.__qualname__,
|
|
72
|
+
event_type,
|
|
73
|
+
exc_info=True,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
async def teardown(self) -> None:
|
|
77
|
+
"""Call teardown() on every loaded plugin, continuing after failures."""
|
|
78
|
+
|
|
79
|
+
for plugin in self._plugins:
|
|
80
|
+
try:
|
|
81
|
+
await plugin.teardown()
|
|
82
|
+
except Exception:
|
|
83
|
+
logger.warning(
|
|
84
|
+
"Plugin teardown failed for %s",
|
|
85
|
+
type(plugin).__name__,
|
|
86
|
+
exc_info=True,
|
|
87
|
+
)
|
|
File without changes
|