From 5fb6137d3b524b5d60975f6a7b37957387ee44be Mon Sep 17 00:00:00 2001 From: Josh Mabry Date: Tue, 10 Nov 2026 20:46:25 -0800 Subject: [PATCH 1/6] =?UTF-8?q?feat(view):=20the=20camera=20shows=20what?= =?UTF-8?q?=20it=20read=20=E2=80=94=20a=20running=20Scanned=20list=20and?= =?UTF-8?q?=20a=20real=20shutter=20(0.17.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Put away: a Scanned strip right under the video, newest three first with a count, so each read is visibly in without scrolling past the viewfinder. Check a bin shows Found the same way. - A read flashes a quick white shutter, snaps the frame green and names the piece in a pill on the video (plus a short vibrate where supported). Already scanned is amber, a foreign QR is red. - Fix: the old success flash added a bare `hit` class, which is the Stock list's tap-target rule (display:flex + padding), so every read briefly re-laid-out the viewfinder. Classes are cam--*. Co-Authored-By: Claude Opus 5.5 --- docs/upgrading.md | 10 ++++ docs/usage.md | 6 +- protoagent.plugin.yaml | 2 +- pyproject.toml | 2 +- tests/test_live_camera.py | 43 ++++++++++++++ tests/test_scan_in_app.py | 5 +- view.py | 114 ++++++++++++++++++++++++++++++++------ 7 files changed, 160 insertions(+), 22 deletions(-) diff --git a/docs/upgrading.md b/docs/upgrading.md index 59da3df..9b01f3b 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -4,6 +4,16 @@ Version notes that change behavior, newest first. Installing or updating through database migrations for you: every one is additive, and an older database upgrades in place on first open. Take a copy of `inventory.db` before a big jump anyway. +## 0.17.0 + +- **The camera shows what it read.** In Put away, a **Scanned** list sits right under the video, newest + first, so you can see each piece go in without scrolling. Check a bin shows what it has found the same + way. +- **A clearer read.** A quick shutter flash and a green snap of the frame, with the name in a pill on the + video (and a short buzz on phones that support it). Already scanned is amber, a QR code that isn't an + Inventory label is red. Before, the success flash also borrowed a Stock-list style and briefly + re-laid-out the viewfinder. + ## 0.16.4 - **Price the sell pile needs a comps source.** Without the ebay plugin enabled, it no longer starts an diff --git a/docs/usage.md b/docs/usage.md index 6dd7e56..8786e14 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -97,8 +97,10 @@ price changes and the sticker doesn't. Label first, then bin by scanning: 1. **Bins → Put away**, then **Scan with camera** (or **Take a photo**). -2. Point at a piece's label. It's added to the list with a short beep. Do the same for as many pieces as are - going in the same bin. +2. Point at a piece's label. The screen flashes, the frame turns green, a beep sounds, and the piece's name + shows at the top of the camera and at the top of the **Scanned** list right under it (the newest three, + with a count). A label already in the list turns the frame amber ("Already scanned"); a QR code that + isn't one of your labels turns it red. Do the same for as many pieces as are going in the same bin. 3. Point at the bin's label and confirm "Put 3 items in B01?". They move into that bin, and a planned piece becomes available. diff --git a/protoagent.plugin.yaml b/protoagent.plugin.yaml index ee5e85d..f201f6f 100644 --- a/protoagent.plugin.yaml +++ b/protoagent.plugin.yaml @@ -1,6 +1,6 @@ id: inventory name: Inventory (resale source of truth) -version: 0.16.4 +version: 0.17.0 description: >- Inventory for resellers who buy in lots and sell piece by piece. Tracks what you bought, what each box split into, which bin every piece is in, what it's worth (eBay sold comps, each price with its diff --git a/pyproject.toml b/pyproject.toml index 79ef382..31ef575 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "inventory-plugin" -version = "0.16.4" +version = "0.17.0" description = "Resale inventory as a source of truth for protoAgent — lots, items, listings, sales, price evidence, audit" requires-python = ">=3.11" license = "MIT" diff --git a/tests/test_live_camera.py b/tests/test_live_camera.py index d62d1e7..fff6292 100644 --- a/tests/test_live_camera.py +++ b/tests/test_live_camera.py @@ -208,3 +208,46 @@ def test_every_third_tick_reads_the_whole_frame_so_an_off_centre_label_still_rea ) got = _node(script, str(ROOT / "vendor" / "jsqr" / "jsQR.js"), stdin=json.dumps(frame)) assert got == [None, {"kind": "item", "id": "NH-SH-Harrows"}] # the centre crop misses it; the full frame reads it + + +# ── 0.17.0: the viewfinder shows what it read ──────────────────────────────────────────── + + +def _feed_fn() -> str: + page = _page() + return page[page.index(" const CAM_FEED_ROWS") : page.index(" function camFeed(head, names)")] + + +def test_the_feed_lists_the_newest_reads_first_capped_with_a_more_line_and_escaped(): + esc = "const esc = (s) => String(s).replace(/&/g,'&').replace(/'], [])," + + " six: camFeedHtml('Scanned · 6', ['a','b','c','d','e','f'], ['b','c','d'])," + + " again: camFeedHtml('Scanned · 6', ['a','b','c','d','e','f'], ['d','e','f']) }));" + ) + assert got["empty"] == "" + assert "Ork <Boyz>" in got["one"] and '
  • ' in got["one"] + six = got["six"] + order = [six.index(x) for x in ("f<", "e<", "d<")] + assert order == sorted(order) # newest first + assert "c<" not in six and "+ 3 more below" in six # three rows, then a count + assert six.count(" new") == 1 and six.count(" old") == 2 # only the fresh read slides in + assert " new" not in got["again"] # nothing new: no row animates + + +def test_a_read_never_borrows_the_stock_lists_hit_class_and_every_outcome_shows(): + page = _page() + cam = page[page.index(" const CAM = {") : page.index(" function openPutAway()")] + assert '"hit"' not in cam and ".cam.hit" not in page # .hit is the Stock row's tap target + hit = page[page.index("async function camHit") :][:2200] + for kind in ('camSignal("ok"', 'camSignal("dup"', 'camSignal("bad"'): + assert kind in hit + assert "void el.offsetWidth" in page # back-to-back reads each replay the animation + # The running list is painted onto the video by every drawer that owns the camera. + assert page.count("camMount(); camFeed(") == 3 + style = page[page.index("")] + assert "@keyframes cam-shutter" in style and "prefers-reduced-motion" in style diff --git a/tests/test_scan_in_app.py b/tests/test_scan_in_app.py index 1982943..58d50a8 100644 --- a/tests/test_scan_in_app.py +++ b/tests/test_scan_in_app.py @@ -156,6 +156,7 @@ def test_the_scanner_opens_items_and_bins_and_never_navigates(): assert "openItem(it.id)" in fn and "openBin(lab.id)" in fn assert "location" not in fn and "window.open" not in fn assert "parseLabel(text)" in PAGE[PAGE.index("async function slScan") :][:600] - hit = PAGE[PAGE.index("async function camHit") :][:700] - assert 'CAM.ctx === "scanlabel"' in hit and "slApply(parseLabel(text))" in hit + hit = PAGE[PAGE.index("async function camHit") :][:1400] + assert "const lab = parseLabel(text);" in hit # parsed once, before any context sees it + assert 'CAM.ctx === "scanlabel"' in hit and "slApply(lab)" in hit assert 'data-cap === "sl" ? slScan(f)' in PAGE.replace("t.dataset.cap", "data-cap") diff --git a/view.py b/view.py index 33dc522..e66408f 100644 --- a/view.py +++ b/view.py @@ -129,11 +129,41 @@ .scanbar{display:none} .cam{position:relative;width:100%;aspect-ratio:1/1;max-height:60vh;overflow:hidden;border-radius:var(--pl-radius);background:var(--pl-color-bg-inset)} .cam video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover} - .cam-frame{position:absolute;inset:15%;border:calc(var(--pl-border-width) * 2) solid var(--pl-color-fg);border-radius:var(--pl-radius);opacity:.85;transition:border-color .15s} - .cam.hit .cam-frame{border-color:var(--pl-color-status-success);border-width:calc(var(--pl-border-width) * 4)} - .cam-hint{position:absolute;left:0;right:0;bottom:var(--pl-space-2);text-align:center;font-size:var(--pl-font-size-sm);color:var(--pl-color-fg)} + .cam-frame{position:absolute;inset:15%;border:calc(var(--pl-border-width) * 3) solid rgb(255 255 255 / .9);border-radius:var(--pl-radius-lg);box-shadow:0 0 0 100vmax rgb(0 0 0 / .18);transition:border-color var(--pl-motion-base) var(--pl-motion-ease)} + .cam-hint{position:absolute;left:0;right:0;bottom:var(--pl-space-3);text-align:center;font-size:var(--pl-font-size-sm);font-weight:var(--pl-font-weight-medium);color:#fff;text-shadow:0 0 .4em rgb(0 0 0 / .8)} .cam-acts{justify-content:space-between;align-items:center} - @media (prefers-reduced-motion:reduce){.cam-frame{transition:none}} + /* A read (0.17.0): a quick white shutter, the frame snaps green, and a pill names what was read. + The classes are cam--*: a bare .hit is the Stock list's tap target, and it used to restyle + the whole viewfinder for a moment. */ + .cam-shutter{position:absolute;inset:0;background:#fff;opacity:0;pointer-events:none} + .cam--ok .cam-shutter{animation:cam-shutter .28s ease-out} + .cam--ok .cam-frame{border-color:var(--pl-color-status-success);animation:cam-snap .42s var(--pl-motion-ease)} + .cam--dup .cam-frame{border-color:var(--pl-color-status-warning)} + .cam--bad .cam-frame{border-color:var(--pl-color-status-error);animation:cam-shake .32s var(--pl-motion-ease)} + @keyframes cam-shutter{0%{opacity:.7}100%{opacity:0}} + @keyframes cam-snap{0%{transform:scale(1)}35%{transform:scale(.93)}100%{transform:scale(1)}} + @keyframes cam-shake{0%,100%{transform:translateX(0)}25%{transform:translateX(-2%)}75%{transform:translateX(2%)}} + .cam-pill{position:absolute;top:var(--pl-space-3);left:50%;max-width:88%;display:flex;align-items:center;gap:var(--pl-space-1_5);padding:var(--pl-space-1_5) var(--pl-space-3);border-radius:var(--pl-radius-pill);background:rgb(0 0 0 / .72);color:#fff;font-size:var(--pl-font-size-sm);font-weight:var(--pl-font-weight-semibold);white-space:nowrap;opacity:0;transform:translate(-50%,-40%);transition:opacity var(--pl-motion-base) var(--pl-motion-ease),transform var(--pl-motion-base) var(--pl-motion-ease);pointer-events:none} + .cam-pill.on{opacity:1;transform:translate(-50%,0)} + .cam-pill span{overflow:hidden;text-overflow:ellipsis} + .cam-pill i{flex:0 0 auto;width:1.4em;height:1.4em;border-radius:50%;display:grid;place-items:center;font-style:normal;font-size:var(--pl-font-size-xs);color:#000;background:var(--pl-color-status-success)} + .cam-pill--dup i{background:var(--pl-color-status-warning)} + .cam-pill--bad i{background:var(--pl-color-status-error);color:#fff} + /* The running list, right under the video: the newest read on top, so a scan is visibly IN + without scrolling past a viewfinder that fills the phone, and without covering the aim. */ + .camwrap .cam{border-radius:var(--pl-radius) var(--pl-radius) 0 0;max-height:50vh} + .camwrap:not(.has-feed) .cam{border-radius:var(--pl-radius)} + .cam-feed{margin:0;padding:var(--pl-space-2) var(--pl-space-3);list-style:none;display:flex;flex-direction:column;gap:var(--pl-space-1);border-radius:0 0 var(--pl-radius) var(--pl-radius);background:var(--pl-color-bg-inset);border:var(--pl-border-width) solid var(--pl-color-border);border-top:0;color:var(--pl-color-fg);font-size:var(--pl-font-size-sm)} + .cam-feed:empty{display:none} + .cam-feed .cf-head{font-size:var(--pl-font-size-xs);font-weight:var(--pl-font-weight-semibold);color:var(--pl-color-fg-muted);text-transform:uppercase;letter-spacing:.06em} + .cam-feed .cf-row{display:flex;align-items:center;gap:var(--pl-space-1_5);white-space:nowrap;overflow:hidden} + .cam-feed .cf-row span{overflow:hidden;text-overflow:ellipsis} + .cam-feed .cf-row b{flex:0 0 auto;color:var(--pl-color-status-success)} + .cam-feed .cf-row.old{color:var(--pl-color-fg-muted)} + .cam-feed .cf-row.new{animation:cam-in .32s var(--pl-motion-ease)} + .cam-feed .cf-more{font-size:var(--pl-font-size-xs);color:var(--pl-color-fg-muted)} + @keyframes cam-in{0%{opacity:0;transform:translateY(-60%)}100%{opacity:1;transform:none}} + @media (prefers-reduced-motion:reduce){.cam-frame,.cam-pill{transition:none}.cam--ok .cam-frame,.cam--bad .cam-frame,.cam-feed .cf-row.new{animation:none}.cam--ok .cam-shutter{animation-duration:.01s}} @media (max-width:639px){.form{grid-template-columns:1fr}.foot > *,.rowact{min-height:var(--pl-space-12)}.view .scan-top{display:none}.binsel{min-height:var(--pl-space-12)}.scanbar{display:block;padding:var(--pl-space-2) var(--pl-space-4) calc(var(--pl-space-2) + env(safe-area-inset-bottom));border-top:var(--pl-border-width) solid var(--pl-color-border);background:var(--pl-color-bg)}} @media (max-width:999px){.col-lot{display:none}} @media (max-width:639px){.pline .form{grid-template-columns:1fr 1fr}} @@ -1876,15 +1906,60 @@ o.start(); o.stop(a.currentTime + 0.08); } catch (_) { /* no sound is fine */ } } - function camFlash() { if (!CAM.el) return; CAM.el.classList.add("hit"); setTimeout(() => CAM.el && CAM.el.classList.remove("hit"), 450); } + // What a read looks like (0.17.0). kind: "ok" (in: shutter, green snap, beep, a buzz where the + // phone can), "dup" (already in: amber, no shutter), "bad" (not a label we know: red shake). + // The class comes off and goes back on with a reflow between, so back-to-back reads each animate. + const CAM_SIGNAL_MS = 1600; + function camSignal(kind, text) { + const el = CAM.view; if (!el) return; + el.classList.remove("cam--ok", "cam--dup", "cam--bad"); + void el.offsetWidth; + el.classList.add("cam--" + kind); + if (kind === "ok") { camBeep(); try { navigator.vibrate && navigator.vibrate(35); } catch (_) { /* no haptics */ } } + const pill = CAM.pill; + if (pill) { + pill.className = "cam-pill cam-pill--" + kind + " on"; + pill.innerHTML = '" + esc(text || "") + ""; + } + clearTimeout(CAM.signalT); + CAM.signalT = setTimeout(() => { + if (CAM.view) CAM.view.classList.remove("cam--ok", "cam--dup", "cam--bad"); + if (CAM.pill) CAM.pill.classList.remove("on"); + }, CAM_SIGNAL_MS); + } + // The running list over the video: a heading, the newest CAM_FEED_ROWS names (newest first), and + // "+ N more". Only a row not shown last time slides in, so a repaint doesn't replay the list. + const CAM_FEED_ROWS = 3; + function camFeedHtml(head, names, prev) { + if (!names.length) return ""; + const shown = names.slice(-CAM_FEED_ROWS).reverse(); + const more = names.length - shown.length; + return '
  • ' + esc(head) + "
  • " + + shown.map((n, k) => '
  • 0 ? " old" : "") + '">' + esc(n) + "
  • ").join("") + + (more > 0 ? '
  • + ' + more + " more below
  • " : ""); + } + function camFeed(head, names) { + if (!CAM.feed) return; + const key = head + "\n" + names.join("\n"); + if (key !== CAM.feedKey) { // a repaint with the same list leaves the rows (and their animation) alone + CAM.feed.innerHTML = camFeedHtml(head, names, CAM.feedPrev); + CAM.feedKey = key; CAM.feedPrev = names.slice(-CAM_FEED_ROWS); + } + CAM.el.classList.toggle("has-feed", names.length > 0); + } function camBuild() { - const el = document.createElement("div"); el.className = "cam"; + const wrap = document.createElement("div"); wrap.className = "camwrap"; + const el = document.createElement("div"); el.className = "cam"; wrap.appendChild(el); const v = document.createElement("video"); v.setAttribute("playsinline", ""); v.setAttribute("muted", ""); v.setAttribute("autoplay", ""); v.muted = true; v.playsInline = true; el.appendChild(v); const frame = document.createElement("div"); frame.className = "cam-frame"; el.appendChild(frame); const hint = document.createElement("div"); hint.className = "cam-hint"; hint.textContent = "Point at a label"; el.appendChild(hint); - CAM.el = el; CAM.video = v; + const shutter = document.createElement("div"); shutter.className = "cam-shutter"; el.appendChild(shutter); + const pill = document.createElement("div"); pill.className = "cam-pill"; pill.setAttribute("aria-hidden", "true"); el.appendChild(pill); + const feed = document.createElement("ul"); feed.className = "cam-feed"; feed.setAttribute("aria-hidden", "true"); wrap.appendChild(feed); + // CAM.el (what camMount moves between drawers) is the wrapper; CAM.view is the video box. + CAM.el = wrap; CAM.view = el; CAM.video = v; CAM.feed = feed; CAM.pill = pill; CAM.feedKey = ""; CAM.feedPrev = []; CAM.canvas = document.createElement("canvas"); CAM.g = CAM.canvas.getContext("2d", { willReadFrequently: true }); } // paPaint rebuilds the drawer's HTML: move the live