Skip to content

Commit 604121e

Browse files
committed
Fix readme and cli err on linux
1 parent c06ac91 commit 604121e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

plugins/communication_protocols/cli/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ Some commands work across platforms:
179179

180180
- Commands execute in isolated subprocesses with controlled environment
181181
- Environment variables provide secure credential passing
182-
- Working directory restrictions limit file system access
183-
- UTCP_ARG placeholders prevent command injection
184182
- Previous command outputs should be used carefully to avoid injection
185183
- Commands should use platform-appropriate syntax
186184

plugins/communication_protocols/cli/src/utcp_cli/cli_communication_protocol.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,14 @@ async def register_manual(self, caller, manual_call_template: CallTemplate) -> R
174174
)
175175

176176
try:
177-
# For discovery, use the first command only
178-
first_command = manual_call_template.commands[0]
179-
177+
# Execute commands using the same approach as call_tool but with no arguments
180178
env = self._prepare_environment(manual_call_template)
181-
# Parse command string into proper arguments
182-
# Use posix=False on Windows, posix=True on Unix-like systems
183-
command = shlex.split(first_command.command, posix=(os.name != 'nt'))
184-
185-
self._log_info(f"Executing command for tool discovery: {' '.join(command)}")
179+
shell_script = self._build_combined_shell_script(manual_call_template.commands, {})
180+
181+
self._log_info(f"Executing shell script for tool discovery from provider '{manual_call_template.name}'")
186182

187-
stdout, stderr, return_code = await self._execute_command(
188-
command,
183+
stdout, stderr, return_code = await self._execute_shell_script(
184+
shell_script,
189185
env,
190186
timeout=30.0,
191187
working_dir=manual_call_template.working_dir,
@@ -196,14 +192,14 @@ async def register_manual(self, caller, manual_call_template: CallTemplate) -> R
196192

197193
if not output.strip():
198194
self._log_info(
199-
f"No output from command '{manual_call_template.command_name}'"
195+
f"No output from commands for CLI provider '{manual_call_template.name}'"
200196
)
201197
return RegisterManualResult(
202198
success=False,
203199
manual_call_template=manual_call_template,
204200
manual=UtcpManual(manual_version="0.0.0", tools=[]),
205201
errors=[
206-
f"No output from discovery command for CLI provider '{manual_call_template.name}'"
202+
f"No output from discovery commands for CLI provider '{manual_call_template.name}'"
207203
],
208204
)
209205

@@ -415,8 +411,14 @@ def _parse_combined_output(self, stdout: str, stderr: str, return_code: int, com
415411
Returns:
416412
Final output from script (already filtered by append_to_final_output)
417413
"""
418-
# Use stdout if successful, stderr if failed
419-
output = stdout if return_code == 0 else stderr
414+
# Platform-specific output handling
415+
if os.name == 'nt':
416+
# Windows (PowerShell): Use stdout on success, stderr on failure
417+
output = stdout if return_code == 0 else stderr
418+
else:
419+
# Unix (Bash): Our script captures everything and echoes to stdout
420+
# So we always use stdout first, fallback to stderr if stdout is empty
421+
output = stdout if stdout.strip() else stderr
420422

421423
if not output.strip():
422424
self._log_info(f"CLI tool '{tool_name}' produced no output")

0 commit comments

Comments
 (0)