| Layer | Language | Size | Why |
|---|---|---|---|
| Application (engine, UI, platform bindings) | Python (3.15t, free-threaded, in the apps) | ~everything | ctypes covers Win32 (PuiKit’s Windows backend proves it incl. COM/Direct2D); PyObjC covers Quartz/AX/AppKit |
Embedding launcher, Windows (Keyhac.exe) |
C | ~150 lines | PEP 587 PyConfig isolated init, module search paths. Also: exe icon, DPI manifest. |
Embedding launcher, macOS (Keyhac.app main) |
Objective-C | ~150 lines | Same PEP 587 pattern. A real bundle executable is required so the Accessibility permission attaches to a stable identity — running under a generic python3 would grant the permission to that interpreter, not to Keyhac. |
| Build scripts | PowerShell / shell / Python | windows_app/build.ps1, macos_app/build.sh, tools/ |
No ckit, no pyauto, no compiled extension of our own. Runtime dependencies: puikit,
pyobjc-framework-{Cocoa,Quartz,ApplicationServices} (macOS only), pillow (via
puikit). The pipeline is a port of XeFM’s Makefile/bundle system — the author’s
shipped PuiKit app, the standard to follow for build infra.
windows_app/src/launcher.c — C, GUI subsystem, static CRT, delay-loaded python3XX.dll,
PEP 587 explicit search paths.resources/Keyhac.rc + Keyhac.manifest — icon, version info, Per-Monitor-V2 DPI.build.ps1 — embeddable CPython download → bundle assembly → dependency collection
→ third-party notices → compileall → cl.exe. The stdlib comes from the
python.org embeddable package under runtime\; _pth is deleted and paths come
from PyConfig alone. install_zip.ps1 installs a built zip.make venv picks the newest Python’s
free-threaded build (py -X.Yt) and build.ps1 refuses a GIL venv. The runtime is
python3XXt.dll (its stdlib zip keeps the plain python3XX.zip name), and the
launcher is compiled with /DPy_GIL_DISABLED=1: one pyconfig.h serves both
builds on Windows, so an embedder has to say which, and that picks
python3XXt.lib and the DLL name launcher.c loads. The packages are looked up in
python.org’s index-windows.json (what Python’s install manager reads) and checked
against the SHA-256 it publishes: pythonembed-3.XXt-<arch> for the runtime and,
when cross-compiling, pythoncore-3.XXt-<arch> for the headers and import library.
The embeddable’s file name changed between 3.14 (-embed-) and 3.15
(-embeddable-), which is why the URL is looked up rather than spelled. python.org’s
arm64 embeddable carries an x64 vcruntime140_1.dll; any runtime binary whose PE
machine is not the target’s is dropped. The zip is written with / entry names
rather than by Compress-Archive, whose \ names macOS and Linux unzip mangle.Keyhac.exe + runtime\ (CPython) + Lib\site-packages\ +
app\{keyhac,puikit}.Keyhac-<version>-win-x64.zip via make windows-zip,
Keyhac-<version>-win-arm64.zip via make windows-zip ARCH=arm64, and the
Microsoft Store as one .msixbundle of both (below).build.ps1 -Arch x64|arm64 writes to
build\Keyhac or build\arm64\Keyhac. Either builds on one machine with one
venv, whatever its architecture. When the venv does not match the target, the
embeddable, the headers and import library (python.org’s pythoncore package)
and the dependency wheels (collect_dependencies.py --target-platform, at the
versions the venv holds, cp3XXt from a free-threaded venv) are fetched for
the target, and MSVC cross-compiles;
that needs the ARM64 or x64 C++ build tools component. A universal binary is
not an option: python.org builds neither python3XX.dll nor the stdlib .pyd
files as ARM64X. A zip of both would double the download for a choice people
can make themselves.Ported from XeFM’s pipeline (../xefm/windows_app/build_msix.ps1,
doc/dev/WINDOWS_STORE_MSIX_PLAN.md there has the full background). The Store
route exists because it makes Windows code signing free: the package is uploaded
unsigned and Microsoft re-signs it during certification — no certificate to
buy, no SmartScreen warning, and a winget install --source msstore line for free.
build_msix.ps1 -Arch x64|arm64 — wraps that architecture’s bundle into
build\Keyhac-<version>.0-<arch>.msix, and -Bundle combines the two into
build\Keyhac-<version>.0.msixbundle (make windows-msixbundle), which is
what goes to the Store: one listing and one install command, and the device
gets the payload that matches it (the Store requires requires 4-part versions with
major ≥ 1 and revision 0, so __version__ 2.0.0 packages as 2.0.0.0, derived
not hardcoded). Emits AppxManifest.xml at pack time: runFullTrust
(classic Win32 desktop app — the hook, SendInput and UIA all work
unchanged), plus a windows.startupTask extension — the MSIX-native
replacement for the manual shell:startup shortcut, on by default and
user-toggleable under Settings → Apps → Startup.windows_app/resources/Assets/*.png) are committed,
rendered from art/icon.svg by tools/make_icons.py like every other icon
target (icons-check guards drift) — unlike XeFM, which generates them at
pack time.Package/Identity/Name, Publisher, display name) comes from the
gitignored windows_app/store.env (copy store.env.example), values copied
verbatim from Partner Center → product → Product identity. Without it the
pack warns and uses a Keyhac.Prototype identity that sideloads but cannot
be submitted.C:\Program Files\WindowsApps\...); Keyhac is
already safe: all state including the launcher’s crash log lives under
~/.keyhac, bytecode is precompiled, and nothing writes next to the exe.make windows-msix (unsigned pack; SIGN=1 to self-sign),
make install-windows-msix / uninstall-windows-msix (self-signed local
sideload test; trusting/untrusting the throwaway cert elevates via UAC), and
make release-windows-msix (repack unsigned + submit to the Store listing
via the msstore CLI — needs msstore reconfigure once, and
KEYHAC_STORE_PRODUCT_ID in store.env).PRIVACY.md (repo root) as the privacy policy.macos_app/src/main.m + KeyhacAppDelegate.m — NSApplication + embedded Python framework.build.sh refuses a GIL venv (ALLOW_GIL_PYTHON=1 for a local comparison build).
python.org installs that build as a framework of its own, PythonT.framework, and
spells every per-ABI name with a t (PythonT, python3.15t,
include/python3.15t, config-3.15t-darwin), so build.sh derives the framework
name from sysconfig’s PYTHONFRAMEWORK and the rest from sys.abiflags instead of
spelling them. The framework keeps its own name in the bundle; the launcher is
compiled with KEYHAC_PYTHON_FRAMEWORK to find it, and the MCP bridge script looks
for Python*.framework. bin/ keeps only pythonX.Yt and python3: the
free-threaded framework ships a second pythonX.Y stub that still names
/Library/Frameworks. The launcher’s old install name is read off the source dylib
and the result checked, since install_name_tool -change no-ops on a mismatch.build.sh — framework embed, delocate, signing/notarization (credentials in
gitignored signing.env); create_dmg.sh → Keyhac-<version>-macos.dmg.resources/{Info.plist.template,entitlements.plist,sitecustomize.py};
LSUIElement=YES (agent app), hardened runtime, no sandbox,
disable-library-validation.Resources/bin/keyhac-mcp-bridge execs it. build.sh’s
relocate_embedded_interpreter is what makes that true, and it fails the
build if anything under the framework’s bin/ still loads a library from
outside the bundle — a framework’s bin/pythonX.Y is only the GUI stub for
the Python.app this build drops, and every binary copied in still names the
Homebrew path it was linked against. 2.4.1 shipped exactly that (#140).MACOS_MIN_VERSION in build.sh (12.0), and it is a
decision, not a property of the build machine. 12 is the oldest macOS
Keyhac has been run on (#270, a Tart VM; the record is in
testing.md). 11 was the floor
until then, but Apple silicon cannot virtualize it, so nobody had run
it, and the floor was raised to what had been run. Without
-mmacosx-version-min, clang targets whatever macOS compiles it: 2.5.0 was
built on macOS 27 and macOS 26 refused to launch it, while Info.plist still
said 11.0. build.sh now compiles the launcher for the floor, writes the same
value into LSMinimumSystemVersion, and fails the build if any Mach-O in
the finished bundle declares a newer minimum. It also starts from an empty
bundle every time, since leftovers from earlier builds were being shipped.-arch) is built for the build machine alone, so 2.6.0 shipped
106 universal binaries and an x86_64-only pythonX.Y-intel64 none of which
could ever run (#273). build.sh drops the -intel64 launcher, thins every
Mach-O to the launcher’s slices (read off the launcher, so a universal
launcher keeps a fat bundle), and fails the build if any Mach-O still
carries an architecture the launcher lacks. Intel Macs are not supported
either way — the Homebrew cask declares depends_on arch: :arm64..pyc written there breaks the seal of the installed copy. Every Python tree
in it is precompiled by build.sh’s compile_bytecode in unchecked-hash
mode, because the default timestamp mode compares against source mtimes that
cp -R (create_dmg.sh, make install-macos-dmg) does not keep — 2.5.0 had
427 stale .pyc once installed, and no stdlib bytecode at all. A compile
failure stops the build, the launcher sets write_bytecode = 0 (as the
Windows one does), and the MCP bridge runs with -B.crftwr.Keyhac2, settled: it is the identity TCC keys the
Accessibility grant on (and NSUserDefaults the saved window frames), so changing
it after 2.0.0 shipped would revoke both for everyone installed. Reusing 1.x’s
crftwr.Keyhac would have inherited its grant instead — that window closed with
2.0.0, and the two versions could never coexist anyway (shared ~/.keyhac).
BUNDLE_ID= still overrides, for local experiments.Python’s ssl verifies with OpenSSL against a static CA file and checks no
revocation. Keyhac.app’s python.org Python.framework looks for that file at
/Library/Frameworks/Python.framework/Versions/3.14/etc/openssl/cert.pem,
outside the app: missing on a Mac without python.org’s Python
(CERTIFICATE_VERIFY_FAILED), and that installation’s certifi on a Mac with
it. The framework’s own site-packages/certifi, copied in with it, is as old
as the build machine’s. Neither, nor /etc/ssl/cert.pem, refused the
revoked eMudhra intermediates (October 2026).
So main() calls keyhac.tls.use_os_trust_store() before anything else, keyhac
deps included: truststore.inject_into_ssl() on darwin and win32, which
replaces ssl.SSLContext process-wide. urllib, requests and anything else
that builds a context afterwards verify through Security.framework / CryptoAPI:
revocation is checked, and Keychain or certificate-store roots (corporate
proxies, MDM) are trusted. A context built before the call keeps OpenSSL -
urllib.request.urlopen caches its opener on first use - which is why it is
the first thing main() does. On Windows it also covers the roots Windows has
not fetched yet, which OpenSSL reading the store would not see.
truststore is a marker-gated [project] dependency, so both bundles collect
it; if it is missing (an old pip install), Keyhac logs a warning and keeps
OpenSSL. A synced package’s own truststore is pruned like any other
distribution Keyhac already provides.
tools/collect_dependencies.py — runtime closure of pyproject.toml’s
[project] dependencies; markers gate pyobjc off Windows. Fails the build
when an installed version does not satisfy its requirement — the bundle
ships whatever the venv holds, PuiKit included, so a venv older than the
puikit>= pin would otherwise ship the old PuiKit unnoticed. It also
refuses anything not installed from a package index (an editable or
local-directory install, a local wheel, a VCS URL: a PEP 610
direct_url.json), PuiKit included, since each may be a build no one
released. A release build takes PuiKit from PyPI (make install-puikit
PUIKIT_DIR=); a local development build against the checkout names it in
KEYHAC_BUNDLE_ALLOW_LOCAL=puikit (comma-separated), and that editable
PuiKit’s version then goes unchecked, as its metadata is as old as its
install. An editable install other than PuiKit is refused regardless: only
its shim would be copied.tools/generate_third_party_notices.py — license aggregation; fails on a bundled
dist without discoverable license text.windows-app / windows-zip / macos-app / macos-dmg,
install-* / uninstall-*, clean-*. The bundle builds depend on the venv
stamp, so a changed pyproject.toml refreshes the venv before they copy
from it.make tag → make release-github → make release-macos-dmg (on macOS) /
make release-windows-zip (on Windows) → make release-whl → make release-skill;
make release-status shows where a version stands. make release-windows-msix
(on Windows) is the
odd one out: it submits to the Microsoft Store, not the GitHub Release. After the DMG
is attached, brew bump-cask-pr --no-fork --version X.Y.Z crftwr/tap/keyhac bumps the
cask in crftwr/homebrew-tap (by hand, not
from the Makefile; the cask is only a URL and a sha256 pointing at that DMG). Supporting scripts:
tools/{release_preflight,bump_version,_version_source}.py. The version lives in
keyhac/__init__.py (__version__), one number for both OSes.
make release-review (tools/release_review.py) runs before make tag,
from the release skill’s step 2, and reports what is about to ship against
CLAUDE.md’s rules; it fixes nothing. Keyhac has no CI and most changes land
through the maintainer’s own sessions, so this one pass over the last
tag..origin/main is where drift across many small changes shows.
keyhac/core/, or AppKit / Win32 under keyhac/ui/; a
Windows DLL function called with no restype declared in its file;
camelCase in the public API; the public API compared tag to head through
tests/data/api_snapshot.txt - whatever tools/api_snapshot.py classifies
as breaking, unless the major version moved - and the api-reference-check
and check-docs results. Comparing across the release sees what no single
PR does: an entry added and removed again inside it is fine, one that
shipped is not. A base older than that file (before v2.8.0) is compared
through the generated references instead, which can report a name that only
left the documentation.tests/, new or moved dependencies, core
reaching into platform/mac|win or ui, changed hooks (against
design-notes.md’s load-bearing list), lines near
UINode’s identity and lifetime, the MCP tool surface, user docstrings that
name keyhac-mac / keyhac-win (migration help, or porting history for a
comment?), and every API addition or new deprecation - the release note’s
material, and an addition is the reason a release is at least a minor.Release artifacts per version: Keyhac-<ver>-macos.dmg, Keyhac-<ver>-win-x64.zip,
Keyhac-<ver>-win-arm64.zip,
the skill bundles - one zip per folder in keyhac/skills/, all attached to the
GitHub Release - and the keyhac wheel on PyPI. PuiKit is
versioned/released independently on PyPI; Keyhac2 pins a minimum in
pyproject.toml.
A bundle built off the release tag, or from a dirty tree, is named and stamped
with a dev version (2.7.0+dev.g<sha>), and its links to the repository name the
commit. So release-skill uploads only a bundle built from a clean checkout at
the tag: from anywhere else, the keyhac-<ver>-skill.zip it looks for is not
built.
release-skill is not optional the way it looks. The bundles are the
only way a user can obtain the skills — make skill-bundle needs the
Makefile and tools/, and neither ships — so a release without it leaves
doc/ai-integration.md pointing at an asset that is not
there, and leaves anyone who connects the MCP endpoint in the half-installed
state that fails quietly: the tools work and the actions come back full of
sleep and screen coordinates.
| Item | Path (both OSes) |
|---|---|
| Config | ~/.keyhac/config.py (template copied on first run) |
| Extensions | ~/.keyhac/extensions/ (on sys.path) |
| Clipboard history | ~/.keyhac/clipboard.json |
| App settings | ~/.keyhac/settings.json |
| Extra libraries | ~/.keyhac/requirements.txt → ~/.keyhac/site-packages/X.Y/ (appended to sys.path, not purged on reload) |
With --config PATH, clipboard.json and settings.json live beside the config
(sandbox isolation). Windows portable mode (everything next to Keyhac.exe) is not
implemented yet — issue tracker.
requirements.txt (#272)The bundles are sealed, so a library Keyhac does not ship reaches config.py
through ~/.keyhac/requirements.txt and a user-started sync
(keyhac/core/python_packages.py; the user doc is in
configuration.md). The design is
XeFM’s (crftwr/xefm#664) and the module is a port of xefm/python_packages.py;
keep the two in step.
<data dir>/requirements.txt
<data dir>/site-packages/
3.14/ target, appended to sys.path with site.addsitedir
.stamp JSON: requirements sha256, host sha256, python, platform
.3.14.new/ staging: built by a sync, swapped in whole
.3.14.old/ the previous target during a swap
.pip/ pip wheel downloaded from PyPI (Windows app only)
Keymap.configure calls activate() after _prepare_extensions
and before config.py runs, on every load. It finishes a staged swap that
waited for a restart, appends the target unless the stamp names another
platform, and logs a warning when a sync is due. The check is offline; it
reads the stamp and importlib.metadata, nothing else.ui/tray.py’s PackageSync,
worker thread, outcome back through call_on_main_thread, then
keymap.configure()), or keyhac deps sync (keyhac/deps_cli.py, only
where keyhac is a command: the launchers hand Python a fixed argv). pip
runs with --target into staging, the host’s distributions as exact-version
constraints, then those are pruned and the directory is swapped in. This is
the only code in Keyhac that reaches the network, and doc/installation.md
says so..pyd stays staged and completes
at the next start.Which interpreter and which pip (keyhac_python(), pip_command()):
| Install | Interpreter | pip |
|---|---|---|
| pip / pipx / uv, source checkout | sys.executable |
python -m pip, else ensurepip’s bundled wheel |
| macOS app | sys.base_prefix/bin/python3 (the framework’s; relocate_embedded_interpreter makes it runnable) |
python3 -m pip: the python.org framework’s site-packages/pip, which build.sh keeps |
| Windows app (zip, Store) | <root>\runtime\python.exe |
neither pip nor ensurepip in the embeddable CPython: a pip wheel from PyPI, sha256-checked against PyPI’s digest, cached in site-packages/.pip/ |
pip runs with PYTHONDONTWRITEBYTECODE=1, since a .pyc written into the
signed macOS bundle would break its seal. pip still compiles what it installs,
into the target.
Verified on macOS (2026-10-22), against a Developer ID–signed, hardened-runtime
build: a sync run with the bundle’s python3 installed markupsafe from PyPI,
the same interpreter imported its unsigned _speedups .so from the target,
and the bundle gained no .pyc. Still open:
disable-library-validation, so it is expected to load), through
the tray menu end to end.runtime\python.exe from inside the MSIX package, and loading an unsigned
.pyd from ~/.keyhac have not been run there.