Skip to content

refactor(ai): unify provider flow and update ai routes#67

Merged
mbayue merged 6 commits into
masterfrom
feature/ai-provider-refactor
Jul 2, 2026
Merged

refactor(ai): unify provider flow and update ai routes#67
mbayue merged 6 commits into
masterfrom
feature/ai-provider-refactor

Conversation

@mbayue

@mbayue mbayue commented Jul 2, 2026

Copy link
Copy Markdown
Owner

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)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (edits to README, templates, or instructions)
  • Refactoring (improving code quality without altering behavior)

Checklist

Before submitting, please make sure your PR meets the following:

  • My code follows the code style of this project.
  • I have ran linting locally (bun run lint) and fixed all errors/warnings.
  • I have ran typecheck locally (bun run typecheck) and resolved all compile errors.
  • I have run the tests locally (bun run test) and all 210+ tests pass.
  • I have updated the documentation / README if applicable.

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

    • Centralized provider selection/caching under server/ai; trimmed summarizer exports and simplified ai-routes.
    • Removed onboarding/architecture/suggest-files tasks, related client APIs/types, and unused vizStore fields; surfaced diagram/export errors via vizStore toasts and gated toasts behind the active check.
    • Adopted copyToClipboard across 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).
    • Expanded and stabilized tests: provider/embedding/QA engine, indexing pipeline search, mermaid generator, workspace package detection (now covers pnpm apps/* with rootPath/manager mapping), graph builder fallbacks, GitHub fetches, and npm registry edge cases; updated AGENTS.md.
  • Migration

    • Client APIs removed: aiArchitecture, aiSuggestFiles, aiOnboarding and their types.
    • Server routes removed: /api/ai/architecture, /api/ai/suggest-files, /api/ai/onboarding. Use /api/ai/explain, /api/ai/mermaid, /api/ai/learning-path, etc.
    • Update callers to aiExplain/aiMermaid/aiLearningPath and the unified provider flow.

Written for commit 770ec68. Summary will update on new commits.

Review in cubic

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Comment thread src/components/viz/architecture/mermaid-generator.test.ts Dismissed
…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

@cubic-dev-ai cubic-dev-ai Bot 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.

5 issues found across 42 files

Confidence score: 3/5

  • In src/components/viz/architecture/hooks/useArchitectureState.ts, stale async cycles can still call setToastMessage in .catch after a re-render, so users may see error toasts for work that was already superseded; guard the toast update with the same active check used for setRenderError before merging.
  • In src/lib/clipboard.ts, the fallback document.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.ts and server/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*)
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/lib/clipboard.ts Outdated
Comment thread src/components/viz/architecture/hooks/useArchitectureState.ts Outdated
Comment thread server/search/indexing-pipeline.test.ts Outdated
Comment thread server/parser/dependency-analyzer.test.ts Outdated
Comment thread AGENTS.md Outdated
mbayue and others added 2 commits July 2, 2026 14:22
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

@cubic-dev-ai cubic-dev-ai Bot 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.

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

Comment thread server/parser/dependency-analyzer.test.ts
…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
@mbayue mbayue merged commit 777150c into master Jul 2, 2026
8 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.

2 participants