Skip to content

Commit caac070

Browse files
committed
Address maintainer feedback - simplify error handling, expand validation
Changes: - Remove custom error classes - revert to simple error strings (maintainer confirmed strings aren't matched, just used for control flow) - Add devError method to logger for developer-only errors (no TUI output) - Expand numeric validation to all fields: - nudgeFrequency: validate >= 1, clamp at runtime - turnProtection.turns: validate >= 1 (already has runtime check) - purgeErrors.turns: already validated >= 1 - Add runtime clamping for nudgeFrequency in inject.ts Fixes maintainer concerns: 1. Custom error classes were overkill for simple control flow 2. Numeric validation now covers all numeric config fields
1 parent 3a1f2ba commit caac070

File tree

5 files changed

+23
-82
lines changed

5 files changed

+23
-82
lines changed

lib/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,17 @@ export function validateConfigTypes(config: Record<string, any>): ValidationErro
337337
actual: typeof tools.settings.nudgeFrequency,
338338
})
339339
}
340+
// Warn if nudgeFrequency is 0 or negative
341+
if (
342+
typeof tools.settings.nudgeFrequency === "number" &&
343+
tools.settings.nudgeFrequency < 1
344+
) {
345+
errors.push({
346+
key: "tools.settings.nudgeFrequency",
347+
expected: "positive number (>= 1)",
348+
actual: `${tools.settings.nudgeFrequency} (will be clamped to 1)`,
349+
})
350+
}
340351
if (
341352
tools.settings.protectedTools !== undefined &&
342353
!Array.isArray(tools.settings.protectedTools)

lib/errors.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

lib/hooks.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ import { handleSweepCommand } from "./commands/sweep"
1414
import { handleManualToggleCommand, handleManualTriggerCommand } from "./commands/manual"
1515
import { ensureSessionInitialized } from "./state/state"
1616
import { getCurrentParams } from "./strategies/utils"
17-
import {
18-
DCPContextHandledError,
19-
DCPStatsHandledError,
20-
DCPSweepHandledError,
21-
DCPManualHandledError,
22-
DCPManualTriggerBlockedError,
23-
DCPHelpHandledError,
24-
} from "./errors"
2517

2618
const INTERNAL_AGENT_SIGNATURES = [
2719
"You are a title generator",
@@ -180,12 +172,12 @@ export function createCommandExecuteHandler(
180172

181173
if (subcommand === "context") {
182174
await handleContextCommand(commandCtx)
183-
throw new DCPContextHandledError()
175+
throw new Error("__DCP_CONTEXT_HANDLED__")
184176
}
185177

186178
if (subcommand === "stats") {
187179
await handleStatsCommand(commandCtx)
188-
throw new DCPStatsHandledError()
180+
throw new Error("__DCP_STATS_HANDLED__")
189181
}
190182

191183
if (subcommand === "sweep") {
@@ -194,12 +186,12 @@ export function createCommandExecuteHandler(
194186
args: subArgs,
195187
workingDirectory,
196188
})
197-
throw new DCPSweepHandledError()
189+
throw new Error("__DCP_SWEEP_HANDLED__")
198190
}
199191

200192
if (subcommand === "manual") {
201193
await handleManualToggleCommand(commandCtx, subArgs[0]?.toLowerCase())
202-
throw new DCPManualHandledError()
194+
throw new Error("__DCP_MANUAL_HANDLED__")
203195
}
204196

205197
if (
@@ -209,7 +201,7 @@ export function createCommandExecuteHandler(
209201
const userFocus = subArgs.join(" ").trim()
210202
const prompt = await handleManualTriggerCommand(commandCtx, subcommand, userFocus)
211203
if (!prompt) {
212-
throw new DCPManualTriggerBlockedError()
204+
throw new Error("__DCP_MANUAL_TRIGGER_BLOCKED__")
213205
}
214206

215207
state.pendingManualTrigger = {
@@ -226,7 +218,7 @@ export function createCommandExecuteHandler(
226218
}
227219

228220
await handleHelpCommand(commandCtx)
229-
throw new DCPHelpHandledError()
221+
throw new Error("__DCP_HELP_HANDLED__")
230222
}
231223
}
232224
}

lib/logger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export class Logger {
111111
return this.write("ERROR", component, message, data)
112112
}
113113

114+
devError(message: string, data?: any) {
115+
// Developer error log - only writes to file, never to console/TUI
116+
this.error(message, data)
117+
}
118+
114119
/**
115120
* Strips unnecessary metadata from messages for cleaner debug logs.
116121
*

lib/messages/inject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export const insertPruneToolContext = (
260260
contentParts.push(renderCompressNudge())
261261
} else if (
262262
config.tools.settings.nudgeEnabled &&
263-
state.nudgeCounter >= config.tools.settings.nudgeFrequency
263+
state.nudgeCounter >= Math.max(1, config.tools.settings.nudgeFrequency)
264264
) {
265265
logger.info("Inserting prune nudge message")
266266
contentParts.push(getNudgeString(config))

0 commit comments

Comments
 (0)