Skip to content

Commit 1725d26

Browse files
author
Your Name
committed
Add validation pipeline to address:
- #548 - #549 - #550 - #553
1 parent 4d6a12c commit 1725d26

19 files changed

Lines changed: 155 additions & 77 deletions

cecli/tools/_yield.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
2-
import json
32
import logging
43

54
from cecli.tools.utils.base_tool import BaseTool
5+
from cecli.tools.utils.helpers import ToolError
66
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
7+
from cecli.tools.validations import ToolValidations
78

89
logger = logging.getLogger(__name__)
910

@@ -150,15 +151,23 @@ async def execute(cls, coder, **kwargs):
150151
@classmethod
151152
def format_output(cls, coder, mcp_server, tool_response):
152153
color_start, color_end = color_markers(coder)
153-
params = json.loads(tool_response.function.arguments)
154154

155+
# Output header
155156
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
156157

158+
try:
159+
params = ToolValidations.validate_params(
160+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
161+
)
162+
except ToolError:
163+
coder.io.tool_error("Invalid Tool JSON")
164+
return
165+
157166
summary = params.get("summary")
158167
if summary:
159168
coder.io.tool_output("")
160169
coder.io.tool_output(f"{color_start}Summary:{color_end}")
161170
coder.io.tool_output(summary)
162171
coder.io.tool_output("")
163172

164-
tool_footer(coder=coder, tool_response=tool_response)
173+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/command.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Import necessary functions
2-
import json
32
import os
43
import platform
54

65
from cecli.helpers.background_commands import BackgroundCommandManager
76
from cecli.run_cmd import run_cmd_subprocess
87
from cecli.tools.utils.base_tool import BaseTool
8+
from cecli.tools.utils.helpers import ToolError
99
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
10+
from cecli.tools.validations import ToolValidations
1011

1112

1213
class Tool(BaseTool):
@@ -392,15 +393,17 @@ def format_output(cls, coder, mcp_server, tool_response):
392393
"""Format output for Command tool."""
393394
color_start, color_end = color_markers(coder)
394395

396+
# Output header
397+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
398+
395399
try:
396-
params = json.loads(tool_response.function.arguments)
397-
except json.JSONDecodeError:
400+
params = ToolValidations.validate_params(
401+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
402+
)
403+
except ToolError:
398404
coder.io.tool_error("Invalid Tool JSON")
399405
return
400406

401-
# Output header
402-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
403-
404407
command = params.get("command", "")
405408
background = params.get("background", False)
406409
stop = params.get("stop", False)
@@ -430,4 +433,4 @@ def format_output(cls, coder, mcp_server, tool_response):
430433
coder.io.tool_output("")
431434

432435
# Output footer
433-
tool_footer(coder=coder, tool_response=tool_response)
436+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/context_manager.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import os
32
import re
43
import time
@@ -7,6 +6,7 @@
76
from cecli.tools.utils.base_tool import BaseTool
87
from cecli.tools.utils.helpers import ToolError, parse_arg_as_list
98
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
9+
from cecli.tools.validations import ToolValidations
1010

1111

1212
class Tool(BaseTool):
@@ -121,14 +121,17 @@ def format_output(cls, coder, mcp_server, tool_response):
121121
"""Format output for ContextManager tool."""
122122
color_start, color_end = color_markers(coder)
123123

124+
# Output header
125+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
126+
124127
try:
125-
params = json.loads(tool_response.function.arguments)
126-
except json.JSONDecodeError:
128+
params = ToolValidations.validate_params(
129+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
130+
)
131+
except ToolError:
127132
coder.io.tool_error("Invalid Tool JSON")
128133
return
129134

