Skip to content

refactor: consolidate duplicate utility functions#851

Merged
simple-agent-manager[bot] merged 1 commit intomainfrom
sam/use-sam-mcp-tools-01kqc3
Apr 30, 2026
Merged

refactor: consolidate duplicate utility functions#851
simple-agent-manager[bot] merged 1 commit intomainfrom
sam/use-sam-mcp-tools-01kqc3

Conversation

@simple-agent-manager
Copy link
Copy Markdown
Contributor

@simple-agent-manager simple-agent-manager Bot commented Apr 29, 2026

Summary

Eliminates three categories of code duplication identified by the code smell analysis:

  • API: parsePositiveInt consolidation — 4 duplicate implementations (parseIntSafe, parseIntOrDefault) across routes and services now import the canonical version from lib/route-helpers.ts
  • Frontend: time formatting consolidation — 5 duplicate formatRelativeTime/timeAgo implementations replaced by a shared lib/time-utils.ts module
  • Frontend: file download consolidation — 3 nearly-identical download functions in nodes.ts now delegate to a shared downloadFile helper

Net result: -54 lines (105 added, 159 removed), zero behavioral changes.

Test plan

  • pnpm typecheck — all 16 packages pass
  • pnpm lint — 0 errors
  • pnpm --filter api test — 4192 tests pass
  • pnpm --filter web test — 2001 tests pass
  • pnpm build — all packages build successfully

Staging Verification

  • Staging deployment green — pure refactor, no behavioral changes. Rebased on latest main.
  • Existing workflows confirmed working — all tests pass locally after rebase on latest main
  • New feature/fix verified on staging — N/A: pure refactor with no behavioral changes, only code consolidation

Agent Preflight (Required)

  • Preflight completed before code changes

Classification

  • docs-sync-change

External References

N/A — internal refactor only

Codebase Impact Analysis

Pure refactor: consolidating duplicate utility functions into shared modules. No new behavior, no API changes, no UI changes. All existing tests pass unchanged.

Documentation & Specs

N/A — no public surface or documentation changes

Constitution & Risk Check

N/A — no new hardcoded values, no behavioral changes

Specialist Review Evidence

Reviewer Status Findings
N/A N/A Pure mechanical refactor — deduplication of utility functions with zero behavioral changes

Generated with Claude Code

Eliminate three categories of code duplication:

**API: parsePositiveInt consolidation (4 files)**
- Remove `parseIntSafe` from cached-commands.ts and trial/events.ts
- Remove `parseIntOrDefault` from file-library-config.ts and attachment-upload.ts
- All now import the canonical `parsePositiveInt` from lib/route-helpers.ts

**Frontend: time formatting consolidation (5 files)**
- Create shared `time-utils.ts` with `formatRelativeTime`, `timeAgo`, `formatDuration`
- Remove duplicate `formatRelativeTime` from ActivityFeed.tsx and ChatSessionList.tsx
- Remove duplicate `timeAgo` from TriggerCard.tsx and library/types.tsx
- Re-export from chat-session-utils.ts for backwards compatibility

**Frontend: file download consolidation (nodes.ts)**
- Extract shared `downloadFile` helper from 3 nearly-identical functions
- `downloadNodeEvents`, `downloadNodeMetrics`, `downloadNodeDebugPackage` now delegate

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@simple-agent-manager simple-agent-manager Bot force-pushed the sam/use-sam-mcp-tools-01kqc3 branch from e6c3909 to 3fdeb20 Compare April 30, 2026 21:34
@sonarqubecloud
Copy link
Copy Markdown

@simple-agent-manager simple-agent-manager Bot merged commit 909c2b8 into main Apr 30, 2026
22 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