diff --git a/Tests/StackNudgePanelCoreTests/MCPServerTests.swift b/Tests/StackNudgePanelCoreTests/MCPServerTests.swift index 6acb24a..de7dcba 100644 --- a/Tests/StackNudgePanelCoreTests/MCPServerTests.swift +++ b/Tests/StackNudgePanelCoreTests/MCPServerTests.swift @@ -501,6 +501,30 @@ final class MCPNudgeTests: XCTestCase { XCTAssertNil(MCPNudge.liveSession(for: fromDesktop, in: [session(pid: 10, claude: "s-10")])) } + // A client asked for the user's attention, so the nudge is spoken, or + // makes the user's own sound, even with banners off. + func testTheNudgeIsSpokenAsTheClient() { + let request = try! MCPNudge.request(from: ["title": "Migration finished"]).get() + let event = MCPNudge.event(request, caller: MCPCaller(clientName: "local-agent-mode-stack-nudge"), + session: nil, sound: "Glass") + XCTAssertEqual(event.agent, "Claude") + XCTAssertEqual(event.voiceMessage, "Claude: Migration finished") + XCTAssertEqual(event.soundName, "Glass") + } + + func testASettingsChangeLeavesOneLine() { + let setting = SettingSnapshot(key: "STACKNUDGE_THEME", label: "Accent color", category: "appearance", + value: .string("mint"), kindJSON: ["type": "string"], readOnlyReason: nil) + let row = MCPNudge.auditEvent(caller: MCPCaller(clientName: "claude-ai"), setting: setting) + XCTAssertEqual(row.title, "Claude set Accent color to mint") + XCTAssertEqual(row.message, "") + } + + func testClaudeDesktopIsNamedClaude() { + XCTAssertEqual(MCPCaller.friendlyName("local-agent-mode-stack-nudge"), "Claude") + XCTAssertEqual(MCPCaller.friendlyName("my-own-client"), "my-own-client") + } + // The hook socket may not claim to be MCP: an MCP nudge can take you to a // terminal or app, so only the server makes them. func testAScriptCantClaimToBeMCP() { diff --git a/panel/MCPAppContext.swift b/panel/MCPAppContext.swift index 65582a6..e7f81f8 100644 --- a/panel/MCPAppContext.swift +++ b/panel/MCPAppContext.swift @@ -58,7 +58,10 @@ final class MCPAppContext: MCPContext { func raiseNudge(_ request: MCPNudge.Request, caller: MCPCaller) { onMain { let session = MCPNudge.session(for: caller, in: sessionStore?.sessions ?? []) - store?.append(MCPNudge.event(request, caller: caller, session: session)) + // The sound an agent's own would make: waiting is a prompt's, the + // rest a finished turn's. + let sound = request.kind == .waiting ? nav?.soundPermission : nav?.soundStop + store?.append(MCPNudge.event(request, caller: caller, session: session, sound: sound)) } } diff --git a/panel/MCPNudge.swift b/panel/MCPNudge.swift index dd8095f..82467fd 100644 --- a/panel/MCPNudge.swift +++ b/panel/MCPNudge.swift @@ -85,13 +85,16 @@ enum MCPNudge { // The feed event: source mcp, so it can never be a permission prompt and // has its own cap in the queue. It carries what acting on it needs to take // you back: the session's pid and Claude session id, or the launching - // app's bundle id. - static func event(_ request: Request, caller: MCPCaller, session: Session?) -> NudgeEvent { + // app's bundle id. And what to say, since a client asked for the user's + // attention: with banners off, voice may be the only way they hear it. + // `sound` is the user's own, for when voice is off. + static func event(_ request: Request, caller: MCPCaller, session: Session?, sound: String? = nil) -> NudgeEvent { NudgeEvent(agent: caller.displayName, kind: .other, title: request.title, message: request.message, projectPath: session?.projectPath, bundleID: session == nil ? caller.parentBundleID : nil, agentPID: session?.pid, terminalApp: session?.terminalApp, + voiceMessage: "\(caller.displayName): \(request.title)", soundName: sound, claudeSessionID: session?.claudeSessionID ?? caller.claudeSessionID, source: .mcp, tag: request.tag ?? "mcp", severity: request.kind.severity, url: request.url) @@ -109,10 +112,12 @@ enum MCPNudge { return nil } - // The audit line a settings change leaves in Events. + // The audit line a settings change leaves in Events: one line, since the + // title says what changed and the row's MCP chip says how. Every change + // leaves one, so anything more is read over and over. static func auditEvent(caller: MCPCaller, setting: SettingSnapshot) -> NudgeEvent { NudgeEvent.feed(source: .mcp, tag: "settings", severity: .info, title: "\(caller.displayName) set \(setting.label) to \(SettingsRegistry.describe(setting.value))", - message: "Changed over MCP. Settings has the switch for this.") + message: "") } } diff --git a/panel/MCPProtocol.swift b/panel/MCPProtocol.swift index 04c67fb..17d0951 100644 --- a/panel/MCPProtocol.swift +++ b/panel/MCPProtocol.swift @@ -132,6 +132,8 @@ struct MCPCaller: Equatable { // Clients name themselves in code form ("claude-code"); a row reads better // with the product name. static func friendlyName(_ raw: String) -> String { + // Claude Desktop names itself after the server it's talking to. + if raw.lowercased().hasPrefix("local-agent-mode-") { return "Claude" } switch raw.lowercased() { case "claude-code", "claude code": return "Claude Code" case "claude-ai", "claude", "claude-desktop": return "Claude"