Skip to content

Commit 6f15712

Browse files
authored
Merge pull request #381 from misterdas/fix/critical-bugs-and-improvements
fix: critical bugs and error handling improvements
2 parents a49cf11 + 9d46a8f commit 6f15712

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/config.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ export function validateConfigTypes(config: Record<string, any>): ValidationErro
243243
actual: typeof config.turnProtection.turns,
244244
})
245245
}
246+
if (typeof config.turnProtection.turns === "number" && config.turnProtection.turns < 1) {
247+
errors.push({
248+
key: "turnProtection.turns",
249+
expected: "positive number (>= 1)",
250+
actual: `${config.turnProtection.turns}`,
251+
})
252+
}
246253
}
247254

248255
// Commands validator
@@ -326,6 +333,16 @@ export function validateConfigTypes(config: Record<string, any>): ValidationErro
326333
actual: typeof tools.settings.nudgeFrequency,
327334
})
328335
}
336+
if (
337+
typeof tools.settings.nudgeFrequency === "number" &&
338+
tools.settings.nudgeFrequency < 1
339+
) {
340+
errors.push({
341+
key: "tools.settings.nudgeFrequency",
342+
expected: "positive number (>= 1)",
343+
actual: `${tools.settings.nudgeFrequency} (will be clamped to 1)`,
344+
})
345+
}
329346
if (
330347
tools.settings.protectedTools !== undefined &&
331348
!Array.isArray(tools.settings.protectedTools)
@@ -497,6 +514,17 @@ export function validateConfigTypes(config: Record<string, any>): ValidationErro
497514
actual: typeof strategies.purgeErrors.turns,
498515
})
499516
}
517+
// Warn if turns is 0 or negative - will be clamped to 1
518+
if (
519+
typeof strategies.purgeErrors.turns === "number" &&
520+
strategies.purgeErrors.turns < 1
521+
) {
522+
errors.push({
523+
key: "strategies.purgeErrors.turns",
524+
expected: "positive number (>= 1)",
525+
actual: `${strategies.purgeErrors.turns} (will be clamped to 1)`,
526+
})
527+
}
500528
if (
501529
strategies.purgeErrors.protectedTools !== undefined &&
502530
!Array.isArray(strategies.purgeErrors.protectedTools)

lib/messages/inject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export const insertPruneToolContext = (
274274
contentParts.push(renderCompressNudge())
275275
} else if (
276276
config.tools.settings.nudgeEnabled &&
277-
state.nudgeCounter >= config.tools.settings.nudgeFrequency
277+
state.nudgeCounter >= Math.max(1, config.tools.settings.nudgeFrequency)
278278
) {
279279
logger.info("Inserting prune nudge message")
280280
contentParts.push(getNudgeString(config))

lib/strategies/purge-errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const purgeErrors = (
3939
}
4040

4141
const protectedTools = config.strategies.purgeErrors.protectedTools
42-
const turnThreshold = config.strategies.purgeErrors.turns
42+
const turnThreshold = Math.max(1, config.strategies.purgeErrors.turns)
4343

4444
const newPruneIds: string[] = []
4545

0 commit comments

Comments
 (0)