refactor: extract duplicated code into shared utilities#157
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: extract duplicated code into shared utilities#157devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- Create src/shared/strings.ts with escapeHtml, truncate, isRecord, errorMessage - Create src/chat/page-tools.ts consolidating page-tool normalization helpers - Replace 4 duplicate escapeHtml implementations with shared import - Replace 6 duplicate truncate implementations with shared import - Replace 4 duplicate isRecord/isObject type guards with shared import - Consolidate ~13 duplicated page-tool helpers (normalizePageToolName, normalizePageUrl, normalizePagePath, stringField, numberField, etc.) from run-timeline.ts and continuity-context.ts - Replace err instanceof Error ? err.message : String(err) with errorMessage() in 13 high-frequency files (~75 call sites) All 2640 tests pass. Lint and typecheck clean. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
Extracts widespread duplicated code patterns into two shared utility modules and updates all consumers to import from the canonical source.
New files:
src/shared/strings.ts—escapeHtml,truncate,isRecord,errorMessagesrc/chat/page-tools.ts— page-tool normalization helpers (normalizePageToolName,normalizePageUrl,normalizePagePath,stringField,numberField,parseJsonRecord,urlFromPath,urlFromText,stripTrailingPunctuation,hasSensitiveQuery)Deduplicated patterns (29 files touched, net -65 lines):
escapeHtml()ui/html.ts,chat/util/escape.ts,core/health-page.ts,secrets/form-page.tstruncate()mcp/audit.ts,evolution/gate.ts,evolution/invariant-check.ts,agent/judge-query.ts,channels/slack/render-first-hour-dm.tsisRecord()/isObject()chat/sdk-to-wire.ts,chat/transcript-search.ts,chat/run-timeline.ts,agent/murph-context.tschat/run-timeline.ts,chat/continuity-context.tserr instanceof Error ? err.message : String(err)index.ts,**/storage.ts,channels/*.ts,scheduler/service.ts, etc.)Existing re-export modules (
ui/html.ts,chat/util/escape.ts) are preserved as thin re-exports so no downstream import paths break.Why
The codebase had identical utility functions copy-pasted across subsystems. This creates maintenance risk: a bugfix in one copy doesn't propagate, and slightly different implementations (e.g.
escapeHtmlinsecrets/form-page.tsmissing'escaping) can introduce subtle inconsistencies. Centralizing these intosrc/shared/strings.tsandsrc/chat/page-tools.tsgives a single place to maintain each pattern.How I Tested
Checklist
bun test)bun run lint)bun run typecheck).envfiles includedLink to Devin session: https://app.devin.ai/sessions/5fa2d0c4926149aa9cd093df6997936a
Requested by: @mcheemaa