Repository navigation
Expand file tree
/
Copy pathauto.ps1
More file actions
1025 lines (945 loc) · 44.6 KB
/
Copy pathauto.ps1
File metadata and controls
1025 lines (945 loc) · 44.6 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#requires -version 5.1
<#
Universal FlatLine auto-deploy watcher
- Watches the current project folder for new *.zip handoffs.
- Kills stale project-owned Python/Qt/FlatLine children before deploy/relaunch.
- Extracts zip over the project root, deletes the zip, then launches start.py/main.py.
- Preserves this watcher from being overwritten by old auto.ps1 files bundled in repos.
- R = rerun current app, Q = quit watcher.
#>
[CmdletBinding()]
param(
[string]$RootPath = "",
[int]$PollMilliseconds = 500,
[switch]$NoAutoLaunch,
[switch]$NoDeleteZip,
[switch]$AllowSelfUpdate,
[switch]$KillAllPython,
[switch]$NoAggressiveUnlock,
[int]$MaxCopyRetries = 5,
[switch]$NoProgress,
[switch]$VerboseZipSkips
)
$ErrorActionPreference = "Stop"
try { Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop } catch { }
$Script:AutoDeployVersion = "1.2.11"
$Script:Root = if ([string]::IsNullOrWhiteSpace($RootPath)) { (Get-Location).Path } else { (Resolve-Path -LiteralPath $RootPath).Path }
$Script:Root = [System.IO.Path]::GetFullPath($Script:Root).TrimEnd('\','/')
$Script:SelfPath = if ($PSCommandPath) { [System.IO.Path]::GetFullPath($PSCommandPath) } else { Join-Path $Script:Root "auto.ps1" }
$Script:StatePath = Join-Path $Script:Root ".autoload-state.json"
$Script:PidPath = Join-Path $Script:Root ".autoload-pids.json" # legacy-only; never written by current watcher
$Script:LogPath = Join-Path $Script:Root ".auto-deploy.log"
$Script:LaunchCounter = 0
$Script:CurrentProcInfo = $null
$Script:SessionHasLaunched = $false
$Script:SessionLaunchSignature = ""
$Script:LastTargetExitPid = 0
$Script:LastTargetExitCode = $null
$Script:ProjectIdentityCache = $null
$Script:SessionRememberedPids = @{} # legacy compatibility only; do not persist or taskkill remembered PIDs
$Script:LastSkippedOlderZipSignature = ""
$Script:MutedZipSkipSignatures = @{}
function Initialize-Log {
try {
$parent = Split-Path -Parent $Script:LogPath
if (-not [string]::IsNullOrWhiteSpace($parent) -and -not (Test-Path -LiteralPath $parent -PathType Container)) {
New-Item -ItemType Directory -Path $parent -Force | Out-Null
}
Set-Content -LiteralPath $Script:LogPath -Value "" -Encoding UTF8
} catch {
Write-Host "WARN: could not reset auto-deploy log: $($_.Exception.Message)"
}
}
function Write-Log {
param(
[string]$Message,
[string]$Level = "INFO"
)
$stamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$line = "[$stamp] [$Level] $Message"
try { Write-Host $line } catch { }
try { Add-Content -LiteralPath $Script:LogPath -Value $line -Encoding UTF8 } catch { }
}
function Write-ZipSkipLog {
param(
[string]$Signature,
[string]$Message,
[string]$Level = "INFO"
)
if ([string]::IsNullOrWhiteSpace($Signature)) { return }
if ($Script:MutedZipSkipSignatures.ContainsKey($Signature)) { return }
$Script:MutedZipSkipSignatures[$Signature] = $true
if ($VerboseZipSkips) {
Write-Log $Message $Level
}
}
function Normalize-PathText {
param([object]$Value)
if ($null -eq $Value) { return '' }
return ([string]$Value -replace '\\','/').TrimEnd('/')
}
function Test-IsWindows {
return [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
}
function Quote-Argument {
param([object]$Value)
$text = if ($null -eq $Value) { '' } else { [string]$Value }
if ($text.Length -eq 0) { return '""' }
if ($text -notmatch '[\s"`$&|<>;()]') { return $text }
return '"' + ($text -replace '(["\\])','\$1') + '"'
}
function Join-Arguments {
param([object[]]$Arguments)
return (($Arguments | ForEach-Object { Quote-Argument $_ }) -join ' ')
}
function Get-FileTimeMarker {
param($Item)
if (-not $Item) { return "" }
return $Item.LastWriteTimeUtc.ToString("o")
}
function Load-State {
if (Test-Path -LiteralPath $Script:StatePath) {
try {
$loaded = Get-Content -LiteralPath $Script:StatePath -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
if ($loaded) {
return [pscustomobject]@{
ZipPath = [string]($loaded.ZipPath)
ZipWriteTime = [string]($loaded.ZipWriteTime)
LastExtractedZipPath = [string]($loaded.LastExtractedZipPath)
LastExtractedZipWrite = [string]($loaded.LastExtractedZipWrite)
LastFailedZipPath = [string]($loaded.LastFailedZipPath)
LastFailedZipWrite = [string]($loaded.LastFailedZipWrite)
LastFailedZipError = [string]($loaded.LastFailedZipError)
Version = [string]($loaded.Version)
}
}
} catch {
Write-Log "State file unreadable. Resetting. $($_.Exception.Message)" "WARN"
}
}
return [pscustomobject]@{
ZipPath = ""
ZipWriteTime = ""
LastExtractedZipPath = ""
LastExtractedZipWrite = ""
LastFailedZipPath = ""
LastFailedZipWrite = ""
LastFailedZipError = ""
Version = $Script:AutoDeployVersion
}
}
function Save-State {
param($State)
try {
$State.Version = $Script:AutoDeployVersion
$State | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $Script:StatePath -Encoding UTF8
} catch {
Write-Log "Could not save state: $($_.Exception.Message)" "WARN"
}
}
function Get-NewestZip {
return Get-ChildItem -LiteralPath $Script:Root -File -Filter *.zip -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -ne $Script:SelfPath -and $_.Name -notmatch '^auto-deploy-reports.*\.zip$' } |
Sort-Object LastWriteTimeUtc -Descending |
Select-Object -First 1
}
function Get-RootScript {
param([string]$Name)
$path = Join-Path $Script:Root $Name
if (Test-Path -LiteralPath $path -PathType Leaf) { return Get-Item -LiteralPath $path }
return $null
}
function Get-NewestRecursiveScript {
param([string]$Name)
$skipParts = @('/.git/','/__pycache__/','/.ruff_cache/','/vendor/','/packages/','/debs/','/fonts/','/logs/','/snapshots/')
return Get-ChildItem -LiteralPath $Script:Root -Recurse -File -Filter $Name -ErrorAction SilentlyContinue |
Where-Object {
$norm = Normalize-PathText $_.FullName
$keep = $true
foreach ($part in $skipParts) {
if ($norm.IndexOf($part, [StringComparison]::OrdinalIgnoreCase) -ge 0) {
$keep = $false
break
}
}
$keep
} |
Sort-Object LastWriteTimeUtc -Descending |
Select-Object -First 1
}
function Resolve-LaunchTarget {
# TrioDesktop must launch the repo-root start.py. Do not let an older nested copy,
# a staged workspace, or a sidecar app.py/main.py win when root start.py exists.
$rootStart = Get-RootScript -Name 'start.py'
if ($rootStart) {
return [pscustomobject]@{
Kind = 'start'
File = $rootStart
Source = 'repo-root-start.py'
ExpectedRoot = (Join-Path $Script:Root 'start.py')
}
}
# Generic fallback for other FlatLine projects that do not ship a root start.py.
foreach ($name in @('main.py','app.py')) {
$rootScript = Get-RootScript -Name $name
if ($rootScript) {
return [pscustomobject]@{
Kind = [System.IO.Path]::GetFileNameWithoutExtension($name)
File = $rootScript
Source = ('repo-root-' + $name)
ExpectedRoot = $rootScript.FullName
}
}
}
# Last resort only. Nested start.py is dangerous for TrioDesktop and should never
# be used while root start.py exists, but this keeps the universal watcher useful
# for unusual projects that intentionally keep their launcher below root.
foreach ($name in @('start.py','main.py','app.py')) {
$nested = Get-NewestRecursiveScript -Name $name
if ($nested) {
return [pscustomobject]@{
Kind = [System.IO.Path]::GetFileNameWithoutExtension($name)
File = $nested
Source = ('nested-' + $name)
ExpectedRoot = $nested.FullName
}
}
}
return $null
}
function Get-ProjectIdentity {
if ($Script:ProjectIdentityCache) { return $Script:ProjectIdentityCache }
$names = New-Object System.Collections.Generic.List[string]
$rootName = Split-Path -Leaf $Script:Root
if (-not [string]::IsNullOrWhiteSpace($rootName)) { $names.Add($rootName) }
$target = Resolve-LaunchTarget
if ($target -and $target.File) {
try {
$names.Add($target.File.BaseName)
$names.Add($target.File.Name)
} catch { }
}
$configPath = Join-Path $Script:Root 'config.ini'
if (Test-Path -LiteralPath $configPath -PathType Leaf) {
try {
$section = ''
foreach ($line in Get-Content -LiteralPath $configPath -ErrorAction Stop) {
$trimmed = ([string]$line).Trim()
if ($trimmed -match '^\[([^\]]+)\]') {
$section = $Matches[1].Trim().ToLowerInvariant()
continue
}
if ($trimmed -match '^(application|debugger|project|project_name|window_title|name)\s*=\s*(.+?)\s*$') {
$key = $Matches[1].Trim().ToLowerInvariant()
$raw = ([string]$Matches[2]).Trim().Trim('"',"'")
# Do not read random provider settings like [azure] app_name=Trio.
$allowed = ($section -in @('about','app','application','project','flatline','debugger','ui'))
if (-not $allowed) { continue }
foreach ($piece in ($raw -split '[/|,;]')) {
$piece = $piece.Trim()
if ($piece.Length -ge 3 -and $piece.Length -le 80) { $names.Add($piece) }
}
}
}
} catch { Write-Log "Could not read config identity: $($_.Exception.Message)" "WARN" }
}
foreach ($scriptName in @('start.py','main.py','app.py','cutiepy.py','gtp.py','prompt_app.py','flop.py','pyaudioencoder.py')) {
$script = Join-Path $Script:Root $scriptName
if (-not (Test-Path -LiteralPath $script -PathType Leaf)) { continue }
try {
$text = Get-Content -LiteralPath $script -Raw -ErrorAction Stop
foreach ($pattern in @(
'setWindowTitle\(\s*["'']([^"'']+)["'']',
'(?im)^\s*(APP_NAME|APPLICATION_NAME|PROJECT_NAME|WINDOW_TITLE)\s*=\s*["'']([^"'']+)["'']'
)) {
foreach ($m in [regex]::Matches($text, $pattern)) {
$value = if ($m.Groups.Count -gt 2) { $m.Groups[2].Value } else { $m.Groups[1].Value }
$value = ([string]$value).Trim()
if ($value.Length -ge 3 -and $value.Length -le 80) { $names.Add($value) }
}
}
} catch { }
}
$unique = @()
foreach ($n in $names) {
$clean = ([string]$n).Trim()
if ($clean.Length -ge 3 -and -not ($unique | Where-Object { $_ -ieq $clean })) { $unique += $clean }
}
$Script:ProjectIdentityCache = $unique
return $unique
}
function Test-CommandLineBelongsToProject {
param([string]$CommandLine)
if ([string]::IsNullOrWhiteSpace($CommandLine)) { return $false }
$cmd = (Normalize-PathText $CommandLine).ToLowerInvariant()
$rootNorm = (Normalize-PathText $Script:Root).ToLowerInvariant()
if ($cmd.Contains($rootNorm + '/')) { return $true }
if ($cmd.Contains($rootNorm)) { return $true }
return $false
}
function Test-ProcessBelongsToApplicationName {
param(
[string]$CommandLine,
[string]$ProcessName = '',
[string]$WindowTitle = ''
)
# Cleanup must be based on a fresh live inventory and the application name / identity,
# never on remembered PIDs from a previous run.
$identities = @(Get-ProjectIdentity)
if (-not ($identities | Where-Object { $_ -ieq 'TrioDesktop' })) { $identities += 'TrioDesktop' }
$cmd = (Normalize-PathText $CommandLine).ToLowerInvariant()
$pname = ([string]$ProcessName).Trim().ToLowerInvariant()
$pbase = [System.IO.Path]::GetFileNameWithoutExtension($pname)
$title = ([string]$WindowTitle).Trim().ToLowerInvariant()
$rootMatch = Test-CommandLineBelongsToProject -CommandLine $CommandLine
foreach ($identity in $identities) {
$clean = ([string]$identity).Trim()
if ($clean.Length -lt 3) { continue }
$needle = (Normalize-PathText $clean).ToLowerInvariant()
$compact = ($needle -replace '[^a-z0-9]', '')
if ($title.Contains($needle)) { return $true }
if ($pbase -eq $compact -or $pbase -eq $needle -or $pname -eq ($needle + '.exe')) { return $true }
# For command lines, app-name evidence is accepted when paired with the project root
# or with the canonical TrioDesktop name to avoid killing unrelated generic tools.
if ($cmd.Contains($needle) -and ($rootMatch -or $needle -eq 'triodesktop')) { return $true }
}
return $rootMatch
}
function Clear-StaleRememberedPidFile {
<#
Older auto.ps1 builds wrote .autoload-pids.json and then tried to taskkill
those remembered PIDs on the next run. That created noisy "process not
found" startup spam and made cleanup depend on stale state. The watcher
now keeps only the process it launched during this PowerShell session in
memory; startup cleanup uses a fresh process inventory instead.
#>
try {
if (Test-Path -LiteralPath $Script:PidPath -PathType Leaf) {
Remove-Item -LiteralPath $Script:PidPath -Force -ErrorAction Stop
Write-Log "PID-LEDGER:CLEARED stale=$Script:PidPath"
}
} catch {
Write-Log "PID-LEDGER:CLEAR-FAILED path=$Script:PidPath error=$($_.Exception.Message)" "WARN"
}
}
function Get-RememberedPids {
# Legacy compatibility shim. Current auto.ps1 never uses remembered PID rows
# as kill evidence. Startup cleanup must be one live process inventory pass.
return @()
}
function Save-RememberedPids {
param([object[]]$Rows)
# Intentionally no-op. Older builds wrote stale PID ledgers that later
# replayed TASKKILL against dead processes. Do not recreate that state.
$Script:SessionRememberedPids = @{}
}
function Add-RememberedPid {
param(
[int]$ProcessId,
[string]$TargetPath
)
# Intentionally no-op. The active child is tracked by $Script:CurrentProcInfo;
# stale cleanup is based on a fresh process inventory, never saved PIDs.
return
}
function Remove-RememberedPid {
param([int]$ProcessId)
# Intentionally no-op; see Add-RememberedPid.
return
}
function Test-ProcessIsAlive {
param([int]$ProcessId)
if ($ProcessId -le 0) { return $false }
try { return $null -ne (Get-Process -Id $ProcessId -ErrorAction SilentlyContinue) } catch { return $false }
}
function Stop-RememberedPids {
param([string]$Reason = 'remembered-cleanup')
# Critical contract: never taskkill remembered/stale PIDs. The single cleanup
# task is Stop-ProjectOwnedProcesses, which inventories live project-owned
# processes and then verifies cleanup. This function is silent by design.
$Script:SessionRememberedPids = @{}
return 0
}
function Get-FileHashSafe {
param([string]$Path)
try {
if (Test-Path -LiteralPath $Path -PathType Leaf) {
return (Get-FileHash -LiteralPath $Path -Algorithm SHA256 -ErrorAction Stop).Hash
}
} catch { }
return ''
}
function Test-FilesAreIdentical {
param(
[string]$Source,
[string]$Destination
)
if (-not (Test-Path -LiteralPath $Source -PathType Leaf)) { return $false }
if (-not (Test-Path -LiteralPath $Destination -PathType Leaf)) { return $false }
$srcHash = Get-FileHashSafe -Path $Source
$dstHash = Get-FileHashSafe -Path $Destination
return (-not [string]::IsNullOrWhiteSpace($srcHash) -and $srcHash -eq $dstHash)
}
function Test-IsLockedFileError {
param([string]$Message)
$msg = [string]$Message
return ($msg -match 'being used by another process|cannot access the file|access.*denied|used by another process|The process cannot access')
}
function Copy-ToPendingFile {
param(
[string]$Source,
[string]$Destination,
[string]$RelativePath
)
$pending = "$Destination.pending"
try {
Copy-Item -LiteralPath $Source -Destination $pending -Force -ErrorAction Stop
Write-Log "COPY:PENDING relative=$RelativePath pending=$pending" "WARN"
return $true
} catch {
Write-Log "COPY:PENDING-FAILED relative=$RelativePath error=$($_.Exception.Message)" "ERROR"
return $false
}
}
function Get-ProjectOwnedProcesses {
param([switch]$AllPython)
$currentPid = [int]$PID
$rows = @{}
$safeNames = @('python.exe','pythonw.exe','py.exe','node.exe','qtwebengineprocess.exe','powershell.exe','pwsh.exe')
if (Test-IsWindows) {
try {
$processes = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue)
foreach ($proc in $processes) {
$pidValue = if ($null -eq $proc.ProcessId) { 0 } else { [int]$proc.ProcessId }
if ($pidValue -le 0 -or $pidValue -eq $currentPid) { continue }
$name = if ($null -eq $proc.Name) { '' } else { [string]$proc.Name }
$cmd = if ($null -eq $proc.CommandLine) { '' } else { [string]$proc.CommandLine }
$title = ''
$isPython = $name -match '^(python|pythonw|py)\.exe$'
$isSafeName = $safeNames -contains $name.ToLowerInvariant()
$belongs = Test-ProcessBelongsToApplicationName -CommandLine $cmd -ProcessName $name -WindowTitle $title
if (($AllPython -and $isPython) -or ($belongs -and $isSafeName)) {
$rows[[string]$pidValue] = [pscustomobject]@{
ProcessId = $pidValue
Name = $name
CommandLine = $cmd
Reason = if ($AllPython -and $isPython) { 'all-python' } else { 'project-command-line' }
}
}
}
} catch {
Write-Log "Get-CimInstance process inventory failed: $($_.Exception.Message)" "WARN"
}
# Secondary safety net: title-bar match for Python GUI children that may have short command lines.
try {
$identities = @(Get-ProjectIdentity)
if ($identities.Count -gt 0) {
foreach ($p in @(Get-Process -ErrorAction SilentlyContinue)) {
try {
$pidValue = [int]$p.Id
if ($pidValue -le 0 -or $pidValue -eq $currentPid -or $rows.ContainsKey([string]$pidValue)) { continue }
$title = if ($null -eq $p.MainWindowTitle) { '' } else { [string]$p.MainWindowTitle }
if ([string]::IsNullOrWhiteSpace($title)) { continue }
$pname = ([string]$p.ProcessName).ToLowerInvariant()
if ($pname -notin @('python','pythonw','py','qtwebengineprocess')) { continue }
foreach ($identity in $identities) {
if ($title.IndexOf([string]$identity, [StringComparison]::OrdinalIgnoreCase) -ge 0) {
$rows[[string]$pidValue] = [pscustomobject]@{
ProcessId = $pidValue
Name = $p.ProcessName + '.exe'
CommandLine = "<title:$title>"
Reason = "project-window-title:$identity"
}
break
}
}
} catch { }
}
}
} catch { }
} else {
try {
$rootNorm = (Normalize-PathText $Script:Root).ToLowerInvariant()
$psRows = & ps -eo pid=,comm=,args= 2>$null
foreach ($line in $psRows) {
$text = [string]$line
if ($text -notmatch '^\s*(\d+)\s+(\S+)\s+(.*)$') { continue }
$pidValue = [int]$Matches[1]
if ($pidValue -le 0 -or $pidValue -eq $currentPid) { continue }
$name = [string]$Matches[2]
$cmd = [string]$Matches[3]
$isPython = $name -match '^(python|python3|pythonw|py)$'
$belongs = Test-ProcessBelongsToApplicationName -CommandLine $cmd -ProcessName $name -WindowTitle ''
if (($AllPython -and $isPython) -or ($belongs -and ($isPython -or $name -match '^(node|QtWebEngineProcess|pwsh|powershell)$'))) {
$rows[[string]$pidValue] = [pscustomobject]@{ ProcessId=$pidValue; Name=$name; CommandLine=$cmd; Reason=if($AllPython -and $isPython){'all-python'}else{'project-command-line'} }
}
}
} catch {
Write-Log "ps process inventory failed: $($_.Exception.Message)" "WARN"
}
}
return @($rows.Values | Sort-Object ProcessId)
}
function Invoke-TaskKillPid {
param([int]$ProcessId)
if ($ProcessId -le 0 -or $ProcessId -eq [int]$PID) { return $false }
try {
if (Test-IsWindows) {
$output = & taskkill.exe /PID ([string]$ProcessId) /T /F 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) { return $true }
$text = (($output | ForEach-Object { [string]$_ }) -join ' ').Trim()
if ($text -match 'not found|not running|no running instance') { return $false }
if (-not [string]::IsNullOrWhiteSpace($text)) { Write-Log "TASKKILL:FAILED pid=$ProcessId exit=$exitCode output=$text" "WARN" }
return $false
}
try { & kill -TERM -- -$ProcessId 2>$null } catch { }
Start-Sleep -Milliseconds 300
try { & kill -KILL -- -$ProcessId 2>$null } catch { }
try { & kill -TERM $ProcessId 2>$null } catch { }
return $true
} catch {
Write-Log "taskkill failed pid=${ProcessId}: $($_.Exception.Message)" "WARN"
return $false
}
}
function Stop-ProjectOwnedProcesses {
param(
[string]$Reason = 'cleanup',
[switch]$AllPython
)
$rows = @(Get-ProjectOwnedProcesses -AllPython:$AllPython)
if ($rows.Count -eq 0) {
Write-Log "PROJECT-PROCESS-CLEANUP SUCCESS! reason=$Reason found=0 killed=0 verified_noop=application_name_live_inventory_empty"
return 0
}
$killed = 0
$pids = @()
foreach ($row in $rows) {
try { $pids += ([string][int]$row.ProcessId) } catch { }
if (Invoke-TaskKillPid -ProcessId ([int]$row.ProcessId)) { $killed++ }
}
Start-Sleep -Milliseconds 700
Write-Log "PROJECT-PROCESS-CLEANUP SUCCESS! reason=$Reason found=$($rows.Count) killed=$killed pids=$(($pids -join ',')) verified_by=application_name_live_inventory_after_taskkill"
return $killed
}
function Stop-ManagedCurrentProcess {
param([string]$Reason = 'restart')
if (-not $Script:CurrentProcInfo -or -not $Script:CurrentProcInfo.Process) { return }
$proc = $Script:CurrentProcInfo.Process
try {
if (-not $proc.HasExited) {
Write-Log "Stopping managed app pid=$($proc.Id) reason=$Reason"
[void](Invoke-TaskKillPid -ProcessId ([int]$proc.Id))
}
} catch { Write-Log "Managed stop failed: $($_.Exception.Message)" "WARN" }
try { if ($Script:CurrentProcInfo.StdoutEvent) { Unregister-Event -SourceIdentifier $Script:CurrentProcInfo.StdoutEvent -ErrorAction SilentlyContinue } } catch { }
try { if ($Script:CurrentProcInfo.StderrEvent) { Unregister-Event -SourceIdentifier $Script:CurrentProcInfo.StderrEvent -ErrorAction SilentlyContinue } } catch { }
try { Remove-RememberedPid -ProcessId ([int]$proc.Id) } catch { }
try { $proc.Dispose() } catch { }
$Script:CurrentProcInfo = $null
}
function Resolve-ZipSourceRoot {
param([string]$TempRoot)
$entries = @(Get-ChildItem -LiteralPath $TempRoot -Force -ErrorAction SilentlyContinue)
if ($entries.Count -eq 1 -and $entries[0].PSIsContainer) {
Write-Log "Zip has a single wrapper folder. Flattening from: $($entries[0].FullName)"
return $entries[0].FullName
}
return $TempRoot
}
function Test-ProtectedDeployRelativePath {
param([string]$RelativePath)
$rel = (Normalize-PathText $RelativePath).TrimStart('/').ToLowerInvariant()
if ($rel -eq 'auto.ps1' -and -not $AllowSelfUpdate) { return $true }
if ($rel -eq '.autoload-state.json') { return $true }
if ($rel -eq '.auto-deploy.log') { return $true }
if ($rel -like '.auto-deploy-child.*.log') { return $true }
return $false
}
function Copy-FileWithRetry {
param(
[string]$Source,
[string]$Destination,
[string]$RelativePath
)
$attempt = 0
$maxAttempts = [Math]::Max(1, [int]$MaxCopyRetries)
if (Test-FilesAreIdentical -Source $Source -Destination $Destination) {
Write-Log "COPY:SKIP-IDENTICAL relative=$RelativePath"
return
}
while ($attempt -lt $maxAttempts) {
$attempt++
try {
$destDir = Split-Path -Parent $Destination
if (-not (Test-Path -LiteralPath $destDir -PathType Container)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
Copy-Item -LiteralPath $Source -Destination $Destination -Force -ErrorAction Stop
Write-Log "COPY:OK relative=$RelativePath"
return
} catch {
$message = $_.Exception.Message
$isLock = Test-IsLockedFileError -Message $message
Write-Log "COPY:RETRY attempt=$attempt/$maxAttempts relative=$RelativePath lock=$isLock error=$message" "WARN"
if (Test-FilesAreIdentical -Source $Source -Destination $Destination) {
Write-Log "COPY:SKIP-IDENTICAL-AFTER-LOCK relative=$RelativePath"
return
}
Stop-ManagedCurrentProcess -Reason "copy-lock:$RelativePath"
[void](Stop-RememberedPids -Reason "copy-lock:$RelativePath")
[void](Stop-ProjectOwnedProcesses -Reason "copy-lock:$RelativePath" -AllPython:$KillAllPython)
if ($isLock -and -not $NoAggressiveUnlock -and -not $KillAllPython -and $attempt -ge 2) {
Write-Log "COPY:AGGRESSIVE-UNLOCK relative=$RelativePath killing other Python processes after targeted cleanup failed" "WARN"
[void](Stop-ProjectOwnedProcesses -Reason "aggressive-copy-lock:$RelativePath" -AllPython)
}
Start-Sleep -Milliseconds (350 * $attempt)
if ($attempt -ge $maxAttempts) {
if (Test-FilesAreIdentical -Source $Source -Destination $Destination) {
Write-Log "COPY:SKIP-IDENTICAL-FINAL relative=$RelativePath"
return
}
$normRel = (Normalize-PathText $RelativePath).ToLowerInvariant()
if ($isLock -and ($normRel -like 'fonts/*' -or $normRel -like 'assets/*' -or $normRel -like 'webview/*')) {
if (Copy-ToPendingFile -Source $Source -Destination $Destination -RelativePath $RelativePath) { return }
}
throw
}
}
}
}
function Copy-TreeOverRoot {
param(
[string]$SourceRoot,
[string]$DestinationRoot,
[string]$ZipLeaf = 'archive.zip'
)
$items = @(Get-ChildItem -LiteralPath $SourceRoot -Recurse -Force -ErrorAction Stop)
$files = @($items | Where-Object { -not $_.PSIsContainer })
$total = [Math]::Max(1, $files.Count)
$index = 0
foreach ($item in $items) {
$relative = $item.FullName.Substring($SourceRoot.Length).TrimStart('\','/')
if ([string]::IsNullOrWhiteSpace($relative)) { continue }
$dest = Join-Path $DestinationRoot $relative
if ($item.PSIsContainer) {
if (-not (Test-Path -LiteralPath $dest -PathType Container)) { New-Item -ItemType Directory -Path $dest -Force | Out-Null }
continue
}
$index++
if (-not $NoProgress) {
$pct = [int](($index / $total) * 100)
Write-Progress -Activity "Deploying $ZipLeaf" -Status $relative -PercentComplete $pct
}
if (Test-ProtectedDeployRelativePath -RelativePath $relative) {
if ((Normalize-PathText $relative).ToLowerInvariant() -eq 'auto.ps1') {
$incoming = Join-Path $DestinationRoot 'auto.incoming.ps1'
Copy-FileWithRetry -Source $item.FullName -Destination $incoming -RelativePath 'auto.incoming.ps1'
Write-Log "SELF-PRESERVE: skipped overwriting running auto.ps1; saved incoming copy as auto.incoming.ps1"
} else {
Write-Log "DEPLOY:SKIP protected runtime file $relative"
}
continue
}
Copy-FileWithRetry -Source $item.FullName -Destination $dest -RelativePath $relative
}
if (-not $NoProgress) { Write-Progress -Activity "Deploying $ZipLeaf" -Completed }
}
function Extract-ZipOverRoot {
param([string]$ZipPath)
Write-Log "Extracting archive over root: $ZipPath"
Stop-ManagedCurrentProcess -Reason 'pre-deploy'
[void](Stop-ProjectOwnedProcesses -Reason 'pre-deploy' -AllPython:$KillAllPython)
$temp = Join-Path ([System.IO.Path]::GetTempPath()) ("autoload_" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $temp -Force | Out-Null
try {
$expanded = $false
try {
Expand-Archive -LiteralPath $ZipPath -DestinationPath $temp -Force -ErrorAction Stop
$expanded = $true
} catch {
Write-Log "Expand-Archive failed, trying .NET extraction. $($_.Exception.Message)" "WARN"
}
if (-not $expanded) {
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipPath, $temp)
}
$sourceRoot = Resolve-ZipSourceRoot -TempRoot $temp
Write-Log "Payload root: $sourceRoot"
Copy-TreeOverRoot -SourceRoot $sourceRoot -DestinationRoot $Script:Root -ZipLeaf ([System.IO.Path]::GetFileName($ZipPath))
if (-not $NoDeleteZip) {
Remove-Item -LiteralPath $ZipPath -Force -ErrorAction Stop
Write-Log "Extracted and deleted zip: $ZipPath"
} else {
Write-Log "Extracted zip without deleting due to -NoDeleteZip: $ZipPath"
}
} finally {
Remove-Item -LiteralPath $temp -Recurse -Force -ErrorAction SilentlyContinue
}
}
function Test-PythonCandidate {
param([string]$FilePath, [string[]]$PrefixArgs)
try {
$allArgs = @($PrefixArgs) + @('-c', 'import sys; print(sys.executable)')
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $FilePath
$psi.Arguments = Join-Arguments $allArgs
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.CreateNoWindow = $true
$p = [System.Diagnostics.Process]::Start($psi)
if (-not $p.WaitForExit(8000)) { try { if (Test-IsWindows) { & taskkill.exe /PID ([string]$p.Id) /T /F 2>$null | Out-Null } else { $p.Kill() } } catch { }; return $false }
return $p.ExitCode -eq 0
} catch { return $false }
}
function Get-PythonCommand {
# Prefer stable CPython 3.12 for TrioDesktop. Python 3.14 can exist on the box,
# but PySide6 / Qt / audio wheels are still the common failure point there.
$explicitCandidates = @(
'C:\Python312\python.exe',
'C:\Program Files\Python312\python.exe',
'C:\Users\moren\AppData\Local\Programs\Python\Python312\python.exe'
)
foreach ($candidate in $explicitCandidates) {
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
if (Test-PythonCandidate -FilePath $candidate -PrefixArgs @()) {
return [pscustomobject]@{ FilePath = $candidate; PrefixArgs = @(); Source = 'explicit-python312' }
}
}
}
$py = Get-Command py -ErrorAction SilentlyContinue
if ($py) {
foreach ($prefix in @(@('-3.12'), @('-3.13'), @('-3'), @('-3.14'))) {
if (Test-PythonCandidate -FilePath $py.Source -PrefixArgs $prefix) {
return [pscustomobject]@{ FilePath = $py.Source; PrefixArgs = $prefix; Source = ('py-launcher ' + (($prefix -join ' '))) }
}
}
}
$python = Get-Command python -ErrorAction SilentlyContinue
if ($python -and (Test-PythonCandidate -FilePath $python.Source -PrefixArgs @())) {
return [pscustomobject]@{ FilePath = $python.Source; PrefixArgs = @(); Source = 'python-path' }
}
$python3 = Get-Command python3 -ErrorAction SilentlyContinue
if ($python3 -and (Test-PythonCandidate -FilePath $python3.Source -PrefixArgs @())) {
return [pscustomobject]@{ FilePath = $python3.Source; PrefixArgs = @(); Source = 'python3-path' }
}
throw "Could not find a working python/py launcher."
}
function New-ChildLogSession {
$Script:LaunchCounter++
$stamp = Get-Date -Format "yyyyMMdd_HHmmss_fff"
$suffix = "{0}_{1}" -f $stamp, $Script:LaunchCounter
$stdout = Join-Path $Script:Root (".auto-deploy-child.{0}.stdout.log" -f $suffix)
$stderr = Join-Path $Script:Root (".auto-deploy-child.{0}.stderr.log" -f $suffix)
New-Item -ItemType File -Path $stdout -Force | Out-Null
New-Item -ItemType File -Path $stderr -Force | Out-Null
return [pscustomobject]@{ Stdout = $stdout; Stderr = $stderr }
}
function Register-ProcessOutput {
param($Process, [string]$SourceIdentifier, [string]$LogPath, [string]$Prefix)
$messageData = [pscustomobject]@{ LogPath = $LogPath; Prefix = $Prefix; WatcherLog = $Script:LogPath }
$subscriptionId = "auto.{0}.{1}.{2}" -f $Prefix, $Process.Id, ([guid]::NewGuid().ToString('N'))
Register-ObjectEvent -InputObject $Process -EventName $SourceIdentifier -SourceIdentifier $subscriptionId -MessageData $messageData -Action {
$line = $EventArgs.Data
if ([string]::IsNullOrWhiteSpace($line)) { return }
$stamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$msg = "[$stamp] [$($Event.MessageData.Prefix)] $line"
try { Add-Content -LiteralPath $Event.MessageData.LogPath -Value $line -Encoding UTF8 } catch { }
try { Add-Content -LiteralPath $Event.MessageData.WatcherLog -Value $msg -Encoding UTF8 } catch { }
try { Write-Host $msg } catch { }
} | Out-Null
return $subscriptionId
}
function Launch-Script {
param($Target)
Stop-ManagedCurrentProcess -Reason 'relaunch'
[void](Stop-ProjectOwnedProcesses -Reason 'pre-launch' -AllPython:$KillAllPython)
$rootStartPath = Join-Path $Script:Root 'start.py'
if (Test-Path -LiteralPath $rootStartPath -PathType Leaf) {
$resolvedTargetPath = [System.IO.Path]::GetFullPath($Target.File.FullName)
$resolvedRootStart = [System.IO.Path]::GetFullPath($rootStartPath)
if ($resolvedTargetPath -ne $resolvedRootStart) {
Write-Log "LAUNCH-TARGET:FORCE-ROOT-START previous=$resolvedTargetPath root=$resolvedRootStart" "WARN"
$Target = [pscustomobject]@{
Kind = 'start'
File = (Get-Item -LiteralPath $resolvedRootStart)
Source = 'forced-repo-root-start.py'
ExpectedRoot = $resolvedRootStart
}
}
}
$py = Get-PythonCommand
$logs = New-ChildLogSession
$args = @($py.PrefixArgs) + @($Target.File.FullName)
$argText = Join-Arguments $args
Write-Log "LAUNCH-TARGET: $($Target.Source) file=$($Target.File.FullName) expected=$($Target.ExpectedRoot)"
Write-Log "PYTHON-TARGET: source=$($py.Source) file=$($py.FilePath) prefix=$(($py.PrefixArgs -join ' '))"
Write-Log "Launching $($Target.Kind).py target hidden/no-new-window: $($py.FilePath) $argText"
Write-Log "Working directory: $($Target.File.DirectoryName)"
Write-Log "Child stdout: $($logs.Stdout)"
Write-Log "Child stderr: $($logs.Stderr)"
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $py.FilePath
$psi.Arguments = $argText
$psi.WorkingDirectory = $Target.File.DirectoryName
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
try { $psi.StandardOutputEncoding = [System.Text.Encoding]::UTF8 } catch { }
try { $psi.StandardErrorEncoding = [System.Text.Encoding]::UTF8 } catch { }
$psi.CreateNoWindow = $true
$psi.Environment['PYTHONUNBUFFERED'] = '1'
$psi.Environment['PYTHONIOENCODING'] = 'utf-8'
# auto.ps1 captures child streams and mirrors them into .auto-deploy.log.
# Force ASCII debugger UI art here so box-drawing/Braille never turns into Γòæ mojibake.
$psi.Environment['TRIO_ASCII_CONSOLE'] = '1'
$psi.Environment['FLATLINE_AUTO_DEPLOY'] = '1'
$psi.Environment['FLATLINE_AUTO_DEPLOY_ROOT'] = $Script:Root
$psi.Environment['FLATLINE_EXPECTED_START_PATH'] = (Join-Path $Script:Root 'start.py')
$psi.Environment['TRIODESKTOP_EXPECTED_START_PATH'] = (Join-Path $Script:Root 'start.py')
$psi.Environment['TRIODESKTOP_DEBUG_LOG'] = (Join-Path $Script:Root 'debug.log')
$proc = New-Object System.Diagnostics.Process
$proc.StartInfo = $psi
$proc.EnableRaisingEvents = $true
if (-not $proc.Start()) { throw "Process did not start." }
$stdoutSub = Register-ProcessOutput -Process $proc -SourceIdentifier 'OutputDataReceived' -LogPath $logs.Stdout -Prefix 'APP'
$stderrSub = Register-ProcessOutput -Process $proc -SourceIdentifier 'ErrorDataReceived' -LogPath $logs.Stderr -Prefix 'ERR'
$proc.BeginOutputReadLine()
$proc.BeginErrorReadLine()
$Script:CurrentProcInfo = [pscustomobject]@{ Process = $proc; StdoutEvent = $stdoutSub; StderrEvent = $stderrSub; Logs = $logs; ExitLogged = $false }
Add-RememberedPid -ProcessId ([int]$proc.Id) -TargetPath $Target.File.FullName
Write-Log "LAUNCHED pid=$($proc.Id)"
}
function Read-Hotkeys {
$result = [pscustomobject]@{ Restart = $false; Quit = $false; Kill = $false }
try {
while ([Console]::KeyAvailable) {
$keyInfo = [Console]::ReadKey($true)
switch ($keyInfo.Key) {
([ConsoleKey]::R) { $result.Restart = $true }
([ConsoleKey]::Q) { $result.Quit = $true }
([ConsoleKey]::K) { $result.Kill = $true }
}
}
} catch { }
return $result
}
function Update-ManagedExitStatus {
if (-not $Script:CurrentProcInfo -or -not $Script:CurrentProcInfo.Process) { return }
$proc = $Script:CurrentProcInfo.Process
try {
if ($proc.HasExited -and -not $Script:CurrentProcInfo.ExitLogged) {
$Script:CurrentProcInfo.ExitLogged = $true
$Script:LastTargetExitPid = [int]$proc.Id
$Script:LastTargetExitCode = [int]$proc.ExitCode
Write-Log "APP:EXIT pid=$($proc.Id) code=$($proc.ExitCode)"
try { Remove-RememberedPid -ProcessId ([int]$proc.Id) } catch { }
}
} catch { }
}
Initialize-Log
$state = Load-State
Write-Log "Universal FlatLine auto-deploy watcher v$Script:AutoDeployVersion started."
Write-Log "Original cwd: $((Get-Location).Path)"
Write-Log "Script path: $Script:SelfPath"
Write-Log "Canonical root: $Script:Root"
Write-Log "R = relaunch app | K = taskkill project children | Q = quit watcher"
Write-Log "Self-preserve auto.ps1: $([bool](-not $AllowSelfUpdate))"
Write-Host ""
Clear-StaleRememberedPidFile
[void](Stop-ProjectOwnedProcesses -Reason 'startup-cleanup' -AllPython:$KillAllPython)
if ($KillAllPython) {
Write-Log "PANIC MODE: -KillAllPython is enabled; all other Python processes may be killed." "WARN"
}
while ($true) {
try {
Update-ManagedExitStatus
$hotkeys = Read-Hotkeys
if ($hotkeys.Quit) {
Write-Log "Quit requested."
Stop-ManagedCurrentProcess -Reason 'quit'
[void](Stop-ProjectOwnedProcesses -Reason 'quit-cleanup' -AllPython:$KillAllPython)
break
}
if ($hotkeys.Kill) {
Write-Log "Manual project taskkill requested."
Stop-ManagedCurrentProcess -Reason 'manual-kill'
[void](Stop-ProjectOwnedProcesses -Reason 'manual-kill' -AllPython:$KillAllPython)
}
$manualRestart = [bool]$hotkeys.Restart
if ($manualRestart) { Write-Log "Manual restart requested." }
$zip = Get-NewestZip
$zipChanged = $false
if ($zip) {
$zipWriteTime = Get-FileTimeMarker -Item $zip
$isNewerThanLastExtract = $true
if (-not [string]::IsNullOrWhiteSpace($state.LastExtractedZipWrite)) {
try {
$currentZipTime = [DateTimeOffset]::Parse($zipWriteTime)
$lastExtractedTime = [DateTimeOffset]::Parse($state.LastExtractedZipWrite)
$isNewerThanLastExtract = ($currentZipTime -gt $lastExtractedTime)
} catch {
$isNewerThanLastExtract = ($state.ZipPath -ne $zip.FullName -or $state.ZipWriteTime -ne $zipWriteTime)
}
}
$sameFailedZip = (-not [string]::IsNullOrWhiteSpace($state.LastFailedZipPath) -and $state.LastFailedZipPath -eq $zip.FullName -and $state.LastFailedZipWrite -eq $zipWriteTime)
if ($sameFailedZip) {
$failedSignature = "failed|{0}|{1}|{2}" -f $zip.FullName, $zipWriteTime, $state.LastFailedZipError
Write-ZipSkipLog -Signature $failedSignature -Message "ZIP-SKIP: previously failed zip is unchanged: $($zip.FullName) last_error=$($state.LastFailedZipError)" -Level "WARN"
} elseif ($isNewerThanLastExtract -and ($state.ZipPath -ne $zip.FullName -or $state.ZipWriteTime -ne $zipWriteTime -or $state.LastExtractedZipPath -ne $zip.FullName)) {
try {
Extract-ZipOverRoot -ZipPath $zip.FullName
$state.ZipPath = $zip.FullName
$state.ZipWriteTime = $zipWriteTime
$state.LastExtractedZipPath = $zip.FullName
$state.LastExtractedZipWrite = $zipWriteTime
$state.LastFailedZipPath = ""
$state.LastFailedZipWrite = ""
$state.LastFailedZipError = ""
$zipChanged = $true
Save-State $state
$Script:ProjectIdentityCache = $null
$Script:SessionRememberedPids = @{} # legacy compatibility reset only
$Script:LastSkippedOlderZipSignature = ""
$Script:MutedZipSkipSignatures = @{}
} catch {
$state.LastFailedZipPath = $zip.FullName
$state.LastFailedZipWrite = $zipWriteTime
$state.LastFailedZipError = $_.Exception.Message
Save-State $state
throw
}
} elseif (-not $isNewerThanLastExtract) {
$olderSignature = "older|{0}|{1}" -f $zip.FullName, $zipWriteTime
$Script:LastSkippedOlderZipSignature = $olderSignature
Write-ZipSkipLog -Signature $olderSignature -Message "ZIP-SKIP: older zip ignored: $($zip.FullName)" -Level "INFO"
}
}
$target = Resolve-LaunchTarget
if (-not $target -or -not $target.File) {
Write-Log "No start.py/main.py/app.py found yet."
Start-Sleep -Milliseconds $PollMilliseconds
continue