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
24 changes: 24 additions & 0 deletions Tests/StackNudgePanelCoreTests/MCPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion panel/MCPAppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
13 changes: 9 additions & 4 deletions panel/MCPNudge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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: "")
}
}
2 changes: 2 additions & 0 deletions panel/MCPProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading