MCPcopy
hub / github.com/OS-Copilot/OS-Copilot / list_working_dir

Method list_working_dir

oscopilot/environments/env.py:35–71  ·  view source on GitHub ↗

Lists the contents of the working directory in a detailed format. Returns a string representation similar to the output of the 'ls' command in Linux, including file/directory names, sizes, and types. Returns: str: Detailed listings of the working direct

(self)

Source from the content-addressed store, hash-verified

33 self.env_state: Union[EnvState, None] = None
34
35 def list_working_dir(self):
36 """
37 Lists the contents of the working directory in a detailed format.
38
39 Returns a string representation similar to the output of the 'ls' command in Linux,
40 including file/directory names, sizes, and types.
41
42 Returns:
43 str: Detailed listings of the working directory's contents, or an error message if the directory does not exist.
44 """
45 directory = self.working_dir
46 # Check if the directory exists
47 if not os.path.exists(directory):
48 return f"Directory '{directory}' does not exist."
49
50 # List files and directories
51 files_and_dirs = os.listdir(directory)
52
53 # Create a list to store the details
54 details = []
55
56 for name in files_and_dirs:
57 # Get the full path
58 full_path = os.path.join(directory, name)
59
60 # Get file or directory size
61 size = os.path.getsize(full_path)
62
63 # Check if it's a file or directory
64 if os.path.isdir(full_path):
65 doc_type = 'Directory'
66 else:
67 doc_type = 'File'
68
69 details.append(f"{name}\t {size} bytes\t {doc_type}")
70
71 return "\n".join(details)
72
73 def step(self, _command) -> EnvState:
74 """

Callers 2

decompose_taskMethod · 0.80
replan_taskMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected