119e18c810
- Extract atlas/ into 15 focused modules (hook, event handler, tool policies, types, etc.) - Split auto-update-checker into checker/ and hook/ subdirectories with single-purpose files - Decompose session-recovery into separate recovery strategy files per error type - Extract todo-continuation-enforcer from monolith to directory with dedicated modules - Split background-task/tools.ts into individual tool creator files - Extract command-executor, tmux-utils into focused sub-modules - Split config/schema.ts into domain-specific schema files - Decompose cli/config-manager.ts into focused modules - Rollback skill-mcp-manager, model-availability, index.ts splits that broke tests - Fix all import path depths for moved files (../../ -> ../../../) - Add explicit type annotations to resolve TS7006 implicit any errors Typecheck: 0 errors Tests: 2359 pass, 5 fail (all pre-existing)
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import * as fs from "node:fs"
|
|
import { log } from "../../../shared/logger"
|
|
import { PACKAGE_NAME } from "../constants"
|
|
|
|
export function updatePinnedVersion(configPath: string, oldEntry: string, newVersion: string): boolean {
|
|
try {
|
|
const content = fs.readFileSync(configPath, "utf-8")
|
|
const newEntry = `${PACKAGE_NAME}@${newVersion}`
|
|
|
|
const pluginMatch = content.match(/"plugin"\s*:\s*\[/)
|
|
if (!pluginMatch || pluginMatch.index === undefined) {
|
|
log(`[auto-update-checker] No "plugin" array found in ${configPath}`)
|
|
return false
|
|
}
|
|
|
|
const startIndex = pluginMatch.index + pluginMatch[0].length
|
|
let bracketCount = 1
|
|
let endIndex = startIndex
|
|
|
|
for (let i = startIndex; i < content.length && bracketCount > 0; i++) {
|
|
if (content[i] === "[") bracketCount++
|
|
else if (content[i] === "]") bracketCount--
|
|
endIndex = i
|
|
}
|
|
|
|
const before = content.slice(0, startIndex)
|
|
const pluginArrayContent = content.slice(startIndex, endIndex)
|
|
const after = content.slice(endIndex)
|
|
|
|
const escapedOldEntry = oldEntry.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
const regex = new RegExp(`["']${escapedOldEntry}["']`)
|
|
|
|
if (!regex.test(pluginArrayContent)) {
|
|
log(`[auto-update-checker] Entry "${oldEntry}" not found in plugin array of ${configPath}`)
|
|
return false
|
|
}
|
|
|
|
const updatedPluginArray = pluginArrayContent.replace(regex, `"${newEntry}"`)
|
|
const updatedContent = before + updatedPluginArray + after
|
|
|
|
if (updatedContent === content) {
|
|
log(`[auto-update-checker] No changes made to ${configPath}`)
|
|
return false
|
|
}
|
|
|
|
fs.writeFileSync(configPath, updatedContent, "utf-8")
|
|
log(`[auto-update-checker] Updated ${configPath}: ${oldEntry} → ${newEntry}`)
|
|
return true
|
|
} catch (err) {
|
|
log(`[auto-update-checker] Failed to update config file ${configPath}:`, err)
|
|
return false
|
|
}
|
|
}
|