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
janito/tools/tool_base.py CHANGED
@@ -1,121 +1,122 @@
1
- from janito.report_events import ReportEvent, ReportSubtype, ReportAction
2
- from janito.event_bus.bus import event_bus as default_event_bus
3
-
4
- import inspect
5
- from collections import namedtuple
6
-
7
-
8
- class ToolPermissions(namedtuple("ToolPermissions", ["read", "write", "execute"])):
9
- __slots__ = ()
10
-
11
- def __new__(cls, read=False, write=False, execute=False):
12
- return super().__new__(cls, read, write, execute)
13
-
14
- def __repr__(self):
15
- return f"ToolPermissions(read={self.read}, write={self.write}, execute={self.execute})"
16
-
17
-
18
- class ToolBase:
19
- """
20
- Base class for all tools in the janito project.
21
- Extend this class to implement specific tool functionality.
22
- """
23
-
24
- permissions: "ToolPermissions" = None # Required: must be set by subclasses
25
-
26
- def __init__(self, name=None, event_bus=None):
27
- if self.permissions is None or not isinstance(
28
- self.permissions, ToolPermissions
29
- ):
30
- raise ValueError(
31
- f"Tool '{self.__class__.__name__}' must define a 'permissions' attribute of type ToolPermissions."
32
- )
33
- self.name = name or self.__class__.__name__
34
- self._event_bus = event_bus or default_event_bus
35
-
36
- @property
37
- def event_bus(self):
38
- return self._event_bus
39
-
40
- @event_bus.setter
41
- def event_bus(self, bus):
42
- self._event_bus = bus or default_event_bus
43
-
44
- def report_action(self, message: str, action: ReportAction, context: dict = None):
45
- """
46
- Report that a tool action is starting. This should be the first reporting call for every tool action.
47
- """
48
- self._event_bus.publish(
49
- ReportEvent(
50
- subtype=ReportSubtype.ACTION_INFO,
51
- message=" " + message,
52
- action=action,
53
- tool=self.name,
54
- context=context,
55
- )
56
- )
57
-
58
- def report_error(self, message: str, context: dict = None):
59
- self._event_bus.publish(
60
- ReportEvent(
61
- subtype=ReportSubtype.ERROR,
62
- message=message,
63
- action=None,
64
- tool=self.name,
65
- context=context,
66
- )
67
- )
68
-
69
- def report_success(self, message: str, context: dict = None):
70
- self._event_bus.publish(
71
- ReportEvent(
72
- subtype=ReportSubtype.SUCCESS,
73
- message=message,
74
- action=None,
75
- tool=self.name,
76
- context=context,
77
- )
78
- )
79
-
80
- def report_warning(self, message: str, context: dict = None):
81
- self._event_bus.publish(
82
- ReportEvent(
83
- subtype=ReportSubtype.WARNING,
84
- message=message,
85
- action=None,
86
- tool=self.name,
87
- context=context,
88
- )
89
- )
90
-
91
- def report_stdout(self, message: str, context: dict = None):
92
- self._event_bus.publish(
93
- ReportEvent(
94
- subtype=ReportSubtype.STDOUT,
95
- message=message,
96
- action=None,
97
- tool=self.name,
98
- context=context,
99
- )
100
- )
101
-
102
- def report_stderr(self, message: str, context: dict = None):
103
- self._event_bus.publish(
104
- ReportEvent(
105
- subtype=ReportSubtype.STDERR,
106
- message=message,
107
- action=None,
108
- tool=self.name,
109
- context=context,
110
- )
111
- )
112
-
113
- def run(self, *args, **kwargs):
114
- raise NotImplementedError("Subclasses must implement the run method.")
115
-
116
- def get_signature(self):
117
- """
118
- Return the function signature for this tool's run method.
119
- This is used for introspection and validation.
120
- """
121
- return inspect.signature(self.run)
1
+ from janito.report_events import ReportEvent, ReportSubtype, ReportAction
2
+ from janito.event_bus.bus import event_bus as default_event_bus
3
+ from janito.tools.base import BaseTool
4
+
5
+ import inspect
6
+ from collections import namedtuple
7
+
8
+
9
+ class ToolPermissions(namedtuple("ToolPermissions", ["read", "write", "execute"])):
10
+ __slots__ = ()
11
+
12
+ def __new__(cls, read=False, write=False, execute=False):
13
+ return super().__new__(cls, read, write, execute)
14
+
15
+ def __repr__(self):
16
+ return f"ToolPermissions(read={self.read}, write={self.write}, execute={self.execute})"
17
+
18
+
19
+ class ToolBase(BaseTool):
20
+ """
21
+ Base class for all tools in the janito project.
22
+ Extend this class to implement specific tool functionality.
23
+ """
24
+
25
+ permissions: "ToolPermissions" = None # Required: must be set by subclasses
26
+
27
+ def __init__(self, name=None, event_bus=None):
28
+ if self.permissions is None or not isinstance(
29
+ self.permissions, ToolPermissions
30
+ ):
31
+ raise ValueError(
32
+ f"Tool '{self.__class__.__name__}' must define a 'permissions' attribute of type ToolPermissions."
33
+ )
34
+ self.name = name or self.__class__.__name__
35
+ self._event_bus = event_bus or default_event_bus
36
+
37
+ @property
38
+ def event_bus(self):
39
+ return self._event_bus
40
+
41
+ @event_bus.setter
42
+ def event_bus(self, bus):
43
+ self._event_bus = bus or default_event_bus
44
+
45
+ def report_action(self, message: str, action: ReportAction, context: dict = None):
46
+ """
47
+ Report that a tool action is starting. This should be the first reporting call for every tool action.
48
+ """
49
+ self._event_bus.publish(
50
+ ReportEvent(
51
+ subtype=ReportSubtype.ACTION_INFO,
52
+ message=" " + message,
53
+ action=action,
54
+ tool=self.name,
55
+ context=context,
56
+ )
57
+ )
58
+
59
+ def report_error(self, message: str, context: dict = None):
60
+ self._event_bus.publish(
61
+ ReportEvent(
62
+ subtype=ReportSubtype.ERROR,
63
+ message=message,
64
+ action=None,
65
+ tool=self.name,
66
+ context=context,
67
+ )
68
+ )
69
+
70
+ def report_success(self, message: str, context: dict = None):
71
+ self._event_bus.publish(
72
+ ReportEvent(
73
+ subtype=ReportSubtype.SUCCESS,
74
+ message=message,
75
+ action=None,
76
+ tool=self.name,
77
+ context=context,
78
+ )
79
+ )
80
+
81
+ def report_warning(self, message: str, context: dict = None):
82
+ self._event_bus.publish(
83
+ ReportEvent(
84
+ subtype=ReportSubtype.WARNING,
85
+ message=message,
86
+ action=None,
87
+ tool=self.name,
88
+ context=context,
89
+ )
90
+ )
91
+
92
+ def report_stdout(self, message: str, context: dict = None):
93
+ self._event_bus.publish(
94
+ ReportEvent(
95
+ subtype=ReportSubtype.STDOUT,
96
+ message=message,
97
+ action=None,
98
+ tool=self.name,
99
+ context=context,
100
+ )
101
+ )
102
+
103
+ def report_stderr(self, message: str, context: dict = None):
104
+ self._event_bus.publish(
105
+ ReportEvent(
106
+ subtype=ReportSubtype.STDERR,
107
+ message=message,
108
+ action=None,
109
+ tool=self.name,
110
+ context=context,
111
+ )
112
+ )
113
+
114
+ def run(self, *args, **kwargs):
115
+ raise NotImplementedError("Subclasses must implement the run method.")
116
+
117
+ def get_signature(self):
118
+ """
119
+ Return the function signature for this tool's run method.
120
+ This is used for introspection and validation.
121
+ """
122
+ return inspect.signature(self.run)
@@ -1,104 +1,104 @@
1
- import inspect
2
- import typing
3
- import re
4
-
5
-
6
- class ToolSchemaBase:
7
- def parse_param_section(self, lines, param_section_headers):
8
- param_descs = {}
9
- in_params = False
10
- for line in lines:
11
- stripped_line = line.strip()
12
- if any(
13
- stripped_line.lower().startswith(h + ":") or stripped_line.lower() == h
14
- for h in param_section_headers
15
- ):
16
- in_params = True
17
- continue
18
- if in_params:
19
- m = re.match(
20
- r"([a-zA-Z_][a-zA-Z0-9_]*)\s*(?:\(([^)]+)\))?\s*[:\-]?\s*(.+)",
21
- stripped_line,
22
- )
23
- if m:
24
- param, _, desc = m.groups()
25
- param_descs[param] = desc.strip()
26
- elif stripped_line and stripped_line[0] != "-":
27
- if param_descs:
28
- last = list(param_descs)[-1]
29
- param_descs[last] += " " + stripped_line
30
- if (
31
- stripped_line.lower().startswith("returns:")
32
- or stripped_line.lower() == "returns"
33
- ):
34
- break
35
- return param_descs
36
-
37
- def parse_return_section(self, lines):
38
- in_returns = False
39
- return_desc = ""
40
- for line in lines:
41
- stripped_line = line.strip()
42
- if (
43
- stripped_line.lower().startswith("returns:")
44
- or stripped_line.lower() == "returns"
45
- ):
46
- in_returns = True
47
- continue
48
- if in_returns:
49
- if stripped_line:
50
- return_desc += (" " if return_desc else "") + stripped_line
51
- return return_desc
52
-
53
- def parse_docstring(self, docstring: str):
54
- if not docstring:
55
- return "", {}, ""
56
- lines = docstring.strip().split("\n")
57
- summary = lines[0].strip()
58
- param_section_headers = ("args", "arguments", "params", "parameters")
59
- param_descs = self.parse_param_section(lines[1:], param_section_headers)
60
- return_desc = self.parse_return_section(lines[1:])
61
- return summary, param_descs, return_desc
62
-
63
- def validate_tool_class(self, tool_class):
64
- if not hasattr(tool_class, "tool_name") or not isinstance(
65
- tool_class.tool_name, str
66
- ):
67
- raise ValueError(
68
- "Tool class must have a class-level 'tool_name' attribute (str) for registry and schema generation."
69
- )
70
- if not hasattr(tool_class, "run") or not callable(getattr(tool_class, "run")):
71
- raise ValueError("Tool class must have a callable 'run' method.")
72
- func = tool_class.run
73
- tool_name = tool_class.tool_name
74
- sig = inspect.signature(func)
75
- if sig.return_annotation is inspect._empty or sig.return_annotation is not str:
76
- raise ValueError(
77
- f"Tool '{tool_name}' must have an explicit return type of 'str'. Found: {sig.return_annotation}"
78
- )
79
- missing_type_hints = [
80
- name
81
- for name, param in sig.parameters.items()
82
- if name != "self" and param.annotation is inspect._empty
83
- ]
84
- if missing_type_hints:
85
- raise ValueError(
86
- f"Tool '{tool_name}' is missing type hints for parameter(s): {', '.join(missing_type_hints)}.\nAll parameters must have explicit type hints for schema generation."
87
- )
88
- class_doc = (
89
- tool_class.__doc__.strip() if tool_class and tool_class.__doc__ else ""
90
- )
91
- summary, param_descs, return_desc = self.parse_docstring(class_doc)
92
- description = summary
93
- if return_desc:
94
- description += f"\n\nReturns: {return_desc}"
95
- undocumented = [
96
- name
97
- for name, param in sig.parameters.items()
98
- if name != "self" and name not in param_descs
99
- ]
100
- if undocumented:
101
- raise ValueError(
102
- f"Tool '{tool_name}' is missing docstring documentation for parameter(s): {', '.join(undocumented)}.\nParameter documentation must be provided in the Tool class docstring, not the method docstring."
103
- )
104
- return func, tool_name, sig, summary, param_descs, return_desc, description
1
+ import inspect
2
+ import typing
3
+ import re
4
+
5
+
6
+ class ToolSchemaBase:
7
+ def parse_param_section(self, lines, param_section_headers):
8
+ param_descs = {}
9
+ in_params = False
10
+ for line in lines:
11
+ stripped_line = line.strip()
12
+ if any(
13
+ stripped_line.lower().startswith(h + ":") or stripped_line.lower() == h
14
+ for h in param_section_headers
15
+ ):
16
+ in_params = True
17
+ continue
18
+ if in_params:
19
+ m = re.match(
20
+ r"([a-zA-Z_][a-zA-Z0-9_]*)\s*(?:\(([^)]+)\))?\s*[:\-]?\s*(.+)",
21
+ stripped_line,
22
+ )
23
+ if m:
24
+ param, _, desc = m.groups()
25
+ param_descs[param] = desc.strip()
26
+ elif stripped_line and stripped_line[0] != "-":
27
+ if param_descs:
28
+ last = list(param_descs)[-1]
29
+ param_descs[last] += " " + stripped_line
30
+ if (
31
+ stripped_line.lower().startswith("returns:")
32
+ or stripped_line.lower() == "returns"
33
+ ):
34
+ break
35
+ return param_descs
36
+
37
+ def parse_return_section(self, lines):
38
+ in_returns = False
39
+ return_desc = ""
40
+ for line in lines:
41
+ stripped_line = line.strip()
42
+ if (
43
+ stripped_line.lower().startswith("returns:")
44
+ or stripped_line.lower() == "returns"
45
+ ):
46
+ in_returns = True
47
+ continue
48
+ if in_returns:
49
+ if stripped_line:
50
+ return_desc += (" " if return_desc else "") + stripped_line
51
+ return return_desc
52
+
53
+ def parse_docstring(self, docstring: str):
54
+ if not docstring:
55
+ return "", {}, ""
56
+ lines = docstring.strip().split("\n")
57
+ summary = lines[0].strip()
58
+ param_section_headers = ("args", "arguments", "params", "parameters")
59
+ param_descs = self.parse_param_section(lines[1:], param_section_headers)
60
+ return_desc = self.parse_return_section(lines[1:])
61
+ return summary, param_descs, return_desc
62
+
63
+ def validate_tool_class(self, tool_class):
64
+ # Create instance to get tool_name property
65
+ instance = tool_class()
66
+ tool_name = instance.tool_name
67
+ if not tool_name or not isinstance(tool_name, str):
68
+ raise ValueError(
69
+ "Tool class must have a valid 'tool_name' property for registry and schema generation."
70
+ )
71
+ if not hasattr(tool_class, "run") or not callable(getattr(tool_class, "run")):
72
+ raise ValueError("Tool class must have a callable 'run' method.")
73
+ func = tool_class.run
74
+ sig = inspect.signature(func)
75
+ if sig.return_annotation is inspect._empty or sig.return_annotation is not str:
76
+ raise ValueError(
77
+ f"Tool '{tool_name}' must have an explicit return type of 'str'. Found: {sig.return_annotation}"
78
+ )
79
+ missing_type_hints = [
80
+ name
81
+ for name, param in sig.parameters.items()
82
+ if name != "self" and param.annotation is inspect._empty
83
+ ]
84
+ if missing_type_hints:
85
+ raise ValueError(
86
+ f"Tool '{tool_name}' is missing type hints for parameter(s): {', '.join(missing_type_hints)}.\nAll parameters must have explicit type hints for schema generation."
87
+ )
88
+ class_doc = (
89
+ tool_class.__doc__.strip() if tool_class and tool_class.__doc__ else ""
90
+ )
91
+ summary, param_descs, return_desc = self.parse_docstring(class_doc)
92
+ description = summary
93
+ if return_desc:
94
+ description += f"\n\nReturns: {return_desc}"
95
+ undocumented = [
96
+ name
97
+ for name, param in sig.parameters.items()
98
+ if name != "self" and name not in param_descs
99
+ ]
100
+ if undocumented:
101
+ raise ValueError(
102
+ f"Tool '{tool_name}' is missing docstring documentation for parameter(s): {', '.join(undocumented)}.\nParameter documentation must be provided in the Tool class docstring, not the method docstring."
103
+ )
104
+ return func, tool_name, sig, summary, param_descs, return_desc, description
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: janito
3
- Version: 3.14.1
3
+ Version: 3.15.0
4
4
  Summary: A new Python package called janito.
