Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions .agents/skills/jarvis-meter-to-digit-box-sync/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
name: jarvis-meter-to-digit-box-sync
description: "Continue an approved Jarvis meter-photo ingestion into the full-image digit-detector dataset: verify the trusted reading, ROI, canonical orientation, and retained artifacts; bootstrap four digit-aperture boxes with classes 0-9; prepare a Make Sense review batch; import corrected YOLO annotations; preserve source exclusions and persistent CV folds; regenerate labels and previews; and enforce the human-review training gate. Use after jarvis-meter-to-roi-sync for new canonical meter photos, or when existing full-image digit boxes need review or correction."
---

# Jarvis Meter To Digit Box Sync

Execute this workflow from the Jarvis repository root. Use `backend/.venv` for
every Python step.

This skill starts only after `jarvis-meter-to-roi-sync` has completed. It does
not ingest raw photos, decide trusted readings, approve register ROIs, train a
detector, or promote a model.

Run mutating sequences fail-fast. Record `git status --short` first and preserve
unrelated Git and DVC changes. Do not rebuild while
`train_full_image_digit_detector.py` is running.

## Workflow

1. Establish the approved batch.
- Use the canonical `meter_YYYYMMDD.JPEG` or `.PNG` filenames handed off by
`jarvis-meter-to-roi-sync`.
- Do not silently add every unannotated file in the worktree to the batch.
- For every target, verify:
- the canonical photo exists in `assets/`;
- `assets/meter_readings.csv` contains one trusted four-digit reading;
- `backend/data/roi_boxes_manifest.json` contains the approved register
ROI;
- the matching image and one-box label exist in the persistent ROI split;
- the photo and ROI image dataset DVC targets were published after the
user approved the ROI overlay.
- If any condition is missing, stop this workflow and finish
`jarvis-meter-to-roi-sync`. ROI approval is not digit-box approval.

2. Verify canonical reading orientation.
- Confirm every target has one row in
`backend/data/digit_dataset/manifests/canonical_windows.csv`, with the same
split and reading as the approved upstream data.
- If the row is missing, incrementally refresh the existing digit
preparation pipeline:

```bash
backend/.venv/bin/python backend/extract_digit_windows.py
backend/.venv/bin/python backend/split_digit_windows.py --clean
backend/.venv/bin/python backend/label_digit_sections.py --clean
backend/.venv/bin/python backend/validate_digit_dataset.py
npm run qa:strip-dataset
```

- Do not pass `--clean` to `extract_digit_windows.py` during additive
ingestion. That flag removes the whole `data/digit_dataset` root,
including unrelated synthetic artifacts and DVC pointers. Reserve it for
an explicitly requested full regeneration that also rebuilds every
affected derived dataset.
- Run `npm run qa:strip-dataset` when no fresh QA artifact covers the target.
Show the target canonical-strip QA previews to the user and require
explicit confirmation that their left-to-right order matches the trusted
reading, even when a canonical manifest row already existed. If the
direction is wrong, correct
`backend/data/digit_dataset/manifests/direction_overrides.csv`, regenerate
from `split_digit_windows.py` onward, and repeat QA.
- If orientation preparation changed the standard digit datasets, refresh
and safely publish only their DVC targets:

```bash
backend/.venv/bin/python -m dvc add \
backend/data/digit_dataset/windows \
backend/data/digit_dataset/windows_canonical \
backend/data/digit_dataset/sections \
backend/data/digit_dataset/sections_labeled
scripts/dvc-push-safe.sh \
backend/data/digit_dataset/windows.dvc \
backend/data/digit_dataset/windows_canonical.dvc \
backend/data/digit_dataset/sections.dvc \
backend/data/digit_dataset/sections_labeled.dvc
backend/.venv/bin/python -m dvc status \
backend/data/digit_dataset/windows.dvc \
backend/data/digit_dataset/windows_canonical.dvc \
backend/data/digit_dataset/sections.dvc \
backend/data/digit_dataset/sections_labeled.dvc
```

If DVC needs an alternate cache, set
`DVC_SITE_CACHE_DIR=/tmp/dvc-site-cache`. Never run raw `dvc push`.

