Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
## [Unreleased]

### Fixed
- **Zoom (⌘+/⌘−/⌘0) now reflows the page instead of scaling a fixed layout** — the View menu drove `WKWebView.magnification`, the scroll-view scale also used by pinch gestures. That enlarges an already-laid-out page inside a viewport that keeps its pre-zoom size, so nothing re-lays-out: zooming in pushed the composer below the window, and zooming out left the scaled page sitting top-left with unused gutters on the right and bottom. Zoom now goes through `WKWebView.pageZoom`, which changes the CSS viewport, so text re-wraps and flex/grid layouts rearrange the way ⌘+/⌘− does in Safari. Steps stay at 0.1 across the 0.5–3.0 range but are quantized onto a 0.1 grid (no float drift), the level still persists across launches, and an existing `webViewMagnification` value is migrated on first read (new key: `webViewPageZoom`). The policy lives in `HermesAgentCore.ZoomLevel` and is covered by `swift test`.
- **Long conversations no longer enter WebKit's virtual-measurement retry loop** — the macOS client now installs a document-start compatibility guard for the upstream transcript-virtualization bug tracked by hermes-webui issue #6654 (fixed upstream by PR #6717, first shipped in `exp-v0.52.374`). When the loaded scheduler still contains the faulty per-window retry reset, virtualization uses WebUI's supported non-virtualized fallback inside WKWebView only. Browser and iOS clients remain unchanged, and virtualization automatically resumes in the Mac client once the server supplies the corrected scheduler.

### Changed
- **Pinch-to-zoom no longer magnifies** — the trackpad pinch gesture is WebKit's scroll-view magnification, i.e. the same non-reflowing path as the zoom bug above, and it composes multiplicatively with page zoom (so a pinch could leave ⌘0 not actually at 100%). `allowsMagnification` is now disabled and ⌘+/⌘−/⌘0 is the single zoom mechanism. Mapping pinch onto page-zoom steps is a possible follow-up for users who rely on the gesture.

## [v1.7.3] — 2026-07-18

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ Sources/HermesAgent/
TunnelManager.swift # Optional SSH tunnel (Process-based)
main.swift # Entry point

Sources/HermesAgentCore/
ZoomLevel.swift # Page-zoom policy + persistence (no WebKit, unit-tested)

Tests/HermesAgentTests/
ValidationTests.swift # URL validation, preference parsing tests
ZoomLevelTests.swift # Zoom steps/clamping + zoom persistence migration

build.sh # Local build — generates Info.plist heredoc, signs ad-hoc
Package.swift # SPM — depends on Sparkle 2 only
Package.swift # SPM — Sparkle 2 + the HermesAgentCore target
Entitlements.plist # No sandbox — ad-hoc signed
appcast.xml # Sparkle update feed (hosted on GitHub Pages)
CHANGELOG.md # One entry per release — update before every tag
Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ let package = Package(
),
],
targets: [
// WebKit-free policy so `swift test` exercises the real type, not a copy.
.target(
name: "HermesAgentCore",
path: "Sources/HermesAgentCore"
),
.executableTarget(
name: "HermesAgent",
dependencies: [
.product(name: "Sparkle", package: "Sparkle"),
"HermesAgentCore",
],
path: "Sources/HermesAgent"
),
.testTarget(
name: "HermesAgentTests",
dependencies: [],
dependencies: ["HermesAgentCore"],
path: "Tests/HermesAgentTests"
),
]
Expand Down
29 changes: 20 additions & 9 deletions Sources/HermesAgent/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AVFoundation
import Carbon.HIToolbox
import Cocoa
import HermesAgentCore
import Network
import Sparkle

