janito 3.14.2__py3-none-any.whl → 3.15.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/platform_discovery.py +1 -8
- janito/plugins/tools/local/adapter.py +3 -2
- janito/plugins/tools/local/ask_user.py +111 -112
- janito/plugins/tools/local/copy_file.py +86 -87
- janito/plugins/tools/local/create_directory.py +111 -112
- janito/plugins/tools/local/create_file.py +0 -1
- janito/plugins/tools/local/delete_text_in_file.py +133 -134
- janito/plugins/tools/local/fetch_url.py +465 -466
- janito/plugins/tools/local/find_files.py +142 -143
- janito/plugins/tools/local/markdown_view.py +0 -1
- janito/plugins/tools/local/move_file.py +130 -131
- janito/plugins/tools/local/open_html_in_browser.py +50 -51
- janito/plugins/tools/local/open_url.py +36 -37
- janito/plugins/tools/local/python_code_run.py +171 -172
- janito/plugins/tools/local/python_command_run.py +170 -171
- janito/plugins/tools/local/python_file_run.py +171 -172
- janito/plugins/tools/local/read_chart.py +258 -259
- janito/plugins/tools/local/read_files.py +57 -58
- janito/plugins/tools/local/remove_directory.py +54 -55
- janito/plugins/tools/local/remove_file.py +57 -58
- janito/plugins/tools/local/replace_text_in_file.py +275 -276
- janito/plugins/tools/local/run_bash_command.py +182 -183
- janito/plugins/tools/local/run_powershell_command.py +217 -218
- janito/plugins/tools/local/show_image.py +0 -1
- janito/plugins/tools/local/show_image_grid.py +0 -1
- janito/plugins/tools/local/view_file.py +0 -1
- janito/providers/alibaba/provider.py +1 -1
- janito/tools/base.py +19 -12
- janito/tools/tool_base.py +122 -121
- janito/tools/tools_schema.py +104 -104
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/METADATA +9 -29
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/RECORD +36 -36
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/WHEEL +0 -0
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/entry_points.txt +0 -0
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/top_level.txt +0 -0
janito/platform_discovery.py
CHANGED
@@ -24,13 +24,7 @@ class PlatformDiscovery:
|
|
24
24
|
return f"Git Bash ({self.os_environ.get('MSYSTEM')})"
|
25
25
|
return None
|
26
26
|
|
27
|
-
|
28
|
-
if self.os_environ.get("WSL_DISTRO_NAME"):
|
29
|
-
shell = self.os_environ.get("SHELL")
|
30
|
-
shell_name = shell.split("/")[-1] if shell else "unknown"
|
31
|
-
distro = self.os_environ.get("WSL_DISTRO_NAME")
|
32
|
-
return f"{shell_name} (WSL: {distro})"
|
33
|
-
return None
|
27
|
+
|
34
28
|
|
35
29
|
def _detect_powershell(self):
|
36
30
|
try:
|
@@ -87,7 +81,6 @@ class PlatformDiscovery:
|
|
87
81
|
"""
|
88
82
|
shell_info = (
|
89
83
|
self._detect_git_bash()
|
90
|
-
or self._detect_wsl()
|
91
84
|
or self._detect_powershell()
|
92
85
|
or self._detect_shell_env()
|
93
86
|
or self._detect_comspec()
|
@@ -76,10 +76,11 @@ class LocalToolsAdapter(ToolsAdapter):
|
|
76
76
|
raise TypeError(
|
77
77
|
f"Tool '{tool_class.__name__}' must implement a callable 'run' method."
|
78
78
|
)
|
79
|
-
|
79
|
+
# Derive tool name from class name by convention
|
80
|
+
tool_name = instance.tool_name
|
80
81
|
if not tool_name or not isinstance(tool_name, str):
|
81
82
|
raise ValueError(
|
82
|
-
f"Tool '{tool_class.__name__}' must provide a
|
83
|
+
f"Tool '{tool_class.__name__}' must provide a valid tool_name property."
|
83
84
|
)
|
84
85
|
if tool_name in self._tools:
|
85
86
|
raise ValueError(f"Tool '{tool_name}' is already registered.")
|
@@ -1,112 +1,111 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.plugins.tools.local.adapter import register_local_tool
|
3
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
4
|
-
|
5
|
-
from rich import print as rich_print
|
6
|
-
from janito.i18n import tr
|
7
|
-
from rich.panel import Panel
|
8
|
-
from rich.markdown import Markdown
|
9
|
-
from prompt_toolkit import PromptSession
|
10
|
-
from prompt_toolkit.key_binding import KeyBindings
|
11
|
-
from prompt_toolkit.enums import EditingMode
|
12
|
-
from prompt_toolkit.formatted_text import HTML
|
13
|
-
from janito.cli.chat_mode.prompt_style import chat_shell_style
|
14
|
-
from prompt_toolkit.styles import Style
|
15
|
-
|
16
|
-
toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
|
17
|
-
|
18
|
-
|
19
|
-
@register_local_tool
|
20
|
-
class AskUserTool(ToolBase):
|
21
|
-
"""
|
22
|
-
Prompts the user for clarification or input with a question.
|
23
|
-
|
24
|
-
Args:
|
25
|
-
question (str): The question to ask the user. This parameter is required and should be a string containing the prompt or question to display to the user.
|
26
|
-
Returns:
|
27
|
-
str: The user's response as a string. Example:
|
28
|
-
- "Yes"
|
29
|
-
- "No"
|
30
|
-
- "Some detailed answer..."
|
31
|
-
"""
|
32
|
-
|
33
|
-
permissions = ToolPermissions(read=True)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
buf =
|
52
|
-
buf.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
buf =
|
58
|
-
buf.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
#
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
return sanitized
|
1
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
+
from janito.plugins.tools.local.adapter import register_local_tool
|
3
|
+
from janito.tools.loop_protection_decorator import protect_against_loops
|
4
|
+
|
5
|
+
from rich import print as rich_print
|
6
|
+
from janito.i18n import tr
|
7
|
+
from rich.panel import Panel
|
8
|
+
from rich.markdown import Markdown
|
9
|
+
from prompt_toolkit import PromptSession
|
10
|
+
from prompt_toolkit.key_binding import KeyBindings
|
11
|
+
from prompt_toolkit.enums import EditingMode
|
12
|
+
from prompt_toolkit.formatted_text import HTML
|
13
|
+
from janito.cli.chat_mode.prompt_style import chat_shell_style
|
14
|
+
from prompt_toolkit.styles import Style
|
15
|
+
|
16
|
+
toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
|
17
|
+
|
18
|
+
|
19
|
+
@register_local_tool
|
20
|
+
class AskUserTool(ToolBase):
|
21
|
+
"""
|
22
|
+
Prompts the user for clarification or input with a question.
|
23
|
+
|
24
|
+
Args:
|
25
|
+
question (str): The question to ask the user. This parameter is required and should be a string containing the prompt or question to display to the user.
|
26
|
+
Returns:
|
27
|
+
str: The user's response as a string. Example:
|
28
|
+
- "Yes"
|
29
|
+
- "No"
|
30
|
+
- "Some detailed answer..."
|
31
|
+
"""
|
32
|
+
|
33
|
+
permissions = ToolPermissions(read=True)
|
34
|
+
|
35
|
+
@protect_against_loops(max_calls=5, time_window=10.0, key_field="question")
|
36
|
+
def run(self, question: str) -> str:
|
37
|
+
|
38
|
+
print() # Print an empty line before the question panel
|
39
|
+
rich_print(Panel.fit(Markdown(question), title=tr("Question"), style="cyan"))
|
40
|
+
|
41
|
+
bindings = KeyBindings()
|
42
|
+
mode = {"multiline": False}
|
43
|
+
|
44
|
+
@bindings.add("c-r")
|
45
|
+
def _(event):
|
46
|
+
pass
|
47
|
+
|
48
|
+
@bindings.add("f12")
|
49
|
+
def _(event):
|
50
|
+
buf = event.app.current_buffer
|
51
|
+
buf.text = "Do It"
|
52
|
+
buf.validate_and_handle()
|
53
|
+
|
54
|
+
@bindings.add("f2")
|
55
|
+
def _(event):
|
56
|
+
buf = event.app.current_buffer
|
57
|
+
buf.text = "F2"
|
58
|
+
buf.validate_and_handle()
|
59
|
+
|
60
|
+
# Use shared CLI styles
|
61
|
+
|
62
|
+
# prompt_style contains the prompt area and input background
|
63
|
+
# toolbar_style contains the bottom-toolbar styling
|
64
|
+
|
65
|
+
# Use the shared chat_shell_style for input styling only
|
66
|
+
style = chat_shell_style
|
67
|
+
|
68
|
+
def get_toolbar():
|
69
|
+
f12_hint = " F2: F2 | F12: Do It"
|
70
|
+
if mode["multiline"]:
|
71
|
+
return HTML(
|
72
|
+
f"<b>Multiline mode (Esc+Enter to submit). Type /single to switch.</b>{f12_hint}"
|
73
|
+
)
|
74
|
+
else:
|
75
|
+
return HTML(
|
76
|
+
f"<b>Single-line mode (Enter to submit). Type /multi for multiline.</b>{f12_hint}"
|
77
|
+
)
|
78
|
+
|
79
|
+
session = PromptSession(
|
80
|
+
multiline=False,
|
81
|
+
key_bindings=bindings,
|
82
|
+
editing_mode=EditingMode.EMACS,
|
83
|
+
bottom_toolbar=get_toolbar,
|
84
|
+
style=style,
|
85
|
+
)
|
86
|
+
|
87
|
+
prompt_icon = HTML("<inputline>💬 </inputline>")
|
88
|
+
|
89
|
+
while True:
|
90
|
+
response = session.prompt(prompt_icon)
|
91
|
+
if not mode["multiline"] and response.strip() == "/multi":
|
92
|
+
mode["multiline"] = True
|
93
|
+
session.multiline = True
|
94
|
+
continue
|
95
|
+
elif mode["multiline"] and response.strip() == "/single":
|
96
|
+
mode["multiline"] = False
|
97
|
+
session.multiline = False
|
98
|
+
continue
|
99
|
+
else:
|
100
|
+
sanitized = response.strip()
|
101
|
+
try:
|
102
|
+
sanitized.encode("utf-8")
|
103
|
+
except UnicodeEncodeError:
|
104
|
+
sanitized = sanitized.encode("utf-8", errors="replace").decode(
|
105
|
+
"utf-8"
|
106
|
+
)
|
107
|
+
rich_print(
|
108
|
+
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
109
|
+
)
|
110
|
+
print("\a", end="", flush=True) # Print bell character
|
111
|
+
return sanitized
|
@@ -1,87 +1,86 @@
|
|
1
|
-
import os
|
2
|
-
from janito.tools.path_utils import expand_path
|
3
|
-
import shutil
|
4
|
-
from typing import List, Union
|
5
|
-
from janito.plugins.tools.local.adapter import register_local_tool
|
6
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
-
from janito.tools.tool_utils import display_path
|
8
|
-
from janito.report_events import ReportAction
|
9
|
-
from janito.i18n import tr
|
10
|
-
|
11
|
-
|
12
|
-
@register_local_tool
|
13
|
-
class CopyFileTool(ToolBase):
|
14
|
-
"""
|
15
|
-
Copy one or more files to a target directory, or copy a single file to a new file.
|
16
|
-
Args:
|
17
|
-
sources (str): Space-separated path(s) to the file(s) to copy.
|
18
|
-
For multiple sources, provide a single string with paths separated by spaces.
|
19
|
-
target (str): Destination path. If copying multiple sources, this must be an existing directory.
|
20
|
-
overwrite (bool, optional): Overwrite existing files. Default: False.
|
21
|
-
Recommended only after reading the file to be overwritten.
|
22
|
-
Returns:
|
23
|
-
str: Status string for each copy operation.
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(read=True, write=True)
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
)
|
1
|
+
import os
|
2
|
+
from janito.tools.path_utils import expand_path
|
3
|
+
import shutil
|
4
|
+
from typing import List, Union
|
5
|
+
from janito.plugins.tools.local.adapter import register_local_tool
|
6
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
+
from janito.tools.tool_utils import display_path
|
8
|
+
from janito.report_events import ReportAction
|
9
|
+
from janito.i18n import tr
|
10
|
+
|
11
|
+
|
12
|
+
@register_local_tool
|
13
|
+
class CopyFileTool(ToolBase):
|
14
|
+
"""
|
15
|
+
Copy one or more files to a target directory, or copy a single file to a new file.
|
16
|
+
Args:
|
17
|
+
sources (str): Space-separated path(s) to the file(s) to copy.
|
18
|
+
For multiple sources, provide a single string with paths separated by spaces.
|
19
|
+
target (str): Destination path. If copying multiple sources, this must be an existing directory.
|
20
|
+
overwrite (bool, optional): Overwrite existing files. Default: False.
|
21
|
+
Recommended only after reading the file to be overwritten.
|
22
|
+
Returns:
|
23
|
+
str: Status string for each copy operation.
|
24
|
+
"""
|
25
|
+
|
26
|
+
permissions = ToolPermissions(read=True, write=True)
|
27
|
+
|
28
|
+
def run(self, sources: str, target: str, overwrite: bool = False) -> str:
|
29
|
+
source_list = [expand_path(src) for src in sources.split() if src]
|
30
|
+
target = expand_path(target)
|
31
|
+
messages = []
|
32
|
+
if len(source_list) > 1:
|
33
|
+
if not os.path.isdir(target):
|
34
|
+
return tr(
|
35
|
+
"❗ Target must be an existing directory when copying multiple files: '{target}'",
|
36
|
+
target=display_path(target),
|
37
|
+
)
|
38
|
+
for src in source_list:
|
39
|
+
if not os.path.isfile(src):
|
40
|
+
messages.append(
|
41
|
+
tr(
|
42
|
+
"❗ Source file does not exist: '{src}'",
|
43
|
+
src=display_path(src),
|
44
|
+
)
|
45
|
+
)
|
46
|
+
continue
|
47
|
+
dst = os.path.join(target, os.path.basename(src))
|
48
|
+
messages.append(self._copy_one(src, dst, overwrite=overwrite))
|
49
|
+
else:
|
50
|
+
src = source_list[0]
|
51
|
+
if os.path.isdir(target):
|
52
|
+
dst = os.path.join(target, os.path.basename(src))
|
53
|
+
else:
|
54
|
+
dst = target
|
55
|
+
messages.append(self._copy_one(src, dst, overwrite=overwrite))
|
56
|
+
return "\n".join(messages)
|
57
|
+
|
58
|
+
def _copy_one(self, src, dst, overwrite=False) -> str:
|
59
|
+
disp_src = display_path(src)
|
60
|
+
disp_dst = display_path(dst)
|
61
|
+
if not os.path.isfile(src):
|
62
|
+
return tr("❗ Source file does not exist: '{src}'", src=disp_src)
|
63
|
+
if os.path.exists(dst) and not overwrite:
|
64
|
+
return tr(
|
65
|
+
"❗ Target already exists: '{dst}'. Set overwrite=True to replace.",
|
66
|
+
dst=disp_dst,
|
67
|
+
)
|
68
|
+
try:
|
69
|
+
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
70
|
+
shutil.copy2(src, dst)
|
71
|
+
note = (
|
72
|
+
"\n⚠️ Overwrote existing file. (recommended only after reading the file to be overwritten)"
|
73
|
+
if (os.path.exists(dst) and overwrite)
|
74
|
+
else ""
|
75
|
+
)
|
76
|
+
self.report_success(
|
77
|
+
tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst)
|
78
|
+
)
|
79
|
+
return tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst) + note
|
80
|
+
except Exception as e:
|
81
|
+
return tr(
|
82
|
+
"❗ Copy failed from '{src}' to '{dst}': {err}",
|
83
|
+
src=disp_src,
|
84
|
+
dst=disp_dst,
|
85
|
+
err=str(e),
|
86
|
+
)
|