Decide which stale preview environments to delete
Your task
Every branch spins up a preview environment, few get torn down, and the cloud bill shows it. An agent cleans them up, and because deletion cannot be undone, it only deletes what is provably dead.
Write classify_preview_cleanup(env_records): the rule your agent follows for each environment.
env_records(list of str): one environment each, written askey=valuefields separated by;, for example"branch_merged=true;idle_days=21;has_data_volume=false;label=none".- Return one decision per record, in input order:
"keep","notify"(ping the owner),"confirm"(the owner must approve) or"delete".
Read each record like this:
- Split on
;, and each field at its first=. Skip a field with no=. Trim and lowercase both the key and the value. Ignore keys other than the 4 below. branch_merged: merged only if the value is exactlytrue. Missing means not merged.has_data_volume: attached unless the value is exactlyfalse. Missing means not attached.labelandidle_days: the value, or empty if missing.
Then decide. The first rule that matches wins:
idle_daysis not 1 to 9 digits (0 to 9 only):"confirm".- Idle for fewer than 7 days:
"keep". - A data volume is attached, or the label is
keepordemo:"confirm". - Merged, and idle for 14 days or more:
"delete". - Otherwise:
"notify".
Examples
classify_preview_cleanup(env_records: list[str]) -> list[str]Example 1
Input
classify_preview_cleanup(["branch_merged=true;idle_days=21;has_data_volume=false;label=none", "branch_merged=false;idle_days=9;has_data_volume=false;label=none", "branch_merged=true;idle_days=2;has_data_volume=false;label=none"])Output
["delete", "notify", "keep"]Example 2
Input
classify_preview_cleanup(["branch_merged=true;idle_days=30;has_data_volume=true;label=none", "branch_merged=true;idle_days=30;has_data_volume=false;label=demo"])Output
["confirm", "confirm"]Example 3
Input
classify_preview_cleanup(["branch_merged=true;idle_days=14;has_data_volume=false;label=none", "branch_merged=true;idle_days=13;has_data_volume=false;label=none"])Output
["delete", "notify"]