metallkart-erp/scripts/send-task.ps1
2026-04-08 15:48:24 +03:00

96 lines
3.3 KiB
PowerShell

#!/usr/bin/env pwsh
# send-task.ps1 — Envoie une spec au pipeline (local ou VPS)
# Usage: .\send-task.ps1 "contenu de la spec inline"
# Usage: .\send-task.ps1 -File specs\ma-spec.md
# Usage: .\send-task.ps1 -File specs\ma-spec.md -Mode orchestrator
# Usage: .\send-task.ps1 -File specs\ma-spec.md -Target vps
#
# Modes: simple (dev-task.ps1) | orchestrator (orchestrator.ps1)
# Targets: local (defaut) | vps (envoie au VPS via SCP)
param(
[Parameter(Position=0)]
[string]$Inline,
[string]$File,
[ValidateSet("simple","orchestrator")]
[string]$Mode = "simple",
[ValidateSet("local","vps")]
[string]$Target = "local",
[switch]$NoCommit,
[switch]$NoPush,
[switch]$Background
)
$REPO = "C:\Projects\metallkart-erp"
$SCRIPTS = "$REPO\scripts"
$VPS = "root@76.13.55.81"
# --- Resolve spec content ---
$specPath = ""
if ($File) {
if (-not [System.IO.Path]::IsPathRooted($File)) {
$File = Join-Path $REPO $File
}
if (-not (Test-Path $File)) {
Write-Host "ERREUR: $File introuvable" -ForegroundColor Red
exit 1
}
$specPath = $File
$specName = [System.IO.Path]::GetFileNameWithoutExtension($File)
} elseif ($Inline) {
# Write inline spec to file
$specName = "inline-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
$specPath = Join-Path $REPO "specs\$specName.md"
[System.IO.File]::WriteAllText($specPath, $Inline, [System.Text.Encoding]::UTF8)
Write-Host "Spec ecrite: $specPath" -ForegroundColor Cyan
} else {
Write-Host "Usage: send-task.ps1 'spec inline' ou -File specs\ma-spec.md" -ForegroundColor Red
exit 1
}
Write-Host "Task: $specName | Mode: $Mode | Target: $Target" -ForegroundColor Cyan
# --- Execute ---
if ($Target -eq "vps") {
# Encode spec and send to VPS queue
$specContent = Get-Content $specPath -Raw
$b64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($specContent))
$taskId = "$specName-$(Get-Date -Format 'yyyyMMddHHmmss')"
$taskJson = @{
task_id = $taskId
project = "metallkart-erp"
project_dir = "/opt/erp/metallkart-erp"
spec_b64 = $b64
mode = $Mode
created_at = (Get-Date -Format "o")
} | ConvertTo-Json -Compress
$tmpTask = "$env:TEMP\task-$taskId.json"
[System.IO.File]::WriteAllText($tmpTask, $taskJson, [System.Text.Encoding]::UTF8)
scp $tmpTask "${VPS}:/opt/win-terminal/queue/$taskId.json" 2>$null
ssh $VPS "/opt/win-terminal/poll-update.sh" 2>$null
Remove-Item $tmpTask -Force -ErrorAction SilentlyContinue
Write-Host "Envoye au VPS: $taskId" -ForegroundColor Green
& "$SCRIPTS\notify-telegram.ps1" "ENVOI Task $taskId au VPS ($Mode)"
} else {
# Local execution
$script = if ($Mode -eq "orchestrator") { "orchestrator.ps1" } else { "dev-task.ps1" }
$taskArgs = @($specPath)
if ($NoCommit) { $taskArgs += "-NoCommit" }
if ($NoPush) { $taskArgs += "-NoPush" }
if ($Background) {
Write-Host "Lancement en background..." -ForegroundColor Yellow
Start-Process powershell.exe -ArgumentList @(
"-NoProfile", "-ExecutionPolicy", "Bypass",
"-File", "$SCRIPTS\$script"
) + $taskArgs -NoNewWindow
Write-Host "Process lance. Logs dans $REPO\logs\" -ForegroundColor Green
} else {
& "$SCRIPTS\$script" @args
}
}