This commit is contained in:
2026-05-19 00:40:34 +02:00
parent 9ea26ad610
commit cff0635aff
141 changed files with 90329 additions and 5633 deletions

2
scripts/codex-export.cmd Normal file
View File

@@ -0,0 +1,2 @@
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0codex-export.ps1" %*

83
scripts/codex-export.ps1 Normal file
View File

@@ -0,0 +1,83 @@
param(
[string]$OutputDir = "D:\notatnik-ai\codex",
[string]$SourceCodexHome = (Join-Path $env:USERPROFILE ".codex")
)
$ErrorActionPreference = "Stop"
function New-CleanDirectory {
param([Parameter(Mandatory = $true)][string]$Path)
if (Test-Path -LiteralPath $Path) {
Remove-Item -LiteralPath $Path -Recurse -Force
}
New-Item -ItemType Directory -Path $Path -Force | Out-Null
}
function Copy-DirectoryContents {
param(
[Parameter(Mandatory = $true)][string]$Source,
[Parameter(Mandatory = $true)][string]$Destination
)
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
Get-ChildItem -LiteralPath $Source -Force | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination $Destination -Recurse -Force
}
}
if (-not (Test-Path -LiteralPath $SourceCodexHome)) {
throw "Codex home not found: $SourceCodexHome"
}
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$archiveBaseName = "codex-backup-$timestamp"
$stagingRoot = Join-Path $env:TEMP $archiveBaseName
$payloadDir = Join-Path $stagingRoot "payload"
$toolsDir = Join-Path $stagingRoot "tools"
$sourceScriptsDir = $PSScriptRoot
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
New-CleanDirectory -Path $stagingRoot
New-Item -ItemType Directory -Path $payloadDir -Force | Out-Null
New-Item -ItemType Directory -Path $toolsDir -Force | Out-Null
Copy-DirectoryContents -Source $SourceCodexHome -Destination (Join-Path $payloadDir ".codex")
$profileCodexFiles = Get-ChildItem -LiteralPath $env:USERPROFILE -Force -File -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like ".codex*" -and $_.FullName -ne $SourceCodexHome }
foreach ($file in $profileCodexFiles) {
Copy-Item -LiteralPath $file.FullName -Destination (Join-Path $payloadDir $file.Name) -Force
}
Copy-Item -LiteralPath (Join-Path $sourceScriptsDir "codex-import.ps1") -Destination (Join-Path $toolsDir "codex-import.ps1") -Force
Copy-Item -LiteralPath (Join-Path $sourceScriptsDir "codex-import.cmd") -Destination (Join-Path $toolsDir "codex-import.cmd") -Force
$files = Get-ChildItem -LiteralPath $payloadDir -Force -Recurse -File
$manifest = [ordered]@{
kind = "codex-local-backup"
createdAt = (Get-Date).ToString("o")
sourceCodexHome = $SourceCodexHome
sourceUserProfile = $env:USERPROFILE
payloadRoot = "payload"
tools = @(
"tools/codex-import.ps1",
"tools/codex-import.cmd"
)
fileCount = @($files).Count
totalBytes = [int64](($files | Measure-Object -Property Length -Sum).Sum)
}
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $stagingRoot "manifest.json") -Encoding UTF8
$zipPath = Join-Path $OutputDir "$archiveBaseName.zip"
if (Test-Path -LiteralPath $zipPath) {
Remove-Item -LiteralPath $zipPath -Force
}
Compress-Archive -Path (Join-Path $stagingRoot "*") -DestinationPath $zipPath -Force
Remove-Item -LiteralPath $stagingRoot -Recurse -Force
Write-Output $zipPath

2
scripts/codex-import.cmd Normal file
View File

@@ -0,0 +1,2 @@
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0codex-import.ps1" %*

62
scripts/codex-import.ps1 Normal file
View File

@@ -0,0 +1,62 @@
param(
[Parameter(Mandatory = $true)][string]$ArchivePath,
[string]$TargetCodexHome = (Join-Path $env:USERPROFILE ".codex"),
[switch]$NoBackup
)
$ErrorActionPreference = "Stop"
function New-CleanDirectory {
param([Parameter(Mandatory = $true)][string]$Path)
if (Test-Path -LiteralPath $Path) {
Remove-Item -LiteralPath $Path -Recurse -Force
}
New-Item -ItemType Directory -Path $Path -Force | Out-Null
}
if (-not (Test-Path -LiteralPath $ArchivePath)) {
throw "Archive not found: $ArchivePath"
}
$extractRoot = Join-Path $env:TEMP ("codex-restore-" + (Get-Date -Format "yyyyMMdd-HHmmss"))
New-CleanDirectory -Path $extractRoot
try {
Expand-Archive -LiteralPath $ArchivePath -DestinationPath $extractRoot -Force
$manifestPath = Join-Path $extractRoot "manifest.json"
$payloadCodexHome = Join-Path $extractRoot "payload\.codex"
if (-not (Test-Path -LiteralPath $manifestPath)) {
throw "Invalid archive: manifest.json missing"
}
if (-not (Test-Path -LiteralPath $payloadCodexHome)) {
throw "Invalid archive: payload/.codex missing"
}
if ((Test-Path -LiteralPath $TargetCodexHome) -and -not $NoBackup) {
$backupPath = "$TargetCodexHome.before-import-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
Move-Item -LiteralPath $TargetCodexHome -Destination $backupPath
Write-Output "Existing Codex config moved to: $backupPath"
} elseif (Test-Path -LiteralPath $TargetCodexHome) {
Remove-Item -LiteralPath $TargetCodexHome -Recurse -Force
}
Copy-Item -LiteralPath $payloadCodexHome -Destination $TargetCodexHome -Recurse -Force
$payloadRoot = Join-Path $extractRoot "payload"
Get-ChildItem -LiteralPath $payloadRoot -Force -File -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like ".codex*" } |
ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $env:USERPROFILE $_.Name) -Force
}
Write-Output "Codex config restored to: $TargetCodexHome"
} finally {
if (Test-Path -LiteralPath $extractRoot) {
Remove-Item -LiteralPath $extractRoot -Recurse -Force
}
}