janito 2.3.0__py3-none-any.whl → 2.4.0__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.
- janito/__init__.py +6 -6
- janito/_version.py +57 -0
- janito/agent/setup_agent.py +92 -18
- janito/agent/templates/profiles/system_prompt_template_developer.txt.j2 +44 -0
- janito/cli/chat_mode/bindings.py +21 -2
- janito/cli/chat_mode/chat_entry.py +2 -3
- janito/cli/chat_mode/prompt_style.py +5 -0
- janito/cli/chat_mode/session.py +80 -94
- janito/cli/chat_mode/session_profile_select.py +80 -0
- janito/cli/chat_mode/shell/autocomplete.py +21 -21
- janito/cli/chat_mode/shell/commands/__init__.py +13 -7
- janito/cli/chat_mode/shell/commands/_priv_check.py +5 -0
- janito/cli/chat_mode/shell/commands/clear.py +12 -12
- janito/cli/chat_mode/shell/commands/conversation_restart.py +30 -0
- janito/cli/chat_mode/shell/commands/execute.py +42 -0
- janito/cli/chat_mode/shell/commands/help.py +6 -3
- janito/cli/chat_mode/shell/commands/model.py +28 -0
- janito/cli/chat_mode/shell/commands/multi.py +51 -51
- janito/cli/chat_mode/shell/commands/read.py +37 -0
- janito/cli/chat_mode/shell/commands/tools.py +45 -18
- janito/cli/chat_mode/shell/commands/write.py +37 -0
- janito/cli/chat_mode/shell/commands.bak.zip +0 -0
- janito/cli/chat_mode/shell/input_history.py +62 -62
- janito/cli/chat_mode/shell/session.bak.zip +0 -0
- janito/cli/chat_mode/toolbar.py +44 -27
- janito/cli/cli_commands/list_models.py +35 -35
- janito/cli/cli_commands/list_providers.py +9 -9
- janito/cli/cli_commands/list_tools.py +86 -53
- janito/cli/cli_commands/model_selection.py +50 -50
- janito/cli/cli_commands/set_api_key.py +19 -19
- janito/cli/cli_commands/show_config.py +51 -51
- janito/cli/cli_commands/show_system_prompt.py +105 -62
- janito/cli/config.py +5 -6
- janito/cli/core/__init__.py +4 -4
- janito/cli/core/event_logger.py +59 -59
- janito/cli/core/runner.py +25 -18
- janito/cli/core/setters.py +10 -1
- janito/cli/core/unsetters.py +54 -54
- janito/cli/main_cli.py +28 -5
- janito/cli/prompt_core.py +18 -2
- janito/cli/prompt_setup.py +56 -0
- janito/cli/single_shot_mode/__init__.py +6 -6
- janito/cli/single_shot_mode/handler.py +14 -73
- janito/cli/verbose_output.py +1 -1
- janito/config.py +5 -5
- janito/config_manager.py +13 -0
- janito/drivers/anthropic/driver.py +113 -113
- janito/drivers/dashscope.bak.zip +0 -0
- janito/drivers/openai/README.md +20 -0
- janito/drivers/openai_responses.bak.zip +0 -0
- janito/event_bus/event.py +2 -2
- janito/formatting_token.py +54 -54
- janito/i18n/__init__.py +35 -35
- janito/i18n/messages.py +23 -23
- janito/i18n/pt.py +46 -47
- janito/llm/README.md +23 -0
- janito/llm/__init__.py +5 -5
- janito/llm/agent.py +507 -443
- janito/llm/driver.py +8 -0
- janito/llm/driver_config_builder.py +34 -34
- janito/llm/driver_input.py +12 -12
- janito/llm/message_parts.py +60 -60
- janito/llm/model.py +38 -38
- janito/llm/provider.py +196 -196
- janito/provider_registry.py +8 -6
- janito/providers/anthropic/model_info.py +22 -22
- janito/providers/anthropic/provider.py +2 -0
- janito/providers/azure_openai/provider.py +3 -0
- janito/providers/dashscope.bak.zip +0 -0
- janito/providers/deepseek/__init__.py +1 -1
- janito/providers/deepseek/model_info.py +16 -16
- janito/providers/deepseek/provider.py +94 -91
- janito/providers/google/provider.py +3 -0
- janito/providers/mistralai/provider.py +3 -0
- janito/providers/openai/provider.py +4 -0
- janito/providers/registry.py +26 -26
- janito/shell.bak.zip +0 -0
- janito/tools/DOCSTRING_STANDARD.txt +33 -0
- janito/tools/README.md +3 -0
- janito/tools/__init__.py +20 -6
- janito/tools/adapters/__init__.py +1 -1
- janito/tools/adapters/local/__init__.py +65 -62
- janito/tools/adapters/local/adapter.py +18 -35
- janito/tools/adapters/local/ask_user.py +101 -102
- janito/tools/adapters/local/copy_file.py +84 -84
- janito/tools/adapters/local/create_directory.py +69 -69
- janito/tools/adapters/local/create_file.py +82 -82
- janito/tools/adapters/local/delete_text_in_file.py +2 -2
- janito/tools/adapters/local/fetch_url.py +97 -97
- janito/tools/adapters/local/find_files.py +139 -138
- janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
- janito/tools/adapters/local/get_file_outline/core.py +117 -117
- janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
- janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
- janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
- janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
- janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
- janito/tools/adapters/local/move_file.py +2 -2
- janito/tools/adapters/local/open_html_in_browser.py +2 -1
- janito/tools/adapters/local/open_url.py +2 -2
- janito/tools/adapters/local/python_code_run.py +166 -166
- janito/tools/adapters/local/python_command_run.py +164 -164
- janito/tools/adapters/local/python_file_run.py +163 -163
- janito/tools/adapters/local/remove_directory.py +2 -2
- janito/tools/adapters/local/remove_file.py +2 -2
- janito/tools/adapters/local/replace_text_in_file.py +2 -2
- janito/tools/adapters/local/run_bash_command.py +176 -176
- janito/tools/adapters/local/run_powershell_command.py +219 -219
- janito/tools/adapters/local/search_text/__init__.py +1 -1
- janito/tools/adapters/local/search_text/core.py +201 -201
- janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
- janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
- janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
- janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
- janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
- janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
- janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
- janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
- janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
- janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
- janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
- janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
- janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
- janito/tools/adapters/local/view_file.py +168 -167
- janito/tools/inspect_registry.py +17 -17
- janito/tools/outline_file.bak.zip +0 -0
- janito/tools/permissions.py +45 -0
- janito/tools/permissions_parse.py +12 -0
- janito/tools/tool_base.py +118 -105
- janito/tools/tool_events.py +58 -58
- janito/tools/tool_run_exception.py +12 -12
- janito/tools/tool_use_tracker.py +81 -81
- janito/tools/tool_utils.py +43 -45
- janito/tools/tools_adapter.py +25 -20
- janito/tools/tools_schema.py +104 -104
- {janito-2.3.0.dist-info → janito-2.4.0.dist-info}/METADATA +425 -388
- janito-2.4.0.dist-info/RECORD +195 -0
- janito/agent/templates/profiles/system_prompt_template_base_pt.txt.j2 +0 -13
- janito/agent/templates/profiles/system_prompt_template_main.txt.j2 +0 -37
- janito/cli/chat_mode/shell/commands/edit.py +0 -25
- janito/cli/chat_mode/shell/commands/exec.py +0 -27
- janito/cli/chat_mode/shell/commands/termweb_log.py +0 -92
- janito/cli/termweb_starter.py +0 -122
- janito/termweb/app.py +0 -95
- janito/version.py +0 -4
- janito-2.3.0.dist-info/RECORD +0 -181
- {janito-2.3.0.dist-info → janito-2.4.0.dist-info}/WHEEL +0 -0
- {janito-2.3.0.dist-info → janito-2.4.0.dist-info}/entry_points.txt +0 -0
- {janito-2.3.0.dist-info → janito-2.4.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.3.0.dist-info → janito-2.4.0.dist-info}/top_level.txt +0 -0
@@ -1,167 +1,168 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
-
from janito.tools.tool_utils import pluralize
|
5
|
-
from janito.i18n import tr
|
6
|
-
|
7
|
-
|
8
|
-
@register_local_tool
|
9
|
-
class ViewFileTool(ToolBase):
|
10
|
-
"""
|
11
|
-
Read lines from a file. You can specify a line range, or read the entire file by simply omitting the from_line and to_line parameters.
|
12
|
-
|
13
|
-
Args:
|
14
|
-
file_path (str): Path to the file to read lines from.
|
15
|
-
from_line (int, optional): Starting line number (1-based). Omit to start from the first line.
|
16
|
-
to_line (int, optional): Ending line number (1-based). Omit to read to the end of the file.
|
17
|
-
|
18
|
-
To read the full file, just provide file_path and leave from_line and to_line unset.
|
19
|
-
|
20
|
-
Returns:
|
21
|
-
str: File content with a header indicating the file name and line range. Example:
|
22
|
-
- "---\nFile: /path/to/file.py | Lines: 1-10 (of 100)\n---\n<lines...>"
|
23
|
-
- "---\nFile: /path/to/file.py | All lines (total: 100 (all))\n---\n<all lines...>"
|
24
|
-
- "Error reading file: <error message>"
|
25
|
-
- "❗ not found"
|
26
|
-
"""
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
entries.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
selected_len
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
selected_len
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
selected_len
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
disp_path
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
disp_path
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
disp_path
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
disp_path
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
1
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
+
from janito.report_events import ReportAction
|
3
|
+
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
+
from janito.tools.tool_utils import pluralize
|
5
|
+
from janito.i18n import tr
|
6
|
+
|
7
|
+
|
8
|
+
@register_local_tool
|
9
|
+
class ViewFileTool(ToolBase):
|
10
|
+
"""
|
11
|
+
Read lines from a file. You can specify a line range, or read the entire file by simply omitting the from_line and to_line parameters.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
file_path (str): Path to the file to read lines from.
|
15
|
+
from_line (int, optional): Starting line number (1-based). Omit to start from the first line.
|
16
|
+
to_line (int, optional): Ending line number (1-based). Omit to read to the end of the file.
|
17
|
+
|
18
|
+
To read the full file, just provide file_path and leave from_line and to_line unset.
|
19
|
+
|
20
|
+
Returns:
|
21
|
+
str: File content with a header indicating the file name and line range. Example:
|
22
|
+
- "---\nFile: /path/to/file.py | Lines: 1-10 (of 100)\n---\n<lines...>"
|
23
|
+
- "---\nFile: /path/to/file.py | All lines (total: 100 (all))\n---\n<all lines...>"
|
24
|
+
- "Error reading file: <error message>"
|
25
|
+
- "❗ not found"
|
26
|
+
"""
|
27
|
+
|
28
|
+
permissions = ToolPermissions(read=True)
|
29
|
+
tool_name = "view_file"
|
30
|
+
|
31
|
+
def run(self, file_path: str, from_line: int = None, to_line: int = None) -> str:
|
32
|
+
import os
|
33
|
+
from janito.tools.tool_utils import display_path
|
34
|
+
|
35
|
+
disp_path = display_path(file_path)
|
36
|
+
self.report_action(
|
37
|
+
tr("📖 View '{disp_path}'", disp_path=disp_path),
|
38
|
+
ReportAction.READ,
|
39
|
+
)
|
40
|
+
try:
|
41
|
+
if os.path.isdir(file_path):
|
42
|
+
return self._list_directory(file_path, disp_path)
|
43
|
+
lines = self._read_file_lines(file_path)
|
44
|
+
selected, selected_len, total_lines = self._select_lines(
|
45
|
+
lines, from_line, to_line
|
46
|
+
)
|
47
|
+
self._report_success(selected_len, from_line, to_line, total_lines)
|
48
|
+
header = self._format_header(
|
49
|
+
disp_path, from_line, to_line, selected_len, total_lines
|
50
|
+
)
|
51
|
+
return header + "".join(selected)
|
52
|
+
except FileNotFoundError as e:
|
53
|
+
self.report_warning(tr("❗ not found"))
|
54
|
+
return f"Error reading file: {e}"
|
55
|
+
except Exception as e:
|
56
|
+
self.report_error(tr(" ❌ Error: {error}", error=e))
|
57
|
+
return tr("Error reading file: {error}", error=e)
|
58
|
+
|
59
|
+
def _list_directory(self, file_path, disp_path):
|
60
|
+
import os
|
61
|
+
|
62
|
+
try:
|
63
|
+
entries = os.listdir(file_path)
|
64
|
+
entries.sort()
|
65
|
+
# Suffix subdirectories with '/'
|
66
|
+
formatted_entries = []
|
67
|
+
for entry in entries:
|
68
|
+
full_path = os.path.join(file_path, entry)
|
69
|
+
if os.path.isdir(full_path):
|
70
|
+
formatted_entries.append(entry + "/")
|
71
|
+
else:
|
72
|
+
formatted_entries.append(entry)
|
73
|
+
header = (
|
74
|
+
f"--- view_file: {disp_path} [directory, {len(entries)} entries] ---\n"
|
75
|
+
)
|
76
|
+
listing = "\n".join(formatted_entries)
|
77
|
+
self.report_success(tr("📁 Directory ({count} items)", count=len(entries)))
|
78
|
+
return header + listing + "\n"
|
79
|
+
except Exception as e:
|
80
|
+
self.report_error(tr(" ❌ Error listing directory: {error}", error=e))
|
81
|
+
return tr("Error listing directory: {error}", error=e)
|
82
|
+
|
83
|
+
def _read_file_lines(self, file_path):
|
84
|
+
"""Read all lines from the file."""
|
85
|
+
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
86
|
+
return f.readlines()
|
87
|
+
|
88
|
+
def _select_lines(self, lines, from_line, to_line):
|
89
|
+
"""Select the requested lines and return them with their count and total lines."""
|
90
|
+
selected = lines[
|
91
|
+
(from_line - 1 if from_line else 0) : (to_line if to_line else None)
|
92
|
+
]
|
93
|
+
selected_len = len(selected)
|
94
|
+
total_lines = len(lines)
|
95
|
+
return selected, selected_len, total_lines
|
96
|
+
|
97
|
+
def _report_success(self, selected_len, from_line, to_line, total_lines):
|
98
|
+
"""Report the success message after reading lines."""
|
99
|
+
if from_line and to_line:
|
100
|
+
requested = to_line - from_line + 1
|
101
|
+
at_end = to_line >= total_lines or selected_len < requested
|
102
|
+
if at_end:
|
103
|
+
self.report_success(
|
104
|
+
tr(
|
105
|
+
" ✅ {selected_len} {line_word} (end)",
|
106
|
+
selected_len=selected_len,
|
107
|
+
line_word=pluralize("line", selected_len),
|
108
|
+
)
|
109
|
+
)
|
110
|
+
elif to_line < total_lines:
|
111
|
+
self.report_success(
|
112
|
+
tr(
|
113
|
+
" ✅ {selected_len} {line_word} ({remaining} to end)",
|
114
|
+
selected_len=selected_len,
|
115
|
+
line_word=pluralize("line", selected_len),
|
116
|
+
remaining=total_lines - to_line,
|
117
|
+
)
|
118
|
+
)
|
119
|
+
else:
|
120
|
+
self.report_success(
|
121
|
+
tr(
|
122
|
+
" ✅ {selected_len} {line_word} (all)",
|
123
|
+
selected_len=selected_len,
|
124
|
+
line_word=pluralize("line", selected_len),
|
125
|
+
)
|
126
|
+
)
|
127
|
+
|
128
|
+
def _format_header(self, disp_path, from_line, to_line, selected_len, total_lines):
|
129
|
+
"""Format the header for the output."""
|
130
|
+
if from_line and to_line:
|
131
|
+
requested = to_line - from_line + 1
|
132
|
+
at_end = selected_len < requested or to_line >= total_lines
|
133
|
+
if at_end:
|
134
|
+
return tr(
|
135
|
+
"---\n{disp_path} {from_line}-{to_line} (end)\n---\n",
|
136
|
+
disp_path=disp_path,
|
137
|
+
from_line=from_line,
|
138
|
+
to_line=to_line,
|
139
|
+
)
|
140
|
+
else:
|
141
|
+
return tr(
|
142
|
+
"---\n{disp_path} {from_line}-{to_line} (of {total_lines})\n---\n",
|
143
|
+
disp_path=disp_path,
|
144
|
+
from_line=from_line,
|
145
|
+
to_line=to_line,
|
146
|
+
total_lines=total_lines,
|
147
|
+
)
|
148
|
+
elif from_line:
|
149
|
+
return tr(
|
150
|
+
"---\n{disp_path} {from_line}-END (of {total_lines})\n---\n",
|
151
|
+
disp_path=disp_path,
|
152
|
+
from_line=from_line,
|
153
|
+
total_lines=total_lines,
|
154
|
+
)
|
155
|
+
else:
|
156
|
+
return tr(
|
157
|
+
"---\n{disp_path} All lines (total: {total_lines} (all))\n---\n",
|
158
|
+
disp_path=disp_path,
|
159
|
+
total_lines=total_lines,
|
160
|
+
)
|
161
|
+
|
162
|
+
def _handle_read_error(self, e):
|
163
|
+
"""Handle file read errors and report appropriately."""
|
164
|
+
if isinstance(e, FileNotFoundError):
|
165
|
+
self.report_error(tr("❗ not found"), ReportAction.READ)
|
166
|
+
return tr("❗ not found")
|
167
|
+
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.READ)
|
168
|
+
return tr("Error reading file: {error}", error=e)
|
janito/tools/inspect_registry.py
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
def check_tools_registry():
|
2
|
-
# Import and use the singleton tools adapter instance
|
3
|
-
from janito.tools.adapters.local import local_tools_adapter
|
4
|
-
|
5
|
-
print("Available tool names:", local_tools_adapter.list_tools())
|
6
|
-
print(
|
7
|
-
"Available tool classes:",
|
8
|
-
[cls.__name__ for cls in local_tools_adapter.get_tool_classes()],
|
9
|
-
)
|
10
|
-
print(
|
11
|
-
"Available tool instances:",
|
12
|
-
[tool.name for tool in local_tools_adapter.get_tools()],
|
13
|
-
)
|
14
|
-
|
15
|
-
|
16
|
-
if __name__ == "__main__":
|
17
|
-
check_tools_registry()
|
1
|
+
def check_tools_registry():
|
2
|
+
# Import and use the singleton tools adapter instance
|
3
|
+
from janito.tools.adapters.local import local_tools_adapter
|
4
|
+
|
5
|
+
print("Available tool names:", local_tools_adapter.list_tools())
|
6
|
+
print(
|
7
|
+
"Available tool classes:",
|
8
|
+
[cls.__name__ for cls in local_tools_adapter.get_tool_classes()],
|
9
|
+
)
|
10
|
+
print(
|
11
|
+
"Available tool instances:",
|
12
|
+
[tool.name for tool in local_tools_adapter.get_tools()],
|
13
|
+
)
|
14
|
+
|
15
|
+
|
16
|
+
if __name__ == "__main__":
|
17
|
+
check_tools_registry()
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from janito.tools.tool_base import ToolPermissions
|
2
|
+
|
3
|
+
class AllowedPermissionsState:
|
4
|
+
_instance = None
|
5
|
+
_permissions = ToolPermissions(read=False, write=False, execute=False)
|
6
|
+
_default_permissions = None
|
7
|
+
|
8
|
+
def __new__(cls):
|
9
|
+
if cls._instance is None:
|
10
|
+
cls._instance = super().__new__(cls)
|
11
|
+
return cls._instance
|
12
|
+
|
13
|
+
@classmethod
|
14
|
+
def get_permissions(cls):
|
15
|
+
return cls._permissions
|
16
|
+
|
17
|
+
@classmethod
|
18
|
+
def set_permissions(cls, permissions):
|
19
|
+
if not isinstance(permissions, ToolPermissions):
|
20
|
+
raise ValueError("permissions must be a ToolPermissions instance")
|
21
|
+
cls._permissions = permissions
|
22
|
+
|
23
|
+
@classmethod
|
24
|
+
def set_default_permissions(cls, permissions):
|
25
|
+
if not isinstance(permissions, ToolPermissions):
|
26
|
+
raise ValueError("permissions must be a ToolPermissions instance")
|
27
|
+
cls._default_permissions = permissions
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def get_default_permissions(cls):
|
31
|
+
return cls._default_permissions
|
32
|
+
|
33
|
+
# Convenience functions
|
34
|
+
|
35
|
+
def get_global_allowed_permissions():
|
36
|
+
return AllowedPermissionsState.get_permissions()
|
37
|
+
|
38
|
+
def set_global_allowed_permissions(permissions):
|
39
|
+
AllowedPermissionsState.set_permissions(permissions)
|
40
|
+
|
41
|
+
def set_default_allowed_permissions(permissions):
|
42
|
+
AllowedPermissionsState.set_default_permissions(permissions)
|
43
|
+
|
44
|
+
def get_default_allowed_permissions():
|
45
|
+
return AllowedPermissionsState.get_default_permissions()
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from janito.tools.tool_base import ToolPermissions
|
2
|
+
|
3
|
+
def parse_permissions_string(perm_str: str) -> ToolPermissions:
|
4
|
+
"""
|
5
|
+
Parse a string like 'rwx', 'rw', 'r', etc. into a ToolPermissions object.
|
6
|
+
"""
|
7
|
+
perm_str = perm_str.lower()
|
8
|
+
return ToolPermissions(
|
9
|
+
read='r' in perm_str,
|
10
|
+
write='w' in perm_str,
|
11
|
+
execute='x' in perm_str,
|
12
|
+
)
|