Description
This issue addresses several bugs, code smells, and TypeScript errors discovered during static analysis (linting and type checking).
1. Unused Imports in Test Files
- File:
apps/web/lib/chat-agent-registry.test.ts
- Issue: The imports
existsSync and mkdirSync from node:fs are declared but never used in the file, cluttering the import block.
2. Dead Code (Unused Function and Variable)
- File:
apps/web/lib/denchclaw-state.ts
- Issue: The function
defaultEmailBodyHydrationAttempted is defined but never invoked anywhere in the codebase.
- File:
apps/web/lib/active-runs.ts
- Issue: The variable
everSentResponseActivity is declared and assigned values in the wireSubscribeOnlyProcess function, but it is never used in that scope.
3. Array Mutation Bug
- File:
apps/web/lib/denchclaw-state.ts
- Issue: The code uses
Array.from(current).sort(). The sort() method mutates the array in place. While Array.from creates a new array, using .toSorted() is the more modern, idiomatic, and safer approach to ensure arrays are sorted without unintended side effects (as flagged by eslint-plugin-unicorn(no-array-sort)).
4. TypeScript Error in AI Gateway
- File:
extensions/dench-ai-gateway/sync-trigger.ts
- Issue: There is a TypeScript error:
Element implicitly has an 'any' type because expression of type '"syncTrigger"' can't be used to index type '{}'. This occurs because pluginConfig?.config is not properly typed before attempting to access the ["syncTrigger"] property.
5. Arrow Function Body Formatting and Object Spreads
- File:
apps/web/lib/active-runs.test.ts
- Issue: The linter flags single-line arrow function bodies (e.g.
subscribeToRun(idA, (e) => { if (e) eventsA.push(e); }, { replay: false });) that lack curly braces after the if statement.
- File:
apps/web/lib/active-runs.ts
- Issue: The linter flags a useless fallback in an object spread (
...(details ?? {}) where details is already an object).
Proposed Solution
- Remove the unused imports from
chat-agent-registry.test.ts.
- Delete the unused
defaultEmailBodyHydrationAttempted function from denchclaw-state.ts and the everSentResponseActivity variable from active-runs.ts.
- Replace
.sort() with .toSorted() in denchclaw-state.ts.
- Add proper type assertion (
as Record<string, unknown>) when accessing the config in sync-trigger.ts to satisfy the TypeScript compiler.
- Add curly braces to the arrow function bodies in
active-runs.test.ts.
- Remove the unnecessary
?? {} fallback in the object spread in active-runs.ts.
Description
This issue addresses several bugs, code smells, and TypeScript errors discovered during static analysis (linting and type checking).
1. Unused Imports in Test Files
apps/web/lib/chat-agent-registry.test.tsexistsSyncandmkdirSyncfromnode:fsare declared but never used in the file, cluttering the import block.2. Dead Code (Unused Function and Variable)
apps/web/lib/denchclaw-state.tsdefaultEmailBodyHydrationAttemptedis defined but never invoked anywhere in the codebase.apps/web/lib/active-runs.tseverSentResponseActivityis declared and assigned values in thewireSubscribeOnlyProcessfunction, but it is never used in that scope.3. Array Mutation Bug
apps/web/lib/denchclaw-state.tsArray.from(current).sort(). Thesort()method mutates the array in place. WhileArray.fromcreates a new array, using.toSorted()is the more modern, idiomatic, and safer approach to ensure arrays are sorted without unintended side effects (as flagged byeslint-plugin-unicorn(no-array-sort)).4. TypeScript Error in AI Gateway
extensions/dench-ai-gateway/sync-trigger.tsElement implicitly has an 'any' type because expression of type '"syncTrigger"' can't be used to index type '{}'. This occurs becausepluginConfig?.configis not properly typed before attempting to access the["syncTrigger"]property.5. Arrow Function Body Formatting and Object Spreads
apps/web/lib/active-runs.test.tssubscribeToRun(idA, (e) => { if (e) eventsA.push(e); }, { replay: false });) that lack curly braces after theifstatement.apps/web/lib/active-runs.ts...(details ?? {})wheredetailsis already an object).Proposed Solution
chat-agent-registry.test.ts.defaultEmailBodyHydrationAttemptedfunction fromdenchclaw-state.tsand theeverSentResponseActivityvariable fromactive-runs.ts..sort()with.toSorted()indenchclaw-state.ts.as Record<string, unknown>) when accessing the config insync-trigger.tsto satisfy the TypeScript compiler.active-runs.test.ts.?? {}fallback in the object spread inactive-runs.ts.