-
Notifications
You must be signed in to change notification settings - Fork 44
Can I auto encode string arguments to shell commands to simply gh operations? #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Proposal for Auto-Encoding String Arguments in Shell CommandsCurrent SituationCurrently, when working with GitHub CLI commands that require multiline content (like issue or PR descriptions), the tool writes content to temporary files on disk and references them with The core issue is properly escaping string arguments with line endings across different operating systems (Windows, macOS, Linux) when passing them directly to shell commands. Research on Available SolutionsAfter researching various approaches, I've identified several potential solutions: 1. Use existing shell escaping librariesThere are several npm packages that can help with shell escaping: shell-escape (286 dependent projects)
cross-spawn (10,000+ dependent projects)
2. Platform-specific approachShell escaping rules differ significantly between platforms:
3. Base64 encoding approachInstead of escaping, we could encode multiline content:
Example with GitHub CLI: const encodedContent = Buffer.from(content).toString('base64');
await shellExecute({
command: `echo "${encodedContent}" | base64 -d | gh issue create --body-stdin`,
description: 'Creating issue with encoded content'
}); This approach works consistently across platforms as base64 is standard. Proposed SolutionI recommend implementing a combination of approaches:
Implementation Exampleimport { spawn } from 'child_process';
import crossSpawn from 'cross-spawn';
// For simple commands with arguments that need escaping
function executeCommand(command: string, args: string[], options = {}) {
return crossSpawn(command, args, { ...options, shell: true });
}
// For commands with complex multiline input
async function executeWithEncodedInput(command: string, input: string, options = {}) {
const isWindows = process.platform === 'win32';
if (isWindows) {
// Windows-specific approach using PowerShell
const encodedCommand = Buffer.from(input).toString('base64');
return crossSpawn('powershell', [
'-Command',
`[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${encodedCommand}')) | ${command}`
], options);
} else {
// POSIX approach (Linux/macOS)
const encodedInput = Buffer.from(input).toString('base64');
const child = crossSpawn('bash', [
'-c',
`echo "${encodedInput}" | base64 -d | ${command}`
], options);
return child;
}
} Benefits
Next Steps
Would you like me to proceed with implementing this solution? |
Thank you for the research. I think that the best way to make this would and to have the tool parameters understandable intuitively by the LLM would be to add a parameter called stdinContent (a string) to the shellStart and shellExecute functions and describe it as content that is pipelined into the shell command upon start, or something to that extent. We can then use crossSpawn to start it in the cross platform way that you demonstrate above. |
Updating the GitHub integration is really just changing the prompt used for githubMode so that it says use stdinContent for the body of GitHub issues, pull requests and comments rather than temporary files. |
This commit adds a new `stdinContent` parameter to the shellStart and shellExecute functions, which allows passing content directly to shell commands via stdin. This is particularly useful for GitHub CLI commands that accept stdin input. Key changes: - Add stdinContent parameter to shellStart and shellExecute - Implement cross-platform approach using base64 encoding - Update GitHub mode instructions to use stdinContent instead of temporary files - Add tests for the new functionality - Add example test files demonstrating usage Closes #301
# [mycoder-agent-v1.5.0](mycoder-agent-v1.4.2...mycoder-agent-v1.5.0) (2025-03-20) ### Bug Fixes * improve resource trackers and fix tests ([c31546e](c31546e)) * properly format agentDone tool completion message ([8d19c41](8d19c41)) * resolve build and test issues ([549f0c7](549f0c7)) * resolve TypeError in interactive mode ([6e5e191](6e5e191)) * restore visibility of tool execution output ([0809694](0809694)), closes [#328](#328) * shell message should reset output on each read ([670a10b](670a10b)) * update CLI cleanup to use ShellTracker instead of processStates ([3dca767](3dca767)) ### Features * add colored console output for agent logs ([5f38b2d](5f38b2d)) * Add interactive correction feature to CLI mode ([de2861f](de2861f)), closes [#326](#326) * add parent-to-subagent communication in agentMessage tool ([3b11db1](3b11db1)) * add stdinContent parameter to shell commands ([5342a0f](5342a0f)), closes [#301](#301) * implement ShellTracker to decouple from backgroundTools ([65378e3](65378e3)) * remove respawn capability, it wasn't being used anyhow. ([8e086b4](8e086b4))
🎉 This issue has been resolved in version mycoder-agent-v1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [mycoder-v1.5.0](mycoder-v1.4.1...mycoder-v1.5.0) (2025-03-20) ### Bug Fixes * list default model correctly in logging ([5b67b58](5b67b58)) * restore visibility of tool execution output ([0809694](0809694)), closes [#328](#328) * update CLI cleanup to use ShellTracker instead of processStates ([3dca767](3dca767)) ### Features * Add interactive correction feature to CLI mode ([de2861f](de2861f)), closes [#326](#326) * add stdinContent parameter to shell commands ([5342a0f](5342a0f)), closes [#301](#301)
🎉 This issue has been resolved in version mycoder-v1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I feel that I could auto encode end of line characters in string arguments.
I think the approaches are different on windows than on macOS and Linux.
But this would simplify the GitHub integration significantly.
The text was updated successfully, but these errors were encountered: