tass 0.1.4__py3-none-any.whl → 0.1.5__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.
src/app.py CHANGED
@@ -124,16 +124,30 @@ class TassApp:
124
124
  return self.call_llm()
125
125
 
126
126
  def read_file(self, path: str, start: int = 1) -> str:
127
- console.print(f" Reading file [bold]{path}[/]...")
127
+ if start == 1:
128
+ console.print(f" └ Reading file [bold]{path}[/]...")
129
+ else:
130
+ console.print(f" └ Reading file [bold]{path}[/] (from line {start})...")
128
131
 
129
132
  try:
130
- with open(path) as f:
131
- out = f.read()
133
+ result = subprocess.run(
134
+ f"cat -n {path}",
135
+ shell=True,
136
+ capture_output=True,
137
+ text=True,
138
+ )
132
139
  except Exception as e:
133
140
  console.print(" [red]read_file failed[/red]")
134
141
  console.print(f" [red]{str(e)}[/red]")
135
142
  return f"read_file failed: {str(e)}"
136
143
 
144
+ out = result.stdout
145
+ err = result.stderr
146
+ if result.returncode != 0:
147
+ console.print(" [red]read_file failed[/red]")
148
+ console.print(f" [red]{err}[/red]")
149
+ return f"read_file failed: {err}"
150
+
137
151
  lines = []
138
152
  line_num = 1
139
153
  for line in out.split("\n"):
@@ -151,11 +165,22 @@ class TassApp:
151
165
  console.print(" [green]Command succeeded[/green]")
152
166
  return "".join(lines)
153
167
 
154
- def edit_file(self, path: str, find: str, replace: str) -> str:
155
- find_with_minuses = "\n".join([f"-{line}" for line in find.split("\n")])
168
+ def edit_file(self, path: str, line_start: int, line_end: int, replace: str) -> str:
169
+ with open(path, "r") as f:
170
+ original_content = f.read()
171
+
172
+ original_lines = original_content.split("\n")
173
+ replaced_lines = original_lines[line_start - 1:line_end]
174
+ new_content = "\n".join(
175
+ original_lines[:line_start - 1]
176
+ + replace.split("\n")
177
+ + original_lines[line_end:]
178
+ )
179
+
180
+ replaced_with_minuses = "\n".join([f"-{line}" for line in replaced_lines])
156
181
  replace_with_pluses = "\n".join([f"+{line}" for line in replace.split("\n")])
157
182
  console.print()
158
- console.print(Markdown(f"```diff\nEditing {path}\n{find_with_minuses}\n{replace_with_pluses}\n```"))
183
+ console.print(Markdown(f"```diff\nEditing {path}\n{replaced_with_minuses}\n{replace_with_pluses}\n```"))
159
184
  answer = console.input("\n[bold]Run?[/] ([bold]Y[/]/n): ").strip().lower()
160
185
  if answer not in ("yes", "y", ""):
161
186
  reason = console.input("Why not? (optional, press Enter to skip): ").strip()
@@ -163,16 +188,6 @@ class TassApp:
163
188
 
164
189
  console.print(" └ Running...")
165
190
  try:
166
- with open(path, "r") as f:
167
- original_content = f.read()
168
-
169
- if find not in original_content:
170
- console.print(" [red]edit_file failed[/red]")
171
- console.print(f" [red]edit_file failed:\n'{find}'\nnot found in file[/red]")
172
- return f"edit_file failed: '{find}' not found in file"
173
-
174
- new_content = original_content.replace(find, replace)
175
-
176
191
  with open(path, "w") as f:
177
192
  f.write(new_content)
178
193
  except Exception as e:
src/constants.py CHANGED
@@ -37,7 +37,7 @@ TOOLS = [
37
37
  "type": "function",
38
38
  "function": {
39
39
  "name": "edit_file",
40
- "description": "Edits a file. Replaces the instance of 'find' with 'replace'. 'find' and 'replace' are exact strings.The file must be read at least once before calling this tool.",
40
+ "description": "Edits a file. Removes the contents between the lines 'line_start' and 'line_end' inclusive entirely and replaces it with 'replace'.",
41
41
  "parameters": {
42
42
  "type": "object",
43
43
  "properties": {
@@ -45,13 +45,17 @@ TOOLS = [
45
45
  "type": "string",
46
46
  "description": "Relative path of the file",
47
47
  },
48
- "find": {
49
- "type": "string",
50
- "description": "The string to find",
48
+ "line_start": {
49
+ "type": "integer",
50
+ "description": "The first line to remove the contents of (inclusive)",
51
+ },
52
+ "line_end": {
53
+ "type": "integer",
54
+ "description": "The last line to remove the contents of (inclusive)",
51
55
  },
52
56
  "replace": {
53
57
  "type": "string",
54
- "description": "The string to replace with",
58
+ "description": "The string to replace with. Must have the correct spacing and indentation for all lines.",
55
59
  },
56
60
  },
57
61
  "required": ["path", "find", "replace"],
@@ -63,7 +67,7 @@ TOOLS = [
63
67
  "type": "function",
64
68
  "function": {
65
69
  "name": "read_file",
66
- "description": "Read a file's contents (up to 1000 lines)",
70
+ "description": "Read a file's contents (up to 1000 lines). The output will be identical to calling `cat -n <path>` with preceding spaces, line number and a tab.",
67
71
  "parameters": {
68
72
  "type": "object",
69
73
  "properties": {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tass
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: A terminal assistant that allows you to ask an LLM to run commands.
5
5
  Project-URL: Homepage, https://github.com/cetincan0/tass
6
6
  Author: Can Cetin
@@ -0,0 +1,10 @@
1
+ src/__init__.py,sha256=tu2q9W5_pkq30l3tRMTGahColBAAubbLP6LaB3l3IFg,89
2
+ src/app.py,sha256=Jej2qjyBRqQREpvm6WWvd6cPy9RLzW74rYegeM8ICPI,10224
3
+ src/cli.py,sha256=op3fYcyfek_KqCCiA-Zdlc9jVZSCi036whMmR2ZjjAs,76
4
+ src/constants.py,sha256=gFIMWh38-uyh2XJdiKUsOwAh7yk4jbdfxmeJZ9yl4fw,3847
5
+ src/utils.py,sha256=rKq34DVmFbsWPy7R6Bfdvv1ztzFLPT4hUd8BFpPHjqs,681
6
+ tass-0.1.5.dist-info/METADATA,sha256=HskJ2m7qsulvtK_N5nZ_aJAcq1PH5zGMDnYMm_cjda8,1071
7
+ tass-0.1.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
8
+ tass-0.1.5.dist-info/entry_points.txt,sha256=pviKuIOuHvaQ7_YiFxatJEY8XYfh3EzVWy4LJh0v-A0,38
9
+ tass-0.1.5.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
10
+ tass-0.1.5.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- src/__init__.py,sha256=tu2q9W5_pkq30l3tRMTGahColBAAubbLP6LaB3l3IFg,89
2
- src/app.py,sha256=sTPTwDc8KjF9RpL7W5Ix0D0n8ERcWsP1WEVzLWGOKco,9779
3
- src/cli.py,sha256=op3fYcyfek_KqCCiA-Zdlc9jVZSCi036whMmR2ZjjAs,76
4
- src/constants.py,sha256=A0_PwEYo1Dpf8UC6HV7JgQwU7GlZQxKhLgwgmyoc3WY,3478
5
- src/utils.py,sha256=rKq34DVmFbsWPy7R6Bfdvv1ztzFLPT4hUd8BFpPHjqs,681
6
- tass-0.1.4.dist-info/METADATA,sha256=K1hq1AlWam-s671Nhmb0-X4jj6qAOi8Lfw27wuDxAXA,1071
7
- tass-0.1.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
8
- tass-0.1.4.dist-info/entry_points.txt,sha256=pviKuIOuHvaQ7_YiFxatJEY8XYfh3EzVWy4LJh0v-A0,38
9
- tass-0.1.4.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
10
- tass-0.1.4.dist-info/RECORD,,
File without changes