5
5
  Author-email: João Pinto <janito@ikignosis.org>
6
6
  Project-URL: Homepage, https://github.com/ikignosis/janito
@@ -40,7 +40,7 @@ Dynamic: license-file
40
40
  $ janito --help
41
41
  Usage: janito <command>
42
42
 
43
- Interact with Nine API resources. See https://docs.nineapis.ch for the full API docs.
43
+ A command-line tool for managing your projects.
44
44
 
45
45
  Run "janito <command> --help" for more information on a command.
46
46
  ```
@@ -48,38 +48,15 @@ Run "janito <command> --help" for more information on a command.
48
48
  ## Setup
49
49
 
50
50
  ```bash
51
- # If you have go already installed
52
- go install github.com/ninech/janito@latest
51
+ # Install using pip
52
+ pip install janito
53
53
 
54
- # Homebrew
55
- brew install ninech/taps/janito
56
-
57
- # Debian/Ubuntu
58
- echo "deb [trusted=yes] https://repo.nine.ch/deb/ /" | sudo tee /etc/apt/sources.list.d/repo.nine.ch.list
59
- sudo apt-get update
60
- sudo apt-get install janito
61
-
62
- # Fedora/RHEL
63
- cat <<EOF > /etc/yum.repos.d/repo.nine.ch.repo
64
- [repo.nine.ch]
65
- name=Nine Repo
66
- baseurl=https://repo.nine.ch/yum/
67
- enabled=1
68
- gpgcheck=0
69
- EOF
70
- dnf install janito
71
-
72
- # Arch
73
- # Install yay: https://github.com/Jguer/yay#binary
74
- yay --version
75
- yay -S janito-bin
54
+ # Or install from source
55
+ git clone https://github.com/yourusername/janito.git
56
+ cd janito
57
+ pip install -e .
76
58
  ```
77
59
 
78
- For Windows users, janito is also built for arm64 and amd64. You can download the
79
- latest exe file from the [releases](https://github.com/ninech/janito/releases) and
80
- install it.
81
-
82
60
  ## Getting started
83
61
 
84
- * login to the API using `janito auth login`
85
- * run `janito --help` to get a list of all available commands
62
+ * Run `janito --help` to get a list of all available commands