diff --git a/README.md b/README.md index 9e49c64..25bd382 100644 --- a/README.md +++ b/README.md @@ -1,251 +1,124 @@ # GlassMap +**A web map is a WebGL canvas — a black box to AI agents. WebMCP makes it glass.** -**An agent-native web map.** GlassMap uses [WebMCP](https://webmachinelearning.github.io/webmcp/) to turn the map canvas from a black box into a semantic surface: an AI agent can read the current view, find features, move the camera, draw shapes and annotate the map **without taking a single screenshot** — and the human watches it happen on the same map. +Live: **https://glassmap.clyeh.xyz** · **15 WebMCP tools, no backend, no API keys** · Built for [The WebMCP Challenge](https://webmcp.devpost.com/) (Aug 25 – Sep 3, 2026). -> Live: **https://glassmap.clyeh.xyz** · Built for [The WebMCP Challenge](https://webmcp.devpost.com/) (Aug 25 – Sep 3, 2026). -> **Status:** all fourteen planned tools are implemented and unit-tested — `get_map_state`, `set_map_view`, `list_features_in_view`, `find_features`, `select_features`, `draw_shape`, `plan_route`, `annotate`, `remove_from_map`, `describe_surroundings`, `compare_areas`, `measure`, `get_place_details`, `get_share_link` — plus one declarative form, `add_note`: fifteen in total, the number the on-page WebMCP badge counts. (`set_layers` was cut on 2026-08-29 — the demo script never needed layer toggling, so it was never built.) They act on 24 categories of data — six bundled Taipei datasets (2,063 features, always in memory; five are real OpenStreetMap data, the sixth is 25 fabricated sample listings, not OSM) plus 18 more real OpenStreetMap point-of-interest categories (31,069 features, loaded lazily per category on first use). The redesigned "Smoked Glass" interface and the agent-presence FX layer (every tool call renders a brief, self-clearing effect on the map) are both live. The page itself opens as a plain map with no agent chrome; the first live tool call wakes the inspector panel and the "Agent activity" feed into view, and a human can also open or close that view by hand at any time. Remaining: the demo video and the submission freeze. +![The map after an agent session: a 6-call activity feed, a dashed teal 800 m "10-minute walk" circle around 7 teal-ringed parks, an inspector reading SELECTED 7 · SHAPES 1 · NOTES 1, and a footer reading "Agent connected · 15 tools · WebMCP".](docs/media/hero.jpg) ## Why "Glass" +To an agent, every station, park and pin on a web map is just pixels. A screenshot can't read an unlabeled green polygon, a click stops working the moment the zoom changes, and drawing a shape, measuring a distance or selecting every park in view is essentially impossible from a picture. WebMCP exposes the map's state, features and actions as tools instead, so an agent never has to guess from pixels — the black box becomes **glass**. Every web map has this problem — property search, delivery planning, travel — and the fix is a tool contract, not a bigger screenshot model. For someone who cannot see the map at all, the same read-only tools double as agent-mediated map access — not a WCAG or accessibility-compliance claim. -A web map is a WebGL canvas. To a browser agent every station, park and pin is just pixels: +## The same task, two ways +Both arms were asked: *"Show every park within a 10-minute walk of Daan Station."* — the first "Try asking" card on the page. Open the live site and say it verbatim. -- To *see*, it must screenshot and let a multimodal model guess what the markers are. -- To *act*, it must click at coordinates that stop being valid the moment the zoom changes. -- To *draw a polygon*, *measure a distance* or *select every park in view*, it has essentially no way at all. +**Screenshot agent** +![The screenshot agent driving GlassMap by clicks, keys and full-page screenshots, with no tool access.](docs/media/screenshot-agent.gif) +19 UI actions · 8 screenshots → finds 2 of 7 parks. The 800 m "circle" is an 8-vertex polygon whose radius is a guess (the page shows a screenshot agent no scale bar and no zoom readout). The other 5 were never found: each one is another click-and-read-the-card round trip, and nothing on screen says how many are left. The search box needs two tries — "Daan Station" has no match, "Daan" does. -Maps are the largest "DOM without semantics" surface on the web. WebMCP fills exactly that gap: the page exposes map state, features and actions as structured tools, so the agent never has to look at pixels. The black box becomes **glass** — the agent sees straight through the canvas to the data underneath. +**WebMCP agent** +![The WebMCP agent calling map tools directly, with the map updating and no screenshots taken.](docs/media/webmcp-agent.gif) +5 tool calls · 2.9 KB returned · 82 ms of tool time · 0 screenshots → all 7 parks inside an exact 800 m circle, each with an id, a distance and a compass direction — two of them parks OpenStreetMap never named: +`set_map_view({ place: "Daan Station" })` → `draw_shape({ type: "circle", center: "Daan Station", radius_m: 800, label: "10-minute walk" })` → `set_map_view({ fit: "drawing:1" })` → `find_features({ near: "Daan Station", radius_m: 800, categories: ["park"] })` → `select_features({ ids: [...] })`. -The same opacity that blocks agents also blocks screen readers, so the read-only tools double as a semantic layer for people who cannot see the map. We call this *agent-mediated map access*; it is not a WCAG or accessibility-compliance claim. +Both clips are scripted replays recorded on 2026-09-02 with Playwright's headless Chromium against a local production build of this repository — not a live model. The screenshot arm was allowed only what a generic computer-use agent has: a search box, clicks, keys, mouse wheel, screenshots. The WebMCP arm calls `document.modelContext.executeTool` through the page's own dev shim (`?shim=1`), because headless Chromium has no native WebMCP; the tool code and its output are identical to what Chrome's native surface exposes. The measured, live-model comparison is the table below. -`describe_surroundings` is the clearest example. It names the district a point is in — falling back to the nearest district boundary within 300 m when the point sits in a seam between two independently simplified polygons, and naming none rather than guessing beyond that — then lists nearby features grouped into up to eight compass directions, nearest first, each with a distance in metres and a feature id an agent can act on next (`select_features`, `set_map_view`). When more features match than the tool describes, it says so instead of staying quiet: `total` is how many are within `radius_m`, `returned` is how many were actually listed (at most 30) — so a wider radius is never implied to reveal features that were simply cut off. - -## What an agent can do - -| You say | Without WebMCP | With GlassMap | -|---|---|---| -| "Move the map to Daan Park Station" | screenshot → find search box → type → screenshot → maybe click the wrong result | `set_map_view({ place: "Daan Park Station" })` | -| "Which parks are in view?" | screenshot → guess that green blobs are parks → can't read names | `list_features_in_view({ categories: ["park"] })` | -| "Circle an 800 m walk from the station" | nearly impossible: compute a pixel radius at the right zoom, then drag | `draw_shape({ type: "circle", center: …, radius_m: 800 })` | -| "What's inside the area I just drew?" | impossible — the agent cannot see vector geometry | `find_features({ within: "drawing:1" })` | -| "How big is the circle I just drew?" | impossible — a screenshot has no scale, so area has to be guessed from pixels | `measure({ target: "drawing:1" })` → `{ area_m2, perimeter_m }` | -| "Is Daan or Zhongshan better connected?" | screenshot both, eyeball the pins on each, guess which side has more | `compare_areas({ a: "Daan Park Station", b: "Zhongshan Station" })` → per-category counts and nearest match on each side | -| "I can't see the map. Where's the nearest park?" | impossible | `describe_surroundings()` → nearest features grouped by direction, each with a name, distance in metres and id | - -## Screenshots vs. tools, measured - -One run per arm, per task, measured on 2026-08-28 against the production build of that date — no statistical claims. The tool output has changed since (`docs/comparison.md`'s dated footnote quantifies one such change), so read the byte counts below as of that date, not today's; full method and every other honesty caveat are in [`docs/comparison.md`](./docs/comparison.md). +One run per arm per task, measured 2026-08-28 against that date's production build, before the page had a human search box (one response below has since grown a field); full method and every caveat: [`docs/comparison.md`](./docs/comparison.md). | Task | Screenshot agent | WebMCP | |---|---|---| -| Move to a station and mark an 800 m walking radius | 16 UI actions + 7 screenshots (~6 min); circle approximated as an 8-vertex polygon; centring 33 m off | **2 tool calls, 576 B (~1 s)**; exact centre (gazetteer); a true circle | -| List the parks in the current view, by name | 3 screenshots (full + 2 crops); only **1 of 11** parks nameable — the rest are unlabeled green polygons at this zoom | **1 tool call, ~1.2 KB**; all **11** parks, each with a name, distance and compass direction | -| How far and which direction to a named park | 1 screenshot + pixel/overlay arithmetic; ≈426 m guessed from pixels, +20% error (correct direction) | **1 tool call**, 2,771 B; **355 m**, computed from feature geometry (ground truth) | - -Four tool calls, ~4.5 KB of structured output, zero screenshots, across all three tasks — against 11 screenshots/crops on the control side, which still failed the second task outright and approximated the other two. - -## Tools - -Three layers, fourteen tools implemented. `set_layers` was cut before build — never built, not counted here (see below). Every write tool returns the new map state so the agent never needs a follow-up read. - -``` -Perceive (read-only, replaces screenshots) Navigate (camera only) Act (page state, no server) -├─ get_map_state ✅ ├─ set_map_view ✅ ├─ draw_shape ✅ -│ └─ set_layers (cut) ├─ plan_route ✅ -├─ list_features_in_view ✅ ├─ select_features ✅ -├─ find_features ✅ ├─ annotate ✅ -├─ describe_surroundings ✅ ├─ remove_from_map ✅ -│ └─ get_share_link ✅ -├─ measure ✅ -├─ compare_areas ✅ -└─ get_place_details ✅ -``` - -✅ = implemented and covered by unit tests. `set_layers` was cut on 2026-08-29 — not planned, not pending, simply not built once the demo script turned out not to need layer toggling. - -| Tool | What it does | Key inputs | -|---|---|---| -| `get_map_state` | Reads the camera, visible bounds, feature count, selection, drawings and annotations in one call — the read that used to require a screenshot. | *(none)* | -| `set_map_view` | Moves the camera: by exact `center`/`zoom`/`bearing`/`pitch`, by `feature_id` or `place` name (defaulting to a zoom *floor* — flying to a place never zooms you out; pass `zoom` to override, in either direction), or by `fit` — a drawing or feature id framed whole, with the same math the inspector's row clicks use. An ambiguous `place` does not move the map — it returns candidates with distances instead. | `place`, `feature_id`, `fit`, `center`, `zoom`, `bearing`, `pitch` | -| `list_features_in_view` | Lists loaded features whose bounds overlap the current view, nearest-first, each with distance in metres and an 8-point compass direction from the view centre; `query` searches within the view over the same five fields `find_features` matches (name, English name, brand, cuisine, address). | `query`, `categories`, `limit` | -| `find_features` | Searches every loaded feature, not just what's visible, by a substring of its name, English name, brand, cuisine or address, by category, by distance from a place/feature/coordinate, and by whether it's inside a shape on the map — including one a human drew by hand; a query that matches places in categories not yet loaded says so under `unloaded_matches`. | `query`, `categories`, `near`, `radius_m`, `within`, `limit` | -| `select_features` | Highlights features on the map and in the inspector's Selected list, by explicit ids or the same `query`/`near`/`radius_m`/`categories`/`within` filter `find_features` accepts — but selects every match, not just the first `limit`. | `ids` or filter, `within`, `replace` | -| `draw_shape` | Draws a circle, polygon or line on the map so the human can see the area being discussed; returns its area (circle/polygon) or length (line) and a `drawing:` id. | `type`, `center`+`radius_m` (circle) or `coordinates` (polygon/line), `label` | -| `plan_route` | Plans a walking route between two places via the keyless FOSSGIS OSRM service (OpenStreetMap data) and draws it as a line the human can see; returns the drawing id, `distance_m` and `duration_s`, says `simplified: true` when the geometry was thinned to fit, and fails honestly — never a fake route — when the service cannot answer. The one tool that talks to an external service; attribution renders on the page. | `from`, `to`, `label` | -| `annotate` | Pins a short note to a place on the map, so the human sees what was found where it was found. | `at`, `note`, `icon` | -| `remove_from_map` | Takes things off the map by id: the agent's own drawings and notes are removed, named features leave the selection, and a shape or note the *human* made is refused per-id — the person who drew it can tap it and press Remove. Every id in the batch is accounted for in exactly one bucket; removal is permanent, with no undo. | `ids` (drawing/annotation/feature ids) | -| `describe_surroundings` | Describes what's around a point the way a person would say it out loud: the district, then nearby features grouped by compass direction, nearest first, each with a distance and an id. | `from`, `radius_m` | -| `compare_areas` | Compares two places in one call: per-category counts of what's within `radius_m` of each, plus the nearest match of each category on each side; if a place name doesn't resolve, the error names which side (`a` or `b`) failed. | `a`, `b`, `radius_m`, `categories` | -| `measure` | Measures one drawing or loaded feature: area and perimeter for a circle or polygon, length for a line. A point has no extent and is refused, with a pointer to `find_features` for distances instead. | `target` | -| `get_place_details` | Everything the page knows about one place — address, phone, website, opening hours, wheelchair (as OpenStreetMap reports it, not a verified accessibility claim) and category-specific facts — for the questions a list answer is too lean for. Fields exist only where OSM has them; absent means absent. | `id` | -| `get_share_link` | Builds a link that reproduces this map for whoever opens it — camera, selection, every drawing and every note, encoded in the URL itself, nothing uploaded. Returns `{ url, bytes }`; a map too large to fit in a URL (over 8 KB) is refused with an error naming what to remove. | *(none)* | - -`within: "drawing:"` on `find_features` and `select_features` is the read half of the collaborative loop: any circle or polygon on the map — agent-drawn or hand-drawn by a human — becomes something an agent can query by id, not just something rendered on screen. (A line has no inside, so `within` does not apply to it.) - -Design rules the tool layer follows: - -- Every write tool (`set_map_view`, `select_features`, `draw_shape`, `annotate`, `plan_route`, `remove_from_map`) returns the full new map state, so the agent never needs a follow-up read. -- Read-only tools carry `readOnlyHint: true` so clients can skip confirmation prompts. -- Output that contains OpenStreetMap or user-entered text carries `untrustedContentHint: true`. -- Responses are small on purpose: `limit` defaults to 20, coordinates are rounded to 5 decimals, geometry is returned by id rather than inline. -- Bad input returns a structured `{ error }` instead of throwing, so the agent can recover. -- No `alert` / `confirm` / `prompt` anywhere — modal dialogs freeze agents. - -## City-wide breadth - -The six bundled datasets above (2,063 features) are always in memory. Beyond them, GlassMap knows about 18 more OpenStreetMap point-of-interest categories — `restaurant`, `cafe`, `pharmacy`, `hotel`, `bank` and 13 others — covering 31,069 more features across Taipei, held as static files under `public/data/tier2/` and described by a manifest the tools read without loading a byte of feature data. - -**Naming a category is what fetches it.** Pass `categories: ["restaurant"]` to `find_features`, `list_features_in_view`, `describe_surroundings` or `compare_areas` and it fetches every restaurant in the city once — 13,789 of them — and keeps them in memory for the rest of the session. There is no "list every category" call: loading all 18 at once would put 31,069 features into a browser tab for a question nobody asked. A query that omits `categories` is answered only from what is already loaded (the six bundled datasets plus whatever a category call already fetched this session) — and it says so: the answer's `unsearched_categories` names every category it did not search, each with its true city-wide count from the manifest, so "no cafes nearby" can never be confused with "no cafe file was ever fetched." - -A few real counts from the manifest (`public/data/tier2/index.json`): `restaurant` 13,789, `convenience` 3,231, `bicycle_rental` 2,602 (YouBike stations), `cafe` 2,298, down to `museum` 119 and `hospital` 74. Full table, tag mapping and Overpass queries for all 18 are in [`public/data/README.md`](./public/data/README.md). - -`select_features` still highlights every match a filter finds, its contract since the tool shipped — but once a point-of-interest category is involved, a filter matching more than 500 of them is refused rather than lighting up half the city: the answer gives the true count and asks for `near`+`radius_m`, `within` or `query` to narrow it. The six bundled categories are exempt from that cap. - -A `get_share_link` link carries the *names* of every point-of-interest category the sender had loaded, not their features — the recipient's page fetches the same files itself — so opening the link rebuilds the sender's map, selection included, instead of resolving to features the recipient's session never heard of. A link that names a category is written as `v2`; a link with none still encodes to the exact `v1` bytes it always did, so no existing link breaks. The one exception is a map whose drawings would not fit in a URL at all: their coordinates then travel delta-encoded and the link is written as `v3` — smaller maps keep their old bytes, and every older link still decodes. - -Fetching a category file can fail two honestly different ways: a **permanent** failure (this deployment ships no such file — a 404) drops the category and is not retried; a **transient** one (a slow connection, a rate-limited mirror — a 5xx, or a 408/425/429 that means "ask again") keeps the category on the books, including in any share link handed out meanwhile, so the next call simply tries again. - -## Working together on the same map - -The map is shared state, not a private channel for the agent: - -- **Human draws, agent reads.** Click "Draw a polygon", add vertices, close it — the shape appears in `get_map_state().drawings` with `source: "user"` and is immediately queryable with `find_features({ within: "drawing:" })`, the same call an agent uses on its own shapes. -- **Agent draws or annotates, human sees and edits.** A `draw_shape` or `annotate` call renders on the map at once and lists in the inspector's Shapes / Notes section with an "agent" or "user" provenance tag and a ✕ button to remove it — no confirmation dialog blocks either side. -- **A search box for humans, calling no tool.** Top-left, under the brand: type a place name and get results instantly from what the page already has loaded, plus a citywide name index for what it does not, and a list of categories the words might mean. Picking any of them moves the camera onto it (never zooming out) and writes a `source: "user"` selection; picking a citywide place first fetches its category, and picking a category outright loads and paints it exactly as the Places tray does, evictions included. None of this calls a tool, records an activity or wakes the agent chrome — it is the human half of the same question `find_features` answers for an agent. -- **A Places tray for browsing by kind.** The six bundled datasets are always painted; below them, a tap adds one of the 18 point-of-interest categories the tools fetch — "cafes" or "pharmacies" — up to three kinds painted at once; a fourth tap retires the oldest and says so out loud in the tray's foot line ("Cafés came off the map — 3 kinds of place at a time"), so nobody is left guessing what left. -- **`get_place_details`, echoed on the tap card.** The address, phone, website, opening hours and category-specific facts described under [Data and licensing](#data-and-licensing) are not agent-only: tapping the same pin opens a card that renders the same fields from the same table, so an agent saying "vegetarian, open till nine" and a person tapping the pin see the same two facts. The inspector's Selected list stays deliberately lean (name, English name when the data has one, and category) and does not repeat them — a ratified narrowing, not an oversight. -- **Inspector rows act, not just list.** Click a Selected, Shape or Note row and the camera flies to it — a point centres, an area or line is framed whole — except a Selected row whose id nothing has loaded, which is inert by design (nowhere to fly). Each Selected row carries its own ✕ to deselect just that one, and every row is keyboard reachable. -- **The human decides what chrome is on screen.** The page opens as a plain map and wakes into the agent view on the first live tool call — but the person can also open that view by hand (the corner spark's card offers a preview) and close it again at any time. A closed view stays closed while the agent keeps working; the spark carries a pulse and an exact count of the calls made since, and `get_map_state().bounds` always describes the rectangle actually on screen. -- **Two WebMCP APIs, one state.** Besides the imperative tools above, the inspector's pin-note field is a plain `
` — the declarative half of WebMCP, filled in by a human or submitted by an agent with no JavaScript registration. `SubmitEvent.agentInvoked` tells the store which one happened, so the note is stored as `source: "agent"` or `source: "user"` honestly either way. Together the 14 registered tools and this one declarative form are the 15 the on-page WebMCP badge counts. - -The address bar is part of that shared state, too: it always holds a link back to the map exactly as it stands, kept current whether the human or the agent made the last change, and opening that link — or one handed off from `get_share_link` — restores the same camera, selection, drawings and notes rather than a description of them. That is what lets a judge (or anyone else) reproduce what this README can only show as a screenshot. - -## Seeing the agent work - -Every tool call also plays out on the map itself, not just as a row in the activity feed: a read (`get_map_state`, `find_features`, `describe_surroundings`, …) washes translucent teal across whatever it looked at — a compass sweep, a glinting hit, a soft glow over the viewport — then fades to nothing; a write (`set_map_view`, `draw_shape`, `select_features`, `annotate`, …) materializes in the same teal as the change lands — a reticle drops onto the new camera centre, a shape draws itself on, a pin lands — and what's left behind is exactly the ordinary map state it always would have been. A shape or note a human adds by hand plays the identical two verbs in rose instead of teal, so who did what is legible without reading a word. Every effect is capped under two seconds and leaves zero residue on the canvas, and the matching row in the "Agent activity" feed glows on the same clock it animates on. Append `?fx=off` to the URL to turn the whole layer off, and it already honours `prefers-reduced-motion` (a short opacity crossfade plays instead of the full animation). +| Move to a station, mark an 800 m radius | 16 actions + 7 screenshots (~6 min); circle approximated, centring 33 m off | 2 calls, 576 B (~1 s); exact centre, true circle | +| List the parks in view, by name | 3 screenshots; **1 of 11** parks nameable | 1 call, ~1.2 KB; all **11** parks, named | +| Distance and direction to a named park | 1 screenshot + pixel math; ≈426 m, +20% error | 1 call, 2,771 B; **355 m**, ground truth | ## Try it - -### Chrome (149+) +**Chrome 149+:** 1. Enable `chrome://flags/#enable-webmcp-testing` and restart Chrome. -2. Open **https://glassmap.clyeh.xyz** or run it locally (below). -3. Open the [Model Context Tool Inspector](https://developer.chrome.com/docs/ai/webmcp) extension (or any WebMCP-capable agent) and ask it one of these, verbatim: - - *"Show every park within a 10-minute walk of Daan Station."* → `draw_shape` · `find_features` · `select_features` - - *"Compare Daan District and Xinyi District for parks and supermarkets."* → `compare_areas` - - *"Describe the area around Daan Station."* → `describe_surroundings` -4. Or skip the agent and call the tools directly from DevTools: +2. Open **https://glassmap.clyeh.xyz**. +3. Open the [Model Context Tool Inspector extension](https://developer.chrome.com/docs/ai/webmcp) or any WebMCP-capable agent and ask it one of these, verbatim: + - "Show every park within a 10-minute walk of Daan Station." → `draw_shape` · `find_features` · `select_features` + - "Compare Daan District and Xinyi District for parks and supermarkets." → `compare_areas` + - "Describe the area around Daan Station." → `describe_surroundings` + - "How big is Daan Forest Park?" → `find_features` · `measure` + - "What is the phone number and address of the post office nearest Daan Station?" → `find_features` · `get_place_details` + +Or call the tools directly from DevTools: ```js const tools = await document.modelContext.getTools(); -const byName = Object.fromEntries(tools.map(t => [t.name, t])); - -// Move the camera by name — no coordinates needed. +const byName = Object.fromEntries(tools.map((t) => [t.name, t])); await document.modelContext.executeTool(byName.set_map_view, { place: "Daan Park Station" }); - -// Everything within comfortable walking distance of the station. const found = await document.modelContext.executeTool(byName.find_features, { near: "Daan Park Station", radius_m: 800, - categories: ["park", "school"], -}); -JSON.parse(found); -// → { total: , returned: , -// features: [ { id, name, name_en?, category: "park" | "school", distance_m, direction }, … ], -// origin: { lng, lat }, // what these distances were measured from -// radius_m: 800 } // echoed back because near/radius_m bounded the search -// e.g. { total: 13, returned: 13, features: [ -// { id: "osm:way:1227733215", name: "大安森林公園", name_en: "Da-an Forest Park", -// category: "park", distance_m: 355, direction: "S" }, … ], -// origin: { lng: 121.53528, lat: 25.03356 }, radius_m: 800 } - -// Draw a circle so the human can see the area, then ask what's inside it — the -// same "within" an agent would use to read a shape a human drew by hand. -const drawn = await document.modelContext.executeTool(byName.draw_shape, { - type: "circle", - center: "Daan Park Station", - radius_m: 500, - label: "5-minute walk", -}); -const { drawing_id } = JSON.parse(drawn); -// → { drawing_id: "drawing:", area_m2: , state: { …, drawings: { count: 1, items: [...] } } } - -const inside = await document.modelContext.executeTool(byName.find_features, { - within: drawing_id, categories: ["park"], }); -JSON.parse(inside); -// → { total, returned, features: [ { id, name, category: "park", distance_m, direction }, … ] } +JSON.parse(found); ``` -### ChatGPT desktop app +Any browser works with `?shim=1` appended to the URL: the shim installs `document.modelContext` only when no native implementation exists, and it is already on in development builds. + +## Fifteen tools +Three layers, listed in that order: **Perceive** (read-only, replaces screenshots), **Navigate** (camera only) and **Act** (writes page state; only `plan_route` leaves the page). + +| Tool | What it does | +|---|---| +| `get_map_state` | Reads the camera, bounds, feature count, selection, drawings and notes in one call — no screenshot needed. | +| `list_features_in_view` | Lists what's on screen right now, nearest first, each with distance and compass direction. | +| `find_features` | Searches every loaded feature by name, category, distance from a point, or containment inside a shape. | +| `describe_surroundings` | Describes what's around a point out loud: the district, then nearby features by compass direction. | +| `measure` | Measures a drawing's or feature's area, perimeter or length. | +| `compare_areas` | Compares two places' per-category counts and nearest match, in one call. | +| `get_place_details` | Returns everything known about one place: address, phone, website, hours, `wheelchair` (an OSM tag, not a verified accessibility claim). | +| `get_share_link` | Builds a URL that restores this exact map — camera, selection, drawings, notes — for whoever opens it. | +| `set_map_view` | Moves the camera by place name, feature id, `fit` (frame a drawing or feature whole), or exact center/zoom/bearing/pitch. | +| `select_features` | Highlights features on the map and in the inspector, by id or the same filter `find_features` accepts. | +| `draw_shape` | Draws a circle, polygon or line so the human can see the area being discussed. | +| `plan_route` | Plans a walking route via the keyless FOSSGIS OSRM service and draws it as a line. | +| `annotate` | Pins a short note to a place on the map. | +| `remove_from_map` | Removes the agent's own drawings, notes or a selection entry; refuses to touch what a human drew. | +| `add_note` (``) | Pins a note from a plain HTML form; `SubmitEvent.agentInvoked` decides `source: "agent"` or `"user"`. | + +Design rules the tool layer follows: + +- Every write tool returns the new map state, so no follow-up read is needed. +- Read-only tools carry `readOnlyHint: true`. +- Output containing OpenStreetMap or user text carries `untrustedContentHint: true`. +- Responses stay small: `limit` defaults to 20, coordinates round to 5 decimals, geometry returns by id. +- Bad input returns a structured `{ error }`, never throws; no `alert` / `confirm` / `prompt` anywhere. + +More on how these behave: [`docs/details.md`](./docs/details.md). + +Verified once, 2026-08-28, against the ChatGPT desktop app: it listed the eleven tools the page declared at the time and called `get_map_state` live, no Chrome flag needed. The roster has grown to fourteen registered tools since (the `add_note` form is the fifteenth), and that growth is unverified against ChatGPT. -ChatGPT's built-in browser supports WebMCP tools on supported plans and models. Verified once, 2026-08-28, against this app's production build: ChatGPT desktop listed the 11 tools the page declared at the time and called `get_map_state` live — no Chrome flag needed. The roster has grown to fourteen tools since; that growth has not been re-verified against ChatGPT. Open the app URL in that browser and ask it to use the map. +## One map, two hands +The map is shared state, not a private channel for the agent. +![The page as it opens: a plain map with no agent chrome — search box, Draw/Note/Share buttons, Places tray and a small "also readable by AI agents" hint.](docs/media/landing.jpg) -### Any other browser +- The page opens as a plain map. The first live tool call wakes the inspector and activity feed into view, and a human can open or close that view by hand at any time (a share link that carries agent state opens with that view already up). +- Human draws, agent reads: a shape drawn by hand appears with `source: "user"` and is immediately queryable with `find_features({ within: "drawing:" })`. +- Agent draws or annotates, human sees and edits: the shape or note renders at once with an "agent" or "user" provenance tag and a ✕ to remove it — no confirmation dialog on either side. +- **Two WebMCP APIs, one state.** The pin-note field is a plain `` — no JavaScript registration — and `SubmitEvent.agentInvoked` decides whether the note is stored as `agent` or `user`. +- A search box lets a human find a place, calling no tool; a Places tray loads any of 18 OpenStreetMap categories, up to 3 painted at once — a fourth tap evicts the oldest and says so. +- Every tool call plays a brief effect on the map, capped at 2 seconds — teal for the agent, rose for a human action. `?fx=off` turns it off, and it honours `prefers-reduced-motion`. +- The address bar holds a link that restores this exact map — camera, selection, drawings and notes — for whoever opens it. -In development builds — or with `?shim=1` appended to the URL — GlassMap installs a small `document.modelContext` shim that implements the same `registerTool / getTools / executeTool / toolchange` surface, so the snippet above works even without the flag. The shim is never installed when a native implementation exists. +## Data +Six bundled Taipei datasets are always in memory — 109 MRT stations, 12 districts, 865 parks, 445 schools, 607 supermarkets and 25 sample listings (fabricated, not OSM) — 2,063 features total. 18 more OpenStreetMap point-of-interest categories (31,069 features) load lazily, one at a time, the moment a category is named; an answer that didn't search one lists it under `unsearched_categories`. Full provenance and tag mapping: [`public/data/README.md`](./public/data/README.md). -## Development +- Map data © [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors, [ODbL](https://opendatacommons.org/licenses/odbl/). Tiles by [OpenFreeMap](https://openfreemap.org/). +- Listings shown are **sample data**, not real properties. +- Code: [MIT](./LICENSE). -Requires Node 22+ (matches CI) and [pnpm](https://pnpm.io/). +## How it is built +A single Next.js app on Vercel — **no backend, no database, no API keys, no login**. [MapLibre GL JS](https://maplibre.org/) renders [OpenFreeMap](https://openfreemap.org/) vector tiles; [Turf.js](https://turfjs.org/) runs every spatial query in the browser; [Zustand](https://zustand.docs.pmnd.rs/) holds map state. Tools in `src/lib/map-tools/` talk to the map only through a `MapToolStore` interface, so they are unit-tested against an in-memory store. `src/lib/webmcp/register.ts` registers on both `document.modelContext` and `navigator.modelContext`, cancellable via `AbortSignal`. The one external service is `plan_route`, which asks the keyless FOSSGIS OSRM instance for walking routes, throttled to its 1 request/second policy, and answers with an honest error (map unchanged) when it is unreachable. ```bash pnpm install pnpm dev # http://localhost:3000 pnpm check # typecheck + lint + unit tests -pnpm test:e2e # Playwright: drives the tools through document.modelContext +pnpm test:e2e # Playwright, via document.modelContext pnpm build ``` -### Layout - -``` -src/ - app/ Next.js App Router pages - components/ React components (WebMcpProvider registers tools on mount) - lib/ - webmcp/ WebMCP glue: ambient types, registration, dev shim - map-tools/ Tool definitions + execute, decoupled from React/MapLibre - store/ Zustand map state + the narrow MapToolStore adapter tools use - geo/ Camera/projection math shared by the tools and the UI - data/ Bundled dataset schema + GeoJSON loader - awaken/ When the page wakes from a plain map into the agent view - types/webmcp.d.ts Types for document.modelContext / navigator.modelContext -e2e/ Playwright specs -``` - -Tools talk to the map only through the `MapToolStore` interface, so they are unit-tested against an in-memory store and can be lifted out of this app. - -Branching, worktrees, commit and PR conventions are in [CONTRIBUTING.md](./CONTRIBUTING.md). CI (`.github/workflows/ci.yml`) runs `pnpm check`, `pnpm build` and the Playwright suite on every PR. - -### WebMCP registration - -`src/lib/webmcp/register.ts` feature-detects both `document.modelContext` (current spec and Chrome) and `navigator.modelContext` (older shape some clients still expose) and registers on whichever exists. Registration is cancelled with an `AbortSignal`, per the current spec. Every tool's `execute` returns a JSON string, the lowest common denominator across clients. - -## Architecture - -Single Next.js app on Vercel. **No backend, no database, no API keys, no login.** One keyless external data service: `plan_route` asks the [FOSSGIS OSRM instance](https://routing.openstreetmap.de/) for walking routes at call time — throttled to their 1 request/second policy, credited on the page for the rest of the session once a route has been planned, and answering with an honest error (map unchanged) when unreachable. Everything else runs on bundled data entirely in the browser; the only other network the app touches is the keyless OpenFreeMap basemap tiles below, which stay display-only. - -- [MapLibre GL JS](https://maplibre.org/) with [OpenFreeMap](https://openfreemap.org/) vector tiles (no key required) -- Bundled GeoJSON under `public/data/` (Taipei MRT stations, districts, parks, schools, supermarkets, sample listings) -- [Turf.js](https://turfjs.org/) for spatial queries in the browser -- [Zustand](https://zustand.docs.pmnd.rs/) for map state; share links encode the full state in the URL hash - -## Data and licensing - -Six GeoJSON files under `public/data/` are bundled and loaded on startup, prepared ahead of time by the scripts in `scripts/` — the running app never calls Overpass or any other external data API at runtime; the single exception is the `plan_route` routing request described under [Architecture](#architecture). A further 18 point-of-interest files under `public/data/tier2/` (31,069 features total) are prepared the same way but loaded lazily, one category at a time, on first use — by an agent naming the category, or by a human picking it from the search box or the Places tray (see [City-wide breadth](#city-wide-breadth) above). Full provenance, Overpass queries and export notes for all 24 categories are in [`public/data/README.md`](./public/data/README.md). - -| Dataset | Category | Features | -|---|---|---:| -| MRT stations | `mrt_station` | 109 | -| Districts | `district` | 12 | -| Parks | `park` | 865 | -| Schools | `school` | 445 | -| Supermarkets | `supermarket` | 607 | -| Sample listings | `listing` | 25 (fabricated, not OSM) | - -Tier-2 features can also carry up to eleven further OSM tags, added in this build's enrichment pass: address, phone, website and `wheelchair` (as OpenStreetMap tags it — never a verified accessibility claim) apply to any category; seven more are gated to one category each — hotel `stars`; parking `fee` and `capacity`; pharmacy `dispensing`; place-of-worship `religion` and `denomination`; hospital `emergency` (five categories, seven fields). Together with the `cuisine`/`brand`/`opening_hours` already used for search, that is fourteen OSM tags a tier-2 feature can carry in total — but only where a contributor entered them: coverage citywide across all 31,069 features is roughly 43% for `address`, 22% for `phone`, 14% for `wheelchair` and 9% for `website`, and a field's absence means the tag was never recorded, not that the place lacks the thing it names. These fields are answered by `get_place_details`, one place per call, and rendered on the human's tap card from the same table; the inspector's Selected list stays deliberately lean and does not repeat them (a ratified narrowing, not an oversight). The six bundled datasets above do not carry these fields at all. - -- Map data © [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors, [ODbL](https://opendatacommons.org/licenses/odbl/). Tiles by [OpenFreeMap](https://openfreemap.org/). -- Listings shown in the demo are **sample data**, not real properties. -- Code: [MIT](./LICENSE). +CI runs the same commands plus Playwright on every PR: 1,436 unit tests across 60 files, all green. Requires Node 22+. Branching, worktrees, commit and PR conventions: [CONTRIBUTING.md](./CONTRIBUTING.md). diff --git a/docs/TASKS.md b/docs/TASKS.md index eb72ec1..5357487 100644 --- a/docs/TASKS.md +++ b/docs/TASKS.md @@ -24,6 +24,10 @@ Deadline: 2026-09-03 13:00 PDT. Must-have tools: `get_map_state`, `list_features ## D6 — 2026-09-02 · buffer; submit by evening of 2026-09-03 Taiwan time +| ID | Task | Owner | Status | Notes | +|---|---|---|---|---| +| T-105 | README shows the map before it explains it: 251 → 124 lines, describes only shipped behaviour; hero and landing images; two GIFs of the same ask card run by a screenshot agent and by a WebMCP agent; `docs/details.md` keeps the cut prose | docs-writer → review → docs-writer → review | done | Owner asked 2026-09-02 for: no unshipped work in the README, a 2–3 scenario comparison recording, images, and a condensed pitch judged adversarially. Two scenarios recorded (Playwright headless Chromium, scripted replays, WebMCP arm on `?shim=1`; the README says all of this); a third, human–agent collaboration, was not recorded — the "One map, two hands" section carries it in text. Recording the first arm surfaced T-104. Two review rounds: nine false or unsupported claims corrected before merge | + ## UI redesign — "Smoked Glass" · approved 2026-08-29 · gate: production matches the shipped mockup Design handoff: `docs/design/ui-redesign-handoff.md` (tokens, component inventory, ship-gates, honesty caveats). Verdict: SHIP after a five-round adversarial design review; mockup + evidence live in the design session workspace outside the repo. diff --git a/docs/details.md b/docs/details.md new file mode 100644 index 0000000..e2f57aa --- /dev/null +++ b/docs/details.md @@ -0,0 +1,19 @@ +# GlassMap — tool behaviour in detail + +Behaviour the README summarises, spelled out. + +## `describe_surroundings` district fallback + +`describe_surroundings` names the district a point is in — falling back to the nearest district boundary within 300 m when the point sits in a seam between two independently simplified polygons, and naming none rather than guessing beyond that — then lists nearby features grouped into up to eight compass directions, nearest first, each with a distance in metres and a feature id an agent can act on next (`select_features`, `set_map_view`). When more features match than the tool describes, it says so instead of staying quiet: `total` is how many are within `radius_m`, `returned` is how many were actually listed (at most 30) — so a wider radius is never implied to reveal features that were simply cut off. + +## `select_features` 500-match cap + +`select_features` still highlights every match a filter finds, its contract since the tool shipped — but once a point-of-interest category is involved, a filter matching more than 500 of them is refused rather than lighting up half the city: the answer gives the true count and asks for `near`+`radius_m`, `within` or `query` to narrow it. The six bundled categories are exempt from that cap. + +## `get_share_link` versioning (v1/v2/v3) + +A `get_share_link` link carries the *names* of every point-of-interest category the sender had loaded, not their features — the recipient's page fetches the same files itself — so opening the link rebuilds the sender's map, selection included, instead of resolving to features the recipient's session never heard of. A link that names a category is written as `v2`; a link with none still encodes to the exact `v1` bytes it always did, so no existing link breaks. The one exception is a map whose drawings would not fit in a URL at all: their coordinates then travel delta-encoded and the link is written as `v3` — smaller maps keep their old bytes, and every older link still decodes. + +## Tier-2 fetch failure: permanent vs. transient + +Fetching a category file can fail two honestly different ways: a **permanent** failure (this deployment ships no such file — a 404) drops the category and is not retried; a **transient** one (a slow connection, a rate-limited mirror — a 5xx, or a 408/425/429 that means "ask again") keeps the category on the books, including in any share link handed out meanwhile, so the next call simply tries again. diff --git a/docs/media/hero.jpg b/docs/media/hero.jpg new file mode 100644 index 0000000..977e7d2 Binary files /dev/null and b/docs/media/hero.jpg differ diff --git a/docs/media/landing.jpg b/docs/media/landing.jpg new file mode 100644 index 0000000..1f32f94 Binary files /dev/null and b/docs/media/landing.jpg differ diff --git a/docs/media/screenshot-agent.gif b/docs/media/screenshot-agent.gif new file mode 100644 index 0000000..28812c2 Binary files /dev/null and b/docs/media/screenshot-agent.gif differ diff --git a/docs/media/webmcp-agent.gif b/docs/media/webmcp-agent.gif new file mode 100644 index 0000000..1c52bd2 Binary files /dev/null and b/docs/media/webmcp-agent.gif differ diff --git a/src/components/TryAsking.tsx b/src/components/TryAsking.tsx index b8ff22c..22c5db7 100644 --- a/src/components/TryAsking.tsx +++ b/src/components/TryAsking.tsx @@ -12,11 +12,10 @@ * two-step `find_features · measure` chain. Re-verify resolution before * changing a single word. * - * And these strings are not only here: README.md's "Try it" section quotes the - * first three cards verbatim, question and tool tag both. Editing one of those - * three without editing the README leaves the repo saying two different things - * a judge can hand the same agent. (It quotes three of five and claims no - * completeness, so adding a card is safe; changing one of the three is not.) + * And these strings are not only here: README.md's "Try it" section quotes all + * five cards verbatim, question and tool tag both. Editing any of them without + * editing the README leaves the repo saying two different things a judge can + * hand the same agent. (Adding a card is safe; changing one is not.) * * The `get_place_details` card (F-4) is held to the same bar twice over, and * both halves are easy to break by rewording it: