siada-cli 0.0.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.
- agent_config.yaml +34 -0
- siada/__init__.py +13 -0
- siada/agent_hub/__init__.py +10 -0
- siada/agent_hub/coder/bug_fix_agent.py +398 -0
- siada/agent_hub/coder/code_gen_agent.py +235 -0
- siada/agent_hub/coder/fe_gen_agent.py +37 -0
- siada/agent_hub/coder/issue_review_agent.py +68 -0
- siada/agent_hub/coder/prompt/__init__.py +0 -0
- siada/agent_hub/coder/prompt/base/__init__.py +0 -0
- siada/agent_hub/coder/prompt/base/capabilities.py +18 -0
- siada/agent_hub/coder/prompt/base/non_interactive.py +14 -0
- siada/agent_hub/coder/prompt/base/prompt_builder.py +33 -0
- siada/agent_hub/coder/prompt/base/rules.py +40 -0
- siada/agent_hub/coder/prompt/base/tool_use.py +14 -0
- siada/agent_hub/coder/prompt/bug_prompt/bug_fix_prompt.py +51 -0
- siada/agent_hub/coder/prompt/bug_prompt/rules.py +53 -0
- siada/agent_hub/coder/prompt/code_gen_prompt.py +45 -0
- siada/agent_hub/coder/prompt/fe_gen_prompt.py +45 -0
- siada/agent_hub/coder/prompt/issue_review_prompt.py +121 -0
- siada/agent_hub/coder/tracing/__init__.py +22 -0
- siada/agent_hub/coder/tracing/logger_tracing_processor.py +458 -0
- siada/agent_hub/hooks/__init__.py +0 -0
- siada/agent_hub/hooks/io_hooks.py +30 -0
- siada/agent_hub/siada_agent.py +214 -0
- siada/config/__init__.py +0 -0
- siada/config/config_loader.py +67 -0
- siada/entrypoint/__init__.py +3 -0
- siada/entrypoint/args_parser/__init__.py +0 -0
- siada/entrypoint/args_parser/args.py +195 -0
- siada/entrypoint/interaction/__init__.py +0 -0
- siada/entrypoint/interaction/base_turn.py +107 -0
- siada/entrypoint/interaction/config.py +30 -0
- siada/entrypoint/interaction/controller.py +122 -0
- siada/entrypoint/interaction/nointeractive_controller.py +27 -0
- siada/entrypoint/interaction/turn/interface.py +116 -0
- siada/entrypoint/interaction/turn/models.py +34 -0
- siada/entrypoint/interaction/turn/run_turn.py +641 -0
- siada/entrypoint/interaction/turn_factory.py +35 -0
- siada/entrypoint/interaction/turn_models.py +28 -0
- siada/entrypoint/siadahub.py +413 -0
- siada/foundation/__init__.py +0 -0
- siada/foundation/code_agent_context.py +48 -0
- siada/foundation/config.py +59 -0
- siada/foundation/constants.py +2 -0
- siada/foundation/context.py +76 -0
- siada/foundation/logging.py +341 -0
- siada/foundation/tools/__init__.py +0 -0
- siada/foundation/tools/get_git_diff.py +105 -0
- siada/io/__init__.py +0 -0
- siada/io/banner.py +148 -0
- siada/io/color_settings.py +207 -0
- siada/io/color_utils.py +16 -0
- siada/io/components/__init__.py +0 -0
- siada/io/components/mdstream.py +204 -0
- siada/io/console_printer.py +68 -0
- siada/io/io.py +661 -0
- siada/io/key_bindings.py +129 -0
- siada/io/notification_command.py +40 -0
- siada/io/test_banner.py +64 -0
- siada/models/__init__.py +0 -0
- siada/models/agent.py +47 -0
- siada/models/coder/__init__.py +0 -0
- siada/models/converter.py +27 -0
- siada/models/model_base_config.py +121 -0
- siada/models/model_run_config.py +153 -0
- siada/provider/__init__.py +0 -0
- siada/provider/client_factory.py +112 -0
- siada/provider/llm_client.py +11 -0
- siada/provider/openrouter/__init__.py +0 -0
- siada/provider/openrouter/coverter.py +17 -0
- siada/provider/openrouter/openroute_provider.py +33 -0
- siada/provider/provider_factory.py +53 -0
- siada/queries/tree-sitter-language-pack/README.md +7 -0
- siada/queries/tree-sitter-language-pack/arduino-tags.scm +5 -0
- siada/queries/tree-sitter-language-pack/c-tags.scm +9 -0
- siada/queries/tree-sitter-language-pack/chatito-tags.scm +16 -0
- siada/queries/tree-sitter-language-pack/commonlisp-tags.scm +122 -0
- siada/queries/tree-sitter-language-pack/cpp-tags.scm +15 -0
- siada/queries/tree-sitter-language-pack/csharp-tags.scm +26 -0
- siada/queries/tree-sitter-language-pack/d-tags.scm +26 -0
- siada/queries/tree-sitter-language-pack/dart-tags.scm +92 -0
- siada/queries/tree-sitter-language-pack/elisp-tags.scm +5 -0
- siada/queries/tree-sitter-language-pack/elixir-tags.scm +54 -0
- siada/queries/tree-sitter-language-pack/elm-tags.scm +19 -0
- siada/queries/tree-sitter-language-pack/gleam-tags.scm +41 -0
- siada/queries/tree-sitter-language-pack/go-tags.scm +42 -0
- siada/queries/tree-sitter-language-pack/java-tags.scm +20 -0
- siada/queries/tree-sitter-language-pack/javascript-tags.scm +88 -0
- siada/queries/tree-sitter-language-pack/lua-tags.scm +34 -0
- siada/queries/tree-sitter-language-pack/ocaml-tags.scm +115 -0
- siada/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +98 -0
- siada/queries/tree-sitter-language-pack/pony-tags.scm +39 -0
- siada/queries/tree-sitter-language-pack/properties-tags.scm +5 -0
- siada/queries/tree-sitter-language-pack/python-tags.scm +14 -0
- siada/queries/tree-sitter-language-pack/r-tags.scm +21 -0
- siada/queries/tree-sitter-language-pack/racket-tags.scm +12 -0
- siada/queries/tree-sitter-language-pack/ruby-tags.scm +64 -0
- siada/queries/tree-sitter-language-pack/rust-tags.scm +60 -0
- siada/queries/tree-sitter-language-pack/solidity-tags.scm +43 -0
- siada/queries/tree-sitter-language-pack/swift-tags.scm +51 -0
- siada/queries/tree-sitter-language-pack/udev-tags.scm +20 -0
- siada/queries/tree-sitter-languages/README.md +23 -0
- siada/queries/tree-sitter-languages/c-tags.scm +9 -0
- siada/queries/tree-sitter-languages/c_sharp-tags.scm +46 -0
- siada/queries/tree-sitter-languages/cpp-tags.scm +15 -0
- siada/queries/tree-sitter-languages/dart-tags.scm +91 -0
- siada/queries/tree-sitter-languages/elisp-tags.scm +8 -0
- siada/queries/tree-sitter-languages/elixir-tags.scm +54 -0
- siada/queries/tree-sitter-languages/elm-tags.scm +19 -0
- siada/queries/tree-sitter-languages/go-tags.scm +30 -0
- siada/queries/tree-sitter-languages/hcl-tags.scm +77 -0
- siada/queries/tree-sitter-languages/java-tags.scm +20 -0
- siada/queries/tree-sitter-languages/javascript-tags.scm +88 -0
- siada/queries/tree-sitter-languages/kotlin-tags.scm +27 -0
- siada/queries/tree-sitter-languages/ocaml-tags.scm +115 -0
- siada/queries/tree-sitter-languages/ocaml_interface-tags.scm +98 -0
- siada/queries/tree-sitter-languages/php-tags.scm +26 -0
- siada/queries/tree-sitter-languages/python-tags.scm +12 -0
- siada/queries/tree-sitter-languages/ql-tags.scm +26 -0
- siada/queries/tree-sitter-languages/ruby-tags.scm +64 -0
- siada/queries/tree-sitter-languages/rust-tags.scm +60 -0
- siada/queries/tree-sitter-languages/scala-tags.scm +65 -0
- siada/queries/tree-sitter-languages/typescript-tags.scm +41 -0
- siada/services/__init__.py +30 -0
- siada/services/at_file_recommendation_design_document.md +1213 -0
- siada/services/code_context_manager.py +136 -0
- siada/services/enhanced_fix_result_check.py +546 -0
- siada/services/execution_trace_collector.py +207 -0
- siada/services/file_recommendation/__init__.py +136 -0
- siada/services/file_recommendation/core/__init__.py +17 -0
- siada/services/file_recommendation/core/completion_engine.py +351 -0
- siada/services/file_recommendation/core/config.py +62 -0
- siada/services/file_recommendation/core/file_discovery.py +353 -0
- siada/services/file_recommendation/core/suggestion.py +110 -0
- siada/services/file_recommendation/utils/__init__.py +22 -0
- siada/services/file_recommendation/utils/path_utils.py +138 -0
- siada/services/file_recommendation/utils/text_utils.py +253 -0
- siada/services/fix_result_check.py +377 -0
- siada/services/handle_at_command/README.md +247 -0
- siada/services/handle_at_command/__init__.py +115 -0
- siada/services/handle_at_command/exceptions.py +46 -0
- siada/services/handle_at_command/models.py +92 -0
- siada/services/handle_at_command/parser.py +189 -0
- siada/services/handle_at_command/processor.py +321 -0
- siada/services/handle_at_command/resolver.py +318 -0
- siada/services/handle_at_command/utils.py +345 -0
- siada/services/model_info_service.py +103 -0
- siada/services/siada_runner.py +170 -0
- siada/session/__init__.py +29 -0
- siada/session/session_manager.py +66 -0
- siada/session/session_models.py +43 -0
- siada/support/__init__.py +0 -0
- siada/support/completer.py +204 -0
- siada/support/editor.py +146 -0
- siada/support/envprocessor.py +54 -0
- siada/support/repo.py +51 -0
- siada/support/slash_commands.py +410 -0
- siada/support/spinner.py +320 -0
- siada/tools/__init__.py +0 -0
- siada/tools/ast/README.md +345 -0
- siada/tools/ast/ast_tool.py +341 -0
- siada/tools/ast/models.py +11 -0
- siada/tools/coder/__init__.py +0 -0
- siada/tools/coder/ask_followup_question.py +70 -0
- siada/tools/coder/cmd_runner.py +132 -0
- siada/tools/coder/file_operator.py +284 -0
- siada/tools/coder/file_search/README.md +223 -0
- siada/tools/coder/file_search/__init__.py +10 -0
- siada/tools/coder/file_search/bin/rg-linux-arm64 +0 -0
- siada/tools/coder/file_search/bin/rg-linux-x64 +0 -0
- siada/tools/coder/file_search/bin/rg-macos-arm64 +0 -0
- siada/tools/coder/file_search/bin/rg-macos-x64 +0 -0
- siada/tools/coder/file_search/bin/rg.exe +0 -0
- siada/tools/coder/file_search/search.py +437 -0
- siada/tools/coder/file_search/setup_package.py +150 -0
- siada/tools/coder/file_search/test_search.py +142 -0
- siada/tools/coder/files.py +147 -0
- siada/tools/coder/fix_attempt_completion.py +58 -0
- siada/tools/coder/issue_review_completion.py +29 -0
- siada/tools/coder/observation/__init__.py +0 -0
- siada/tools/coder/observation/error.py +22 -0
- siada/tools/coder/observation/file_observation.py +216 -0
- siada/tools/coder/observation/observation.py +71 -0
- siada/tools/coder/repo_map/__init__.py +157 -0
- siada/tools/coder/repo_map/dump.py +29 -0
- siada/tools/coder/repo_map/io.py +226 -0
- siada/tools/coder/repo_map/repo_map.py +881 -0
- siada/tools/coder/repo_map/special.py +203 -0
- siada/tools/coder/repo_map/token_counter.py +154 -0
- siada/tools/coder/repo_map/waiting.py +221 -0
- siada/tools/coder/reproduce_completion.py +39 -0
- siada/tools/coder/run_cmd.py +60 -0
- siada/tools/coder/test_completion.py +25 -0
- siada/tools/coder/tool_docs.py +44 -0
- siada/tools/compression_tool.py +200 -0
- siada/tools/read_many_files/README.md +220 -0
- siada/tools/read_many_files/__init__.py +25 -0
- siada/tools/read_many_files/file_processor.py +486 -0
- siada/tools/read_many_files/filters.py +326 -0
- siada/tools/read_many_files/formatters.py +204 -0
- siada/tools/read_many_files/models.py +189 -0
- siada/tools/read_many_files_tool.py +233 -0
- siada/tools/tool_call_format/__init__.py +55 -0
- siada/tools/tool_call_format/file_to_language.py +231 -0
- siada/tools/tool_call_format/formatter_factory.py +80 -0
- siada/tools/tool_call_format/formatters.py +282 -0
- siada/tools/tool_call_format/tool_call_formatter.py +54 -0
- siada/tools/web/__init__.py +0 -0
- siada/tools/web/web_crawl.py +208 -0
- siada/utils.py +194 -0
- siada_cli-0.0.1.dist-info/LICENSE +201 -0
- siada_cli-0.0.1.dist-info/METADATA +457 -0
- siada_cli-0.0.1.dist-info/RECORD +215 -0
- siada_cli-0.0.1.dist-info/WHEEL +4 -0
- siada_cli-0.0.1.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Dict, ClassVar
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class ColorSettings:
|
|
7
|
+
user_input_color: str = "blue"
|
|
8
|
+
tool_output_color: str = None
|
|
9
|
+
tool_error_color: str = "red"
|
|
10
|
+
tool_warning_color: str = "#FFA500"
|
|
11
|
+
tool_result_color: str = "#00FF00"
|
|
12
|
+
tool_call_color: str = "#FFD700"
|
|
13
|
+
assistant_output_color: str = "blue"
|
|
14
|
+
completion_menu_color: str = None
|
|
15
|
+
completion_menu_bg_color: str = None
|
|
16
|
+
completion_menu_current_color: str = None
|
|
17
|
+
completion_menu_current_bg_color: str = None
|
|
18
|
+
code_theme: str = "default"
|
|
19
|
+
split_line_color: str = "#0000FF"
|
|
20
|
+
shell_model_color: str = "#FF00FF"
|
|
21
|
+
at_file_reference_color: str = "#FF6B6B"
|
|
22
|
+
|
|
23
|
+
# Predefined theme configurations
|
|
24
|
+
THEMES: ClassVar[Dict[str, Dict[str, str]]] = {
|
|
25
|
+
"default": {
|
|
26
|
+
"user_input_color": "blue",
|
|
27
|
+
"tool_output_color": None,
|
|
28
|
+
"tool_error_color": "red",
|
|
29
|
+
"tool_warning_color": "#FFA500",
|
|
30
|
+
"tool_result_color": "#00FF00",
|
|
31
|
+
"tool_call_color": "#FFD700",
|
|
32
|
+
"assistant_output_color": "blue",
|
|
33
|
+
"completion_menu_color": None,
|
|
34
|
+
"completion_menu_bg_color": None,
|
|
35
|
+
"completion_menu_current_color": None,
|
|
36
|
+
"completion_menu_current_bg_color": None,
|
|
37
|
+
"code_theme": "default",
|
|
38
|
+
"split_line_color": "#0000FF",
|
|
39
|
+
"shell_model_color": "#FF00FF",
|
|
40
|
+
"at_file_reference_color": "#FF6B6B"
|
|
41
|
+
},
|
|
42
|
+
"dark": {
|
|
43
|
+
"user_input_color": "#32FF32",
|
|
44
|
+
"tool_output_color": None,
|
|
45
|
+
"tool_error_color": "#FF3333",
|
|
46
|
+
"tool_warning_color": "#FFFF00",
|
|
47
|
+
"tool_result_color": "#00FF7F",
|
|
48
|
+
"tool_call_color": "#FFA500",
|
|
49
|
+
"assistant_output_color": "#00FFFF",
|
|
50
|
+
"completion_menu_color": None,
|
|
51
|
+
"completion_menu_bg_color": None,
|
|
52
|
+
"completion_menu_current_color": None,
|
|
53
|
+
"completion_menu_current_bg_color": None,
|
|
54
|
+
"code_theme": "monokai",
|
|
55
|
+
"split_line_color": "#4169E1",
|
|
56
|
+
"shell_model_color": "#DA70D6",
|
|
57
|
+
"at_file_reference_color": "#FF8A80"
|
|
58
|
+
},
|
|
59
|
+
"light": {
|
|
60
|
+
"user_input_color": "green",
|
|
61
|
+
"tool_output_color": None,
|
|
62
|
+
"tool_error_color": "red",
|
|
63
|
+
"tool_warning_color": "#FFA500",
|
|
64
|
+
"tool_result_color": "#008000",
|
|
65
|
+
"tool_call_color": "#FF8C00",
|
|
66
|
+
"assistant_output_color": "blue",
|
|
67
|
+
"completion_menu_color": None,
|
|
68
|
+
"completion_menu_bg_color": None,
|
|
69
|
+
"completion_menu_current_color": None,
|
|
70
|
+
"completion_menu_current_bg_color": None,
|
|
71
|
+
"code_theme": "default",
|
|
72
|
+
"split_line_color": "#1E90FF",
|
|
73
|
+
"shell_model_color": "#9370DB",
|
|
74
|
+
"at_file_reference_color": "#E91E63"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def from_theme(cls, theme_name: str) -> 'ColorSettings':
|
|
80
|
+
"""Create ColorSettings instance from theme name"""
|
|
81
|
+
if theme_name not in cls.THEMES:
|
|
82
|
+
raise ValueError(f"Unknown theme: {theme_name}. Available themes: {list(cls.THEMES.keys())}")
|
|
83
|
+
|
|
84
|
+
theme_config = cls.THEMES[theme_name]
|
|
85
|
+
return cls(**theme_config)
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def get_available_themes(cls) -> list:
|
|
89
|
+
"""Get list of all available themes"""
|
|
90
|
+
return list(cls.THEMES.keys())
|
|
91
|
+
|
|
92
|
+
def apply_to_args(self, args):
|
|
93
|
+
"""Apply color settings to args object"""
|
|
94
|
+
args.user_input_color = self.user_input_color
|
|
95
|
+
args.tool_output_color = self.tool_output_color
|
|
96
|
+
args.tool_error_color = self.tool_error_color
|
|
97
|
+
args.tool_warning_color = self.tool_warning_color
|
|
98
|
+
args.tool_result_color = self.tool_result_color
|
|
99
|
+
args.tool_call_color = self.tool_call_color
|
|
100
|
+
args.assistant_output_color = self.assistant_output_color
|
|
101
|
+
args.completion_menu_color = self.completion_menu_color
|
|
102
|
+
args.completion_menu_bg_color = self.completion_menu_bg_color
|
|
103
|
+
args.completion_menu_current_color = self.completion_menu_current_color
|
|
104
|
+
args.completion_menu_current_bg_color = self.completion_menu_current_bg_color
|
|
105
|
+
args.code_theme = self.code_theme
|
|
106
|
+
args.split_line_color = self.split_line_color
|
|
107
|
+
args.shell_model_color = self.shell_model_color
|
|
108
|
+
args.at_file_reference_color = self.at_file_reference_color
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class RunningConfigColorSettings:
|
|
112
|
+
"""Runtime color settings with processed color values."""
|
|
113
|
+
|
|
114
|
+
def __init__(self, color_settings=None, pretty=True):
|
|
115
|
+
"""Initialize running color settings.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
color_settings (ColorSettings, optional): Base color settings
|
|
119
|
+
pretty (bool): Whether to apply colors (if False, most colors will be None)
|
|
120
|
+
"""
|
|
121
|
+
from .color_utils import ColorUtils
|
|
122
|
+
|
|
123
|
+
self.color_settings = color_settings or ColorSettings()
|
|
124
|
+
self.user_input_color = (
|
|
125
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.user_input_color) if pretty else None
|
|
126
|
+
)
|
|
127
|
+
self.tool_output_color = (
|
|
128
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.tool_output_color) if pretty else None
|
|
129
|
+
)
|
|
130
|
+
self.tool_error_color = (
|
|
131
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.tool_error_color) if pretty else None
|
|
132
|
+
)
|
|
133
|
+
self.tool_warning_color = (
|
|
134
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.tool_warning_color) if pretty else None
|
|
135
|
+
)
|
|
136
|
+
self.tool_result_color = (
|
|
137
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.tool_result_color) if pretty else None
|
|
138
|
+
)
|
|
139
|
+
self.tool_call_color = (
|
|
140
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.tool_call_color) if pretty else None
|
|
141
|
+
)
|
|
142
|
+
self.assistant_output_color = ColorUtils.ensure_hash_prefix(
|
|
143
|
+
self.color_settings.assistant_output_color
|
|
144
|
+
)
|
|
145
|
+
self.completion_menu_color = (
|
|
146
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.completion_menu_color) if pretty else None
|
|
147
|
+
)
|
|
148
|
+
self.completion_menu_bg_color = (
|
|
149
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.completion_menu_bg_color)
|
|
150
|
+
if pretty
|
|
151
|
+
else None
|
|
152
|
+
)
|
|
153
|
+
self.completion_menu_current_color = (
|
|
154
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.completion_menu_current_color)
|
|
155
|
+
if pretty
|
|
156
|
+
else None
|
|
157
|
+
)
|
|
158
|
+
self.completion_menu_current_bg_color = (
|
|
159
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.completion_menu_current_bg_color)
|
|
160
|
+
if pretty
|
|
161
|
+
else None
|
|
162
|
+
)
|
|
163
|
+
self.split_line_color = (
|
|
164
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.split_line_color) if pretty else None
|
|
165
|
+
)
|
|
166
|
+
self.shell_model_color = (
|
|
167
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.shell_model_color) if pretty else None
|
|
168
|
+
)
|
|
169
|
+
self.at_file_reference_color = (
|
|
170
|
+
ColorUtils.ensure_hash_prefix(self.color_settings.at_file_reference_color) if pretty else None
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
self.code_theme = self.color_settings.code_theme
|
|
174
|
+
|
|
175
|
+
# Validate color settings after initialization
|
|
176
|
+
self._validate_color_settings()
|
|
177
|
+
|
|
178
|
+
def _validate_color_settings(self):
|
|
179
|
+
"""Validate configured color strings and reset invalid ones."""
|
|
180
|
+
from rich.color import ColorParseError
|
|
181
|
+
from rich.style import Style as RichStyle
|
|
182
|
+
|
|
183
|
+
color_attributes = [
|
|
184
|
+
"user_input_color",
|
|
185
|
+
"tool_output_color",
|
|
186
|
+
"tool_error_color",
|
|
187
|
+
"tool_warning_color",
|
|
188
|
+
"assistant_output_color",
|
|
189
|
+
"completion_menu_color",
|
|
190
|
+
"completion_menu_bg_color",
|
|
191
|
+
"completion_menu_current_color",
|
|
192
|
+
"completion_menu_current_bg_color",
|
|
193
|
+
"split_line_color",
|
|
194
|
+
"shell_model_color",
|
|
195
|
+
"at_file_reference_color",
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
for attr_name in color_attributes:
|
|
199
|
+
color_value = getattr(self, attr_name, None)
|
|
200
|
+
if color_value:
|
|
201
|
+
try:
|
|
202
|
+
# Try creating a style to validate the color
|
|
203
|
+
RichStyle(color=color_value)
|
|
204
|
+
except ColorParseError as e:
|
|
205
|
+
# Print warning and reset invalid color to None
|
|
206
|
+
print(f"Warning: Invalid configuration for {attr_name}: '{color_value}'. {e}. Disabling this color.")
|
|
207
|
+
setattr(self, attr_name, None)
|
siada/io/color_utils.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class ColorUtils:
|
|
2
|
+
"""A utility class for color-related operations."""
|
|
3
|
+
|
|
4
|
+
@staticmethod
|
|
5
|
+
def ensure_hash_prefix(color: str) -> str:
|
|
6
|
+
"""Ensure hex color values have a # prefix."""
|
|
7
|
+
if not color:
|
|
8
|
+
return color
|
|
9
|
+
if isinstance(color, str) and color.strip() and not color.startswith("#"):
|
|
10
|
+
# Check if it's a valid hex color (3 or 6 hex digits)
|
|
11
|
+
if all(c in "0123456789ABCDEFabcdef" for c in color) and len(color) in (
|
|
12
|
+
3,
|
|
13
|
+
6,
|
|
14
|
+
):
|
|
15
|
+
return f"#{color}"
|
|
16
|
+
return color
|
|
File without changes
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
from rich import box
|
|
7
|
+
from rich.console import Console
|
|
8
|
+
from rich.live import Live
|
|
9
|
+
from rich.markdown import CodeBlock, Heading, Markdown
|
|
10
|
+
from rich.panel import Panel
|
|
11
|
+
from rich.syntax import Syntax
|
|
12
|
+
from rich.text import Text
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class NoInsetCodeBlock(CodeBlock):
|
|
16
|
+
"""A code block with syntax highlighting and no padding."""
|
|
17
|
+
|
|
18
|
+
def __rich_console__(self, console, options):
|
|
19
|
+
code = str(self.text).rstrip()
|
|
20
|
+
syntax = Syntax(code, self.lexer_name, theme=self.theme, word_wrap=True, padding=(1, 0))
|
|
21
|
+
yield syntax
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class LeftHeading(Heading):
|
|
25
|
+
"""A heading class that renders left-justified."""
|
|
26
|
+
|
|
27
|
+
def __rich_console__(self, console, options):
|
|
28
|
+
text = self.text
|
|
29
|
+
text.justify = "left" # Override justification
|
|
30
|
+
if self.tag == "h1":
|
|
31
|
+
# Draw a border around h1s, but keep text left-aligned
|
|
32
|
+
yield Panel(
|
|
33
|
+
text,
|
|
34
|
+
box=box.HEAVY,
|
|
35
|
+
style="markdown.h1.border",
|
|
36
|
+
)
|
|
37
|
+
else:
|
|
38
|
+
# Styled text for h2 and beyond
|
|
39
|
+
if self.tag == "h2":
|
|
40
|
+
yield Text("") # Keep the blank line before h2
|
|
41
|
+
yield text
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class NoInsetMarkdown(Markdown):
|
|
45
|
+
"""Markdown with code blocks that have no padding and left-justified headings."""
|
|
46
|
+
|
|
47
|
+
elements = {
|
|
48
|
+
**Markdown.elements,
|
|
49
|
+
"fence": NoInsetCodeBlock,
|
|
50
|
+
"code_block": NoInsetCodeBlock,
|
|
51
|
+
"heading_open": LeftHeading,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class MarkdownRender:
|
|
56
|
+
"""Streaming markdown renderer that progressively displays content with a live updating window.
|
|
57
|
+
|
|
58
|
+
Uses rich.console and rich.live to render markdown content with smooth scrolling
|
|
59
|
+
and partial updates. Maintains a sliding window of visible content while streaming
|
|
60
|
+
in new markdown text.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
live = None # Rich Live display instance
|
|
64
|
+
when = 0 # Timestamp of last update
|
|
65
|
+
min_delay = 1.0 / 20 # Minimum time between updates (20fps)
|
|
66
|
+
live_window = 6 # Number of lines to keep visible at bottom during streaming
|
|
67
|
+
|
|
68
|
+
def __init__(self, mdargs=None):
|
|
69
|
+
"""Initialize the markdown stream.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
mdargs (dict, optional): Additional arguments to pass to rich Markdown renderer
|
|
73
|
+
"""
|
|
74
|
+
self.printed = [] # Stores lines that have already been printed
|
|
75
|
+
|
|
76
|
+
if mdargs:
|
|
77
|
+
self.mdargs = mdargs
|
|
78
|
+
else:
|
|
79
|
+
self.mdargs = dict()
|
|
80
|
+
|
|
81
|
+
# Defer Live creation until the first update.
|
|
82
|
+
self.live = None
|
|
83
|
+
self._live_started = False
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
def render_markdown_to_lines(text, mdargs=None):
|
|
87
|
+
"""Render markdown text to a list of lines.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
text (str): Markdown text to render
|
|
91
|
+
mdargs (dict, optional): Additional markdown arguments to override defaults
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
list: List of rendered lines with line endings preserved
|
|
95
|
+
"""
|
|
96
|
+
# Use provided mdargs or fall back to instance mdargs
|
|
97
|
+
final_mdargs = mdargs if mdargs is not None else {}
|
|
98
|
+
|
|
99
|
+
# Render the markdown to a string buffer
|
|
100
|
+
string_io = io.StringIO()
|
|
101
|
+
console = Console(file=string_io, force_terminal=True)
|
|
102
|
+
markdown = NoInsetMarkdown(text, **final_mdargs)
|
|
103
|
+
console.print(markdown)
|
|
104
|
+
output = string_io.getvalue()
|
|
105
|
+
|
|
106
|
+
# Split rendered output into lines
|
|
107
|
+
return output.splitlines(keepends=True)
|
|
108
|
+
|
|
109
|
+
def close(self):
|
|
110
|
+
"""Explicitly close the Live display and clean up resources."""
|
|
111
|
+
if self.live:
|
|
112
|
+
try:
|
|
113
|
+
self.live.stop()
|
|
114
|
+
self.live = None
|
|
115
|
+
except Exception as e:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
def __del__(self):
|
|
119
|
+
"""Destructor to ensure Live display is properly cleaned up."""
|
|
120
|
+
try:
|
|
121
|
+
self.close()
|
|
122
|
+
except Exception:
|
|
123
|
+
pass # Ignore any errors during cleanup
|
|
124
|
+
|
|
125
|
+
def update(self, text, final=False):
|
|
126
|
+
"""Update the displayed markdown content.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
text (str): The markdown text received so far
|
|
130
|
+
final (bool): If True, this is the final update and we should clean up
|
|
131
|
+
|
|
132
|
+
Splits the output into "stable" older lines and the "last few" lines
|
|
133
|
+
which aren't considered stable. They may shift around as new chunks
|
|
134
|
+
are appended to the markdown text.
|
|
135
|
+
|
|
136
|
+
The stable lines emit to the console above the Live window.
|
|
137
|
+
The unstable lines emit into the Live window so they can be repainted.
|
|
138
|
+
|
|
139
|
+
Markdown going to the console works better in terminal scrollback buffers.
|
|
140
|
+
The live window doesn't play nice with terminal scrollback.
|
|
141
|
+
"""
|
|
142
|
+
# On the first call, stop the spinner and start the Live renderer
|
|
143
|
+
if not getattr(self, "_live_started", False):
|
|
144
|
+
self.live = Live(Text(""), refresh_per_second=1.0 / self.min_delay)
|
|
145
|
+
self.live.start()
|
|
146
|
+
self._live_started = True
|
|
147
|
+
|
|
148
|
+
now = time.time()
|
|
149
|
+
# Throttle updates to maintain smooth rendering
|
|
150
|
+
if not final and now - self.when < self.min_delay:
|
|
151
|
+
return
|
|
152
|
+
self.when = now
|
|
153
|
+
|
|
154
|
+
# Measure render time and adjust min_delay to maintain smooth rendering
|
|
155
|
+
start = time.time()
|
|
156
|
+
lines = MarkdownRender.render_markdown_to_lines(text, self.mdargs)
|
|
157
|
+
render_time = time.time() - start
|
|
158
|
+
|
|
159
|
+
# Set min_delay to render time plus a small buffer
|
|
160
|
+
self.min_delay = min(max(render_time * 10, 1.0 / 20), 2)
|
|
161
|
+
|
|
162
|
+
num_lines = len(lines)
|
|
163
|
+
|
|
164
|
+
# How many lines have "left" the live window and are now considered stable?
|
|
165
|
+
# Or if final, consider all lines to be stable.
|
|
166
|
+
if not final:
|
|
167
|
+
num_lines -= self.live_window
|
|
168
|
+
|
|
169
|
+
# If we have stable content to display...
|
|
170
|
+
if final or num_lines > 0:
|
|
171
|
+
# How many stable lines do we need to newly show above the live window?
|
|
172
|
+
num_printed = len(self.printed)
|
|
173
|
+
show = num_lines - num_printed
|
|
174
|
+
|
|
175
|
+
# Skip if no new lines to show above live window
|
|
176
|
+
if show <= 0:
|
|
177
|
+
return
|
|
178
|
+
|
|
179
|
+
# Get the new lines and display them
|
|
180
|
+
show = lines[num_printed:num_lines]
|
|
181
|
+
show = "".join(show)
|
|
182
|
+
show = Text.from_ansi(show)
|
|
183
|
+
self.live.console.print(show) # to the console above the live area
|
|
184
|
+
|
|
185
|
+
# Update our record of printed lines
|
|
186
|
+
self.printed = lines[:num_lines]
|
|
187
|
+
|
|
188
|
+
# Handle final update cleanup
|
|
189
|
+
if final:
|
|
190
|
+
self.live.update(Text(""))
|
|
191
|
+
self.live.stop()
|
|
192
|
+
self.live = None
|
|
193
|
+
return
|
|
194
|
+
|
|
195
|
+
# Update the live window with remaining lines
|
|
196
|
+
rest = lines[num_lines:]
|
|
197
|
+
rest = "".join(rest)
|
|
198
|
+
rest = Text.from_ansi(rest)
|
|
199
|
+
self.live.update(rest)
|
|
200
|
+
|
|
201
|
+
def find_minimal_suffix(self, text, match_lines=50):
|
|
202
|
+
"""
|
|
203
|
+
Splits text into chunks on blank lines "\n\n".
|
|
204
|
+
"""
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.style import Style as RichStyle
|
|
3
|
+
from rich.text import Text
|
|
4
|
+
|
|
5
|
+
from siada.io.color_utils import ColorUtils
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ConsolePrinter:
|
|
9
|
+
"""A utility class for handling styled console output."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, console: Console, pretty: bool = True, colors: dict = None):
|
|
12
|
+
"""
|
|
13
|
+
Initializes the ConsolePrinter.
|
|
14
|
+
:param console: The rich Console object.
|
|
15
|
+
:param pretty: Whether to use pretty output with colors and styles.
|
|
16
|
+
:param colors: A dictionary mapping message types to color strings.
|
|
17
|
+
Expected keys: 'error', 'warning', 'output'.
|
|
18
|
+
"""
|
|
19
|
+
self.console = console
|
|
20
|
+
self.pretty = pretty
|
|
21
|
+
self.colors = colors if colors else {}
|
|
22
|
+
|
|
23
|
+
def print_messages(self, *messages, color_name: str = None, bold: bool = False):
|
|
24
|
+
"""Internal method to print styled messages to the console."""
|
|
25
|
+
color = self.colors.get(color_name)
|
|
26
|
+
|
|
27
|
+
# Convert each message to Text, treating each message as a whole unit
|
|
28
|
+
text_messages = [Text(str(msg)) for msg in messages]
|
|
29
|
+
style_dict = {}
|
|
30
|
+
|
|
31
|
+
if self.pretty:
|
|
32
|
+
if color:
|
|
33
|
+
style_dict["color"] = ColorUtils.ensure_hash_prefix(color)
|
|
34
|
+
if bold:
|
|
35
|
+
style_dict["reverse"] = True
|
|
36
|
+
|
|
37
|
+
style = RichStyle(**style_dict)
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
self.console.print(*text_messages, style=style)
|
|
41
|
+
except UnicodeEncodeError:
|
|
42
|
+
# Fallback to ASCII-safe output
|
|
43
|
+
plain_messages = [m.plain if isinstance(m, Text) else str(m) for m in text_messages]
|
|
44
|
+
safe_messages = [str(m).encode("ascii", errors="replace").decode("ascii") for m in plain_messages]
|
|
45
|
+
self.console.print(*safe_messages, style=style)
|
|
46
|
+
|
|
47
|
+
def error(self, *messages):
|
|
48
|
+
"""Prints error messages."""
|
|
49
|
+
self.print_messages(*messages, color_name='error')
|
|
50
|
+
|
|
51
|
+
def warning(self, *messages):
|
|
52
|
+
"""Prints warning messages."""
|
|
53
|
+
self.print_messages(*messages, color_name='warning')
|
|
54
|
+
|
|
55
|
+
def output(self, *messages, bold: bool = False):
|
|
56
|
+
"""Prints standard tool output."""
|
|
57
|
+
self.print_messages(*messages, color_name='output', bold=bold)
|
|
58
|
+
|
|
59
|
+
def print(self, *args, **kwargs):
|
|
60
|
+
self.console.print(*args, **kwargs)
|
|
61
|
+
|
|
62
|
+
def result(self, *messages):
|
|
63
|
+
"""Prints tool result messages."""
|
|
64
|
+
self.print_messages(*messages, color_name='result')
|
|
65
|
+
|
|
66
|
+
def call(self, *messages):
|
|
67
|
+
"""Prints tool call messages."""
|
|
68
|
+
self.print_messages(*messages, color_name='call')
|