@@ -26,7 +26,7 @@ export { Parameters } from "./shell/prompt"
2626
2727const MAX_METADATA_LENGTH = 30_000
2828const DEFAULT_TIMEOUT = Flag . OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS || 2 * 60 * 1000
29- const CWD = new Set ( [ "cd" , "push-location" , "set-location" ] )
29+ const CWD = new Set ( [ "cd" , "chdir" , "popd" , "pushd" , " push-location", "set-location" ] )
3030const FILES = new Set ( [
3131 ...CWD ,
3232 "rm" ,
@@ -49,6 +49,7 @@ const FILES = new Set([
4949 "new-item" ,
5050 "rename-item" ,
5151] )
52+ const CMD_FILES = new Set ( [ "copy" , "del" , "dir" , "erase" , "md" , "mkdir" , "move" , "rd" , "ren" , "rename" , "rmdir" , "type" ] )
5253const FLAGS = new Set ( [ "-destination" , "-literalpath" , "-path" ] )
5354const SWITCHES = new Set ( [ "-confirm" , "-debug" , "-force" , "-nonewline" , "-recurse" , "-verbose" , "-whatif" ] )
5455
@@ -174,11 +175,16 @@ function prefix(text: string) {
174175 return text . slice ( 0 , match . index )
175176}
176177
177- function pathArgs ( list : Part [ ] , ps : boolean ) {
178+ function pathArgs ( list : Part [ ] , ps : boolean , cmd = false ) {
178179 if ( ! ps ) {
179180 return list
180181 . slice ( 1 )
181- . filter ( ( item ) => ! item . text . startsWith ( "-" ) && ! ( list [ 0 ] ?. text === "chmod" && item . text . startsWith ( "+" ) ) )
182+ . filter (
183+ ( item ) =>
184+ ! item . text . startsWith ( "-" ) &&
185+ ! ( cmd && item . text . startsWith ( "/" ) ) &&
186+ ! ( list [ 0 ] ?. text === "chmod" && item . text . startsWith ( "+" ) ) ,
187+ )
182188 . map ( ( item ) => item . text )
183189 }
184190
@@ -363,8 +369,8 @@ export const ShellTool = Tool.define(
363369 const tokens = command . map ( ( item ) => item . text )
364370 const cmd = ps ? tokens [ 0 ] ?. toLowerCase ( ) : tokens [ 0 ]
365371
366- if ( cmd && FILES . has ( cmd ) ) {
367- for ( const arg of pathArgs ( command , ps ) ) {
372+ if ( cmd && ( FILES . has ( cmd ) || ( shellKind === "cmd" && CMD_FILES . has ( cmd ) ) ) ) {
373+ for ( const arg of pathArgs ( command , ps , shellKind === "cmd" ) ) {
368374 const resolved = yield * argPath ( arg , cwd , ps , shell )
369375 log . info ( "resolved path" , { arg, resolved } )
370376 if ( ! resolved || Instance . containsPath ( resolved ) ) continue
0 commit comments