Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e619798
Add mobile chat observer regression coverage
azooz2003-bit Jun 29, 2026
cb9601a
Detect Claude mobile chat sessions from process details
azooz2003-bit Jun 29, 2026
4004b39
Await mobile chat observation before listing sessions
azooz2003-bit Jun 30, 2026
bf4d102
Split mobile chat observation scanner files
azooz2003-bit Jun 30, 2026
8f2e200
Merge remote-tracking branch 'origin/main' into feat-ios-claude-gui-d…
azooz2003-bit Jun 30, 2026
e2cef6c
Keep exit liveness matching to agent executables
azooz2003-bit Jun 30, 2026
45ddba9
Make observed agent scan load process details lazily
azooz2003-bit Jun 30, 2026
b0a7edb
Avoid inherited env mobile chat detections
azooz2003-bit Jun 30, 2026
944b3cb
Refresh mobile chat observations on each list pull
azooz2003-bit Jun 30, 2026
2ab6bfd
Avoid unchanged observed session updates
azooz2003-bit Jun 30, 2026
e67ec27
Single-flight mobile chat observations
azooz2003-bit Jun 30, 2026
a7b56bb
Share mobile chat liveness detection
azooz2003-bit Jun 30, 2026
c592ca6
Avoid blocking mobile chat list observation
azooz2003-bit Jun 30, 2026
a63295d
Throttle scheduled mobile chat observation
azooz2003-bit Jun 30, 2026
5b2a221
Use timestamp throttle for mobile chat observation
azooz2003-bit Jun 30, 2026
f8ca5b4
Surface fresh Claude sessions in mobile chat
azooz2003-bit Jun 30, 2026
782228a
Reconcile pending Claude chat sessions
azooz2003-bit Jun 30, 2026
247030a
Split agent chat observe scan helpers
azooz2003-bit Jun 30, 2026
3767d49
Store seeded chat sessions by canonical id
azooz2003-bit Jun 30, 2026
993e0c7
Fix pending Claude lifecycle reconciliation
azooz2003-bit Jun 30, 2026
04e3e36
Notify clients when Claude aliases are removed
azooz2003-bit Jun 30, 2026
640f3c5
Harden pending Claude session removal
azooz2003-bit Jun 30, 2026
d9d58b5
Preserve Claude hook-store lookup aliases
azooz2003-bit Jun 30, 2026
3e8f3ea
Avoid permanent unversioned removal tombstones
azooz2003-bit Jun 30, 2026
95e23f6
Fix stale Claude GUI chat rows
azooz2003-bit Jun 30, 2026
57be801
Make Claude mobile chat detection deterministic
azooz2003-bit Jul 2, 2026
f330d20
Bound mobile chat agent observation
azooz2003-bit Jul 3, 2026
4eb3baa
Fix scoped agent observation reuse
azooz2003-bit Jul 3, 2026
552726f
Coalesce ignored mobile chat refreshes
azooz2003-bit Jul 3, 2026
270f9ec
Preserve pending Claude history identity
azooz2003-bit Jul 3, 2026
ec9cf42
Gate Claude session identity by provenance
azooz2003-bit Jul 3, 2026
80a8db5
Preserve pinned Claude chat during alias handoff
azooz2003-bit Jul 3, 2026
d910ac9
Gate agent chat detection to foreground processes
azooz2003-bit Jul 3, 2026
9dc043b
Drain superseded agent observation waiters
azooz2003-bit Jul 3, 2026
5ca0489
Require authoritative Claude chat identity
azooz2003-bit Jul 3, 2026
277c067
Index live Claude session aliases
azooz2003-bit Jul 3, 2026
dd51e51
Match Claude liveness by session identity
azooz2003-bit Jul 3, 2026
ff0e70f
Isolate settings notification observer tests
azooz2003-bit Jul 3, 2026
6a4cbc4
Harden Claude resume session parsing
azooz2003-bit Jul 3, 2026
7027cdd
Stabilize chat store cache-head test
azooz2003-bit Jul 3, 2026
5c552c3
Harden Claude liveness review paths
azooz2003-bit Jul 3, 2026
ca789c0
Merge remote-tracking branch 'origin/main' into feat-ios-claude-gui-d…
azooz2003-bit Jul 3, 2026
d1c28ce
Preserve launch-kind agent detection
azooz2003-bit Jul 3, 2026
9234eec
Constrain Claude liveness fallback
azooz2003-bit Jul 3, 2026
13bc715
Fix Claude GUI session surface binding
azooz2003-bit Jul 3, 2026
7e84a11
Address Claude GUI detection review issues
azooz2003-bit Jul 3, 2026
9bd543d
Reject inherited Claude launch env for child tools
azooz2003-bit Jul 3, 2026
dcf4f9a
Detect Claude exe runtime process
azooz2003-bit Jul 3, 2026
4a46400
Create pending Claude sessions for unidentified GUI launches
azooz2003-bit Jul 3, 2026
a5190ce
Preserve live agent chat bindings during seed
azooz2003-bit Jul 3, 2026
ce3f092
Cancel superseded agent chat scans
azooz2003-bit Jul 3, 2026
59aa121
Address agent chat policy review fixes
azooz2003-bit Jul 3, 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
96 changes: 79 additions & 17 deletions Sources/Mobile/AgentChat/AgentChatSessionRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import Foundation

/// A coding-agent session discovered by observing the process table, with no
/// dependency on hooks firing. Identity (and, for codex, the transcript path)
/// comes from the agent's own argv or open transcript file, so a session
/// launched through any indirection (a subrouter, a wrapper) is still found.
/// comes from the agent's own argv, environment, or open transcript file, so a
/// session launched through any indirection (a subrouter, a wrapper) is still
/// found.
nonisolated struct ObservedAgentSession: Sendable {
let sessionID: String
let agentKind: ChatAgentKind
let surfaceID: String
let workspaceID: String?
let pid: Int
let workingDirectory: String?
let transcriptPath: String?
}

Expand Down Expand Up @@ -130,11 +132,9 @@ final class AgentChatSessionRegistry {
let wantedID = kind.sourceName
for pid in snapshot.expandedPIDs(rootPIDs: rootPIDs).sorted() {
guard let info = snapshot.process(pid: pid),
let def = CmuxTaskManagerCodingAgentDefinition.matchingDefinition(
processName: info.name,
processPath: info.path,
arguments: [],
environment: [:]
let def = codingAgentDefinition(
for: info,
processArgumentsAndEnvironment: CmuxTopProcessSnapshot.processArgumentsAndEnvironment(for:)
),
def.id == wantedID else { continue }
return pid
Expand All @@ -147,8 +147,9 @@ final class AgentChatSessionRegistry {
/// Off-main scan + main-actor apply: discover live codex/claude sessions by
/// observing the process table, with no dependency on hooks firing. Resolves
/// identity from the agent's own state (codex: the rollout file it holds
/// open; claude: its `--session-id`/`--resume` argv), so a session launched
/// through any indirection (a subrouter, a wrapper) is still found and bound.
/// open; claude: `CLAUDE_CODE_SESSION_ID` or `--session-id`/`--resume`),
/// so a session launched through any indirection (a subrouter, a wrapper)
/// is still found and bound.
/// Throttled; safe to call coarsely (e.g. on the iOS list pull). The snapshot
/// is captured off the main actor.
private var observeThrottle: Date?
Expand Down Expand Up @@ -182,7 +183,7 @@ final class AgentChatSessionRegistry {
agentKind: session.agentKind,
workspaceID: session.workspaceID,
surfaceID: session.surfaceID,
workingDirectory: nil,
workingDirectory: session.workingDirectory,
transcriptPath: session.transcriptPath,
state: .idle,
lastActivityAt: now,
Expand All @@ -198,6 +199,7 @@ final class AgentChatSessionRegistry {
update(sessionID: session.sessionID) { rec in
if rec.surfaceID == nil { rec.surfaceID = session.surfaceID }
if rec.workspaceID == nil { rec.workspaceID = session.workspaceID }
if rec.workingDirectory == nil { rec.workingDirectory = session.workingDirectory }
if rec.transcriptPath == nil { rec.transcriptPath = session.transcriptPath }
if rec.pid == nil { rec.pid = session.pid }
}
Expand All @@ -212,25 +214,41 @@ final class AgentChatSessionRegistry {
includeProcessDetails: true,
includeCMUXScope: true
)
return scanObservedAgentSessions(
in: snapshot,
processArgumentsAndEnvironment: CmuxTopProcessSnapshot.processArgumentsAndEnvironment(for:),
codexRolloutPath: openCodexRolloutPath(pid:)
)
}

nonisolated static func scanObservedAgentSessions(
in snapshot: CmuxTopProcessSnapshot,
processArgumentsAndEnvironment: (Int) -> CmuxTopProcessArguments?,
codexRolloutPath: (Int) -> String?
Comment thread
azooz2003-bit marked this conversation as resolved.
Resolved
) -> [ObservedAgentSession] {
var result: [ObservedAgentSession] = []
var seen = Set<String>()
for process in snapshot.cmuxScopedProcesses() {
let details = processArgumentsAndEnvironment(process.pid)
guard let surfaceID = process.cmuxSurfaceID,
let def = CmuxTaskManagerCodingAgentDefinition.matchingDefinition(
processName: process.name,
processPath: process.path,
arguments: [],
environment: [:]
let def = codingAgentDefinition(
for: process,
processArgumentsAndEnvironment: { _ in details }
),
def.id == "codex" || def.id == "claude" else { continue }
var sessionID: String?
var transcriptPath: String?
if def.id == "codex", let rollout = openCodexRolloutPath(pid: process.pid) {
if def.id == "codex", let rollout = codexRolloutPath(process.pid) {
transcriptPath = rollout
sessionID = firstUUIDLike(in: (rollout as NSString).lastPathComponent)
}
if def.id == "claude",
let envSessionID = details?.environment["CLAUDE_CODE_SESSION_ID"],
let id = firstUUIDLike(in: envSessionID) {
sessionID = id
}
if sessionID == nil,
let argv = CmuxTopProcessSnapshot.processArgumentsAndEnvironment(for: process.pid)?.arguments {
let argv = details?.arguments {
sessionID = sessionIDFromArguments(argv)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
guard let resolved = sessionID, !seen.contains(resolved) else { continue }
Expand All @@ -241,12 +259,56 @@ final class AgentChatSessionRegistry {
surfaceID: surfaceID.uuidString,
workspaceID: process.cmuxWorkspaceID?.uuidString,
pid: process.pid,
workingDirectory: observedWorkingDirectory(details?.environment),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
transcriptPath: transcriptPath
))
}
return result
}

private nonisolated static func codingAgentDefinition(
for process: CmuxTopProcessInfo,
processArgumentsAndEnvironment: (Int) -> CmuxTopProcessArguments?
) -> CmuxTaskManagerCodingAgentDefinition? {
let shouldReadDetails = CmuxTaskManagerCodingAgentDefinition.shouldReadArguments(
processName: process.name,
processPath: process.path
)
if let direct = CmuxTaskManagerCodingAgentDefinition.matchingDefinition(
processName: process.name,
processPath: process.path,
arguments: [],
environment: [:]
), !shouldReadDetails {
return direct
}
guard let details = processArgumentsAndEnvironment(process.pid) else {
return CmuxTaskManagerCodingAgentDefinition.matchingDefinition(
processName: process.name,
processPath: process.path,
arguments: [],
environment: [:]
)
Comment thread
azooz2003-bit marked this conversation as resolved.
Resolved
}
return CmuxTaskManagerCodingAgentDefinition.matchingDefinition(
processName: process.name,
processPath: process.path,
arguments: details.arguments,
environment: details.environment
)
}

private nonisolated static func observedWorkingDirectory(_ environment: [String: String]?) -> String? {
guard let environment else { return nil }
for key in ["CMUX_AGENT_LAUNCH_CWD", "PWD"] {
if let value = environment[key]?.trimmingCharacters(in: .whitespacesAndNewlines),
!value.isEmpty {
return value
}
}
return nil
}

/// libproc: the path of a `~/.codex/sessions/**/rollout-*.jsonl` the process
/// holds open (codex keeps its rollout open for writing), or nil.
private nonisolated static func openCodexRolloutPath(pid: Int) -> String? {
Expand Down
106 changes: 106 additions & 0 deletions cmuxTests/TaskManagerResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,87 @@ final class TaskManagerResourcesTests: XCTestCase {
)
}

func testMobileChatObserverDetectsNodeHostedClaudeFromProcessDetails() throws {
let workspaceID = UUID()
let surfaceID = UUID()
let sessionID = "24ec0052-450c-4914-b1dd-2ee80d4bc84b"
let snapshot = CmuxTopProcessSnapshot(
processes: [
topProcess(
pid: 101,
name: "node",
path: "/opt/homebrew/bin/node",
workspaceID: workspaceID,
surfaceID: surfaceID
)
],
sampledAt: Date(timeIntervalSince1970: 100),
includesProcessDetails: true
)

let observed = AgentChatSessionRegistry.scanObservedAgentSessions(
in: snapshot,
processArgumentsAndEnvironment: { pid in
guard pid == 101 else { return nil }
return CmuxTopProcessArguments(
arguments: [
"node",
"/Users/example/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js",
],
environment: [
"CLAUDE_CODE_SESSION_ID": sessionID,
"CMUX_AGENT_LAUNCH_CWD": "/Users/example/project",
]
)
},
codexRolloutPath: { _ in nil }
)

let session = try XCTUnwrap(observed.first)
XCTAssertEqual(observed.count, 1)
XCTAssertEqual(session.sessionID, sessionID)
XCTAssertEqual(session.agentKind, .claude)
XCTAssertEqual(session.workspaceID, workspaceID.uuidString)
XCTAssertEqual(session.surfaceID, surfaceID.uuidString)
XCTAssertEqual(session.pid, 101)
XCTAssertEqual(session.workingDirectory, "/Users/example/project")
}

func testMobileChatObserverStillDetectsDirectCodexFromRolloutFile() throws {
let workspaceID = UUID()
let surfaceID = UUID()
let sessionID = "018ff5fe-3f91-79d0-99aa-a6a2d7c17b22"
let rolloutPath = "/Users/example/.codex/sessions/2026/06/29/rollout-2026-06-29T12-00-00-\(sessionID).jsonl"
let snapshot = CmuxTopProcessSnapshot(
processes: [
topProcess(
pid: 202,
name: "codex",
path: "/opt/homebrew/bin/codex",
workspaceID: workspaceID,
surfaceID: surfaceID
)
],
sampledAt: Date(timeIntervalSince1970: 200),
includesProcessDetails: true
)

let observed = AgentChatSessionRegistry.scanObservedAgentSessions(
in: snapshot,
processArgumentsAndEnvironment: { _ in nil },
codexRolloutPath: { pid in pid == 202 ? rolloutPath : nil }
)

let session = try XCTUnwrap(observed.first)
XCTAssertEqual(observed.count, 1)
XCTAssertEqual(session.sessionID, sessionID)
XCTAssertEqual(session.agentKind, .codex)
XCTAssertEqual(session.workspaceID, workspaceID.uuidString)
XCTAssertEqual(session.surfaceID, surfaceID.uuidString)
XCTAssertEqual(session.pid, 202)
XCTAssertEqual(session.transcriptPath, rolloutPath)
}

func testCodingAgentMatcherCoversSupportedAgentExecutableNames() {
let cases: [(processName: String, expectedId: String)] = [
("claude_code", "claude"),
Expand Down Expand Up @@ -637,6 +718,31 @@ final class TaskManagerResourcesTests: XCTestCase {
)
}

private func topProcess(
pid: Int,
name: String,
path: String?,
workspaceID: UUID,
surfaceID: UUID
) -> CmuxTopProcessInfo {
CmuxTopProcessInfo(
pid: pid,
parentPID: 1,
name: name,
path: path,
ttyDevice: nil,
cmuxWorkspaceID: workspaceID,
cmuxSurfaceID: surfaceID,
cmuxAttributionReason: "test",
processGroupID: nil,
terminalProcessGroupID: nil,
cpuPercent: 0,
residentBytes: 1,
virtualBytes: 1,
threadCount: 1
)
}

private func assertUnmodifiedAttributedPayload(
_ payload: [String: Any],
file: StaticString = #filePath,
Expand Down
Loading