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.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Fix coucou_agent routing: id prefix, collisions, approvals, label
Louis Raille46dfa6715a49
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 33d4f173..60f2332d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,4 +8,4 @@- The island always reopens after folding, and Settings opens below it, resizable — thanks @rouderz- Choose the Claude model for the chat in Settings; the list comes from your Anthropic account, and Claude Sonnet 4.6 stays the default — thanks @rouderz- Windows build artifacts are now downloadable from a manual CI run — thanks @MysJofR-- Any agent can talk to Mochi: tag a hook payload with `coucou_agent` (e.g. `nb-hook --agent gemini`) and it gets its own pill in the island (#7, #9) — thanks @lacatu5+- Any agent can talk to Mochi: tag a hook payload with `coucou_agent` (e.g. `nb-hook --agent my-agent`) and it gets its own pill in the island (#7, #9) — thanks @lacatu5diff --git a/NotchBuddy/Sources/App/HookServer.swift b/NotchBuddy/Sources/App/HookServer.swiftindex a1a4b323..89ab4a92 100644--- a/NotchBuddy/Sources/App/HookServer.swift+++ b/NotchBuddy/Sources/App/HookServer.swift@@ -170,7 +170,7 @@ final class HookServer: @unchecked Sendable {// Absent or invalid → Claude Code pill (integration_claude); no change in behaviour.let rawAgent = payload["coucou_agent"] as? String ?? ""let validAgent = Self.validateAgent(rawAgent)- let agentId = validAgent.map { "integration_\($0)" } ?? "integration_claude"+ let agentId = validAgent.map { "agent_\($0)" } ?? "integration_claude"let isExternalAgent = validAgent != nillet termProgram = payload["term_program"] as? String ?? ""@@ -283,9 +283,10 @@ final class HookServer: @unchecked Sendable {// MARK: - Agent validation + dynamic pill/// Validates a coucou_agent name: lowercase, digits and hyphens, 1–24 chars.+ /// "claude" is reserved and rejected so it cannot impersonate the Claude Code pill./// Returns the name unchanged if valid, nil otherwise.private static func validateAgent(_ raw: String) -> String? {- guard !raw.isEmpty, raw.count <= 24 else { return nil }+ guard !raw.isEmpty, raw.count <= 24, raw != "claude" else { return nil }for scalar in raw.unicodeScalars {let v = scalar.valuelet ok = (v >= 0x61 && v <= 0x7A) // a-z@@ -297,12 +298,13 @@ final class HookServer: @unchecked Sendable {}/// Creates a dynamic pill for a third-party agent on first event, then no-ops.+ /// ID format: "agent_<name>" — never collides with "integration_*" pills.@MainActorprivate func upsertExternalAgent(id: String, name: String) {let state = AppState.sharedguard state.tasks.firstIndex(where: { $0.id == id }) == nil else { return }let color = IslandConst.colorForProject(name)- let task = AgentTask(id: id, name: name, color: color, state: .idle, steps: [], source: .claudeCode)+ let task = AgentTask(id: id, name: name, color: color, state: .idle, steps: [], source: .agent)state.tasks.append(task)if state.focusId == nil { state.focusId = id }state.syncMode()@@ -341,6 +343,19 @@ final class HookServer: @unchecked Sendable {let rawName = URL(fileURLWithPath: cwd).lastPathComponentlet projectName = aliasProjectName(rawName.isEmpty ? "Session" : rawName)+ // External agents (coucou_agent) do not yet get an approval card — answering+ // would show a card that looks like a Claude Code request. Reply immediately+ // with no decision so the relay writes nothing and the agent re-asks in its+ // terminal. Approval support for other agents will come with Codex (n°20).+ let rawAgent = payload["coucou_agent"] as? String ?? ""+ if Self.validateAgent(rawAgent) != nil {+ Task.detached { [weak self] in+ self?.sendLine(fd: fd, text: #"{"permissionDecision":"ask"}"#)+ close(fd)+ }+ return+ }+let termProgram = payload["term_program"] as? String ?? ""let bundleId = payload["bundle_id"] as? String ?? ""let isVSCode = termProgram.lowercased().contains("vscode") ||diff --git a/NotchBuddy/Sources/App/IslandTypes.swift b/NotchBuddy/Sources/App/IslandTypes.swiftindex c2777a9a..e8483848 100644--- a/NotchBuddy/Sources/App/IslandTypes.swift+++ b/NotchBuddy/Sources/App/IslandTypes.swift@@ -60,6 +60,7 @@ struct AgentTask: Identifiable, Equatable {enum AgentSource: Equatable {case claudeCodecase n8n+ case agent // third-party agent via coucou_agent field}// MARK: - View dimensions (from VIEWS in prototype)diff --git a/NotchBuddy/Sources/App/IslandViewContent.swift b/NotchBuddy/Sources/App/IslandViewContent.swiftindex eca9a85b..778f1216 100644--- a/NotchBuddy/Sources/App/IslandViewContent.swift+++ b/NotchBuddy/Sources/App/IslandViewContent.swift@@ -59,7 +59,13 @@ struct OverviewView: View {.lineLimit(1).truncationMode(.tail).layoutPriority(1)- Text(agent.source == .claudeCode ? "Claude Code" : "n8n")+ Text({ () -> String in+ switch agent.source {+ case .claudeCode: return "Claude Code"+ case .agent: return "Agent"+ case .n8n: return "n8n"+ }+ }()).font(.system(size: 11)).foregroundColor(Color(hex: "#8E939C")).lineLimit(1)diff --git a/docs/AGENTS.md b/docs/AGENTS.mdindex 7e91792d..90c0822c 100644--- a/docs/AGENTS.md+++ b/docs/AGENTS.md@@ -58,7 +58,13 @@ Send newline-terminated JSON to the socket:## Supported events-All standard Claude Code hook events are supported. The pill lifecycle:+All standard Claude Code hook events are supported, **except `PermissionRequest`**:+approval cards are not yet implemented for third-party agents (only Claude Code gets+one). A `PermissionRequest` from an external agent is answered immediately with no+decision, so the relay writes nothing and the agent re-asks in its terminal.+Approval support for other agents will be added with Codex support (n°20).++The pill lifecycle:| Event | Effect ||---|---|diff --git a/windows/src/core/state.ts b/windows/src/core/state.tsindex e4988b8e..cc52fc11 100644--- a/windows/src/core/state.ts+++ b/windows/src/core/state.ts@@ -3,7 +3,7 @@import type { BotEmoteName, BotStateName, IslandMode, IslandViewName } from "./layout";import type { EyeShape } from "../mochi/engine";-export type AgentSource = "claudeCode" | "n8n";+export type AgentSource = "claudeCode" | "n8n" | "agent";export type PillBadge = "approval" | "finished" | "error";export interface AgentTask {@@ -209,12 +209,40 @@ class AppState {if (!shouldLoad && idx >= 0) this.tasks.splice(idx, 1);}// Keep the declared order so pills never shuffle.+ // Dynamic agent_ pills (coucou_agent) are not in the order list — sort them last.const order = INTEGRATION_AGENTS.map((t) => t.id);- this.tasks.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));+ this.tasks.sort((a, b) => {+ const ia = order.indexOf(a.id);+ const ib = order.indexOf(b.id);+ if (ia < 0 && ib < 0) return 0;+ if (ia < 0) return 1;+ if (ib < 0) return -1;+ return ia - ib;+ });if (!this.focusId) this.focusId = "integration_claude";this.notify();}+ removeTask(id: string) {+ const idx = this.tasks.findIndex((t) => t.id === id);+ if (idx < 0) return;+ this.tasks.splice(idx, 1);+ if (this.focusId === id) this.focusId = this.tasks[0]?.id ?? "integration_claude";+ this.notify();+ }++ /** Creates a dynamic agent_ pill on first event; no-ops if it already exists. */+ upsertExternalAgent(id: string, name: string, color: string) {+ if (this.tasks.some((t) => t.id === id)) return;+ this.tasks.push({+ id, name, color,+ state: "idle", stepIndex: 0, steps: [],+ source: "agent", isIntegration: false,+ });+ if (!this.focusId) this.focusId = id;+ this.notify();+ }+toggleIntegration(id: string) {if (id === "integration_claude") return;const active = this.settings.activeIntegrations;diff --git a/windows/src/island/hooks.ts b/windows/src/island/hooks.tsindex 547b1679..8e92bca3 100644--- a/windows/src/island/hooks.ts+++ b/windows/src/island/hooks.ts@@ -23,6 +23,25 @@ interface HookPayload {prompt?: string;tool_name?: string;tool_input?: Record<string, unknown>;+ /** Optional agent tag: lowercase, digits and hyphens, ≤ 24 chars. */+ coucou_agent?: string;+}++/** Same rule as HookServer.validateAgent on macOS. "claude" is reserved. */+function validateAgent(raw: string | undefined): string | null {+ if (!raw || raw.length > 24 || raw === "claude") return null;+ if (!/^[a-z0-9-]+$/.test(raw)) return null;+ return raw;+}++const FALLBACK_COLORS = ["#22C55E", "#EAB308", "#60A5FA", "#E879F9"];++function agentColor(name: string): string {+ let h = 0;+ for (let i = 0; i < name.length; i++) {+ h = (Math.imul(31, h) + name.charCodeAt(i)) | 0;+ }+ return FALLBACK_COLORS[Math.abs(h) % FALLBACK_COLORS.length];}const PROJECT_ALIASES: Record<string, string> = {@@ -123,9 +142,6 @@ export function registerHookHandlers(island: Island) {function handleHook(island: Island, payload: HookPayload) {if (State.paused) {- // Silence here used to cost Claude Code nearly two minutes: the relay waited- // for a decision from an island that had already decided not to look. Say so,- // and the terminal takes the question immediately.if (payload.request_id) void Bridge.approvalDecline(payload.request_id);return;}@@ -134,7 +150,14 @@ function handleHook(island: Island, payload: HookPayload) {const cwd = payload.cwd ?? "";const raw = lastPathComponent(cwd);const projectName = aliasProjectName(raw || "Session");- const focused = State.focusId === CLAUDE_ID;++ // Route to the right pill. Valid coucou_agent → dynamic "agent_<name>" pill.+ // "claude" is reserved; absent or invalid → Claude Code pill unchanged.+ const validAgent = validateAgent(payload.coucou_agent);+ const agentId = validAgent ? `agent_${validAgent}` : CLAUDE_ID;+ const isExternalAgent = validAgent !== null;++ const focused = State.focusId === agentId;/** Alerts force the island open; work events only reveal the compact island. */const surface = (view: Parameters<Island["alert"]>[0], isAlert: boolean) => {@@ -147,91 +170,113 @@ function handleHook(island: Island, payload: HookPayload) {}};+ /** Ensure the agent pill exists (no-op for Claude Code). */+ const ensurePill = () => {+ if (isExternalAgent) {+ State.upsertExternalAgent(agentId, validAgent!, agentColor(validAgent!));+ } else {+ upsert(projectName, cwd);+ }+ };+switch (name) {case "SessionStart":- upsert(projectName, cwd);+ ensurePill();surface("overview", false);Sound.play("work");break;case "UserPromptSubmit": {- upsert(projectName, cwd);- State.updateTask(CLAUDE_ID, "thinking");- // The field is `prompt`; reading `message` meant this step was always blank.+ ensurePill();+ State.updateTask(agentId, "thinking");const asked = payload.prompt ?? payload.message;- if (asked) State.appendStep(CLAUDE_ID, asked.slice(0, 60));+ if (asked) State.appendStep(agentId, asked.slice(0, 60));surface("overview", false);break;}case "PreToolUse": {- upsert(projectName, cwd);- State.updateTask(CLAUDE_ID, "working");+ ensurePill();+ State.updateTask(agentId, "working");const tool = payload.tool_name ?? "Tool";- State.appendStep(CLAUDE_ID, stepLabel(tool, payload.tool_input ?? {}));+ State.appendStep(agentId, stepLabel(tool, payload.tool_input ?? {}));surface("overview", false);break;}case "PostToolUse":- State.updateTask(CLAUDE_ID, "working");+ State.updateTask(agentId, "working");break;case "PostToolUseFailure":- State.updateTask(CLAUDE_ID, "working");- State.appendStep(CLAUDE_ID, "⚠ failed");+ State.updateTask(agentId, "working");+ State.appendStep(agentId, "⚠ failed");break;case "Notification": {const message = payload.message ?? "";const lower = message.toLowerCase();if (lower.includes("rate limit") || lower.includes("limite d")) {- State.updateTask(CLAUDE_ID, "ratelimit");+ State.updateTask(agentId, "ratelimit");Sound.play("rate");} else if (message.endsWith("?")) {- State.updateTask(CLAUDE_ID, "question");- State.appendStep(CLAUDE_ID, message);+ State.updateTask(agentId, "question");+ State.appendStep(agentId, message);}break;}case "Stop":- State.updateTask(CLAUDE_ID, "finished");- if (payload.message) State.appendStep(CLAUDE_ID, payload.message.slice(0, 60));+ State.updateTask(agentId, "finished");+ if (payload.message) State.appendStep(agentId, payload.message.slice(0, 60));Sound.play("finish");if (focused) surface("finished", true);- else State.setPillBadge(CLAUDE_ID, "finished");+ else State.setPillBadge(agentId, "finished");window.setTimeout(() => {- State.updateTask(CLAUDE_ID, "idle");- State.setPillBadge(CLAUDE_ID, null);+ if (isExternalAgent) {+ State.removeTask(agentId);+ } else {+ State.updateTask(agentId, "idle");+ State.setPillBadge(agentId, null);+ }}, 5200);break;case "StopFailure":- State.updateTask(CLAUDE_ID, "error");+ State.updateTask(agentId, "error");Sound.play("error");if (focused) surface("error", true);- else State.setPillBadge(CLAUDE_ID, "error");+ else State.setPillBadge(agentId, "error");break;case "SessionEnd":- State.updateTask(CLAUDE_ID, "idle");- clearSession();+ if (isExternalAgent) {+ State.removeTask(agentId);+ } else {+ State.updateTask(agentId, "idle");+ clearSession();+ }break;case "SubagentStart":- State.appendStep(CLAUDE_ID, "+ subagent");+ State.appendStep(agentId, "+ subagent");break;case "SubagentStop":- State.appendStep(CLAUDE_ID, "• subagent done");+ State.appendStep(agentId, "• subagent done");break;case "PermissionRequest": {+ // External agents do not get an approval card — showing one would look like+ // a Claude Code request. Decline immediately so the agent re-asks in its+ // terminal. Approval support for other agents will come with Codex (n°20).+ if (isExternalAgent) {+ if (payload.request_id) void Bridge.approvalDecline(payload.request_id);+ break;+ }+const requestId = payload.request_id ?? "";- // One card, one request. A second one must never quietly replace the first- // — that would leave a human staring at request B while request A waits for- // a decision nobody can give. Hand it straight back to the terminal.+ // One card, one request. A second one must never quietly replace the first.if (State.pendingApproval && State.pendingApproval.requestId !== requestId) {if (requestId) void Bridge.approvalDecline(requestId);break;@@ -246,8 +291,6 @@ function handleHook(island: Island, payload: HookPayload) {tool,command: approvalTarget(tool, input),};- // The relay's short ack window closes in 800 ms; everything below this- // line is synchronous, so the card really is up by the time it lands.if (requestId) void Bridge.approvalAck(requestId);State.updateTask(CLAUDE_ID, "approval");State.isPinned = true;@@ -255,14 +298,9 @@ function handleHook(island: Island, payload: HookPayload) {if (focused) {island.alert("approval");} else {- // Another agent holds the view, so the card would yank it away. The badge- // is the signal instead — but it has to be on screen for that to mean- // anything, hence the reveal. We just told the relay a human can act.State.setPillBadge(CLAUDE_ID, "approval");island.reveal();}- // Coucou answers within 108 s or not at all; after that the terminal has- // taken over and the card would be lying.pendingTimeout = window.setTimeout(() => {pendingTimeout = null;if (!State.pendingApproval) return;