Skip to content

Add built-in macOS window placement provider - #52

Draft
LivioGama wants to merge 7 commits into
fdussert:mainfrom
LivioGama:codex/native-macos-window-core
Draft

LivioGama wants to merge 7 commits into
fdussert:mainfrom
LivioGama:codex/native-macos-window-core

Conversation

@LivioGama

Copy link
Copy Markdown
Contributor

What this changes

Adds a built-in-only macOS window-placement provider for Fremkit's rectangle command. Each action uses a freshly inspected target, a unique Core Graphics window ID, a one-use token, and geometry verification; the provider excludes Fremkit's own windows and does not invoke or depend on Rectangle.app.

How to see it

Pair this provider with the Rectangle widget PR in fdussert/fremkit-sietch. On macOS, grant the Fremkit helper Accessibility access, select a harmless target window, then try left-half, right-half, fill, and next-display. Existing native acceptance verified left-half, right-half, and fill against an owned scratch window. Next-display correctly returned no-next-display on the one-display test setup; transfer to a second physical display remains unverified.

Checks

  • Focused provider suite: 18/18 passed on this exact source tip, according to the task's verification receipt; not rerun while preparing this PR.
  • Source and test TypeScript checks passed on this exact source tip, according to the task's verification receipt; not rerun while preparing this PR.
  • Round-two independent Deep review approved the current core source hashes at ac5dbfd63fa1384a927a5114e461c04f475637a0.
  • Only the provider registration, native helper/provider, and focused provider tests are in the change.
  • No Rectangle.app invocation or dependency; no private screenshot or machine-specific data is included.
  • Upstream CI and maintainer review are pending. Both source commits are unsigned; please review the exact PR head before merge.
  • Second-display transfer is unverified because the acceptance machine had one connected display.

The branch is 13 commits behind current upstream main; the merge-tree check found no conflicts. The PR preserves the exact reviewed source commits, so it has not been rebased. The worktree contains an existing untracked server/node_modules directory; it is not part of this PR.

@fdussert

Copy link
Copy Markdown
Owner

Thanks Livio, this is a lot of careful work: fresh window IDs, one-use tokens, geometry verification. Two things stop it from landing as it is:

  1. It runs Swift source through /usr/bin/swift at call time. That needs the Command Line Tools on the user's Mac and doesn't exist in the downloadable app, which ships the server as a Node single executable. Native code belongs in the helper (native/), built once with the app, which already holds the Accessibility grant.
  2. Overlap with work in flight. @mcouzinet has helper: windows that land on the Edge come back #7 and fence: a patrol, for a pointer that arrives without moving #9 open on windows that land on the Edge, in the helper too. Window management on the Mac side is a design decision we should make together before either lands.

The widget side also can't be both "built-in only" and published on the registry. I'll put this on hold until #7/#9 settle, and loop you in on that discussion.

devin-ai-integration Bot and others added 5 commits October 21, 2026 01:42
The widget bridge adds instanceId to every command payload, so the
strict inspect/run schemas rejected every request with
invalid-request and the widget showed "no safe target" for any tap.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Two gaps showed up against live apps. Some frontmost apps never report a
focused window — Electron shells among them — while AXMainWindow or the
window list still answer, so inspect now falls back through those
attributes; identity is still proven by the Core Graphics window match.

And an app can answer the Window → Move & Resize press without honouring
it (Warp's menu item exists yet does nothing), which surfaced as
geometry-unverified. When the menu did not move the window to the target
frame, its position and size are now set directly on the AX window and
re-verified.

Co-Authored-By: Claude <noreply@anthropic.com>
CGWindowList omits window names unless the caller holds Screen
Recording, so every candidate was dropped and inspect answered
no-safe-window under the helper identity while succeeding under a
terminal that has the grant. An empty candidate title now means
"unknown" rather than "different": the owner PID and bounds still
prove identity, and the widget finally shows the inspector's real
error — such as accessibility-permission-required — instead of the
generic no-target.

Co-Authored-By: Claude <noreply@anthropic.com>
Each `swift file.swift` invocation costs several hundred milliseconds
in the compiler driver before the script's first line, which made every
inspect and every action feel laggy. resolveNative builds the script
once under a content hash in the shared cache and runs that binary,
falling back to the interpreter when no toolchain is available.

Co-Authored-By: Claude <noreply@anthropic.com>
The next-display action walked every NSScreen, so a window on the last
screen in sorted order wrapped onto the Xeneon Edge — the strip is the
dashboard itself, not a destination for app windows.

kioskDisplayIDs() finds the screen the helper's kiosk covers edge-to-edge
(layer > 0 plus an exact CGDisplayBounds match, which the layer-0 admin
window that stops at the menu bar can never satisfy) and nextDisplayIndex
cycles only through the remaining screens. A window already sitting on the
kiosk display moves to the first usable one; when no usable screen remains
the action reports no-next-display as before.

The selection logic runs under a test-next-display probe like the existing
identity tests.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@fdussert fdussert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Livio, the follow-ups are solid work: the owner-and-bounds match without Screen Recording, skipping the Edge on next-display, and the tests around both. A few things still stand between this and main:

  1. The Swift still runs on the user's Mac. Compiling with /usr/bin/swiftc into $TMPDIR on first use moves the problem without solving it. Without the Command Line Tools, swift/swiftc are xcode-select shims that pop the "install developer tools" dialog, and with the widget polling every 1–2 s that dialog will keep coming back. The cached binary is also run on presence alone (no ownership or mode check), with the helper's Accessibility grant behind it. This needs to live in native/ as a small executable built and signed with the helper, the way fremkit-scan is (build-helper.sh, build-app.sh, path passed in by the helper like FREMKIT_SCANNER).
  2. It breaks the downloadable app. rectangle.ts:23 resolves new URL(..., import.meta.url) at module load. In the CJS bundle import.meta is empty, so the server throws ERR_INVALID_URL on startup, whether or not anyone installed the widget.
  3. CI: rectangle.test.ts shells out to /usr/bin/swift and AppKit; CI runs on Ubuntu. Once the code is in native/, those cases belong in scripts/test-helper.sh.
  4. Smaller: window titles go through argv (visible to ps), so stdin or the window id alone would be better; a demo fake for the rectangle channel; the test-only modes shouldn't ship in the production binary; after rebasing on main, CommandContext needs paired in the tests and the provider goes in registerRealProviders().
  5. On the Sietch side (fdussert/fremkit-sietch#19): the README still says "built-in" and mentions the Refresh button that 1.2.0 removed, and author should be you.

The design question with #7/#9 still holds, so this stays on hold for now. Fixing 1–3 would make it ready to pick up as soon as that's settled.

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.

2 participants