Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
feat: detect active sessions via JSONL file growth + hook state
libokai6c54ea9e060d
diff --git a/CodePulse-macOS/Services/SessionStateManager.swift b/CodePulse-macOS/Services/SessionStateManager.swiftindex 343275a8..f420928c 100644--- a/CodePulse-macOS/Services/SessionStateManager.swift+++ b/CodePulse-macOS/Services/SessionStateManager.swift@@ -10,12 +10,15 @@ final class SessionStateManager: ObservableObject {@Published var sessions: [SessionState] = []private let scanner: SessionScanner- /// Reference to hook server for real-time Claude statevar hookServer: ClaudeHookServer?private var cancellables = Set<AnyCancellable>()private let deviceId = Host.current().localizedName ?? UUID().uuidString+ /// Track JSONL file sizes to detect growth (= session is active)+ private var jsonlSizes: [String: UInt64] = [:]+ private var jsonlLastGrowth: [String: Date] = [:]+init(scanner: SessionScanner) {self.scanner = scannerscanner.$activeSessions@@ -37,8 +40,10 @@ final class SessionStateManager: ObservableObject {let jsonlInfo = JSONLTailReader.extractInfo(url: jsonlUrl)let hookInfo = hookSessions[sessionId]- // Use hook state as primary source of truth (like Command app)- let status = detectStatus(sessionId: sessionId, raw: raw, tasks: tasks, hookState: hookInfo?.state)+ // Track JSONL file growth+ let jsonlGrowing = updateJsonlGrowth(sessionId: sessionId, url: jsonlUrl)++ let status = detectStatus(sessionId: sessionId, raw: raw, tasks: tasks, hookState: hookInfo?.state, jsonlGrowing: jsonlGrowing)let projectName = URL(fileURLWithPath: raw.cwd).lastPathComponentlet startDate = Date(timeIntervalSince1970: TimeInterval(raw.startedAt) / 1000)@@ -80,7 +85,6 @@ final class SessionStateManager: ObservableObject {updated.append(session)}- // Mark recently disappeared sessions as completedfor existing in sessions where existing.status != .completed {if !rawSessions.keys.contains(existing.sessionId) {var completed = existing@@ -96,23 +100,53 @@ final class SessionStateManager: ObservableObject {}}- private func detectStatus(sessionId: String, raw: RawSessionFile, tasks: [TaskItem], hookState: ClaudeState?) -> SessionStatus {+ /// Returns true if JSONL file has grown recently (within last 10 seconds)+ private func updateJsonlGrowth(sessionId: String, url: URL) -> Bool {+ let currentSize = JSONLTailReader.fileSize(url: url) ?? 0+ let previousSize = jsonlSizes[sessionId] ?? 0++ if currentSize != previousSize {+ jsonlSizes[sessionId] = currentSize+ jsonlLastGrowth[sessionId] = Date()+ return true+ }++ // Consider "growing" if file changed in last 10 seconds+ if let lastGrowth = jsonlLastGrowth[sessionId] {+ return Date().timeIntervalSince(lastGrowth) < 10+ }++ // First time seeing this session — record size, don't report as growing+ jsonlSizes[sessionId] = currentSize+ return false+ }++ private func detectStatus(sessionId: String, raw: RawSessionFile, tasks: [TaskItem], hookState: ClaudeState?, jsonlGrowing: Bool) -> SessionStatus {// 1. PID dead → completedguard PIDChecker.isAlive(pid: raw.pid) else { return .completed }- // 2. Hook state is the primary source of truth (real-time from Claude Code)+ // 2. Hook state is the primary source of truthif let hookState {switch hookState {- case .working: return .working- case .waitingForUser: return .needsInput- case .needsPermission: return .needsInput+ case .working:+ return .working+ case .waitingForUser, .needsPermission:+ // BUT if JSONL is growing, Claude is actually responding+ // (user sent message or Claude is generating text without tools)+ if jsonlGrowing {+ return .working+ }+ return hookState == .needsPermission ? .needsInput : .needsInput}}- // 3. Fallback: check tasks (for sessions started before CodePulse)+ // 3. JSONL growing = something is happening+ if jsonlGrowing { return .working }++ // 4. Fallback: check tasksif tasks.contains(where: { $0.status == .inProgress }) { return .working }- // 4. No hook data, no active tasks → idle+ // 5. No signal at all → idlereturn .idle}