mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
The zone rule counted taps: a zone was kept when, on the check half, it gained at least 3 taps net
and lost at most a third of what it gained. Taps overstate a zone's cost and understate its gain:
Hex's next-letter odds and autocorrect repair most letter taps that press a neighbour, while a
space read as a letter runs two words together. Replaced by a rule on words.
- simulate_zones.py also scores each zone on the logged words, using what the log says Hex did
with each: an untouched word keeps its outcome; a wrong word whose taps all become right is made
right; a right word with a new slip stays right as often as Hex repaired a word with one slip of
that kind (letter, space as letter, which also joins the next word, letter as space, other key)
in that half, leaning toward Hex's own rate on 106 people of two public recordings when the
person's log has few examples. Prints wordsRight and wordsWrong, --sweep by net words, --repair
the rates. It can't see context or words deleted and retyped differently (reference, "How a zone
is scored").
- The rule (limits.json, generated into TypingConfigLimits.swift, limits.py and the schema):
tuned >= 15 taps in the strip and more words right than wrong; checked >= 10 taps, words right -
wrong >= 2, wrong <= 34% of right. Removed: zoneMinNetCheckedTaps, zoneMaxLostShare (and
minNetCheckedTaps, maxLostShare). Added: zoneMinCheckedTaps, zoneMinNetCheckedWords,
zoneMaxWrongShare, repair, repairPrior.
- Zone evidence gains wordsRight and wordsWrong (TypingConfigFile.Tally, optional; required by the
schema). check_config.py demands them exactly as simulate_zones.py prints them. The phone's review
applies the same rule, so a zone with tap-only evidence is now skipped as notEnoughEvidence. No
config with zones has shipped (the experiment is off by default).
- words.py recognises a run-in deleted and typed again as two words (retyped_as_two), so the word
rule sees the words a missed space broke.
- SKILL.md, the reference's zone section and worked examples, and docs/typing-configs.md follow.
Verified, on 2b5f2ae8:
- HEXMobileTests: 981 tests, 0 failures (4 skipped), Studio, iPhone 17 Pro sim, iOS 27.2.
- Fresh agents on the six planted-fault fixtures and Ryan's day 1 built configs that pass
check_config.py with 0 problems.
- 106 public-recording people, tuned on half A by the package's rules, scored by replaying half B
through the real keys: under the word rule 27 have a config, 4 a zone (all the space bar);
8 better, 15 unchanged, 4 worse, each worse one by 1-2 words and from aim only; errors 2752 ->
2576, 185 words made right, 19 wrong. Under the tap rule: 5 zones, 7 / 15 / 5, 2574, 189 / 23.
- The estimate against the engine on 33 zone-only replays: 211 words right and 66 wrong
estimated, 323 and 111 replayed; every zone the rule would keep improved the replay, and each of
the three that cost words (13, 16 and 2) is rejected.
162 lines
11 KiB
Python
162 lines
11 KiB
Python
#!/usr/bin/env python3
|
|
"""Generates the typing config's limits for the phone and the agent package from one table.
|
|
|
|
python3 scripts/build-typing-config.py # write the generated files
|
|
python3 scripts/build-typing-config.py --check # exit 1 if any is out of date
|
|
|
|
Reads TypingConfig/limits.json and writes:
|
|
- HEXShared/FullKeyboard/TypingConfig/TypingConfigLimits.swift: the clamps the keyboard and the
|
|
app apply when they read a config;
|
|
- TypingConfig/package/scripts/limits.py: the same numbers for the package's check_config.py;
|
|
- TypingConfig/typing-config.schema.json: the JSON schema an agent's config is checked against,
|
|
and the same in the package's reference/;
|
|
- TypingConfig/package/reference/log-format.md: docs/typing-logs.md, as the package carries it.
|
|
"""
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
IOS = Path(__file__).resolve().parents[1]
|
|
TABLE = IOS / 'TypingConfig/limits.json'
|
|
SWIFT = IOS / 'HEXShared/FullKeyboard/TypingConfig/TypingConfigLimits.swift'
|
|
PYTHON = IOS / 'TypingConfig/package/scripts/limits.py'
|
|
SCHEMA = IOS / 'TypingConfig/typing-config.schema.json'
|
|
PACKAGE_SCHEMA = IOS / 'TypingConfig/package/reference/typing-config.schema.json'
|
|
LOG_DOC = IOS / 'docs/typing-logs.md'
|
|
PACKAGE_LOG_DOC = IOS / 'TypingConfig/package/reference/log-format.md'
|
|
HEADER = 'Generated by ios/scripts/build-typing-config.py from ios/TypingConfig/limits.json. Do not edit.'
|
|
|
|
|
|
def swift(t):
|
|
w, k = t['words'], t['keys']
|
|
a, z = k['aim'], k['zones']
|
|
edges = ', '.join('"%s": [%s]' % (key, ', '.join('.%s' % e for e in sides)) for key, sides in z['edges'].items())
|
|
lines = [
|
|
'// ' + HEADER,
|
|
'import CoreGraphics',
|
|
'',
|
|
'/// The typing config\'s limits (format %d): what a reader clamps to and what it skips.' % t['version'],
|
|
'nonisolated enum TypingConfigLimits {',
|
|
' static let format = "%s"' % t['format'],
|
|
' static let version = %d' % t['version'],
|
|
' static let maxBytes = %d' % t['file']['maxBytes'],
|
|
' static let noteMaxCharacters = %d' % t['file']['noteMaxCharacters'],
|
|
' static let wordLetters = %d...%d' % (w['minLetters'], w['maxLetters']),
|
|
' static let maxKeep = %d' % w['keep']['maxEntries'],
|
|
' static let maxNeverCorrectTo = %d' % w['neverCorrectTo']['maxEntries'],
|
|
' static let maxFixes = %d' % w['fixes']['maxEntries'],
|
|
' static let maxDictation = %d' % w['dictation']['maxEntries'],
|
|
' static let dictationMaxWords = %d' % w['dictation']['maxWords'],
|
|
' static let maxContexts = %d' % k['maxContexts'],
|
|
' /// Contexts match on width rounded to this many points.',
|
|
' static let contextWidthRound: CGFloat = %g' % k['context']['widthRound'],
|
|
' /// Keycap height and row pitch may differ from the context\'s by this share.',
|
|
' static let contextGeometryTolerance: CGFloat = %g' % k['context']['geometryTolerance'],
|
|
' /// Each axis of an aim offset, in keycaps.',
|
|
' static let aimBound: CGFloat = %g' % a['bound'],
|
|
' /// A zone moves an edge at most this many letter keycaps.',
|
|
' static let zoneMaxMove: CGFloat = %g' % z['maxMove'],
|
|
' /// Every key keeps its keycap\'s centre plus this share of its keycap each way.',
|
|
' static let zoneKeepFromCentre: CGFloat = %g' % z['keepFromCentre'],
|
|
' /// The edges a zone may move, by key ("letter" is every letter key).',
|
|
' static let zoneEdges: [String: [KeyboardZone.Edge]] = [%s]' % edges,
|
|
' /// The least evidence a part may claim (a reader skips one that claims less).',
|
|
' static let keepMinTimes = %d' % w['keep']['minTimes'],
|
|
' static let keepMinSessions = %d' % w['keep']['minSessions'],
|
|
' static let neverCorrectToMinTakenBack = %d' % w['neverCorrectTo']['minTakenBack'],
|
|
' static let fixMinTimes = %d' % w['fixes']['minTimes'],
|
|
' static let fixMinSessions = %d' % w['fixes']['minSessions'],
|
|
' static let dictationMinTimes = %d' % w['dictation']['minTimes'],
|
|
' static let aimMinTunedTaps = %d' % a['minTunedTaps'],
|
|
' static let aimMinCheckedTaps = %d' % a['minCheckedTaps'],
|
|
' static let zoneMinTunedTaps = %d' % z['minTunedTaps'],
|
|
' static let zoneMinCheckedTaps = %d' % z['minCheckedTaps'],
|
|
' /// A zone\'s words made right less words made wrong on the check half (expected counts).',
|
|
' static let zoneMinNetCheckedWords: Double = %g' % z['minNetCheckedWords'],
|
|
' static let zoneMaxWrongShare: Double = %g' % z['maxWrongShare'],
|
|
'}',
|
|
'',
|
|
]
|
|
return '\n'.join(lines)
|
|
|
|
|
|
def python(t):
|
|
return '# %s\nLIMITS = %s\n' % (HEADER, json.dumps(t, indent=1, sort_keys=True))
|
|
|
|
|
|
def schema(t):
|
|
w, k = t['words'], t['keys']
|
|
word = {'type': 'string', 'minLength': w['minLetters'], 'maxLength': w['maxLetters']}
|
|
count = {'type': 'integer', 'minimum': 0}
|
|
def entries(props, required, n, evidence):
|
|
return {'type': 'array', 'maxItems': n, 'items': {'type': 'object', 'additionalProperties': False,
|
|
'required': required + ['evidence'],
|
|
'properties': dict(props, evidence={'type': 'object', 'required': evidence,
|
|
'properties': {e: count for e in evidence}})}}
|
|
pair = {'type': 'array', 'items': {'type': 'number', 'minimum': -k['aim']['bound'], 'maximum': k['aim']['bound']}, 'minItems': 2, 'maxItems': 2}
|
|
tally = {'type': 'object', 'additionalProperties': True, 'required': ['gained', 'lost'], 'properties': {'taps': count, 'gained': count, 'lost': count}}
|
|
words = {'type': 'number', 'minimum': 0}
|
|
zone_tally = {'type': 'object', 'additionalProperties': True, 'required': ['taps', 'gained', 'lost', 'wordsRight', 'wordsWrong'],
|
|
'properties': {'taps': count, 'gained': count, 'lost': count, 'wordsRight': words, 'wordsWrong': words}}
|
|
edge_names = sorted({e for sides in k['zones']['edges'].values() for e in sides})
|
|
return {
|
|
'$schema': 'https://json-schema.org/draft/2020-12/schema',
|
|
'$id': 'https://hex.anomaly.co/typing-config/%d.schema.json' % t['version'],
|
|
'title': 'Hex typing config, format %d' % t['version'],
|
|
'description': HEADER + ' Strict: what an agent must write. Hex itself reads leniently (reference/typing-config.md, "Reading").',
|
|
'type': 'object', 'additionalProperties': False,
|
|
'required': ['format', 'version', 'id', 'basedOn', 'madeFrom', 'madeFor', 'note'],
|
|
'properties': {
|
|
'format': {'const': t['format']},
|
|
'version': {'const': t['version']},
|
|
'id': {'type': 'string', 'pattern': '^cfg-[0-9a-f]{16}$'},
|
|
'basedOn': {'type': ['string', 'null']},
|
|
'madeFrom': {'type': 'object', 'required': ['exportId', 'hexVersion', 'hexBuild', 'logDays', 'heldOut'], 'properties': {
|
|
'exportId': {'type': 'string'}, 'hexVersion': {'type': 'string'}, 'hexBuild': {'type': 'string'},
|
|
'logDays': {'type': 'array', 'items': {'type': 'string'}},
|
|
'heldOut': {'type': 'object', 'required': ['tunedOn', 'checkedOn'], 'properties': {'tunedOn': {'enum': ['A', 'B']}, 'checkedOn': {'enum': ['A', 'B']}}}}},
|
|
'madeFor': {'type': 'object', 'required': ['device', 'language'], 'properties': {'device': {'type': 'string'}, 'language': {'type': 'string'}}},
|
|
'note': {'type': 'string', 'maxLength': t['file']['noteMaxCharacters']},
|
|
'words': {'type': 'object', 'additionalProperties': False, 'properties': {
|
|
'keep': entries({'word': word}, ['word'], w['keep']['maxEntries'], ['times', 'sessions']),
|
|
'neverCorrectTo': entries({'word': word}, ['word'], w['neverCorrectTo']['maxEntries'], ['takenBack']),
|
|
'fixes': entries({'typo': word, 'word': word, 'mode': {'enum': ['apply', 'suggest']}}, ['typo', 'word', 'mode'], w['fixes']['maxEntries'], ['times', 'sessions']),
|
|
'dictation': entries({'heard': {'type': 'string', 'minLength': 1, 'maxLength': 96}, 'meant': {'type': 'string', 'minLength': 1, 'maxLength': 96}}, ['heard', 'meant'], w['dictation']['maxEntries'], ['times']),
|
|
}},
|
|
'keys': {'type': 'array', 'maxItems': k['maxContexts'], 'items': {'type': 'object', 'additionalProperties': False, 'required': ['context'], 'properties': {
|
|
'context': {'type': 'object', 'additionalProperties': False,
|
|
'required': ['width', 'orientation', 'posture', 'language', 'letters', 'split', 'hexPlacement', 'numberRow', 'keyHeight', 'rowPitch', 'letterWidth', 'hitModel'],
|
|
'properties': {'width': {'type': 'number'}, 'orientation': {'enum': ['portrait', 'landscape']}, 'posture': {'type': 'string'},
|
|
'language': {'type': 'string'}, 'letters': {'type': 'string'}, 'split': {'type': 'boolean'},
|
|
'hexPlacement': {'type': 'string'}, 'numberRow': {'type': 'boolean'}, 'keyHeight': {'type': 'number'},
|
|
'rowPitch': {'type': 'number'}, 'letterWidth': {'type': 'number'}, 'hitModel': {'type': 'integer'}}},
|
|
'aim': {'type': 'object', 'propertyNames': {'pattern': '^.$'}, 'additionalProperties': {'type': 'object', 'additionalProperties': False, 'required': ['offset', 'evidence'], 'properties': {
|
|
'offset': pair, 'evidence': {'type': 'object', 'required': ['tuned', 'checked'], 'properties': {'tuned': tally, 'checked': tally}}}}},
|
|
'zones': {'type': 'array', 'items': {'type': 'object', 'additionalProperties': False, 'required': ['key', 'edge', 'move', 'evidence'], 'properties': {
|
|
'key': {'type': 'string'}, 'edge': {'enum': edge_names},
|
|
'move': {'type': 'number', 'minimum': -k['zones']['maxMove'], 'maximum': k['zones']['maxMove']},
|
|
'evidence': {'type': 'object', 'required': ['tuned', 'checked'], 'properties': {'tuned': zone_tally, 'checked': zone_tally}}}}},
|
|
}}},
|
|
},
|
|
}
|
|
|
|
|
|
def main():
|
|
t = json.loads(TABLE.read_text(encoding='utf-8'))
|
|
schema_text = json.dumps(schema(t), indent=2) + '\n'
|
|
log_doc = '<!-- %s Copied from ios/docs/typing-logs.md. -->\n' % HEADER.replace(' from ios/TypingConfig/limits.json', '') + LOG_DOC.read_text(encoding='utf-8').replace(
|
|
'Part of [Hex for iPhone](../README.md).\n\n', '')
|
|
outputs = {SWIFT: swift(t), PYTHON: python(t), SCHEMA: schema_text, PACKAGE_SCHEMA: schema_text, PACKAGE_LOG_DOC: log_doc}
|
|
stale = [p for p, text in outputs.items() if not p.exists() or p.read_text(encoding='utf-8') != text]
|
|
if '--check' in sys.argv:
|
|
for p in stale:
|
|
print('out of date: %s (run python3 ios/scripts/build-typing-config.py)' % p.relative_to(IOS.parent))
|
|
sys.exit(1 if stale else 0)
|
|
for p, text in outputs.items():
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
p.write_text(text, encoding='utf-8')
|
|
print('wrote', p.relative_to(IOS.parent))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|