janito 3.14.1__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.
Files changed (38) hide show
  1. janito/platform_discovery.py +1 -8
  2. janito/plugins/tools/local/adapter.py +3 -2
  3. janito/plugins/tools/local/ask_user.py +111 -112
  4. janito/plugins/tools/local/copy_file.py +86 -87
  5. janito/plugins/tools/local/create_directory.py +111 -112
  6. janito/plugins/tools/local/create_file.py +0 -1
  7. janito/plugins/tools/local/delete_text_in_file.py +133 -134
  8. janito/plugins/tools/local/fetch_url.py +465 -466
  9. janito/plugins/tools/local/find_files.py +142 -143
  10. janito/plugins/tools/local/markdown_view.py +0 -1
  11. janito/plugins/tools/local/move_file.py +130 -131
  12. janito/plugins/tools/local/open_html_in_browser.py +50 -51
  13. janito/plugins/tools/local/open_url.py +36 -37
  14. janito/plugins/tools/local/python_code_run.py +171 -172
  15. janito/plugins/tools/local/python_command_run.py +170 -171
  16. janito/plugins/tools/local/python_file_run.py +171 -172
  17. janito/plugins/tools/local/read_chart.py +258 -259
  18. janito/plugins/tools/local/read_files.py +57 -58
  19. janito/plugins/tools/local/remove_directory.py +54 -55
  20. janito/plugins/tools/local/remove_file.py +57 -58
  21. janito/plugins/tools/local/replace_text_in_file.py +275 -276
  22. janito/plugins/tools/local/run_bash_command.py +182 -183
  23. janito/plugins/tools/local/run_powershell_command.py +217 -218
  24. janito/plugins/tools/local/show_image.py +0 -1
  25. janito/plugins/tools/local/show_image_grid.py +0 -1
  26. janito/plugins/tools/local/view_file.py +0 -1
  27. janito/providers/alibaba/provider.py +1 -1
  28. janito/providers/deepseek/model_info.py +16 -37
  29. janito/providers/deepseek/provider.py +4 -3
  30. janito/tools/base.py +19 -12
  31. janito/tools/tool_base.py +122 -121
  32. janito/tools/tools_schema.py +104 -104
  33. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/METADATA +9 -32
  34. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/RECORD +38 -38
  35. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/WHEEL +0 -0
  36. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/entry_points.txt +0 -0
  37. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/licenses/LICENSE +0 -0
  38. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/top_level.txt +0 -0
@@ -24,13 +24,7 @@ class PlatformDiscovery:
24
24
  return f"Git Bash ({self.os_environ.get('MSYSTEM')})"
25
25
  return None
26
26
 
27
- def _detect_wsl(self):
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
- tool_name = getattr(instance, "tool_name", None)
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 class attribute 'tool_name' (str) for its registration name."
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
- tool_name = "ask_user"
35
-
36
- @protect_against_loops(max_calls=5, time_window=10.0, key_field="question")
37
- def run(self, question: str) -> str:
38
-
39
- print() # Print an empty line before the question panel
40
- rich_print(Panel.fit(Markdown(question), title=tr("Question"), style="cyan"))
41
-
42
- bindings = KeyBindings()
43
- mode = {"multiline": False}
44
-
45
- @bindings.add("c-r")
46
- def _(event):
47
- pass
48
-
49
- @bindings.add("f12")
50
- def _(event):
51
- buf = event.app.current_buffer
52
- buf.text = "Do It"
53
- buf.validate_and_handle()
54
-
55
- @bindings.add("f2")
56
- def _(event):
57
- buf = event.app.current_buffer
58
- buf.text = "F2"
59
- buf.validate_and_handle()
60
-
61
- # Use shared CLI styles
62
-
63
- # prompt_style contains the prompt area and input background
64
- # toolbar_style contains the bottom-toolbar styling
65
-
66
- # Use the shared chat_shell_style for input styling only
67
- style = chat_shell_style
68
-
69
- def get_toolbar():
70
- f12_hint = " F2: F2 | F12: Do It"
71
- if mode["multiline"]:
72
- return HTML(
73
- f"<b>Multiline mode (Esc+Enter to submit). Type /single to switch.</b>{f12_hint}"
74
- )
75
- else:
76
- return HTML(
77
- f"<b>Single-line mode (Enter to submit). Type /multi for multiline.</b>{f12_hint}"
78
- )
79
-
80
- session = PromptSession(
81
- multiline=False,
82
- key_bindings=bindings,
83
- editing_mode=EditingMode.EMACS,
84
- bottom_toolbar=get_toolbar,
85
- style=style,
86
- )
87
-
88
- prompt_icon = HTML("<inputline>💬 </inputline>")
89
-
90
- while True:
91
- response = session.prompt(prompt_icon)
92
- if not mode["multiline"] and response.strip() == "/multi":
93
- mode["multiline"] = True
94
- session.multiline = True
95
- continue
96
- elif mode["multiline"] and response.strip() == "/single":
97
- mode["multiline"] = False
98
- session.multiline = False
99
- continue
100
- else:
101
- sanitized = response.strip()
102
- try:
103
- sanitized.encode("utf-8")
104
- except UnicodeEncodeError:
105
- sanitized = sanitized.encode("utf-8", errors="replace").decode(
106
- "utf-8"
107
- )
108
- rich_print(
109
- "[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
110
- )
111
- print("\a", end="", flush=True) # Print bell character
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
- tool_name = "copy_file"
28
-
29
- def run(self, sources: str, target: str, overwrite: bool = False) -> str:
30
- source_list = [expand_path(src) for src in sources.split() if src]
31
- target = expand_path(target)
32
- messages = []
33
- if len(source_list) > 1:
34
- if not os.path.isdir(target):
35
- return tr(
36
- "❗ Target must be an existing directory when copying multiple files: '{target}'",
37
- target=display_path(target),
38
- )
39
- for src in source_list:
40
- if not os.path.isfile(src):
41
- messages.append(
42
- tr(
43
- "❗ Source file does not exist: '{src}'",
44
- src=display_path(src),
45
- )
46
- )
47
- continue
48
- dst = os.path.join(target, os.path.basename(src))
49
- messages.append(self._copy_one(src, dst, overwrite=overwrite))
50
- else:
51
- src = source_list[0]
52
- if os.path.isdir(target):
53
- dst = os.path.join(target, os.path.basename(src))
54
- else:
55
- dst = target
56
- messages.append(self._copy_one(src, dst, overwrite=overwrite))
57
- return "\n".join(messages)
58
-
59
- def _copy_one(self, src, dst, overwrite=False) -> str:
60
- disp_src = display_path(src)
61
- disp_dst = display_path(dst)
62
- if not os.path.isfile(src):
63
- return tr("❗ Source file does not exist: '{src}'", src=disp_src)
64
- if os.path.exists(dst) and not overwrite:
65
- return tr(
66
- "❗ Target already exists: '{dst}'. Set overwrite=True to replace.",
67
- dst=disp_dst,
68
- )
69
- try:
70
- os.makedirs(os.path.dirname(dst), exist_ok=True)
71
- shutil.copy2(src, dst)
72
- note = (
73
- "\n⚠️ Overwrote existing file. (recommended only after reading the file to be overwritten)"
74
- if (os.path.exists(dst) and overwrite)
75
- else ""
76
- )
77
- self.report_success(
78
- tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst)
79
- )
80
- return tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst) + note
81
- except Exception as e:
82
- return tr(
83
- "❗ Copy failed from '{src}' to '{dst}': {err}",
84
- src=disp_src,
85
- dst=disp_dst,
86
- err=str(e),
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
+ )