blob: ebfdb3938470788e0a0f8166058693894fda18bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# managed by herdr; reinstalling the integration replaces this file.
# HERDR_INTEGRATION_ID=cursor
# HERDR_INTEGRATION_VERSION=1
param([string]$Action = "")
function Exit-Hook {
Write-Output "{}"
exit 0
}
if ($Action -ne "session") { Exit-Hook }
if ($env:HERDR_ENV -ne "1") { Exit-Hook }
if ([string]::IsNullOrWhiteSpace($env:HERDR_PANE_ID)) { Exit-Hook }
$inputText = [Console]::In.ReadToEnd()
$jsonStart = $inputText.IndexOf("{")
if ($jsonStart -gt 0) {
$inputText = $inputText.Substring($jsonStart)
}
try {
$payload = if ([string]::IsNullOrWhiteSpace($inputText)) { $null } else { $inputText | ConvertFrom-Json }
} catch {
Exit-Hook
}
if ($null -eq $payload) { Exit-Hook }
$event = if ($payload.hook_event_name -is [string]) { $payload.hook_event_name } else { $payload.hookEventName }
if (-not [string]::IsNullOrWhiteSpace($event) -and $event -ne "sessionStart") { Exit-Hook }
$sessionId = $null
foreach ($name in @("session_id", "sessionId", "conversation_id", "conversationId")) {
$value = $payload.$name
if ($value -is [string] -and -not [string]::IsNullOrWhiteSpace($value)) {
$sessionId = $value
break
}
}
if ([string]::IsNullOrWhiteSpace($sessionId)) { Exit-Hook }
$seq = [DateTime]::UtcNow.Ticks
$herdr = if ([string]::IsNullOrWhiteSpace($env:HERDR_BIN_PATH)) { "herdr" } else { $env:HERDR_BIN_PATH }
try {
& $herdr pane report-agent-session $env:HERDR_PANE_ID --source herdr:cursor --agent cursor --seq $seq --agent-session-id $sessionId 2>$null | Out-Null
} catch {
}
Exit-Hook
|