Skip to content

Reduce complexity warnings across scoring logic and UI flows - #25

Merged
leejsinclair merged 2 commits into
mainfrom
copilot/reduce-complexity
May 16, 2026
Merged

Reduce complexity warnings across scoring logic and UI flows#25
leejsinclair merged 2 commits into
mainfrom
copilot/reduce-complexity

Conversation

Copilot AI commented May 16, 2026

Copy link
Copy Markdown
Contributor

Pull Request Template

📝 Summary

This PR removes the complexity warnings called out by npm run lint without changing the story/criteria flow. It breaks up branching-heavy scoring, AI, and UI orchestration paths into smaller helpers and focused subcomponents.

🔧 Changes

  • Scoring engine: split complex criteria scoring paths into focused helpers for feedback, suggestions, completeness, per-criterion grading, and shared matching utilities.
  • AI service: extracted reusable request/validation helpers in llmService so prompt construction, payload validation, fallback generation, and API handling no longer sit behind large conditional blocks.
  • UI flow orchestration: decomposed App into smaller phase/result/panel components and extracted shared helpers for scrolling, history hydration, and AI suggestion application.
  • Form rendering: pulled acceptance-criteria and story tooltip/rating logic into dedicated helpers/components to flatten nested render branches while keeping current UX intact.
  • Documentation: added targeted JSDoc blocks for the extracted helpers introduced by the refactor.
function buildImproveCriteriaRequest(criteriaDraftInput, criteriaDraftResult, confirmedStory, aiApiKey) {
  return {
    criteria: criteriaDraftInput?.criteria,
    format: criteriaDraftInput?.format,
    draftScore: criteriaDraftResult?.totalScore,
    breakdown: criteriaDraftResult?.breakdown,
    hintTargets: criteriaDraftResult?.hintTargets,
    story: confirmedStory,
    apiKey: aiApiKey,
  };
}

🎯 Motivation

The lint output was dominated by complexity warnings in a few central scoring and UI coordination paths, which made the code harder to change safely. This refactor reduces that branching density while preserving existing behavior and keeping lint/test verification green.

🧪 Testing

  • npm run lint
  • npm run verify

📸 Screenshots (optional)

N/A

✅ Checklist

  • Code compiles and runs
  • Tests added or updated (if applicable)
  • Documentation updated (if needed)
  • No linting or formatting issues
  • PR title is clear and descriptive

Copilot AI and others added 2 commits May 16, 2026 05:55
Agent-Logs-Url: https://github.com/leejsinclair/kipling-v2/sessions/fb0b5a0e-af7e-4856-b531-ae5ded0bcba7

Co-authored-by: leejsinclair <707675+leejsinclair@users.noreply.github.com>
Agent-Logs-Url: https://github.com/leejsinclair/kipling-v2/sessions/fb0b5a0e-af7e-4856-b531-ae5ded0bcba7

Co-authored-by: leejsinclair <707675+leejsinclair@users.noreply.github.com>
@leejsinclair
leejsinclair marked this pull request as ready for review May 16, 2026 06:01
Copilot AI review requested due to automatic review settings May 16, 2026 06:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactor focused on reducing lint complexity warnings in scoring, AI, and UI orchestration code paths by extracting helpers and decomposing large components. Intent is to keep behavior identical while flattening branching.

Changes:

  • Extracted helpers in llmService.js (error normalization, API fetch, validation, fallback builders) and helpers in criteriaScoring.js (feedback/suggestion/completeness/format/testability/specificity/alignment).
  • Split App.jsx into many small phase/result/panel/section subcomponents and shared helpers (scrollToPageBottom, buildStoryText, etc.).
  • Pulled tooltip data + subcomponents out of StoryForm.jsx, AcceptanceCriteriaForm.jsx, and StoryHistory.jsx.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/llmService.js Refactored error matching, payload validation, fetch, and fallbacks into helpers.
src/criteriaScoring.js Broke scoring of criteria and single-criterion paths into focused helpers; introduced rule tables.
src/components/StoryHistory.jsx Extracted StoryDetailsModal subcomponent.
src/components/StoryForm.jsx Lifted SoThatFeedback and tooltip content tables out of the component body.
src/components/AcceptanceCriteriaForm.jsx Extracted criterion editor/tooltip subcomponents and tier mapping.
src/App.jsx Decomposed App into phase/section/panel components and helper functions.

Comment thread src/criteriaScoring.js
Comment on lines +549 to +554
const presentKeywords = [hasGiven, hasWhen, hasThen].filter(Boolean).length;
const hasFullStructure = hasWhen && presentKeywords >= 2;

if (hasFullStructure) {
return { score: hasAnd ? 5 : 4, feedback: [] };
}
Comment thread src/App.jsx
setTimeout(() => {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}, 100);
scrollToPageBottom();
@leejsinclair
leejsinclair merged commit fcc03d9 into main May 16, 2026
5 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.

3 participants