From 0770b70ad08bdeffefc84e6eabff214a38279098 Mon Sep 17 00:00:00 2001 From: Michael Gilardi <11632652+mgilardi@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:40:45 -0700 Subject: [PATCH] Reuse the Skylight section's own spelling for new grocery items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A live test on 2026-11-16 added an item from the Fry’s Reminders list (curly apostrophe) to Skylight in a new Fry’s section, beside the existing Fry's (straight). Matching ignored the difference, but writing didn't. New items now use the section already on the list. Tested: unit tests. Not tested: a live pass with the fix. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + engine/tools/skylight_sync.py | 16 +++++++++++----- tests/test_skylight_sync.py | 12 ++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6fbc1b..eadb8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- **The Skylight sync keeps one section per store.** A Reminders list called Fry’s (curly apostrophe) made new Skylight items in a second section beside Fry's (straight). New items and items with no section now go in the section already on the Skylight list, spelled as it is there. A section set in `grocery_store_sections` still wins. Found in a live test on 2026-11-16. Tested: unit tests for both cases. Not tested: a live pass with the fix. - **Leave-by times start from home on your Contacts card.** Set `"eta_from": "contacts:home"` and Theseus reads the home address on your own card (My Card) each time, through the new `ek me-address`. The address isn't saved anywhere, so it stays right if you move. If the card has no home address, the briefing says so and shows no leave-by times. Tested: read from a real card and routed through Apple Maps; three new tests cover the card, a missing address and nothing being saved. - **Leave-by times from Apple Maps** (optional). Set `eta_from` to where your trips start, and the briefing shows when to leave for each event with a place, using Apple Maps' travel time for arriving at its start. Traffic is predicted for that time: the same 23 km test route between two public places took 34 minutes arriving at a weekday rush hour and 19 minutes early on a Sunday. It reads every calendar the Calendar app has, skips online, declined and all-day events, and makes at most 12 lookups a day, refreshing one in the two hours before an event. The cache holds no places or titles. `ek eta` does the lookup and `ek events` now gives each event's map location when it has one. Tested: 12 tests with a stand-in for ek, and real lookups by address, by place name, by coordinates and by transit. Not tested: a real day's events from your calendar. - **A fast Skylight sync for groceries and chores, without Claude** (optional, off until you turn it on). Every 2 minutes it brings the grocery list and the chores linked in `data/chore-map.json` into step with Reminders, both ways: a change on one side is copied, done beats not-done, the newer rename wins when both sides say when, and deletions never cross. It never creates, dates or reschedules a chore. The Skylight login lives in the Keychain. Setup is in docs/SETUP.md §3. Tested: 42 tests for the matching and conflict rules, chores by date and the connection to skylight-mcp (against a stand-in). Not tested: a real Skylight account, which waits on the Keychain login. diff --git a/engine/tools/skylight_sync.py b/engine/tools/skylight_sync.py index 7b8ba39..2ede3cb 100644 --- a/engine/tools/skylight_sync.py +++ b/engine/tools/skylight_sync.py @@ -109,8 +109,13 @@ def stores(cfg: dict) -> list[str]: return [raw] if isinstance(raw, str) else [s for s in raw if isinstance(s, str) and s] -def section_for(cfg: dict, store: str) -> str: - return (cfg.get("grocery_store_sections") or {}).get(store, store) +def section_for(cfg: dict, store: str, existing=()) -> str: + """The Skylight section for a store. A section already on the list that matches is reused as it's spelled + there, so a Reminders list called Fry’s (curly apostrophe) doesn't add a second Fry's section (2026-11-16).""" + mapped = (cfg.get("grocery_store_sections") or {}).get(store) + if mapped: + return mapped + return next((sec for sec in existing if sec and norm(sec) == norm(store)), store) def store_for(cfg: dict, section) -> str | None: @@ -137,6 +142,7 @@ def plan_groceries(cfg: dict, links: list[dict], sky: list[dict], rems: list[dic Returns (actions, links, notes, orphans). Actions are tuples for apply(). New links for items still to be created carry "pending": the action index that will create the missing side. """ + existing = sorted({s["section"] for s in sky if s.get("section")}) shops = stores(cfg) first = shops[0] by_sky = {s["id"]: s for s in sky} @@ -194,7 +200,7 @@ def plan_groceries(cfg: dict, links: list[dict], sky: list[dict], rems: list[dic # Store: a Skylight section change moves the reminder; a reminder moved to another store sets the section. sky_store = store_for(cfg, s.get("section")) if r["list"] != ln["store"] and sky_store == ln["store"]: - actions.append(("sky_section", s["id"], section_for(cfg, r["list"]))) + actions.append(("sky_section", s["id"], section_for(cfg, r["list"], existing))) new["store"] = r["list"] elif sky_store and sky_store != ln["store"] and r["list"] == ln["store"]: actions.append(("rem_list", r["id"], sky_store)) @@ -212,7 +218,7 @@ def plan_groceries(cfg: dict, links: list[dict], sky: list[dict], rems: list[dic store = store_for(cfg, s.get("section")) if store is None: store = first - actions.append(("sky_section", s["id"], section_for(cfg, first))) + actions.append(("sky_section", s["id"], section_for(cfg, first, existing))) match = next((r for r in open_rems if r["list"] == store and norm(r["title"]) == norm(s["label"])), None) if match: open_rems.remove(match) @@ -225,7 +231,7 @@ def plan_groceries(cfg: dict, links: list[dict], sky: list[dict], rems: list[dic linked_sky.add(s["id"]) for r in open_rems: - actions.append(("sky_add", r["title"], section_for(cfg, r["list"]))) + actions.append(("sky_add", r["title"], section_for(cfg, r["list"], existing))) kept.append({"sky": None, "rem": r["id"], "store": r["list"], "label": r["title"], "title": r["title"], "sky_done": False, "rem_done": False, "pending": len(actions) - 1}) return actions, kept, notes, sorted(single) diff --git a/tests/test_skylight_sync.py b/tests/test_skylight_sync.py index 0a8b853..7de9864 100644 --- a/tests/test_skylight_sync.py +++ b/tests/test_skylight_sync.py @@ -74,6 +74,18 @@ def test_a_reminder_is_added_to_skylight_in_its_store_section(self): actions, _, _ = plan(CFG, [], [], [rem("r1", "Paper towels", lst="Sam’s Club")]) self.assertEqual(actions, [("sky_add", "Paper towels", "Sam’s Club")]) + def test_a_new_item_reuses_the_skylight_section_as_spelled_there(self): + # The Reminders list says Fry’s (curly); the Skylight list already has Fry's (straight). One section, not two. + actions, _, _ = plan(CFG, [], [sky("s1", "Bread", section="Fry's")], [rem("r1", "Eggs", lst="Fry’s")]) + self.assertIn(("sky_add", "Eggs", "Fry's"), actions) + actions, _, _ = plan(CFG, [], [sky("s1", "Bread", section="Fry's"), sky("s2", "Apples", section=None)], []) + self.assertIn(("sky_section", "s2", "Fry's"), actions) + + def test_a_mapped_section_still_wins(self): + cfg = {**CFG, "grocery_store_sections": {"Fry’s": "Frys Market"}} + actions, _, _ = plan(cfg, [], [sky("s1", "Bread", section="Fry's")], [rem("r1", "Eggs", lst="Fry’s")]) + self.assertIn(("sky_add", "Eggs", "Frys Market"), actions) + def test_matching_respects_the_store(self): actions, _, _ = plan(CFG, [], [sky("s1", "Milk", section="Sam’s Club")], [rem("r1", "Milk", lst="Fry’s")]) self.assertIn(("rem_add", "Sam’s Club", "Milk"), actions)