Repository navigation
feat(app-kit): keep desktop app shortcuts and prefs per machine - #37457
Conversation
|
Decisions taken under the owner ruling (#26967, comment 6841699202), for the reviewer:
|
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing blocks: the diff adds no rendered control. It adds manifest parsing, Electron main-process stores and level-3 bridge calls ( Notes
[UX-REVIEWED] c560438 Description read[DESCRIPTION-READ] be86609548833a9bbe98a681b27a1880f744b9e67dd88bf93827d6bde8583773 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the new manifest key, the bridge calls and the reservation hand-over are all additive and app-agnostic, and Mochi's id appears only in the hand-off code under Notes
[DESIGN-REVIEWED] c560438 Description read[DESCRIPTION-READ] 5293d534a7f1d62157e03485ebdd4095f74dd6778e7fe619e0ad52ac50c1c525 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS One rider ships ahead of its only caller: the Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: let an adopted desktop app (Mochi) keep users' rebinds, per-OS default keys and chosen crew once the window host serves it — ADDITION.
[FIRST-PRINCIPLES-REVIEWED] c560438 Description read[DESCRIPTION-READ] c1a8e4ee9940c19a502c88e71526df78507e7184b3b80ea3e957aa2b04d5fb97 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
0baa3e5 to
6154e62
Compare
|
Review finding: the legacy-store guards had no test that fails without them:
|
|
Review finding: never-overwrite was tested only for the gateway choice, and the import order not at all:
|
|
Review finding: after any click, a page could move a shortcut onto any chord the rule allows:
|
|
Review finding: prefs and bindings are keyed by app name and never pruned:
|
|
Review finding:
|
|
Review finding: one duplicate chord was reported three times:
|
|
Review finding: the spec cited the wrong ruling, and the prefs API and import are not shown at install: attribution
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 14% chance that this change introduces a defect, above the 12% limit for approving on its own. The PR adds per-platform shortcut defaults, user rebinding of shortcuts through the window host, a hand-over of reserved chords that apps must opt into, and a seeded copy of Mochi's crew choice and rebinds. I checked each part in the code. Rebinding: only within 2 s of the user acting in the window, one request per press, and a chord other than the default must be the one the user actually pressed. The new chord is registered before the old one is released, so a refused rebind keeps the app's chord. Reservation hand-over: only to the owner's own app id, and only when every owner holding the chord agrees. All callers of isReserved were updated. Hand-off: it runs inside a try/catch before the host is created. The crew choice is used only when the app holds the gatewayChoice capability, and the copy-again rule never overwrites a choice made through the host. The Python and JavaScript parsers agree, signing is unchanged for existing manifests, and nothing changes for users today because no built-in declares a desktop block. Tests cover the new behaviour, including the cases that must be refused. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
8aacf04 to
38df4db
Compare
|
self-added: yes
|
|
resolution: removed the pending host-side import that could land late
|
|
Design note for the reviewer: decisions 2 and 3 in the first comment (the declared |
38df4db to
d1b69b5
Compare
|
|
|
|
|
The desktop window host gave an app fixed manifest accelerators and no per-machine state, so a desktop pet could not move onto it: its users rebind its global shortcuts, its defaults differ per platform, its shell code reserves its chords even while disabled, and the crew it shows plus the rebinds live in a shell store a window page cannot read (#36349 left the shortcut gap under "Not a goal"). Generically, with the app id as data: - desktop.shortcuts[].platformAccelerators: a per-platform default, held to the same chord rules (gateway and shell); seam level 8. - The host binds the user's chord per app per machine, and a page's shortcuts() / setShortcut() (bridge level 3) lists and rebinds only the app's declared shortcuts, only right after a press in that window, and onto a chord other than the declared default only when the user pressed that chord there. The new chord is registered before the binding moves, so a refused rebind or reset keeps the chord the app held and never frees it for another app. - A shell owner that is an app's own shell code may reserve { app: true } so the host serving that app id may bind those chords. Mochi keeps a plain reservation until its built-in steps aside (#37454), so the two never register the same chords. One binding is one chord whatever its spelling, so a respelled rebind keeps the chord with its holder. For Mochi, its own shell code (mochi/hostHandOff.js, called from initMochi before the host is created) copies the crew the pet shows and the user's rebinds from mochi-machine.json into the host's gateway choice and bindings for mochi, recording what it copied. It copies again only while the host still holds that value, so a change in the built-in before adoption carries over and a choice made through the host is never overwritten. It leaves core with Mochi's shell code. Built-ins behave as before: no built-in declares a desktop block, so the host serves none of them yet. Part of #26967
d1b69b5 to
c560438
Compare
buluoray
left a comment
There was a problem hiding this comment.
Approve on c560438. This PR lets a desktop app that the window host serves keep the user's own shortcut keys and a per-platform default on each computer, and it lets Mochi's own shell code copy the crew the pet shows and the user's rebinds into the host's stores ahead of Mochi moving onto the host. Nothing changes for users today, because no built-in declares a desktop block yet. Mochi's existing file is only read, apart from one new record of what was copied, so an upgrade or a downgrade loses nothing. The copy repeats only while the host still holds the value it last copied, so a choice the user makes through the host is never overwritten; tests turn red when the copy is skipped or made unconditional. The new store is written the same way as the shell's existing stores: atomically and owner-only. No app id appears in the host code. This head is rebased onto a main that carries #37545, the fix for main's red metrics tests (#37546), and its CI run is green. Follow-ups: a test that fails when the hand-off is not wired into startup, and a note for #37454 that a Mochi rebind which the host's chord rule refuses falls back to the default after adoption. Decisive lines: website/electron/mochi/hostHandOff.js:56-58 (hostStillSeeded), website/electron/mochi/hostHandOff.js:83-122 (seedHostMachinePrefs reads mochi-machine.json and writes only the new mochi.hostHandOff record there), website/electron/mochi/index.js:1447-1459 (hand-off runs in try/catch), website/electron/main.js:913-931 (prefs store opened 0600 and handed to initMochi before the host is created), website/electron/app-window-host.js:1087-1106 (rebindShortcut registers the new chord before the binding moves), website/electron/shell-shortcut-reservations.js:98-106 (hand-over only for an owner that opted in with { app: true }), docs/system-specs/modules/app-kit-platform.md (§35 updated in the same commit)
Problem / Motivation
Goal: A desktop app the window host serves keeps the user's own shortcut keys, its per-platform defaults and its per-computer settings, and an adopted built-in brings the user's chosen crew and rebinds along, so Mochi can move onto the host without its users losing anything.
The window host (§35) gives an app fixed manifest accelerators and no per-computer state. Mochi's shell code has four things the host could not express, so an adopted Mochi would regress for its users (owner ruling on #26967, comment 6841699202: "decide directly; users' normal use must not be affected; grant what is needed"):
CommandOrControl+Shift+M/H/Xon macOS,Alt+Shift+M/H/Xelsewhere) while the manifest takes one accelerator;reserveMochiShortcutsholds Mochi's chords even while it is disabled, so the host would refuse an adopted Mochi declaring the same chords;mochi-machine.json, which a window page cannot read.#36349 named the shortcut gap under "Not a goal" ("user-rebindable shortcuts"); this is that gap.
Why it matters
Mochi cannot leave core (#26967) while these exist only as Mochi's main-process code. Without them an external Mochi would bind fixed keys its users had moved, use macOS chords on Windows and Linux, be refused its own chords, and forget which crew the pet showed.
Not a goal
desktop-host-serve(feat(app-kit): let built-in shell code step aside for the window host #37454). This PR only hands over the reservation and seeds the gateway choice that lane reads.desktopblock to the built-in manifest, or creating Mochi's repository.What changed (motivation → approach → change)
Goal: the four Mochi-only behaviours as app-agnostic host seams, with the app id as data; Mochi's own state handed over by Mochi's own shell code.
Approach: the shell keeps the user's bindings the way it keeps
appWindowGatewayChoices, in a newapp-window-prefs.jsover its own 0600app-window-prefs.json; every page call resolves to its sender's own app. Mochi's per-computer settings are the crew the pet shows and its rebinds, so they land in the gateway choice and the bindings; a page gets no second, generic store.desktop.shortcuts[].platformAccelerators(macos/windows/linux), each held to the chord rule, unique per platform; parsed inapps/desktop_manifest.pyandapp-window-host-rules.js.shortcuts()andsetShortcut(id, accel|""|null): only a declared shortcut, only within 2 s of a press in that window, never a background page, only the manifest's chord rule and no chord another of the app's shortcuts holds; a chord other than the declared default only when the user pressed it in that window (before-input-event, elsenot-pressed). The new chord is registered before the binding moves, so a refused rebind or reset keeps the chord the app held and never frees it for another app.shell-shortcut-reservations.js: an owner reserving{ app: true }under an app id does not block the host serving that app. Mochi keeps its plain reservation until its built-in steps aside (feat(app-kit): let built-in shell code step aside for the window host #37454): opting in earlier would let the built-in and the host register the same chords. One binding is one chord whatever its spelling, so a respelled rebind keeps the chord with its holder.mochi/hostHandOff.js, run byinitMochibeforemain.jscreates the host, copies the crew and the rebinds frommochi-machine.jsoninto the host's stores formochiand records what it copied. It copies again only while the host still holds that value, so a change in the built-in before adoption carries over and a choice made through the host (a reset, "self", a new chord) is never overwritten: the rule of Crew Companion'sdisplayHandOff.js. It leaves core with Mochi's shell directory; the host has no import of its own.Wiring:
main.jsopens the bindings store beforeinitMochiand hands both stores to it;package.jsonbuild.filesgains the two modules (no dependency change). Level:platformAcceleratorsjoins unreleased App Kit seam level 8;scripts/adoption_pin.pymaps it. Types indesktopWindowTarget.ts. Specs: app-kit-platform §35/§32, mochi.md, manifest reference, electron README.Backwards compatibility
Compatible: the manifest key is new and optional, the bridge calls are additive behind
level,isReservedanddesktopDeclarationstake only new optional arguments, and only an owner that opts in with{ app: true }is handed over. No built-in declares adesktopblock, so the host serves none of them and nothing changes for a user until an app adopts. The hand-off only writes the host's entries formochi, which the host reads only for an installed app of that name declaring those shortcuts (and, for the crew, holding approvedgatewayChoice).Removes nothing: no key, call, record or row is removed or tightened;
mochi-machine.jsonis only read, apart from Mochi's ownmochi.hostHandOffrecord in it.Tests
website/electron/test/app-window-host-prefs.test.js: the per-platform default on darwin, linux and win32; listing; a rebind moving the chord and surviving a restart; unbind and reset; NEGATIVE: no press, a stale press, a second request on one press, a stranger sender and a background page cannot rebind; an undeclared or another app's shortcut, a single-modifier chord, a chord on another of its shortcuts, a reserved chord, another app's chord and another program's chord are refused with every binding unchanged; a refused reset or rebind keeps the app's custom chord from another app declaring it, which takes it only once a move succeeds; respelling a held chord keeps it from an app listed first that declares it; a chord the page picked after a click, another chord, one pressed in another window, a stale, spent, repeated or released press are refusednot-pressed, while the pressed chord (by position or character), the default,""andnullpass; the hand-over only to the app named by an{ app: true }owner; bindings kept across a listing without the app.mochi/test/hostHandOff.test.js: the adopted declaration's defaults and ids equalshortcuts.js; the crew and the rebinds reach the host (a chord at the built-in's default is no binding) and a second start writes nothing; a change in the built-in before adoption carries over; NEGATIVE: a "self", a reset or a new chord made through the host is never copied over, even when the built-in's value moves later; before any copy, a host value of its own is kept; a rebind the host's rules refuse leaves the host's default; onlymochi's entries are written.app-window-host-rules.test.js,test/test_app_manifest_desktop.py:platformAcceleratorsparses, round-trips, is signed and is refused outside the rules on every platform; a repeated chord is one refusal naming only the platforms it repeats on; adesktopblock asking for anything else is refused;pressedChord/keyPressChordsper platform.shell-shortcut-reservations.test.js: the hand-over only to the app an{ app: true }owner names, never for a plain owner.app-window-preload.test.js: the level 3 calls and their empty answers.test_builtin_adoption_pins.py:platformAcceleratorsmaps to level 8.Mutation check: dropping the pre-registration in
rebindShortcutreds the refused-reset test and the refusal test; comparing a binding by its spelling instead of its chord reds the respelling test; letting the hand-off always copy reds both of its NEGATIVE keep-the-host's-choice tests, and copying over a host value before any record reds the second; dropping the app argument from the host's reservation check reds the hand-over test; servingsetShortcutto any sender instead of one the user is acting in reds the no-press test; dropping the pressed-chord check, its spend or its 2 s window reds thenot-pressedtest.Determinism: the touched Electron files 3x green; the full Electron suite green in its default order and with the file order reversed, apart from three
packaging.test.jscases that need this host's absentnode_modules/app-builder-lib; 419 related backend tests green; flake-pattern ratchet green. The new tests use the injected clock or plain Map stores and no sleep.Local gates: black (pinned 26.10.1) on the changed Python, isort, flake8, mypy on the changed module, comment-history, brand, harness parity, file-line cap, docs-lint. The only
website/src/change is a type declaration with no other reference. Semgrep is not installed on this host; CI's SAST runs it. Local review ran as a self-review against the lanes' contracts: this host has no model-pinned subagent facility.Manual verification
N/A for a live desktop session: the host was exercised through the injected-Electron tests only, as in #36349. No window, prompt or page renders differently.
Screenshots / video
Why no screenshot: the only file under
website/src/is a type declaration for the bridge, and nothing renders differently.Related Issues
Part of #26967
Owner ruling: #26967 (comment) (also the 2026-11-07 ruling 6713005850, item 5: the generic window seam). Gap named by #36349.
Same batch, separate lanes: Mochi's
reserveMochiShortcutsopts into the hand-over ({ app: true }) together with its step-aside, in #37454 or right after it.desktop-host-serve(#37454) touchesapp-window-host.js,app-window-host-rules.js(itsdesktopDeclarationsoptions object composes with this one'splatform), the independence gate and the same specs; whichever lands second rebases.app-chat-slot-createshares no file.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)