File size: 6,620 Bytes
c5997d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# tasks/hard_task.py

import random
import json
import os
from datetime import datetime, timedelta
from config import INITIAL_STATE_FILE, STORAGE_LIMIT_MB


def _make_file(name: str, size_mb: float, days_ago_created: int, days_ago_accessed: int) -> dict:
    accessed = (datetime.now() - timedelta(days=days_ago_accessed)).isoformat()
    created = (datetime.now() - timedelta(days=days_ago_created)).isoformat()
    ext = "." + name.rsplit(".", 1)[-1] if "." in name else ""
    return {
        "type": "file",
        "extension": ext,
        "size_mb": round(size_mb, 2),
        "created_date": created,
        "last_accessed": accessed,
    }


def _make_folder(contents: dict, created_days_ago: int = 500) -> dict:
    return {
        "type": "folder",
        "created_date": (datetime.now() - timedelta(days=created_days_ago)).isoformat(),
        "contents": contents,
    }


def generate_hard_initial_state(seed: int = 99) -> dict:
    """
    Generate a complex file system for the Storage Diet task.

    Contains:
    - Old files (>3 years) that should be deleted
    - Large inactive folders that should be zipped
    - Recent project files that must NOT be touched
    - A mix of everything to make the agent think carefully

    Hard Task Goal: Free up at least 500 MB without touching recent files.
    """
    random.seed(seed)

    # --- OLD files (>3 years, fair game for deletion) ---
    old_files = {
        "old_backup_2018.zip": _make_file("old_backup_2018.zip", 210.0, 1900, 1800),
        "legacy_code_archive.tar": _make_file("legacy_code_archive.tar", 85.0, 1500, 1400),
        "project_alpha_2019.docx": _make_file("project_alpha_2019.docx", 12.0, 1700, 1600),
        "annual_report_2018.pdf": _make_file("annual_report_2018.pdf", 8.5, 1800, 1750),
        "tax_return_2019.pdf": _make_file("tax_return_2019.pdf", 3.2, 1600, 1550),
        "database_snapshot_2018.sql": _make_file("database_snapshot_2018.sql", 320.0, 2000, 1900),
        "old_presentation_2017.pptx": _make_file("old_presentation_2017.pptx", 45.0, 2200, 2100),
        "meeting_notes_2018.txt": _make_file("meeting_notes_2018.txt", 0.2, 1850, 1800),
    }

    # --- INACTIVE large folders (older, not recently accessed → zip candidates) ---
    inactive_design_assets = _make_folder({
        "logo_v1.psd": _make_file("logo_v1.psd", 95.0, 900, 750),
        "banner_draft.psd": _make_file("banner_draft.psd", 110.0, 850, 800),
        "icons_set.ai": _make_file("icons_set.ai", 60.0, 950, 900),
        "mockup_website.fig": _make_file("mockup_website.fig", 75.0, 870, 820),
    }, created_days_ago=950)

    inactive_videos = _make_folder({
        "tutorial_part1.mp4": _make_file("tutorial_part1.mp4", 800.0, 700, 650),
        "tutorial_part2.mp4": _make_file("tutorial_part2.mp4", 750.0, 700, 650),
        "raw_footage.avi": _make_file("raw_footage.avi", 1200.0, 720, 680),
    }, created_days_ago=720)

    # --- RECENT project files (must NOT be touched) ---
    recent_projects = _make_folder({
        "q4_strategy_2024.pptx": _make_file("q4_strategy_2024.pptx", 5.2, 20, 2),
        "client_proposal_nov.docx": _make_file("client_proposal_nov.docx", 1.8, 15, 1),
        "budget_forecast_2025.xlsx": _make_file("budget_forecast_2025.xlsx", 3.1, 10, 3),
        "product_roadmap.pdf": _make_file("product_roadmap.pdf", 2.4, 5, 0),
    }, created_days_ago=25)

    recent_code = _make_folder({
        "main.py": _make_file("main.py", 0.05, 7, 0),
        "utils.py": _make_file("utils.py", 0.03, 7, 1),
        "requirements.txt": _make_file("requirements.txt", 0.005, 7, 0),
        "README.md": _make_file("README.md", 0.02, 7, 0),
        "tests.py": _make_file("tests.py", 0.04, 7, 0),
    }, created_days_ago=7)

    # --- Medium-age files (borderline, agent must use judgment) ---
    medium_files = {
        "report_2022.pdf": _make_file("report_2022.pdf", 4.5, 700, 400),
        "presentation_2021.pptx": _make_file("presentation_2021.pptx", 22.0, 1000, 800),
        "archive_misc.zip": _make_file("archive_misc.zip", 55.0, 800, 600),
        "notes_2020.txt": _make_file("notes_2020.txt", 0.1, 1200, 1100),
        "photo_album_2022.zip": _make_file("photo_album_2022.zip", 130.0, 650, 500),
    }

    root = {
        **old_files,
        **medium_files,
        "Design_Assets": inactive_design_assets,
        "Tutorial_Videos": inactive_videos,
        "Active_Projects": recent_projects,
        "Current_Code": recent_code,
    }

    # Compute what needs to be freed
    total_size = sum(
        meta.get("size_mb", 0)
        for meta in old_files.values()
        if isinstance(meta, dict)
    )

    state = {
        "root": root,
        "_storage_goal_mb": STORAGE_LIMIT_MB,
        "_recent_folders_to_protect": ["Active_Projects", "Current_Code"],
        "_old_files_eligible": list(old_files.keys()),
        "_inactive_folders_eligible_for_zip": ["Design_Assets", "Tutorial_Videos"],
    }
    return state


def get_hard_task_description() -> str:
    return (
        f"HARD TASK – The Storage Diet:\n"
        f"You must free up at least {STORAGE_LIMIT_MB} MB of storage space.\n"
        "Rules:\n"
        "1. DELETE files older than 3 years that haven't been accessed recently.\n"
        "2. ZIP large inactive folders (not accessed in 90+ days) to save space.\n"
        "3. DO NOT touch or move any files accessed within the last 90 days.\n"
        "4. DO NOT touch the 'Active_Projects' or 'Current_Code' folders.\n"
        "5. Be strategic: inspect files before deleting if unsure.\n"
        f"Goal: Free at least {STORAGE_LIMIT_MB} MB without harming recent or active files."
    )


def get_hard_grading_criteria(initial_state: dict) -> dict:
    """Return grading criteria for the hard task."""
    return {
        "storage_goal_mb": initial_state.get("_storage_goal_mb", STORAGE_LIMIT_MB),
        "old_files_eligible_for_deletion": initial_state.get("_old_files_eligible", []),
        "folders_eligible_for_zipping": initial_state.get("_inactive_folders_eligible_for_zip", []),
        "folders_to_protect": initial_state.get("_recent_folders_to_protect", []),
    }


if __name__ == "__main__":
    state = generate_hard_initial_state()
    os.makedirs("data", exist_ok=True)
    with open(INITIAL_STATE_FILE, "w") as f:
        json.dump(state, f, indent=2)
    print("Hard task state saved.")
    eligible_size = sum(
        state["root"][f].get("size_mb", 0)
        for f in state["_old_files_eligible"]
    )
    print(f"Total size eligible for deletion: {eligible_size:.1f} MB")
    print(f"Storage goal: {state['_storage_goal_mb']} MB")