-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ps1
More file actions
78 lines (70 loc) · 3.43 KB
/
Copy pathconfig.ps1
File metadata and controls
78 lines (70 loc) · 3.43 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
# =====================================================================
# wt-claude-restore -- Configurazione condivisa
# Dot-sourced da snapshot.ps1, restore.ps1, install.ps1, uninstall.ps1
# Le impostazioni "utente" vivono in settings.json (accanto a questo file).
# =====================================================================
# --- Percorsi fissi dell'infrastruttura ---------------------------------
$Global:WCR_Root = $PSScriptRoot
$Global:WCR_SettingsFile = Join-Path $PSScriptRoot 'settings.json'
$Global:WCR_StateDir = Join-Path $env:USERPROFILE '.claude\wt-restore'
$Global:WCR_StateFile = Join-Path $WCR_StateDir 'last-count.json'
$Global:WCR_LogFile = Join-Path $WCR_StateDir 'wt-claude-restore.log'
$Global:WCR_ProjectsRoot = Join-Path $env:USERPROFILE '.claude\projects'
# Avvio: processo agent lanciato dalla cartella Esecuzione automatica (no admin).
$Global:WCR_AgentScript = Join-Path $PSScriptRoot 'agent.ps1'
$Global:WCR_StartupDir = [Environment]::GetFolderPath('Startup')
$Global:WCR_StartupFile = Join-Path $WCR_StartupDir 'wt-claude-restore.vbs'
# --- Default usati se settings.json manca o e' incompleto ---------------
$Global:WCR_DefaultSettings = [ordered]@{
recencyDays = 7
maxTabsPerFolder = 8
layout = 'tab'
activityWindowMinutes = 45
snapshotEveryMinutes = 2
folders = @( [ordered]@{ path = 'C:\devprojects'; primary = $true } )
}
function WCR-Log {
param([string]$Message)
try {
if (-not (Test-Path $WCR_StateDir)) { New-Item -ItemType Directory -Path $WCR_StateDir -Force | Out-Null }
$ts = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
Add-Content -Path $WCR_LogFile -Value "[$ts] $Message"
} catch { }
}
# Encoding cartella -> nome dir nello store Claude (ogni non-alfanumerico -> '-').
function WCR-EncodeFolder {
param([string]$Path)
return ($Path -replace '[^A-Za-z0-9]', '-')
}
# Carica settings.json (creandolo dai default se manca) e normalizza i campi.
function WCR-LoadSettings {
if (-not (Test-Path $WCR_SettingsFile)) {
($WCR_DefaultSettings | ConvertTo-Json -Depth 5) | Set-Content -Path $WCR_SettingsFile -Encoding UTF8
WCR-Log "settings.json creato dai default."
}
$s = Get-Content $WCR_SettingsFile -Raw | ConvertFrom-Json
# Merge con i default per i campi mancanti.
$get = {
param($obj, $name, $def)
if ($null -ne $obj.PSObject.Properties[$name] -and $null -ne $obj.$name) { $obj.$name } else { $def }
}
$cfg = [ordered]@{
recencyDays = [int](& $get $s 'recencyDays' $WCR_DefaultSettings.recencyDays)
maxTabsPerFolder = [int](& $get $s 'maxTabsPerFolder' $WCR_DefaultSettings.maxTabsPerFolder)
layout = [string](& $get $s 'layout' $WCR_DefaultSettings.layout)
activityWindowMinutes = [int](& $get $s 'activityWindowMinutes' $WCR_DefaultSettings.activityWindowMinutes)
snapshotEveryMinutes = [int](& $get $s 'snapshotEveryMinutes' $WCR_DefaultSettings.snapshotEveryMinutes)
folders = @()
}
foreach ($f in @($s.folders)) {
if (-not $f.path) { continue }
$cfg.folders += [ordered]@{
path = [string]$f.path
primary = [bool]($f.primary)
}
}
if ($cfg.folders.Count -eq 0) {
$cfg.folders = @([ordered]@{ path = 'C:\devprojects'; primary = $true })
}
return $cfg
}