--- name: spreadsheet-cleanup description: Turns a messy spreadsheet or CSV export into a pivot-ready table without ever touching the original file, standardizing dates and currency, merging obvious duplicate names, stripping stray whitespace, and removing exact duplicate rows, while flagging near-duplicates and missing data instead of guessing. Logs every change made. Use when the user has a messy export, inconsistent formatting, duplicate entries, or wants data cleaned or standardized before analysis. --- # Spreadsheet Cleanup Cleans messy data carefully: look before touching anything, ask before anything destructive, and never overwrite the original. ## Procedure 1. Get the file — ask for a path, an upload, or a pasted sample if you can't read files directly. If the sheet is large, don't stop at the first few rows; sample across the whole range so rare formats and edge cases actually get seen. 2. If a `business-context.md` file is available, read it first — it may define the canonical name for a client, vendor, or product that this sheet writes inconsistently. 3. For each column, determine what it's actually holding (date, currency, name, free text, ID) from the sample, and note every format variant present — not just the dominant one. 4. Report what you found before changing anything: each column, its variants, and the fix you're about to apply. Wait for a yes before doing anything that could be considered destructive — merging names or removing rows. 5. Once confirmed, apply the fixes: - **Dates** — standardize to one consistent format; state which format you chose. - **Currency** — consistent symbol and decimal handling; if more than one currency is genuinely present, keep them distinguishable rather than collapsing them. - **Name variants** — merge only obvious matches (e.g., "Acme Inc", "Acme, Inc.", "ACME INC"). List every single merge explicitly in the log — never merge silently. - **Whitespace and punctuation** — strip stray leading/trailing spaces and stray punctuation from text fields. - **Exact duplicate rows** — remove them. 6. Do not resolve on your own: near-duplicate rows (similar but not identical) and rows with missing required fields. Flag both with enough detail that the user can decide. 7. Write the cleaned result to a new file. The original is never modified. 8. Produce the change log below. ## If the input is thin If you can't tell what a column is meant to represent from the sample, ask rather than guessing — a wrong guess about a currency or a date format (03/04 vs 04/03) silently corrupts the sheet. ## Output format ```markdown ## Spreadsheet Cleanup **Original:** [filename] (untouched) **Cleaned output:** [new filename] **Rows:** [before] → [after] **Changes made:** - Dates: [format chosen, N cells affected] - Currency: [handling used, N cells affected] - Name merges (N): - "[variant]" + "[variant]" → "[canonical]" - Whitespace/punctuation cleaned: [N cells] - Exact duplicate rows removed: [N] **Flagged, not touched:** - Near-duplicates (N): [what makes them look similar, and why they weren't auto-merged] - Missing required fields (N): [which rows, which fields] **Worth double-checking:** [the one or two things most likely to need a human look] ``` ## Rules - Never overwrite the original file — the cleaned result always lands in a separate file. - Never merge names or delete non-exact-duplicate rows without an explicit yes from the user first. - When uncertain whether two rows are the same entity, flag them — don't merge on a guess. - Every fix goes in the log, including ones that seem minor. The log is the point as much as the clean file is.