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,36 @@
|
|
|
1
|
+
"""Main CLI entry point for CLI Agent Orchestrator."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from cli_agent_orchestrator.cli.commands.env import env
|
|
6
|
+
from cli_agent_orchestrator.cli.commands.flow import flow
|
|
7
|
+
from cli_agent_orchestrator.cli.commands.info import info
|
|
8
|
+
from cli_agent_orchestrator.cli.commands.init import init
|
|
9
|
+
from cli_agent_orchestrator.cli.commands.install import install
|
|
10
|
+
from cli_agent_orchestrator.cli.commands.launch import launch
|
|
11
|
+
from cli_agent_orchestrator.cli.commands.mcp_server import mcp_server
|
|
12
|
+
from cli_agent_orchestrator.cli.commands.session import session
|
|
13
|
+
from cli_agent_orchestrator.cli.commands.shutdown import shutdown
|
|
14
|
+
from cli_agent_orchestrator.cli.commands.skills import skills
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group()
|
|
18
|
+
def cli():
|
|
19
|
+
"""CLI Agent Orchestrator."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Register commands
|
|
23
|
+
cli.add_command(launch)
|
|
24
|
+
cli.add_command(init)
|
|
25
|
+
cli.add_command(install)
|
|
26
|
+
cli.add_command(shutdown)
|
|
27
|
+
cli.add_command(flow)
|
|
28
|
+
cli.add_command(env)
|
|
29
|
+
cli.add_command(mcp_server)
|
|
30
|
+
cli.add_command(info)
|
|
31
|
+
cli.add_command(skills)
|
|
32
|
+
cli.add_command(session)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
cli()
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"""Minimal database client with only terminal metadata."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from typing import Any, Dict, List, Optional
|
|
6
|
+
|
|
7
|
+
from sqlalchemy import Boolean, Column, DateTime, Integer, String, create_engine
|
|
8
|
+
from sqlalchemy.orm import DeclarativeBase, declarative_base, sessionmaker
|
|
9
|
+
|
|
10
|
+
from cli_agent_orchestrator.constants import DATABASE_URL, DB_DIR, DEFAULT_PROVIDER
|
|
11
|
+
from cli_agent_orchestrator.models.flow import Flow
|
|
12
|
+
from cli_agent_orchestrator.models.inbox import InboxMessage, MessageStatus
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
Base: Any = declarative_base()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TerminalModel(Base):
|
|
20
|
+
"""SQLAlchemy model for terminal metadata only."""
|
|
21
|
+
|
|
22
|
+
__tablename__ = "terminals"
|
|
23
|
+
|
|
24
|
+
id = Column(String, primary_key=True) # "abc123ef"
|
|
25
|
+
tmux_session = Column(String, nullable=False) # "cao-session-name"
|
|
26
|
+
tmux_window = Column(String, nullable=False) # "window-name"
|
|
27
|
+
provider = Column(String, nullable=False) # "q_cli", "claude_code"
|
|
28
|
+
agent_profile = Column(String) # "developer", "reviewer" (optional)
|
|
29
|
+
allowed_tools = Column(String, nullable=True) # JSON-encoded list of CAO tool names
|
|
30
|
+
last_active = Column(DateTime, default=datetime.now)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class InboxModel(Base):
|
|
34
|
+
"""SQLAlchemy model for inbox messages."""
|
|
35
|
+
|
|
36
|
+
__tablename__ = "inbox"
|
|
37
|
+
|
|
38
|
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
39
|
+
sender_id = Column(String, nullable=False)
|
|
40
|
+
receiver_id = Column(String, nullable=False)
|
|
41
|
+
message = Column(String, nullable=False)
|
|
42
|
+
status = Column(String, nullable=False) # MessageStatus enum value
|
|
43
|
+
created_at = Column(DateTime, default=datetime.now)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class FlowModel(Base):
|
|
47
|
+
"""SQLAlchemy model for flow metadata."""
|
|
48
|
+
|
|
49
|
+
__tablename__ = "flows"
|
|
50
|
+
|
|
51
|
+
name = Column(String, primary_key=True)
|
|
52
|
+
file_path = Column(String, nullable=False)
|
|
53
|
+
schedule = Column(String, nullable=False)
|
|
54
|
+
agent_profile = Column(String, nullable=False)
|
|
55
|
+
provider = Column(String, nullable=False)
|
|
56
|
+
script = Column(String, nullable=True)
|
|
57
|
+
last_run = Column(DateTime, nullable=True)
|
|
58
|
+
next_run = Column(DateTime, nullable=True)
|
|
59
|
+
enabled = Column(Boolean, default=True)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# Module-level singletons
|
|
63
|
+
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
64
|
+
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
|
65
|
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def init_db() -> None:
|
|
69
|
+
"""Initialize database tables and apply schema migrations."""
|
|
70
|
+
Base.metadata.create_all(bind=engine)
|
|
71
|
+
_migrate_add_allowed_tools()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _migrate_add_allowed_tools() -> None:
|
|
75
|
+
"""Add allowed_tools column to terminals table if missing (schema migration)."""
|
|
76
|
+
import sqlite3
|
|
77
|
+
|
|
78
|
+
from cli_agent_orchestrator.constants import DATABASE_FILE
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
conn = sqlite3.connect(str(DATABASE_FILE))
|
|
82
|
+
cursor = conn.execute("PRAGMA table_info(terminals)")
|
|
83
|
+
columns = {row[1] for row in cursor.fetchall()}
|
|
84
|
+
if "allowed_tools" not in columns:
|
|
85
|
+
conn.execute("ALTER TABLE terminals ADD COLUMN allowed_tools TEXT")
|
|
86
|
+
conn.commit()
|
|
87
|
+
logger.info("Migration: added allowed_tools column to terminals table")
|
|
88
|
+
conn.close()
|
|
89
|
+
except Exception as e:
|
|
90
|
+
logger.warning(f"Migration check for allowed_tools failed: {e}")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def create_terminal(
|
|
94
|
+
terminal_id: str,
|
|
95
|
+
tmux_session: str,
|
|
96
|
+
tmux_window: str,
|
|
97
|
+
provider: str,
|
|
98
|
+
agent_profile: Optional[str] = None,
|
|
99
|
+
allowed_tools: Optional[List[str]] = None,
|
|
100
|
+
) -> Dict[str, Any]:
|
|
101
|
+
"""Create terminal metadata record."""
|
|
102
|
+
import json as _json
|
|
103
|
+
|
|
104
|
+
with SessionLocal() as db:
|
|
105
|
+
terminal = TerminalModel(
|
|
106
|
+
id=terminal_id,
|
|
107
|
+
tmux_session=tmux_session,
|
|
108
|
+
tmux_window=tmux_window,
|
|
109
|
+
provider=provider,
|
|
110
|
+
agent_profile=agent_profile,
|
|
111
|
+
allowed_tools=_json.dumps(allowed_tools) if allowed_tools else None,
|
|
112
|
+
)
|
|
113
|
+
db.add(terminal)
|
|
114
|
+
db.commit()
|
|
115
|
+
return {
|
|
116
|
+
"id": terminal.id,
|
|
117
|
+
"tmux_session": terminal.tmux_session,
|
|
118
|
+
"tmux_window": terminal.tmux_window,
|
|
119
|
+
"provider": terminal.provider,
|
|
120
|
+
"agent_profile": terminal.agent_profile,
|
|
121
|
+
"allowed_tools": allowed_tools,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_terminal_metadata(terminal_id: str) -> Optional[Dict[str, Any]]:
|
|
126
|
+
"""Get terminal metadata by ID."""
|
|
127
|
+
import json as _json
|
|
128
|
+
|
|
129
|
+
with SessionLocal() as db:
|
|
130
|
+
terminal = db.query(TerminalModel).filter(TerminalModel.id == terminal_id).first()
|
|
131
|
+
if not terminal:
|
|
132
|
+
logger.warning(f"Terminal metadata not found for terminal_id: {terminal_id}")
|
|
133
|
+
return None
|
|
134
|
+
logger.debug(
|
|
135
|
+
f"Retrieved terminal metadata for {terminal_id}: provider={terminal.provider}, session={terminal.tmux_session}"
|
|
136
|
+
)
|
|
137
|
+
allowed_tools = _json.loads(terminal.allowed_tools) if terminal.allowed_tools else None
|
|
138
|
+
return {
|
|
139
|
+
"id": terminal.id,
|
|
140
|
+
"tmux_session": terminal.tmux_session,
|
|
141
|
+
"tmux_window": terminal.tmux_window,
|
|
142
|
+
"provider": terminal.provider,
|
|
143
|
+
"agent_profile": terminal.agent_profile,
|
|
144
|
+
"allowed_tools": allowed_tools,
|
|
145
|
+
"last_active": terminal.last_active,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def list_terminals_by_session(tmux_session: str) -> List[Dict[str, Any]]:
|
|
150
|
+
"""List all terminals in a tmux session."""
|
|
151
|
+
with SessionLocal() as db:
|
|
152
|
+
terminals = db.query(TerminalModel).filter(TerminalModel.tmux_session == tmux_session).all()
|
|
153
|
+
return [
|
|
154
|
+
{
|
|
155
|
+
"id": t.id,
|
|
156
|
+
"tmux_session": t.tmux_session,
|
|
157
|
+
"tmux_window": t.tmux_window,
|
|
158
|
+
"provider": t.provider,
|
|
159
|
+
"agent_profile": t.agent_profile,
|
|
160
|
+
"last_active": t.last_active,
|
|
161
|
+
}
|
|
162
|
+
for t in terminals
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def update_last_active(terminal_id: str) -> bool:
|
|
167
|
+
"""Update last active timestamp."""
|
|
168
|
+
with SessionLocal() as db:
|
|
169
|
+
terminal = db.query(TerminalModel).filter(TerminalModel.id == terminal_id).first()
|
|
170
|
+
if terminal:
|
|
171
|
+
terminal.last_active = datetime.now()
|
|
172
|
+
db.commit()
|
|
173
|
+
return True
|
|
174
|
+
return False
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def list_all_terminals() -> List[Dict[str, Any]]:
|
|
178
|
+
"""List all terminals."""
|
|
179
|
+
with SessionLocal() as db:
|
|
180
|
+
terminals = db.query(TerminalModel).all()
|
|
181
|
+
return [
|
|
182
|
+
{
|
|
183
|
+
"id": t.id,
|
|
184
|
+
"tmux_session": t.tmux_session,
|
|
185
|
+
"tmux_window": t.tmux_window,
|
|
186
|
+
"provider": t.provider,
|
|
187
|
+
"agent_profile": t.agent_profile,
|
|
188
|
+
"last_active": t.last_active,
|
|
189
|
+
}
|
|
190
|
+
for t in terminals
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def delete_terminal(terminal_id: str) -> bool:
|
|
195
|
+
"""Delete terminal metadata."""
|
|
196
|
+
with SessionLocal() as db:
|
|
197
|
+
deleted = db.query(TerminalModel).filter(TerminalModel.id == terminal_id).delete()
|
|
198
|
+
db.commit()
|
|
199
|
+
return deleted > 0
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def delete_terminals_by_session(tmux_session: str) -> int:
|
|
203
|
+
"""Delete all terminals in a session."""
|
|
204
|
+
with SessionLocal() as db:
|
|
205
|
+
deleted = (
|
|
206
|
+
db.query(TerminalModel).filter(TerminalModel.tmux_session == tmux_session).delete()
|
|
207
|
+
)
|
|
208
|
+
db.commit()
|
|
209
|
+
return deleted
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def create_inbox_message(sender_id: str, receiver_id: str, message: str) -> InboxMessage:
|
|
213
|
+
"""Create inbox message with status=MessageStatus.PENDING."""
|
|
214
|
+
with SessionLocal() as db:
|
|
215
|
+
inbox_msg = InboxModel(
|
|
216
|
+
sender_id=sender_id,
|
|
217
|
+
receiver_id=receiver_id,
|
|
218
|
+
message=message,
|
|
219
|
+
status=MessageStatus.PENDING.value,
|
|
220
|
+
)
|
|
221
|
+
db.add(inbox_msg)
|
|
222
|
+
db.commit()
|
|
223
|
+
db.refresh(inbox_msg)
|
|
224
|
+
return InboxMessage(
|
|
225
|
+
id=inbox_msg.id,
|
|
226
|
+
sender_id=inbox_msg.sender_id,
|
|
227
|
+
receiver_id=inbox_msg.receiver_id,
|
|
228
|
+
message=inbox_msg.message,
|
|
229
|
+
status=MessageStatus(inbox_msg.status),
|
|
230
|
+
created_at=inbox_msg.created_at,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def get_pending_messages(receiver_id: str, limit: int = 1) -> List[InboxMessage]:
|
|
235
|
+
"""Get pending messages ordered by created_at ASC (oldest first)."""
|
|
236
|
+
return get_inbox_messages(receiver_id, limit=limit, status=MessageStatus.PENDING)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def get_inbox_messages(
|
|
240
|
+
receiver_id: str, limit: int = 10, status: Optional[MessageStatus] = None
|
|
241
|
+
) -> List[InboxMessage]:
|
|
242
|
+
"""Get inbox messages with optional status filter ordered by created_at ASC (oldest first).
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
receiver_id: Terminal ID to get messages for
|
|
246
|
+
limit: Maximum number of messages to return (default: 10)
|
|
247
|
+
status: Optional filter by message status (None = all statuses)
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
List of inbox messages ordered by creation time (oldest first)
|
|
251
|
+
"""
|
|
252
|
+
with SessionLocal() as db:
|
|
253
|
+
query = db.query(InboxModel).filter(InboxModel.receiver_id == receiver_id)
|
|
254
|
+
|
|
255
|
+
if status is not None:
|
|
256
|
+
query = query.filter(InboxModel.status == status.value)
|
|
257
|
+
|
|
258
|
+
messages = query.order_by(InboxModel.created_at.asc()).limit(limit).all()
|
|
259
|
+
|
|
260
|
+
return [
|
|
261
|
+
InboxMessage(
|
|
262
|
+
id=msg.id,
|
|
263
|
+
sender_id=msg.sender_id,
|
|
264
|
+
receiver_id=msg.receiver_id,
|
|
265
|
+
message=msg.message,
|
|
266
|
+
status=MessageStatus(msg.status),
|
|
267
|
+
created_at=msg.created_at,
|
|
268
|
+
)
|
|
269
|
+
for msg in messages
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def update_message_status(message_id: int, status: MessageStatus) -> bool:
|
|
274
|
+
"""Update message status to MessageStatus.DELIVERED or MessageStatus.FAILED."""
|
|
275
|
+
with SessionLocal() as db:
|
|
276
|
+
message = db.query(InboxModel).filter(InboxModel.id == message_id).first()
|
|
277
|
+
if message:
|
|
278
|
+
message.status = status.value
|
|
279
|
+
db.commit()
|
|
280
|
+
return True
|
|
281
|
+
return False
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
# Flow database functions
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def create_flow(
|
|
288
|
+
name: str,
|
|
289
|
+
file_path: str,
|
|
290
|
+
schedule: str,
|
|
291
|
+
agent_profile: str,
|
|
292
|
+
provider: str,
|
|
293
|
+
script: str,
|
|
294
|
+
next_run: datetime,
|
|
295
|
+
) -> Flow:
|
|
296
|
+
"""Create flow record."""
|
|
297
|
+
with SessionLocal() as db:
|
|
298
|
+
flow = FlowModel(
|
|
299
|
+
name=name,
|
|
300
|
+
file_path=file_path,
|
|
301
|
+
schedule=schedule,
|
|
302
|
+
agent_profile=agent_profile,
|
|
303
|
+
provider=provider,
|
|
304
|
+
script=script,
|
|
305
|
+
next_run=next_run,
|
|
306
|
+
)
|
|
307
|
+
db.add(flow)
|
|
308
|
+
db.commit()
|
|
309
|
+
db.refresh(flow)
|
|
310
|
+
return Flow(
|
|
311
|
+
name=flow.name,
|
|
312
|
+
file_path=flow.file_path,
|
|
313
|
+
schedule=flow.schedule,
|
|
314
|
+
agent_profile=flow.agent_profile,
|
|
315
|
+
provider=flow.provider,
|
|
316
|
+
script=flow.script,
|
|
317
|
+
last_run=flow.last_run,
|
|
318
|
+
next_run=flow.next_run,
|
|
319
|
+
enabled=flow.enabled,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def get_flow(name: str) -> Optional[Flow]:
|
|
324
|
+
"""Get flow by name."""
|
|
325
|
+
with SessionLocal() as db:
|
|
326
|
+
flow = db.query(FlowModel).filter(FlowModel.name == name).first()
|
|
327
|
+
if not flow:
|
|
328
|
+
return None
|
|
329
|
+
return Flow(
|
|
330
|
+
name=flow.name,
|
|
331
|
+
file_path=flow.file_path,
|
|
332
|
+
schedule=flow.schedule,
|
|
333
|
+
agent_profile=flow.agent_profile,
|
|
334
|
+
provider=flow.provider,
|
|
335
|
+
script=flow.script,
|
|
336
|
+
last_run=flow.last_run,
|
|
337
|
+
next_run=flow.next_run,
|
|
338
|
+
enabled=flow.enabled,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def list_flows() -> List[Flow]:
|
|
343
|
+
"""List all flows."""
|
|
344
|
+
with SessionLocal() as db:
|
|
345
|
+
flows = db.query(FlowModel).order_by(FlowModel.next_run).all()
|
|
346
|
+
return [
|
|
347
|
+
Flow(
|
|
348
|
+
name=f.name,
|
|
349
|
+
file_path=f.file_path,
|
|
350
|
+
schedule=f.schedule,
|
|
351
|
+
agent_profile=f.agent_profile,
|
|
352
|
+
provider=f.provider,
|
|
353
|
+
script=f.script,
|
|
354
|
+
last_run=f.last_run,
|
|
355
|
+
next_run=f.next_run,
|
|
356
|
+
enabled=f.enabled,
|
|
357
|
+
)
|
|
358
|
+
for f in flows
|
|
359
|
+
]
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def update_flow_run_times(name: str, last_run: datetime, next_run: datetime) -> bool:
|
|
363
|
+
"""Update flow run times after execution."""
|
|
364
|
+
with SessionLocal() as db:
|
|
365
|
+
flow = db.query(FlowModel).filter(FlowModel.name == name).first()
|
|
366
|
+
if flow:
|
|
367
|
+
flow.last_run = last_run
|
|
368
|
+
flow.next_run = next_run
|
|
369
|
+
db.commit()
|
|
370
|
+
return True
|
|
371
|
+
return False
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def update_flow_enabled(name: str, enabled: bool, next_run: Optional[datetime] = None) -> bool:
|
|
375
|
+
"""Update flow enabled status and optionally next_run."""
|
|
376
|
+
with SessionLocal() as db:
|
|
377
|
+
flow = db.query(FlowModel).filter(FlowModel.name == name).first()
|
|
378
|
+
if flow:
|
|
379
|
+
flow.enabled = enabled
|
|
380
|
+
if next_run is not None:
|
|
381
|
+
flow.next_run = next_run
|
|
382
|
+
db.commit()
|
|
383
|
+
return True
|
|
384
|
+
return False
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def delete_flow(name: str) -> bool:
|
|
388
|
+
"""Delete flow."""
|
|
389
|
+
with SessionLocal() as db:
|
|
390
|
+
deleted = db.query(FlowModel).filter(FlowModel.name == name).delete()
|
|
391
|
+
db.commit()
|
|
392
|
+
return deleted > 0
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def get_flows_to_run() -> List[Flow]:
|
|
396
|
+
"""Get enabled flows where next_run <= now."""
|
|
397
|
+
with SessionLocal() as db:
|
|
398
|
+
now = datetime.now()
|
|
399
|
+
flows = (
|
|
400
|
+
db.query(FlowModel).filter(FlowModel.enabled == True, FlowModel.next_run <= now).all()
|
|
401
|
+
)
|
|
402
|
+
return [
|
|
403
|
+
Flow(
|
|
404
|
+
name=f.name,
|
|
405
|
+
file_path=f.file_path,
|
|
406
|
+
schedule=f.schedule,
|
|
407
|
+
agent_profile=f.agent_profile,
|
|
408
|
+
provider=f.provider,
|
|
409
|
+
script=f.script,
|
|
410
|
+
last_run=f.last_run,
|
|
411
|
+
next_run=f.next_run,
|
|
412
|
+
enabled=f.enabled,
|
|
413
|
+
)
|
|
414
|
+
for f in flows
|
|
415
|
+
]
|