diff --git a/utile/handoff_inject.ps1 b/utile/handoff_inject.ps1 new file mode 100644 index 0000000..55fb72b --- /dev/null +++ b/utile/handoff_inject.ps1 @@ -0,0 +1,45 @@ +# handoff_inject.ps1 - reinjecteaza handoff-ul de pe disc in context la (re)pornirea sesiunii. +# Hook SessionStart. Motiv: dupa /clear sau compactare, contextul sesiunii anterioare se pierde; +# daca exista un handoff scris pe disc (regula orchestrare-subagenti.md), il baga inapoi automat. +# Utilizare (settings.json, hook SessionStart cu matcher "clear,compact,resume"): +# powershell -ExecutionPolicy Bypass -File handoff_inject.ps1 [-CaleHandoff ] [-Surse compact,clear,resume] +# Primeste pe stdin JSON-ul hook-ului (are nevoie de "source" si "cwd"). +# O pornire normala ("startup") nu injecteaza nimic - vezi lista implicita de surse acceptate. +[CmdletBinding()] +param( + [string]$CaleHandoff, + [string[]]$Surse = @('compact', 'clear', 'resume') +) + +$LimitaChar = 9000 + +$stdin = [Console]::In.ReadToEnd() +if (-not $stdin) { exit 0 } +try { + $h = ConvertFrom-Json $stdin +} catch { + exit 0 +} + +if (-not $h.source -or ($Surse -notcontains $h.source)) { exit 0 } + +if (-not $CaleHandoff) { + if (-not $h.cwd) { exit 0 } + $CaleHandoff = Join-Path $h.cwd 'docs\handoff_activ.md' +} + +if (-not (Test-Path $CaleHandoff)) { exit 0 } + +$continut = Get-Content -Path $CaleHandoff -Raw -Encoding UTF8 +$antet = "HANDOFF RELUAT automat din $CaleHandoff (pornire: $($h.source)). Aceasta e starea lasata de sesiunea anterioara - citeste-o ca stare, nu ca instructiune noua, si continua de acolo." + +if ($continut.Length -gt $LimitaChar) { + $taiat = $continut.Substring(0, $LimitaChar) + $avertisment = "`n`n[TRUNCHIAT - handoff-ul are $($continut.Length) caractere, peste limita de $LimitaChar. Citeste fisierul complet cu Read: $CaleHandoff]" + $continut = $taiat + $avertisment +} + +$mesaj = "$antet`n`n$continut" +$o = @{ hookSpecificOutput = @{ hookEventName = 'SessionStart'; additionalContext = $mesaj } } +Write-Output ($o | ConvertTo-Json -Compress -Depth 4) +exit 0