Manage the TODO.md task list — add, remove, update, or move items. Commits and pushes changes automatically.

## Argument Parsing

Parse `$ARGUMENTS` as a natural-language instruction. Determine the **action** and **details**:

| Action | Trigger examples |
|--------|-----------------|
| **add** | "add Fix login bug", "new task: refactor auth", "blocked: waiting on API keys" |
| **remove** | "remove #3", "delete Fix login bug" |
| **update** | "update #2 status done", "#4 weight L", "rename #1 to New description" |
| **move** | "move #2 to Blocked", "unblock #1" (moves to Tasks) |
| **archive** | "archive #2", "archive done" (moves all done tasks to Archived) |
| **list** | "list", "show", "status" (or empty arguments) |

Extract from the argument string:
- **Action**: one of the above (default: **list** if `$ARGUMENTS` is empty or just "show"/"list"/"status")
- **Target**: a task number (`#N` or bare `N`) or a substring match against existing task descriptions
- **Section**: which section to add to or move to (default: **Tasks** for add, inferred for move). Recognise aliases like "blocked" → Blocked section, "archive"/"archived" → Archived section
- **Fields**: description text, weight (`S`, `M`, `L`, `XL` — default `S`), status (default: `todo` for Tasks, `blocked` for Blocked, `done` for Archived)

If the intent is ambiguous, **ask the user to clarify** before making changes. Do not guess.

## Step 1 — Read TODO.md

Read `TODO.md` at the repo root. Parse every section, its table headers, and all task rows. Track:
- Section name (e.g., "Tasks", "Blocked")
- Each row's `#`, `Task`, weight column, and `Status`
- The highest `#` in each section (for auto-numbering new items)

If `TODO.md` does not exist, stop and tell the user.

## Step 2 — Validate

Based on the action:

### Add
- **Check for duplicates**: Search all sections for a task whose description is a case-insensitive substring match (either direction) with the new task. If found, show the match and ask the user to confirm before adding.
- Determine the target section. Default is **Tasks** unless the user said "blocked", "block", or the description context clearly implies it.
- Auto-assign the next `#` in that section.
- Default weight: `S`. Default status: `todo` (or `blocked` if adding to Blocked section).
- If the user specified a weight or status, use those instead.

### Remove
- Locate the task by `#` (within the specified or inferred section) or by substring match on description.
- If not found, report the error and list similar tasks as suggestions.
- If found, show the task and **ask the user to confirm** deletion.

### Update
- Locate the task by `#` or substring match.
- If not found, report the error and list similar tasks.
- Apply only the fields the user specified (description, weight, status). Do not change unmentioned fields.

### Move
- Locate the task in its current section.
- If not found, report the error.
- Remove it from the current section and add it to the target section with the next available `#` and appropriate default status (`todo` for Tasks, `blocked` for Blocked, `done` for Archived).

### Archive
- If a specific task is targeted (`archive #N`): locate it, remove from its current section, and add to the **Archived** section with the source section name in the `From` column and today's date in the `Completed` column (format: `YYYY-MM-DD`).
- If `archive done` or just `archive` with no target: find **all** tasks with status `done` across all sections (except Archived) and move them all to the Archived section, recording each task's source section in the `From` column. Report how many tasks were archived.
- If no done tasks are found, tell the user.

### List
- Display all sections and their tasks in a readable format. No file changes needed — skip Steps 3–4.

## Auto-Archive

### On status change
When an **update** action sets a task's status to `done`, automatically move it to the **Archived** section instead of leaving it in place. Set the `From` column to the task's original section name and the `Completed` column to today's date. Inform the user that the task was archived.

### Monday sweep
If today is a **Monday**, run an automatic sweep **before** executing the user's action. Find all tasks with status `done` across all sections (except Archived) and move them to the Archived section. If any tasks were swept, inform the user (e.g., "Monday sweep: archived 2 done tasks") before proceeding with the requested action.

## Step 3 — Apply Changes

Edit `TODO.md` using the **Edit** tool:
- For **add**: insert a new row at the end of the target section's table.
- For **remove**: delete the row. Renumber subsequent rows in the same section so `#` values stay sequential.
- For **update**: replace the row with updated values.
- For **move**: delete from source section (renumber), insert into target section (next `#`).
- For **archive**: delete from source section (renumber), insert into Archived section (next `#`) with the source section name in `From` and today's date in `Completed`.

### Priority stacking (after every mutation)

After any add, remove, update, or move, **re-sort** the rows within the affected section(s) by priority, highest first:

1. `(!!!)` — critical (sort first)
2. `(!!)` — high
3. `(!)` — medium
4. No marker — lowest (sort last)

Tasks at the same priority level keep their relative order (stable sort). After sorting, **renumber** the `#` column sequentially from 1.

After editing, re-read the file to verify the change looks correct (table alignment, no broken markdown).

## Step 4 — Commit and Push

1. Stage `TODO.md`:
   ```
   git add TODO.md
   ```
2. Craft a commit message that reflects the action:
   - Add: `Add TODO: <short description>`
   - Remove: `Remove TODO #N: <short description>`
   - Update: `Update TODO #N: <what changed>`
   - Move: `Move TODO #N to <section>: <short description>`
   - Archive: `Archive TODO #N: <short description>` or `Archive N done tasks`
3. Commit with co-author tag:
   ```
   git commit -m "<message>

   Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
   ```
4. Push to remote:
   ```
   git push
   ```
5. Confirm success to the user with a summary of what changed.