130-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
131-
132135
# Define action display names
133136
action_names = {
134137
"create": "create",
@@ -145,7 +148,7 @@ def format_output(cls, coder, mcp_server, tool_response):
145148
file_list = ", ".join(files)
146149
coder.io.tool_output(f"{color_start}{display_name}:{color_end} {file_list}")
147150

148-
tool_footer(coder=coder, tool_response=tool_response)
151+
tool_footer(coder=coder, tool_response=tool_response, params=params)
149152

150153
@classmethod
151154
def _remove(cls, coder, file_path):

cecli/tools/delegate.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Delegate tool - allows the primary agent to spawn sub-agents."""
22

33
import asyncio
4-
import json
54

65
from cecli.tools.utils.base_tool import BaseTool
6+
from cecli.tools.utils.helpers import ToolError
77
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
8+
from cecli.tools.validations import ToolValidations
89

910

1011
class Tool(BaseTool):
@@ -103,14 +104,17 @@ def format_output(cls, coder, mcp_server, tool_response):
103104
"""Format output for Delegate tool - show each delegation's agent and task."""
104105
color_start, color_end = color_markers(coder)
105106

107+
# Output header
108+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
109+
106110
try:
107-
params = json.loads(tool_response.function.arguments)
108-
except json.JSONDecodeError:
111+
params = ToolValidations.validate_params(
112+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
113+
)
114+
except ToolError:
109115
coder.io.tool_error("Invalid Tool JSON")
110116
return
111117

112-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
113-
114118
delegations = params.get("delegations", [])
115119
if delegations:
116120
coder.io.tool_output("")
@@ -123,4 +127,4 @@ def format_output(cls, coder, mcp_server, tool_response):
123127
if i < len(delegations) - 1:
124128
coder.io.tool_output("")
125129

126-
tool_footer(coder=coder, tool_response=tool_response)
130+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/edit_text.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
from cecli.helpers.hashline import (
42
ContentHashError,
53
apply_hashline_operations,
@@ -15,6 +13,7 @@
1513
validate_file_for_edit,
1614
)
1715
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
16+
from cecli.tools.validations import ToolValidations
1817

1918
VALID_OPERATIONS = {"replace", "delete", "insert"}
2019
OPERATION_NOUNS = {
@@ -235,7 +234,7 @@ def execute(
235234
if new_content != original_content:
236235
file_successful_edits += len(successful_ops)
237236
else:
238-
raise ToolError("Invalid Edit - Edit Results In Same Content")
237+
raise ToolError("Invalid Edit - Update content hash bounds")
239238

240239
if len(failed_ops):
241240
for failed_op in failed_ops:
@@ -373,12 +372,16 @@ def execute(
373372
def format_output(cls, coder, mcp_server, tool_response):
374373
color_start, color_end = color_markers(coder)
375374

375+
# Output header
376+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
377+
376378
try:
377-
params = json.loads(tool_response.function.arguments)
378-
except json.JSONDecodeError:
379+
params = ToolValidations.validate_params(
380+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
381+
)
382+
except ToolError:
379383
coder.io.tool_error("Invalid Tool JSON")
380-
381-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
384+
return
382385

383386
# Group edits by file_path for display
384387
edits_by_file = {}
@@ -453,4 +456,4 @@ def format_output(cls, coder, mcp_server, tool_response):
453456
coder.io.tool_output(range_info)
454457
coder.io.tool_output("")
455458

456-
tool_footer(coder=coder, tool_response=tool_response)
459+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/explore_code.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import json
21
import os
32

43
from cecli.tools.utils.base_tool import BaseTool
54
from cecli.tools.utils.helpers import ToolError
65
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
6+
from cecli.tools.validations import ToolValidations
77

88
cwd = os.getcwd()
99

@@ -300,14 +300,17 @@ def format_output(cls, coder, mcp_server, tool_response):
300300
"""Format output for ExploreCode tool."""
301301
color_start, color_end = color_markers(coder)
302302

303+
# Output header
304+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
305+
303306
try:
304-
params = json.loads(tool_response.function.arguments)
305-
except json.JSONDecodeError:
307+
params = ToolValidations.validate_params(
308+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
309+
)
310+
except ToolError:
306311
coder.io.tool_error("Invalid Tool JSON")
307312
return
308313

309-
# Output header
310-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
311314
queries = params.get("queries", [])
312315
if queries:
313316
coder.io.tool_output("")
@@ -324,4 +327,4 @@ def format_output(cls, coder, mcp_server, tool_response):
324327
coder.io.tool_output("")
325328

326329
# Output footer
327-
tool_footer(coder=coder, tool_response=tool_response)
330+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/grep.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import shutil
32
from pathlib import Path
43

@@ -7,7 +6,9 @@
76
from cecli.helpers.hashline import strip_hashline
87
from cecli.run_cmd import run_cmd_subprocess
98
from cecli.tools.utils.base_tool import BaseTool
9+
from cecli.tools.utils.helpers import ToolError
1010
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
11+
from cecli.tools.validations import ToolValidations
1112

1213

1314
class Tool(BaseTool):
@@ -239,14 +240,17 @@ def format_output(cls, coder, mcp_server, tool_response):
239240
"""Format output for Grep tool."""
240241
color_start, color_end = color_markers(coder)
241242

243+
# Output header
244+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
245+
242246
try:
243-
params = json.loads(tool_response.function.arguments)
244-
except json.JSONDecodeError:
247+
params = ToolValidations.validate_params(
248+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
249+
)
250+
except ToolError:
245251
coder.io.tool_error("Invalid Tool JSON")
246252
return
247253

248-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
249-
250254
# Output each search operation with the requested format
251255
searches = params.get("searches", [])
252256
if searches:
@@ -281,4 +285,4 @@ def format_output(cls, coder, mcp_server, tool_response):
281285
coder.io.tool_output(formatted_query)
282286
coder.io.tool_output("")
283287

284-
tool_footer(coder=coder, tool_response=tool_response)
288+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/ls.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import json
21
import os
32

43
from cecli.tools.utils.base_tool import BaseTool
4+
from cecli.tools.utils.helpers import ToolError
55
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
6+
from cecli.tools.validations import ToolValidations
67

78

89
class Tool(BaseTool):
@@ -95,14 +96,17 @@ def format_output(cls, coder, mcp_server, tool_response):
9596
"""Format output for Ls tool."""
9697
color_start, color_end = color_markers(coder)
9798

99+
# Output header
100+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
101+
98102
try:
99-
params = json.loads(tool_response.function.arguments)
100-
except json.JSONDecodeError:
103+
params = ToolValidations.validate_params(
104+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
105+
)
106+
except ToolError:
101107
coder.io.tool_error("Invalid Tool JSON")
102108
return
103109

104-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
105-
106110
# Output the directory parameter with the requested format
107111
directory = params.get("path", "")
108112
if directory:
@@ -111,4 +115,4 @@ def format_output(cls, coder, mcp_server, tool_response):
111115
coder.io.tool_output(formatted_query)
112116
coder.io.tool_output("")
113117

114-
tool_footer(coder=coder, tool_response=tool_response)
118+
tool_footer(coder=coder, tool_response=tool_response, params=params)

cecli/tools/read_range.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import os
32
from typing import Dict, List
43

@@ -11,6 +10,7 @@
1110
resolve_paths,
1211
)
1312
from cecli.tools.utils.output import color_markers, tool_footer, tool_header
13+
from cecli.tools.validations import ToolValidations
1414

1515

1616
class Tool(BaseTool):
@@ -599,14 +599,17 @@ def format_output(cls, coder, mcp_server, tool_response):
599599
"""Format output for ReadRange tool."""
600600
color_start, color_end = color_markers(coder)
601601

602+
# Output header
603+
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
604+
602605
try:
603-
params = json.loads(tool_response.function.arguments)
604-
except json.JSONDecodeError:
606+
params = ToolValidations.validate_params(
607+
tool_response.function.arguments, cls.VALIDATIONS, cls.SCHEMA
608+
)
609+
except ToolError:
605610
coder.io.tool_error("Invalid Tool JSON")
606611
return
607612

608-
tool_header(coder=coder, mcp_server=mcp_server, tool_response=tool_response)
609-
610613
show_ops = params.get("show", [])
611614
if show_ops:
612615
coder.io.tool_output("")
@@ -623,7 +626,7 @@ def format_output(cls, coder, mcp_server, tool_response):
623626
coder.io.tool_output(formatted_query)
624627
coder.io.tool_output("")
625628

626-
tool_footer(coder=coder, tool_response=tool_response)
629+
tool_footer(coder=coder, tool_response=tool_response, params=params)
627630

628631
@classmethod
629632
def format_error(cls, coder, error_text, file_path, start_text, end_text, operation_index):

0 commit comments

Comments
 (0)