Skip to content

Commit d6b2417

Browse files
committed
Build an isolated local Agent preview for macOS 14
1 parent 22be8b1 commit d6b2417

23 files changed

Lines changed: 372 additions & 108 deletions

‎Helpers/AgentCatalogMCP.swift‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
static let maxProofs = AgentLimits.proofCount
1313
// Derive the peer pin from this trusted bundled executable, never the socket.
1414
static let pin = AgentPeerSigning.ownLeaf()
15-
static let directory = "/private/tmp/codebasic-tts-mcp-\(getuid())"
15+
static let directory = TTSRuntime.socketDirectory
1616

1717
struct Proof {
1818
let profile: String
@@ -47,9 +47,9 @@ import Foundation
4747
initialized = true
4848
let requested = params["protocolVersion"] as? String ?? ""
4949
let version = ["2025-11-25", "2025-06-18", "2025-03-26"].contains(requested) ? requested : "2025-11-25"
50-
result(id, ["protocolVersion":version, "serverInfo":["name":"codebasic-tts-agent", "version":"2.0"],
50+
result(id, ["protocolVersion":version, "serverInfo":["name":TTSRuntime.mcpServerName, "version":"2.0"],
5151
"capabilities":["tools":["listChanged":false]],
52-
"instructions":"Open Codebasic TTS → Agent (에이전트), then enable the session. With no instruction selected, use submit_tts_draft without reading anything. If an instruction is selected, read it and use submit_explanation_draft. Incoming drafts open for editing without playback."])
52+
"instructions":"Open \(TTSRuntime.displayName) → Agent (에이전트), then enable the session. With no instruction selected, use submit_tts_draft without reading anything. If an instruction is selected, read it and use submit_explanation_draft. Incoming drafts open for editing without playback."])
5353
case "ping":
5454
result(id, [:])
5555
case "tools/list" where ready:
@@ -83,7 +83,7 @@ import Foundation
8383
let rev = reply["revision"] as? String, UUID(uuidString: rev) != nil,
8484
let hash = reply["body_sha256"] as? String, hash == AgentBytes.hash(Data(text.utf8)),
8585
let opaque = reply["proof"] as? String, UUID(uuidString: opaque) != nil else {
86-
tool(id, "That profile is not approved or its revision changed. Select it in Codebasic TTS → Agent (에이전트).", failed: true); continue
86+
tool(id, "That profile is not approved or its revision changed. Select it in \(TTSRuntime.displayName) → Agent (에이전트).", failed: true); continue
8787
}
8888
let proof = Proof(profile: selector, revision: rev, bodyHash: hash, token: opaque,
8989
expiry: .now.advanced(by: .seconds(AgentLimits.grantSeconds)))
@@ -116,7 +116,7 @@ import Foundation
116116
let connection = pairingStatus()
117117
guard connection == "ready" || connection == "receiving_only" || connection == "instruction_required" else {
118118
let message = connection == "reading_only"
119-
? "Draft receipt is not approved. Select an instruction in Codebasic TTS → Agent (에이전트)."
119+
? "Draft receipt is not approved. Select an instruction in \(TTSRuntime.displayName) → Agent (에이전트)."
120120
: describe(connection)
121121
tool(id, message, failed: true); continue
122122
}
@@ -189,15 +189,15 @@ import Foundation
189189

190190
static func describe(_ status: String) -> String {
191191
switch status {
192-
case "signing_required": return "Use the certificate-signed helper bundled with Codebasic TTS."
193-
case "app_unavailable": return "Open Codebasic TTS and try again. The running app must match this signed helper."
194-
case "other_agent": return "Another MCP session is connected. Close it or disconnect it in Codebasic TTS → Agent (에이전트), then retry."
195-
case "approval_required": return "Connected. In Codebasic TTS → Agent (에이전트), enable draft receipt."
192+
case "signing_required": return "Use the certificate-signed helper bundled with \(TTSRuntime.displayName)."
193+
case "app_unavailable": return "Open \(TTSRuntime.displayName) and try again. The running app must match this signed helper."
194+
case "other_agent": return "Another MCP session is connected. Close it or disconnect it in \(TTSRuntime.displayName) → Agent (에이전트), then retry."
195+
case "approval_required": return "Connected. In \(TTSRuntime.displayName) → Agent (에이전트), enable draft receipt."
196196
case "reading_only": return "Connected. One instruction revision is approved. Draft receipt is off."
197197
case "receiving_only": return "Connected. Send with submit_tts_draft; there is no selected instruction."
198198
case "instruction_required": return "A saved instruction was selected but is no longer shareable. Ask the user to update or clear the selection."
199199
case "ready": return "Connected. Read the selected saved instruction and submit with submit_explanation_draft. Nothing plays automatically."
200-
default: return "Connection not confirmed. Check Codebasic TTS → Agent (에이전트) and try again."
200+
default: return "Connection not confirmed. Check \(TTSRuntime.displayName) → Agent (에이전트) and try again."
201201
}
202202
}
203203

‎Sources/App/AgentPeerSigning.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import Foundation
44
import Security
55

66
enum AgentPeerSigning {
7-
static let appID = "com.seongjoo.SelectedTextTTS"
8-
static let helperID = "com.seongjoo.SelectedTextTTS.agent-helper"
7+
static let appID = TTSRuntime.appID
8+
static let helperID = TTSRuntime.helperID
99

1010
static func ownLeaf() -> String? {
1111
var code: SecCode?

‎Sources/App/AntigravityPlan.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ enum AntigravityPlan {
99
.first { FileManager.default.isExecutableFile(atPath: $0) }.map(URL.init(fileURLWithPath:))
1010
}
1111
static var home: URL {
12-
FileManager.default.homeDirectoryForCurrentUser
13-
.appendingPathComponent("Library/Application Support/Codebasic TTS/antigravity-plan")
12+
URL(fileURLWithPath: Secrets.appSupportDir, isDirectory: true)
13+
.appendingPathComponent("antigravity-plan", isDirectory: true)
1414
}
1515
static func environment(home: URL) -> [String: String] {
1616
["HOME": home.path,
@@ -32,6 +32,7 @@ enum AntigravityPlan {
3232
try JSONSerialization.data(withJSONObject: settings).write(to: config.appendingPathComponent("settings.json"), options: .atomic)
3333
}
3434
@MainActor static func login() throws {
35+
guard !TTSRuntime.isPreview else { throw connectionError("프리뷰에서는 Google 계정 연결을 사용할 수 없습니다.") }
3536
guard let executable else { throw connectionError("Antigravity CLI를 설치한 뒤 다시 시도하세요.") }
3637
try prepare(home: home)
3738
let script = home.appendingPathComponent("Google 로그인.command")
@@ -44,6 +45,7 @@ enum AntigravityPlan {
4445
}
4546
@MainActor static func run(arguments: [String], input: Data = Data(), executable: URL? = AntigravityPlan.executable,
4647
home: URL = AntigravityPlan.home, timeout: TimeInterval = 180, onOutput: ((Data) throws -> Void)? = nil) async throws -> (Data, Int32) {
48+
guard !TTSRuntime.isPreview else { throw connectionError("프리뷰에서는 Google 계정 연결을 사용할 수 없습니다.") }
4749
guard let executable else { throw connectionError("Antigravity CLI(agy) 설치가 필요합니다.") }
4850
try prepare(home: home)
4951
let process = Process()

‎Sources/App/AppDelegate.swift‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
2525
AppDelegate.shared = self
2626

2727
setUpMainMenu()
28-
registerServices()
29-
registerHotKeys()
28+
if !TTSRuntime.isPreview {
29+
registerServices()
30+
registerHotKeys()
31+
}
3032
observeState()
3133
appState.agentAccess.startPairing()
3234

3335
// Opening the app does not refresh cloud voices. Settings already
3436
// loads voice/model inventory when the user opens it.
3537
mainWindow.show() // open the management window on launch
3638

37-
Log.app.info("Codebasic TTS launched. Backend: \(self.appState.backendIdentity, privacy: .public)")
39+
Log.app.info("\(TTSRuntime.displayName, privacy: .public) launched. Backend: \(self.appState.backendIdentity, privacy: .public)")
3840
}
3941

4042
// MARK: - Local MCP opt-in
4143

4244
@objc private func toggleLocalSpeech() {
45+
guard !TTSRuntime.isPreview else { return }
4346
if let socket = localSpeechSocket {
4447
socket.stop(); localSpeechSocket = nil; localSpeechGate = nil
4548
localSpeechMenu?.state = .off
@@ -64,6 +67,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
6467
@objc private func toggleLocalInstructions() { toggleInstructionSharing() }
6568

6669
func toggleInstructionSharing(preselect: LocalInstructionProfile.Name? = nil) {
70+
guard !TTSRuntime.isPreview else { return }
6771
if localInstructionSocket != nil { revokeLocalInstructions(); return }
6872
guard appState.agentAccess.shared == nil else {
6973
showInstructionShareError("활성 에이전트 지시 조회를 먼저 해제하세요.")
@@ -241,7 +245,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
241245

242246
// MARK: - Global hotkeys (read/explain the selection from any app)
243247

244-
private let hotKeys = HotKeyCenter()
248+
private lazy var hotKeys = HotKeyCenter()
245249

246250
/// ⌃⌥⌘R → read the selection aloud. The selection is
247251
/// grabbed via a clipboard-preserving copy, so it works even where the
@@ -267,6 +271,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
267271
/// Called by ServiceProvider when the user picks "Codebasic TTS": synthesize
268272
/// the selected text (cache-first) and play it without opening the window.
269273
func handleSelectedText(_ text: String) {
274+
guard !TTSRuntime.isPreview else { return }
270275
let preview = text.replacingOccurrences(of: "\n", with: " ").prefix(60)
271276
Log.app.info("handleSelectedText: \(text.count) chars — \"\(preview, privacy: .public)\"")
272277
appState.captureHUDTarget()
@@ -280,25 +285,27 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
280285

281286
let appItem = NSMenuItem()
282287
main.addItem(appItem)
283-
let appMenu = NSMenu(title: "Codebasic TTS")
288+
let appMenu = NSMenu(title: TTSRuntime.displayName)
284289
appItem.submenu = appMenu
285-
appMenu.addItem(withTitle: "설정…", action: #selector(openSettings), keyEquivalent: ",").target = self
286-
appMenu.addItem(.separator())
287-
appMenu.addItem(withTitle: "재생 중지", action: #selector(stopSpeaking), keyEquivalent: "").target = self
288-
let local = appMenu.addItem(withTitle: "로컬 MCP 음성 입력 허용 (이번 실행)",
289-
action: #selector(toggleLocalSpeech), keyEquivalent: "")
290-
local.target = self
291-
localSpeechMenu = local
292-
let instructions = appMenu.addItem(withTitle: "로컬 MCP 지시 공유 (이번 실행)…",
293-
action: #selector(toggleLocalInstructions), keyEquivalent: "")
294-
instructions.target = self
295-
localInstructionMenu = instructions
290+
if !TTSRuntime.isPreview {
291+
appMenu.addItem(withTitle: "설정…", action: #selector(openSettings), keyEquivalent: ",").target = self
292+
appMenu.addItem(.separator())
293+
appMenu.addItem(withTitle: "재생 중지", action: #selector(stopSpeaking), keyEquivalent: "").target = self
294+
let local = appMenu.addItem(withTitle: "로컬 MCP 음성 입력 허용 (이번 실행)",
295+
action: #selector(toggleLocalSpeech), keyEquivalent: "")
296+
local.target = self
297+
localSpeechMenu = local
298+
let instructions = appMenu.addItem(withTitle: "로컬 MCP 지시 공유 (이번 실행)…",
299+
action: #selector(toggleLocalInstructions), keyEquivalent: "")
300+
instructions.target = self
301+
localInstructionMenu = instructions
302+
}
296303
let draftReceipt = appMenu.addItem(withTitle: "외부 대본 받기 허용 (이번 실행)",
297304
action: #selector(toggleDraftReceipt), keyEquivalent: "")
298305
draftReceipt.target = self
299306
draftReceiptMenu = draftReceipt
300307
appMenu.addItem(.separator())
301-
appMenu.addItem(withTitle: "Codebasic TTS 가리기", action: #selector(NSApplication.hide(_:)), keyEquivalent: "h")
308+
appMenu.addItem(withTitle: "\(TTSRuntime.displayName) 가리기", action: #selector(NSApplication.hide(_:)), keyEquivalent: "h")
302309
appMenu.addItem(withTitle: "다른 항목 가리기",
303310
action: #selector(NSApplication.hideOtherApplications(_:)), keyEquivalent: "h")
304311
.keyEquivalentModifierMask = [.command, .option]
@@ -324,8 +331,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
324331
windowMenu.addItem(withTitle: "최소화", action: #selector(NSWindow.performMiniaturize(_:)), keyEquivalent: "m")
325332
windowMenu.addItem(withTitle: "닫기", action: #selector(NSWindow.performClose(_:)), keyEquivalent: "w")
326333
windowMenu.addItem(.separator())
327-
windowMenu.addItem(withTitle: "Codebasic TTS 열기", action: #selector(openWindow), keyEquivalent: "").target = self
328-
windowMenu.addItem(withTitle: "재생 기록", action: #selector(openHistory), keyEquivalent: "").target = self
334+
windowMenu.addItem(withTitle: "\(TTSRuntime.displayName) 열기", action: #selector(openWindow), keyEquivalent: "").target = self
335+
if !TTSRuntime.isPreview {
336+
windowMenu.addItem(withTitle: "재생 기록", action: #selector(openHistory), keyEquivalent: "").target = self
337+
}
329338
NSApp.windowsMenu = windowMenu
330339

331340
NSApp.mainMenu = main

‎Sources/App/AppState.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ final class AppState: ObservableObject {
146146
/// The external agent has already done the text work. Only the current
147147
/// voice engine may be used, and only on this explicit editor action.
148148
func playExplanationDraft(displayOnly: Bool = false) {
149-
guard !isBusy, !explaining, !normalizing,
149+
guard !TTSRuntime.isPreview, !isBusy, !explaining, !normalizing,
150150
let input = explanationDrafts.playback(displayOnly: displayOnly),
151151
AgentBytes.safeForSpeech(input.speech) else { return }
152152
playbackMode = .explain

‎Sources/App/CodexPlan.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class CodexPlanRPC {
4747
}
4848

4949
init(executable suppliedExecutable: URL? = nil, home suppliedHome: URL? = nil) throws {
50+
guard !TTSRuntime.isPreview else { throw connectionError("프리뷰에서는 Codex 계정 연결을 사용할 수 없습니다.") }
5051
guard let executable = suppliedExecutable ?? Self.executable else { throw connectionError("Codex CLI가 필요합니다. 설치 안내를 확인하세요.") }
5152
let home = suppliedHome ?? URL(fileURLWithPath: Secrets.appSupportDir).appendingPathComponent("codex-plan", isDirectory: true)
5253
try FileManager.default.createDirectory(at: home, withIntermediateDirectories: true)

‎Sources/App/LocalInstructionSocket.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ final class LocalInstructionSocket {
8383
/// Private Unix transport for one explicitly approved live process. Endpoint
8484
/// instances have disjoint paths, handlers, and leases.
8585
final class LocalApprovedSocket {
86-
static var defaultDirectory: String { "/private/tmp/codebasic-tts-mcp-\(getuid())" }
86+
static var defaultDirectory: String { TTSRuntime.socketDirectory }
8787
static let unknownPathMessage = "기존 소켓의 출처를 확인할 수 없어 그대로 두었습니다. 이전 앱을 종료하고 다시 시도하거나 복사·붙여넣기를 사용하세요."
8888
private let directory: String
8989
private let endpoint: String

‎Sources/App/LocalSpeechSocket.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ final class LocalSpeechSocket {
88
private var fd: Int32 = -1
99
private var source: DispatchSourceRead?
1010
private var socketInode: ino_t = 0
11-
private let directory = "/private/tmp/codebasic-tts-mcp-\(getuid())"
11+
private let directory = TTSRuntime.socketDirectory
1212
private var path: String { directory + "/s.sock" }
1313
private let handler: @MainActor (String, String) -> String
1414

‎Sources/App/Secrets.swift‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import Foundation
22

3-
/// API key access. MVP reads a plaintext key file from Application Support
4-
/// (user-readable only); build.sh installs it there from Sidecar/.eleven_key.
5-
/// Keychain hardening is a later milestone.
3+
/// API keys live in files under the active build's Application Support directory.
64
enum Secrets {
7-
static let appSupportDir = ("~/Library/Application Support/Codebasic TTS"
8-
as NSString).expandingTildeInPath
5+
static let appSupportDir = TTSRuntime.applicationSupport().path
96

107
static var elevenLabsKey: String? { key(named: "eleven_key") }
118
static var geminiKey: String? { key(named: "gemini_key") }

‎Sources/Core/AgentMCPConfiguration.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct AgentMCPConfiguration {
1818
init?(command: String, bundleID: String) {
1919
guard command.hasPrefix("/"), !command.utf8.contains(0), !bundleID.isEmpty else { return nil }
2020
self.command = command
21-
if bundleID == "com.seongjoo.SelectedTextTTS" {
21+
if bundleID == TTSRuntime.productionAppID {
2222
serverName = "codebasic_tts_agent"
2323
} else {
2424
// Every review bundle gets a different key from production and other previews.

0 commit comments

Comments
 (0)