Expand Down Expand Up @@ -851,23 +852,33 @@ class AppDelegate: NSObject, NSApplicationDelegate {

// MARK: - View zoom (fix #24, #43 — zoom level persisted)

static let zoomKey = "webViewMagnification"
private let zoomPreferences = ZoomPreferences()

@objc func zoomIn() {
/// Applies the zoom to the front-most browser window (see `ZoomLevel`).
private func applyZoom(_ level: ZoomLevel) {
guard let webView = keyBrowserWindow?.webViewForZoom else { return }
webView.magnification = min(webView.magnification + 0.1, 3.0)
UserDefaults.standard.set(webView.magnification, forKey: Self.zoomKey)
webView.pageZoom = CGFloat(level.factor)
zoomPreferences.save(level)
}

/// Read from the live web view so each window continues from its own value.
private func currentZoom() -> ZoomLevel {
guard let webView = keyBrowserWindow?.webViewForZoom else {
return zoomPreferences.load()
}
return ZoomLevel(clamping: Double(webView.pageZoom))
}

@objc func zoomIn() {
applyZoom(currentZoom().increased())
}

@objc func zoomOut() {
guard let webView = keyBrowserWindow?.webViewForZoom else { return }
webView.magnification = max(webView.magnification - 0.1, 0.5)
UserDefaults.standard.set(webView.magnification, forKey: Self.zoomKey)
applyZoom(currentZoom().decreased())
}

@objc func zoomReset() {
keyBrowserWindow?.webViewForZoom?.magnification = 1.0
UserDefaults.standard.set(1.0, forKey: Self.zoomKey)
applyZoom(.identity)
}

@objc func openPreferences() {
Expand Down
19 changes: 12 additions & 7 deletions Sources/HermesAgent/BrowserWindowController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AVFoundation
import Cocoa
import HermesAgentCore
import UserNotifications
import WebKit

Expand Down Expand Up @@ -136,7 +137,7 @@ class BrowserWindowController: NSWindowController, NSWindowDelegate, WKUIDelegat

/// Exposes the WKWebView for zoom operations called from AppDelegate menu actions.
/// Return type is WKWebView (not the private HermesWebView subclass) so Swift's
/// access-level rules are satisfied — callers only need .magnification anyway.
/// access-level rules are satisfied — callers only need `.pageZoom` anyway.
var webViewForZoom: WKWebView? { webView }
private var separator: NSView!
private var statusDot: NSView!
Expand Down Expand Up @@ -202,6 +203,8 @@ class BrowserWindowController: NSWindowController, NSWindowDelegate, WKUIDelegat
/// which is what AppKit shows on the tab.
private var pageTitleObservation: NSKeyValueObservation?

private let zoomPreferences = ZoomPreferences()

/// - Parameter useFrameAutosave: When true (default), the window persists its
/// frame to UserDefaults under HermesMainWindow. Only the *first* window of a
/// multi-window session should set this true; secondary windows pass false so
Expand Down Expand Up @@ -584,7 +587,10 @@ class BrowserWindowController: NSWindowController, NSWindowDelegate, WKUIDelegat
webView.autoresizingMask = [.width, .height]
webView.uiDelegate = self
webView.navigationDelegate = self
webView.allowsMagnification = true
// Magnification scales a fixed layout and composes with pageZoom.
webView.allowsMagnification = false
// Apply the saved zoom before the first paint (fix #43).
webView.pageZoom = CGFloat(zoomPreferences.load().factor)

// Mirror document.title into window.title so the AppKit tab shows
// the active conversation name (truncated). KVO fires on every page
Expand Down Expand Up @@ -1147,11 +1153,10 @@ class BrowserWindowController: NSWindowController, NSWindowDelegate, WKUIDelegat
// Fix #57: refine traffic light clearance to exact measured value.
injectTrafficLightWidthVar()

// Restore persisted zoom level. double(forKey:) returns 0.0 when unset —
// treat any value outside the valid zoom range as "no preference".
let saved = UserDefaults.standard.double(forKey: AppDelegate.zoomKey)
if saved >= 0.5 && saved <= 3.0 {
webView.magnification = saved
// A recreated WebContent process starts at 100%; re-assert the saved zoom.
let persistedZoom = CGFloat(zoomPreferences.load().factor)
if webView.pageZoom != persistedZoom {
webView.pageZoom = persistedZoom
}

// Apply tabbed-mode titlebar class on first paint and SPA navigations —
Expand Down
86 changes: 86 additions & 0 deletions Sources/HermesAgentCore/ZoomLevel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import Foundation

/// A page zoom that reflows the layout, applied through `WKWebView.pageZoom`.
///
/// `WKWebView.magnification` scales an already-laid-out page inside a viewport
/// that keeps its pre-zoom size: zooming in pushes bottom-anchored UI out of the
/// window, zooming out leaves gutters on the right and bottom.
public struct ZoomLevel: Equatable {

public static let step: Double = 0.1
public static let minimumFactor: Double = Double(minimumTenths) / 10
public static let maximumFactor: Double = Double(maximumTenths) / 10
/// 100% — restored by ⌘0.
public static let identity = ZoomLevel(tenths: 10)

private static let minimumTenths = 5
private static let maximumTenths = 30

public let factor: Double

private init(tenths: Int) {
self.factor = Double(tenths) / 10
}

/// Clamps into range and snaps onto the step grid.
public init(clamping raw: Double) {
guard raw.isFinite else {
self = .identity
return
}
// Integer tenths: `factor + 0.1` accumulates binary float error.
let clamped = min(max(raw, Self.minimumFactor), Self.maximumFactor)
self.init(tenths: Int((clamped * 10).rounded()))
}

/// Rejects the 0 `UserDefaults` reports for a missing key, and out-of-range values.
public init?(restoring stored: Double) {
guard stored.isFinite,
stored >= Self.minimumFactor,
stored <= Self.maximumFactor
else { return nil }
self.init(clamping: stored)
}

public func increased() -> ZoomLevel {
ZoomLevel(clamping: factor + Self.step)
}

public func decreased() -> ZoomLevel {
ZoomLevel(clamping: factor - Self.step)
}

public var isMinimum: Bool { factor <= Self.minimumFactor }
public var isMaximum: Bool { factor >= Self.maximumFactor }
}

/// Persists the page zoom, migrating the magnification value of earlier releases.
public struct ZoomPreferences {

public static let currentKey = "webViewPageZoom"

/// Written by the magnification implementation (v1.1.0–v1.7.3); read only.
public static let legacyKey = "webViewMagnification"

private let defaults: UserDefaults

public init(defaults: UserDefaults = .standard) {
self.defaults = defaults
}

/// The persisted zoom, or 100% when nothing usable is stored.
public func load() -> ZoomLevel {
storedLevel(forKey: Self.currentKey)
?? storedLevel(forKey: Self.legacyKey)
?? .identity
}

public func save(_ level: ZoomLevel) {
defaults.set(level.factor, forKey: Self.currentKey)
}

private func storedLevel(forKey key: String) -> ZoomLevel? {
guard let number = defaults.object(forKey: key) as? NSNumber else { return nil }
return ZoomLevel(restoring: number.doubleValue)
}
}
Loading
Loading