feat(hayabusa): add auto-case scoring and 6h automation

This commit is contained in:
igor04091968
2026-05-21 20:47:49 +03:00
parent 4e4898828b
commit 0c88b519ee
22 changed files with 757 additions and 32 deletions
@@ -1,8 +1,9 @@
[CmdletBinding()]
param(
[string]$ConfigPath = 'C:\ProgramData\AWatch-rus\deployment-config.json',
[Nullable[int]]$HoursBack,
[int]$DaysBack = 1,
[string]$ServerHost = '10.10.10.13',
[string]$ServerHost = '',
[string]$ServerUser = 'awops',
[string]$RemoteDropDir = '/opt/activitywatch/aw-rus-ops/drop',
[string]$RemoteKeyPath = 'C:\ProgramData\AWatch-rus\ssh\awops_ed25519',
@@ -41,7 +42,23 @@ if (-not (Test-Path -LiteralPath $RemoteKeyPath)) {
throw "SSH private key not found: $RemoteKeyPath"
}
$export = & $exportScript -ConfigPath $ConfigPath -DaysBack $DaysBack
$config = Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json
if ([string]::IsNullOrWhiteSpace($ServerHost)) {
$ServerHost = [string]$config.server.host
}
if ([string]::IsNullOrWhiteSpace($ServerHost)) {
throw "ServerHost is empty and deployment-config has no server.host: $ConfigPath"
}
$exportArgs = @{
ConfigPath = $ConfigPath
}
if ($null -ne $HoursBack) {
$exportArgs.HoursBack = [int]$HoursBack
} else {
$exportArgs.DaysBack = $DaysBack
}
$export = & $exportScript @exportArgs
$zipPath = [string]$export.zipPath
$hostName = [string]$export.hostname
if ([string]::IsNullOrWhiteSpace($zipPath) -or -not (Test-Path -LiteralPath $zipPath)) {
@@ -52,9 +69,23 @@ $zipName = Split-Path -Leaf $zipPath
$remoteTarget = "$ServerUser@$ServerHost`:$RemoteDropDir/"
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($zipPath)
$caseIdPath = Join-Path ([System.IO.Path]::GetDirectoryName($zipPath)) ($baseName + '.caseid')
$metaPath = Join-Path ([System.IO.Path]::GetDirectoryName($zipPath)) ($baseName + '.meta.json')
$effectiveKeyPath = New-TemporarySshKeyCopy -SourceKeyPath $RemoteKeyPath
try {
$meta = [ordered]@{
host = $hostName
mode = $Mode
link_source = 'windows-drop-upload'
}
if ($null -ne $CaseId) {
$meta.case_id = [int]$CaseId
}
$meta | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $metaPath -Encoding UTF8
& scp.exe -i $effectiveKeyPath -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL $metaPath $remoteTarget
if ($LASTEXITCODE -ne 0) {
throw "scp meta upload failed with rc=$LASTEXITCODE"
}
if ($null -ne $CaseId) {
Set-Content -LiteralPath $caseIdPath -Value ([string]$CaseId) -Encoding ASCII
& scp.exe -i $effectiveKeyPath -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL $caseIdPath $remoteTarget
@@ -69,12 +100,14 @@ try {
}
finally {
Remove-Item -LiteralPath $effectiveKeyPath -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $metaPath -Force -ErrorAction SilentlyContinue
}
$result = [ordered]@{
exportedZip = $zipPath
uploadedTo = "$RemoteDropDir/$zipName"
caseIdSidecar = if ($null -ne $CaseId) { "$RemoteDropDir/$baseName.caseid" } else { $null }
metaSidecar = "$RemoteDropDir/$baseName.meta.json"
hostname = $hostName
mode = $Mode
runRemote = [bool]$RunRemote