Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(install): self-heal a stale or broken install dir instead of aborting

Ruben Lütke59bc2264d542
diff --git a/install/install.ps1 b/install/install.ps1
index 02fc97a7c2..f4f9085a3a 100644
--- a/install/install.ps1
+++ b/install/install.ps1
@@ -537,25 +537,69 @@ Write-Note $InstallDir
# report 2026-07-15); a redirected/CI run keeps --quiet for a clean
# transcript. Real errors still surface on stderr either way.
$GitVerbosity = if ([Console]::IsErrorRedirected) { '--quiet' } else { '--progress' }
+
+# Self-heal a broken install dir (leftover non-git folder from an earlier or
+# aborted install, or a checkout whose git state no longer updates): keep the
+# old tree as a timestamped sibling backup - never delete - clone fresh, then
+# carry the user's local state (data/, jarvis.toml, .env) into the new
+# checkout. A stale folder must never require manual cleanup to install.
+function Invoke-SalvageReclone {
+ $StaleBackup = "$InstallDir.stale-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
+ try {
+ Move-Item -LiteralPath $InstallDir -Destination $StaleBackup -ErrorAction Stop
+ } catch {
+ Write-Err "cannot move the broken install dir aside ($InstallDir -> $StaleBackup)."
+ Write-Note 'Close any program using that folder (or move it yourself), then re-run.'
+ exit 1
+ }
+ Write-Note "moved the old directory to $StaleBackup (nothing was deleted)"
+ & git clone $GitVerbosity --depth 1 --branch $Branch $RepoUrl $InstallDir
+ if ($LASTEXITCODE -ne 0) { Write-Err 'git clone failed.'; exit 1 }
+ foreach ($Item in @('data', 'jarvis.toml', '.env')) {
+ $Old = Join-Path $StaleBackup $Item
+ $New = Join-Path $InstallDir $Item
+ if ((Test-Path $Old) -and -not (Test-Path $New)) {
+ try {
+ Copy-Item -LiteralPath $Old -Destination $New -Recurse -ErrorAction Stop
+ Write-Note "kept your $Item from the previous install"
+ } catch {}
+ }
+ }
+ Write-Ok 'reinstalled fresh (previous state preserved in the backup dir)'
+}
+
if (Test-Path (Join-Path $InstallDir '.git')) {
+ $UpdateOk = $true
Push-Location $InstallDir
try {
& git fetch $GitVerbosity --depth 1 origin $Branch
- & git checkout --quiet $Branch
- & git reset --quiet --hard "origin/$Branch"
+ if ($LASTEXITCODE -ne 0) { $UpdateOk = $false }
+ if ($UpdateOk) {
+ & git checkout --quiet $Branch
+ if ($LASTEXITCODE -ne 0) { $UpdateOk = $false }
+ }
+ if ($UpdateOk) {
+ & git reset --quiet --hard "origin/$Branch"
+ if ($LASTEXITCODE -ne 0) { $UpdateOk = $false }
+ }
} finally {
Pop-Location
}
- Write-Ok 'updated existing checkout to latest'
+ if ($UpdateOk) {
+ Write-Ok 'updated existing checkout to latest'
+ } else {
+ Write-Note 'existing checkout would not update (broken git state) - reinstalling in place.'
+ Invoke-SalvageReclone
+ }
} else {
if (Test-Path $InstallDir) {
- Write-Err "$InstallDir exists but is not a git repo."
- Write-Note 'Aborting to avoid clobbering your files. Remove or move that directory, then re-run.'
- exit 1
+ Write-Note "$InstallDir exists but is not a git repo (leftover from an earlier install) - reinstalling in place."
+ Invoke-SalvageReclone
+ } else {
+ & git clone $GitVerbosity --depth 1 --branch $Branch $RepoUrl $InstallDir
+ if ($LASTEXITCODE -ne 0) { Write-Err 'git clone failed.'; exit 1 }
+ Write-Ok 'downloaded'
}
- & git clone $GitVerbosity --depth 1 --branch $Branch $RepoUrl $InstallDir
- if ($LASTEXITCODE -ne 0) { Write-Err 'git clone failed.'; exit 1 }
- Write-Ok 'downloaded'
}
# WAVE 5 - payload-commit pin (axis E, Wave-5 audit Finding 2).
diff --git a/install/install.sh b/install/install.sh
index 5786e344ef..e4c17a5f86 100755
--- a/install/install.sh
+++ b/install/install.sh
@@ -857,15 +857,45 @@ note "$INSTALL_DIR"
# run keeps --quiet for a clean log. Errors surface on stderr either way.
GIT_VERBOSITY='--quiet'
[ -t 2 ] && GIT_VERBOSITY='--progress'
+
+# Self-heal a broken install dir (leftover non-git folder from an earlier or
+# aborted install, or a checkout whose git state no longer updates): keep the
+# old tree as a timestamped sibling backup — never delete — clone fresh, then
+# carry the user's local state (data/, jarvis.toml, .env) into the new
+# checkout. A stale folder must never require manual cleanup to install.
+salvage_reclone() {
+ local stale_backup
+ stale_backup="${INSTALL_DIR%/}.stale-$(date +%Y%m%d-%H%M%S)"
+ if ! mv "$INSTALL_DIR" "$stale_backup"; then
+ err "cannot move the broken install dir aside ($INSTALL_DIR -> $stale_backup)."
+ note 'Close any program using that folder (or move it yourself), then re-run.'
+ exit 1
+ fi
+ note "moved the old directory to $stale_backup (nothing was deleted)"
+ git clone "$GIT_VERBOSITY" --depth 1 --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR"
+ local item
+ for item in data jarvis.toml .env; do
+ if [ -e "$stale_backup/$item" ] && [ ! -e "$INSTALL_DIR/$item" ]; then
+ if cp -R "$stale_backup/$item" "$INSTALL_DIR/$item" 2>/dev/null; then
+ note "kept your $item from the previous install"
+ fi
+ fi
+ done
+ ok 'reinstalled fresh (previous state preserved in the backup dir)'
+}
+
if [ -d "$INSTALL_DIR/.git" ]; then
- git -C "$INSTALL_DIR" fetch "$GIT_VERBOSITY" --depth 1 origin "$BRANCH"
- git -C "$INSTALL_DIR" checkout --quiet "$BRANCH"
- git -C "$INSTALL_DIR" reset --quiet --hard "origin/$BRANCH"
- ok 'updated existing checkout to latest'
+ if git -C "$INSTALL_DIR" fetch "$GIT_VERBOSITY" --depth 1 origin "$BRANCH" \
+ && git -C "$INSTALL_DIR" checkout --quiet "$BRANCH" \
+ && git -C "$INSTALL_DIR" reset --quiet --hard "origin/$BRANCH"; then
+ ok 'updated existing checkout to latest'
+ else
+ note 'existing checkout would not update (broken git state) - reinstalling in place.'
+ salvage_reclone
+ fi
elif [ -e "$INSTALL_DIR" ]; then
- err "$INSTALL_DIR exists but is not a git repo."
- note 'Aborting to avoid clobbering your files. Remove or move that directory, then re-run.'
- exit 1
+ note "$INSTALL_DIR exists but is not a git repo (leftover from an earlier install) - reinstalling in place."
+ salvage_reclone
else
git clone "$GIT_VERBOSITY" --depth 1 --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR"
ok 'downloaded'