Skip to content

Commit b407f1d

Browse files
committed
Refactor backup logic to simplify backupFile function and streamline agent implementations
1 parent 8171946 commit b407f1d

13 files changed

+20
-43
lines changed

src/agents/AiderAgent.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export class AiderAgent implements IAgent {
2525
const mdPath =
2626
agentConfig?.outputPathInstructions ??
2727
this.getDefaultOutputPath(projectRoot).instructions;
28-
if (!agentConfig?.disableBackup) {
29-
await backupFile(mdPath);
30-
}
28+
await backupFile(mdPath, agentConfig?.disableBackup);
3129
await writeGeneratedFile(mdPath, concatenatedRules);
3230

3331
const cfgPath =
@@ -40,9 +38,7 @@ export class AiderAgent implements IAgent {
4038
let doc: AiderConfig = {} as AiderConfig;
4139
try {
4240
await fs.access(cfgPath);
43-
if (!agentConfig?.disableBackup) {
44-
await backupFile(cfgPath);
45-
}
41+
await backupFile(cfgPath, agentConfig?.disableBackup);
4642
const raw = await fs.readFile(cfgPath, 'utf8');
4743
doc = (yaml.load(raw) || {}) as AiderConfig;
4844
} catch {

src/agents/AugmentCodeAgent.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ export class AugmentCodeAgent implements IAgent {
3030
): Promise<void> {
3131
const output =
3232
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
33-
if (!agentConfig?.disableBackup) {
34-
await backupFile(output);
35-
}
33+
await backupFile(output, agentConfig?.disableBackup);
3634
await writeGeneratedFile(output, concatenatedRules);
3735

3836
if (rulerMcpJson) {
3937
const settingsPath = getVSCodeSettingsPath(projectRoot);
40-
if (!agentConfig?.disableBackup) {
41-
await backupFile(settingsPath);
42-
}
38+
await backupFile(settingsPath, agentConfig?.disableBackup);
4339

4440
const existingSettings = await readVSCodeSettings(settingsPath);
4541
const augmentServers = transformRulerToAugmentMcp(rulerMcpJson);

src/agents/ClaudeAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export class ClaudeAgent implements IAgent {
2222
): Promise<void> {
2323
const output =
2424
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
25-
if (!agentConfig?.disableBackup) {
26-
await backupFile(output);
27-
}
25+
await backupFile(output, agentConfig?.disableBackup);
2826
await writeGeneratedFile(output, concatenatedRules);
2927
}
3028
getDefaultOutputPath(projectRoot: string): string {

src/agents/ClineAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export class ClineAgent implements IAgent {
2222
): Promise<void> {
2323
const output =
2424
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
25-
if (!agentConfig?.disableBackup) {
26-
await backupFile(output);
27-
}
25+
await backupFile(output, agentConfig?.disableBackup);
2826
await writeGeneratedFile(output, concatenatedRules);
2927
}
3028
getDefaultOutputPath(projectRoot: string): string {

src/agents/CodexCliAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export class CodexCliAgent implements IAgent {
3434
defaults.instructions;
3535

3636
// Write the instructions file
37-
if (!agentConfig?.disableBackup) {
38-
await backupFile(instructionsPath);
39-
}
37+
await backupFile(instructionsPath, agentConfig?.disableBackup);
4038
await writeGeneratedFile(instructionsPath, concatenatedRules);
4139

4240
// Handle MCP configuration if enabled

src/agents/CopilotAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ export class CopilotAgent implements IAgent {
2727
const output =
2828
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
2929
await ensureDirExists(path.dirname(output));
30-
if (!agentConfig?.disableBackup) {
31-
await backupFile(output);
32-
}
30+
await backupFile(output, agentConfig?.disableBackup);
3331
await writeGeneratedFile(output, concatenatedRules);
3432
}
3533
getDefaultOutputPath(projectRoot: string): string {

src/agents/CursorAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export class CursorAgent implements IAgent {
3333
const content = `${frontMatter}${concatenatedRules.trimStart()}`;
3434

3535
await ensureDirExists(path.dirname(output));
36-
if (!agentConfig?.disableBackup) {
37-
await backupFile(output);
38-
}
36+
await backupFile(output, agentConfig?.disableBackup);
3937
await writeGeneratedFile(output, content);
4038
}
4139
getDefaultOutputPath(projectRoot: string): string {

src/agents/FirebaseAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export class FirebaseAgent implements IAgent {
2222
): Promise<void> {
2323
const output =
2424
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
25-
if (!agentConfig?.disableBackup) {
26-
await backupFile(output);
27-
}
25+
await backupFile(output, agentConfig?.disableBackup);
2826
await writeGeneratedFile(output, concatenatedRules);
2927
}
3028

src/agents/JunieAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ export class JunieAgent implements IAgent {
2727
const output =
2828
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
2929
await ensureDirExists(path.dirname(output));
30-
if (!agentConfig?.disableBackup) {
31-
await backupFile(output);
32-
}
30+
await backupFile(output, agentConfig?.disableBackup);
3331
await writeGeneratedFile(output, concatenatedRules);
3432
}
3533
getDefaultOutputPath(projectRoot: string): string {

src/agents/KiloCodeAgent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export class KiloCodeAgent implements IAgent {
2828
const output =
2929
agentConfig?.outputPath ?? this.getDefaultOutputPath(projectRoot);
3030
await ensureDirExists(path.dirname(output));
31-
if (!agentConfig?.disableBackup) {
32-
await backupFile(output);
33-
}
31+
await backupFile(output, agentConfig?.disableBackup);
3432
await writeGeneratedFile(output, concatenatedRules);
3533
}
3634

0 commit comments

Comments
 (0)