fix(cliproxy): improve sync robustness and consistency

- Add timeout warning in restartAutoSyncWatcher when sync exceeds 10s
- Improve YAML key detection with regex pattern for safer parsing
- Replace --force help with --verbose (no confirmation prompt exists)
- Add force flag parsing for future use
This commit is contained in:
kaitranntt
2026-01-28 13:49:46 -05:00
parent e80d2d2d05
commit 4124780ce0
4 changed files with 10 additions and 3 deletions
+4
View File
@@ -169,6 +169,10 @@ export async function restartAutoSyncWatcher(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 100));
}
if (isSyncing) {
log('Warning: Sync still in progress after 10s timeout, proceeding with restart');
}
await stopAutoSyncWatcher();
startAutoSyncWatcher();
}
+3 -2
View File
@@ -124,13 +124,14 @@ function replaceSectionInYaml(content: string, sectionKey: string, newSection: s
// If we're in the section, skip lines until we hit another top-level key
if (inSection) {
// Top-level key starts at column 0 and has format "key:" or "key :"
// Top-level key: starts at column 0, valid YAML key format (word chars + hyphens)
// Must match pattern like "key:", "my-key:", "key_name:" but not comments or strings
const isTopLevelKey =
line.length > 0 &&
!line.startsWith(' ') &&
!line.startsWith('\t') &&
!line.startsWith('#') &&
line.includes(':');
/^[a-zA-Z_][a-zA-Z0-9_-]*\s*:/.test(line);
if (isTopLevelKey) {
// We've exited the section, resume normal processing
+1 -1
View File
@@ -621,7 +621,7 @@ async function showHelp(): Promise<void> {
[
['sync', 'Sync API profiles to local CLIProxy config'],
['sync --dry-run', 'Preview sync without applying'],
['sync --force', 'Sync without confirmation prompt'],
['sync --verbose', 'Show detailed sync information'],
],
],
[
+2
View File
@@ -10,6 +10,7 @@ import { initUI, header, subheader, color, dim, ok, fail, warn, info, table } fr
interface SyncArgs {
dryRun: boolean;
verbose: boolean;
force: boolean;
}
/**
@@ -19,6 +20,7 @@ export function parseSyncArgs(args: string[]): SyncArgs {
return {
dryRun: args.includes('--dry-run') || args.includes('-n'),
verbose: args.includes('--verbose') || args.includes('-v'),
force: args.includes('--force') || args.includes('-f'),
};
}