Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

A pill can stand for its client: AgentTask.pill and PillCatalog.basePillId

NikitaBulichev7ef170cf1905
diff --git a/NotchBuddy/Sources/App/HookServer.swift b/NotchBuddy/Sources/App/HookServer.swift
index 8798114d..52e25c49 100644
--- a/NotchBuddy/Sources/App/HookServer.swift
+++ b/NotchBuddy/Sources/App/HookServer.swift
@@ -70,26 +70,26 @@ final class HookServer: @unchecked Sendable {
/// Note shown when a request was answered outside Coucou.
@MainActor
private func handledNote(pill: String) -> String {
- switch pill {
+ switch PillCatalog.basePillId(pill) {
case "agent_cursor": return "Handled in Cursor."
case "agent_codex": return "Handled in Codex."
case "agent_copilot": return "Handled in Copilot CLI."
case "agent_muse": return "Handled in Muse Code."
case "agent_hermes": return "Handled in Hermes."
- default: return "Handled in \(claudeHostName)."
+ default: return "Handled in \(claudeHostName(pill: pill))."
}
}
/// Note shown when a request waited too long and went back to the agent.
@MainActor
private func waitingNote(pill: String) -> String {
- switch pill {
+ switch PillCatalog.basePillId(pill) {
case "agent_cursor": return "Still waiting in Cursor."
case "agent_codex": return "Still waiting in Codex."
case "agent_copilot": return "Still waiting in Copilot CLI."
case "agent_muse": return "Still waiting in Muse Code."
case "agent_hermes": return "Still waiting in Hermes."
- default: return "Still waiting in \(claudeHostName)."
+ default: return "Still waiting in \(claudeHostName(pill: pill))."
}
}
@@ -1142,10 +1142,10 @@ final class HookServer: @unchecked Sendable {
showQuestionHead()
}
- /// "VS Code", "Warp"… — where the Claude Code pill's current session runs.
+ /// "VS Code", "Warp"… — where the session behind a Claude Code pill runs.
@MainActor
- private var claudeHostName: String {
- ClaudeHost.name(for: AppState.shared.tasks.first { $0.id == "integration_claude" }?.hostApp)
+ private func claudeHostName(pill: String) -> String {
+ ClaudeHost.name(for: AppState.shared.tasks.first { $0.id == pill }?.hostApp)
}
/// Records the session an event came from, then refreshes its card.
@@ -1174,13 +1174,14 @@ final class HookServer: @unchecked Sendable {
let state = AppState.shared
state.tasks[idx].name = owner.projectName
if !owner.cwd.isEmpty { state.tasks[idx].sessionCwd = owner.cwd }
- if pill == "integration_claude" { state.tasks[idx].hostApp = owner.hostApp }
+ if PillCatalog.basePillId(pill) == "integration_claude" { state.tasks[idx].hostApp = owner.hostApp }
if !owner.bundleId.isEmpty { state.tasks[idx].sessionBundleId = owner.bundleId }
}
- /// Updates or transiently creates a workspace pill (VS Code or Cursor) task.
- /// If the task already exists (persistent), just updates name/cwd.
- /// If missing (transient), creates it and inserts after the main pill.
+ /// Updates or transiently creates a workspace pill (VS Code or Cursor) task, or a session's
+ /// own pill. If the task already exists (persistent), just updates name/cwd.
+ /// If missing (transient), creates it and inserts after the main pill (a session's own
+ /// pill: after its client's).
/// Name, cwd and terminal belong to the session that owns the pill (the oldest one
/// still running), so a second session under the same client cannot rename the card,
/// or send "Open terminal" elsewhere, out from under the first.
@@ -1191,7 +1192,7 @@ final class HookServer: @unchecked Sendable {
guard sessions.ownsDisplay(pill: id, session: session) else { return }
state.tasks[idx].name = projectName
if !cwd.isEmpty { state.tasks[idx].sessionCwd = cwd }
- if id == "integration_claude" { state.tasks[idx].hostApp = hostApp }
+ if PillCatalog.basePillId(id) == "integration_claude" { state.tasks[idx].hostApp = hostApp }
if !bundleId.isEmpty { state.tasks[idx].sessionBundleId = bundleId }
return
}
@@ -1201,9 +1202,12 @@ final class HookServer: @unchecked Sendable {
let source = def?.source ?? .agent
var task = AgentTask(id: id, name: projectName, color: color,
state: .idle, steps: [], source: source, isIntegration: true)
- if id == "integration_claude" { task.hostApp = hostApp }
+ if task.pill == "integration_claude" { task.hostApp = hostApp }
if !bundleId.isEmpty { task.sessionBundleId = bundleId }
- if let mainIdx = state.tasks.firstIndex(where: { $0.id == state.mainPillId }) {
+ // A session's own pill goes after its client's other pills, so they stay together.
+ if let sibling = state.tasks.lastIndex(where: { $0.pill == task.pill }) {
+ state.tasks.insert(task, at: sibling + 1)
+ } else if let mainIdx = state.tasks.firstIndex(where: { $0.id == state.mainPillId }) {
state.tasks.insert(task, at: mainIdx + 1)
} else {
state.tasks.insert(task, at: 0)
diff --git a/NotchBuddy/Sources/App/IslandViewContent.swift b/NotchBuddy/Sources/App/IslandViewContent.swift
index 40e44219..3d6120d2 100644
--- a/NotchBuddy/Sources/App/IslandViewContent.swift
+++ b/NotchBuddy/Sources/App/IslandViewContent.swift
@@ -222,7 +222,7 @@ struct OverviewView: View {
private func openAgentTarget(_ task: AgentTask?) {
guard let task else { return }
- switch task.id {
+ switch task.pill {
case "integration_claude":
if ClaudeHost.activate(task.hostApp) { return }
let vscodeBundleId = "com.microsoft.VSCode"
@@ -401,9 +401,10 @@ struct ApprovalView: View {
HookServer.shared.sendApprovalDecision("allow", for: shownId)
}
// Codex, Copilot CLI and Muse Code do not support updatedPermissions
- let hideAlways = approval?.pillId == "agent_codex"
- || approval?.pillId == "agent_copilot"
- || approval?.pillId == "agent_muse"
+ let asking = PillCatalog.basePillId(approval?.pillId ?? "")
+ let hideAlways = asking == "agent_codex"
+ || asking == "agent_copilot"
+ || asking == "agent_muse"
if !hideAlways {
SecondaryButton("Always") {
HookServer.shared.sendApprovalDecision("always", for: shownId)
@@ -711,7 +712,7 @@ struct ErrorView: View {
NotificationCenter.default.post(name: .islandCollapse, object: nil)
}
}
- } else if task?.id == "agent_claude-desktop" {
+ } else if task?.pill == "agent_claude-desktop" {
PrimaryButton("Open Claude") {
openClaudeDesktopApp()
NotificationCenter.default.post(name: .islandCollapse, object: nil)
@@ -740,7 +741,7 @@ struct ErrorView: View {
#if !APPSTORE
/// The app a session runs in (its terminal, or VS Code), else any known terminal.
private func openSessionApp(_ task: AgentTask?) {
- if !(task?.id == "integration_claude" && ClaudeHost.activate(task?.hostApp)),
+ if !(task?.pill == "integration_claude" && ClaudeHost.activate(task?.hostApp)),
!TerminalTarget.activate(sessionBundleId: task?.sessionBundleId) {
NSWorkspace.shared.open(URL(fileURLWithPath: "/System/Applications/Utilities/Terminal.app"))
}
@@ -775,7 +776,7 @@ struct FinishedView: View {
.lineLimit(1)
.truncationMode(.tail)
HStack(spacing: 8) {
- if state.focusTask?.id == "agent_claude-desktop" {
+ if state.focusTask?.pill == "agent_claude-desktop" {
// Sessions from the Claude desktop app live there, not in a terminal.
PrimaryButton("Open Claude") {
openClaudeDesktopApp()
@@ -1917,7 +1918,7 @@ struct IntegrationCardView: View {
#endif
private var isConfigured: Bool {
- switch task.id {
+ switch task.pill {
// Cursor sessions are Claude Code running in Cursor's integrated terminal,
// so the Cursor pill is set up exactly when the Claude Code hooks are.
case "integration_claude", "agent_cursor":
@@ -2011,7 +2012,7 @@ struct IntegrationCardView: View {
}
private var openURL: URL? {
- switch task.id {
+ switch task.pill {
case "integration_claude": return nil // uses terminal button below
case "integration_resend": return URL(string: "https://resend.com/emails")
case "integration_n8n":
@@ -2148,16 +2149,16 @@ struct IntegrationCardView: View {
// Pills driven by hooks, never by a key: the idle card reports whether the
// hooks are in place. integration_claude read "Connected · loading…" with
// nothing left to load — a session replaces this card, it never resolves here.
- let isHooks = task.id == "integration_claude" || task.id == "agent_gemini"
- || task.id == "agent_antigravity" || task.id == "agent_cursor"
- || task.id == "agent_codex" || task.id == "agent_copilot"
- || task.id == "agent_muse" || task.id == "agent_opencode"
- || task.id == "agent_amp" || task.id == "agent_hermes"
+ let isHooks = task.pill == "integration_claude" || task.pill == "agent_gemini"
+ || task.pill == "agent_antigravity" || task.pill == "agent_cursor"
+ || task.pill == "agent_codex" || task.pill == "agent_copilot"
+ || task.pill == "agent_muse" || task.pill == "agent_opencode"
+ || task.pill == "agent_amp" || task.pill == "agent_hermes"
let isAI = ChatProvider(pillID: task.id) != nil
if isConfigured {
if isHooks { return String(localized: "Hooks installed") }
// No key or poller behind this pill: it only reflects hook events.
- if task.id == "agent_claude-desktop" { return String(localized: "Ready · no setup needed") }
+ if task.pill == "agent_claude-desktop" { return String(localized: "Ready · no setup needed") }
if isAI {
let provider = ChatProvider(pillID: task.id)!
if provider.isLocal {
@@ -2308,7 +2309,7 @@ struct IntegrationCardView: View {
Circle()
.fill(Color(hex: task.color))
.frame(width: 7, height: 7)
- Text(task.id == "integration_claude" ? ClaudeHost.pillName(hostApp: task.hostApp)
+ Text(task.pill == "integration_claude" ? ClaudeHost.pillName(hostApp: task.hostApp)
: PillCatalog.definition(for: task.id)?.name ?? task.name)
.font(.system(size: 12, weight: .semibold))
.foregroundColor(Color(hex: "#F5F6F8"))
@@ -2331,17 +2332,17 @@ struct IntegrationCardView: View {
.padding(.top, 2)
HStack(spacing: 8) {
- if task.id == "integration_claude", task.hostApp != nil {
+ if task.pill == "integration_claude", task.hostApp != nil {
Button("Open \(ClaudeHost.name(for: task.hostApp))") { ClaudeHost.activate(task.hostApp) }
.font(.system(size: 11, weight: .medium))
.foregroundColor(Color(hex: task.color).opacity(0.7))
.buttonStyle(.plain)
- } else if task.id == "integration_claude" {
+ } else if task.pill == "integration_claude" {
Button("Open Visual Studio Code") { openVSCode() }
.font(.system(size: 11, weight: .medium))
.foregroundColor(Color(hex: task.color).opacity(0.7))
.buttonStyle(.plain)
- } else if task.id == "agent_cursor" {
+ } else if task.pill == "agent_cursor" {
#if !APPSTORE
if let url = NSWorkspace.shared.urlForApplication(
withBundleIdentifier: "com.todesktop.230313mzl4w4u92") {
@@ -2354,7 +2355,7 @@ struct IntegrationCardView: View {
.buttonStyle(.plain)
}
#endif
- } else if task.id == "agent_codex" {
+ } else if task.pill == "agent_codex" {
#if !APPSTORE
if let url = NSWorkspace.shared.urlForApplication(
withBundleIdentifier: "com.openai.codex") {
@@ -2445,8 +2446,8 @@ struct IntegrationCardView: View {
}
// Settings button: shown when not configured, except cursor/codex and music
if !isConfigured
- && task.id != "agent_cursor"
- && task.id != "agent_codex"
+ && task.pill != "agent_cursor"
+ && task.pill != "agent_codex"
&& task.id != "integration_music"
&& task.id != "integration_mail" {
Button("Settings…") {
diff --git a/NotchBuddy/Sources/App/PhoneLink/InstructionRunner.swift b/NotchBuddy/Sources/App/PhoneLink/InstructionRunner.swift
index 0f8fd7a8..6cfdebce 100644
--- a/NotchBuddy/Sources/App/PhoneLink/InstructionRunner.swift
+++ b/NotchBuddy/Sources/App/PhoneLink/InstructionRunner.swift
@@ -116,7 +116,9 @@ final class InstructionRunner {
guard Self.isEnabled else { log("ignored: instructions are off"); return }
guard Date().timeIntervalSince(createdAt) < maxAge else { log("ignored: older than 10 min"); return }
guard !text.isEmpty, text.count <= 8000 else { log("ignored: empty or too long"); return }
- guard pillId == "integration_claude" || pillId == "agent_cursor" else { log("ignored: \(pillId) can't take instructions"); return }
+ // A session's own pill ("integration_claude#2") resumes that very session.
+ let client = PillCatalog.basePillId(pillId)
+ guard client == "integration_claude" || client == "agent_cursor" else { log("ignored: \(pillId) can't take instructions"); return }
guard let session = TurnRecorder.shared.lastSession(for: pillId) else {
log("ignored: no Claude Code session seen for \(pillId) yet")
return
@@ -149,7 +151,7 @@ final class InstructionRunner {
env["PATH"] = [URL(fileURLWithPath: claude).deletingLastPathComponent().path, "/opt/homebrew/bin", "/usr/local/bin",
"/usr/bin", "/bin", "/usr/sbin", "/sbin", "\(home)/.local/bin", env["PATH"] ?? ""].joined(separator: ":")
// The hooks route events by editor: keep them on the same pill.
- if pillId == "agent_cursor" {
+ if PillCatalog.basePillId(pillId) == "agent_cursor" {
env["__CFBundleIdentifier"] = "com.todesktop.230313mzl4w4u92"
} else {
env["TERM_PROGRAM"] = "vscode"
diff --git a/NotchBuddy/Sources/App/PhoneLink/SessionPublisher.swift b/NotchBuddy/Sources/App/PhoneLink/SessionPublisher.swift
index 7dc324e4..75271eb9 100644
--- a/NotchBuddy/Sources/App/PhoneLink/SessionPublisher.swift
+++ b/NotchBuddy/Sources/App/PhoneLink/SessionPublisher.swift
@@ -174,6 +174,8 @@ struct SessionSnapshot: Equatable {
/// The question's choices (QuestionPayload JSON) and its fingerprint, for answering from the iPhone.
var questionPayload: String = ""
var questionFingerprint: String = ""
+ /// False for a question's own record ("<pill>#q2"): it is not a session to send work to.
+ var takesInstructions = true
static func all(tasks: [AgentTask], approval: ApprovalInfo?,
questions: [QueuedQuestion]) -> [String: SessionSnapshot] {
@@ -203,7 +205,7 @@ struct SessionSnapshot: Equatable {
questionPayload: payload?.json ?? "",
questionFingerprint: payload?.fingerprint ?? "")
// Questions from other sessions behind the same pill get a record of their own
- // ("<pill>#2"…), so each one shows up and is answered on its own.
+ // ("<pill>#q2"…), so each one shows up and is answered on its own.
for entry in questions where entry.pillId == task.id && entry.slot > 1 {
let payload = QuestionPayload(ask: entry.question)
result[entry.phoneRecordId] = SessionSnapshot(
@@ -220,7 +222,8 @@ struct SessionSnapshot: Equatable {
approvalFingerprint: "",
question: entry.question.questions.map(\.question).joined(separator: "\n"),
questionPayload: payload.json,
- questionFingerprint: payload.fingerprint)
+ questionFingerprint: payload.fingerprint,
+ takesInstructions: false)
}
}
return result
@@ -264,7 +267,9 @@ struct SessionSnapshot: Equatable {
#if APPSTORE
record["acceptsInstructions"] = false
#else
- record["acceptsInstructions"] = InstructionRunner.isEnabled && (pillId == "integration_claude" || pillId == "agent_cursor")
+ let client = PillCatalog.basePillId(pillId)
+ record["acceptsInstructions"] = InstructionRunner.isEnabled && takesInstructions
+ && (client == "integration_claude" || client == "agent_cursor")
#endif
record.encryptedValues["name"] = name
record.encryptedValues["steps"] = steps
diff --git a/NotchBuddy/Sources/App/QuestionQueue.swift b/NotchBuddy/Sources/App/QuestionQueue.swift
index 3d09fbfc..a1201cb5 100644
--- a/NotchBuddy/Sources/App/QuestionQueue.swift
+++ b/NotchBuddy/Sources/App/QuestionQueue.swift
@@ -24,9 +24,10 @@ struct QueuedQuestion: Equatable, Sendable {
var received = Date()
/// The iPhone record that shows this question: the pill's own for the first question
- /// behind a pill, "<pill>#<slot>" for the others, so each session's question is answered
- /// on its own. The iPhone sends this id back with its answer.
- var phoneRecordId: String { slot == 1 ? pillId : "\(pillId)#\(slot)" }
+ /// behind a pill, "<pill>#q<slot>" for the others, so each session's question is answered
+ /// on its own (a session's own pill is "<pill>#<n>": the two never meet). The iPhone sends
+ /// this id back with its answer.
+ var phoneRecordId: String { slot == 1 ? pillId : "\(pillId)#q\(slot)" }
}
struct QuestionQueue: Sendable {
diff --git a/NotchBuddy/Sources/App/RecapStore.swift b/NotchBuddy/Sources/App/RecapStore.swift
index 6884f43d..e3dfc053 100644
--- a/NotchBuddy/Sources/App/RecapStore.swift
+++ b/NotchBuddy/Sources/App/RecapStore.swift
@@ -179,9 +179,9 @@ final class RecapStore {
let allowed = decisions.filter { $0.decision == "allow" || $0.decision == "always" }.count
let denied = decisions.filter { $0.decision == "deny" }.count
- // Top agent by session count
+ // Top agent by session count (a session's own pill counts for its client)
var countByAgent: [String: Int] = [:]
- for t in turns { countByAgent[t.pillId, default: 0] += 1 }
+ for t in turns { countByAgent[PillCatalog.basePillId(t.pillId), default: 0] += 1 }
let topAgentId = countByAgent.max { $0.value < $1.value }?.key
let topAgent = topAgentId.flatMap { PillCatalog.definition(for: $0)?.name } ?? topAgentId
diff --git a/NotchBuddy/Sources/CoucouKit/IslandTypes.swift b/NotchBuddy/Sources/CoucouKit/IslandTypes.swift
index 20187cce..04124796 100644
--- a/NotchBuddy/Sources/CoucouKit/IslandTypes.swift
+++ b/NotchBuddy/Sources/CoucouKit/IslandTypes.swift
@@ -84,6 +84,10 @@ struct AgentTask: Identifiable, Equatable {
var sessionBundleId: String? = nil // app the session runs in (hook bundle_id), for "Open terminal"
var finalLine: String? = nil // last assistant message shown as static text after Stop
var hostApp: String? = nil // bundle id of the terminal running a Claude Code session; nil = VS Code
+
+ /// The client pill this task belongs to: its id, or for a session's own pill
+ /// ("integration_claude#2") the pill of its client. Compare this, not `id`, to a pill ID.
+ var pill: String { PillCatalog.basePillId(id) }
}
enum AgentSource: Equatable {
diff --git a/NotchBuddy/Sources/CoucouKit/PillCatalog.swift b/NotchBuddy/Sources/CoucouKit/PillCatalog.swift
index bc92f8cf..d76327d8 100644
--- a/NotchBuddy/Sources/CoucouKit/PillCatalog.swift
+++ b/NotchBuddy/Sources/CoucouKit/PillCatalog.swift
@@ -146,11 +146,17 @@ enum PillCatalog {
/// Default ID for the always-on main workspace pill.
static let defaultMainPillId = "integration_claude"
- /// Looks up a definition by task ID (nil if not in catalog). The iPhone record of a second
- /// question behind a pill ("integration_claude#2", QueuedQuestion.phoneRecordId) reads as
- /// that pill; pill IDs themselves never contain "#".
+ /// The catalog pill an ID stands for. A second session's own pill ("integration_claude#2",
+ /// SessionPillMap) and the iPhone record of a second question behind a pill
+ /// ("integration_claude#q2", QueuedQuestion.phoneRecordId) read as that pill; pill IDs
+ /// themselves never contain "#".
+ static func basePillId(_ id: String) -> String {
+ id.firstIndex(of: "#").map { String(id[..<$0]) } ?? id
+ }
+
+ /// Looks up a definition by task ID (nil if not in catalog), see `basePillId`.
static func definition(for id: String) -> PillDefinition? {
- let pill = id.firstIndex(of: "#").map { String(id[..<$0]) } ?? id
+ let pill = basePillId(id)
return all.first { $0.id == pill }
}
}
diff --git a/NotchBuddy/Sources/Phone/SessionDetailView.swift b/NotchBuddy/Sources/Phone/SessionDetailView.swift
index 913ad21e..fc0be423 100644
--- a/NotchBuddy/Sources/Phone/SessionDetailView.swift
+++ b/NotchBuddy/Sources/Phone/SessionDetailView.swift
@@ -82,7 +82,8 @@ struct SessionDetailView: View {
}
// The composer stays at the bottom, like a chat.
.safeAreaInset(edge: .bottom) {
- if let session, session.id == "integration_claude" || session.id == "agent_cursor" {
+ // A session's own pill ("integration_claude#2") takes instructions like its client's.
+ if let session, ["integration_claude", "agent_cursor"].contains(PillCatalog.basePillId(session.id)) {
InstructionComposer(link: link, session: session)
}
}
diff --git a/tests/QuestionQueueTests.swift b/tests/QuestionQueueTests.swift
index bed00fe0..17055cd1 100644
--- a/tests/QuestionQueueTests.swift
+++ b/tests/QuestionQueueTests.swift
@@ -29,7 +29,7 @@ enum QuestionQueueTests {
// Slots: the pill's own iPhone record first, then one record per extra question
precondition(q.entries.map(\.slot) == [1, 2])
- precondition(q.entries.map(\.phoneRecordId) == ["integration_claude", "integration_claude#2"])
+ precondition(q.entries.map(\.phoneRecordId) == ["integration_claude", "integration_claude#q2"])
// Another pill counts its own slots
let c = entry(3, session: "s3", pill: "agent_codex")
@@ -89,14 +89,14 @@ enum QuestionQueueTests {
QuestionQueue.question(answering: fingerprint, onRecord: record, in: same.entries, fingerprintOf: fp)?.id
}
precondition(answered("Same?", "integration_claude") == s1.id)
- precondition(answered("Same?", "integration_claude#2") == s2.id)
+ precondition(answered("Same?", "integration_claude#q2") == s2.id)
precondition(answered("Other?", "agent_codex") == other.id)
precondition(answered("Same?", "") == s1.id) // no record named: the oldest
precondition(answered("Same?", "agent_codex") == nil) // not the question on that record
precondition(answered("Gone?", "integration_claude") == nil)
_ = same.remove(id: s1.id)
precondition(answered("Same?", "integration_claude") == nil) // answered already
- precondition(answered("Same?", "integration_claude#2") == s2.id)
+ precondition(answered("Same?", "integration_claude#q2") == s2.id)
print("QuestionQueue tests: all passed")
}