3. Snapshot the full-image dataset boundary.
- Read, do not infer, the existing:
- `backend/data/full_image_digit_dataset/manifests/annotations.csv`;
- `backend/data/full_image_digit_dataset/manifests/cv_folds.csv`;
- `backend/data/full_image_digit_dataset/manifests/source_exclusions.csv`;
- `backend/data/full_image_digit_dataset/manifests/summary.json`.
- Record the target filenames, existing review states, exclusions, and CV
assignments so the post-build comparison can detect unintended changes.
- Preserve `source_exclusions.csv`. Do not exclude a new image because it is
difficult without an explicit user decision.

4. Bootstrap the four digit boxes.
- Run:

```bash
backend/.venv/bin/python backend/build_full_image_digit_dataset.py
```

- Never pass `--rebuild-cv-folds` during ingestion.
- Confirm each new target seeded exactly four rows in `annotations.csv`, at
positions `0..3`, with digits/classes equal to the trusted reading,
`annotation_source=bootstrap-roi-split`, and
`review_status=pending`.
- Confirm existing reviewed rows, existing fold assignments, and exclusions
are unchanged. A new train source may receive one new persistent CV fold;
a test source must not receive one.

5. Present the review batch.
- Inspect and show the target files under
`output/full-image-digit-review/previews/crops/`. Use
`digit-box-contact-sheet.jpg` only as an overview; full-resolution images
are authoritative.
- Lead every initial or corrective Make Sense annotation request with a
prominent clickable Markdown link to
`[Open Make Sense](https://www.makesense.ai/)`; localize the link text to
the user's language when useful. Prefer the link over opening an external
browser automatically, and never require the user to remember or type the
site address.
- In the same message, provide clickable local links for every target image,
the class-list file, the matching bootstrap annotation files, and the
exact ZIP or directory path expected from the user's export.
- Ask the user to review the batch in Make Sense:
1. Upload only the target files from
`output/full-image-digit-review/images/`.
2. Choose **Object Detection**.
3. Load the class list from
`output/full-image-digit-review/annotations/labels.txt`.
4. Import only the matching `<meter-stem>.txt` files from that same
annotations directory. Do not import `labels.txt` as annotations.
5. Keep exactly four boxes per image. Each box must cover one complete
digit-wheel aperture, not only the dark glyph.
6. Verify that the classes form the trusted reading in reading order,
correct boxes/classes when needed, retain the original filenames, and
export YOLO annotations.
- Even when the bootstrap looks correct, require a Make Sense export. That
export is the durable evidence that the boxes were human-reviewed.
- Stop and wait for the exported ZIP or directory path.

6. Import the reviewed subset.
- For a normal new-image batch, run:

```bash
backend/.venv/bin/python backend/import_full_image_digit_annotations.py \
/path/to/makesense-export.zip \
--allow-partial
backend/.venv/bin/python backend/build_full_image_digit_dataset.py
```

- Omit `--allow-partial` only when the export intentionally contains every
active review-package image.
- Let the importer reject unknown images, out-of-bounds coordinates, any
count other than four boxes, and class sequences that do not match the
trusted reading. Do not bypass these checks.
- The import must update `annotations.csv` as the source of truth. Derived
YOLO labels, `summary.json`, fold assignment, and previews come from the
following builder run; do not edit generated label files directly.

7. Enforce the final gate.
- Confirm every target now has exactly four rows with:
- positions `0..3`;
- `annotation_source=human-makesense`;
- `review_status=reviewed`;
- classes equal to the trusted reading.
- Confirm the target's derived YOLO label exists in its active split,
exclusions are unchanged, old CV assignments are unchanged, and each new
train target retains its newly seeded fold.
- Inspect the regenerated target crop previews and ask the user for explicit
final approval.
- Run `npm run test:backend`.
- Declare the whole full-image dataset training-ready only when
`summary.json` reports no active `pending` annotations and the user has
approved the regenerated previews. If unrelated pending rows remain,
report the target batch as reviewed but the dataset as not training-ready.

8. Summarize without training.
- Report the target filenames and readings, imported row count, review
status, regenerated labels/previews, new fold assignments, validation
result, user approval state, and unrelated pre-existing changes.
- Report any condition that prevents the training-ready claim.
- Do not start training, evaluate checkpoints, promote models, rebuild CV
folds, or publish release artifacts unless the user requests that as a
separate next step.

## Invariants

