hex/tests/fixtures/hex-words/hex-words.schema.json
Ryan Vogel ff9c7fc1a2 docs: define the Hex words file (.hexwords), version 1, with shared cases
Ryan approved sharing vocabulary and word replacements between the desktop,
iPhone and Android apps through a file the person moves themselves. Three
builders start from this in parallel, so the format is written down and frozen
first, with cases all three apps must pass.

- docs/specs/hex-words.md: every field and limit, how text is cleaned and
  compared, the reading order with its refusal and skip reasons, versions,
  what each app writes, the merge rules (desktop and phone) and Undo, the
  file's name and type on each platform, and what a reader must never do.
- tests/fixtures/hex-words: read.json (54 cases over files/, from small to
  hostile: not UTF-8, 10,000 levels deep, duplicate keys, lone surrogates,
  8 MiB + 1 byte generated), merge.json (24 desktop and phone cases),
  write.json (6 cases) and hex-words.schema.json (JSON Schema 2020-12 for
  writer output). files/ is byte-exact (-text -whitespace).
- docs/README.md links the spec.

No app code changes. The typing config (.mhexconfig) stays separate: its
parts need evidence and Full Access, and it describes one phone's keyboard.

Verified: the expected results were produced by a throwaway Python reference
reader, merger and writer (not committed) and read through by hand; every
write.json output and the valid read results re-written validate against the
schema with jsonschema 4.26, and five malformed writer outputs are rejected;
a file with every list at its limits in 4-byte characters is 6.5 MiB, under
the 8 MiB cap; markdownlint-cli2 is clean on the new docs.
2026-11-24 17:45:25 -05:00

121 lines
3.7 KiB
JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Hex words file, version 1",
"description": "What a writer must produce (docs/specs/hex-words.md). Readers are more lenient: a file that fails this schema can still be partly read, by the rules in the definition. Not expressible here, and still required of writers: every term, spelling and heard phrase has a letter or digit; terms are unique ignoring case (the key in the definition), spellings are unique within their term and differ from it, heard phrases are unique; text is NFC.",
"type": "object",
"required": [
"format",
"version",
"madeBy",
"vocabulary",
"replacements"
],
"additionalProperties": false,
"properties": {
"format": {
"const": "hex.words"
},
"version": {
"const": 1
},
"madeBy": {
"type": "object",
"required": [
"app"
],
"additionalProperties": false,
"properties": {
"app": {
"$ref": "#/$defs/line",
"maxLength": 64,
"description": "Hex for Mac, Hex for Windows, Hex for Linux, Hex for iPhone or Hex for Android"
},
"version": {
"$ref": "#/$defs/line",
"maxLength": 32
}
}
},
"vocabulary": {
"type": "array",
"maxItems": 500,
"items": {
"type": "object",
"required": [
"term"
],
"additionalProperties": false,
"properties": {
"term": {
"$ref": "#/$defs/line",
"maxLength": 64
},
"soundsLike": {
"type": "array",
"minItems": 1,
"maxItems": 16,
"uniqueItems": true,
"items": {
"allOf": [
{
"$ref": "#/$defs/line"
},
{
"$ref": "#/$defs/eightWords"
}
],
"maxLength": 64
}
}
}
}
},
"replacements": {
"type": "array",
"maxItems": 1000,
"items": {
"type": "object",
"required": [
"heard",
"write"
],
"additionalProperties": false,
"properties": {
"heard": {
"allOf": [
{
"$ref": "#/$defs/line"
},
{
"$ref": "#/$defs/eightWords"
}
],
"maxLength": 128
},
"write": {
"type": "string",
"maxLength": 1000,
"pattern": "^[^\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u061c\\u180e\\u200b\\u200e\\u200f\\u202a-\\u202e\\u2060-\\u2064\\u2066-\\u2069\\ufeff\\ufff9-\\ufffb]*$",
"description": "Kept exactly. May be empty (deletes the heard phrase) and may hold line feeds and tabs, never a carriage return."
},
"learned": {
"const": true,
"description": "Written only for a fix Hex learned on a phone; left out otherwise."
}
}
}
}
},
"$defs": {
"line": {
"type": "string",
"minLength": 1,
"pattern": "^[^ \\u0000-\\u001f\\u007f-\\u00a0\\u00ad\\u061c\\u1680\\u180e\\u2000-\\u200b\\u200e\\u200f\\u2028-\\u202f\\u205f-\\u2064\\u2066-\\u2069\\u3000\\ufeff\\ufff9-\\ufffb]+( [^ \\u0000-\\u001f\\u007f-\\u00a0\\u00ad\\u061c\\u1680\\u180e\\u2000-\\u200b\\u200e\\u200f\\u2028-\\u202f\\u205f-\\u2064\\u2066-\\u2069\\u3000\\ufeff\\ufff9-\\ufffb]+)*$",
"description": "Cleaned one-line text: no leading, trailing or double spaces, no other whitespace, no hidden characters."
},
"eightWords": {
"type": "string",
"pattern": "^[^ ]+( [^ ]+){0,7}$"
}
}
}