tass 0.1.0__tar.gz
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.
- tass-0.1.0/.gitignore +3 -0
- tass-0.1.0/.python-version +1 -0
- tass-0.1.0/LICENSE +202 -0
- tass-0.1.0/PKG-INFO +36 -0
- tass-0.1.0/README.md +23 -0
- tass-0.1.0/pyproject.toml +41 -0
- tass-0.1.0/src/__init__.py +7 -0
- tass-0.1.0/src/app.py +186 -0
- tass-0.1.0/src/cli.py +6 -0
- tass-0.1.0/src/constants.py +94 -0
- tass-0.1.0/src/third_party/README.md +1 -0
- tass-0.1.0/src/third_party/__init__.py +0 -0
- tass-0.1.0/src/third_party/apply_patch.md +64 -0
- tass-0.1.0/src/third_party/apply_patch.py +529 -0
- tass-0.1.0/src/utils.py +18 -0
- tass-0.1.0/tests/test_utils.py +23 -0
- tass-0.1.0/uv.lock +354 -0
tass-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
tass-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
tass-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tass
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A terminal assistant that allows you to ask an LLM to run commands.
|
|
5
|
+
Project-URL: Homepage, https://github.com/cetincan0/tass
|
|
6
|
+
Author: Can Cetin
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: requests>=2.32.5
|
|
11
|
+
Requires-Dist: rich>=14.2.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# tass
|
|
15
|
+
|
|
16
|
+
A terminal assistant that allows you to ask an LLM to run commands.
|
|
17
|
+
|
|
18
|
+
## Warning
|
|
19
|
+
|
|
20
|
+
This tool can run commands including ones that can modify, move, or delete files. Use at your own risk.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
uv tools install tass
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
You can run it with
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
tass
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
tass has only been tested with gpt-oss-120b using llama.cpp so far, but in theory any LLM with tool calling capabilities should work. By default, it will try connecting to http://localhost:8080. If you want to use another host, set the `TASS_HOST` environment variable.
|
|
35
|
+
|
|
36
|
+
Once it's running, you can ask questions like "Can you create an empty file called test.txt?" and it will propose a command to run after user confirmation.
|
tass-0.1.0/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# tass
|
|
2
|
+
|
|
3
|
+
A terminal assistant that allows you to ask an LLM to run commands.
|
|
4
|
+
|
|
5
|
+
## Warning
|
|
6
|
+
|
|
7
|
+
This tool can run commands including ones that can modify, move, or delete files. Use at your own risk.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
uv tools install tass
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You can run it with
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
tass
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
tass has only been tested with gpt-oss-120b using llama.cpp so far, but in theory any LLM with tool calling capabilities should work. By default, it will try connecting to http://localhost:8080. If you want to use another host, set the `TASS_HOST` environment variable.
|
|
22
|
+
|
|
23
|
+
Once it's running, you can ask questions like "Can you create an empty file called test.txt?" and it will propose a command to run after user confirmation.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tass"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A terminal assistant that allows you to ask an LLM to run commands."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = {text = "Apache-2.0"}
|
|
8
|
+
authors = [{name = "Can Cetin"}]
|
|
9
|
+
|
|
10
|
+
dependencies = [
|
|
11
|
+
"requests>=2.32.5",
|
|
12
|
+
"rich>=14.2.0",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build.targets.wheel]
|
|
16
|
+
packages = ["src/"]
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://github.com/cetincan0/tass"
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
tass = "src.cli:main"
|
|
23
|
+
|
|
24
|
+
[tool.uv]
|
|
25
|
+
package = true
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
30
|
+
|
|
31
|
+
[dependency-groups]
|
|
32
|
+
dev = [
|
|
33
|
+
"ruff>=0.14.9",
|
|
34
|
+
"pytest>=9.0.2",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[tool.pyright]
|
|
38
|
+
pythonVersion = "3.10"
|
|
39
|
+
include = ["src/**/*.py"]
|
|
40
|
+
venvPath = "."
|
|
41
|
+
venv = ".venv"
|
tass-0.1.0/src/app.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.markdown import Markdown
|
|
8
|
+
|
|
9
|
+
from src.constants import (
|
|
10
|
+
SYSTEM_PROMPT,
|
|
11
|
+
TOOLS,
|
|
12
|
+
)
|
|
13
|
+
from src.third_party.apply_patch import apply_patch
|
|
14
|
+
from src.utils import (
|
|
15
|
+
is_read_only_command,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
console = Console()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TassApp:
|
|
22
|
+
|
|
23
|
+
def __init__(self):
|
|
24
|
+
self.messages: list[dict] = [{"role": "system", "content": SYSTEM_PROMPT}]
|
|
25
|
+
self.host = os.environ.get("TASS_HOST", "http://localhost:8080")
|
|
26
|
+
self.TOOLS_MAP = {
|
|
27
|
+
"execute": self.execute,
|
|
28
|
+
"apply_patch": self.apply_patch_tass,
|
|
29
|
+
"read_file": self.read_file,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def call_llm(self) -> str | None:
|
|
33
|
+
response = requests.post(
|
|
34
|
+
f"{self.host}/v1/chat/completions",
|
|
35
|
+
json={
|
|
36
|
+
"messages": self.messages,
|
|
37
|
+
"tools": TOOLS,
|
|
38
|
+
"chat_template_kwargs": {
|
|
39
|
+
"reasoning_effort": "medium",
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
data = response.json()
|
|
45
|
+
if "tool_calls" in data["choices"][0]["message"]:
|
|
46
|
+
tool_name = data["choices"][0]["message"]["tool_calls"][0]["function"]["name"]
|
|
47
|
+
tool_args_str = data["choices"][0]["message"]["tool_calls"][0]["function"]["arguments"]
|
|
48
|
+
self.messages.append(
|
|
49
|
+
{
|
|
50
|
+
"role": "assistant",
|
|
51
|
+
"tool_calls": [
|
|
52
|
+
{
|
|
53
|
+
"index": 0,
|
|
54
|
+
"id": "id1",
|
|
55
|
+
"type": "function",
|
|
56
|
+
"function": {
|
|
57
|
+
"name": tool_name,
|
|
58
|
+
"arguments": tool_args_str
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
try:
|
|
65
|
+
tool = self.TOOLS_MAP[tool_name]
|
|
66
|
+
tool_args = json.loads(tool_args_str)
|
|
67
|
+
result = tool(**tool_args)
|
|
68
|
+
self.messages.append({"role": "tool", "content": result})
|
|
69
|
+
except Exception as e:
|
|
70
|
+
self.messages.append({"role": "user", "content": str(e)})
|
|
71
|
+
return self.call_llm()
|
|
72
|
+
|
|
73
|
+
return data["choices"][0]["message"]["content"]
|
|
74
|
+
|
|
75
|
+
def read_file(self, path: str, start: int = 1) -> str:
|
|
76
|
+
console.print(f" └ Reading file [bold]{path}[/] (start={start})...")
|
|
77
|
+
|
|
78
|
+
lines = []
|
|
79
|
+
with open(path) as f:
|
|
80
|
+
line_num = 1
|
|
81
|
+
for line in f:
|
|
82
|
+
if line_num < start:
|
|
83
|
+
line_num += 1
|
|
84
|
+
continue
|
|
85
|
+
|
|
86
|
+
lines.append(line)
|
|
87
|
+
line_num += 1
|
|
88
|
+
|
|
89
|
+
if len(lines) >= 1000:
|
|
90
|
+
break
|
|
91
|
+
|
|
92
|
+
console.print(" [green]Command succeeded[/green]")
|
|
93
|
+
return "".join(lines)
|
|
94
|
+
|
|
95
|
+
def apply_patch_tass(self, patch: str) -> str:
|
|
96
|
+
console.print()
|
|
97
|
+
console.print(Markdown(f"```diff\n{patch}\n```"))
|
|
98
|
+
answer = console.input("\n[bold]Run?[/] ([bold]Y[/]/n): ").strip().lower()
|
|
99
|
+
if answer not in ("yes", "y", ""):
|
|
100
|
+
reason = console.input("Why not? (optional, press Enter to skip): ").strip()
|
|
101
|
+
return f"User declined: {reason or 'no reason'}"
|
|
102
|
+
|
|
103
|
+
console.print(" └ Running...")
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
apply_patch(patch)
|
|
107
|
+
except Exception as e:
|
|
108
|
+
console.print(" [red]apply_patch failed[/red]")
|
|
109
|
+
console.print(f" [red]{str(e)}[/red]")
|
|
110
|
+
return f"apply_patch failed: {str(e)}"
|
|
111
|
+
|
|
112
|
+
console.print(" [green]Command succeeded[/green]")
|
|
113
|
+
|
|
114
|
+
return "Command output (exit 0): apply_patch succeeded"
|
|
115
|
+
|
|
116
|
+
def execute(self, command: str, explanation: str) -> str:
|
|
117
|
+
command = command.strip()
|
|
118
|
+
requires_confirmation = not is_read_only_command(command)
|
|
119
|
+
if requires_confirmation:
|
|
120
|
+
console.print()
|
|
121
|
+
console.print(Markdown(f"```shell\n{command}\n```"))
|
|
122
|
+
if explanation:
|
|
123
|
+
console.print(f"Explanation: {explanation}")
|
|
124
|
+
answer = console.input("\n[bold]Run?[/] ([bold]Y[/]/n): ").strip().lower()
|
|
125
|
+
if answer not in ("yes", "y", ""):
|
|
126
|
+
reason = console.input("Why not? (optional, press Enter to skip): ").strip()
|
|
127
|
+
return f"User declined: {reason or 'no reason'}"
|
|
128
|
+
|
|
129
|
+
if requires_confirmation:
|
|
130
|
+
console.print(" └ Running...")
|
|
131
|
+
else:
|
|
132
|
+
console.print(f" └ Running [bold]{command}[/] (Explanation: {explanation})...")
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
result = subprocess.run(
|
|
136
|
+
command,
|
|
137
|
+
shell=True,
|
|
138
|
+
capture_output=True,
|
|
139
|
+
text=True,
|
|
140
|
+
)
|
|
141
|
+
except Exception as e:
|
|
142
|
+
console.print(" [red]subprocess.run failed[/red]")
|
|
143
|
+
console.print(f" [red]{str(e)}[/red]")
|
|
144
|
+
return f"subprocess.run failed: {str(e)}"
|
|
145
|
+
|
|
146
|
+
out = result.stdout.strip()
|
|
147
|
+
err = result.stderr.strip()
|
|
148
|
+
if result.returncode == 0:
|
|
149
|
+
console.print(" [green]Command succeeded[/green]")
|
|
150
|
+
else:
|
|
151
|
+
console.print(f" [red]Command failed[/red] (code {result.returncode})")
|
|
152
|
+
console.print(f" [red]{err}[/red]")
|
|
153
|
+
|
|
154
|
+
if len(out) > 5000:
|
|
155
|
+
out = f"{out[:5000]}... (Truncated)"
|
|
156
|
+
|
|
157
|
+
if len(err) > 5000:
|
|
158
|
+
err = f"{err[:5000]}... (Truncated)"
|
|
159
|
+
|
|
160
|
+
return f"Command output (exit {result.returncode}):\n{out}\n{err}"
|
|
161
|
+
|
|
162
|
+
def run(self):
|
|
163
|
+
console.print("Terminal Assistant")
|
|
164
|
+
|
|
165
|
+
while True:
|
|
166
|
+
try:
|
|
167
|
+
user_input = console.input("\n> ").strip()
|
|
168
|
+
except KeyboardInterrupt:
|
|
169
|
+
console.print("\nBye!")
|
|
170
|
+
break
|
|
171
|
+
|
|
172
|
+
if not user_input:
|
|
173
|
+
continue
|
|
174
|
+
|
|
175
|
+
if user_input.lower().strip() == "exit":
|
|
176
|
+
console.print("\nBye!")
|
|
177
|
+
break
|
|
178
|
+
|
|
179
|
+
self.messages.append({"role": "user", "content": user_input})
|
|
180
|
+
|
|
181
|
+
while True:
|
|
182
|
+
llm_resp = self.call_llm()
|
|
183
|
+
if llm_resp is not None:
|
|
184
|
+
console.print("")
|
|
185
|
+
console.print(Markdown(llm_resp))
|
|
186
|
+
break
|
tass-0.1.0/src/cli.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
_apply_patch_path = Path(__file__).resolve().parent / "third_party" / "apply_patch.md"
|
|
4
|
+
APPLY_PATCH_PROMPT = _apply_patch_path.read_text().strip()
|
|
5
|
+
|
|
6
|
+
SYSTEM_PROMPT = f"""You are Terminal-Assistant, a helpful AI that executes shell commands based on natural-language requests.
|
|
7
|
+
|
|
8
|
+
If the user's request involves making changes to the filesystem such as creating or deleting files or directories, you MUST first check whether the file or directory exists before proceeding.
|
|
9
|
+
|
|
10
|
+
If a user asks for an answer or explanation to something instead of requesting to run a command, answer briefly and concisely. Do not supply extra information, suggestions, tips, or anything of the sort.
|
|
11
|
+
|
|
12
|
+
{APPLY_PATCH_PROMPT}"""
|
|
13
|
+
|
|
14
|
+
TOOLS = [
|
|
15
|
+
{
|
|
16
|
+
"type": "function",
|
|
17
|
+
"function": {
|
|
18
|
+
"name": "execute",
|
|
19
|
+
"description": "Executes a shell command.",
|
|
20
|
+
"parameters": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"command": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Full shell command to be executed.",
|
|
26
|
+
},
|
|
27
|
+
"explanation": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "A brief explanation of why you want to run this command.",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
"required": ["command", "explanation"],
|
|
33
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"type": "function",
|
|
39
|
+
"function": {
|
|
40
|
+
"name": "apply_patch",
|
|
41
|
+
"description": "Patch a file",
|
|
42
|
+
"parameters": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"properties": {
|
|
45
|
+
"patch": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "Formatted patch code",
|
|
48
|
+
"default": "*** Begin Patch\n*** End Patch\n",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
"required": ["patch"],
|
|
52
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"type": "function",
|
|
58
|
+
"function": {
|
|
59
|
+
"name": "read_file",
|
|
60
|
+
"description": "Read a file's contents (up to 1000 lines)",
|
|
61
|
+
"parameters": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"properties": {
|
|
64
|
+
"path": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "Relative path of the file",
|
|
67
|
+
},
|
|
68
|
+
"start": {
|
|
69
|
+
"type": "integer",
|
|
70
|
+
"description": "Which line to start reading from",
|
|
71
|
+
"default": 1,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
"required": ["path"],
|
|
75
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
READ_ONLY_COMMANDS = [
|
|
82
|
+
"ls",
|
|
83
|
+
"cat",
|
|
84
|
+
"less",
|
|
85
|
+
"more",
|
|
86
|
+
"echo",
|
|
87
|
+
"tail",
|
|
88
|
+
"wc",
|
|
89
|
+
"grep",
|
|
90
|
+
"find",
|
|
91
|
+
"ack",
|
|
92
|
+
"which",
|
|
93
|
+
"sed",
|
|
94
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
These files are taken directly from https://github.com/openai/gpt-oss to assist with gpt-oss-120b's code editing capabilities. No modifications have been made.
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
When requested to perform coding-related tasks, you MUST adhere to the following criteria when executing the task:
|
|
2
|
+
|
|
3
|
+
- Use `apply_patch` to edit files.
|
|
4
|
+
- If completing the user's task requires writing or modifying files:
|
|
5
|
+
- Your code and final answer should follow these _CODING GUIDELINES_:
|
|
6
|
+
- Avoid unneeded complexity in your solution. Minimize program size.
|
|
7
|
+
- Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.
|
|
8
|
+
- NEVER add copyright or license headers unless specifically requested.
|
|
9
|
+
- Never implement function stubs. Provide complete working implementations.
|
|
10
|
+
|
|
11
|
+
§ `apply_patch` Specification
|
|
12
|
+
|
|
13
|
+
Your patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:
|
|
14
|
+
|
|
15
|
+
*** Begin Patch
|
|
16
|
+
[ one or more file sections ]
|
|
17
|
+
*** End Patch
|
|
18
|
+
|
|
19
|
+
Within that envelope, you get a sequence of file operations.
|
|
20
|
+
You MUST include a header to specify the action you are taking.
|
|
21
|
+
Each operation starts with one of three headers:
|
|
22
|
+
|
|
23
|
+
*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).
|
|
24
|
+
*** Delete File: <path> - remove an existing file. Nothing follows.
|
|
25
|
+
*** Update File: <path> - patch an existing file in place (optionally with a rename).
|
|
26
|
+
|
|
27
|
+
May be immediately followed by *** Move to: <new path> if you want to rename the file.
|
|
28
|
+
Then one or more “hunks”, each introduced by @@ (optionally followed by a hunk header).
|
|
29
|
+
Within a hunk each line starts with:
|
|
30
|
+
|
|
31
|
+
- for inserted text,
|
|
32
|
+
|
|
33
|
+
* for removed text, or
|
|
34
|
+
space ( ) for context.
|
|
35
|
+
At the end of a truncated hunk you can emit *** End of File.
|
|
36
|
+
|
|
37
|
+
Patch := Begin { FileOp } End
|
|
38
|
+
Begin := "*** Begin Patch" NEWLINE
|
|
39
|
+
End := "*** End Patch" NEWLINE
|
|
40
|
+
FileOp := AddFile | DeleteFile | UpdateFile
|
|
41
|
+
AddFile := "*** Add File: " path NEWLINE { "+" line NEWLINE }
|
|
42
|
+
DeleteFile := "*** Delete File: " path NEWLINE
|
|
43
|
+
UpdateFile := "*** Update File: " path NEWLINE [ MoveTo ] { Hunk }
|
|
44
|
+
MoveTo := "*** Move to: " newPath NEWLINE
|
|
45
|
+
Hunk := "@@" [ header ] NEWLINE { HunkLine } [ "*** End of File" NEWLINE ]
|
|
46
|
+
HunkLine := (" " | "-" | "+") text NEWLINE
|
|
47
|
+
|
|
48
|
+
A full patch can combine several operations:
|
|
49
|
+
|
|
50
|
+
*** Begin Patch
|
|
51
|
+
*** Add File: hello.txt
|
|
52
|
+
+Hello world
|
|
53
|
+
*** Update File: src/app.py
|
|
54
|
+
*** Move to: src/main.py
|
|
55
|
+
@@ def greet():
|
|
56
|
+
-print("Hi")
|
|
57
|
+
+print("Hello, world!")
|
|
58
|
+
*** Delete File: obsolete.txt
|
|
59
|
+
*** End Patch
|
|
60
|
+
|
|
61
|
+
It is important to remember:
|
|
62
|
+
|
|
63
|
+
- You must include a header with your intended action (Add/Delete/Update)
|
|
64
|
+
- You must prefix new lines with `+` even when creating a new file
|