Online class definition GitHub issue

vibecode
{"vibecode": {
    "doc": "puck_class_definition",
    "role": "spec for how a Puck class defines itself online — the JSON shape a Puck server publishes so clients can discover the class's constructor parameters, methods, return types, and metadata. The class definition is what `puck.lookup(url)` resolves to before instantiation.",
    "audience": ["Puck client implementors needing to know what to expect from a server's class definition",
        "Puck server implementors publishing a class",
        "Caspian and other-language tooling generating client stubs from a definition"],
    "example_class": "https://puck.uno/geo/",
    "example_language": "Python",
    "key_concepts": ["class_publishes_itself_as_json",
        "constructor_and_methods_as_keyed_hashes",
        "keyword_only_params_per_protocol",
        "single_class_key_polymorphic_built_in_name_or_url",
        "parametric_types_use_of_modifier",
        "clients_consume_at_lookup_time"]
}}
Open issues (3)

File: documentation/requirements/puck/class-definition.md § Open points (#open-points)

§ Open points
Regarding this: Versioning across calls. A client cached the v1.0.0 definition; the server has shipped v1.1.0 since. Does the proxy re-resolve, raise on mismatch, or silently use the older shape? TBD. Review versioning in Puck. Versioning is only loosely supported.

File: documentation/requirements/puck/class-definition.md § Example: rendered page for https://puck.uno/geo (#example-rendered-page-for-https-puck-uno-geo)

§ Example: rendered page for https://puck.uno/geo
Put this below the JSON example

File: documentation/requirements/puck/class-definition.md § JSON or HTML — both work (#json-or-html)

§ JSON or HTML — both work
Move this section to above the fiest example.

A Puck class publishes its definition as a JSON document at its URL. When a client does puck.lookup('https://puck.uno/geo/'), the server returns this JSON; the client uses it to know what constructor parameters the class accepts, what methods it exposes, what those methods take and return.

The shape is strictly declarative — no executable code crosses the wire as part of the definition. The class's actual logic lives on the server; clients only see the interface.


JSON or HTML — both work GitHub issue

Open issues (1)

File: documentation/requirements/puck/class-definition.md § JSON or HTML — both work (#json-or-html)

Move this section to above the fiest example.
vibecode
{"vibecode": {
    "section":                       "json_or_html",
    "rule":                          "class_page_served_as_either_pure_json_or_html",
    "content_type_dispatch":         {"application/json": "body_is_the_definition_parse_directly",
                                      "text/html":        "body_embeds_definition_in_pre_id_definition_extract_textcontent_parse_as_json"},
    "definition_element":            "<pre id=\"definition\">",
    "extraction_method":             "textcontent_or_equivalent",
    "extraction_strips_markup":      true,
    "client_extraction_methods":     {"javascript":           "element.textContent",
                                      "python_beautifulsoup": ".get_text()",
                                      "ruby_nokogiri":        ".text"},
    "one_url_two_audiences":         true,
    "no_separate_json_url_required": true,
    "no_accept_header_dance":        true,
    "server_default_html_for_browser_friendliness": true,
    "accept_application_json_optional":             true,
    "client_unaware_of_surrounding_page":           true,
    "rationale":                     ["one_url_two_audiences_authors_publish_one_thing",
                                      "syntax_highlighting_does_not_break_extraction",
                                      "no_accept_header_negotiation_required",
                                      "pre_id_definition_convention_is_the_contract"],
    "supported_syntax_highlighters": ["pygments", "highlight.js", "prism", "any_html_emitter"],
    "open_questions": {
        "multiple_definitions_per_page": {
            "current_state": "id_definition_only_supports_one",
            "options":       ["id_definition_n_array_form", "class_puck_definition_multiple_allowed"],
            "current_need":  false
        },
        "malformed_json_in_pre": {
            "behavior":                      "client_raises_puck_uno_error_protocol",
            "same_as_malformed_direct_json": true,
            "html_wrapper_is_just_transport": true
        },
        "cache_headers": {
            "concern":                            "html_cached_but_embedded_json_drifts",
            "resolution":                         "standard_http_cache_control_applies",
            "json_embedding_doesnt_change_rules": true
        }
    }
}}

A class page can be served as either pure JSON or as HTML. The client checks the response's Content-Type and parses accordingly:

This means a class can publish a single URL that serves humans (browser → readable docs) AND machines (client → parsed definition). No separate .json URL; no Accept-header dance for the basic case.

Example: https://puck.uno/geo/ GitHub issue

The geolocation class. Takes a coordinate at construction, exposes methods for the various location-derived queries.

json
{
    "vibecode": {
        "class": "https://puck.uno/geo/",
        "shape":                       "remote_class",
        "domain":                      "geolocation",
        "instantiation":               "coordinate_at_construction",
        "constructor_params":          ["lat", "lon", "alt"],
        "required_params":             ["lat", "lon"],
        "queries":                     ["address", "city", "country_code", "weather",
                                        "congressional_district", "distance_to", "map_image"],
        "returns_scalars":             ["address", "city", "country_code"],
        "returns_other_puck_objects":  ["weather", "congressional_district"],
        "returns_bytes":               ["map_image"],
        "returns_numbers":             ["distance_to"],
        "us_specific_methods":         ["congressional_district"]
    },

    "class":       "https://puck.uno/geo/",
    "version":     "1.0.0",
    "description": "Geolocation service. Instantiate with a latitude/longitude (and optional altitude); query weather, address, political boundaries, map imagery, etc. for that point.",

    "constructor": {
        "lat": {
            "class":        "number",
            "required":    true,
            "description": "Latitude in decimal degrees. Range -90.0 to 90.0."
        },
        "lon": {
            "class":        "number",
            "required":    true,
            "description": "Longitude in decimal degrees. Range -180.0 to 180.0."
        },
        "alt": {
            "class":        "number",
            "required":    false,
            "description": "Altitude in meters above sea level. Optional; defaults to 0.0."
        }
    },

    "methods": {
        "address": {
            "params":      {},
            "returns":      {"class": "string"},
            "description": "Reverse-geocoded street address at the point."
        },

        "city": {
            "params":      {},
            "returns":      {"class": "string"},
            "description": "City name at the point, in the local language."
        },

        "country_code": {
            "params":      {},
            "returns":      {"class": "string"},
            "description": "ISO 3166-1 alpha-2 country code (e.g. 'US', 'JP')."
        },

        "weather": {
            "params":      {},
            "returns":      {"class": "https://puck.uno/geo/weather"},
            "description": "Current weather report at the point. Returns a Weather Puck object."
        },

        "congressional_district": {
            "params":      {},
            "returns":      {"class": "https://puck.uno/geo/congressional_district"},
            "description": "US congressional district info for the point. Returns a CongressionalDistrict Puck object. Raises `puck.uno/error/not_found` if the point isn't in the US."
        },

        "distance_to": {
            "params": {
                "other": {
                    "class":       "https://puck.uno/geo/",
                    "required":    true,
                    "description": "Another Geo object."
                },
                "unit": {
                    "class":        "string",
                    "required":    false,
                    "enum":        ["meters", "kilometers", "miles", "nautical_miles"],
                    "default":     "meters",
                    "description": "Unit for the returned distance."
                }
            },
            "returns":      {"class": "number"},
            "description": "Great-circle distance from this point to another Geo point."
        },

        "map_image": {
            "params": {
                "zoom": {
                    "class":        "integer",
                    "required":    false,
                    "default":     14,
                    "range":       [0, 20],
                    "description": "Zoom level. 0 = world view, 20 = building-level detail."
                },
                "format": {
                    "class":        "string",
                    "required":    false,
                    "enum":        ["png", "jpeg"],
                    "default":     "png",
                    "description": "Image format."
                },
                "width": {
                    "class":        "integer",
                    "required":    false,
                    "default":     512,
                    "description": "Image width in pixels."
                },
                "height": {
                    "class":        "integer",
                    "required":    false,
                    "default":     512,
                    "description": "Image height in pixels."
                }
            },
            "returns":      {"class": "bytes", "content_type": "image/png"},
            "description": "Map image centered on the point. Returns raw bytes with the indicated Content-Type."
        }
    }
}

Example: rendered page for https://puck.uno/geo/ GitHub issue

Here's what a human visitor sees in their browser when they navigate to https://puck.uno/geo/. The page is real human documentation; the machine-readable JSON is embedded at the bottom in a <pre id="definition"> element.

https://puck.uno/geo/

Geo

vibecode
{"vibecode": {
    "doc":                          "puck_uno_geo",
    "class":                        "https://puck.uno/geo/",
    "shape":                        "remote_puck_class",
    "domain":                       "geolocation",

    "protocol":                     "puck",
    "protocol_intro_for_agents":    "https://puck.uno/ai/protocol",
    "cold_agent_instructions": [
        "this_is_a_puck_class_definition_page",
        "if_unfamiliar_with_puck_fetch_protocol_intro_for_agents_url_first",
        "find_pre_id_definition_extract_textcontent_parse_as_json",
        "use_class_url_to_instantiate_via_puck_client",
        "call_methods_per_methods_hash_in_definition"
    ],

    "instantiation":                "coordinate_at_construction",
    "constructor_params":           ["lat", "lon", "alt"],
    "required_params":              ["lat", "lon"],
    "queries":                      ["address", "city", "country_code", "weather",
                                     "congressional_district", "distance_to", "map_image"],
    "returns_scalars":              ["address", "city", "country_code"],
    "returns_other_puck_objects":   ["weather", "congressional_district"],
    "returns_bytes":                ["map_image"],
    "returns_numbers":              ["distance_to"],
    "us_specific_methods":          ["congressional_district"],
    "definition_at":                "<pre id=\"definition\"> at the bottom of this page"
}}

https://puck.uno/geo/ — a Puck class for location-derived queries. Instantiate with a coordinate; query weather, address, political boundaries, map imagery, etc.

Quick example GitHub issue

python
import puck

hq = puck.lookup('https://puck.uno/geo/')(lat=37.7980, lon=-122.4626)
print(hq.city)              # 'San Francisco'
print(hq.address)           # '24 Polk St, San Francisco, CA 94102, USA'
print(hq.country_code)      # 'US'

Constructor GitHub issue

ParamTypeRequiredDescription
latnumberyesLatitude in decimal degrees (−90.0 to 90.0).
lonnumberyesLongitude in decimal degrees (−180.0 to 180.0).
altnumbernoAltitude in meters above sea level. Defaults to 0.0.

Methods GitHub issue

MethodReturnsDescription
addressstringReverse-geocoded street address at the point.
citystringCity name at the point, in the local language.
country_codestringISO 3166-1 alpha-2 country code (e.g. 'US', 'JP').
weatherWeather Puck objectCurrent weather report.
congressional_districtCongressionalDistrict Puck objectUS congressional district info. Raises puck.uno/error/not_found if the point isn't in the US.
distance_to(other, unit?)numberGreat-circle distance to another Geo. unit is one of 'meters' (default), 'kilometers', 'miles', 'nautical_miles'.
map_image(zoom?, format?, width?, height?)bytes (PNG by default)Map image centered on the point.

Machine-readable definition GitHub issue

{
    "vibecode": {
        "class":                       "https://puck.uno/geo/",
        "shape":                       "remote_class",
        "domain":                      "geolocation",
        "instantiation":               "coordinate_at_construction",
        "constructor_params":          ["lat", "lon", "alt"],
        "required_params":             ["lat", "lon"],
        "queries":                     ["address", "city", "country_code", "weather",
                                        "congressional_district", "distance_to", "map_image"],
        "returns_scalars":             ["address", "city", "country_code"],
        "returns_other_puck_objects":  ["weather", "congressional_district"],
        "returns_bytes":               ["map_image"],
        "returns_numbers":             ["distance_to"],
        "us_specific_methods":         ["congressional_district"]
    },

    "class":       "https://puck.uno/geo/",
    "version":     "1.0.0",
    "description": "Geolocation service. Instantiate with a latitude/longitude (and optional altitude); query weather, address, political boundaries, map imagery, etc. for that point.",

    "constructor": {
        "lat": {
            "class":       "number",
            "required":    true,
            "description": "Latitude in decimal degrees. Range -90.0 to 90.0."
        },
        "lon": {
            "class":       "number",
            "required":    true,
            "description": "Longitude in decimal degrees. Range -180.0 to 180.0."
        },
        "alt": {
            "class":       "number",
            "required":    false,
            "description": "Altitude in meters above sea level. Optional; defaults to 0.0."
        }
    },

    "methods": {
        "address": {
            "params":      {},
            "returns":     {"class": "string"},
            "description": "Reverse-geocoded street address at the point."
        },

        "city": {
            "params":      {},
            "returns":     {"class": "string"},
            "description": "City name at the point, in the local language."
        },

        "country_code": {
            "params":      {},
            "returns":     {"class": "string"},
            "description": "ISO 3166-1 alpha-2 country code (e.g. 'US', 'JP')."
        },

        "weather": {
            "params":      {},
            "returns":     {"class": "https://puck.uno/geo/weather"},
            "description": "Current weather report at the point. Returns a Weather Puck object."
        },

        "congressional_district": {
            "params":      {},
            "returns":     {"class": "https://puck.uno/geo/congressional_district"},
            "description": "US congressional district info for the point. Returns a CongressionalDistrict Puck object. Raises `puck.uno/error/not_found` if the point isn't in the US."
        },

        "distance_to": {
            "params": {
                "other": {
                    "class":       "https://puck.uno/geo/",
                    "required":    true,
                    "description": "Another Geo object."
                },
                "unit": {
                    "class":       "string",
                    "required":    false,
                    "enum":        ["meters", "kilometers", "miles", "nautical_miles"],
                    "default":     "meters",
                    "description": "Unit for the returned distance."
                }
            },
            "returns":     {"class": "number"},
            "description": "Great-circle distance from this point to another Geo point."
        },

        "map_image": {
            "params": {
                "zoom": {
                    "class":       "integer",
                    "required":    false,
                    "default":     14,
                    "range":       [0, 20],
                    "description": "Zoom level. 0 = world view, 20 = building-level detail."
                },
                "format": {
                    "class":       "string",
                    "required":    false,
                    "enum":        ["png", "jpeg"],
                    "default":     "png",
                    "description": "Image format."
                },
                "width": {
                    "class":       "integer",
                    "required":    false,
                    "default":     512,
                    "description": "Image width in pixels."
                },
                "height": {
                    "class":       "integer",
                    "required":    false,
                    "default":     512,
                    "description": "Image height in pixels."
                }
            },
            "returns":     {"class": "bytes", "content_type": "image/png"},
            "description": "Map image centered on the point. Returns raw bytes with the indicated Content-Type."
        }
    }
}

Shape rationale GitHub issue

Notes on the choices the example illustrates:


What happens at puck.lookup GitHub issue

python
hq = puck.lookup('https://puck.uno/geo/')(lat=37.7980, lon=-122.4626)

Under the hood:

  1. Client does an HTTP GET to https://puck.uno/geo/ requesting the class definition (per the protocol).
  2. Server returns the JSON shape documented above.
  3. Client parses the JSON; constructs a local proxy class with:
    • The constructor signature derived from the constructor block.
    • A method per entry in methods, each making a remote call when invoked.
    • Type validation per the param specs (optional; client's choice).
  4. puck.lookup(...) returns the proxy class.
  5. Calling (lat=..., lon=...) runs the proxy's constructor — usually a remote instantiation call that returns an object reference.

The client never sees the server's actual implementation; it only knows what the definition says.


© 2026 Puck.uno