|
| 1 | +/** |
| 2 | + * PostHog-specific ACP extensions. |
| 3 | + * |
| 4 | + * These follow the ACP extensibility model: |
| 5 | + * - Custom notification methods are prefixed with `_posthog/` |
| 6 | + * - Custom data can be attached via `_meta` fields |
| 7 | + * |
| 8 | + * Note: When using `extNotification()` from the ACP SDK, it automatically |
| 9 | + * adds an extra underscore prefix (e.g., `_posthog/tree_snapshot` becomes |
| 10 | + * `__posthog/tree_snapshot` in the log). Code that reads logs should handle both. |
| 11 | + * |
| 12 | + * See: https://agentclientprotocol.com/docs/extensibility |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * Custom notification methods for PostHog-specific events. |
| 17 | + * Used with AgentSideConnection.extNotification() or Client.extNotification() |
| 18 | + */ |
| 19 | +export const POSTHOG_NOTIFICATIONS = { |
| 20 | + /** Git branch was created for a task */ |
| 21 | + BRANCH_CREATED: "_posthog/branch_created", |
| 22 | + |
| 23 | + /** Task run has started execution */ |
| 24 | + RUN_STARTED: "_posthog/run_started", |
| 25 | + |
| 26 | + /** Task has completed (success or failure) */ |
| 27 | + TASK_COMPLETE: "_posthog/task_complete", |
| 28 | + |
| 29 | + /** Error occurred during task execution */ |
| 30 | + ERROR: "_posthog/error", |
| 31 | + |
| 32 | + /** Console/log output from the agent */ |
| 33 | + CONSOLE: "_posthog/console", |
| 34 | + |
| 35 | + /** Maps a session ID to the underlying SDK session ID (for resumption) */ |
| 36 | + SDK_SESSION: "_posthog/sdk_session", |
| 37 | + |
| 38 | + /** Tree state snapshot captured (git tree hash + file archive) */ |
| 39 | + TREE_SNAPSHOT: "_posthog/tree_snapshot", |
| 40 | + |
| 41 | + /** Agent mode changed (interactive/background) */ |
| 42 | + MODE_CHANGE: "_posthog/mode_change", |
| 43 | + |
| 44 | + /** Request to resume a session from previous state */ |
| 45 | + SESSION_RESUME: "_posthog/session/resume", |
| 46 | + |
| 47 | + /** User message sent from client to agent */ |
| 48 | + USER_MESSAGE: "_posthog/user_message", |
| 49 | + |
| 50 | + /** Request to cancel current operation */ |
| 51 | + CANCEL: "_posthog/cancel", |
| 52 | + |
| 53 | + /** Request to close the session */ |
| 54 | + CLOSE: "_posthog/close", |
| 55 | + |
| 56 | + /** Agent status update (thinking, working, etc.) */ |
| 57 | + STATUS: "_posthog/status", |
| 58 | + |
| 59 | + /** Task-level notification (progress, milestones) */ |
| 60 | + TASK_NOTIFICATION: "_posthog/task_notification", |
| 61 | + |
| 62 | + /** Marks a boundary for log compaction */ |
| 63 | + COMPACT_BOUNDARY: "_posthog/compact_boundary", |
| 64 | +} as const; |
| 65 | + |
| 66 | +export type PostHogNotificationType = |
| 67 | + (typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS]; |
| 68 | + |
| 69 | +// --- Payload types for each notification --- |
| 70 | + |
| 71 | +export interface BranchCreatedPayload { |
| 72 | + branch: string; |
| 73 | +} |
| 74 | + |
| 75 | +export interface RunStartedPayload { |
| 76 | + sessionId: string; |
| 77 | + runId: string; |
| 78 | + taskId?: string; |
| 79 | +} |
| 80 | + |
| 81 | +export interface TaskCompletePayload { |
| 82 | + sessionId: string; |
| 83 | + taskId: string; |
| 84 | +} |
| 85 | + |
| 86 | +export interface ErrorNotificationPayload { |
| 87 | + sessionId: string; |
| 88 | + message: string; |
| 89 | + error?: unknown; |
| 90 | +} |
| 91 | + |
| 92 | +export interface ConsoleNotificationPayload { |
| 93 | + sessionId: string; |
| 94 | + level: "debug" | "info" | "warn" | "error"; |
| 95 | + message: string; |
| 96 | +} |
| 97 | + |
| 98 | +export interface SdkSessionPayload { |
| 99 | + sessionId: string; |
| 100 | + sdkSessionId: string; |
| 101 | +} |
| 102 | + |
| 103 | +export interface TreeSnapshotPayload { |
| 104 | + treeHash: string; |
| 105 | + baseCommit: string | null; |
| 106 | + archiveUrl?: string; |
| 107 | + filesChanged: string[]; |
| 108 | + filesDeleted?: string[]; |
| 109 | + timestamp: string; |
| 110 | + interrupted?: boolean; |
| 111 | + device?: { |
| 112 | + type: "local" | "cloud"; |
| 113 | + name?: string; |
| 114 | + }; |
| 115 | +} |
| 116 | + |
| 117 | +export interface ModeChangePayload { |
| 118 | + mode: "interactive" | "background"; |
| 119 | + previous_mode: "interactive" | "background"; |
| 120 | +} |
| 121 | + |
| 122 | +export interface SessionResumePayload { |
| 123 | + sessionId: string; |
| 124 | + fromSnapshot?: string; |
| 125 | +} |
| 126 | + |
| 127 | +export interface UserMessagePayload { |
| 128 | + content: string; |
| 129 | +} |
| 130 | + |
| 131 | +export interface StatusPayload { |
| 132 | + sessionId: string; |
| 133 | + status: string; |
| 134 | + message?: string; |
| 135 | +} |
| 136 | + |
| 137 | +export interface TaskNotificationPayload { |
| 138 | + sessionId: string; |
| 139 | + type: string; |
| 140 | + message?: string; |
| 141 | + data?: Record<string, unknown>; |
| 142 | +} |
| 143 | + |
| 144 | +export interface CompactBoundaryPayload { |
| 145 | + sessionId: string; |
| 146 | + timestamp: string; |
| 147 | +} |
| 148 | + |
| 149 | +export type PostHogNotificationPayload = |
| 150 | + | BranchCreatedPayload |
| 151 | + | RunStartedPayload |
| 152 | + | TaskCompletePayload |
| 153 | + | ErrorNotificationPayload |
| 154 | + | ConsoleNotificationPayload |
| 155 | + | SdkSessionPayload |
| 156 | + | TreeSnapshotPayload |
| 157 | + | ModeChangePayload |
| 158 | + | SessionResumePayload |
| 159 | + | UserMessagePayload |
| 160 | + | StatusPayload |
| 161 | + | TaskNotificationPayload |
| 162 | + | CompactBoundaryPayload; |
0 commit comments