Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e91b892
fix: what the review of 2026-11-22 found, with a test for each
manhpham90vn Nov 23, 2026
d76af79
test: a minus count of a command's lines on the mirror itself, not th…
manhpham90vn Nov 23, 2026
36871b5
fix: the Mac app's issues of the review of 2026-11-22
manhpham90vn Nov 23, 2026
c71b78d
fix: the iPhone app's issues of the review of 2026-11-22
manhpham90vn Nov 23, 2026
0aaf3d6
test: the Mac's notification is waited for, which may come after the …
manhpham90vn Nov 23, 2026
c88fd5c
fix: the relay, the release job and the docs of the review of 2026-11-22
manhpham90vn Nov 23, 2026
0a7793f
chore: no step output inside a release script, and RELEASE.md says th…
manhpham90vn Nov 23, 2026
38d0693
fix: the browser's issues of the review of 2026-11-22
manhpham90vn Nov 23, 2026
753bd75
fix: a client's large messages go in pieces, and a client that does n…
manhpham90vn Nov 23, 2026
022aa66
fix: a program that prints without end waits for its session's screen
manhpham90vn Nov 23, 2026
2871bdf
fix: the agents' folders are found in one place, and a listener that …
manhpham90vn Nov 23, 2026
3402b88
test: the tests left of #253, #281, #306 and #308
manhpham90vn Nov 23, 2026
6f19dc3
fix: a commit ends on its own answer, and the tests and pictures left…
manhpham90vn Nov 23, 2026
e068705
test: a refused pairing link keeps the paired Mac, and screenshots.sh…
manhpham90vn Nov 23, 2026
9e5e8f7
fix: typed text carries no control character, and a forgotten Mac is …
manhpham90vn Nov 23, 2026
5b7e648
fix: keys and Send while the Mac is gone are said, open files follow …
manhpham90vn Nov 24, 2026
6e068ec
feat: an agent's session uses a browser profile only once the user al…
manhpham90vn Nov 24, 2026
27dac35
fix: take back the profile question, answer an agent from the Inbox, …
manhpham90vn Nov 24, 2026
7b7cb80
chore: 0.15.1, its protocol row and release notes
manhpham90vn Nov 24, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: maxim-lobanov/setup-xcode@v1
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1
with:
xcode-version: ${{ env.XCODE_VERSION }}
# Formatting and style, with the swift-format that comes with Xcode and
Expand Down
49 changes: 37 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,31 @@ jobs:
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- uses: maxim-lobanov/setup-xcode@v1
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1
with:
xcode-version: ${{ env.XCODE_VERSION }}

# What was typed is given through the environment and checked, never
# pasted into the script (#318).
- name: Resolve version
id: version
env:
TYPED_VERSION: ${{ inputs.version }}
run: |
if [ -n "${{ inputs.version }}" ]; then v="${{ inputs.version }}"; else v="${GITHUB_REF_NAME#v}"; fi
if [ -n "$TYPED_VERSION" ]; then v="$TYPED_VERSION"; else v="${GITHUB_REF_NAME#v}"; fi
printf '%s' "$v" | grep -Eqx '[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?' || { echo "Not a version like 0.15.1 or 0.15.1-beta.1: $v" >&2; exit 1; }
echo "value=$v" >> "$GITHUB_OUTPUT"
case "$v" in *-*) echo "prerelease=true" >> "$GITHUB_OUTPUT" ;; *) echo "prerelease=false" >> "$GITHUB_OUTPUT" ;; esac

# The version has to be the one in VERSION (a -beta.N suffix is fine), and its
# notes have to be written: the GitHub release and TestFlight show them.
- name: Check the version and its release notes
id: notes
env:
VERSION: ${{ steps.version.outputs.value }}
run: |
scripts/check-version.sh "${{ steps.version.outputs.value }}"
echo "path=$(scripts/check-release-notes.sh "${{ steps.version.outputs.value }}")" >> "$GITHUB_OUTPUT"
scripts/check-version.sh "$VERSION"
echo "path=$(scripts/check-release-notes.sh "$VERSION")" >> "$GITHUB_OUTPUT"

- name: Install fastlane
run: command -v fastlane >/dev/null || brew install fastlane
Expand Down Expand Up @@ -124,10 +131,17 @@ jobs:
fastlane mac release
cd dist && shasum -a 256 "AgentTerm-$VERSION.dmg" > "AgentTerm-$VERSION.sha256"

# Gone before publishing: nothing after this needs them (#314).
- name: Remove the signing files
run: rm -f "$RUNNER_TEMP/asc_key.p8" "$RUNNER_TEMP/developer_id.p12" "$RUNNER_TEMP/firebase.plist"

- name: Publish GitHub release
uses: softprops/action-gh-release@v3
uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3
with:
tag_name: ${{ github.ref_type == 'tag' && github.ref_name || format('v{0}', steps.version.outputs.value) }}
# A release started by hand from a branch tags the commit that was
# built, not the default branch's head (#315).
target_commitish: ${{ github.sha }}
name: AgentTerm ${{ steps.version.outputs.value }}
prerelease: ${{ steps.version.outputs.prerelease }}
body_path: ${{ steps.notes.outputs.path }}
Expand All @@ -141,9 +155,12 @@ jobs:
if: env.HOMEBREW_TAP_TOKEN != ''
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: scripts/publish-homebrew.sh "${{ steps.version.outputs.value }}"
# For the release's published checksum (#316).
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.value }}
run: scripts/publish-homebrew.sh "$VERSION"

- name: Remove the signing files
- name: Remove the signing files, whatever happened
if: always()
run: rm -f "$RUNNER_TEMP/asc_key.p8" "$RUNNER_TEMP/developer_id.p12" "$RUNNER_TEMP/firebase.plist"

Expand All @@ -154,14 +171,18 @@ jobs:
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- uses: maxim-lobanov/setup-xcode@v1
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1
with:
xcode-version: ${{ env.XCODE_VERSION }}

# What was typed is given through the environment and checked (#318).
- name: Resolve version
id: version
env:
TYPED_VERSION: ${{ inputs.version }}
run: |
if [ -n "${{ inputs.version }}" ]; then v="${{ inputs.version }}"; else v="${GITHUB_REF_NAME#v}"; fi
if [ -n "$TYPED_VERSION" ]; then v="$TYPED_VERSION"; else v="${GITHUB_REF_NAME#v}"; fi
printf '%s' "$v" | grep -Eqx '[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?' || { echo "Not a version like 0.15.1 or 0.15.1-beta.1: $v" >&2; exit 1; }
# TestFlight takes numbers only: 0.2.0-beta.1 is uploaded as 0.2.0.
echo "value=${v%%-*}" >> "$GITHUB_OUTPUT"
echo "release=$v" >> "$GITHUB_OUTPUT"
Expand All @@ -170,9 +191,11 @@ jobs:
# notes have to be written: the GitHub release and TestFlight show them.
- name: Check the version and its release notes
id: notes
env:
VERSION: ${{ steps.version.outputs.value }}
run: |
scripts/check-version.sh "${{ steps.version.outputs.value }}"
echo "path=$(scripts/check-release-notes.sh "${{ steps.version.outputs.value }}")" >> "$GITHUB_OUTPUT"
scripts/check-version.sh "$VERSION"
echo "path=$(scripts/check-release-notes.sh "$VERSION")" >> "$GITHUB_OUTPUT"

- name: Install fastlane and XcodeGen
run: |
Expand Down Expand Up @@ -233,7 +256,9 @@ jobs:
- name: Post the release notes
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
TYPED_VERSION: ${{ inputs.version }}
run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then echo "No DISCORD_WEBHOOK_URL secret: not announcing."; exit 0; fi
if [ -n "${{ inputs.version }}" ]; then v="${{ inputs.version }}"; else v="${GITHUB_REF_NAME#v}"; fi
if [ -n "$TYPED_VERSION" ]; then v="$TYPED_VERSION"; else v="${GITHUB_REF_NAME#v}"; fi
printf '%s' "$v" | grep -Eqx '[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?' || { echo "Not a version: $v" >&2; exit 1; }
scripts/announce-discord.sh "$v"
10 changes: 6 additions & 4 deletions PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ the source yourself sends nothing at all.
relay the developer runs on Cloudflare, which holds the key Apple asks for. What the notification
says (the session's name, its folder, what the agent said or asks) is encrypted on your Mac with a
key your iPhone made for that Mac alone, and only your iPhone can open it: the relay and Apple
see the iPhone's push token, when a notification is sent, its size, and the address your Mac
connects from. The relay keeps none of it. "Also While the App Is Closed" in the iPhone's
see the iPhone's push token, when a notification is sent, its size, the address your Mac
connects from, and the notification's name, made of a random id your iPhone gave this Mac and
the notification's number on it. The relay keeps none of it. "Also While the App Is Closed" in the iPhone's
Settings turns it off, and "Tell me when an agent is done or needs me" turns off all
notifications; revoking the iPhone on the Mac forgets its token and key. When a notification was
handled or read on another device, the Mac asks the relay to take it back from the iPhone: that request
names the notification only. A build made from the source has no relay and sends nothing this way.
- **The Live Activity through Apple (iPhone, released app).** While agents work, and for 15 minutes
after the last one stops, the Mac keeps the iPhone's Live Activity up to date through the same relay and Apple. Unlike a notification it
cannot be encrypted for the iPhone, because iOS draws it from what the push carries: how many
agents work, wait, are done or stopped, and the names of the sessions that wait or are done,
with whether the change needs you, so that Apple shows it at once. It
agents work, wait, are done or stopped, the names of the sessions that wait or are done, and
your Mac's name as macOS gives it (often "<your name>'s MacBook"), with whether the change
needs you, so that Apple shows it at once. It
never carries what an agent said. The relay keeps none of it. "Live Activity of the Mac's agents"
in the iPhone's Settings turns it off.
- **To the services of the coding agents you use.** To show what your account has left (the figures
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ use versions from the same row.

| Mac app | iPhone app | Protocol |
|---|---|---|
| 0.15.x | 0.15.x | 40 |
| 0.15.1 | 0.15.1 | 45 |
| 0.15.0 | 0.15.0 | 40 |
| 0.14.x | 0.14.x | 39 |
| 0.13.x | 0.13.x | 36 |
| 0.12.x | 0.12.x | 32 |
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ forward its port to the internet or to a network you do not control.**
| Pairing an iPhone | The Mac shows a code that works once, for five minutes, and only while the pairing screen is open. The phone trades it for a token of its own. |
| Taking a device off | Each paired device has its own token, which the Mac can revoke under **Pair iPhone**. |
| The Mac's own token | It is kept in a file only you can read (mode 0600) and is accepted only on connections that arrive on the loopback interface, so it is no use from another machine. |
| Your data | What your terminals show, your prompts, files and folders never leave your devices. The released apps can send crash reports (if you agree) and counts of which features are used (can be switched off) through Firebase; a build from source sends nothing. AgentTerm has no server of its own and no account. See [PRIVACY.md](PRIVACY.md). |
| Your data | What your terminals show, your prompts, files and folders never leave your devices. The released apps can send crash reports (if you agree) and counts of which features are used (can be switched off) through Firebase; a build from source sends nothing. AgentTerm has no account; its one server is the small relay the released apps send notifications through to Apple, which sees no content and keeps nothing. See [PRIVACY.md](PRIVACY.md). |
| Files you preview | A Markdown preview runs nothing from the file: HTML in it is turned into Markdown, and scripts and styles are not interpreted. |

## What it does not protect against
Expand Down
37 changes: 34 additions & 3 deletions Sources/AgentTermClient/AgentTermConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public final class AgentTermConnection: @unchecked Sendable {
private let queue = DispatchQueue(label: "agentterm.client")
/// Touched on the main queue only.
private var closed = false
/// It was said on this connection that a message could not be read.
private var saidUnreadable = false
/// Joins a large message sent in pieces (`MessageParts`).
private var joiner = MessageParts.Joiner()

Expand All @@ -45,6 +47,8 @@ public final class AgentTermConnection: @unchecked Sendable {
/// these wait, and follow the greeting in the order they were sent.
private var waiting: [(data: Data, opcode: NWProtocolWebSocket.Opcode)]? = []
private let waitingLock = NSLock()
/// Numbers the large messages sent in pieces; under `waitingLock`.
private var nextMessage: UInt32 = 0
/// The protocol the host said it is at, in its welcome; nil until then.
/// Under `waitingLock`.
private var hostProtocol: Int?
Expand Down Expand Up @@ -148,7 +152,19 @@ public final class AgentTermConnection: @unchecked Sendable {
let host = hostProtocol
waitingLock.unlock()
if let host, !message.isKnown(toHostAt: host) { return }
send(MessageCoding.encode(message), opcode: .text)
let data = MessageCoding.encode(message)
// Larger than a frame may be: in pieces, one after the other, as
// the host sends its own (#289); a frame over the host's 4 MB
// closed the connection without a word.
waitingLock.lock()
let id = nextMessage
nextMessage &+= 1
waitingLock.unlock()
if let frames = MessageParts.frames(for: data, id: id) {
for frame in frames { send(frame.encoded(), opcode: .binary) }
return
}
send(data, opcode: .text)
}

public func sendInput(_ data: Data, to session: SessionID) {
Expand Down Expand Up @@ -220,6 +236,15 @@ public final class AgentTermConnection: @unchecked Sendable {
}

/// Anything from the host is a sign of life, also a part of a message.
/// A message from the host that could not be read is said, once a
/// connection, as an error both apps show in their banner (#292):
/// before, it was dropped and nothing said so.
private func couldNotRead() {
guard !saidUnreadable else { return }
saidUnreadable = true
deliver { if !self.closed { self.onMessage?(.error(HostErrorWords.unreadableMessage)) } }
}

private func heard() {
lastHeard = .now()
pingSentAt = nil
Expand Down Expand Up @@ -259,14 +284,20 @@ public final class AgentTermConnection: @unchecked Sendable {
if let data, let message = MessageCoding.decode(ServerMessage.self, from: data) {
self.noteProtocol(of: message)
self.deliver { if !self.closed { self.onMessage?(message) } }
} else {
self.couldNotRead()
}
case .binary:
guard let data, let frame = DataFrame(decoding: data) else { break }
if frame.kind == .output {
self.deliver { if !self.closed { self.onOutput?(frame.session, frame.payload) } }
} else if let whole = self.joiner.add(frame), let message = MessageCoding.decode(ServerMessage.self, from: whole) {
} else if let whole = self.joiner.add(frame) {
// A large message, sent in pieces.
self.deliver { if !self.closed { self.onMessage?(message) } }
if let message = MessageCoding.decode(ServerMessage.self, from: whole) {
self.deliver { if !self.closed { self.onMessage?(message) } }
} else {
self.couldNotRead()
}
}
case .close:
self.finish(reason: nil)
Expand Down
142 changes: 142 additions & 0 deletions Sources/AgentTermClient/PairingStore.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Foundation
import Security

/// A Mac this iPhone is paired with, and the token it connects to it with.
public struct SavedHost: Codable, Equatable, Identifiable, Sendable {
public var id: String
public var host: String
public var port: UInt16
public var name: String
/// This device's own token for that Mac, given when pairing. The Mac can
/// revoke it without affecting other devices.
public var token: String

public init(id: String, host: String, port: UInt16, name: String, token: String) {
self.id = id
self.host = host
self.port = port
self.name = name
self.token = token
}
}

/// The Keychain's items of this app, by account: what `PairingStore` asks
/// of it, so that a test can stand a Keychain of its own in (#287).
public protocol KeychainItems: Sendable {
func read(account: String) -> (status: OSStatus, data: Data?)
func update(account: String, data: Data) -> OSStatus
func add(account: String, data: Data) -> OSStatus
func delete(account: String) -> OSStatus
}

/// The system's Keychain, a generic password per account, kept on this
/// device only and readable after its first unlock.
public struct SystemKeychain: KeychainItems {
public init() {}

private func query(account: String) -> [String: Any] {
[
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: "com.manhpham.agentterm",
kSecAttrAccount as String: account,
]
}

public func read(account: String) -> (status: OSStatus, data: Data?) {
var request = query(account: account)
request[kSecReturnData as String] = true
request[kSecMatchLimit as String] = kSecMatchLimitOne
var result: CFTypeRef?
let status = SecItemCopyMatching(request as CFDictionary, &result)
return (status, status == errSecSuccess ? result as? Data : nil)
}

private func changes(_ data: Data) -> [String: Any] {
[kSecValueData as String: data, kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly]
}

public func update(account: String, data: Data) -> OSStatus {
SecItemUpdate(query(account: account) as CFDictionary, changes(data) as CFDictionary)
}

public func add(account: String, data: Data) -> OSStatus {
var item = query(account: account)
item.merge(changes(data)) { $1 }
return SecItemAdd(item as CFDictionary, nil)
}

public func delete(account: String) -> OSStatus {
SecItemDelete(query(account: account) as CFDictionary)
}
}

/// Keeps the paired Macs in the Keychain, since the tokens grant shell access.
public final class PairingStore: @unchecked Sendable {
public static let shared = PairingStore()

private let keychain: KeychainItems
private let lock = NSLock()
private var couldNotRead = false

public init(keychain: KeychainItems = SystemKeychain()) {
self.keychain = keychain
}

/// The Keychain could not be read when the list was loaded (a launch
/// before the first unlock, say): the paired Macs are not known, and
/// nothing is written over them (#287).
public var unreadable: Bool {
lock.lock()
defer { lock.unlock() }
return couldNotRead
}

private func read(account: String) -> Data? {
let (status, data) = keychain.read(account: account)
if status != errSecSuccess, status != errSecItemNotFound {
lock.lock()
couldNotRead = true
lock.unlock()
}
return data
}

public func load() -> [SavedHost] {
lock.lock()
couldNotRead = false
lock.unlock()
if let data = read(account: "hosts"), let hosts = try? JSONDecoder().decode([SavedHost].self, from: data) {
return hosts
}
if unreadable { return [] }
// Builds that paired with a single Mac kept it under another name.
struct Single: Codable {
var host: String
var port: UInt16
var name: String
var token: String
}
guard let data = read(account: "host"), let old = try? JSONDecoder().decode(Single.self, from: data) else { return [] }
let migrated = [SavedHost(id: UUID().uuidString, host: old.host, port: old.port, name: old.name, token: old.token)]
save(migrated)
_ = keychain.delete(account: "host")
return migrated
}

@discardableResult
public func save(_ hosts: [SavedHost]) -> Bool {
// Never over what could not be read: it may hold every paired Mac.
guard !unreadable else { return false }
guard !hosts.isEmpty else {
let status = keychain.delete(account: "hosts")
return status == errSecSuccess || status == errSecItemNotFound
}
guard let data = try? JSONEncoder().encode(hosts) else { return false }
// Changed in place: the list is never deleted before the new one is
// there, so a failure keeps the old one (#287).
let updated = keychain.update(account: "hosts", data: data)
if updated == errSecSuccess { return true }
guard updated == errSecItemNotFound else { return false }
return keychain.add(account: "hosts", data: data) == errSecSuccess
}
}
Loading
Loading