talkops-opscloud 0.3.0b1__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.
- opscloud/__init__.py +5 -0
- opscloud/__main__.py +6 -0
- opscloud/_constants.py +53 -0
- opscloud/_debug.py +145 -0
- opscloud/_debug_buffer.py +250 -0
- opscloud/_textual_patches.py +367 -0
- opscloud/_version.py +15 -0
- opscloud/agent/__init__.py +27 -0
- opscloud/agent/config.py +168 -0
- opscloud/agent/factory.py +1103 -0
- opscloud/approval_mode.py +44 -0
- opscloud/backend/__init__.py +49 -0
- opscloud/backend/composite.py +89 -0
- opscloud/backend/local.py +183 -0
- opscloud/backend/registry.py +79 -0
- opscloud/backend/sandbox_config.py +107 -0
- opscloud/backend/sandbox_factory.py +432 -0
- opscloud/built_in_skills/remember/SKILL.md +124 -0
- opscloud/built_in_skills/skill-creator/SKILL.md +348 -0
- opscloud/built_in_skills/skill-creator/scripts/init_skill.py +371 -0
- opscloud/built_in_skills/skill-creator/scripts/quick_validate.py +165 -0
- opscloud/cli/__init__.py +1 -0
- opscloud/cli/commands/__init__.py +15 -0
- opscloud/cli/commands/auth.py +45 -0
- opscloud/cli/commands/doctor.py +100 -0
- opscloud/cli/commands/mcp.py +137 -0
- opscloud/cli/commands/threads.py +51 -0
- opscloud/cli/interactive.py +154 -0
- opscloud/cli/main.py +903 -0
- opscloud/cli/non_interactive.py +425 -0
- opscloud/cli/server_manager.py +58 -0
- opscloud/commands/__init__.py +19 -0
- opscloud/commands/_base.py +110 -0
- opscloud/commands/_guards.py +52 -0
- opscloud/commands/_router.py +146 -0
- opscloud/commands/_types.py +36 -0
- opscloud/commands/core/__init__.py +47 -0
- opscloud/commands/core/auth.py +94 -0
- opscloud/commands/core/bug.py +46 -0
- opscloud/commands/core/clear.py +106 -0
- opscloud/commands/core/cloud.py +185 -0
- opscloud/commands/core/compact.py +128 -0
- opscloud/commands/core/config_cmd.py +120 -0
- opscloud/commands/core/context.py +220 -0
- opscloud/commands/core/cost.py +44 -0
- opscloud/commands/core/doctor.py +535 -0
- opscloud/commands/core/effort.py +108 -0
- opscloud/commands/core/exit_cmd.py +41 -0
- opscloud/commands/core/fast.py +148 -0
- opscloud/commands/core/help_cmd.py +94 -0
- opscloud/commands/core/mcp.py +134 -0
- opscloud/commands/core/model.py +109 -0
- opscloud/commands/core/permissions.py +196 -0
- opscloud/commands/core/plugins.py +92 -0
- opscloud/commands/core/pool.py +108 -0
- opscloud/commands/core/resume.py +97 -0
- opscloud/commands/core/skills.py +178 -0
- opscloud/commands/power/__init__.py +51 -0
- opscloud/commands/power/agents.py +98 -0
- opscloud/commands/power/btw.py +85 -0
- opscloud/commands/power/copy.py +97 -0
- opscloud/commands/power/goal.py +548 -0
- opscloud/commands/power/loop.py +295 -0
- opscloud/commands/power/memory.py +287 -0
- opscloud/commands/power/review.py +152 -0
- opscloud/commands/power/rubric.py +287 -0
- opscloud/commands/power/runtime.py +321 -0
- opscloud/commands/power/skill_creator.py +70 -0
- opscloud/commands/power/skill_invoke.py +165 -0
- opscloud/commands/power/tasks.py +209 -0
- opscloud/commands/power/trace.py +117 -0
- opscloud/commands/power/ui_toggles.py +135 -0
- opscloud/commands/power/version.py +52 -0
- opscloud/commands/registry.py +176 -0
- opscloud/config/__init__.py +114 -0
- opscloud/config/adapters/__init__.py +5 -0
- opscloud/config/adapters/postgres.py +776 -0
- opscloud/config/adapters/sqlite.py +769 -0
- opscloud/config/aws.py +248 -0
- opscloud/config/cloud_profiles.py +437 -0
- opscloud/config/env_vars.py +81 -0
- opscloud/config/langsmith.py +319 -0
- opscloud/config/manifest.py +817 -0
- opscloud/config/metadata.py +205 -0
- opscloud/config/paths.py +604 -0
- opscloud/config/plugins.py +130 -0
- opscloud/config/settings.py +834 -0
- opscloud/config/store.py +453 -0
- opscloud/config/store_factory.py +97 -0
- opscloud/config/toml_config.py +562 -0
- opscloud/editor.py +173 -0
- opscloud/exceptions.py +65 -0
- opscloud/file_ops.py +217 -0
- opscloud/hooks/__init__.py +139 -0
- opscloud/hooks/env.py +44 -0
- opscloud/hooks/interrupt.py +121 -0
- opscloud/hooks/models/__init__.py +109 -0
- opscloud/hooks/models/adapters.py +19 -0
- opscloud/hooks/models/config.py +79 -0
- opscloud/hooks/models/domain.py +434 -0
- opscloud/hooks/models/transport.py +37 -0
- opscloud/hooks/tools.py +231 -0
- opscloud/input.py +48 -0
- opscloud/integrations/__init__.py +80 -0
- opscloud/integrations/base.py +153 -0
- opscloud/integrations/content_filter.py +119 -0
- opscloud/integrations/event_bus.py +480 -0
- opscloud/integrations/hooks.py +238 -0
- opscloud/integrations/identity.py +181 -0
- opscloud/integrations/notifications.py +134 -0
- opscloud/integrations/stream_bridge.py +397 -0
- opscloud/integrations/thread_store.py +81 -0
- opscloud/json_types.py +20 -0
- opscloud/mcp/__init__.py +57 -0
- opscloud/mcp/config.py +203 -0
- opscloud/mcp/discovery.py +229 -0
- opscloud/mcp/mcp_info.py +109 -0
- opscloud/mcp/middleware.py +102 -0
- opscloud/mcp/preload.py +505 -0
- opscloud/mcp/raw_config.py +149 -0
- opscloud/mcp/semantic_profiler.py +305 -0
- opscloud/mcp/session_manager.py +727 -0
- opscloud/mcp/trust.py +105 -0
- opscloud/memory/__init__.py +27 -0
- opscloud/memory/branch.py +61 -0
- opscloud/memory/guard.py +19 -0
- opscloud/memory/onboarding.py +120 -0
- opscloud/memory/registry.py +134 -0
- opscloud/memory/store.py +223 -0
- opscloud/middleware/__init__.py +106 -0
- opscloud/middleware/_repository_bounds.py +459 -0
- opscloud/middleware/ask_user.py +152 -0
- opscloud/middleware/auto_mode.py +60 -0
- opscloud/middleware/auto_mode_hitl.py +2434 -0
- opscloud/middleware/compaction.py +566 -0
- opscloud/middleware/configurable_model.py +233 -0
- opscloud/middleware/cost_tracking.py +1021 -0
- opscloud/middleware/glm_stall_recovery.py +109 -0
- opscloud/middleware/goal_criteria.py +1234 -0
- opscloud/middleware/goal_state_notice.py +712 -0
- opscloud/middleware/goal_tools.py +407 -0
- opscloud/middleware/headless_mcp_guard.py +88 -0
- opscloud/middleware/jev_model_router.py +1018 -0
- opscloud/middleware/local_context.py +460 -0
- opscloud/middleware/mcp_context.py +151 -0
- opscloud/middleware/mcp_middleware.py +146 -0
- opscloud/middleware/memory_guard.py +393 -0
- opscloud/middleware/model_retry.py +205 -0
- opscloud/middleware/registry.py +137 -0
- opscloud/middleware/reliable_rubric.py +709 -0
- opscloud/middleware/resume_state.py +91 -0
- opscloud/middleware/server_hooks.py +1189 -0
- opscloud/middleware/shell_allow_list.py +90 -0
- opscloud/middleware/skills.py +382 -0
- opscloud/middleware/subagent_artifacts.py +84 -0
- opscloud/middleware/subagent_telemetry.py +261 -0
- opscloud/middleware/subagents.py +243 -0
- opscloud/middleware/tool_filter.py +384 -0
- opscloud/middleware/unified_system_message.py +62 -0
- opscloud/model/__init__.py +37 -0
- opscloud/model/config.py +2992 -0
- opscloud/model/factory.py +477 -0
- opscloud/model/pool.py +459 -0
- opscloud/model/reasoning.py +282 -0
- opscloud/offload.py +173 -0
- opscloud/output.py +64 -0
- opscloud/plugins/__init__.py +189 -0
- opscloud/plugins/_json.py +22 -0
- opscloud/plugins/adapters/__init__.py +13 -0
- opscloud/plugins/adapters/agents.py +112 -0
- opscloud/plugins/adapters/commands.py +190 -0
- opscloud/plugins/adapters/mcp.py +363 -0
- opscloud/plugins/adapters/skills.py +132 -0
- opscloud/plugins/commands_cli.py +541 -0
- opscloud/plugins/discovery.py +512 -0
- opscloud/plugins/manifest.py +335 -0
- opscloud/plugins/marketplace.py +893 -0
- opscloud/plugins/models.py +334 -0
- opscloud/plugins/project_plugins.py +317 -0
- opscloud/plugins/protocol.py +31 -0
- opscloud/plugins/store.py +905 -0
- opscloud/plugins/substitution.py +122 -0
- opscloud/project_utils.py +145 -0
- opscloud/prompts/__init__.py +37 -0
- opscloud/prompts/system.py +483 -0
- opscloud/prompts/templates/system_prompt.md +166 -0
- opscloud/prompts/types.py +54 -0
- opscloud/rubrics/__init__.py +42 -0
- opscloud/rubrics/evaluator.py +404 -0
- opscloud/rubrics/evidence_extractor.py +229 -0
- opscloud/rubrics/generator.py +239 -0
- opscloud/rubrics/jev_compiler.py +175 -0
- opscloud/rubrics/jev_grader.py +297 -0
- opscloud/rubrics/middleware.py +8 -0
- opscloud/schema/__init__.py +107 -0
- opscloud/schema/interrupts.py +981 -0
- opscloud/security/__init__.py +91 -0
- opscloud/security/approval_mode.py +528 -0
- opscloud/security/approval_mode_source.py +230 -0
- opscloud/security/cli_ast_evaluator.py +552 -0
- opscloud/security/jev_classifier.py +651 -0
- opscloud/security/shell_safety.py +340 -0
- opscloud/security/unicode_security.py +439 -0
- opscloud/security/url_validation.py +160 -0
- opscloud/server/__init__.py +13 -0
- opscloud/server/_server_config.py +158 -0
- opscloud/server/server.py +242 -0
- opscloud/server/server_graph.py +93 -0
- opscloud/skills/__init__.py +91 -0
- opscloud/skills/commands.py +1099 -0
- opscloud/skills/invocation.py +200 -0
- opscloud/skills/load.py +388 -0
- opscloud/skills/loader.py +23 -0
- opscloud/skills/merge.py +65 -0
- opscloud/skills/registry.py +263 -0
- opscloud/skills/sources.py +174 -0
- opscloud/skills/trust.py +417 -0
- opscloud/state/__init__.py +142 -0
- opscloud/state/base.py +154 -0
- opscloud/state/cloud_context.py +262 -0
- opscloud/state/goal_channels.py +124 -0
- opscloud/state/goal_state_limits.py +175 -0
- opscloud/state/resume_state.py +58 -0
- opscloud/state/service_context.py +281 -0
- opscloud/state/session.py +957 -0
- opscloud/state/state_migration.py +86 -0
- opscloud/subagents/__init__.py +30 -0
- opscloud/subagents/loader.py +331 -0
- opscloud/subagents/subagents_parser.py +117 -0
- opscloud/subagents/types.py +25 -0
- opscloud/tools/__init__.py +36 -0
- opscloud/tools/catalog.py +37 -0
- opscloud/tools/display.py +24 -0
- opscloud/tools/fetch_url.py +176 -0
- opscloud/tools/goal_tools.py +423 -0
- opscloud/tools/registry.py +105 -0
- opscloud/tools/thread.py +32 -0
- opscloud/tools/web_search.py +215 -0
- opscloud/ui/__init__.py +119 -0
- opscloud/ui/app.py +5400 -0
- opscloud/ui/app.tcss +479 -0
- opscloud/ui/clipboard.py +147 -0
- opscloud/ui/command_registry.py +482 -0
- opscloud/ui/message_store.py +152 -0
- opscloud/ui/permission_store.py +360 -0
- opscloud/ui/preferences.py +113 -0
- opscloud/ui/prompt_manager.py +96 -0
- opscloud/ui/remote_client.py +505 -0
- opscloud/ui/textual_adapter.py +1269 -0
- opscloud/ui/theme.py +728 -0
- opscloud/ui/ui_help.py +415 -0
- opscloud/ui/widgets/__init__.py +383 -0
- opscloud/ui/widgets/_ask_user_types.py +81 -0
- opscloud/ui/widgets/_copy_spans.py +52 -0
- opscloud/ui/widgets/_inline_prompt.py +290 -0
- opscloud/ui/widgets/_js_eval_display.py +139 -0
- opscloud/ui/widgets/_links.py +175 -0
- opscloud/ui/widgets/_tool_stream.py +308 -0
- opscloud/ui/widgets/agent_selector.py +297 -0
- opscloud/ui/widgets/approval.py +741 -0
- opscloud/ui/widgets/ask_user.py +539 -0
- opscloud/ui/widgets/auth.py +695 -0
- opscloud/ui/widgets/auth_manager.py +214 -0
- opscloud/ui/widgets/auto_mode_notice.py +146 -0
- opscloud/ui/widgets/autocomplete.py +709 -0
- opscloud/ui/widgets/chat_input.py +805 -0
- opscloud/ui/widgets/cloud_selector.py +528 -0
- opscloud/ui/widgets/config_manager.py +652 -0
- opscloud/ui/widgets/debug_console.py +1269 -0
- opscloud/ui/widgets/devops_renderers.py +184 -0
- opscloud/ui/widgets/diff.py +237 -0
- opscloud/ui/widgets/effort_selector.py +166 -0
- opscloud/ui/widgets/goal_review.py +612 -0
- opscloud/ui/widgets/goal_status.py +57 -0
- opscloud/ui/widgets/infra_panel.py +141 -0
- opscloud/ui/widgets/install_confirm.py +114 -0
- opscloud/ui/widgets/loading.py +170 -0
- opscloud/ui/widgets/mcp_viewer.py +1204 -0
- opscloud/ui/widgets/messages.py +4461 -0
- opscloud/ui/widgets/model_selector.py +863 -0
- opscloud/ui/widgets/notification_center.py +108 -0
- opscloud/ui/widgets/notification_settings.py +119 -0
- opscloud/ui/widgets/operation_card.py +106 -0
- opscloud/ui/widgets/permissions_manager.py +667 -0
- opscloud/ui/widgets/plugin_manager.py +1212 -0
- opscloud/ui/widgets/pool_selector.py +376 -0
- opscloud/ui/widgets/preamble.py +53 -0
- opscloud/ui/widgets/skills_viewer.py +432 -0
- opscloud/ui/widgets/status.py +1037 -0
- opscloud/ui/widgets/subagent_panel.py +927 -0
- opscloud/ui/widgets/theme_selector.py +232 -0
- opscloud/ui/widgets/thread_selector.py +358 -0
- opscloud/ui/widgets/toast.py +31 -0
- opscloud/ui/widgets/tool_display.py +325 -0
- opscloud/ui/widgets/tool_renderers.py +234 -0
- opscloud/ui/widgets/tool_widgets.py +278 -0
- opscloud/ui/widgets/welcome.py +421 -0
- opscloud/ui/widgets/welcome_popup.py +102 -0
- opscloud/utils/__init__.py +24 -0
- opscloud/utils/cost_estimation.py +169 -0
- opscloud/utils/git.py +390 -0
- opscloud/utils/logger.py +571 -0
- opscloud/utils/session_stats.py +115 -0
- opscloud/utils/startup_error.py +37 -0
- talkops_opscloud-0.3.0b1.dist-info/METADATA +449 -0
- talkops_opscloud-0.3.0b1.dist-info/RECORD +309 -0
- talkops_opscloud-0.3.0b1.dist-info/WHEEL +4 -0
- talkops_opscloud-0.3.0b1.dist-info/entry_points.txt +2 -0
- talkops_opscloud-0.3.0b1.dist-info/licenses/LICENSE +175 -0
opscloud/input.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Input handling utilities including @file mention parsing and path resolution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from opscloud.utils.logger import get_logger
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
logger = get_logger(__name__)
|
|
10
|
+
|
|
11
|
+
PATH_CHAR_CLASS = r"A-Za-z0-9._~/\\:-"
|
|
12
|
+
FILE_MENTION_PATTERN = re.compile(r"@(?P<path>(?:\\.|[" + PATH_CHAR_CLASS + r"])+)")
|
|
13
|
+
EMAIL_PREFIX_PATTERN = re.compile(r"[a-zA-Z0-9._%+-]$")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def parse_file_mentions(text: str) -> tuple[str, list[Path]]:
|
|
17
|
+
"""Extract `@file` mentions from input text and return resolved file paths.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
text: Input text potentially containing `@file` mentions.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
Tuple of (original text unchanged, list of resolved file paths that exist).
|
|
24
|
+
"""
|
|
25
|
+
matches = FILE_MENTION_PATTERN.finditer(text)
|
|
26
|
+
files: list[Path] = []
|
|
27
|
+
|
|
28
|
+
for match in matches:
|
|
29
|
+
text_before = text[: match.start()]
|
|
30
|
+
if text_before and EMAIL_PREFIX_PATTERN.search(text_before):
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
raw_path = match.group("path")
|
|
34
|
+
clean_path = raw_path.replace("\\ ", " ")
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
path = Path(clean_path).expanduser()
|
|
38
|
+
if not path.is_absolute():
|
|
39
|
+
path = Path.cwd() / path
|
|
40
|
+
|
|
41
|
+
resolved = path.resolve()
|
|
42
|
+
if resolved.exists() and resolved.is_file():
|
|
43
|
+
if resolved not in files:
|
|
44
|
+
files.append(resolved)
|
|
45
|
+
except (OSError, RuntimeError) as e:
|
|
46
|
+
logger.debug("Path resolution failed for %s: %s", raw_path, e)
|
|
47
|
+
|
|
48
|
+
return text, files
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""OpsCloud integrations — event hooks, external event bus, notifications, and stream bridging."""
|
|
2
|
+
|
|
3
|
+
from opscloud.integrations.base import (
|
|
4
|
+
IncomingMessage,
|
|
5
|
+
InteractionPayload,
|
|
6
|
+
MessagingIntegration,
|
|
7
|
+
)
|
|
8
|
+
from opscloud.integrations.content_filter import (
|
|
9
|
+
filter_internal_content,
|
|
10
|
+
is_internal_message,
|
|
11
|
+
)
|
|
12
|
+
from opscloud.integrations.event_bus import (
|
|
13
|
+
BypassTier,
|
|
14
|
+
EventBus,
|
|
15
|
+
EventSink,
|
|
16
|
+
ExternalEvent,
|
|
17
|
+
ExternalEventKind,
|
|
18
|
+
ExternalSignal,
|
|
19
|
+
default_unix_socket_path,
|
|
20
|
+
)
|
|
21
|
+
from opscloud.integrations.hooks import (
|
|
22
|
+
ALL_KNOWN_EVENTS,
|
|
23
|
+
DEVOPS_EVENTS,
|
|
24
|
+
STANDARD_EVENTS,
|
|
25
|
+
HookConfig,
|
|
26
|
+
dispatch_hook,
|
|
27
|
+
dispatch_hook_fire_and_forget,
|
|
28
|
+
drain_pending_hooks,
|
|
29
|
+
load_hooks,
|
|
30
|
+
)
|
|
31
|
+
from opscloud.integrations.identity import IdentityMapper, UserIdentity
|
|
32
|
+
from opscloud.integrations.notifications import (
|
|
33
|
+
notify_cloud_event,
|
|
34
|
+
notify_deploy_event,
|
|
35
|
+
notify_session_end,
|
|
36
|
+
notify_session_start,
|
|
37
|
+
notify_task_complete,
|
|
38
|
+
notify_tool_result,
|
|
39
|
+
notify_tool_use,
|
|
40
|
+
)
|
|
41
|
+
from opscloud.integrations.stream_bridge import (
|
|
42
|
+
GraphStreamBridge,
|
|
43
|
+
StreamSink,
|
|
44
|
+
)
|
|
45
|
+
from opscloud.integrations.thread_store import ThreadStore
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"ALL_KNOWN_EVENTS",
|
|
49
|
+
"BypassTier",
|
|
50
|
+
"DEVOPS_EVENTS",
|
|
51
|
+
"EventBus",
|
|
52
|
+
"EventSink",
|
|
53
|
+
"ExternalEvent",
|
|
54
|
+
"ExternalEventKind",
|
|
55
|
+
"ExternalSignal",
|
|
56
|
+
"GraphStreamBridge",
|
|
57
|
+
"HookConfig",
|
|
58
|
+
"IdentityMapper",
|
|
59
|
+
"IncomingMessage",
|
|
60
|
+
"InteractionPayload",
|
|
61
|
+
"MessagingIntegration",
|
|
62
|
+
"STANDARD_EVENTS",
|
|
63
|
+
"StreamSink",
|
|
64
|
+
"ThreadStore",
|
|
65
|
+
"UserIdentity",
|
|
66
|
+
"default_unix_socket_path",
|
|
67
|
+
"dispatch_hook",
|
|
68
|
+
"dispatch_hook_fire_and_forget",
|
|
69
|
+
"drain_pending_hooks",
|
|
70
|
+
"filter_internal_content",
|
|
71
|
+
"is_internal_message",
|
|
72
|
+
"load_hooks",
|
|
73
|
+
"notify_cloud_event",
|
|
74
|
+
"notify_deploy_event",
|
|
75
|
+
"notify_session_end",
|
|
76
|
+
"notify_session_start",
|
|
77
|
+
"notify_task_complete",
|
|
78
|
+
"notify_tool_result",
|
|
79
|
+
"notify_tool_use",
|
|
80
|
+
]
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Abstract base classes for external interface and messaging integrations.
|
|
2
|
+
|
|
3
|
+
To integrate an external interface or runner, subclass ``MessagingIntegration``
|
|
4
|
+
and implement the abstract methods. The generic ``GraphStreamBridge`` and
|
|
5
|
+
``ThreadStore`` can be reused as-is.
|
|
6
|
+
|
|
7
|
+
Data flow::
|
|
8
|
+
|
|
9
|
+
External Event → IncomingMessage → MessagingIntegration.handle_message()
|
|
10
|
+
│
|
|
11
|
+
├─ IdentityMapper.resolve()
|
|
12
|
+
├─ ThreadStore.resolve()
|
|
13
|
+
└─ GraphStreamBridge.process_stream()
|
|
14
|
+
│
|
|
15
|
+
└─ StreamSink (interface-specific)
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from abc import ABC, abstractmethod
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class IncomingMessage:
|
|
27
|
+
"""Platform-agnostic representation of an incoming user message.
|
|
28
|
+
|
|
29
|
+
Each platform adapter (Slack Bolt handler, Teams webhook, etc.)
|
|
30
|
+
converts its native event payload into this structure before handing
|
|
31
|
+
it to :meth:`MessagingIntegration.handle_message`.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
text: str
|
|
35
|
+
"""The user's message text, stripped of platform-specific markup."""
|
|
36
|
+
|
|
37
|
+
user_id: str
|
|
38
|
+
"""Platform-native user identifier (e.g. Slack ``U…``, Teams AAD OID)."""
|
|
39
|
+
|
|
40
|
+
thread_id: str
|
|
41
|
+
"""Platform-native thread identifier used for reply threading."""
|
|
42
|
+
|
|
43
|
+
channel_id: str
|
|
44
|
+
"""Platform-native channel / conversation identifier."""
|
|
45
|
+
|
|
46
|
+
platform: str
|
|
47
|
+
"""Platform key: ``"slack"``, ``"teams"``, ``"discord"``, etc."""
|
|
48
|
+
|
|
49
|
+
raw_event: dict[str, Any] = field(default_factory=dict)
|
|
50
|
+
"""Full, unmodified platform event payload for advanced use cases."""
|
|
51
|
+
|
|
52
|
+
context: dict[str, Any] = field(default_factory=dict)
|
|
53
|
+
"""Additional context extracted from the platform
|
|
54
|
+
(e.g. Slack assistant ``context`` object with ``channel_id``,
|
|
55
|
+
``team_id``, ``enterprise_id``)."""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class InteractionPayload:
|
|
60
|
+
"""Platform-agnostic representation of an interactive user action.
|
|
61
|
+
|
|
62
|
+
Covers button clicks, menu selections, modal submissions, etc.
|
|
63
|
+
The platform adapter converts its native interactive payload into
|
|
64
|
+
this structure before handing it to
|
|
65
|
+
:meth:`MessagingIntegration.handle_interaction`.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
action_id: str
|
|
69
|
+
"""Platform-native action identifier (e.g. ``"approve_deploy"``)."""
|
|
70
|
+
|
|
71
|
+
user_id: str
|
|
72
|
+
"""Platform-native user identifier of the person who acted."""
|
|
73
|
+
|
|
74
|
+
thread_id: str
|
|
75
|
+
"""Thread identifier linking this action back to the conversation."""
|
|
76
|
+
|
|
77
|
+
channel_id: str
|
|
78
|
+
"""Channel / conversation where the interactive element was posted."""
|
|
79
|
+
|
|
80
|
+
platform: str
|
|
81
|
+
"""Platform key: ``"slack"``, ``"teams"``, ``"discord"``, etc."""
|
|
82
|
+
|
|
83
|
+
value: str | None = None
|
|
84
|
+
"""Button value, selected option text, or freeform input."""
|
|
85
|
+
|
|
86
|
+
raw_payload: dict[str, Any] = field(default_factory=dict)
|
|
87
|
+
"""Full, unmodified interactive payload from the platform."""
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class MessagingIntegration(ABC):
|
|
91
|
+
"""Base class all interface and messaging adapters must implement.
|
|
92
|
+
|
|
93
|
+
Subclasses handle four responsibilities:
|
|
94
|
+
|
|
95
|
+
1. **Message ingestion** — Convert external events into
|
|
96
|
+
:class:`IncomingMessage` and run them through the LangGraph agent.
|
|
97
|
+
2. **Streaming output** — Pipe agent output tokens to the interface
|
|
98
|
+
in real time.
|
|
99
|
+
3. **HITL rendering** — Render ``interrupt()`` payloads as
|
|
100
|
+
actionable confirmation / approval requests.
|
|
101
|
+
4. **Identity resolution** — Map caller IDs to internal
|
|
102
|
+
identities and cloud RBAC roles.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
@abstractmethod
|
|
106
|
+
async def handle_message(self, message: IncomingMessage) -> None:
|
|
107
|
+
"""Process an incoming user message through the LangGraph agent.
|
|
108
|
+
|
|
109
|
+
This method should:
|
|
110
|
+
|
|
111
|
+
1. Resolve the user's identity and RBAC permissions.
|
|
112
|
+
2. Map the platform thread to a LangGraph ``thread_id``.
|
|
113
|
+
3. Build the graph input state.
|
|
114
|
+
4. Stream graph execution to the platform via a ``StreamSink``.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
@abstractmethod
|
|
118
|
+
async def handle_interaction(self, payload: InteractionPayload) -> None:
|
|
119
|
+
"""Handle an interactive action (approve / reject / edit).
|
|
120
|
+
|
|
121
|
+
Typically resumes an interrupted LangGraph run with
|
|
122
|
+
``Command(resume=...)``.
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
@abstractmethod
|
|
126
|
+
async def send_text(
|
|
127
|
+
self,
|
|
128
|
+
channel_id: str,
|
|
129
|
+
thread_id: str,
|
|
130
|
+
text: str,
|
|
131
|
+
) -> None:
|
|
132
|
+
"""Send a plain-text message to the platform."""
|
|
133
|
+
|
|
134
|
+
@abstractmethod
|
|
135
|
+
async def send_blocks(
|
|
136
|
+
self,
|
|
137
|
+
channel_id: str,
|
|
138
|
+
thread_id: str,
|
|
139
|
+
blocks: list[dict[str, Any]],
|
|
140
|
+
) -> None:
|
|
141
|
+
"""Send rich / structured content to the platform.
|
|
142
|
+
|
|
143
|
+
"Blocks" is a generic term — on Slack it maps to Block Kit JSON,
|
|
144
|
+
on Teams to Adaptive Cards, etc.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
@abstractmethod
|
|
148
|
+
async def set_typing_status(
|
|
149
|
+
self,
|
|
150
|
+
channel_id: str,
|
|
151
|
+
thread_id: str,
|
|
152
|
+
) -> None:
|
|
153
|
+
"""Show a typing / thinking indicator on the platform."""
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Content filter for internal protocol messages.
|
|
2
|
+
|
|
3
|
+
Detects and filters SystemMessage-echoed content that middleware injects
|
|
4
|
+
into the LLM conversation but should never surface to end users on
|
|
5
|
+
external platforms (Slack, Teams, etc.).
|
|
6
|
+
|
|
7
|
+
These patterns originate from:
|
|
8
|
+
|
|
9
|
+
- :class:`PlanLockMiddleware` — ``ACTIVE PLAN (LOCKED — DO NOT DEVIATE)``
|
|
10
|
+
- :class:`TodoListMiddleware` — ``Execution Checklist``, ``⏳ pending``
|
|
11
|
+
- Coordinator prompt sections — ``[PLAN-APPROVED]``, ``[PLAN-LOCKED]``
|
|
12
|
+
- Duplicate guard — ``[DUPLICATE CALL BLOCKED]``
|
|
13
|
+
|
|
14
|
+
Filtered content is logged at DEBUG level with a ``[FILTERED]`` tag
|
|
15
|
+
for troubleshooting.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import re
|
|
21
|
+
|
|
22
|
+
from opscloud.utils.logger import get_logger
|
|
23
|
+
|
|
24
|
+
logger = get_logger(__name__)
|
|
25
|
+
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
# Compiled patterns — catch both full lines and substring echoes
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
_INTERNAL_PATTERNS: tuple[re.Pattern[str], ...] = (
|
|
31
|
+
# PlanLockMiddleware injected SystemMessages
|
|
32
|
+
re.compile(r"##?\s*ACTIVE PLAN\s*\(LOCKED", re.IGNORECASE),
|
|
33
|
+
re.compile(r"DO NOT DEVIATE\)?", re.IGNORECASE),
|
|
34
|
+
re.compile(r"Any deviation is a protocol violation", re.IGNORECASE),
|
|
35
|
+
re.compile(
|
|
36
|
+
r"STOP and report the error\.?\s*Do NOT attempt alternatives",
|
|
37
|
+
re.IGNORECASE,
|
|
38
|
+
),
|
|
39
|
+
re.compile(
|
|
40
|
+
r"The user approved the following plan\.\s*Execute\s+EXACTLY",
|
|
41
|
+
re.IGNORECASE,
|
|
42
|
+
),
|
|
43
|
+
# TodoList / Execution checklist
|
|
44
|
+
re.compile(r"###?\s*Execution Checklist", re.IGNORECASE),
|
|
45
|
+
re.compile(r"⏳\s*.*\(pending\)", re.IGNORECASE),
|
|
46
|
+
re.compile(r"Update TODO status via\s+`?write_todos`?", re.IGNORECASE),
|
|
47
|
+
re.compile(
|
|
48
|
+
r"Execute the next.*pending/in_progress step",
|
|
49
|
+
re.IGNORECASE,
|
|
50
|
+
),
|
|
51
|
+
# Coordinator delegation prefixes
|
|
52
|
+
re.compile(r"\[PLAN-APPROVED\]"),
|
|
53
|
+
re.compile(r"\[PLAN-LOCKED\]"),
|
|
54
|
+
re.compile(r"Delegate with \[PLAN-APPROVED\]", re.IGNORECASE),
|
|
55
|
+
# Cross-domain / skill shortcut prefixes
|
|
56
|
+
re.compile(r"\[CROSS-DOMAIN\].*Source:", re.IGNORECASE),
|
|
57
|
+
re.compile(r"\[SKILL-EXISTS SHORTCUT\]"),
|
|
58
|
+
# Duplicate guard
|
|
59
|
+
re.compile(r"\[DUPLICATE CALL BLOCKED", re.IGNORECASE),
|
|
60
|
+
# Protocol violation warnings echoed by LLM
|
|
61
|
+
re.compile(r"protocol violation", re.IGNORECASE),
|
|
62
|
+
# Rules section headers from plan-lock
|
|
63
|
+
re.compile(r"###?\s*Rules\s*$", re.IGNORECASE),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def is_internal_message(text: str) -> bool:
|
|
68
|
+
"""Check whether *text* contains internal protocol content.
|
|
69
|
+
|
|
70
|
+
This is a lightweight check intended for per-chunk screening.
|
|
71
|
+
Returns ``True`` if **any** internal pattern matches anywhere in
|
|
72
|
+
the text.
|
|
73
|
+
|
|
74
|
+
>>> is_internal_message("## ACTIVE PLAN (LOCKED — DO NOT DEVIATE)")
|
|
75
|
+
True
|
|
76
|
+
>>> is_internal_message("Here are the pods in namespace default:")
|
|
77
|
+
False
|
|
78
|
+
"""
|
|
79
|
+
if not text:
|
|
80
|
+
return False
|
|
81
|
+
return any(p.search(text) for p in _INTERNAL_PATTERNS)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def filter_internal_content(text: str) -> str:
|
|
85
|
+
r"""Remove internal protocol lines, return user-facing text.
|
|
86
|
+
|
|
87
|
+
Operates line-by-line: any line matching an internal pattern is
|
|
88
|
+
removed and logged at DEBUG level. Returns the cleaned text
|
|
89
|
+
(may be empty if all lines are internal).
|
|
90
|
+
|
|
91
|
+
>>> filter_internal_content(
|
|
92
|
+
... "## ACTIVE PLAN (LOCKED)\\nInstall argo-cd\\nDO NOT DEVIATE"
|
|
93
|
+
... )
|
|
94
|
+
'Install argo-cd'
|
|
95
|
+
"""
|
|
96
|
+
if not text:
|
|
97
|
+
return ""
|
|
98
|
+
|
|
99
|
+
lines = text.split("\n")
|
|
100
|
+
clean_lines: list[str] = []
|
|
101
|
+
|
|
102
|
+
for line in lines:
|
|
103
|
+
if any(p.search(line) for p in _INTERNAL_PATTERNS):
|
|
104
|
+
logger.debug("[FILTERED] %s", line[:120])
|
|
105
|
+
else:
|
|
106
|
+
clean_lines.append(line)
|
|
107
|
+
|
|
108
|
+
result = "\n".join(clean_lines).strip()
|
|
109
|
+
|
|
110
|
+
# Log summary when we actually filtered something
|
|
111
|
+
if len(clean_lines) < len(lines):
|
|
112
|
+
removed = len(lines) - len(clean_lines)
|
|
113
|
+
logger.debug(
|
|
114
|
+
"[FILTERED] Removed %d/%d internal lines from chunk",
|
|
115
|
+
removed,
|
|
116
|
+
len(lines),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
return result
|