refactor(ai): unify provider flow and update ai routes#67
Merged
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
…attern - Extend emptyAnalysis object with all required metadata fields (description, forks, language, sha, url, license, createdAt, updatedAt) - Fix regex pattern to explicitly match 4-space indentation for node detection instead of generic whitespace - Add clarifying comment to explain arrow count validation (matching Mermaid `-->` syntax, not HTML filtering) - LGTM alert mitigation for potential bad tag filter
Contributor
There was a problem hiding this comment.
5 issues found across 42 files
Confidence score: 3/5
- In
src/components/viz/architecture/hooks/useArchitectureState.ts, stale async cycles can still callsetToastMessagein.catchafter a re-render, so users may see error toasts for work that was already superseded; guard the toast update with the sameactivecheck used forsetRenderErrorbefore merging. - In
src/lib/clipboard.ts, the fallbackdocument.execCommand('copy')result is ignored, so failed copies can be reported as success and callers won’t get the documented throw behavior; check the boolean return and throw on failure to align runtime behavior with the function contract. - In
server/search/indexing-pipeline.test.tsandserver/parser/dependency-analyzer.test.ts, test intent is currently under-verified (misnamed cosine helper and weak workspace-manifest assertion), which raises regression risk by allowing incorrect behavior to pass; tighten these assertions before merge to keep future changes safer.
Architecture diagram
sequenceDiagram
participant Client as React SPA (src/)
participant API as API Client (lib/apiClient.ts)
participant Router as Server Router (ai-routes.ts)
participant Task as AI Task Handler (summarizer.ts + tasks/)
participant Provider as AI Provider (provider.ts)
participant ExtAPI as External AI API
participant Clipboard as Clipboard Utility (lib/clipboard.ts)
participant Store as VizStore (stores/vizStore.ts)
Note over Client,Store: Unified AI Provider Flow (Refactored)
Client->>API: aiExplain(owner, repo, branch)
API->>Router: POST /api/ai/explain
Router->>Router: parse body, validate schema, extract user API key / GitHub token
Router->>Task: explainRepo(owner, repo, branch, apiKey, token)
Task->>Task: analyze repository (fetch tree, deps)
Task->>Task: executeAiTask(taskName: 'explain')
Task->>Provider: getAIProvider() or createProvider(apiKey)
Note over Provider: Auto-detect provider: Gemini, OpenAI, Anthropic, or mock fallback
Provider->>ExtAPI: .complete(messages) (with SDK)
ExtAPI-->>Provider: JSON response
Provider-->>Task: { data, cached }
Task-->>Router: { explanation, cached }
Router-->>API: Response.json()
API-->>Client: AIExplainResponse
Note over Client,Store: Clipboard Copy Flow (NEW: shared utility + toast for errors)
Client->>Clipboard: copyToClipboard(text)
alt navigator.clipboard available
Clipboard->>Clipboard: navigator.clipboard.writeText(text)
else fallback
Clipboard->>Clipboard: create textarea, execCommand('copy')
end
Clipboard-->>Client: void (throws on failure)
alt Copy succeeds
Client->>Client: set local copied state, show “Copied” indicator
else Copy fails
Client->>Store: setToastMessage('Failed to copy: ...')
end
Note over Router,Provider: Removed legacy endpoints (architecture, suggest-files, onboarding)
Note over API: Removed client API functions aiArchitecture, aiSuggestFiles, aiOnboarding
Note over Store: Removed stale state fields (onboardingStep, hoveredNodeId, executionFlow*)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
- Add test cases for pnpm workspaces with apps/* and packages/* patterns - Validate that nested packages like @repo/core and @repo/web are detected - Check that package manager and rootPath fields are correctly populated - Update AGENTS.md coverage stats to reflect new test files (33 total) - Simplify clipboard.ts by removing legacy execCommand fallback for older browsers - Fix dangling closing brace in search indexing-pipeline.test.ts - Move toast message logic inside active check in useArchitectureState.ts to prevent race conditions
Contributor
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
…ucture - Extend dependency-analyzer.test.ts workspace package detection tests - Add assertion for @repo/web package in pnpm-style apps/* directory structure - Verify manager and rootPath properties for both npm packages/* and pnpm apps/* workspace patterns - Improve test coverage for monorepo workspace root path resolution across different package managers
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.
Description
Unify AI provider flow behind centralized server-side routes and remove legacy per-endpoint wrappers. This refactor trims dead AI task paths, consolidates shared clipboard/toast handling, and cleans up unused store/API types tied to removed onboarding/architecture/suggest-files flows.
Also updates tests around provider, search, graph, parser, and service layers to cover the refactored behavior and deleted paths.
Types of Changes
What types of changes does your code introduce to gitSdm? (Check all that apply)
Checklist
Before submitting, please make sure your PR meets the following:
bun run lint) and fixed all errors/warnings.bun run typecheck) and resolved all compile errors.bun run test) and all 210+ tests pass.Screenshots / Flow Diagrams (if applicable)
N/A
Summary by cubic
Unifies the AI provider flow behind centralized routes and removes legacy architecture/suggest-files/onboarding endpoints. Adds a modern
copyToClipboard, tightens the top‑nav on tablet, expands tests (indexing pipeline, mermaid, workspace packages incl. pnpm apps/*), and fixes a diagram toast race.Refactors
server/ai; trimmed summarizer exports and simplifiedai-routes.vizStorefields; surfaced diagram/export errors viavizStoretoasts and gated toasts behind the active check.copyToClipboardacross share/code/commit copy actions and dropped the legacy fallback; compacted top‑nav on tablet (smaller gaps, adjusted repo-name widths, icon-only labels at lg thresholds).apps/*with rootPath/manager mapping), graph builder fallbacks, GitHub fetches, and npm registry edge cases; updatedAGENTS.md.Migration
aiArchitecture,aiSuggestFiles,aiOnboardingand their types./api/ai/architecture,/api/ai/suggest-files,/api/ai/onboarding. Use/api/ai/explain,/api/ai/mermaid,/api/ai/learning-path, etc.aiExplain/aiMermaid/aiLearningPathand the unified provider flow.Written for commit 770ec68. Summary will update on new commits.