# Build a task-audit sidebar

## What is included
A working teaching example: Code.gs (pure analysis, spreadsheet adapter, menu) and Sidebar.html (loading/success/failure interface). It reads a bound spreadsheet and returns a preview. It never writes cells, sends mail, changes sharing, deletes files, installs triggers or calls an AI service. No API key is required.

The other three projects are briefs for your own extensions, not completed integrations. Browser labs on the website are separate fixed-rule teaching simulations.

## Install in a disposable sheet
1. Create a new Google Sheet with fictional data. Rename one tab `Tasks`.
2. Set A1:D1 to the exact headers `ID`, `Task`, `Owner`, `Status`.
3. Add these sample records:

| ID | Task | Owner | Status |
|---|---|---|---|
| A1 | Write report | Ada | TODO |
| A1 | Review figures | Lee | DOING |
| B2 | Prepare slides | | DONE |
| | Missing identifier | Sam | later |

4. Open Extensions → Apps Script. Replace the default Code.gs contents with the supplied Code.gs.
5. Add an HTML file named `Sidebar` and paste Sidebar.html into it. Do not name it Sidebar.html.html.
6. Save. Run `testTaskAuditFixtures` to check pure logic with embedded fictional arrays. This function does not call Google services; project-level authorization behavior can still depend on the complete project.
7. Reload the spreadsheet. Choose Task audit → Open preview. Review any authorization request; the project uses Spreadsheet and HTML UI services.
8. Click Refresh preview. Inspect both duplicate A1 rows, the missing ID, and the unknown `later` status. Verify the source cells remain unchanged.

## Behavior contract
- A bound spreadsheet is required. No web-app deployment is included or needed.
- Reads only the first four columns of Tasks, with exact A1:D1 headers.
- At most 100 data rows; formatted or additional populated rows can affect the last-row bound.
- Uses displayed strings. It is a text audit, not a numeric or date calculation tool.
- Fully blank rows are skipped. Partly completed rows are inspected.
- IDs are trimmed and case-sensitive. All repeated nonblank IDs are flagged.
- Status is trimmed and must be exactly TODO, DOING or DONE.
- A blank owner is displayed as blank; it is not an error in this contract.
- Proposed task titles trim outer spaces and collapse internal whitespace. The original task text is preserved in the result.
- Counts are a snapshot, not a live view. Refresh after edits.
- Content is displayed with textContent rather than interpreted as HTML.

## Test deliberately
- Empty sheet with headers: zero records, no zero-height range request.
- Wrong/missing header: readable failure, controls become usable again.
- Missing Tasks tab: readable failure.
- Duplicate IDs and case variants: matching policy is visible.
- Unknown status and blank task: issues reported.
- More than 100 data rows: bounded failure before a full data read.
- A cell containing `<img src=x>`: displayed as text, not markup.

## First AI-assisted extension
Use PROMPT-PACK.md to request a patch that shows `Unassigned` for blank owner names in the preview. Preserve source data, case-sensitive ID rules and issue counts. Verify the returned code, run fixtures and inspect the actual sidebar. Do not assume the assistant's explanation establishes correctness.

## Limits and handoff
The example is read-only and has no apply, scheduling, sending or external API functionality. Adding those features requires new acceptance rules, identity/permission review, tests and recovery behavior. A bound sidebar is not a ready-to-publish public web app. Check official Apps Script documentation for current service behavior and limits.

To stop using the preview, close the sidebar. To remove the menu on future opens, remove or rename onOpen in your test project and reload the sheet. No installable trigger was created.
