hex/ios/TypingConfig/package/scripts/zone_edges.py
Ryan Vogel 17407ee391 ios: the typing-config agent package (words and key positions), and the export's layout state
ios/TypingConfig/package/ is what an export carries besides the logs: SKILL.md, reference/ and
scripts/ (Python 3 standard library, no network). From it alone, a stranger's agent can build a
format-0 .mhexconfig and check it before handing it back.
- SKILL.md tells the agent:
  - what Hex already learns by itself;
  - rules: the text stays in the folder, single words only, every value from a script, tune on
    half A and check on half B, never write an unsimulated zone, less is better;
  - steps from overview to report.
- reference/:
  - typing-config.md, the frozen format;
  - state.md, the export's state/ (phone.json, including layout, and vocabulary.json);
  - log-format.md and typing-config.schema.json, both generated.
- scripts/, key positions:
  - taps.py lines every tap up with the letter or space it was meant for and maps it onto
    today's keys;
  - key_clouds.py shows per-key landing clouds by the letter meant, beside Hex's pressed-key
    average, with aim candidates;
  - zone_edges.py lists every movable edge with the taps that fell just across it;
  - simulate_zones.py says which key every tap would press under proposed zones (with --sweep).
    geometry.py ports KeyboardZoneMap line for line, so the scripts press what the phone would;
  - simulate_aim.py is the touch-model approximation for aim.
- scripts/, the checker: check_config.py re-runs both simulations on the halves the config names
  and rejects any aim or zone whose evidence doesn't match exactly. It also recounts words,
  checks ranges, context and envelope, and fills in the id.
- scripts/, the study's tools: word_outcomes.py (now with session counts and a
  never-correct-to list), words, hexlog, overview, split, space_edges, timings, dictation.
- TypingConfigExportState.layout(_:) gives the phone lane's state writer today's keyboard:
  context, keycap size, touch area, and every key's frame, hitFrame and gapHitFrame.
- build-typing-config.py also writes the package's copies of the schema and of
  docs/typing-logs.md, and --check covers them.

Verified: seven fresh agents (opencode/claude-opus-5-5, told only "Here is a folder. Follow
SKILL.md in it") each produced a config that check_config.py passes with 0 problems.
- Six worked on synthetic one-fault fixtures typed through the real engine with Record typing
  logs; the seventh on Ryan's day 1 (private).
- They found each planted fault: e aimed 0.4 keycap right (aim e +0.30 and e's right edge
  +0.20: 49 taps gained, 0 lost, on the tuning half), a right hand low, own words, a repeated
  real-word slip, and space taps high.
- Where the rules didn't hold, they left the part out: the space zone failed its check half,
  and the slip is one Learn how I type learns itself. The control got no key positions.
- The phone-side replay of these configs follows.
python3 -m py_compile passes for all scripts, and build-typing-config.py --check passes.
2026-11-23 12:47:08 -05:00

61 lines
3.3 KiB
Python

"""Every edge a zone may move, with the taps that fell just across it: taps meant for the key
that pressed the neighbour beyond that edge, and taps meant for a neighbour that landed on
the key's side, within a quarter keycap of the edge. Edges with many of the first and few of
the second are worth a sweep with simulate_zones.py. The space bar and the bottom letter row
come first.
python3 scripts/zone_edges.py [EXPORT_DIR] [--half A]
"""
import os, sys, collections
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import hexlog, taps as T, geometry as G
from limits import LIMITS
ex = hexlog.export_dir([a for a in sys.argv[1:] if os.path.isdir(a)])
half = sys.argv[sys.argv.index("--half") + 1] if "--half" in sys.argv else None
layout = G.load_layout(ex)
base = G.base_regions(layout)
taps = T.load(ex, half)
band_v, band_h = 0.25 * layout["keyHeight"], 0.25 * layout["letterWidth"]
rows = []
for i, k in enumerate(layout["keys"]):
if k["row"] < 0:
continue
edges = G._edges_for(k["id"]) or []
rects = base[i]
minx = min(r[0] for r in rects); miny = min(r[1] for r in rects)
maxx = max(r[0] + r[2] for r in rects); maxy = max(r[1] + r[3] for r in rects)
for edge in edges:
line = {"top": miny, "bottom": maxy, "left": minx, "right": maxx}[edge]
ta = layout["touchArea"]
if (edge == "top" and line <= ta[1] + 0.01) or (edge == "bottom" and line >= ta[1] + ta[3] - 0.01) or \
(edge == "left" and line <= ta[0] + 0.01) or (edge == "right" and line >= ta[0] + ta[2] - 0.01):
continue
across = mine = risk = 0
neighbours = collections.Counter()
for t in taps:
x, y = t["x"], t["y"]
if edge in ("top", "bottom"):
if not (minx <= x < maxx): continue
d = (line - y) if edge == "top" else (y - line)
band = band_v
else:
if not (miny <= y < maxy): continue
d = (line - x) if edge == "left" else (x - line)
band = band_h
if 0 <= d < band and t["meant"] == k["id"] and t["now"] != k["id"]:
across += 1; neighbours[t["now"]] += 1
elif 0 <= d < band and t["meant"] != k["id"] and t["now"] == t["meant"]:
risk += 1
elif -band < d < 0 and t["meant"] != k["id"] and t["now"] == k["id"]:
mine += 1
if across or mine:
rows.append((k["id"], edge, across, risk, mine, neighbours))
rows.sort(key=lambda r: (-(r[0] == "space" or (len(r[0]) == 1 and r[0] in "zxcvbnm")), -(r[2] - r[3])))
print("half %s: taps within a quarter keycap of each edge (sweep the top ones with simulate_zones.py --sweep key:edge)" % (half or "A+B"))
print(" fell out: meant for the key, landed just beyond this edge on a neighbour (growing the key gains them)")
print(" at risk: the neighbour's own taps in that band (growing the key would lose them)")
print(" came in: a neighbour's taps that landed just inside this edge (shrinking the key gains them)")
print("%-14s %-7s %8s %8s %8s %s" % ("key", "edge", "fell out", "at risk", "came in", "pressed instead"))
for key, edge, across, risk, mine, nb in rows[:30]:
print("%-14s %-7s %8d %8d %8d %s" % (key, edge, across, risk, mine, ", ".join("%s %d" % x for x in nb.most_common(3))))