Skip to content

refactor: consolidate cross-module code duplication - #33

Merged
klpanagi merged 4 commits into
devfrom
feat/cleanup_c
Jul 28, 2026
Merged

refactor: consolidate cross-module code duplication#33
klpanagi merged 4 commits into
devfrom
feat/cleanup_c

Conversation

@klpanagi

Copy link
Copy Markdown
Owner

Summary

Consolidated 9 categories of code duplication across the codebase into shared utilities. ~80 net lines removed, 1 bug fixed.

Changes

Category Impact
delay() 4 private duplicates → shared, backward compat via re-export
formatDuration() Removed duplicate from error-helpers.ts
formatBytes() Extracted to shared with tests (4 passing)
Sentinels NOT_CACHED + FALSE_PENDING_RETRY centralized in sentinels.ts
isAbortError() 2 byte-identical files consolidated, 2 deleted, 7 tests
withTimeout() 4 implementations → shared, fixed clearTimeout leak in session-manager/tools.ts
isRecord() 11 sites now import from shared record-type-guard
getErrorMessage() Added to error-formatting.ts, 2 duplicates replaced
TaskStatus Extracted to shared status-types.ts, 2 consumers updated

Verification

  • tsc --noEmit → 0 errors
  • bun run lint → 0 errors
  • bun test src/shared/ → 15/15 pass (new tests)

klpanagi added 4 commits July 28, 2026 17:24
- Delete is-object.ts (duplicate of record-type-guard.ts)
- Merge session-temperature-store, session-tools-store, session-model-state into session-state.ts
- Merge model-resolution-types into model-resolution-pipeline.ts
- Delete model-resolver.ts (resolveModel inlined in categories.ts, resolveModelWithFallback dead code)
- Delete opencode-config-dir-types.ts (types inlined into opencode-config-dir.ts)
- Update 20+ import paths across the codebase
- Clean barrel index.ts (remove dead/duplicate exports)
- Migrate 10 consumer files from barrel to direct imports
- Update model-resolver tests to use resolveModelPipeline directly
…sAbortError, isRecord, sentinels, formatBytes, status types, getErrorMessage)

- delay(): 4 private duplicates consolidated to shared, backward compat via re-export
- formatDuration(): duplicate in error-helpers.ts redirected to shared
- formatBytes(): extracted from message-builder.ts to shared with tests
- sentinels.ts: NOT_CACHED + FALSE_PENDING_RETRY Symbols centralized
- isAbortError(): 2 byte-identical implementations consolidated with 7 tests
- withTimeout(): 4 implementations consolidated, fixes clearTimeout leak in session-manager
- isRecord(): adopted across 11 files, local definitions removed
- getErrorMessage(): added to error-formatting.ts, 2 duplicates replaced
- TaskStatus type: extracted to shared, 2 consumers updated
The original extractMessage function handled objects with .message,
but the shared getErrorMessage replacement didn't. This caused
parseModelSuggestion to fail on plain objects with a message field.
@klpanagi
klpanagi merged commit c093ff5 into dev Jul 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant