Skip to content

fix(components): do not filter custom components in workspaces named ui/#3

Merged
neilwashere merged 1 commit into
mainfrom
fix/components-ui-workspace-false-positive
May 26, 2026
Merged

fix(components): do not filter custom components in workspaces named ui/#3
neilwashere merged 1 commit into
mainfrom
fix/components-ui-workspace-false-positive

Conversation

@neilwashere
Copy link
Copy Markdown

Summary

isUIPrimitive in src/detectors/components.ts had a filePath.includes(\"/ui/\") check intended to filter shadcn primitives. It is too broad: it matches every file under a monorepo workspace literally named `ui/` (e.g. `ui/src/components/*.tsx`), so every custom component in such a repo was wrongly dropped.

The real shadcn case (`components/ui/.tsx`) is still caught by the more specific `/components/ui/` check; lowercase primitive file names are still caught by the `UI_PRIMITIVES` set; vendor path checks (`@radix-ui`, `@shadcn`) are unchanged.

Why we want this in the fork right now

Surfaced while validating MGN-853 (cross-repo wiki ingestion into Talas brain). Running npx codesight --wiki against `morgan` (pnpm workspace `packages: shared, server, ui`) reported `0 components`. After the fix, 130 components are detected with prop signatures extracted via AST. The new `ui.md` article alone (~3.3K tokens) is the single biggest UI-context gain for triage and dev agents working on morgan.

Change

 function isUIPrimitive(filePath: string): boolean {
   const name = basename(filePath, extname(filePath)).toLowerCase();
   return (
     UI_PRIMITIVES.has(name) ||
-    filePath.includes(\"/ui/\") ||
     filePath.includes(\"/components/ui/\") ||
     filePath.includes(\"@radix-ui\") ||
     filePath.includes(\"@shadcn\")
   );
 }

Test plan

  • Added regression test in tests/detectors.test.ts. Fixture has both ui/src/components/AppShell.tsx (must be detected) and ui/src/components/ui/button.tsx (must still be filtered).
  • Existing detects React components with props test still passes.
  • Full suite: 116/117 pass; the one pre-existing failure in tests/monorepo.test.ts:312 also fails on main (verified via stash + re-run).
  • Manual: ran against morgan -- components 0 -> 130, wiki tokens 15,736 -> 19,077, ui.md article generated.

Upstream

Also filed at Houseofmvps#43 as a contribution. This PR lets us land internally without waiting on upstream review.

🤖 Generated with Claude Code

`isUIPrimitive` had a `filePath.includes("/ui/")` check intended to filter
shadcn primitives. That check is too broad: it matches every file under a
monorepo workspace literally named `ui/` (e.g. `ui/src/components/*.tsx`),
so every custom component in such a repo was wrongly dropped.

The real shadcn case (`components/ui/<primitive>.tsx`) is still caught by
the more specific `/components/ui/` check, and lowercase primitive file
names are still caught by the `UI_PRIMITIVES` set. Vendor path checks
(`@radix-ui`, `@shadcn`) are unchanged.

Repro: morgan monorepo (`packages: shared, server, ui`) reported 0
components. After the fix, 130 components are detected with prop
signatures extracted via AST. Includes a regression test fixture that
asserts a workspace-level `ui/src/components/AppShell.tsx` is detected
while a sibling `ui/src/components/ui/button.tsx` is still filtered.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 26, 2026 09:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an over-broad shadcn/ui primitive filter in the component detector that was incorrectly excluding all components in monorepos with a workspace literally named ui/, restoring correct React component detection in those repos.

Changes:

  • Removed the filePath.includes("/ui/") heuristic from isUIPrimitive() to avoid colliding with ui/ workspace paths.
  • Added a regression test fixture covering a ui/ workspace containing both a real app component and a shadcn-style primitive path.

Reviewed changes

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

File Description
src/detectors/components.ts Narrows the UI-primitive filter to avoid excluding components solely due to a /ui/ path segment.
tests/detectors.test.ts Adds regression coverage for monorepos with a ui/ workspace and expected component detection behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 64 to 75
function isUIPrimitive(filePath: string): boolean {
const name = basename(filePath, extname(filePath)).toLowerCase();
// Note: do NOT match a bare `/ui/` segment here. That collides with monorepo
// workspaces literally named `ui/` (e.g. `ui/src/components/*.tsx`), where
// every custom component would be wrongly filtered. The real shadcn case is
// `components/ui/` (caught below) or lowercase primitive filenames (caught
// via UI_PRIMITIVES). Vendor paths (`@radix-ui`, `@shadcn`) are kept.
return (
UI_PRIMITIVES.has(name) ||
filePath.includes("/ui/") ||
filePath.includes("/components/ui/") ||
filePath.includes("@radix-ui") ||
filePath.includes("@shadcn")
Comment thread tests/detectors.test.ts
Comment on lines +395 to +409
// shadcn primitive at the canonical path. Must still be filtered.
"ui/src/components/ui/button.tsx": `export const Button = ({ label }: { label: string }) => <button>{label}</button>;`,
});
const project = await mods.detectProject(dir);
assert.equal(project.componentFramework, "react", "react workspace dep should be aggregated");
const files = await mods.collectFiles(dir);
const components = await mods.detectComponents(files, project);
assert.ok(
components.some((c: any) => c.name === "AppShell"),
`expected AppShell to be detected, got: ${components.map((c: any) => c.name).join(", ") || "<none>"}`,
);
assert.ok(
!components.some((c: any) => c.name === "Button"),
"shadcn primitive at components/ui/button.tsx should still be filtered",
);
@neilwashere neilwashere merged commit 1bbd69e into main May 26, 2026
1 check passed
@neilwashere neilwashere deleted the fix/components-ui-workspace-false-positive branch May 26, 2026 09:27
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