MCPcopy Index your code
hub / github.com/anomalyco/opencode / cmdCommandSection

Function cmdCommandSection

packages/opencode/src/tool/shell/prompt.ts:172–219  ·  view source on GitHub ↗
(chain: string, limits: Limits, defaultTimeoutMs: number)

Source from the content-addressed store, hash-verified

170}
171
172function cmdCommandSection(chain: string, limits: Limits, defaultTimeoutMs: number) {
173 return `# cmd.exe shell notes
174- Use double quotes for paths with spaces.
175- Use %VAR% for environment variables.
176- Use \`if exist\` for existence checks.
177- Use \`call\` when invoking batch files from another batch-style command.
178
179Before executing the command, please follow these steps:
180
1811. Directory Verification:
182 - If the command will create new directories or files, first use \`if exist\` to verify the parent directory exists and is the correct location
183 - For example, before creating \`foo\\bar\`, first use \`if exist "foo\\" dir "foo"\` to check that \`foo\` exists and is the intended parent directory
184
1852. Command Execution:
186 - Always quote file paths that contain spaces with double quotes (e.g., del "path with spaces\\file.txt")
187 - Examples of proper quoting:
188 - mkdir "My Documents" (correct)
189 - mkdir My Documents (incorrect - path is split)
190 - call "path with spaces\\script.bat" (correct)
191 - path with spaces\\script.bat (incorrect - path is split and not invoked correctly)
192 - After ensuring proper quoting, execute the command.
193 - Capture the output of the command.
194
195Usage notes:
196 - The command argument is required.
197 - You can specify an optional timeout in milliseconds. If not specified, commands will time out after ${defaultTimeoutMs}ms.
198 - If the output exceeds ${limits.maxLines} lines or ${limits.maxBytes} bytes, it will be truncated and the full output will be written to a file. You can use Read with offset/limit to read specific sections or Grep to search the full content. Do NOT use \`more\` or other pagination commands to limit output; the full output will already be captured to a file for more precise searching.
199
200 - Avoid using Shell with cmd.exe file/content commands unless explicitly instructed or when these commands are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands:
201 - File search: Use Glob (NOT dir /s)
202 - Content search: Use Grep (NOT findstr)
203 - Read files: Use Read (NOT type)
204 - Edit files: Use Edit (NOT copy)
205 - Write files: Use Write (NOT echo > file)
206 - Communication: Output text directly (NOT echo)
207 - When issuing multiple commands:
208 - If the commands are independent and can run in parallel, make multiple bash tool calls in a single message. For example, if you need to run "dir" and "where cmd", send a single message with two bash tool calls in parallel.
209 - ${chain}
210 - Use \`&\` only when you need to run commands sequentially but don't care if earlier commands fail
211 - DO NOT use newlines to separate commands (newlines are ok in quoted strings)
212 - AVOID changing directories inside the command. Use the \`workdir\` parameter to change directories instead.
213 <good-example>
214 Use workdir="project\\subdir" with command: dir
215 </good-example>
216 <bad-example>
217 cd /d "project\\subdir" && dir
218 </bad-example>`
219}
220
221function profile(name: string, platform: NodeJS.Platform, limits: Limits, defaultTimeoutMs: number) {
222 const isPowerShell = PS.has(name)

Callers 1

profileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected