Skip to content

feat(cloud-agent): add PostHog tracking for remote session events#1767

Merged
eshurakov merged 1 commit intomainfrom
eshurakov/cloud-agent-remote-tracking
Mar 31, 2026
Merged

feat(cloud-agent): add PostHog tracking for remote session events#1767
eshurakov merged 1 commit intomainfrom
eshurakov/cloud-agent-remote-tracking

Conversation

@eshurakov
Copy link
Copy Markdown
Contributor

Summary

Adds PostHog analytics tracking for remote (CLI) session interactions. Two new optional callbacks are introduced in the session manager:

  • onRemoteSessionOpened — fires when a CLI session becomes active and is ready to accept input
  • onRemoteSessionMessageSent — fires after a message is successfully sent to a CLI session

These callbacks are wired in CloudAgentProvider to capture remote_session_opened and remote_session_message_sent PostHog events, each tagged with feature: 'remote-session' and the kilo_session_id. A stable useRef wrapper around the PostHog instance avoids stale-closure issues in the one-time manager initialization block.

Verification

  • Code review — no issues found
  • pnpm typecheck — passed, no type errors
  • pnpm test — 159 tests passed (session-manager + cloud-agent-next), 0 failures

Visual Changes

N/A

Reviewer Notes

  • The onRemoteSessionOpened callback fires inside onFirstActivity in switchSession, gated by !data.cloudAgentSessionId && session.canSend — this correctly limits it to CLI sessions that are live and interactive.
  • The onRemoteSessionMessageSent callback fires in send() after a successful currentSession.send(...), gated by !fetchedData.cloudAgentSessionId to scope it to remote sessions only.
  • Both callbacks are optional, so there is no impact on existing consumers of createSessionManager.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Mar 31, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • src/components/cloud-agent-next/CloudAgentProvider.tsx
  • src/lib/cloud-agent-sdk/session-manager.ts
  • src/lib/cloud-agent-sdk/session.ts

Reviewed by gpt-5.4-20260305 · 1,962,217 tokens

@eshurakov eshurakov force-pushed the eshurakov/cloud-agent-remote-tracking branch from 433f22f to 700e5ef Compare March 31, 2026 13:30
Add onResolved callback to CloudAgentSession that fires after transport
resolution, giving the session manager access to the authoritative
ResolvedSession. Use this to track an ActiveSessionType ('cloud-agent'
| 'cli') and emit PostHog analytics events (remote_session_opened,
remote_session_message_sent) for live CLI sessions.
@eshurakov eshurakov force-pushed the eshurakov/cloud-agent-remote-tracking branch from 700e5ef to 848b151 Compare March 31, 2026 19:24
@eshurakov eshurakov merged commit e847e79 into main Mar 31, 2026
15 checks passed
@eshurakov eshurakov deleted the eshurakov/cloud-agent-remote-tracking branch March 31, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants