summaryrefslogtreecommitdiff
path: root/scripts/Read-AgentLog.ps1
blob: f842e45855b813c2f9393f298876300199a9e36d (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
param(
    [Parameter(Mandatory = $true)]
    [string]$Path,
    [string]$TaskId,
    [string]$SessionId,
    [string]$Event,
    [string]$CallId,
    [ValidateRange(1, 100000)]
    [int]$Tail = 200
)

$ErrorActionPreference = 'Stop'
$resolvedLog = (Resolve-Path -LiteralPath $Path).Path
Get-Content -LiteralPath $resolvedLog -Tail $Tail | ForEach-Object {
    try { $entry = $_ | ConvertFrom-Json -ErrorAction Stop }
    catch { return }

    $entryTaskId = $entry.task_id ?? $entry.taskId
    $entrySessionId = $entry.session_id ?? $entry.sessionId
    if ($TaskId -and [string]$entryTaskId -ne $TaskId) { return }
    if ($SessionId -and [string]$entrySessionId -ne $SessionId) { return }
    if ($Event -and [string]$entry.event_name -ne $Event -and [string]$entry.event -ne $Event) { return }
    if ($CallId -and [string]$entry.call_id -ne $CallId) { return }

    [pscustomobject]@{
        timestamp = $entry.timestamp ?? $entry.ts
        event = $entry.event_name ?? $entry.event
        task_id = $entryTaskId
        session_id = $entrySessionId
        call_id = $entry.call_id
        phase = $entry.phase
        iteration = $entry.iteration
        replan = $entry.replan
        tool = $entry.tool_name
        success = $entry.success
        output = $entry.output
    }
} | Format-Table -AutoSize -Wrap