feat: Refactor compromised mode handling and improve error logging across flows

This commit is contained in:
2025-11-09 18:45:43 +01:00
parent 3df985c7d9
commit 123b2f76b8
8 changed files with 162 additions and 99 deletions

View File

@@ -18,11 +18,10 @@
* node setup/update/update.mjs --docker # Update Docker containers
*/
import { spawn, execSync } from 'node:child_process'
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, cpSync, rmSync } from 'node:fs'
import { join, dirname } from 'node:path'
import { createWriteStream } from 'node:fs'
import { execSync, spawn } from 'node:child_process'
import { cpSync, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
import { get as httpsGet } from 'node:https'
import { dirname, join } from 'node:path'
function stripJsonComments(input) {
let result = ""
@@ -286,11 +285,16 @@ async function updateGit() {
if (!behindCount || behindCount === '0') {
console.log('✓ Already up to date!')
// FIXED: Return 0 but DON'T create update marker (no restart needed)
return 0
}
console.log(` ${behindCount} commits behind remote`)
// MARK: Update is happening - create marker file for bot to detect
const updateMarkerPath = join(process.cwd(), '.update-happened')
writeFileSync(updateMarkerPath, `Updated from ${currentCommit} to latest at ${new Date().toISOString()}`)
// Use merge with strategy to accept remote changes for all files
// We'll restore user files afterwards
const mergeCode = await run('git', ['merge', '--strategy-option=theirs', remoteBranch])
@@ -541,6 +545,11 @@ async function updateGitFree() {
rmSync(extractDir, { recursive: true, force: true })
console.log('✓ Cleanup complete')
// MARK: Update happened - create marker file for bot to detect restart
const updateMarkerPath = join(process.cwd(), '.update-happened')
writeFileSync(updateMarkerPath, `Git-free update completed at ${new Date().toISOString()}`)
console.log('✓ Created update marker for bot restart detection')
// Step 9: Install & build
const hasNpm = await which('npm')
if (!hasNpm) {