An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
feat(mac): preflight screen and the seven-tab control panel in Ember and Daylight
Shahriar8db6231708a6
diff --git a/src/mac/Sources/Browsentic/App/AppModel.swift b/src/mac/Sources/Browsentic/App/AppModel.swiftnew file mode 100644index 0000000..2a6303e--- /dev/null+++ b/src/mac/Sources/Browsentic/App/AppModel.swift@@ -0,0 +1,437 @@+import AppKit+import SwiftUI++enum Phase { case preflight, main }++enum DaemonPhase: Equatable {+ case off, starting, on, stopping++ var label: String {+ switch self {+ case .off: "Off"+ case .starting: "Starting"+ case .on: "Running"+ case .stopping: "Stopping"+ }+ }+}++enum Tab: String, CaseIterable, Identifiable {+ case overview, browsers, agents, skills, activity, logs, settings++ var id: String { rawValue }+ var label: String { rawValue.capitalized }+ var icon: String {+ switch self {+ case .overview: "power"+ case .browsers: "globe"+ case .agents: "sparkles"+ case .skills: "book.closed"+ case .activity: "checkmark.shield"+ case .logs: "text.alignleft"+ case .settings: "gearshape"+ }+ }+}++struct Notice: Identifiable, Equatable {+ let id = UUID()+ let text: String+ let isError: Bool+}++@MainActor+final class AppModel: ObservableObject {+ @Published var phase: Phase = .preflight+ @Published var tab: Tab = .overview+ @Published var checks: [CheckID: CheckState] = Dictionary(uniqueKeysWithValues: CheckID.allCases.map { ($0, .waiting) })+ @Published var preflightBusy = true+ @Published var fixing = false++ @Published var daemon: DaemonPhase = .off+ @Published var lock: Lockfile?+ @Published var status: BridgeStatus?+ @Published var sessions: [BrowserSession] = []+ @Published var pairing: PairingCode?+ @Published var agents: AgentState?+ @Published var skills: SkillListing?+ @Published var grants: [Grant] = []+ @Published var downloads: DownloadListing?+ @Published var stamp: InstallStamp?+ @Published var browsers: [Browser] = []+ @Published var logText = ""+ @Published var commandDir: String?+ @Published var foreignCommand: String?+ @Published var latestRelease: String?+ @Published var busy: Set<String> = []+ @Published var notice: Notice?++ private(set) var node: NodeInstall?+ private let control = ControlClient()+ private var poller: Task<Void, Never>?++ var cli: CLI? { node.map(CLI.init) }+ var appVersion: String { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? Payload.bundledVersion ?? "dev" }+ var extensionNeedsReload: Bool {+ guard let stamp, let loaded = status?.extensionVersion, status?.connected == true else { return false }+ return loaded != stamp.version+ }++ // MARK: Preflight++ func runPreflight() async {+ preflightBusy = true+ for id in CheckID.allCases { checks[id] = .waiting }+ for id in CheckID.allCases {+ checks[id] = .checking+ async let settle: Void = Self.pause(0.42)+ let state = await evaluate(id)+ await settle+ withAnimation(.spring(duration: 0.45)) { checks[id] = state }+ }+ preflightBusy = false+ if CheckID.allCases.filter(\.blocksEntry).allSatisfy({ checks[$0]?.isPassed == true }),+ !CheckID.allCases.contains(where: { checks[$0]?.needsAttention == true }) {+ await Self.pause(0.9)+ enter()+ }+ }++ var canEnter: Bool { CheckID.allCases.filter(\.blocksEntry).allSatisfy { checks[$0]?.isPassed == true } }+ var needsSetup: Bool { CheckID.allCases.contains { $0.installsAutomatically && checks[$0]?.isPassed != true } }++ private func evaluate(_ id: CheckID) async -> CheckState {+ switch id {+ case .system:+ let os = ProcessInfo.processInfo.operatingSystemVersion+ let chip = NodeRuntime.architecture == "arm64" ? "Apple silicon" : "Intel"+ return .passed("macOS \(os.majorVersion).\(os.minorVersion) · \(chip)")+ case .node:+ node = await NodeRuntime.locate()+ guard let node else { return .missing("Version \(NodeRuntime.minimumMajor) or newer runs the daemon. A private copy goes in \(Paths.tilde(Paths.runtime)).") }+ return .passed("\(node.version) · \(node.isPrivate ? "private copy" : Paths.tilde(URL(fileURLWithPath: node.path)))")+ case .command:+ guard let bundled = Payload.bundledVersion else { return .failed(PayloadError.missing.localizedDescription) }+ if Payload.isCurrent { return .passed("v\(bundled) in \(Paths.tilde(Paths.cli))") }+ if let installed = Payload.installedVersion, installed != bundled {+ return .missing("v\(installed) is installed; this app carries v\(bundled).")+ }+ return .missing("Installs the CLI and daemon into \(Paths.tilde(Paths.cli)).")+ case .extensionFiles:+ stamp = ExtensionFiles.stamp()+ guard let bundled = Payload.bundledVersion else { return .failed(PayloadError.missing.localizedDescription) }+ guard let stamp else { return .missing("Unpacks to \(Paths.tilde(Paths.extensionDir())), where the browser loads it from.") }+ if stamp.version != bundled { return .missing("v\(stamp.version) is unpacked; this app carries v\(bundled).") }+ return .passed("v\(stamp.version) in \(Paths.tilde(Paths.extensionDir()))")+ case .browser:+ browsers = Browser.installed()+ return browsers.isEmpty+ ? .advisory("None found. Chrome, Brave, Edge, Arc, Vivaldi or Opera all work.")+ : .passed(browsers.map(\.name).joined(separator: ", "))+ case .agent:+ let found = AgentProbe.installed()+ return found.isEmpty+ ? .advisory("None on your PATH. The side panel needs Claude Code, Codex or Antigravity.")+ : .passed(found.joined(separator: ", "))+ }+ }++ func setUpEverything() async {+ fixing = true+ defer { fixing = false }+ for id in CheckID.allCases where id.installsAutomatically && checks[id]?.isPassed != true {+ guard await fix(id) else { return }+ }+ if canEnter {+ await Self.pause(0.7)+ enter()+ }+ }++ @discardableResult+ func fix(_ id: CheckID) async -> Bool {+ do {+ switch id {+ case .node:+ checks[id] = .working(0, "Starting")+ node = try await NodeRuntime.installPrivate { fraction, label in+ Task { @MainActor [weak self] in self?.checks[.node] = .working(fraction, label) }+ }+ case .command:+ guard let node else { throw CLIError.failed("Node.js has to be installed first.") }+ checks[id] = .working(nil, "Copying the CLI into \(Paths.tilde(Paths.cli))")+ let wasRunning = FileManager.default.fileExists(atPath: Paths.lockfile.path)+ try await Task.detached { try Payload.install(node: node) }.value+ if wasRunning {+ checks[id] = .working(nil, "Restarting the daemon on the new build")+ try await CLI(node: node).restart()+ }+ case .extensionFiles:+ guard let cli else { throw CLIError.failed("Node.js has to be installed first.") }+ checks[id] = .working(nil, "Unpacking the extension")+ _ = try await cli.installExtension()+ case .agent:+ guard let node else { throw CLIError.failed("Node.js has to be installed first.") }+ checks[id] = .working(nil, "npm i -g @anthropic-ai/claude-code")+ let result = await Shell.run(node.npm, ["install", "-g", "@anthropic-ai/claude-code"], extraPath: [node.binDir], timeout: 600)+ guard result.ok else { throw CLIError.failed(String(result.failure.suffix(400))) }+ case .browser:+ NSWorkspace.shared.open(URL(string: "https://www.google.com/chrome/")!)+ return true+ case .system:+ return true+ }+ let state = await evaluate(id)+ withAnimation(.spring(duration: 0.45)) { checks[id] = state }+ return state.isPassed+ } catch {+ withAnimation { checks[id] = .failed(error.localizedDescription) }+ return false+ }+ }++ func enter() {+ withAnimation(.easeInOut(duration: 0.6)) { phase = .main }+ startPolling()+ Task {+ refreshCommandLink()+ if UserDefaults.standard.object(forKey: "startDaemonOnLaunch") as? Bool ?? true, daemon == .off { await setDaemon(on: true) }+ await checkForUpdate()+ }+ }++ // MARK: Daemon++ func startPolling() {+ poller?.cancel()+ poller = Task { [weak self] in+ while !Task.isCancelled {+ await self?.refresh()+ try? await Task.sleep(nanoseconds: 2_000_000_000)+ }+ }+ }++ func refresh() async {+ guard let lock = Self.readLock() else { return markOff() }+ await control.connect(lock)+ do {+ let status = try await control.status()+ let sessions = try await control.sessions()+ self.lock = lock+ self.status = status+ self.sessions = sessions+ if daemon != .stopping { daemon = .on }+ if pairing != nil, !status.pairingPending || (pairing?.expiry ?? .distantPast) < Date() { pairing = nil }+ if agents == nil { await loadAgents() }+ stamp = ExtensionFiles.stamp()+ } catch {+ await control.close()+ markOff()+ }+ }++ private func markOff() {+ guard daemon != .starting else { return }+ daemon = .off+ lock = nil+ status = nil+ sessions = []+ pairing = nil+ }++ private static func readLock() -> Lockfile? {+ (try? Data(contentsOf: Paths.lockfile)).flatMap { try? JSONDecoder().decode(Lockfile.self, from: $0) }+ }++ func setDaemon(on: Bool) async {+ guard let cli, daemon == (on ? .off : .on) else { return }+ daemon = on ? .starting : .stopping+ do {+ if on { try await cli.start() } else {+ await control.close()+ try await cli.stop()+ }+ } catch { report(error) }+ daemon = on ? .starting : .off+ if !on { markOff() }+ await refresh()+ if on, daemon == .starting { daemon = .off }+ }++ func restartDaemon() async {+ await perform("restart") { cli, _ in+ self.daemon = .starting+ await self.control.close()+ try await cli.restart()+ self.agents = nil+ }+ await refresh()+ if daemon == .starting { daemon = .off }+ }++ // MARK: Operations++ func newPairingCode() async {+ await perform("pair") { _, control in self.pairing = try await control.pair() }+ }++ func revoke(_ origin: String?) async {+ await perform("revoke") { _, control in+ let count = try await control.revoke(origin: origin)+ self.say(count == 0 ? "Nothing to unpair." : "Unpaired \(count) browser\(count == 1 ? "" : "s").")+ }+ await refresh()+ }++ func loadAgents() async {+ guard let cli else { return }+ if let state = try? await cli.agents() { agents = state }+ }++ func selectAgent(_ kind: String) async {+ await perform("agent:\(kind)") { _, control in+ let state = try await control.agent(set: kind)+ self.agents = AgentState(active: state.active, runners: state.runners, catalog: self.agents?.catalog)+ }+ }++ func repairAgent(_ kind: String) async {+ await perform("agent:\(kind)") { _, control in+ let state = try await control.agent(grant: kind)+ self.agents = AgentState(active: state.active, runners: state.runners, catalog: self.agents?.catalog)+ }+ }++ func setModel(_ model: String?, for kind: String) async {+ await perform("agent:\(kind)") { cli, _ in+ try await cli.setModel(model, for: kind)+ self.agents = try await cli.agents()+ }+ }++ func installAgent(_ descriptor: AgentDescriptor) async {+ guard descriptor.installsWithNpm, let node else {+ if let url = URL(string: descriptor.install) { NSWorkspace.shared.open(url) }+ return+ }+ await perform("agent:\(descriptor.kind)") { cli, _ in+ let package = descriptor.install.split(separator: " ").last.map(String.init) ?? ""+ let result = await Shell.run(node.npm, ["install", "-g", package], extraPath: [node.binDir], timeout: 600)+ guard result.ok else { throw CLIError.failed(String(result.failure.suffix(400))) }+ self.agents = try await cli.agents()+ self.say("\(descriptor.label) is installed. Run “\(descriptor.bin)” in a terminal once to sign in.")+ }+ }++ func loadSkills() async {+ await perform("skills", quiet: true) { cli, _ in self.skills = try await cli.skills() }+ }++ func loadActivity() async {+ await perform("activity", quiet: true) { cli, _ in+ self.grants = try await cli.approvals()+ self.downloads = try await cli.downloads()+ }+ }++ func clearApprovals(host: String?) async {+ await perform("approvals") { cli, _ in+ try await cli.clearApprovals(host: host)+ self.grants = try await cli.approvals()+ }+ }++ func clearDownloads() async {+ await perform("downloads") { cli, _ in+ try await cli.clearDownloads()+ self.downloads = try await cli.downloads()+ }+ }++ func reinstallExtension() async {+ await perform("extension") { cli, _ in+ let result = try await cli.installExtension(force: true)+ self.stamp = ExtensionFiles.stamp()+ self.say("Extension v\(result.version) written. Press ↻ on its card at chrome://extensions.")+ }+ }++ func openExtensionsPage(in browser: Browser) {+ NSPasteboard.general.clearContents()+ NSPasteboard.general.setString(Paths.extensionDir().path, forType: .string)+ browser.openExtensionsPage()+ say("The extension path is on your clipboard — in the folder picker press ⇧⌘G and paste it.")+ }++ func loadLog() {+ guard let handle = try? FileHandle(forReadingFrom: Paths.log) else { return logText = "" }+ defer { try? handle.close() }+ let size = (try? handle.seekToEnd()) ?? 0+ try? handle.seek(toOffset: size > 96_000 ? size - 96_000 : 0)+ let text = String(decoding: (try? handle.readToEnd()) ?? Data(), as: UTF8.self)+ let trimmed = size > 96_000 ? String(text.drop { !$0.isNewline }.dropFirst()) : text+ if trimmed != logText { logText = trimmed }+ }++ func refreshCommandLink() {+ commandDir = CommandLink.linkedIn+ foreignCommand = CommandLink.foreign+ }++ func setCommandLink(_ on: Bool) {+ do {+ if on { say("“browsentic” now runs from any terminal — linked in \(Paths.tilde(URL(fileURLWithPath: try CommandLink.link()))).") }+ else { CommandLink.unlink() }+ } catch { report(error) }+ refreshCommandLink()+ }++ func uninstall(keepSkills: Bool) async {+ await perform("uninstall") { cli, control in+ await control.close()+ CommandLink.unlink()+ _ = try await cli.uninstall(keepSkills: keepSkills)+ self.poller?.cancel()+ self.markOff()+ self.phase = .preflight+ }+ await runPreflight()+ }++ func checkForUpdate() async {+ struct Release: Decodable { let tag_name: String }+ var request = URLRequest(url: URL(string: "https://api.github.com/repos/imshaikot/browsentic/releases/latest")!)+ request.timeoutInterval = 6+ guard+ let (data, _) = try? await URLSession.shared.data(for: request),+ let release = try? JSONDecoder().decode(Release.self, from: data)+ else { return }+ let latest = release.tag_name.trimmingCharacters(in: CharacterSet(charactersIn: "v"))+ latestRelease = Version.isNewer(latest, than: appVersion) ? latest : nil+ }++ // MARK: Plumbing++ private func perform(_ key: String, quiet: Bool = false, _ work: @escaping (CLI, ControlClient) async throws -> Void) async {+ guard let cli, !busy.contains(key) else { return }+ busy.insert(key)+ defer { busy.remove(key) }+ do { try await work(cli, control) } catch { if !quiet { report(error) } }+ }++ func say(_ text: String) { show(Notice(text: text, isError: false)) }+ func report(_ error: Error) { show(Notice(text: error.localizedDescription, isError: true)) }++ private func show(_ notice: Notice) {+ withAnimation(.spring(duration: 0.4)) { self.notice = notice }+ Task {+ try? await Task.sleep(nanoseconds: notice.isError ? 7_000_000_000 : 4_500_000_000)+ if self.notice == notice { withAnimation { self.notice = nil } }+ }+ }++ private static func pause(_ seconds: Double) async {+ try? await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))+ }+}diff --git a/src/mac/Sources/Browsentic/App/BrowsenticApp.swift b/src/mac/Sources/Browsentic/App/BrowsenticApp.swiftnew file mode 100644index 0000000..a6c59d1--- /dev/null+++ b/src/mac/Sources/Browsentic/App/BrowsenticApp.swift@@ -0,0 +1,105 @@+import AppKit+import SwiftUI++@main+struct BrowsenticApp: App {+ @NSApplicationDelegateAdaptor(AppDelegate.self) private var delegate+ @StateObject private var model = AppModel()+ @AppStorage("appearance") private var appearance = Appearance.system.rawValue++ private var scheme: ColorScheme? { Appearance(rawValue: appearance)?.scheme }++ var body: some Scene {+ Window("Browsentic", id: "main") {+ RootView()+ .environmentObject(model)+ .preferredColorScheme(scheme)+ .frame(minWidth: 940, minHeight: 680)+ .task { await model.runPreflight() }+ }+ .windowStyle(.hiddenTitleBar)+ .defaultSize(width: 1040, height: 760)+ .commands {+ CommandGroup(replacing: .newItem) {}+ CommandMenu("View") {+ ForEach(Array(Tab.allCases.enumerated()), id: \.element) { index, tab in+ Button(tab.label) { model.tab = tab }+ .keyboardShortcut(KeyEquivalent(Character("\(index + 1)")), modifiers: .command)+ .disabled(model.phase != .main)+ }+ }+ CommandMenu("Daemon") {+ Button(model.daemon == .on ? "Turn Off" : "Turn On") { Task { await model.setDaemon(on: model.daemon == .off) } }+ .keyboardShortcut("d", modifiers: [.command, .shift])+ .disabled(model.phase != .main || (model.daemon != .on && model.daemon != .off))+ Button("Restart") { Task { await model.restartDaemon() } }+ .keyboardShortcut("r", modifiers: [.command, .shift])+ .disabled(model.daemon != .on)+ Divider()+ Button("New Pairing Code") {+ model.tab = .browsers+ Task { await model.newPairingCode() }+ }+ .keyboardShortcut("p", modifiers: [.command, .shift])+ .disabled(model.daemon != .on)+ }+ }++ MenuBarExtra {+ MenuBarContent().environmentObject(model)+ } label: {+ Image(systemName: model.daemon == .on ? "circle.hexagongrid.fill" : "circle.hexagongrid")+ }+ }+}++final class AppDelegate: NSObject, NSApplicationDelegate {+ func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool { false }++ func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows visible: Bool) -> Bool {+ if !visible { NSApp.windows.first { $0.canBecomeMain }?.makeKeyAndOrderFront(nil) }+ return true+ }+}++private struct RootView: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ ZStack(alignment: .bottom) {+ switch model.phase {+ case .preflight: PreflightView().transition(.opacity.combined(with: .scale(scale: 1.03)))+ case .main: MainView().transition(.opacity.combined(with: .scale(scale: 0.98)))+ }+ if let notice = model.notice {+ NoticeBanner(notice: notice)+ .padding(.bottom, 22)+ .transition(.move(edge: .bottom).combined(with: .opacity))+ }+ }+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .background { Backdrop() }+ }+}++private struct MenuBarContent: View {+ @EnvironmentObject private var model: AppModel+ @Environment(\.openWindow) private var openWindow++ var body: some View {+ Text("Daemon: \(model.daemon.label)\(model.status.map { " · 127.0.0.1:\($0.port)" } ?? "")")+ if let status = model.status {+ Text(status.connected ? "Extension connected" : "Extension not connected")+ }+ Divider()+ Button(model.daemon == .on ? "Turn Off" : "Turn On") { Task { await model.setDaemon(on: model.daemon == .off) } }+ .disabled(model.phase != .main || (model.daemon != .on && model.daemon != .off))+ Button("Restart") { Task { await model.restartDaemon() } }.disabled(model.daemon != .on)+ Divider()+ Button("Open Browsentic") {+ openWindow(id: "main")+ NSApp.activate(ignoringOtherApps: true)+ }+ Button("Quit") { NSApp.terminate(nil) }.keyboardShortcut("q")+ }+}diff --git a/src/mac/Sources/Browsentic/Theme/Components.swift b/src/mac/Sources/Browsentic/Theme/Components.swiftnew file mode 100644index 0000000..7a4ac38--- /dev/null+++ b/src/mac/Sources/Browsentic/Theme/Components.swift@@ -0,0 +1,240 @@+import SwiftUI++struct Card<Content: View>: View {+ var padding: CGFloat = 20+ @ViewBuilder var content: Content++ var body: some View {+ content+ .padding(padding)+ .frame(maxWidth: .infinity, alignment: .leading)+ .background(Palette.surface.opacity(0.72), in: RoundedRectangle(cornerRadius: 16, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 16, style: .continuous).strokeBorder(Palette.line))+ }+}++struct SectionTitle: View {+ let title: String+ var subtitle: String?++ var body: some View {+ VStack(alignment: .leading, spacing: 4) {+ Text(title).font(.display(15)).foregroundStyle(Palette.ink)+ if let subtitle {+ Text(subtitle).font(.system(size: 12)).foregroundStyle(Palette.inkDim).fixedSize(horizontal: false, vertical: true)+ }+ }+ }+}++struct Pill: View {+ let text: String+ var tint: Color = Palette.inkDim+ var icon: String?++ var body: some View {+ HStack(spacing: 5) {+ if let icon { Image(systemName: icon).font(.system(size: 9, weight: .bold)) }+ Text(text).font(.system(size: 11, weight: .medium))+ }+ .foregroundStyle(tint)+ .padding(.horizontal, 9)+ .padding(.vertical, 4)+ .background(tint.opacity(0.13), in: Capsule())+ }+}++struct GlowDot: View {+ let color: Color+ var pulsing = false+ @Environment(\.colorScheme) private var scheme+ @State private var breathe = false++ var body: some View {+ Circle()+ .fill(color)+ .frame(width: 8, height: 8)+ .shadow(color: color.opacity(0.9 * Palette.glow(scheme)), radius: breathe ? 7 : 3)+ .onAppear {+ guard pulsing else { return }+ withAnimation(.easeInOut(duration: 1.4).repeatForever(autoreverses: true)) { breathe = true }+ }+ }+}++struct PrimaryButtonStyle: ButtonStyle {+ var tint: Color = Palette.brand+ @Environment(\.isEnabled) private var enabled+ @Environment(\.colorScheme) private var scheme++ func makeBody(configuration: Configuration) -> some View {+ configuration.label+ .font(.system(size: 13, weight: .semibold))+ .foregroundStyle(Palette.onBrand)+ .padding(.horizontal, 16)+ .padding(.vertical, 9)+ .background(tint.opacity(enabled ? 1 : 0.4), in: Capsule())+ .shadow(color: tint.opacity(0.45 * Palette.glow(scheme)), radius: configuration.isPressed ? 4 : 12, y: 2)+ .scaleEffect(configuration.isPressed ? 0.97 : 1)+ .animation(.spring(duration: 0.25), value: configuration.isPressed)+ }+}++struct QuietButtonStyle: ButtonStyle {+ var tint: Color = Palette.ink+ @Environment(\.isEnabled) private var enabled++ func makeBody(configuration: Configuration) -> some View {+ configuration.label+ .font(.system(size: 12, weight: .medium))+ .foregroundStyle(tint.opacity(enabled ? 1 : 0.4))+ .padding(.horizontal, 12)+ .padding(.vertical, 7)+ .background(Palette.surface2.opacity(configuration.isPressed ? 1 : 0.7), in: Capsule())+ .overlay(Capsule().strokeBorder(Palette.line))+ .scaleEffect(configuration.isPressed ? 0.97 : 1)+ .animation(.spring(duration: 0.25), value: configuration.isPressed)+ }+}++struct CopyButton: View {+ let value: String+ var label = "Copy"+ @State private var copied = false++ var body: some View {+ Button {+ NSPasteboard.general.clearContents()+ NSPasteboard.general.setString(value, forType: .string)+ copied = true+ Task {+ try? await Task.sleep(nanoseconds: 1_400_000_000)+ copied = false+ }+ } label: {+ Label(copied ? "Copied" : label, systemImage: copied ? "checkmark" : "doc.on.doc")+ }+ .buttonStyle(QuietButtonStyle(tint: copied ? Palette.lime : Palette.ink))+ }+}++struct PathRow: View {+ let url: URL++ var body: some View {+ HStack(spacing: 8) {+ Text(Paths.tilde(url))+ .font(.code(12))+ .foregroundStyle(Palette.ink)+ .lineLimit(1)+ .truncationMode(.middle)+ .textSelection(.enabled)+ Spacer(minLength: 8)+ CopyButton(value: url.path)+ Button {+ NSWorkspace.shared.activateFileViewerSelecting([url])+ } label: { Label("Reveal", systemImage: "folder") }+ .buttonStyle(QuietButtonStyle())+ }+ .padding(.leading, 12)+ .padding(.trailing, 6)+ .padding(.vertical, 6)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 10, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 10, style: .continuous).strokeBorder(Palette.line))+ }+}++struct EmptyState: View {+ let icon: String+ let title: String+ let detail: String++ var body: some View {+ VStack(spacing: 10) {+ Image(systemName: icon).font(.system(size: 30, weight: .light)).foregroundStyle(Palette.inkFaint)+ Text(title).font(.display(15)).foregroundStyle(Palette.ink)+ Text(detail)+ .font(.system(size: 12))+ .foregroundStyle(Palette.inkDim)+ .multilineTextAlignment(.center)+ .frame(maxWidth: 380)+ }+ .frame(maxWidth: .infinity)+ .padding(.vertical, 44)+ }+}++/// The ground every screen sits on: the ember black, a dot grid, and two slow washes of colour.+struct Backdrop: View {+ @Environment(\.colorScheme) private var scheme+ @State private var drift = false++ var body: some View {+ ZStack {+ Palette.ground+ Canvas { context, size in+ let step: CGFloat = 22+ var dots = Path()+ for x in stride(from: step / 2, to: size.width, by: step) {+ for y in stride(from: step / 2, to: size.height, by: step) {+ dots.addEllipse(in: CGRect(x: x, y: y, width: 1.2, height: 1.2))+ }+ }+ context.fill(dots, with: .color(Palette.ink.opacity(0.07)))+ }+ .mask(RadialGradient(colors: [.black, .clear], center: .top, startRadius: 40, endRadius: 760))++ wash(Palette.brand, strength: scheme == .dark ? 0.20 : 0.12)+ .frame(width: 900, height: 900)+ .offset(x: drift ? -260 : -340, y: drift ? -300 : -240)+ wash(Palette.ember, strength: scheme == .dark ? 0.16 : 0.09)+ .frame(width: 860, height: 860)+ .offset(x: drift ? 380 : 300, y: drift ? 260 : 330)+ }+ .ignoresSafeArea()+ .onAppear {+ withAnimation(.easeInOut(duration: 11).repeatForever(autoreverses: true)) { drift = true }+ }+ }+}++private func wash(_ color: Color, strength: Double) -> some View {+ Circle().fill(RadialGradient(colors: [color.opacity(strength), color.opacity(0)], center: .center, startRadius: 0, endRadius: 440))+}++/// The mark from the extension icon: a browser frame holding three linked nodes.+struct BrandMark: View {+ var lineWidth: CGFloat = 1.75++ var body: some View {+ Canvas { context, size in+ let unit = min(size.width, size.height) / 32+ let at: (CGFloat, CGFloat) -> CGPoint = { CGPoint(x: $0 * unit, y: $1 * unit) }+ let brand = GraphicsContext.Shading.color(Palette.brand)++ let frame = Path(roundedRect: CGRect(x: 2.25 * unit, y: 4.25 * unit, width: 27.5 * unit, height: 23.5 * unit), cornerRadius: 6 * unit)+ context.stroke(frame, with: .color(Palette.brand.opacity(0.55)), lineWidth: 1.5 * unit)++ var bar = Path()+ bar.move(to: at(2.5, 10.5))+ bar.addLine(to: at(29.5, 10.5))+ context.stroke(bar, with: .color(Palette.brand.opacity(0.35)), lineWidth: 1.25 * unit)+ for (x, alpha) in [(6.4, 0.5), (9.8, 0.35)] {+ context.fill(Path(ellipseIn: CGRect(x: (x - 1) * unit, y: 6.4 * unit, width: 2 * unit, height: 2 * unit)), with: .color(Palette.brand.opacity(alpha)))+ }++ var curve = Path()+ curve.move(to: at(9, 22.2))+ curve.addCurve(to: at(15.9, 15.8), control1: at(11.4, 22.2), control2: at(11.4, 15.8))+ curve.addCurve(to: at(22.9, 22.2), control1: at(20.4, 15.8), control2: at(20.5, 22.2))+ context.stroke(curve, with: brand, style: StrokeStyle(lineWidth: lineWidth * unit, lineCap: .round))++ for (x, y, r, filled) in [(9.0, 22.2, 2.35, false), (15.9, 15.8, 2.55, true), (22.9, 22.2, 2.35, false)] {+ let node = Path(ellipseIn: CGRect(x: (x - r) * unit, y: (y - r) * unit, width: 2 * r * unit, height: 2 * r * unit))+ context.fill(node, with: filled ? brand : .color(Palette.ground))+ context.stroke(node, with: brand, lineWidth: 1.6 * unit)+ }+ }+ .aspectRatio(1, contentMode: .fit)+ }+}diff --git a/src/mac/Sources/Browsentic/Theme/Theme.swift b/src/mac/Sources/Browsentic/Theme/Theme.swiftnew file mode 100644index 0000000..af4fa18--- /dev/null+++ b/src/mac/Sources/Browsentic/Theme/Theme.swift@@ -0,0 +1,61 @@+import AppKit+import SwiftUI++/// Ember and Daylight from the extension's globals.css, converted from oklch once. The extension+/// owns the palette; a change there is re-derived here rather than tuned by eye.+enum Palette {+ static let ground = dynamic(dark: 0x110A06, light: 0xFCFBF8)+ static let ground2 = dynamic(dark: 0x19100B, light: 0xF6F4F0)+ static let surface = dynamic(dark: 0x201611, light: 0xF0ECE7)+ static let surface2 = dynamic(dark: 0x2B1F1A, light: 0xE2DDD6)+ static let ink = dynamic(dark: 0xF7F0E9, light: 0x2C231D)+ static let inkDim = dynamic(dark: 0xB2A79E, light: 0x60544C)+ static let inkFaint = dynamic(dark: 0x83766E, light: 0x7D7068)+ static let line = dynamic(dark: 0xFEF7F2, light: 0x362B24, darkAlpha: 0.10, lightAlpha: 0.13)+ static let lineStrong = dynamic(dark: 0xFEF7F2, light: 0x362B24, darkAlpha: 0.18, lightAlpha: 0.24)+ static let brand = dynamic(dark: 0x3BE1E1, light: 0x007791)+ static let brandDeep = dynamic(dark: 0x009BA3, light: 0x005A74)+ static let ember = dynamic(dark: 0xFE804C, light: 0xC04307)+ static let magenta = dynamic(dark: 0xE961D1, light: 0xAC2B98)+ static let lime = dynamic(dark: 0x63EA89, light: 0x187E36)+ static let amber = dynamic(dark: 0xF7C243, light: 0xA66300)+ static let danger = dynamic(dark: 0xF14949, light: 0xC92228)+ static let onBrand = dynamic(dark: 0x06201F, light: 0xFFFFFF)++ /// How strongly glows read. Daylight zeroes them, as it does in the extension: neon only exists on black.+ static func glow(_ scheme: ColorScheme) -> Double { scheme == .dark ? 1 : 0 }++ private static func dynamic(dark: UInt32, light: UInt32, darkAlpha: CGFloat = 1, lightAlpha: CGFloat = 1) -> Color {+ Color(nsColor: NSColor(name: nil) { appearance in+ let isDark = appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua+ let hex = isDark ? dark : light+ return NSColor(+ srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255,+ blue: CGFloat(hex & 0xFF) / 255, alpha: isDark ? darkAlpha : lightAlpha+ )+ })+ }+}++enum Appearance: String, CaseIterable, Identifiable {+ case system, light, dark++ var id: String { rawValue }+ var label: String { rawValue.capitalized }+ var scheme: ColorScheme? {+ switch self {+ case .system: nil+ case .light: .light+ case .dark: .dark+ }+ }+}++extension Font {+ static func display(_ size: CGFloat, weight: Font.Weight = .semibold) -> Font {+ .system(size: size, weight: weight, design: .rounded)+ }+ static func code(_ size: CGFloat, weight: Font.Weight = .regular) -> Font {+ .system(size: size, weight: weight, design: .monospaced)+ }+}diff --git a/src/mac/Sources/Browsentic/Views/ActivityView.swift b/src/mac/Sources/Browsentic/Views/ActivityView.swiftnew file mode 100644index 0000000..efc7c26--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/ActivityView.swift@@ -0,0 +1,98 @@+import SwiftUI++struct ActivityView: View {+ @EnvironmentObject private var model: AppModel+ @State private var confirmingApprovals = false+ @State private var confirmingDownloads = false++ var body: some View {+ VStack(spacing: 18) {+ Card {+ VStack(alignment: .leading, spacing: 12) {+ HStack {+ SectionTitle(+ title: "Standing approvals",+ subtitle: "Every “always on this site” you have granted. These actions no longer ask on these sites."+ )+ Spacer()+ if !model.grants.isEmpty {+ Button("Forget all") { confirmingApprovals = true }.buttonStyle(QuietButtonStyle(tint: Palette.danger))+ }+ }+ if model.grants.isEmpty {+ EmptyState(icon: "checkmark.shield", title: "Nothing is pre-approved", detail: "Every gated action still asks before it runs.")+ } else {+ ForEach(Dictionary(grouping: model.grants, by: \.host).sorted { $0.key < $1.key }, id: \.key) { host, grants in+ HStack(alignment: .top, spacing: 12) {+ VStack(alignment: .leading, spacing: 6) {+ Text(host).font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)+ FlowingPills(items: grants.map { "\($0.action.replacingOccurrences(of: "page.", with: "")) · \(Timestamp.ago($0.at))" })+ }+ Spacer()+ Button("Forget") { Task { await model.clearApprovals(host: host) } }+ .buttonStyle(QuietButtonStyle())+ .disabled(model.busy.contains("approvals"))+ }+ .padding(12)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 12, style: .continuous))+ }+ }+ }+ }++ Card {+ VStack(alignment: .leading, spacing: 12) {+ HStack {+ SectionTitle(title: "Captured downloads", subtitle: "Files an agent pulled off a page. The daemon sweeps them after two weeks.")+ Spacer()+ if let downloads = model.downloads, !downloads.downloads.isEmpty {+ Button("Delete all") { confirmingDownloads = true }.buttonStyle(QuietButtonStyle(tint: Palette.danger))+ }+ }+ if let dir = model.downloads?.dir { PathRow(url: URL(fileURLWithPath: dir)) }+ if let downloads = model.downloads?.downloads, !downloads.isEmpty {+ ForEach(downloads) { download in+ HStack(spacing: 12) {+ Image(systemName: "doc").foregroundStyle(Palette.brand)+ VStack(alignment: .leading, spacing: 2) {+ Text(download.name).font(.system(size: 12.5, weight: .medium)).foregroundStyle(Palette.ink).lineLimit(1)+ Text("\(download.notes) · \(Timestamp.ago(download.capturedAt))").font(.system(size: 11.5)).foregroundStyle(Palette.inkDim).lineLimit(1)+ }+ Spacer()+ Button { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: download.savedTo)]) } label: {+ Label("Reveal", systemImage: "folder")+ }+ .buttonStyle(QuietButtonStyle())+ }+ .padding(12)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 12, style: .continuous))+ }+ } else {+ EmptyState(icon: "arrow.down.doc", title: "Nothing captured", detail: "Files land here when an agent uses page.captureDownload.")+ }+ }+ }+ }+ .task { await model.loadActivity() }+ .confirmationDialog("Forget every standing approval?", isPresented: $confirmingApprovals) {+ Button("Forget all", role: .destructive) { Task { await model.clearApprovals(host: nil) } }+ } message: { Text("Gated actions will ask again on every site.") }+ .confirmationDialog("Delete every captured download?", isPresented: $confirmingDownloads) {+ Button("Delete all", role: .destructive) { Task { await model.clearDownloads() } }+ } message: { Text("The files are removed from disk.") }+ }+}++private struct FlowingPills: View {+ let items: [String]++ var body: some View {+ VStack(alignment: .leading, spacing: 5) {+ ForEach(Array(stride(from: 0, to: items.count, by: 3)), id: \.self) { start in+ HStack(spacing: 5) {+ ForEach(items[start..<min(start + 3, items.count)], id: \.self) { Pill(text: $0) }+ }+ }+ }+ }+}diff --git a/src/mac/Sources/Browsentic/Views/AgentsView.swift b/src/mac/Sources/Browsentic/Views/AgentsView.swiftnew file mode 100644index 0000000..770bf6a--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/AgentsView.swift@@ -0,0 +1,114 @@+import SwiftUI++struct AgentsView: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ VStack(spacing: 18) {+ if model.daemon != .on {+ OfflineHint(what: "Agent readiness checks")+ } else if let agents = model.agents {+ Card {+ SectionTitle(+ title: "Which agent runs the side panel",+ subtitle: "Browsentic ships no model and needs no API key. It drives the agent CLI you are already signed in to."+ )+ }+ ForEach(agents.runners) { runner in+ AgentCard(+ runner: runner, descriptor: agents.catalog?.first { $0.kind == runner.kind },+ active: agents.active == runner.kind+ )+ }+ } else {+ ProgressView().padding(60)+ }+ }+ .task(id: model.daemon) { if model.daemon == .on { await model.loadAgents() } }+ }+}++private struct AgentCard: View {+ @EnvironmentObject private var model: AppModel+ let runner: RunnerStatus+ let descriptor: AgentDescriptor?+ let active: Bool++ private var working: Bool { model.busy.contains("agent:\(runner.kind)") }++ var body: some View {+ Card {+ VStack(alignment: .leading, spacing: 12) {+ HStack(spacing: 12) {+ Image(systemName: active ? "largecircle.fill.circle" : "circle")+ .font(.system(size: 18))+ .foregroundStyle(active ? Palette.brand : Palette.inkFaint)+ VStack(alignment: .leading, spacing: 2) {+ HStack(spacing: 8) {+ Text(descriptor?.label ?? runner.kind.capitalized).font(.display(16)).foregroundStyle(Palette.ink)+ if let vendor = descriptor?.vendor { Text(vendor).font(.system(size: 11.5)).foregroundStyle(Palette.inkFaint) }+ }+ Text(runner.ready ? (runner.version ?? "Ready") : "Unavailable")+ .font(.code(11.5))+ .foregroundStyle(runner.ready ? Palette.inkDim : Palette.amber)+ }+ Spacer()+ if working { ProgressView().controlSize(.small) }+ if active { Pill(text: "In use", tint: Palette.brand, icon: "checkmark") }+ else if runner.ready {+ Button("Use this agent") { Task { await model.selectAgent(runner.kind) } }+ .buttonStyle(QuietButtonStyle())+ .disabled(working)+ }+ }++ if let problem = runner.problem {+ VStack(alignment: .leading, spacing: 8) {+ Text(problem.message).font(.system(size: 12.5)).foregroundStyle(Palette.inkDim).fixedSize(horizontal: false, vertical: true)+ if let fix = problem.fix {+ Text(fix).font(.code(11.5)).foregroundStyle(Palette.ink).textSelection(.enabled)+ .padding(.horizontal, 10).padding(.vertical, 6)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 8, style: .continuous))+ }+ HStack(spacing: 8) {+ if problem.code == "AGENT_MISSING", let descriptor {+ Button { Task { await model.installAgent(descriptor) } } label: {+ Label(descriptor.installsWithNpm ? "Install \(descriptor.label)" : "Open the install guide", systemImage: "arrow.down.circle")+ }+ .buttonStyle(PrimaryButtonStyle())+ .disabled(working)+ }+ if problem.grantable == true {+ Button { Task { await model.repairAgent(runner.kind) } } label: { Label("Fix it for me", systemImage: "wand.and.stars") }+ .buttonStyle(PrimaryButtonStyle())+ .disabled(working)+ }+ if let docs = descriptor.flatMap({ URL(string: $0.docs) }) {+ Button("Docs") { NSWorkspace.shared.open(docs) }.buttonStyle(QuietButtonStyle())+ }+ }+ }+ .padding(.leading, 30)+ } else if let descriptor {+ HStack(spacing: 10) {+ Text("Model").font(.system(size: 12)).foregroundStyle(Palette.inkDim)+ Picker("Model", selection: Binding(+ get: { runner.model ?? "" },+ set: { picked in Task { await model.setModel(picked.isEmpty ? nil : picked, for: runner.kind) } }+ )) {+ Text("The CLI’s own default").tag("")+ ForEach(Array(Set(descriptor.models + [runner.model].compactMap { $0 })).sorted { a, b in+ (descriptor.models.firstIndex(of: a) ?? .max) < (descriptor.models.firstIndex(of: b) ?? .max)+ }, id: \.self) { Text($0).tag($0) }+ }+ .labelsHidden()+ .frame(width: 240)+ .disabled(working)+ }+ .padding(.leading, 30)+ }+ }+ }+ .overlay(RoundedRectangle(cornerRadius: 16, style: .continuous).strokeBorder(active ? Palette.brand.opacity(0.5) : .clear))+ }+}diff --git a/src/mac/Sources/Browsentic/Views/BrowsersView.swift b/src/mac/Sources/Browsentic/Views/BrowsersView.swiftnew file mode 100644index 0000000..e359f95--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/BrowsersView.swift@@ -0,0 +1,59 @@+import SwiftUI++struct BrowsersView: View {+ @EnvironmentObject private var model: AppModel+ @State private var confirmingAll = false++ var body: some View {+ VStack(spacing: 18) {+ if model.daemon != .on {+ OfflineHint(what: "Paired browsers")+ } else {+ ConnectCard()+ Card {+ VStack(alignment: .leading, spacing: 14) {+ HStack {+ SectionTitle(title: "Paired browsers", subtitle: "Each one holds a key of its own. Unpairing drops the key and disconnects it at once.")+ Spacer()+ if model.sessions.count > 1 {+ Button("Unpair all") { confirmingAll = true }.buttonStyle(QuietButtonStyle(tint: Palette.danger))+ }+ }+ if model.sessions.isEmpty {+ EmptyState(icon: "globe", title: "No browser is paired", detail: "Get a pairing code above and paste it into the Browsentic popup.")+ } else {+ ForEach(model.sessions) { SessionRow(session: $0) }+ }+ }+ }+ }+ }+ .confirmationDialog("Unpair every browser?", isPresented: $confirmingAll) {+ Button("Unpair all", role: .destructive) { Task { await model.revoke(nil) } }+ } message: { Text("Each one will need a new pairing code to connect again.") }+ }+}++private struct SessionRow: View {+ @EnvironmentObject private var model: AppModel+ let session: BrowserSession++ var body: some View {+ HStack(spacing: 12) {+ GlowDot(color: session.connected ? Palette.lime : Palette.inkFaint, pulsing: session.connected)+ VStack(alignment: .leading, spacing: 3) {+ Text(session.extensionId).font(.code(12)).foregroundStyle(Palette.ink).textSelection(.enabled)+ Text("Extension v\(session.extensionVersion) · paired \(Timestamp.ago(session.pairedAt)) · seen \(Timestamp.ago(session.lastSeenAt))")+ .font(.system(size: 11.5))+ .foregroundStyle(Palette.inkDim)+ }+ Spacer()+ Pill(text: session.connected ? "Connected" : "Away", tint: session.connected ? Palette.lime : Palette.inkDim)+ Button("Unpair") { Task { await model.revoke(session.origin) } }+ .buttonStyle(QuietButtonStyle(tint: Palette.danger))+ .disabled(model.busy.contains("revoke"))+ }+ .padding(12)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 12, style: .continuous))+ }+}diff --git a/src/mac/Sources/Browsentic/Views/LogsView.swift b/src/mac/Sources/Browsentic/Views/LogsView.swiftnew file mode 100644index 0000000..2ecdcd5--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/LogsView.swift@@ -0,0 +1,70 @@+import SwiftUI++struct LogsView: View {+ @EnvironmentObject private var model: AppModel+ @State private var following = true++ var body: some View {+ Card(padding: 0) {+ VStack(spacing: 0) {+ HStack(spacing: 8) {+ SectionTitle(title: "Daemon log", subtitle: Paths.tilde(Paths.log))+ Spacer()+ Toggle("Follow", isOn: $following).toggleStyle(.switch).controlSize(.small).tint(Palette.brand)+ .font(.system(size: 12)).foregroundStyle(Palette.inkDim)+ CopyButton(value: model.logText, label: "Copy all")+ Button { NSWorkspace.shared.activateFileViewerSelecting([Paths.log]) } label: { Label("Reveal", systemImage: "folder") }+ .buttonStyle(QuietButtonStyle())+ }+ .padding(16)+ Divider().overlay(Palette.line)+ ScrollViewReader { proxy in+ ScrollView {+ LazyVStack(alignment: .leading, spacing: 1) {+ ForEach(Array(model.logText.split(whereSeparator: \.isNewline).enumerated()), id: \.offset) { _, line in+ LogLine(text: String(line))+ }+ Color.clear.frame(height: 1).id("end")+ }+ .padding(14)+ .frame(maxWidth: .infinity, alignment: .leading)+ }+ .frame(height: 470)+ .background(Palette.ground2.opacity(0.6))+ .onChange(of: model.logText) { if following { proxy.scrollTo("end", anchor: .bottom) } }+ .onAppear { proxy.scrollTo("end", anchor: .bottom) }+ }+ }+ }+ .task {+ while !Task.isCancelled {+ model.loadLog()+ try? await Task.sleep(nanoseconds: 1_500_000_000)+ }+ }+ }+}++private struct LogLine: View {+ let text: String++ var body: some View {+ let split = text.firstIndex(of: " ")+ let stamp = split.map { String(text[..<$0]) } ?? ""+ let message = split.map { String(text[text.index(after: $0)...]) } ?? text+ let time = stamp.count >= 19 && stamp.contains("T") ? String(stamp.dropFirst(11).prefix(8)) : stamp+ HStack(alignment: .firstTextBaseline, spacing: 10) {+ Text(time).foregroundStyle(Palette.inkFaint)+ Text(message).foregroundStyle(tint(message)).textSelection(.enabled)+ }+ .font(.code(11))+ }++ private func tint(_ message: String) -> Color {+ let lowered = message.lowercased()+ if lowered.contains("rejected") || lowered.contains("error") || lowered.contains("failed") { return Palette.danger }+ if lowered.contains("drifted") || lowered.contains("revoked") { return Palette.amber }+ if lowered.contains("connected") || lowered.contains("paired") || lowered.contains("listening") { return Palette.lime }+ return Palette.inkDim+ }+}diff --git a/src/mac/Sources/Browsentic/Views/MainView.swift b/src/mac/Sources/Browsentic/Views/MainView.swiftnew file mode 100644index 0000000..dc81496--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/MainView.swift@@ -0,0 +1,110 @@+import SwiftUI++struct MainView: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ ZStack(alignment: .top) {+ ScrollView {+ Group {+ switch model.tab {+ case .overview: OverviewView()+ case .browsers: BrowsersView()+ case .agents: AgentsView()+ case .skills: SkillsView()+ case .activity: ActivityView()+ case .logs: LogsView()+ case .settings: SettingsView()+ }+ }+ .frame(maxWidth: 880)+ .padding(.horizontal, 28)+ .padding(.top, 64)+ .padding(.bottom, 36)+ .frame(maxWidth: .infinity)+ .id(model.tab)+ .transition(.opacity.combined(with: .offset(y: 8)))+ }+ .scrollIndicators(.never)++ TabCapsule().padding(.top, 6)+ }+ .animation(.easeInOut(duration: 0.22), value: model.tab)+ }+}++/// The view switcher floats at the top centre, ⌘1…⌘7.+private struct TabCapsule: View {+ @EnvironmentObject private var model: AppModel+ @Namespace private var highlight++ var body: some View {+ HStack(spacing: 2) {+ ForEach(Tab.allCases) { tab in+ let selected = model.tab == tab+ Button { model.tab = tab } label: {+ HStack(spacing: 6) {+ Image(systemName: tab.icon).font(.system(size: 11, weight: .semibold))+ Text(tab.label).font(.system(size: 12, weight: .medium))+ }+ .foregroundStyle(selected ? Palette.onBrand : Palette.inkDim)+ .padding(.horizontal, 12)+ .padding(.vertical, 7)+ .background {+ if selected { Capsule().fill(Palette.brand).matchedGeometryEffect(id: "tab", in: highlight) }+ }+ .contentShape(Capsule())+ }+ .buttonStyle(.plain)+ }+ }+ .padding(4)+ .background(.regularMaterial, in: Capsule())+ .overlay(Capsule().strokeBorder(Palette.line))+ .shadow(color: .black.opacity(0.25), radius: 18, y: 6)+ .animation(.spring(duration: 0.35), value: model.tab)+ }+}++struct NoticeBanner: View {+ let notice: Notice++ var body: some View {+ HStack(spacing: 10) {+ Image(systemName: notice.isError ? "exclamationmark.triangle.fill" : "checkmark.circle.fill")+ .foregroundStyle(notice.isError ? Palette.danger : Palette.lime)+ Text(notice.text)+ .font(.system(size: 12.5))+ .foregroundStyle(Palette.ink)+ .fixedSize(horizontal: false, vertical: true)+ .textSelection(.enabled)+ }+ .padding(.horizontal, 16)+ .padding(.vertical, 11)+ .frame(maxWidth: 620)+ .background(.regularMaterial, in: RoundedRectangle(cornerRadius: 14, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder((notice.isError ? Palette.danger : Palette.lime).opacity(0.4)))+ .shadow(color: .black.opacity(0.3), radius: 20, y: 8)+ }+}++struct OfflineHint: View {+ @EnvironmentObject private var model: AppModel+ let what: String++ var body: some View {+ Card {+ HStack(spacing: 14) {+ Image(systemName: "power").font(.system(size: 18, weight: .semibold)).foregroundStyle(Palette.amber)+ VStack(alignment: .leading, spacing: 3) {+ Text("The daemon is off").font(.display(14)).foregroundStyle(Palette.ink)+ Text("\(what) come from the running daemon.").font(.system(size: 12)).foregroundStyle(Palette.inkDim)+ }+ Spacer()+ Button("Turn it on") { Task { await model.setDaemon(on: true) } }+ .buttonStyle(PrimaryButtonStyle())+ .disabled(model.daemon != .off)+ }+ }+ }+}diff --git a/src/mac/Sources/Browsentic/Views/OverviewView.swift b/src/mac/Sources/Browsentic/Views/OverviewView.swiftnew file mode 100644index 0000000..3dc8bd9--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/OverviewView.swift@@ -0,0 +1,286 @@+import SwiftUI++struct OverviewView: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ VStack(spacing: 18) {+ Card(padding: 26) {+ HStack(spacing: 28) {+ PowerOrb(phase: model.daemon) { Task { await model.setDaemon(on: model.daemon == .off) } }+ VStack(alignment: .leading, spacing: 8) {+ HStack(spacing: 8) {+ GlowDot(color: tint, pulsing: model.daemon == .on)+ Text(model.daemon.label.uppercased())+ .font(.system(size: 11, weight: .bold))+ .kerning(1.2)+ .foregroundStyle(tint)+ }+ Text(title).font(.display(24, weight: .bold)).foregroundStyle(Palette.ink)+ Text(subtitle)+ .font(.system(size: 13))+ .foregroundStyle(Palette.inkDim)+ .fixedSize(horizontal: false, vertical: true)+ if model.daemon == .on {+ Button { Task { await model.restartDaemon() } } label: { Label("Restart", systemImage: "arrow.clockwise") }+ .buttonStyle(QuietButtonStyle())+ .disabled(model.busy.contains("restart"))+ .padding(.top, 4)+ }+ }+ Spacer(minLength: 0)+ }+ }++ if let status = model.status, let lock = model.lock {+ LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12), count: 4), spacing: 12) {+ Stat(label: "Address", value: "127.0.0.1:\(status.port)", icon: "network")+ Stat(label: "Daemon", value: "v\(status.daemonVersion)", detail: "pid \(lock.pid)", icon: "cpu")+ Stat(+ label: "Extension", value: status.connected ? "Connected" : "Not connected",+ detail: status.extensionVersion.map { "v\($0)" }, icon: "puzzlepiece.extension",+ tint: status.connected ? Palette.lime : Palette.amber+ )+ Stat(+ label: "Tools", value: status.manifestInSync ? "In sync" : "Drifted",+ detail: status.manifestInSync ? nil : "reload the extension", icon: "wrench.and.screwdriver",+ tint: status.manifestInSync ? Palette.lime : Palette.amber+ )+ }+ .transition(.opacity)+ }++ if model.daemon == .on, model.status?.pairedBrowsers == 0 || model.pairing != nil { ConnectCard() }+ ExtensionCard()+ }+ .animation(.spring(duration: 0.45), value: model.daemon)+ .animation(.spring(duration: 0.45), value: model.status)+ }++ private var tint: Color {+ switch model.daemon {+ case .on: Palette.lime+ case .off: Palette.inkFaint+ case .starting, .stopping: Palette.amber+ }+ }++ private var title: String {+ switch model.daemon {+ case .on: model.status?.connected == true ? "Your browser is in the loop" : "Waiting for your browser"+ case .off: "Browsentic is off"+ case .starting: "Bringing the daemon up"+ case .stopping: "Shutting down"+ }+ }++ private var subtitle: String {+ switch model.daemon {+ case .on:+ model.status?.connected == true+ ? "Open the side panel in your browser and say what you want. This window can close — the daemon keeps running."+ : "The daemon is listening. Load the extension and pair it, and the side panel comes alive."+ case .off: "Turn it on and the side panel in your browser can reach the agent you already run."+ case .starting, .stopping: "One moment."+ }+ }+}++private struct PowerOrb: View {+ let phase: DaemonPhase+ let toggle: () -> Void+ @Environment(\.colorScheme) private var scheme+ @State private var spin = false+ @State private var breathe = false+ @State private var hovering = false++ private var on: Bool { phase == .on }+ private var moving: Bool { phase == .starting || phase == .stopping }++ var body: some View {+ Button(action: toggle) {+ ZStack {+ Circle()+ .fill(RadialGradient(colors: [Palette.brand.opacity(on ? 0.4 : 0), .clear], center: .center, startRadius: 30, endRadius: 78))+ .scaleEffect(breathe ? 1.1 : 0.94)+ .opacity(Palette.glow(scheme))+ Circle()+ .trim(from: 0, to: moving ? 0.35 : 1)+ .stroke(+ on || moving+ ? AnyShapeStyle(AngularGradient(colors: [Palette.brand, Palette.ember, Palette.magenta, Palette.brand], center: .center))+ : AnyShapeStyle(Palette.lineStrong),+ style: StrokeStyle(lineWidth: 3, lineCap: .round)+ )+ .rotationEffect(.degrees(spin ? 360 : 0))+ .padding(14)+ Circle()+ .fill(LinearGradient(colors: [Palette.surface2, Palette.ground2], startPoint: .top, endPoint: .bottom))+ .overlay(Circle().strokeBorder(Palette.lineStrong))+ .padding(26)+ .shadow(color: .black.opacity(0.35), radius: 10, y: 6)+ Image(systemName: "power")+ .font(.system(size: 30, weight: .bold))+ .foregroundStyle(on ? Palette.brand : Palette.inkFaint)+ .shadow(color: Palette.brand.opacity(on ? 0.8 * Palette.glow(scheme) : 0), radius: 10)+ }+ .frame(width: 148, height: 148)+ .scaleEffect(hovering ? 1.03 : 1)+ .contentShape(Circle())+ }+ .buttonStyle(.plain)+ .disabled(moving)+ .onHover { hovering = $0 }+ .animation(.spring(duration: 0.5), value: phase)+ .animation(.spring(duration: 0.3), value: hovering)+ .onAppear {+ withAnimation(.linear(duration: 6).repeatForever(autoreverses: false)) { spin = true }+ withAnimation(.easeInOut(duration: 2.2).repeatForever(autoreverses: true)) { breathe = true }+ }+ .help(on ? "Turn the daemon off" : "Turn the daemon on")+ .accessibilityLabel(on ? "Turn the daemon off" : "Turn the daemon on")+ }+}++private struct Stat: View {+ let label: String+ let value: String+ var detail: String?+ let icon: String+ var tint: Color = Palette.brand++ var body: some View {+ VStack(alignment: .leading, spacing: 6) {+ HStack(spacing: 6) {+ Image(systemName: icon).font(.system(size: 10, weight: .semibold)).foregroundStyle(tint)+ Text(label.uppercased()).font(.system(size: 10, weight: .semibold)).kerning(0.8).foregroundStyle(Palette.inkFaint)+ }+ Text(value).font(.display(15)).foregroundStyle(Palette.ink).lineLimit(1).minimumScaleFactor(0.8)+ Text(detail ?? " ").font(.code(10.5)).foregroundStyle(Palette.inkDim)+ }+ .padding(14)+ .frame(maxWidth: .infinity, alignment: .leading)+ .background(Palette.surface.opacity(0.72), in: RoundedRectangle(cornerRadius: 14, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Palette.line))+ }+}++struct ConnectCard: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ Card {+ VStack(alignment: .leading, spacing: 16) {+ SectionTitle(+ title: "Pair a browser",+ subtitle: "Open the Browsentic popup in your browser, paste the code, and press Connect. It works once and expires in ten minutes."+ )+ if let pairing = model.pairing {+ PairingCodeView(pairing: pairing)+ } else {+ Button { Task { await model.newPairingCode() } } label: { Label("Get a pairing code", systemImage: "key.horizontal") }+ .buttonStyle(PrimaryButtonStyle())+ .disabled(model.busy.contains("pair"))+ }+ }+ }+ }+}++struct PairingCodeView: View {+ @EnvironmentObject private var model: AppModel+ let pairing: PairingCode++ var body: some View {+ TimelineView(.periodic(from: .now, by: 1)) { context in+ let left = max(0, pairing.expiry.timeIntervalSince(context.date))+ HStack(spacing: 18) {+ HStack(spacing: 6) {+ ForEach(Array(pairing.grouped.enumerated()), id: \.offset) { _, character in+ if character == "-" {+ Text("–").font(.code(22)).foregroundStyle(Palette.inkFaint)+ } else {+ Text(String(character))+ .font(.code(24, weight: .bold))+ .foregroundStyle(Palette.brand)+ .frame(width: 34, height: 44)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 9, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 9, style: .continuous).strokeBorder(Palette.brand.opacity(0.3)))+ }+ }+ }+ VStack(alignment: .leading, spacing: 6) {+ Text(left > 0 ? "Expires in \(Int(left) / 60):\(String(format: "%02d", Int(left) % 60))" : "Expired")+ .font(.code(12))+ .foregroundStyle(left < 60 ? Palette.amber : Palette.inkDim)+ HStack(spacing: 8) {+ CopyButton(value: pairing.grouped, label: "Copy code")+ Button("New code") { Task { await model.newPairingCode() } }.buttonStyle(QuietButtonStyle())+ }+ }+ }+ }+ }+}++struct ExtensionCard: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ Card {+ VStack(alignment: .leading, spacing: 14) {+ HStack {+ SectionTitle(title: "The extension", subtitle: subtitle)+ Spacer()+ if let stamp = model.stamp { Pill(text: "v\(stamp.version) unpacked", tint: Palette.brand) }+ if model.extensionNeedsReload { Pill(text: "Reload needed", tint: Palette.amber, icon: "arrow.clockwise") }+ }+ PathRow(url: Paths.extensionDir())+ if model.status?.connected != true {+ VStack(alignment: .leading, spacing: 8) {+ Step(number: 1, text: "Open chrome://extensions and turn on Developer mode.")+ Step(number: 2, text: "Press “Load unpacked”, then ⇧⌘G, and paste the path above.")+ Step(number: 3, text: "Open the Browsentic popup and paste a pairing code.")+ }+ }+ HStack(spacing: 8) {+ ForEach(model.browsers.prefix(3)) { browser in+ Button { model.openExtensionsPage(in: browser) } label: {+ Label("Extensions in \(browser.name)", systemImage: "arrow.up.forward.app")+ }+ .buttonStyle(QuietButtonStyle())+ }+ Spacer()+ Button { Task { await model.reinstallExtension() } } label: { Label("Write it again", systemImage: "arrow.down.doc") }+ .buttonStyle(QuietButtonStyle())+ .disabled(model.busy.contains("extension"))+ }+ }+ }+ }++ private var subtitle: String {+ if model.extensionNeedsReload {+ return "A newer build is unpacked than the one your browser has loaded. Press ↻ on the Browsentic card at chrome://extensions."+ }+ return model.status?.connected == true+ ? "Loaded and talking to the daemon. The folder below has to stay where it is — the browser's pairing is tied to the path."+ : "Browsers only load an unpacked extension by hand, so these three steps are yours."+ }+}++private struct Step: View {+ let number: Int+ let text: String++ var body: some View {+ HStack(alignment: .firstTextBaseline, spacing: 10) {+ Text("\(number)")+ .font(.code(10, weight: .bold))+ .foregroundStyle(Palette.brand)+ .frame(width: 18, height: 18)+ .background(Palette.brand.opacity(0.14), in: Circle())+ Text(text).font(.system(size: 12.5)).foregroundStyle(Palette.inkDim)+ }+ }+}diff --git a/src/mac/Sources/Browsentic/Views/PreflightView.swift b/src/mac/Sources/Browsentic/Views/PreflightView.swiftnew file mode 100644index 0000000..e1d6e6a--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/PreflightView.swift@@ -0,0 +1,189 @@+import SwiftUI++struct PreflightView: View {+ @EnvironmentObject private var model: AppModel++ var body: some View {+ VStack(spacing: 0) {+ Spacer(minLength: 24)+ Beacon(active: model.preflightBusy || model.fixing, settled: model.canEnter && !model.preflightBusy)+ .frame(width: 148, height: 148)+ Text("Browsentic")+ .font(.display(30, weight: .bold))+ .foregroundStyle(Palette.ink)+ .padding(.top, 18)+ Text(headline)+ .font(.system(size: 13))+ .foregroundStyle(Palette.inkDim)+ .padding(.top, 4)+ .contentTransition(.opacity)+ .animation(.easeInOut, value: headline)++ VStack(spacing: 8) {+ ForEach(Array(CheckID.allCases.enumerated()), id: \.element) { index, id in+ CheckRow(id: id, state: model.checks[id] ?? .waiting)+ .transition(.move(edge: .bottom).combined(with: .opacity))+ .animation(.spring(duration: 0.5).delay(Double(index) * 0.05), value: model.checks[id])+ }+ }+ .frame(width: 560)+ .padding(.top, 28)++ HStack(spacing: 10) {+ if !model.preflightBusy {+ if model.needsSetup {+ Button { Task { await model.setUpEverything() } } label: {+ Label(model.fixing ? "Setting up…" : "Set up everything", systemImage: "wand.and.stars")+ }+ .buttonStyle(PrimaryButtonStyle())+ .disabled(model.fixing)+ } else {+ Button { model.enter() } label: { Label("Open Browsentic", systemImage: "arrow.right") }+ .buttonStyle(PrimaryButtonStyle())+ }+ Button { Task { await model.runPreflight() } } label: { Label("Check again", systemImage: "arrow.clockwise") }+ .buttonStyle(QuietButtonStyle())+ .disabled(model.fixing)+ }+ }+ .frame(height: 40)+ .padding(.top, 22)+ .animation(.easeInOut, value: model.preflightBusy)++ Spacer(minLength: 24)+ Text("Everything Browsentic installs stays in ~/.browsentic and ~/browsentic. No password, no account.")+ .font(.system(size: 11))+ .foregroundStyle(Palette.inkFaint)+ .padding(.bottom, 18)+ }+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ }++ private var headline: String {+ if model.fixing { return "Installing what is missing" }+ if model.preflightBusy { return "Checking what this Mac already has" }+ if model.needsSetup { return "A few things are missing — one click installs them" }+ return "Everything is in place"+ }+}++/// The loading mark: the brand glyph inside two counter-rotating arcs and a breathing halo.+private struct Beacon: View {+ let active: Bool+ let settled: Bool+ @Environment(\.colorScheme) private var scheme+ @State private var spin = false+ @State private var breathe = false++ var body: some View {+ ZStack {+ Circle()+ .fill(RadialGradient(colors: [Palette.brand.opacity(0.35), .clear], center: .center, startRadius: 4, endRadius: 80))+ .scaleEffect(breathe ? 1.12 : 0.9)+ .opacity(Palette.glow(scheme) * 0.9 + 0.1)+ Circle()+ .trim(from: 0, to: active ? 0.62 : 1)+ .stroke(+ AngularGradient(colors: [Palette.brand.opacity(0), Palette.brand, Palette.ember], center: .center),+ style: StrokeStyle(lineWidth: 2.5, lineCap: .round)+ )+ .rotationEffect(.degrees(spin ? 360 : 0))+ .padding(6)+ Circle()+ .trim(from: 0, to: active ? 0.3 : 0)+ .stroke(Palette.magenta.opacity(0.8), style: StrokeStyle(lineWidth: 1.5, lineCap: .round))+ .rotationEffect(.degrees(spin ? -360 : 0))+ .padding(16)+ RoundedRectangle(cornerRadius: 22, style: .continuous)+ .fill(LinearGradient(colors: [Palette.surface, Palette.ground], startPoint: .top, endPoint: .bottom))+ .overlay(RoundedRectangle(cornerRadius: 22, style: .continuous).strokeBorder(Palette.lineStrong))+ .overlay(BrandMark().padding(12))+ .frame(width: 92, height: 92)+ .shadow(color: (settled ? Palette.lime : Palette.brand).opacity(0.5 * Palette.glow(scheme)), radius: 26)+ .scaleEffect(settled ? 1.04 : 1)+ }+ .animation(.spring(duration: 0.7), value: active)+ .animation(.spring(duration: 0.7), value: settled)+ .onAppear {+ withAnimation(.linear(duration: 2.6).repeatForever(autoreverses: false)) { spin = true }+ withAnimation(.easeInOut(duration: 1.8).repeatForever(autoreverses: true)) { breathe = true }+ }+ }+}++private struct CheckRow: View {+ @EnvironmentObject private var model: AppModel+ let id: CheckID+ let state: CheckState++ var body: some View {+ HStack(spacing: 12) {+ Image(systemName: id.icon)+ .font(.system(size: 14, weight: .medium))+ .foregroundStyle(state == .waiting ? Palette.inkFaint : Palette.brand)+ .frame(width: 30, height: 30)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 9, style: .continuous))++ VStack(alignment: .leading, spacing: 2) {+ Text(id.title).font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)+ Text(detail)+ .font(.system(size: 11.5))+ .foregroundStyle(detailTint)+ .lineLimit(2)+ .fixedSize(horizontal: false, vertical: true)+ if case .working(let fraction?, _) = state {+ ProgressView(value: fraction).tint(Palette.brand).padding(.top, 3)+ }+ }+ Spacer(minLength: 8)+ action+ indicator.frame(width: 22)+ }+ .padding(.horizontal, 14)+ .padding(.vertical, 10)+ .background(Palette.surface.opacity(0.72), in: RoundedRectangle(cornerRadius: 14, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(state.needsAttention ? Palette.amber.opacity(0.45) : Palette.line))+ .opacity(state == .waiting ? 0.45 : 1)+ }++ private var detail: String {+ switch state {+ case .waiting: "Waiting"+ case .checking: "Checking…"+ case .passed(let text), .missing(let text), .advisory(let text), .failed(let text): text+ case .working(_, let label): label+ }+ }++ private var detailTint: Color {+ if case .failed = state { return Palette.danger }+ return Palette.inkDim+ }++ @ViewBuilder private var action: some View {+ if !model.fixing, !model.preflightBusy {+ switch (id, state) {+ case (.browser, .advisory):+ Button("Get Chrome") { Task { await model.fix(.browser) } }.buttonStyle(QuietButtonStyle())+ case (.agent, .advisory) where model.node != nil:+ Button("Install Claude Code") { Task { await model.fix(.agent) } }.buttonStyle(QuietButtonStyle())+ case (_, .missing), (_, .failed):+ if id.installsAutomatically {+ Button("Install") { Task { await model.fix(id) } }.buttonStyle(QuietButtonStyle())+ }+ default: EmptyView()+ }+ }+ }++ @ViewBuilder private var indicator: some View {+ switch state {+ case .waiting: Circle().strokeBorder(Palette.lineStrong, lineWidth: 1.5).frame(width: 16, height: 16)+ case .checking, .working: ProgressView().controlSize(.small)+ case .passed: Image(systemName: "checkmark.circle.fill").foregroundStyle(Palette.lime).transition(.scale.combined(with: .opacity))+ case .missing: Image(systemName: "arrow.down.circle.fill").foregroundStyle(Palette.amber)+ case .advisory: Image(systemName: "exclamationmark.circle.fill").foregroundStyle(Palette.amber)+ case .failed: Image(systemName: "xmark.octagon.fill").foregroundStyle(Palette.danger)+ }+ }+}diff --git a/src/mac/Sources/Browsentic/Views/SettingsView.swift b/src/mac/Sources/Browsentic/Views/SettingsView.swiftnew file mode 100644index 0000000..1785436--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/SettingsView.swift@@ -0,0 +1,133 @@+import SwiftUI++struct SettingsView: View {+ @EnvironmentObject private var model: AppModel+ @AppStorage("appearance") private var appearance = Appearance.system.rawValue+ @AppStorage("startDaemonOnLaunch") private var startOnLaunch = true+ @State private var confirmingUninstall = false+ @State private var keepSkills = true++ private var mcpCommand: String { "claude mcp add browsentic -- \(Paths.mcpShim.path)" }++ var body: some View {+ VStack(spacing: 18) {+ if let latest = model.latestRelease {+ Card {+ HStack(spacing: 14) {+ Image(systemName: "arrow.down.circle.fill").font(.system(size: 22)).foregroundStyle(Palette.brand)+ SectionTitle(title: "Browsentic \(latest) is out", subtitle: "You have \(model.appVersion). The new app replaces the command and the extension together.")+ Spacer()+ Button("Download") { NSWorkspace.shared.open(URL(string: "https://github.com/imshaikot/browsentic/releases/latest")!) }+ .buttonStyle(PrimaryButtonStyle())+ }+ }+ }++ Card {+ VStack(alignment: .leading, spacing: 14) {+ SectionTitle(title: "Appearance")+ Picker("Appearance", selection: $appearance) {+ ForEach(Appearance.allCases) { Text($0.label).tag($0.rawValue) }+ }+ .pickerStyle(.segmented)+ .labelsHidden()+ .fixedSize()+ Divider().overlay(Palette.line)+ SwitchRow(+ title: "Turn the daemon on when the app opens",+ subtitle: "It keeps running after the window closes, so the side panel and MCP clients still work.",+ isOn: $startOnLaunch+ )+ }+ }++ Card {+ VStack(alignment: .leading, spacing: 12) {+ SwitchRow(+ title: "“browsentic” in your terminal",+ subtitle: model.commandDir.map { "Linked in \(Paths.tilde(URL(fileURLWithPath: $0))). Everything this window does, the command does too." }+ ?? "Links the command into a folder already on your PATH. No password, and no shell profile is edited.",+ isOn: Binding(get: { model.commandDir != nil }, set: { model.setCommandLink($0) })+ )+ if let foreign = model.foreignCommand {+ Label("Another browsentic is already on your PATH at \(foreign). Remove it with “npm rm -g browsentic” so the two cannot disagree.", systemImage: "exclamationmark.triangle")+ .font(.system(size: 11.5))+ .foregroundStyle(Palette.amber)+ .fixedSize(horizontal: false, vertical: true)+ }+ PathRow(url: Paths.shim)+ }+ }++ Card {+ VStack(alignment: .leading, spacing: 12) {+ SectionTitle(title: "Optional: use it from an MCP client", subtitle: "The same browser tools, handed to Claude Code or any other MCP client. The side panel does not need this.")+ HStack {+ Text(mcpCommand).font(.code(11.5)).foregroundStyle(Palette.ink).lineLimit(1).truncationMode(.middle).textSelection(.enabled)+ Spacer()+ CopyButton(value: mcpCommand)+ }+ .padding(.leading, 12).padding(.trailing, 6).padding(.vertical, 6)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 10, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 10, style: .continuous).strokeBorder(Palette.line))+ if let token = model.lock?.token {+ HStack {+ Text("Control token").font(.system(size: 12)).foregroundStyle(Palette.inkDim)+ Text(String(repeating: "•", count: 24)).font(.code(11)).foregroundStyle(Palette.inkFaint)+ Spacer()+ CopyButton(value: token, label: "Copy token")+ }+ }+ }+ }++ Card {+ VStack(alignment: .leading, spacing: 12) {+ SectionTitle(title: "About", subtitle: "Browsentic \(model.appVersion) · free and open source, MIT.")+ HStack(spacing: 8) {+ Button("browsentic.com") { NSWorkspace.shared.open(URL(string: "https://browsentic.com")!) }.buttonStyle(QuietButtonStyle())+ Button("Source") { NSWorkspace.shared.open(URL(string: "https://github.com/imshaikot/browsentic")!) }.buttonStyle(QuietButtonStyle())+ Button("Run the checks again") { model.phase = .preflight; Task { await model.runPreflight() } }.buttonStyle(QuietButtonStyle())+ Spacer()+ Button("Uninstall…") { confirmingUninstall = true }.buttonStyle(QuietButtonStyle(tint: Palette.danger))+ }+ }+ }+ }+ .onAppear { model.refreshCommandLink() }+ .sheet(isPresented: $confirmingUninstall) {+ VStack(alignment: .leading, spacing: 14) {+ Text("Uninstall Browsentic?").font(.display(18)).foregroundStyle(Palette.ink)+ Text("This stops the daemon, unpairs every browser, and removes ~/.browsentic and ~/browsentic — the command, the unpacked extension, keys, approvals and logs.\n\nRemove the Browsentic card at chrome://extensions first, then drag this app to the Trash afterwards.")+ .font(.system(size: 12.5)).foregroundStyle(Palette.inkDim).fixedSize(horizontal: false, vertical: true)+ Toggle("Keep my skills and site maps", isOn: $keepSkills).toggleStyle(.checkbox)+ HStack {+ Spacer()+ Button("Cancel") { confirmingUninstall = false }.buttonStyle(QuietButtonStyle())+ Button("Uninstall") {+ confirmingUninstall = false+ Task { await model.uninstall(keepSkills: keepSkills) }+ }+ .buttonStyle(PrimaryButtonStyle(tint: Palette.danger))+ }+ }+ .padding(24)+ .frame(width: 440)+ .background(Palette.ground)+ }+ }+}++private struct SwitchRow: View {+ let title: String+ let subtitle: String+ @Binding var isOn: Bool++ var body: some View {+ HStack(spacing: 16) {+ SectionTitle(title: title, subtitle: subtitle)+ Spacer(minLength: 0)+ Toggle(title, isOn: $isOn).toggleStyle(.switch).labelsHidden().tint(Palette.brand)+ }+ }+}diff --git a/src/mac/Sources/Browsentic/Views/SkillsView.swift b/src/mac/Sources/Browsentic/Views/SkillsView.swiftnew file mode 100644index 0000000..a4f06ed--- /dev/null+++ b/src/mac/Sources/Browsentic/Views/SkillsView.swift@@ -0,0 +1,109 @@+import SwiftUI++struct SkillsView: View {+ @EnvironmentObject private var model: AppModel+ @State private var query = ""++ private var shown: [Skill] {+ let skills = model.skills?.skills ?? []+ guard !query.isEmpty else { return skills }+ return skills.filter { "\($0.name) \($0.description) \($0.domains.joined(separator: " "))".localizedCaseInsensitiveContains(query) }+ }++ var body: some View {+ VStack(spacing: 18) {+ Card {+ VStack(alignment: .leading, spacing: 12) {+ HStack {+ SectionTitle(+ title: "Skills the agent can route to",+ subtitle: "Read in order — a later folder shadows an earlier one by name. Drop a folder with a SKILL.md into yours to add one."+ )+ Spacer()+ Button { Task { await model.loadSkills() } } label: { Label("Refresh", systemImage: "arrow.clockwise") }+ .buttonStyle(QuietButtonStyle())+ }+ ForEach(model.skills?.dirs ?? [], id: \.self) { dir in+ PathRow(url: URL(fileURLWithPath: (dir as NSString).expandingTildeInPath))+ }+ TextField("Filter by name, description or site", text: $query)+ .textFieldStyle(.plain)+ .font(.system(size: 13))+ .padding(.horizontal, 12).padding(.vertical, 8)+ .background(Palette.ground2, in: RoundedRectangle(cornerRadius: 10, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 10, style: .continuous).strokeBorder(Palette.line))+ }+ }++ if model.skills == nil {+ ProgressView().padding(40)+ } else if shown.isEmpty {+ EmptyState(icon: "book.closed", title: "No skill matches", detail: "Clear the filter to see all of them.")+ } else {+ LazyVGrid(columns: [GridItem(.flexible(), spacing: 12), GridItem(.flexible(), spacing: 12)], spacing: 12) {+ ForEach(shown) { SkillTile(skill: $0) }+ }+ }++ if let own = model.skills?.agentSkills, !own.isEmpty {+ Card {+ VStack(alignment: .leading, spacing: 10) {+ SectionTitle(title: "The agent’s own skills", subtitle: "Attachable from the side panel’s / picker.")+ ForEach(own) { skill in+ VStack(alignment: .leading, spacing: 2) {+ Text(skill.name).font(.code(12, weight: .semibold)).foregroundStyle(Palette.ink)+ if let description = skill.description, !description.isEmpty {+ Text(description).font(.system(size: 11.5)).foregroundStyle(Palette.inkDim).lineLimit(2)+ }+ }+ }+ }+ }+ }+ }+ .task { await model.loadSkills() }+ }+}++private struct SkillTile: View {+ let skill: Skill++ private var tint: Color {+ switch skill.source {+ case "bundled": Palette.brand+ case "user": Palette.ember+ default: Palette.magenta+ }+ }++ var body: some View {+ VStack(alignment: .leading, spacing: 8) {+ HStack(spacing: 6) {+ Text(skill.name).font(.code(12.5, weight: .semibold)).foregroundStyle(Palette.ink).lineLimit(1)+ Spacer(minLength: 4)+ if skill.isDefault { Pill(text: "default", tint: Palette.lime) }+ Pill(text: skill.provenance == "generated" ? "mapped" : skill.source, tint: tint)+ }+ Text(skill.description.isEmpty ? "No description." : skill.description)+ .font(.system(size: 12))+ .foregroundStyle(Palette.inkDim)+ .lineLimit(3)+ .frame(maxWidth: .infinity, minHeight: 44, alignment: .topLeading)+ HStack(spacing: 6) {+ ForEach(skill.domains.prefix(2), id: \.self) { Pill(text: $0, icon: "globe") }+ Spacer()+ if let path = skill.path {+ Button { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)]) } label: {+ Image(systemName: "folder")+ }+ .buttonStyle(.plain)+ .foregroundStyle(Palette.inkDim)+ .help("Reveal in Finder")+ }+ }+ }+ .padding(14)+ .background(Palette.surface.opacity(0.72), in: RoundedRectangle(cornerRadius: 14, style: .continuous))+ .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Palette.line))+ }+}