Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Reorder or hide panel sections, choose a compact layout, and export settings to

- **Dynamic Island.** Keep music, notifications, calendars, timers, downloads and everyday controls around the camera cutout, or a simulated one on other Macs. Customize sections and shortcuts, with optional lyrics, a live equalizer, camera preview and file tools.
- **AI agents.** Follow Claude, Codex, OpenCode and GitHub Copilot in the Dynamic Island: plan limits and when they reset where available, tokens, API value, models, projects and live work, with a notice when a long task finishes. Codex's banked resets can be used from there too, and each extra Codex account (`CODEX_HOME`) can have a limits card of its own. Copilot uses local CLI/app session logs; its token totals update when shutdown metrics arrive, and aggregate API-value estimates use base rates.
- **Claude Code sessions.** See every Claude Code session running on your Mac in the Dynamic Island: its folder and branch, whether it works, runs a tool, waits on you or is done, its latest tools, tasks, subagents and cost. Answer its permission prompts with the whole command in view, jump to its Terminal tab or Antigravity window, and type a reply that reaches it as if typed there. Enlarge a session's page to read the whole conversation at a text size you pick and write a longer reply. Permission prompts use opt-in Claude Code hooks; prompts and replies stay unread unless you turn on previews.
- **Claude Code sessions.** See every Claude Code session running on your Mac in the Dynamic Island: its folder and branch, whether it works, runs a tool, waits on you or is done, its latest tools, tasks, subagents and cost. Answer its permission prompts with the whole command in view, pick an answer to the questions Claude asks, or write your own, jump to its Terminal tab or Antigravity window, and type a reply that reaches it as if typed there. Enlarge a session's page to read the whole conversation at a text size you pick and write a longer reply. Permission prompts and questions use opt-in Claude Code hooks; prompts and replies stay unread unless you turn on previews.
- **Command Bar.** Search apps, windows, files, clipboard history, snippets and app menu commands from one field. Calculate, convert units, find emoji or run saved scripts.
- **Quick panel.** Open a floating palette of favorite tools with ⌃⌘V.
- **Quick toggles.** Switch appearance, hide desktop icons, eject disks, empty the Trash, lock the screen and more.
Expand Down
14 changes: 13 additions & 1 deletion Sources/Vorssaint/Core/NotchClaudeSessionStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ struct NotchClaudeSessionStrings {
let alwaysAllow: String
let deny: String
let answerInTerminal: String
let question: String
let pickAny: String
let ownAnswer: String
let sendAnswer: String
let skip: String
let questionHint: String
let open: String
let enlarge: String
let leftRunningFormat: String
Expand Down Expand Up @@ -128,6 +134,12 @@ extension NotchClaudeSessionStrings {
alwaysAllow: "Always",
deny: "Deny",
answerInTerminal: "Answer this one in the terminal.",
question: "Claude asks",
pickAny: "Pick any that apply",
ownAnswer: "Or write your own answer…",
sendAnswer: "Answer",
skip: "Skip",
questionHint: "Your answer goes straight to Claude. Return sends what you wrote, and ⌘N skips the question.",
open: "Open",
enlarge: "Enlarge",
leftRunningFormat: "%d left running",
Expand Down Expand Up @@ -167,7 +179,7 @@ extension NotchClaudeSessionStrings {
contentPreview: "Show previews",
contentPreviewHint: "Shows titles, commands, file names and the conversation. They stay in memory and are cleared when you turn this off.",
hooksTitle: "Claude Code hooks",
hooksHint: "Hooks let the island show which tool runs and answer permission prompts. They’re added to ~/.claude/settings.json next to your own, with a backup first. Without the app running, Claude Code asks in the terminal as usual.",
hooksHint: "Hooks let the island show which tool runs, answer permission prompts and answer Claude’s questions. They’re added to ~/.claude/settings.json next to your own, with a backup first. Without the app running, Claude Code asks in the terminal as usual.",
hooksInstalled: "Installed",
hooksMissing: "Not installed",
installHooks: "Install Hooks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct ClaudeHookMessage {
/// The rules Claude Code offered to stop asking, handed back as they came
/// when the person picks Always.
let suggestions: Any?
/// The input of a question, handed back whole with the answers.
var questionInput: [String: Any]? = nil

var isPermissionRequest: Bool {
if case .permissionRequested = fact.event { return true }
Expand All @@ -28,6 +30,7 @@ struct ClaudeHookMessage {
let toolID = json["tool_use_id"] as? String ?? ""
let agent = (json["agent_id"] as? String).flatMap { $0.isEmpty ? nil : $0 }
var suggestions: Any?
var questionInput: [String: Any]?
let event: ClaudeHookFact.Event
// Subagent events name the subagent they are about; any other event
// carrying an agent comes from inside that subagent.
Expand All @@ -44,15 +47,24 @@ struct ClaudeHookMessage {
case "PostToolUse", "PostToolUseFailure":
guard !toolID.isEmpty else { return nil }
event = .toolFinished(id: toolID, failed: name == "PostToolUseFailure")
case "PermissionRequest" where tool == ClaudeQuestion.tool && ClaudeQuestion.questions(in: input) == nil:
// A question the island cannot show is asked in the terminal, never
// allowed without its answers.
event = .other(name)
case "PermissionRequest":
let offered = json["permission_suggestions"] as? [Any] ?? []
suggestions = offered.isEmpty ? nil : offered
// A question Claude asks comes as a permission for its tool; the
// answers go back in the tool's input.
let questions = tool == ClaudeQuestion.tool ? ClaudeQuestion.questions(in: input) ?? [] : []
if !questions.isEmpty { questionInput = input }
event = .permissionRequested(ClaudePermission(
requestID: requestID, tool: tool.isEmpty ? "Tool" : tool,
summary: ClaudeToolSummary.summary(name: tool, input: input),
summary: questions.first.map { ClaudeToolSummary.clip($0.question) }
?? ClaudeToolSummary.summary(name: tool, input: input),
detail: ClaudeToolSummary.permissionDetail(name: tool, input: input),
offersAlways: !offered.isEmpty, since: now,
inputKey: ClaudeToolSummary.inputKey(name: tool, input: input)))
offersAlways: !offered.isEmpty && questions.isEmpty, since: now,
inputKey: ClaudeToolSummary.inputKey(name: tool, input: input), questions: questions))
case "Notification": event = .notification(type: json["notification_type"] as? String ?? "")
case "Stop":
let text = policy.previews ? (json["last_assistant_message"] as? String).map(preview) : nil
Expand All @@ -69,7 +81,7 @@ struct ClaudeHookMessage {
}
return ClaudeHookMessage(
fact: ClaudeHookFact(sessionID: session, date: now, event: event, agentID: from),
transcript: json["transcript_path"] as? String, suggestions: suggestions)
transcript: json["transcript_path"] as? String, suggestions: suggestions, questionInput: questionInput)
}

private static func preview(_ text: String) -> String? {
Expand All @@ -81,20 +93,30 @@ struct ClaudeHookMessage {

enum Decision: Equatable {
case allow, allowAlways, deny
/// What the person picked or typed for each question, by its text.
case answer([String: [String]])
}

static let denyMessage = "Denied from the Dynamic Island."
static let skipMessage = "The user skipped the question from the Dynamic Island without answering."

/// What the hook prints for Claude Code. Always adds the rules Claude Code
/// offered, so it stops asking for the same thing.
static func reply(_ decision: Decision, suggestions: Any?) -> Data {
/// offered, so it stops asking for the same thing. Answers go back in the
/// question's own input, unchanged but for them.
static func reply(_ decision: Decision, suggestions: Any?, input: [String: Any]? = nil) -> Data {
var body: [String: Any]
switch decision {
case .allow: body = ["behavior": "allow"]
case .allowAlways:
body = ["behavior": "allow"]
if let suggestions { body["updatedPermissions"] = suggestions }
case .deny: body = ["behavior": "deny", "message": denyMessage]
case .deny: body = ["behavior": "deny", "message": input == nil ? denyMessage : skipMessage]
case .answer(let answers):
guard var updated = input else { return Data() }
// One answer goes as text; several, for a question that takes
// more than one, as a list.
updated["answers"] = answers.mapValues { picked -> Any in picked.count == 1 ? picked[0] : picked }
body = ["behavior": "allow", "updatedInput": updated]
}
let output: [String: Any] = ["hookSpecificOutput": ["hookEventName": "PermissionRequest", "decision": body]]
return (try? JSONSerialization.data(withJSONObject: output, options: [.sortedKeys])) ?? Data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ final class ClaudeSessionEngine {

/// The phase the rules above give one session.
static func phase(record: ClaudeSessionRecord, activity entry: Activity, now: Date) -> ClaudeSessionPhase {
if !entry.permissions.isEmpty { return .waitingPermission }
// A question Claude asks waits on the person's answer, not a permission.
if let first = entry.permissions.first { return first.asksQuestions ? .waitingInput : .waitingPermission }
if record.status == .waiting {
guard record.waitingFor == ClaudeSessionRecord.dialogOpen else {
return record.waitingFor == ClaudeSessionRecord.permissionPrompt ? .waitingPermission : .waitingInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,58 @@ struct ClaudePermission: Equatable {
var toolID: String? = nil
/// Matches the tool call whose input this is.
var inputKey: Int? = nil
/// What Claude asks the person to choose, when the request is for a
/// question rather than a tool; it is answered, not allowed.
var questions: [ClaudeQuestion] = []

var asksQuestions: Bool { !questions.isEmpty }

/// A request short enough to read whole on one line of the list.
var fitsOnALine: Bool { !detail.contains("\n") && detail.count <= ClaudeToolSummary.quickDecisionLimit }
var fitsOnALine: Bool {
!asksQuestions && !detail.contains("\n") && detail.count <= ClaudeToolSummary.quickDecisionLimit
}
}

/// One question Claude asks through AskUserQuestion, with the answers it
/// wrote for it. Shown even with previews off, like a permission's detail:
/// nobody can answer what they cannot read.
struct ClaudeQuestion: Equatable {
struct Option: Equatable {
let label: String
var description: String? = nil
/// A mockup or snippet the option stands for, shown once it is picked.
var preview: String? = nil
}

static let tool = "AskUserQuestion"
/// Claude Code takes at most four questions of four options each, and
/// refuses answers longer than 32,768 UTF-16 units in all; each answer
/// written by hand keeps to a share of that, leaving room for the choices.
static let ownAnswerLimit = 7_500

let question: String
var header: String? = nil
var options: [Option] = []
var multiSelect = false

/// The questions of the tool's input, or nil when it holds none that
/// can be shown.
static func questions(in input: [String: Any]) -> [ClaudeQuestion]? {
guard let list = input["questions"] as? [[String: Any]] else { return nil }
let questions = list.compactMap { item -> ClaudeQuestion? in
guard let text = item["question"] as? String, !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
else { return nil }
let options = (item["options"] as? [[String: Any]] ?? []).compactMap { option -> Option? in
guard let label = option["label"] as? String, !label.isEmpty else { return nil }
return Option(label: label, description: (option["description"] as? String).flatMap { $0.isEmpty ? nil : $0 },
preview: (option["preview"] as? String).flatMap { $0.isEmpty ? nil : $0 })
}
return ClaudeQuestion(question: text, header: (item["header"] as? String).flatMap { $0.isEmpty ? nil : $0 },
options: options, multiSelect: item["multiSelect"] as? Bool ?? false)
}
// Every question needs an answer Claude Code can match to it.
return questions.isEmpty || questions.count != list.count ? nil : questions
}
}

struct ClaudeSubagent: Equatable, Identifiable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ final class ClaudeSessionService: ObservableObject {
private var lastRecords: [Int32: ClaudeSessionRecord] = [:]
private var server: ClaudeHookServer?
/// Permission requests whose hook waits for the island's answer.
private var pending: [String: (connection: ClaudeHookServer.Connection, session: String, suggestions: Any?, since: Date)] = [:]
private var pending: [String: (connection: ClaudeHookServer.Connection, session: String, suggestions: Any?,
question: [String: Any]?, since: Date)] = [:]
/// Claude Code gives up on a hook after its timeout; the island lets go first.
private static let permissionDeadline: TimeInterval = TimeInterval(ClaudeHookInstaller.permissionTimeout - 10)

Expand Down Expand Up @@ -198,8 +199,16 @@ final class ClaudeSessionService: ObservableObject {
guard let shown = shownRequests[id], shown.request == request,
Date().timeIntervalSince(shown.at) >= NotchClaudeSessionsSupport.settleDelay else { return }
queue.async { [self] in
guard engine.holds(request, for: id), let waiting = pending.removeValue(forKey: request) else { return }
waiting.connection.finish(ClaudeHookMessage.reply(decision, suggestions: waiting.suggestions))
guard engine.holds(request, for: id), let asked = pending[request] else { return }
// A question is answered or skipped, never allowed as it stands;
// answers go only to a question.
switch decision {
case .allow, .allowAlways: guard asked.question == nil else { return }
case .answer: guard asked.question != nil else { return }
case .deny: break
}
pending[request] = nil
asked.connection.finish(ClaudeHookMessage.reply(decision, suggestions: asked.suggestions, input: asked.question))
engine.resolvePermission(requestID: request)
engine.acknowledge(id, now: Date())
publish(now: Date())
Expand Down Expand Up @@ -309,7 +318,7 @@ final class ClaudeSessionService: ObservableObject {
}
if let transcript = message.transcript, !transcript.isEmpty { transcripts[message.fact.sessionID] = transcript }
if message.isPermissionRequest {
pending[request] = (connection, message.fact.sessionID, message.suggestions, now)
pending[request] = (connection, message.fact.sessionID, message.suggestions, message.questionInput, now)
} else {
connection.finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,39 @@ enum NotchClaudeSessionsSupport {
}
}

/// What goes back for Claude's questions: for each, the options picked,
/// in the order Claude wrote them, and the person's own words, which
/// take the place of a single choice. Nil until every question has an
/// answer.
static func answers(_ questions: [ClaudeQuestion], picked: [Int: Set<String>], typed: [Int: String]) -> [String: [String]]? {
guard !questions.isEmpty else { return nil }
var answers: [String: [String]] = [:]
for (index, question) in questions.enumerated() {
var chosen = question.options.map(\.label).filter { picked[index]?.contains($0) == true }
let own = clipped((typed[index] ?? "").trimmingCharacters(in: .whitespacesAndNewlines), utf16: ClaudeQuestion.ownAnswerLimit)
if !own.isEmpty { chosen = question.multiSelect ? chosen + [own] : [own] }
if !question.multiSelect { chosen = Array(chosen.prefix(1)) }
guard !chosen.isEmpty else { return nil }
answers[question.question] = chosen
}
return answers
}

/// The text cut to whole characters within a count of UTF-16 units, the
/// length Claude Code measures.
static func clipped(_ text: String, utf16 limit: Int) -> String {
guard text.utf16.count > limit else { return text }
var used = 0
var end = text.startIndex
for index in text.indices {
let size = text[index].utf16.count
guard used + size <= limit else { break }
used += size
end = text.index(after: index)
}
return String(text[..<end])
}

/// The reply as it goes to the terminal, or nil when nothing is left.
static func reply(_ text: String) -> String? {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down
13 changes: 9 additions & 4 deletions Sources/Vorssaint/Services/Notch/NotchService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,8 @@ final class NotchService: ObservableObject {
}

/// ⌘Y allows and ⌘N denies the permission of the session whose page is
/// open, or of the first session waiting on one.
/// open, or of the first session waiting on one. A question is answered
/// on its card; ⌘N skips it only there, where it can be read.
private func handleSessionKey(_ event: NSEvent) -> Bool {
guard selected == .sessions, !showingAppPanel, !showingSections, selectedMetric == nil,
let decision = NotchClaudeSessionsSupport.decision(
Expand All @@ -1884,8 +1885,9 @@ final class NotchService: ObservableObject {
else { return false }
let sessions = ClaudeSessionService.shared
let focused = sessions.focusedID.flatMap { id in sessions.sessions.first { $0.id == id } }
guard let target = focused ?? sessions.sessions.first(where: { $0.permission != nil }),
let permission = target.permission else { return false }
guard let target = focused ?? sessions.sessions.first(where: { $0.permission.map { !$0.asksQuestions } ?? false }),
let permission = target.permission,
!(permission.asksQuestions && decision != .deny) else { return false }
sessions.decide(target.id, request: permission.requestID, decision)
return true
}
Expand Down Expand Up @@ -4193,7 +4195,10 @@ final class NotchService: ObservableObject {
.joined(separator: " · "),
symbol: NotchClaudeSessionsSupport.symbol(.waitingPermission), agent: .claude, sessionID: id))
case .needsInput:
show(NotchNotice(event: .sessions, title: sessions.displayName(session), detail: text.inputNotice,
// A question Claude asks through the hooks is named in the notice.
let question = session.permission?.asksQuestions == true ? session.permission?.summary : nil
show(NotchNotice(event: .sessions, title: sessions.displayName(session),
detail: [text.inputNotice, question ?? ""].filter { !$0.isEmpty }.joined(separator: " · "),
symbol: NotchClaudeSessionsSupport.symbol(.waitingInput), agent: .claude, sessionID: id))
case .finished(_, let duration):
let locale = L10n.shared.language.formattingLocale()
Expand Down
Loading
Loading