Skip to content

Commit 7648e51

Browse files
committed
Keep a revoked helper revoked; drop stale requests on outside revocation (#43)
Round 1 advice (Codex, Antigravity): - A helper told "revoked" stays revoked for its lifetime, so an app restart or a re-approval of the same key does not reattach that session. - Approval requests raised before their key was revoked by another instance are removed when that revocation is adopted. - trust() withdraws a pending revocation only right before saving, so Failure.full/hostChanged leave it pending. - The mcpServers paste hint matches the copied structure. Agent: Claude Code (runtime model unverified) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LJG7NX2yks21D5Tau2tYG
1 parent b6d815f commit 7648e51

6 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎Helpers/AgentCatalogMCP.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,18 @@ import Security
476476
/// it yet, proves which client it is. Never needs the user unless the app
477477
/// answers that an approval is required.
478478
static func pairingStatus() -> String {
479+
// Once the user revoked this app, this helper process stays revoked, also
480+
// after the app restarts; a new session asks for approval again (#43).
481+
if revokedHere { return "revoked" }
482+
let status = queryPairingStatus()
483+
if status == "revoked" { revokedHere = true }
484+
return status
485+
}
486+
487+
/// Set by the app's first "revoked" answer to this process.
488+
static var revokedHere = false
489+
490+
private static func queryPairingStatus() -> String {
479491
guard pin != nil else { return "signing_required" }
480492
slot = nil
481493
let schema = AgentPairing.schema

‎Sources/App/AgentSessionController.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,16 @@ import Security
819819
private func adoptStoreAfterTakeover() {
820820
let wasFailed = trust.readFailed
821821
let priorKeys = Dictionary(trust.clients.map { ($0.id, $0.keyID) }, uniquingKeysWith: { first, _ in first })
822+
let priorRevoked = Set(trust.file.revoked)
822823
// Only the socket holder writes the file; another instance only reads it.
823824
trust.adoptDisk(writeBack: pairingSocket != nil)
825+
// A request raised before its key was revoked elsewhere cannot lift that
826+
// revocation; a new session of the app asks again (#43).
827+
let newlyRevoked = Set(trust.file.revoked).subtracting(priorRevoked)
828+
if !newlyRevoked.isEmpty {
829+
for request in approvalRequests where newlyRevoked.contains(request.claim.keyID) { removeApproval(request.id) }
830+
challenges.removeAll { newlyRevoked.contains($0.keyID) }
831+
}
824832
// A remembered instruction choice belongs to the key that was approved
825833
// when it was made; a removed or replaced key does not inherit it.
826834
let keys = Dictionary(trust.clients.map { ($0.id, $0.keyID) }, uniquingKeysWith: { first, _ in first })

‎Sources/Core/AgentTrustStore.swift‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,6 @@ final class AgentTrustStore {
336336
guard let keyID = AgentPairingProof.keyID(publicKey) else { throw Failure.invalid }
337337
var next = file
338338
next.revoked.removeAll { $0 == keyID }
339-
// An unsaved revocation of this key must not undo the new approval later.
340-
let hadPendingRevoke = pending.contains(.revoke(keyID))
341-
pending.removeAll { $0 == .revoke(keyID) }
342339
let time = now()
343340
let client: AgentTrustedClient
344341
var replaced: String?
@@ -362,6 +359,9 @@ final class AgentTrustStore {
362359
next.clients.append(client)
363360
}
364361
if let replaced, !pending.contains(.revoke(replaced)) { pending.append(.revoke(replaced)) }
362+
// An unsaved revocation of this key must not undo the new approval later.
363+
let hadPendingRevoke = pending.contains(.revoke(keyID))
364+
pending.removeAll { $0 == .revoke(keyID) }
365365
guard grant(next, byUser: false) else {
366366
// Not approved: the key stays revoked as before.
367367
if hadPendingRevoke, !pending.contains(.revoke(keyID)) { pending.append(.revoke(keyID)) }

‎Sources/UI/ExplainWorkspace.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ struct ExplainWorkspace: View {
602602
switch client {
603603
case "Codex": return "config.toml에 붙여넣으세요."
604604
case "JSON":
605-
return "클라이언트 설정 파일의 mcpServers에 이 항목을 합쳐 넣고 그 앱을 완전히 종료한 뒤 다시 여세요. Claude 데스크톱 앱은 설정 › 개발자 › 구성 편집으로 claude_desktop_config.json을 엽니다."
605+
return "설정 파일이 비어 있으면 그대로 붙여넣고, 이미 mcpServers가 있으면 그 안에 이 서버 항목 한 줄만 추가한 뒤 그 앱을 완전히 종료하고 다시 여세요. Claude 데스크톱 앱은 설정 › 개발자 › 구성 편집으로 claude_desktop_config.json을 엽니다."
606606
default: return "터미널에 붙여넣고 실행하세요."
607607
}
608608
}

‎Tests/Fixtures/run_persistent_pairing.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,22 @@ def client_id():
311311
late = a.send("late", "잊은 뒤 늦은 요청")
312312
assert late["outcome"] == "rejected" and server.documents() == []
313313
assert a.status() == "revoked" and server.snapshot()["trusted"] == []
314-
a.close()
314+
revoked_helper = a
315315
a = client()
316316
assert a.status() == "approval_required" and not server.snapshot()["paired"]
317317
assert server.snapshot()["trusted"] == []
318318
assert fs.approve(server, a) == "receiving_only"; clicks += 1
319319
assert server.snapshot()["trusted"] == [slot_a]
320-
ok("forget: late request refused, that helper stays revoked; a new session asks again and connects after approval")
320+
# The revoked helper stays revoked, also once its key is approved again and
321+
# after the app restarts, and raises no request.
322+
assert revoked_helper.status() == "revoked"
323+
server.end()
324+
server = app()
325+
assert revoked_helper.status() == "revoked" and a.status() == "receiving_only"
326+
assert json.loads(server("requests")) == []
327+
revoked_helper.close()
328+
ok("forget: late request refused, that helper stays revoked across re-approval and app restart; "
329+
"a new session asks again and connects after approval")
321330

322331
# disconnect <id> is this app's receipt off (#13): it keeps the approval and stays
323332
# off across client and app restarts; resume turns it back on with no new pairing.

‎docs/mcp-explanation-drafts.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
command = "/absolute/path/to/Codebasic TTS.app/Contents/Helpers/CodebasicAgentMCP"
1919
```
2020

21-
앱의 **MCP 설정 복사** 메뉴로 현재 번들 경로가 포함된 Codex 설정, Claude Code 사용자 범위 등록 명령, 여러 클라이언트가 공통으로 읽는 `mcpServers` JSON 항목(Claude 데스크톱 앱의 `claude_desktop_config.json` 등)을 복사할 수 있습니다. 연결·승인·철회 후 재승인은 클라이언트와 상관없이 도우미와 앱 사이의 같은 경로에서 처리됩니다. 데스크톱 앱은 설정 › 개발자 › 구성 편집(Edit Config)으로 연 파일(`~/Library/Application Support/Claude/claude_desktop_config.json`)의 `mcpServers`에 복사한 항목을 합쳐 넣고 앱을 완전히 종료한 뒤 다시 열면 됩니다. 데스크톱 앱도 터미널과 같은 방식으로 실행 주체의 서명으로 식별되어 별도의 앱으로 한 번 승인하며, 식별할 수 없으면 실행마다 승인합니다. 복사만으로 설정 파일을 바꾸거나 명령을 실행하지 않습니다. 다른 stdio MCP 클라이언트에도 같은 절대 경로를 실행 명령으로 지정하면 됩니다. 앱을 옮기거나 이름을 바꾸면 이 명령 경로만 수정하세요. 전역 에이전트 설정은 앱이 변경하지 않습니다.
21+
앱의 **MCP 설정 복사** 메뉴로 현재 번들 경로가 포함된 Codex 설정, Claude Code 사용자 범위 등록 명령, 여러 클라이언트가 공통으로 읽는 `mcpServers` JSON 항목(Claude 데스크톱 앱의 `claude_desktop_config.json` 등)을 복사할 수 있습니다. 연결·승인·철회 후 재승인은 클라이언트와 상관없이 도우미와 앱 사이의 같은 경로에서 처리됩니다. 데스크톱 앱은 설정 › 개발자 › 구성 편집(Edit Config)으로 연 파일(`~/Library/Application Support/Claude/claude_desktop_config.json`)의 `mcpServers`에 복사한 서버 항목을 추가하고(파일이 비어 있으면 복사한 내용을 그대로 붙여넣고) 앱을 완전히 종료한 뒤 다시 열면 됩니다. 데스크톱 앱도 터미널과 같은 방식으로 실행 주체의 서명으로 식별되어 별도의 앱으로 한 번 승인하며, 식별할 수 없으면 실행마다 승인합니다. 복사만으로 설정 파일을 바꾸거나 명령을 실행하지 않습니다. 다른 stdio MCP 클라이언트에도 같은 절대 경로를 실행 명령으로 지정하면 됩니다. 앱을 옮기거나 이름을 바꾸면 이 명령 경로만 수정하세요. 전역 에이전트 설정은 앱이 변경하지 않습니다.
2222

2323
- `tts_agent_status`: 앱 연결과 두 권한의 상태를 확인합니다. 지시나 대본은 읽지 않습니다.
2424
- `get_tts_submission_guide`: 제출 형식을 돌려주는 읽기 전용 도구입니다. 어느 도구를 언제 쓰는지, 각 필드의 뜻과 한도, 예시, 결과 코드별 대처를 담습니다. 앱이 꺼져 있거나 허용 전이어도 읽을 수 있고, 지시·대본·승인 정보는 담지 않으며 아무 상태도 바꾸지 않습니다. 도구 스키마와 이 안내는 도우미 안의 한 필드 정의에서 만들어집니다.
@@ -35,7 +35,7 @@ command = "/absolute/path/to/Codebasic TTS.app/Contents/Helpers/CodebasicAgentMC
3535

3636
**승인은 에이전트 앱 단위입니다.** 도우미를 직접 실행한 앱을 코드 서명으로 식별합니다. 식별자는 서명 팀 ID(없으면 서명 인증서)와 코드 서명 식별자(번들 ID)의 조합이며, 앱 이름·경로·PID는 쓰지 않습니다. 유효한 인증서로 강화 런타임 서명이 되어 있고 macOS 기본 구성요소(셸·시스템 인터프리터)가 아닌 앱이면, 한 번 승인한 뒤 그 앱이나 Codebasic TTS를 재시작·업데이트해도, 오래 쓰지 않아도 다시 승인하지 않습니다. 앱이 따로 등록할 것은 없습니다. 애드혹 서명이거나 서명이 없는 실행 파일, 셸(`/bin/zsh -c …`)이나 시스템 인터프리터를 거쳐 도우미를 실행하는 호스트는 앱을 구별할 수 없어 실행별로 승인합니다. 같은 서명된 런타임(예: 공용 `node`)으로 직접 실행되는 서로 다른 도구는 같은 앱으로 보입니다.
3737

38-
식별된 앱은 앱별 키로 새 챌린지에 응답합니다. 키는 `~/Library/Application Support/Codebasic TTS/agent-client-keys/`(폴더 0700, 파일 0600)에 저장됩니다. 키체인에 두면 자체 서명 빌드에서 앱을 다시 빌드·업데이트할 때마다 도우미가 키에 접근하지 못하기 때문입니다. Codebasic TTS는 실행 중인 상대 도우미와 호스트의 서명, 승인된 키를 확인합니다. 전체 받기와 해당 앱의 받기가 켜져 있을 때 다시 연결되고, 화면 잠금 중에는 모든 수신이 막힙니다. **잊기**(승인 철회)를 누르면 해당 앱에 한해 진행 중인 요청을 지우고, 연결돼 있던 도우미는 다시 시작할 때까지 `revoked`로 막습니다. 그 앱의 새 세션(도우미를 새로 시작)이 연결하면 같은 키라도 **에이전트 연결**에 승인 요청이 다시 표시되고, 사용자가 **허용**을 눌러야만 연결됩니다. 허용하면 그 키의 철회가 풀립니다. 철회된 키는 요청 없이 저절로 다시 연결되지 않습니다. 도우미의 `--forget-key`는 키를 잃었거나 바꾸려 할 때만 쓰며, 철회 뒤 다시 허용하는 데는 필요하지 않습니다.
38+
식별된 앱은 앱별 키로 새 챌린지에 응답합니다. 키는 `~/Library/Application Support/Codebasic TTS/agent-client-keys/`(폴더 0700, 파일 0600)에 저장됩니다. 키체인에 두면 자체 서명 빌드에서 앱을 다시 빌드·업데이트할 때마다 도우미가 키에 접근하지 못하기 때문입니다. Codebasic TTS는 실행 중인 상대 도우미와 호스트의 서명, 승인된 키를 확인합니다. 전체 받기와 해당 앱의 받기가 켜져 있을 때 다시 연결되고, 화면 잠금 중에는 모든 수신이 막힙니다. **잊기**(승인 철회)를 누르면 해당 앱에 한해 진행 중인 요청을 지우고, 연결돼 있던 도우미는 `revoked`를 받은 뒤 Codebasic TTS를 재시작해도 그 프로세스가 끝날 때까지 `revoked`로 남습니다. 다른 인스턴스가 저장한 철회를 읽으면 그 전에 떠 있던 해당 키의 승인 요청도 지웁니다. 그 앱의 새 세션(도우미를 새로 시작)이 연결하면 같은 키라도 **에이전트 연결**에 승인 요청이 다시 표시되고, 사용자가 **허용**을 눌러야만 연결됩니다. 허용하면 그 키의 철회가 풀립니다. 철회된 키는 요청 없이 저절로 다시 연결되지 않습니다. 도우미의 `--forget-key`는 키를 잃었거나 바꾸려 할 때만 쓰며, 철회 뒤 다시 허용하는 데는 필요하지 않습니다.
3939

4040
전송 키는 승인된 연결마다 따로 해석합니다. 등록된 앱에서 저장 문서가 남아 있으면 재시작 후에도 동일 키와 동일 제목·본문·낭독본은 중복으로 보고합니다. 임시 승인 세션을 다시 실행한 경우에는 재전송하기 전에 수신 목록을 확인하세요. 선택 지시는 사용자가 지정한 앱에만 공유하며 Codebasic TTS를 다시 실행하면 선택이 풀립니다.
4141

0 commit comments

Comments
 (0)