alita-sdk 0.3.257__py3-none-any.whl → 0.3.562__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.
- alita_sdk/cli/__init__.py +10 -0
- alita_sdk/cli/__main__.py +17 -0
- alita_sdk/cli/agent/__init__.py +5 -0
- alita_sdk/cli/agent/default.py +258 -0
- alita_sdk/cli/agent_executor.py +155 -0
- alita_sdk/cli/agent_loader.py +215 -0
- alita_sdk/cli/agent_ui.py +228 -0
- alita_sdk/cli/agents.py +3601 -0
- alita_sdk/cli/callbacks.py +647 -0
- alita_sdk/cli/cli.py +168 -0
- alita_sdk/cli/config.py +306 -0
- alita_sdk/cli/context/__init__.py +30 -0
- alita_sdk/cli/context/cleanup.py +198 -0
- alita_sdk/cli/context/manager.py +731 -0
- alita_sdk/cli/context/message.py +285 -0
- alita_sdk/cli/context/strategies.py +289 -0
- alita_sdk/cli/context/token_estimation.py +127 -0
- alita_sdk/cli/formatting.py +182 -0
- alita_sdk/cli/input_handler.py +419 -0
- alita_sdk/cli/inventory.py +1073 -0
- alita_sdk/cli/mcp_loader.py +315 -0
- alita_sdk/cli/toolkit.py +327 -0
- alita_sdk/cli/toolkit_loader.py +85 -0
- alita_sdk/cli/tools/__init__.py +43 -0
- alita_sdk/cli/tools/approval.py +224 -0
- alita_sdk/cli/tools/filesystem.py +1751 -0
- alita_sdk/cli/tools/planning.py +389 -0
- alita_sdk/cli/tools/terminal.py +414 -0
- alita_sdk/community/__init__.py +72 -12
- alita_sdk/community/inventory/__init__.py +236 -0
- alita_sdk/community/inventory/config.py +257 -0
- alita_sdk/community/inventory/enrichment.py +2137 -0
- alita_sdk/community/inventory/extractors.py +1469 -0
- alita_sdk/community/inventory/ingestion.py +3172 -0
- alita_sdk/community/inventory/knowledge_graph.py +1457 -0
- alita_sdk/community/inventory/parsers/__init__.py +218 -0
- alita_sdk/community/inventory/parsers/base.py +295 -0
- alita_sdk/community/inventory/parsers/csharp_parser.py +907 -0
- alita_sdk/community/inventory/parsers/go_parser.py +851 -0
- alita_sdk/community/inventory/parsers/html_parser.py +389 -0
- alita_sdk/community/inventory/parsers/java_parser.py +593 -0
- alita_sdk/community/inventory/parsers/javascript_parser.py +629 -0
- alita_sdk/community/inventory/parsers/kotlin_parser.py +768 -0
- alita_sdk/community/inventory/parsers/markdown_parser.py +362 -0
- alita_sdk/community/inventory/parsers/python_parser.py +604 -0
- alita_sdk/community/inventory/parsers/rust_parser.py +858 -0
- alita_sdk/community/inventory/parsers/swift_parser.py +832 -0
- alita_sdk/community/inventory/parsers/text_parser.py +322 -0
- alita_sdk/community/inventory/parsers/yaml_parser.py +370 -0
- alita_sdk/community/inventory/patterns/__init__.py +61 -0
- alita_sdk/community/inventory/patterns/ast_adapter.py +380 -0
- alita_sdk/community/inventory/patterns/loader.py +348 -0
- alita_sdk/community/inventory/patterns/registry.py +198 -0
- alita_sdk/community/inventory/presets.py +535 -0
- alita_sdk/community/inventory/retrieval.py +1403 -0
- alita_sdk/community/inventory/toolkit.py +173 -0
- alita_sdk/community/inventory/toolkit_utils.py +176 -0
- alita_sdk/community/inventory/visualize.py +1370 -0
- alita_sdk/configurations/__init__.py +11 -0
- alita_sdk/configurations/ado.py +148 -2
- alita_sdk/configurations/azure_search.py +1 -1
- alita_sdk/configurations/bigquery.py +1 -1
- alita_sdk/configurations/bitbucket.py +94 -2
- alita_sdk/configurations/browser.py +18 -0
- alita_sdk/configurations/carrier.py +19 -0
- alita_sdk/configurations/confluence.py +130 -1
- alita_sdk/configurations/delta_lake.py +1 -1
- alita_sdk/configurations/figma.py +76 -5
- alita_sdk/configurations/github.py +65 -1
- alita_sdk/configurations/gitlab.py +81 -0
- alita_sdk/configurations/google_places.py +17 -0
- alita_sdk/configurations/jira.py +103 -0
- alita_sdk/configurations/openapi.py +111 -0
- alita_sdk/configurations/postman.py +1 -1
- alita_sdk/configurations/qtest.py +72 -3
- alita_sdk/configurations/report_portal.py +115 -0
- alita_sdk/configurations/salesforce.py +19 -0
- alita_sdk/configurations/service_now.py +1 -12
- alita_sdk/configurations/sharepoint.py +167 -0
- alita_sdk/configurations/sonar.py +18 -0
- alita_sdk/configurations/sql.py +20 -0
- alita_sdk/configurations/testio.py +101 -0
- alita_sdk/configurations/testrail.py +88 -0
- alita_sdk/configurations/xray.py +94 -1
- alita_sdk/configurations/zephyr_enterprise.py +94 -1
- alita_sdk/configurations/zephyr_essential.py +95 -0
- alita_sdk/runtime/clients/artifact.py +21 -4
- alita_sdk/runtime/clients/client.py +458 -67
- alita_sdk/runtime/clients/mcp_discovery.py +342 -0
- alita_sdk/runtime/clients/mcp_manager.py +262 -0
- alita_sdk/runtime/clients/sandbox_client.py +352 -0
- alita_sdk/runtime/langchain/_constants_bkup.py +1318 -0
- alita_sdk/runtime/langchain/assistant.py +183 -43
- alita_sdk/runtime/langchain/constants.py +647 -1
- alita_sdk/runtime/langchain/document_loaders/AlitaDocxMammothLoader.py +315 -3
- alita_sdk/runtime/langchain/document_loaders/AlitaExcelLoader.py +209 -31
- alita_sdk/runtime/langchain/document_loaders/AlitaImageLoader.py +1 -1
- alita_sdk/runtime/langchain/document_loaders/AlitaJSONLinesLoader.py +77 -0
- alita_sdk/runtime/langchain/document_loaders/AlitaJSONLoader.py +10 -3
- alita_sdk/runtime/langchain/document_loaders/AlitaMarkdownLoader.py +66 -0
- alita_sdk/runtime/langchain/document_loaders/AlitaPDFLoader.py +79 -10
- alita_sdk/runtime/langchain/document_loaders/AlitaPowerPointLoader.py +52 -15
- alita_sdk/runtime/langchain/document_loaders/AlitaPythonLoader.py +9 -0
- alita_sdk/runtime/langchain/document_loaders/AlitaTableLoader.py +1 -4
- alita_sdk/runtime/langchain/document_loaders/AlitaTextLoader.py +15 -2
- alita_sdk/runtime/langchain/document_loaders/ImageParser.py +30 -0
- alita_sdk/runtime/langchain/document_loaders/constants.py +189 -41
- alita_sdk/runtime/langchain/interfaces/llm_processor.py +4 -2
- alita_sdk/runtime/langchain/langraph_agent.py +407 -92
- alita_sdk/runtime/langchain/utils.py +102 -8
- alita_sdk/runtime/llms/preloaded.py +2 -6
- alita_sdk/runtime/models/mcp_models.py +61 -0
- alita_sdk/runtime/skills/__init__.py +91 -0
- alita_sdk/runtime/skills/callbacks.py +498 -0
- alita_sdk/runtime/skills/discovery.py +540 -0
- alita_sdk/runtime/skills/executor.py +610 -0
- alita_sdk/runtime/skills/input_builder.py +371 -0
- alita_sdk/runtime/skills/models.py +330 -0
- alita_sdk/runtime/skills/registry.py +355 -0
- alita_sdk/runtime/skills/skill_runner.py +330 -0
- alita_sdk/runtime/toolkits/__init__.py +28 -0
- alita_sdk/runtime/toolkits/application.py +14 -4
- alita_sdk/runtime/toolkits/artifact.py +24 -9
- alita_sdk/runtime/toolkits/datasource.py +13 -6
- alita_sdk/runtime/toolkits/mcp.py +780 -0
- alita_sdk/runtime/toolkits/planning.py +178 -0
- alita_sdk/runtime/toolkits/skill_router.py +238 -0
- alita_sdk/runtime/toolkits/subgraph.py +11 -6
- alita_sdk/runtime/toolkits/tools.py +314 -70
- alita_sdk/runtime/toolkits/vectorstore.py +11 -5
- alita_sdk/runtime/tools/__init__.py +24 -0
- alita_sdk/runtime/tools/application.py +16 -4
- alita_sdk/runtime/tools/artifact.py +367 -33
- alita_sdk/runtime/tools/data_analysis.py +183 -0
- alita_sdk/runtime/tools/function.py +100 -4
- alita_sdk/runtime/tools/graph.py +81 -0
- alita_sdk/runtime/tools/image_generation.py +218 -0
- alita_sdk/runtime/tools/llm.py +1013 -177
- alita_sdk/runtime/tools/loop.py +3 -1
- alita_sdk/runtime/tools/loop_output.py +3 -1
- alita_sdk/runtime/tools/mcp_inspect_tool.py +284 -0
- alita_sdk/runtime/tools/mcp_remote_tool.py +181 -0
- alita_sdk/runtime/tools/mcp_server_tool.py +3 -1
- alita_sdk/runtime/tools/planning/__init__.py +36 -0
- alita_sdk/runtime/tools/planning/models.py +246 -0
- alita_sdk/runtime/tools/planning/wrapper.py +607 -0
- alita_sdk/runtime/tools/router.py +2 -1
- alita_sdk/runtime/tools/sandbox.py +375 -0
- alita_sdk/runtime/tools/skill_router.py +776 -0
- alita_sdk/runtime/tools/tool.py +3 -1
- alita_sdk/runtime/tools/vectorstore.py +69 -65
- alita_sdk/runtime/tools/vectorstore_base.py +163 -90
- alita_sdk/runtime/utils/AlitaCallback.py +137 -21
- alita_sdk/runtime/utils/mcp_client.py +492 -0
- alita_sdk/runtime/utils/mcp_oauth.py +361 -0
- alita_sdk/runtime/utils/mcp_sse_client.py +434 -0
- alita_sdk/runtime/utils/mcp_tools_discovery.py +124 -0
- alita_sdk/runtime/utils/streamlit.py +41 -14
- alita_sdk/runtime/utils/toolkit_utils.py +28 -9
- alita_sdk/runtime/utils/utils.py +48 -0
- alita_sdk/tools/__init__.py +135 -37
- alita_sdk/tools/ado/__init__.py +2 -2
- alita_sdk/tools/ado/repos/__init__.py +15 -19
- alita_sdk/tools/ado/repos/repos_wrapper.py +12 -20
- alita_sdk/tools/ado/test_plan/__init__.py +26 -8
- alita_sdk/tools/ado/test_plan/test_plan_wrapper.py +56 -28
- alita_sdk/tools/ado/wiki/__init__.py +27 -12
- alita_sdk/tools/ado/wiki/ado_wrapper.py +114 -40
- alita_sdk/tools/ado/work_item/__init__.py +27 -12
- alita_sdk/tools/ado/work_item/ado_wrapper.py +95 -11
- alita_sdk/tools/advanced_jira_mining/__init__.py +12 -8
- alita_sdk/tools/aws/delta_lake/__init__.py +14 -11
- alita_sdk/tools/aws/delta_lake/tool.py +5 -1
- alita_sdk/tools/azure_ai/search/__init__.py +13 -8
- alita_sdk/tools/base/tool.py +5 -1
- alita_sdk/tools/base_indexer_toolkit.py +454 -110
- alita_sdk/tools/bitbucket/__init__.py +27 -19
- alita_sdk/tools/bitbucket/api_wrapper.py +285 -27
- alita_sdk/tools/bitbucket/cloud_api_wrapper.py +5 -5
- alita_sdk/tools/browser/__init__.py +41 -16
- alita_sdk/tools/browser/crawler.py +3 -1
- alita_sdk/tools/browser/utils.py +15 -6
- alita_sdk/tools/carrier/__init__.py +18 -17
- alita_sdk/tools/carrier/backend_reports_tool.py +8 -4
- alita_sdk/tools/carrier/excel_reporter.py +8 -4
- alita_sdk/tools/chunkers/__init__.py +3 -1
- alita_sdk/tools/chunkers/code/codeparser.py +1 -1
- alita_sdk/tools/chunkers/sematic/json_chunker.py +2 -1
- alita_sdk/tools/chunkers/sematic/markdown_chunker.py +97 -6
- alita_sdk/tools/chunkers/sematic/proposal_chunker.py +1 -1
- alita_sdk/tools/chunkers/universal_chunker.py +270 -0
- alita_sdk/tools/cloud/aws/__init__.py +11 -7
- alita_sdk/tools/cloud/azure/__init__.py +11 -7
- alita_sdk/tools/cloud/gcp/__init__.py +11 -7
- alita_sdk/tools/cloud/k8s/__init__.py +11 -7
- alita_sdk/tools/code/linter/__init__.py +9 -8
- alita_sdk/tools/code/loaders/codesearcher.py +3 -2
- alita_sdk/tools/code/sonar/__init__.py +20 -13
- alita_sdk/tools/code_indexer_toolkit.py +199 -0
- alita_sdk/tools/confluence/__init__.py +21 -14
- alita_sdk/tools/confluence/api_wrapper.py +197 -58
- alita_sdk/tools/confluence/loader.py +14 -2
- alita_sdk/tools/custom_open_api/__init__.py +11 -5
- alita_sdk/tools/elastic/__init__.py +10 -8
- alita_sdk/tools/elitea_base.py +546 -64
- alita_sdk/tools/figma/__init__.py +11 -8
- alita_sdk/tools/figma/api_wrapper.py +352 -153
- alita_sdk/tools/github/__init__.py +17 -17
- alita_sdk/tools/github/api_wrapper.py +9 -26
- alita_sdk/tools/github/github_client.py +81 -12
- alita_sdk/tools/github/schemas.py +2 -1
- alita_sdk/tools/github/tool.py +5 -1
- alita_sdk/tools/gitlab/__init__.py +18 -13
- alita_sdk/tools/gitlab/api_wrapper.py +224 -80
- alita_sdk/tools/gitlab_org/__init__.py +13 -10
- alita_sdk/tools/google/bigquery/__init__.py +13 -13
- alita_sdk/tools/google/bigquery/tool.py +5 -1
- alita_sdk/tools/google_places/__init__.py +20 -11
- alita_sdk/tools/jira/__init__.py +21 -11
- alita_sdk/tools/jira/api_wrapper.py +315 -168
- alita_sdk/tools/keycloak/__init__.py +10 -8
- alita_sdk/tools/localgit/__init__.py +8 -3
- alita_sdk/tools/localgit/local_git.py +62 -54
- alita_sdk/tools/localgit/tool.py +5 -1
- alita_sdk/tools/memory/__init__.py +38 -14
- alita_sdk/tools/non_code_indexer_toolkit.py +7 -2
- alita_sdk/tools/ocr/__init__.py +10 -8
- alita_sdk/tools/openapi/__init__.py +281 -108
- alita_sdk/tools/openapi/api_wrapper.py +883 -0
- alita_sdk/tools/openapi/tool.py +20 -0
- alita_sdk/tools/pandas/__init__.py +18 -11
- alita_sdk/tools/pandas/api_wrapper.py +40 -45
- alita_sdk/tools/pandas/dataframe/generator/base.py +3 -1
- alita_sdk/tools/postman/__init__.py +10 -11
- alita_sdk/tools/postman/api_wrapper.py +19 -8
- alita_sdk/tools/postman/postman_analysis.py +8 -1
- alita_sdk/tools/pptx/__init__.py +10 -10
- alita_sdk/tools/qtest/__init__.py +21 -14
- alita_sdk/tools/qtest/api_wrapper.py +1784 -88
- alita_sdk/tools/rally/__init__.py +12 -10
- alita_sdk/tools/report_portal/__init__.py +22 -16
- alita_sdk/tools/salesforce/__init__.py +21 -16
- alita_sdk/tools/servicenow/__init__.py +20 -16
- alita_sdk/tools/servicenow/api_wrapper.py +1 -1
- alita_sdk/tools/sharepoint/__init__.py +16 -14
- alita_sdk/tools/sharepoint/api_wrapper.py +179 -39
- alita_sdk/tools/sharepoint/authorization_helper.py +191 -1
- alita_sdk/tools/sharepoint/utils.py +8 -2
- alita_sdk/tools/slack/__init__.py +11 -7
- alita_sdk/tools/sql/__init__.py +21 -19
- alita_sdk/tools/sql/api_wrapper.py +71 -23
- alita_sdk/tools/testio/__init__.py +20 -13
- alita_sdk/tools/testrail/__init__.py +12 -11
- alita_sdk/tools/testrail/api_wrapper.py +214 -46
- alita_sdk/tools/utils/__init__.py +28 -4
- alita_sdk/tools/utils/content_parser.py +182 -62
- alita_sdk/tools/utils/text_operations.py +254 -0
- alita_sdk/tools/vector_adapters/VectorStoreAdapter.py +83 -27
- alita_sdk/tools/xray/__init__.py +17 -14
- alita_sdk/tools/xray/api_wrapper.py +58 -113
- alita_sdk/tools/yagmail/__init__.py +8 -3
- alita_sdk/tools/zephyr/__init__.py +11 -7
- alita_sdk/tools/zephyr_enterprise/__init__.py +15 -9
- alita_sdk/tools/zephyr_enterprise/api_wrapper.py +30 -15
- alita_sdk/tools/zephyr_essential/__init__.py +15 -10
- alita_sdk/tools/zephyr_essential/api_wrapper.py +297 -54
- alita_sdk/tools/zephyr_essential/client.py +6 -4
- alita_sdk/tools/zephyr_scale/__init__.py +12 -8
- alita_sdk/tools/zephyr_scale/api_wrapper.py +39 -31
- alita_sdk/tools/zephyr_squad/__init__.py +11 -7
- {alita_sdk-0.3.257.dist-info → alita_sdk-0.3.562.dist-info}/METADATA +184 -37
- alita_sdk-0.3.562.dist-info/RECORD +450 -0
- alita_sdk-0.3.562.dist-info/entry_points.txt +2 -0
- alita_sdk/tools/bitbucket/tools.py +0 -304
- alita_sdk-0.3.257.dist-info/RECORD +0 -343
- {alita_sdk-0.3.257.dist-info → alita_sdk-0.3.562.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.257.dist-info → alita_sdk-0.3.562.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.257.dist-info → alita_sdk-0.3.562.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Toolkit configuration loading and management.
|
|
3
|
+
|
|
4
|
+
Handles loading toolkit configurations from JSON/YAML files.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import yaml
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Dict, Any, List
|
|
11
|
+
|
|
12
|
+
from .config import substitute_env_vars
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# All available tools in the inventory toolkit
|
|
16
|
+
INVENTORY_TOOLS = [
|
|
17
|
+
"search_graph",
|
|
18
|
+
"get_entity",
|
|
19
|
+
"get_entity_content",
|
|
20
|
+
"impact_analysis",
|
|
21
|
+
"get_related_entities",
|
|
22
|
+
"get_stats",
|
|
23
|
+
"get_citations",
|
|
24
|
+
"list_entities_by_type",
|
|
25
|
+
"list_entities_by_layer",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def load_toolkit_config(file_path: str) -> Dict[str, Any]:
|
|
30
|
+
"""Load toolkit configuration from JSON or YAML file with env var substitution."""
|
|
31
|
+
path = Path(file_path)
|
|
32
|
+
|
|
33
|
+
if not path.exists():
|
|
34
|
+
raise FileNotFoundError(f"Toolkit configuration not found: {file_path}")
|
|
35
|
+
|
|
36
|
+
with open(path) as f:
|
|
37
|
+
content = f.read()
|
|
38
|
+
|
|
39
|
+
# Apply environment variable substitution
|
|
40
|
+
content = substitute_env_vars(content)
|
|
41
|
+
|
|
42
|
+
# Parse based on file extension
|
|
43
|
+
if path.suffix in ['.yaml', '.yml']:
|
|
44
|
+
return yaml.safe_load(content)
|
|
45
|
+
else:
|
|
46
|
+
return json.loads(content)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def load_toolkit_configs(agent_def: Dict[str, Any], toolkit_config_paths: tuple) -> List[Dict[str, Any]]:
|
|
50
|
+
"""Load all toolkit configurations from agent definition and CLI options.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
agent_def: Agent definition dictionary
|
|
54
|
+
toolkit_config_paths: Tuple of file paths or dict configs from CLI options
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
List of toolkit configuration dictionaries
|
|
58
|
+
"""
|
|
59
|
+
toolkit_configs = []
|
|
60
|
+
|
|
61
|
+
# Load from agent definition if present
|
|
62
|
+
if 'toolkit_configs' in agent_def:
|
|
63
|
+
for tk_config in agent_def['toolkit_configs']:
|
|
64
|
+
if isinstance(tk_config, dict):
|
|
65
|
+
if 'file' in tk_config:
|
|
66
|
+
config = load_toolkit_config(tk_config['file'])
|
|
67
|
+
toolkit_configs.append(config)
|
|
68
|
+
elif 'config' in tk_config:
|
|
69
|
+
toolkit_configs.append(tk_config['config'])
|
|
70
|
+
elif 'type' in tk_config:
|
|
71
|
+
# Direct toolkit config (e.g., {'type': 'inventory', ...})
|
|
72
|
+
toolkit_configs.append(tk_config)
|
|
73
|
+
|
|
74
|
+
# Load from CLI options - can be file paths (str) or dict configs
|
|
75
|
+
if toolkit_config_paths:
|
|
76
|
+
for config_item in toolkit_config_paths:
|
|
77
|
+
if isinstance(config_item, dict):
|
|
78
|
+
# Direct config dict (e.g., from /inventory command)
|
|
79
|
+
toolkit_configs.append(config_item)
|
|
80
|
+
elif isinstance(config_item, str):
|
|
81
|
+
# File path
|
|
82
|
+
config = load_toolkit_config(config_item)
|
|
83
|
+
toolkit_configs.append(config)
|
|
84
|
+
|
|
85
|
+
return toolkit_configs
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI tools package.
|
|
3
|
+
|
|
4
|
+
Contains specialized tools for CLI agents.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .filesystem import get_filesystem_tools, FilesystemApiWrapper
|
|
8
|
+
from .terminal import get_terminal_tools, create_default_blocked_patterns_file
|
|
9
|
+
from .planning import (
|
|
10
|
+
get_planning_tools,
|
|
11
|
+
PlanState,
|
|
12
|
+
list_sessions,
|
|
13
|
+
generate_session_id,
|
|
14
|
+
create_session_memory,
|
|
15
|
+
save_session_metadata,
|
|
16
|
+
load_session_metadata,
|
|
17
|
+
update_session_metadata,
|
|
18
|
+
get_session_dir,
|
|
19
|
+
to_portable_path,
|
|
20
|
+
from_portable_path,
|
|
21
|
+
)
|
|
22
|
+
from .approval import create_approval_wrapper, ApprovalToolWrapper, prompt_approval
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
'get_filesystem_tools',
|
|
26
|
+
'FilesystemApiWrapper',
|
|
27
|
+
'get_terminal_tools',
|
|
28
|
+
'create_default_blocked_patterns_file',
|
|
29
|
+
'get_planning_tools',
|
|
30
|
+
'PlanState',
|
|
31
|
+
'list_sessions',
|
|
32
|
+
'generate_session_id',
|
|
33
|
+
'create_session_memory',
|
|
34
|
+
'save_session_metadata',
|
|
35
|
+
'load_session_metadata',
|
|
36
|
+
'update_session_metadata',
|
|
37
|
+
'get_session_dir',
|
|
38
|
+
'to_portable_path',
|
|
39
|
+
'from_portable_path',
|
|
40
|
+
'create_approval_wrapper',
|
|
41
|
+
'ApprovalToolWrapper',
|
|
42
|
+
'prompt_approval',
|
|
43
|
+
]
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tool approval wrapper for CLI.
|
|
3
|
+
|
|
4
|
+
Wraps tools to require user approval before execution based on approval mode.
|
|
5
|
+
Modes:
|
|
6
|
+
- 'always': Always require approval for each tool call
|
|
7
|
+
- 'auto': No approval required (automatic execution)
|
|
8
|
+
- 'yolo': No approval and no safety checks (use with caution)
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import functools
|
|
12
|
+
from typing import Any, Callable, Dict, List, Optional, Set
|
|
13
|
+
from rich.console import Console
|
|
14
|
+
from rich.panel import Panel
|
|
15
|
+
from rich.table import Table
|
|
16
|
+
from rich import box
|
|
17
|
+
from rich.text import Text
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from langchain_core.tools import BaseTool, StructuredTool, Tool
|
|
21
|
+
|
|
22
|
+
console = Console()
|
|
23
|
+
|
|
24
|
+
# Tools that always require approval in 'always' mode (dangerous built-in operations)
|
|
25
|
+
# These are the built-in CLI tools that modify the filesystem or execute commands
|
|
26
|
+
DANGEROUS_TOOLS = {
|
|
27
|
+
'terminal_run_command', # Shell command execution
|
|
28
|
+
'write_file',
|
|
29
|
+
'create_file',
|
|
30
|
+
'delete_file',
|
|
31
|
+
'move_file',
|
|
32
|
+
'copy_file',
|
|
33
|
+
'create_directory',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# Note: Tools NOT in DANGEROUS_TOOLS are auto-approved, including:
|
|
37
|
+
# - Read-only filesystem tools (read_file, list_directory, etc.)
|
|
38
|
+
# - User-added toolkit tools (via --toolkit_config or /add_toolkit)
|
|
39
|
+
# - MCP server tools (via --mcp or /add_mcp)
|
|
40
|
+
#
|
|
41
|
+
# The assumption is that users explicitly add toolkits they trust.
|
|
42
|
+
# Only built-in tools that can modify files or run commands require approval.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def prompt_approval(tool_name: str, tool_args: Dict[str, Any], approval_mode: str) -> bool:
|
|
46
|
+
"""
|
|
47
|
+
Prompt user for approval before executing a tool.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
tool_name: Name of the tool to execute
|
|
51
|
+
tool_args: Arguments to pass to the tool
|
|
52
|
+
approval_mode: Current approval mode ('always', 'auto', 'yolo')
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
True if approved, False if rejected
|
|
56
|
+
"""
|
|
57
|
+
# Auto mode - always approve
|
|
58
|
+
if approval_mode == 'auto':
|
|
59
|
+
return True
|
|
60
|
+
|
|
61
|
+
# Yolo mode - always approve, no questions asked
|
|
62
|
+
if approval_mode == 'yolo':
|
|
63
|
+
return True
|
|
64
|
+
|
|
65
|
+
# Always mode - only prompt for dangerous built-in tools
|
|
66
|
+
# User-added toolkits and MCP tools are auto-approved (user explicitly added them)
|
|
67
|
+
if tool_name not in DANGEROUS_TOOLS:
|
|
68
|
+
return True
|
|
69
|
+
|
|
70
|
+
# Create approval prompt panel for dangerous tools
|
|
71
|
+
console.print()
|
|
72
|
+
|
|
73
|
+
# Build args display
|
|
74
|
+
args_content = []
|
|
75
|
+
for key, value in tool_args.items():
|
|
76
|
+
if isinstance(value, str) and len(value) > 100:
|
|
77
|
+
display_value = value[:100] + "..."
|
|
78
|
+
elif isinstance(value, (dict, list)):
|
|
79
|
+
try:
|
|
80
|
+
formatted = json.dumps(value, indent=2)
|
|
81
|
+
if len(formatted) > 200:
|
|
82
|
+
formatted = formatted[:200] + "..."
|
|
83
|
+
display_value = formatted
|
|
84
|
+
except:
|
|
85
|
+
display_value = str(value)[:100]
|
|
86
|
+
else:
|
|
87
|
+
display_value = str(value)
|
|
88
|
+
args_content.append(f" [cyan]{key}[/cyan]: {display_value}")
|
|
89
|
+
|
|
90
|
+
args_text = "\n".join(args_content) if args_content else " (no arguments)"
|
|
91
|
+
|
|
92
|
+
# All tools reaching here are dangerous (in DANGEROUS_TOOLS)
|
|
93
|
+
icon = "⚠️"
|
|
94
|
+
border_style = "yellow"
|
|
95
|
+
title_style = "bold yellow"
|
|
96
|
+
|
|
97
|
+
panel = Panel(
|
|
98
|
+
Text.from_markup(f"[bold]{tool_name}[/bold]\n\n[dim]Arguments:[/dim]\n{args_text}"),
|
|
99
|
+
title=f"[{title_style}]{icon} Approve Tool Call?[/{title_style}]",
|
|
100
|
+
title_align="left",
|
|
101
|
+
subtitle="[dim][y]es / [n]o / [a]uto-approve / [q]uit[/dim]",
|
|
102
|
+
subtitle_align="right",
|
|
103
|
+
border_style=border_style,
|
|
104
|
+
box=box.ROUNDED,
|
|
105
|
+
padding=(1, 2),
|
|
106
|
+
)
|
|
107
|
+
console.print(panel)
|
|
108
|
+
|
|
109
|
+
# Get user input
|
|
110
|
+
while True:
|
|
111
|
+
try:
|
|
112
|
+
response = input("→ ").strip().lower()
|
|
113
|
+
except (KeyboardInterrupt, EOFError):
|
|
114
|
+
console.print("\n[yellow]Cancelled[/yellow]")
|
|
115
|
+
return False
|
|
116
|
+
|
|
117
|
+
if response in ('y', 'yes', ''):
|
|
118
|
+
console.print("[green]✓ Approved[/green]")
|
|
119
|
+
return True
|
|
120
|
+
elif response in ('n', 'no'):
|
|
121
|
+
console.print("[red]✗ Rejected[/red]")
|
|
122
|
+
return False
|
|
123
|
+
elif response in ('a', 'auto'):
|
|
124
|
+
console.print("[cyan]→ Switching to auto mode for this session[/cyan]")
|
|
125
|
+
# Signal to switch to auto mode
|
|
126
|
+
return 'switch_auto'
|
|
127
|
+
elif response in ('q', 'quit'):
|
|
128
|
+
console.print("[yellow]Quitting...[/yellow]")
|
|
129
|
+
raise KeyboardInterrupt()
|
|
130
|
+
else:
|
|
131
|
+
console.print("[dim]Please enter y/n/a/q[/dim]")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class ApprovalToolWrapper:
|
|
135
|
+
"""
|
|
136
|
+
Wrapper that adds approval prompts to tools based on approval mode.
|
|
137
|
+
|
|
138
|
+
This wrapper intercepts tool calls and prompts for user approval
|
|
139
|
+
before executing dangerous operations.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
def __init__(self, approval_mode_ref: List[str]):
|
|
143
|
+
"""
|
|
144
|
+
Initialize the approval wrapper.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
approval_mode_ref: A mutable list containing the current approval mode.
|
|
148
|
+
Using a list allows the mode to be changed externally.
|
|
149
|
+
access as approval_mode_ref[0]
|
|
150
|
+
"""
|
|
151
|
+
self.approval_mode_ref = approval_mode_ref
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def approval_mode(self) -> str:
|
|
155
|
+
"""Get current approval mode."""
|
|
156
|
+
return self.approval_mode_ref[0] if self.approval_mode_ref else 'always'
|
|
157
|
+
|
|
158
|
+
def wrap_tool(self, tool: BaseTool) -> BaseTool:
|
|
159
|
+
"""
|
|
160
|
+
Wrap a tool to add approval prompts.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
tool: The tool to wrap
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
Wrapped tool with approval logic
|
|
167
|
+
"""
|
|
168
|
+
original_func = tool.func if hasattr(tool, 'func') else tool._run
|
|
169
|
+
tool_name = tool.name
|
|
170
|
+
wrapper_self = self
|
|
171
|
+
|
|
172
|
+
@functools.wraps(original_func)
|
|
173
|
+
def wrapped_func(*args, **kwargs):
|
|
174
|
+
# Get approval
|
|
175
|
+
approval = prompt_approval(tool_name, kwargs, wrapper_self.approval_mode)
|
|
176
|
+
|
|
177
|
+
if approval == 'switch_auto':
|
|
178
|
+
# Switch to auto mode
|
|
179
|
+
wrapper_self.approval_mode_ref[0] = 'auto'
|
|
180
|
+
console.print("[cyan]Mode switched to 'auto' - tools will auto-approve[/cyan]")
|
|
181
|
+
elif not approval:
|
|
182
|
+
return f"Tool execution rejected by user"
|
|
183
|
+
|
|
184
|
+
# Execute the tool
|
|
185
|
+
return original_func(*args, **kwargs)
|
|
186
|
+
|
|
187
|
+
# Create new tool with wrapped function
|
|
188
|
+
if isinstance(tool, StructuredTool):
|
|
189
|
+
return StructuredTool(
|
|
190
|
+
name=tool.name,
|
|
191
|
+
description=tool.description,
|
|
192
|
+
func=wrapped_func,
|
|
193
|
+
args_schema=tool.args_schema,
|
|
194
|
+
return_direct=tool.return_direct,
|
|
195
|
+
)
|
|
196
|
+
else:
|
|
197
|
+
# Clone the tool with wrapped function
|
|
198
|
+
tool.func = wrapped_func
|
|
199
|
+
return tool
|
|
200
|
+
|
|
201
|
+
def wrap_tools(self, tools: List[BaseTool]) -> List[BaseTool]:
|
|
202
|
+
"""
|
|
203
|
+
Wrap multiple tools with approval logic.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
tools: List of tools to wrap
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
List of wrapped tools
|
|
210
|
+
"""
|
|
211
|
+
return [self.wrap_tool(tool) for tool in tools]
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def create_approval_wrapper(approval_mode_ref: List[str]) -> ApprovalToolWrapper:
|
|
215
|
+
"""
|
|
216
|
+
Create an approval wrapper with a reference to the current mode.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
approval_mode_ref: Mutable list containing current approval mode [0]
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
ApprovalToolWrapper instance
|
|
223
|
+
"""
|
|
224
|
+
return ApprovalToolWrapper(approval_mode_ref)
|