- `annotations.csv` is the canonical human-review layer; generated labels are
disposable derivatives.
- Bootstrap runs may seed missing rows but must never overwrite reviewed rows.
- `cv_folds.csv` is persistent. Do not recompute it during routine ingestion.
- `source_exclusions.csv` defines active scope while retaining legacy-stress
artifacts.
- Validation and test images are never augmentation sources.
- Human Make Sense review and explicit preview approval remain mandatory.
- Routine additive ingestion must preserve the synthetic digit dataset and its
DVC pointer unchanged.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Jarvis Meter To Digit Boxes"
short_description: "Review and sync full-image digit boxes"
default_prompt: "Use $jarvis-meter-to-digit-box-sync to bootstrap, review, import, and validate four digit-aperture boxes for newly approved Jarvis meter photos."
14 changes: 12 additions & 2 deletions .agents/skills/jarvis-meter-to-roi-sync/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Run mutating command sequences fail-fast. Use separate checked commands or `set

6. Collect manual ROI labels for the new images.
- Do not auto-estimate ROI boxes as the default path. After canonical photo normalization and meter-value confirmation, ask the user to label the 4-digit black register in a suitable annotation app such as Make Sense.
- Lead every Make Sense labeling request with a prominent clickable Markdown link to `[Open Make Sense](https://www.makesense.ai/)`; localize the link text to the user's language when useful. Prefer the link over opening an external browser automatically so the user keeps control of focus and the workflow remains reliable across execution environments. Never require the user to remember or type the site address.
- Build and report the complete batch of newly ingested canonical image filenames that need labels.
- In the same message as the Make Sense link, provide clickable local links for every canonical input image and list the exact output TXT filename expected for each one.
- Tell the user to label every image in that batch, and wait until they upload one exported label file per new image into `assets/`.
- Expected label format is YOLO TXT with one row per image:
- `0 x_center y_center width height`
Expand All @@ -77,7 +79,7 @@ Run mutating command sequences fail-fast. Use separate checked commands or `set
- Do not use the old external `jarvis-roi-dataset-sync` helper path; the repo now expects `backend/build_roi_dataset.py` with a manifest input.

8. Rebuild the ROI dataset from the current CSV + ROI manifest.
- From the repository root, run `backend/.venv/bin/python backend/build_roi_dataset.py --roi-json backend/data/roi_boxes_manifest.json`.
- From the repository root, run `backend/.venv/bin/python backend/build_roi_dataset.py --roi-json data/roi_boxes_manifest.json`. The script resolves relative arguments from `backend/`, not from the shell's working directory.
- The builder persists split assignments in `backend/data/roi_dataset/splits.json`.
- Existing images keep their assigned split; new images default to `train` unless you edit `splits.json`.
- The builder updates the ROI dataset to match the CSV + manifest without recomputing old splits from CSV order.
Expand All @@ -95,6 +97,7 @@ Run mutating command sequences fail-fast. Use separate checked commands or `set
- Keep rect format: `{"x": ..., "y": ..., "width": ..., "height": ...}` normalized to the full image.
- Target only the 4-digit black register window.
- Preferred correction path: use Make Sense (or another manual labeling tool), export the corrected box to `assets/`, then repeat the label sync step and rebuild.
- When asking for a Make Sense correction, repeat the clickable Make Sense link and the exact local input and output filenames; do not rely on the user finding an earlier message.
- Re-run `build_roi_dataset.py` after any manifest correction so the generated labels stay aligned.
- Re-run `visualize_roi_labels.py` after any correction and ask the user to confirm the updated overlay.
- After the user approves the corrected overlay, scan for stray `:Zone.Identifier` files under `backend/data/roi_dataset/` and delete them before continuing.
Expand Down Expand Up @@ -122,6 +125,11 @@ Run mutating command sequences fail-fast. Use separate checked commands or `set
- DVC pointers pushed and their target-specific status
- unrelated pre-existing Git or DVC changes, if any
- whether the user explicitly approved the new ROI labels or whether further Make Sense correction is still pending
- After the ROI overlay is approved and the batch's canonical photos and ROI
images are published, hand off the canonical filenames to
`jarvis-meter-to-digit-box-sync` when the new photos should join the
full-image digit-detector dataset. Do not treat ROI approval as digit-box
approval.

## Command Snippets

Expand All @@ -134,7 +142,7 @@ Run mutating command sequences fail-fast. Use separate checked commands or `set
- CSV to file consistency:
- `awk -F, 'NR>1 {print $1}' assets/meter_readings.csv | while read -r f; do [ -f "assets/$f" ] || echo "missing: $f"; done`
- Rebuild ROI dataset:
- `backend/.venv/bin/python backend/build_roi_dataset.py --roi-json backend/data/roi_boxes_manifest.json`
- `backend/.venv/bin/python backend/build_roi_dataset.py --roi-json data/roi_boxes_manifest.json`
- Re-render ROI QA overlays:
- `backend/.venv/bin/python backend/visualize_roi_labels.py`
- Check only the DVC targets updated in the current batch:
Expand All @@ -147,3 +155,5 @@ Run mutating command sequences fail-fast. Use separate checked commands or `set
- The browser-assisted OCR path is not authoritative for CSV updates. Always confirm readings manually before writing `assets/meter_readings.csv`.
- New ROI labels are not training-ready until the user has provided manual labels and reviewed the generated overlays.
- Canonical meter photos and ROI image binaries are retained with DVC; do not leave new ingested JPEG/PNG files outside DVC tracking.
- Full-image digit-aperture annotations have a separate downstream human-review
gate in `jarvis-meter-to-digit-box-sync`.
10 changes: 7 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- `npm run serve`: Start the local web server on port `8000`.
- `npm run dev`: Alias of `npm run serve`.
- `npm run test:scripts`: Run launcher, QA service guard, and artifact/DVC safety tests.
- `npm run test:backend`: Run backend API, ROI dataset, and runtime crop unit tests.
- `npm run test:backend`: Auto-discover and run the fast Python tests in `backend/test_*.py`.
- `npm run test:e2e`: Run Playwright end-to-end tests.
- `npm run benchmark:roi-diff`: Generate ROI checkpoint diff artifacts.

Expand All @@ -39,7 +39,11 @@ Open `http://localhost:8000` after starting the frontend server.
- Prefer clear, small functions in `src/` modules and avoid deep nesting.

## Testing Guidelines
- Automated browser tests are configured with Playwright.
- `test:backend` contains fast unit, component, and confirmed-regression tests. Mock model inference and use temporary directories; model training and full checkpoint benchmarks do not belong in this suite.
- `test:scripts` protects launcher, service-guard, DVC, and artifact-safety contracts.
- `test:e2e` contains Playwright browser integration and user-flow regressions; mock the backend unless the behavior specifically requires a live service.
- `qa:*` commands and the UI `Run test set` are model/data benchmarks, not automated code-test cases. Their image counts must not be added to the automated test count.
- Add an automated test when it protects durable behavior, retained data/artifacts, a user-facing workflow, or a confirmed regression. Prefer one table-driven test over several near-identical helper tests, and keep one-off experiment/report checks in the relevant QA workflow.
- CI: `.github/workflows/e2e.yml` runs on each pull request and on pushes to `master`.
- Frontend manual checks: upload an image, run OCR, verify the email draft fields, and confirm the Gmail draft link.
- Backend sanity checks: `GET /health` and confirm `ready: true`, `roi_ready: true`, `digit_ready: true`, `strip_digit_ready: true`, and the expected model paths when all checkpoints are present.
Expand All @@ -56,7 +60,7 @@ Open `http://localhost:8000` after starting the frontend server.
- Backend is intended for local use; keep host/CORS scoped to localhost unless explicitly deploying.

## Artifact Retention
- Treat canonical `assets/` meter photos, `assets/meter_readings.csv`, ROI images/labels, `backend/data/roi_dataset/splits.json`, digit manifests, and promoted `backend/models/*.pt` checkpoints as must-retain artifacts.
- Treat canonical `assets/` meter photos, `assets/meter_readings.csv`, ROI images/labels, `backend/data/roi_dataset/splits.json`, digit manifests (including `backend/data/full_image_digit_dataset/manifests/**`), and promoted `backend/models/*.pt` checkpoints as must-retain artifacts.
- Use DVC for large Tier 1 binaries:
- per-file DVC tracking for canonical meter photos in `assets/`
- `backend/data/roi_dataset/images.dvc`
Expand Down
Loading
Loading