Lab: The Messy Repo
Due: Wednesday, October 21 at 11:59pm (one week after it is assigned) · Worth: 8 points
A classmate is inheriting a repository full of scattered homework, old notes, and build output. Organize the files, record what remains in answers.txt, and save a script that repeats the cleanup.
Start
Create lab-shell from the starter template and clone your copy. Use a Bash terminal; on Windows, choose Terminal → Select Default Profile → Git Bash and open a new terminal. Git Bash comes with the Git installation from course setup; the default macOS terminal also works.
From the repository root, create a work folder and generate the practice files inside it:
$ mkdir messy-repo
$ cd messy-repo
$ bash ../make_mess.shmake_mess.sh writes the practice files into the current folder. Keep your work inside messy-repo, without initializing another Git repository there.
Inspect the Folder
Use pwd, ls, and ls -a to check your location and the folder’s contents. Visit docs, list its contents, then return with cd ... Read README.md with cat. The reading explains paths and navigation.
Practice making a backup: copy lab04.py to lab04.py.bak, confirm both exist, then remove the backup. Use cp and rm from the reading’s file commands. Check the filename before deleting it: rm has no trash can.
Locate the Flag
One file contains a secret string of the form FLAG{...}. Find its path and line number with grep. The -r option searches subdirectories, and -n prints line numbers; the reading shows how to combine them. Quote the search pattern and search from . so you include the whole work folder. Record the location for answers.txt.
Write the Cleanup
Before moving files, predict which names each wildcard matches, then check:
$ ls hw?.py
$ ls hw*.pyWhich pattern includes hw10.py? Use that pattern to move all four homework files with one mv command. The cleanup must:
Preview each wildcard with ls before using it with mv or rm. Save your cleanup commands in messy-repo/tidy.sh, in the order they should run.
Test the script on a fresh copy of the mess in a separate folder outside messy-repo: run make_mess.sh there, then run bash with the path to your tidy.sh. Check the resulting files against the three requirements above. The script only needs to work on a fresh mess; running it twice may report missing files. Return to your cleaned messy-repo before counting.
Count the Remaining Work
Use pipes and redirection to answer these questions after the cleanup:
- How many lines are in the top-level Python files? Combine their contents with
catand pass the result towc -l. - How many lines contain
TODOanywhere in the tree? Search recursively and count the matching lines. - How many Python files remain at the top level? Count the filenames, not their contents.
As a check, the top level should contain the three lab files. Explain to yourself why the first and third counts exclude homework/, while the second includes it. Keep extra test copies outside this folder so they do not affect recursive searches.
Save the Inventory
Write answers.txt inside messy-repo, using > for the first line and >> to append the rest. Label all four results: the flag’s path and line number, top-level Python line count, unfinished-marker count, and top-level Python file count.
Use labels such as “flag location” and “unfinished markers”; do not put the literal FLAG{ or TODO in this file, or it will change later search results.
Practice a Clean Project
The docchat project will need a new repository and a private API key. For ungraded practice, create a sibling folder named docchat-practice outside lab-shell and initialize it with git init. Use the reading’s project setup as a reference.
An API key authorizes requests to a service and may bill them to your account. Use echo and redirection to put the placeholder GROQ_API_KEY=gsk_your_key_goes_here in .env. Create .gitignore with .env on its first line, then append __pycache__/ on a second line. Check both files with cat, then return to lab-shell/messy-repo. No real key or API call is needed for this practice.
Never commit a real key: deleting it later leaves earlier versions in Git’s history.
The Same Commands in Project 3
Project 3 gives a language model tools named ls, cat, and grep to inspect files before answering a question. You will implement those commands as Python tools for the agent.
Submit
Commit and sync messy-repo/answers.txt and messy-repo/tidy.sh. If a command did not work as expected locally, describe the problem in one sentence in answers.txt. On Gradescope, choose GitHub and submit your lab-shell repository and branch. The first lab explains the submission workflow.
Grading Rubric
Gradescope checks each item separately and adds the points earned.
Total: 8 points.