Skip to content

Add missing settings to an existing config file - #14

Merged
TerrifiedBug merged 1 commit into
mainfrom
feat/config-key-backfill
Aug 21, 2026
Merged

Add missing settings to an existing config file#14
TerrifiedBug merged 1 commit into
mainfrom
feat/config-key-backfill

Conversation

@TerrifiedBug

Copy link
Copy Markdown
Owner

The template a new install gets lists every setting — that is how a config-only feature like tap_to_toggle is meant to be discovered. But ensureFileExists returns early when the file is already there, so anyone who upgrades keeps a config with no line for anything added since. "Edit config…" opens a file that hides half the settings, and the README becomes the only way to learn they exist.

The daemon now backfills missing defaults at startup, and again immediately before "Edit config…" opens the file.

What it will and will not do

  • Values you have set are untouched. Only keys absent from the file are added.
  • Unknown keys are left alone — your own additions, or keys from a newer yap.
  • Your formatting survives: insertion is textual, not a re-serialize, so nothing but the new lines moves. Missing keys land where the template lists them, not where the alphabet puts them.
  • It declines rather than forcing it. A section written on one line has nowhere to put a line, and splicing one in turns a tidy hand-written config into a mess that happens to parse. Those files keep their formatting and their missing keys.
  • Every rewrite is verified before it lands: the new text has to parse, and it has to differ from what was there by exactly the defaults being added. Anything else and the file is left as it is. Losing someone's config to a clever edit is far worse than an out-of-date one.

Verification

Six fixtures, each run through the real daemon under a faux HOME (CFFIXED_USER_HOME), so nothing touched a real config:

fixture result
stale real-shape config, only tap_to_toggle missing key inserted in template position, every value and every line of formatting intact
no dictation object at all whole section written, pretty-printed at the right indent, top-level keys in template order
compact one-liner { "dictation": { "hotkey": "right_option" }, … } byte-identical — declined, as designed
unknown keys (my_own_note, dictation.future_key) both survive; missing defaults added around them
malformed JSON untouched; still warns the way it always did
already complete never written — same mtime

Also two cosmetic fixes to Foundation's pretty printer so a generated section reads like the template next to it: "key" : value"key": value, and slashes are no longer escaped (~\/Recordings~/Recordings). Neither can corrupt anything, because the result is parsed and compared before it is written.

No measured path changes: one file read and parse at daemon start, and a write only when a key is actually missing.

The template every new install gets lists every setting, which is how
`tap_to_toggle` is meant to be discovered — but ensureFileExists returns
early when the file is there, so anyone upgrading kept a config with no
line for it. Clicking "Edit config…" opened a file that hid half the
settings, and the README was the only way to learn they existed.

The daemon now backfills the missing defaults at startup, and again right
before "Edit config…" opens the file. Values already set are untouched,
keys yap has never heard of are left alone, and insertion is textual so
the file keeps its own formatting; missing keys land where the template
lists them rather than wherever the alphabet puts them.

It declines rather than forcing it. A section written on one line has
nowhere to put a line, so a compact hand-written config keeps its
formatting and its missing keys. And every rewrite is verified before it
lands: the new text has to parse, and it has to differ from what was
there by exactly the defaults being added, or the file is left alone.

Verified against six fixtures under a faux HOME: a stale real-shape
config gains the key with formatting intact; a config with no dictation
object gets the whole section, indented like the template; a compact
one-liner is left byte-identical; unknown keys survive; malformed JSON is
untouched; and a complete config is never written at all — same mtime.
@TerrifiedBug
TerrifiedBug merged commit dbeecc8 into main Aug 21, 2026
1 check passed
@TerrifiedBug
TerrifiedBug deleted the feat/config-key-backfill branch August 21, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant