Skip to content

chore: dead code clean up#419

Open
odilitime wants to merge 3 commits intodevfrom
odi-png
Open

chore: dead code clean up#419
odilitime wants to merge 3 commits intodevfrom
odi-png

Conversation

@odilitime
Copy link
Copy Markdown
Contributor

@odilitime odilitime commented Mar 30, 2026

Note

Medium Risk
Broad deletion of old Next.js pages, server actions, scripts, and a plugin could break builds or runtime flows if any of these were still referenced dynamically. Risk is moderated by the change being primarily removals plus an additive audit script.

Overview
Removes a large set of unused code paths across the app and packages, including legacy Next.js pages (page-old.tsx), server actions for apps/conversations, deprecated UI landing components, Storybook template files, and the packages/lib/eliza/plugin-assistant implementation.

Cleans up ancillary dead utilities/scripts (metrics backfill, auth debug, env utils, migration helpers) and deletes a small unused CSS rule.

Adds packages/scripts/dead-code-reachability.ts, a standalone static import-graph BFS tool that audits which TS/TSX files are unreachable from production/test entry points, and updates the README to reflect the plugin directory rename (plugin-cloud-bootstrap).

Written by Cursor Bugbot for commit 01327e8. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated plugin path references in configuration.
  • Removals

    • Removed legacy authentication and login UI components.
    • Removed old landing page sections and visual components.
    • Removed server-side conversation and app management actions.
    • Removed chat assistant plugin and related handlers.
    • Removed Storybook documentation and story examples.
  • Chores

    • Added code reachability analysis tooling.
    • Removed deprecated utility scripts and migrations.

Encode 512px AVIF (q55) and JPEG (q88) directly from the eight PNG sources.
Serve via <picture> with AVIF preferred and JPEG fallback for older clients.
Removes ~127MB of 4096px PNGs from the repo.
Drop landing-page.tsx (superseded by landing-page-new), its header hero and
installation sections, React Flow micropayment demo, and lazy wrapper dead code.
Remove OnChainTrust-only AVIF/JPEG assets and unused global button styles.
Remove unused server actions (apps, conversations), legacy login/error pages,
orphan organization encryption repository, legacy plugin-assistant tree
(superseded by plugin-cloud-bootstrap), one-off scripts and Storybook scaffold
under packages/ui/src/stories, and unused ai-elements connection/edge shims.

Add packages/scripts/dead-code-reachability.ts for static import-graph audits.
Update README tree to reference plugin-cloud-bootstrap.

Made-with: Cursor
Copilot AI review requested due to automatic review settings March 30, 2026 03:50
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eliza-cloud-v2 Ready Ready Preview, Comment Mar 30, 2026 3:53am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e976b30d-dd23-4c21-8e2e-66a73196ecee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch odi-png

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Cleans up unused/dead code and assets across the repo (Storybook example content, legacy landing/auth components, old scripts/plugins), and adds a lightweight internal script to audit static import reachability.

Changes:

  • Removed legacy Storybook example components/assets and related CSS.
  • Removed deprecated UI/landing/auth code paths, internal helper scripts, and an unused plugin-assistant implementation.
  • Added packages/scripts/dead-code-reachability.ts to statically audit reachability from entry points.

Reviewed changes

Copilot reviewed 47 out of 71 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
public/cloud-agent-samples/1.png Removed unused sample image asset
public/cloud-agent-samples/2.png Removed unused sample image asset
public/cloud-agent-samples/3.png Removed unused sample image asset
public/cloud-agent-samples/4.png Removed unused sample image asset
public/cloud-agent-samples/5.png Removed unused sample image asset
public/cloud-agent-samples/6.png Removed unused sample image asset
public/cloud-agent-samples/7.png Removed unused sample image asset
public/cloud-agent-samples/8.png Removed unused sample image asset
packages/ui/src/stories/page.css Removed unused Storybook example stylesheet
packages/ui/src/stories/header.css Removed unused Storybook example stylesheet
packages/ui/src/stories/button.css Removed unused Storybook example stylesheet
packages/ui/src/stories/assets/youtube.svg Removed unused Storybook example asset
packages/ui/src/stories/assets/tutorials.svg Removed unused Storybook example asset
packages/ui/src/stories/assets/github.svg Removed unused Storybook example asset
packages/ui/src/stories/assets/discord.svg Removed unused Storybook example asset
packages/ui/src/stories/assets/accessibility.svg Removed unused Storybook example asset
packages/ui/src/stories/assets/theming.png Removed unused Storybook example asset
packages/ui/src/stories/assets/testing.png Removed unused Storybook example asset
packages/ui/src/stories/assets/styling.png Removed unused Storybook example asset
packages/ui/src/stories/assets/share.png Removed unused Storybook example asset
packages/ui/src/stories/assets/figma-plugin.png Removed unused Storybook example asset
packages/ui/src/stories/assets/docs.png Removed unused Storybook example asset
packages/ui/src/stories/assets/context.png Removed unused Storybook example asset
packages/ui/src/stories/assets/avif-test-image.avif Removed unused Storybook example asset
packages/ui/src/stories/assets/assets.png Removed unused Storybook example asset
packages/ui/src/stories/assets/addon-library.png Removed unused Storybook example asset
packages/ui/src/stories/assets/accessibility.png Removed unused Storybook example asset
packages/ui/src/stories/Page.tsx Removed unused Storybook example component
packages/ui/src/stories/Page.stories.ts Removed unused Storybook example story
packages/ui/src/stories/Header.tsx Removed unused Storybook example component
packages/ui/src/stories/Header.stories.ts Removed unused Storybook example story
packages/ui/src/stories/Configure.mdx Removed unused Storybook example docs page
packages/ui/src/stories/Button.tsx Removed unused Storybook example component
packages/ui/src/stories/Button.stories.ts Removed unused Storybook example story
packages/ui/src/components/layout/landing-header-old.tsx Removed deprecated landing header implementation
packages/ui/src/components/landing/landing-page.tsx Removed deprecated landing page implementation
packages/ui/src/components/landing/TopHero.tsx Removed deprecated landing hero section
packages/ui/src/components/landing/OnChainTrust.tsx Removed deprecated landing trust section
packages/ui/src/components/landing/MicropaymentNetworkLazy.tsx Removed deprecated landing visualization wrapper
packages/ui/src/components/landing/MicropaymentNetwork.tsx Removed deprecated landing visualization
packages/ui/src/components/landing/Installation.tsx Removed deprecated landing installation section
packages/ui/src/components/landing/BayerDitheringBackgroundLazy.tsx Removed deprecated lazy loader wrapper
packages/ui/src/components/ai-elements/edge.tsx Removed unused React Flow edge component
packages/ui/src/components/ai-elements/connection.tsx Removed unused React Flow connection component
packages/scripts/test-image-simple.ts Removed unused dev/test script
packages/scripts/restore-ai-element-imports.ts Removed one-off repair script
packages/scripts/remove-hubspot-connections.ts Removed one-off maintenance script
packages/scripts/migrate-encrypt-user-database-uris.ts Removed one-off migration script
packages/scripts/lib/env-utils.ts Removed unused env utility module
packages/scripts/fix-ai-elements-v4.ts Removed one-off code mod script
packages/scripts/fix-ai-elements-v3.ts Removed one-off code mod script
packages/scripts/fix-ai-element-imports.ts Removed one-off code mod script
packages/scripts/fix-ai-element-imports-2.ts Removed one-off code mod script
packages/scripts/debug-auth.ts Removed unused debug script
packages/scripts/backfill-metrics.ts Removed one-off backfill script
packages/scripts/backfill-agent-usernames.ts Removed one-off backfill script
packages/scripts/dead-code-reachability.ts Added static reachability audit script for dead-code detection
packages/lib/eliza/plugin-assistant/providers/providers.ts Removed unused assistant plugin provider implementation
packages/lib/eliza/plugin-assistant/providers/current-run-context.ts Removed unused assistant plugin provider implementation
packages/lib/eliza/plugin-assistant/providers/actions.ts Removed unused assistant plugin provider implementation
packages/lib/eliza/plugin-assistant/prompts/chat-assistant-prompts.ts Removed unused assistant plugin prompt templates
packages/lib/eliza/plugin-assistant/index.ts Removed unused assistant plugin entry
packages/lib/eliza/plugin-assistant/handler.ts Removed unused assistant plugin message handler
packages/lib/eliza/plugin-assistant/actions/image-generation.ts Removed unused assistant plugin image action
packages/db/repositories/organization-encryption-keys.ts Removed unused repository wrapper (no remaining references found)
app/login/page-old.tsx Removed unused legacy login page variant
app/auth/error/page-old.tsx Removed unused legacy auth error page variant
app/actions/conversations.ts Removed unused server actions module
app/actions/apps.ts Removed unused server actions module
app/globals.css Removed unused landing-page hover style
README.md Updated docs path reference to plugin-cloud-bootstrap/

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

Comment on lines +188 to +190
`${basePath}.mts`,
join(basePath, "index.ts"),
join(basePath, "index.tsx"),
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

tryResolveFile() doesn’t include .cts (and similarly misses index.mts/cts), but the script’s source/entry regexes treat .cts as an in-scope extension. That mismatch can cause the reachability graph to miss edges for .cts modules and over-report “dead” files. Suggest adding .cts/index.mts/index.cts to the resolution candidates, or removing .cts from the in-scope extensions to keep behavior consistent.

Suggested change
`${basePath}.mts`,
join(basePath, "index.ts"),
join(basePath, "index.tsx"),
`${basePath}.mts`,
`${basePath}.cts`,
join(basePath, "index.ts"),
join(basePath, "index.tsx"),
join(basePath, "index.mts"),
join(basePath, "index.cts"),

Copilot uses AI. Check for mistakes.
@claude
Copy link
Copy Markdown

claude bot commented Mar 30, 2026

Code Review: Dead Code Cleanup (PR 419)

Overall: Solid cleanup PR. Removing 5,350 lines while adding a useful 340-line audit tool is a net positive. The new dead-code-reachability.ts script is the right direction for ongoing dead code detection. A few things worth verifying before merging.

Potential Issues

Medium - Public static assets not covered by the reachability audit

The 8 deleted public/cloud-agent-samples PNG files are referenced in JSX/HTML via string paths, not import statements. The static import graph cannot trace those. Confirm no component still references them before merging: grep -r "cloud-agent-samples" app/ packages/ui/src/ -- if any do, users will see broken images with no build error.

Medium - organization-encryption-keys.ts repository deletion

The repository wrapper is removed but the Drizzle schema table (organizationEncryptionKeys) likely still exists. Two things to verify: (1) nothing in agent-server, gateway-discord, or operator imports this repository since those services may not be fully covered by the reachability script entry points; (2) if the schema table is now orphaned, follow up with a migration to drop it. Check: grep -r "organizationEncryptionKeys" packages/ services/

Low - migrate-encrypt-user-database-uris.ts deletion

Fine to delete once the migration has run in production for all environments. Worth a note in the PR description for the ops trail.

New Script: dead-code-reachability.ts

Well-structured and the documented limitations (dynamic imports, require variable) are appropriately honest. Minor notes: (1) The header says BFS but bfs() uses queue.pop() which is stack-based DFS - functionally equivalent for reachability but the naming is misleading. (2) The hardcoded alias table in mapSpecifierToPath must stay in sync with tsconfig.json paths as the project evolves. (3) tryResolveFile skips .js/.jsx extension candidates - fine for an all-TypeScript codebase today.

Deletions that look clean

  • page-old.tsx files (auth/error, login): clearly superseded
  • plugin-assistant/: README confirms replacement with plugin-cloud-bootstrap; consistent
  • app/actions/apps.ts and app/actions/conversations.ts: no inbound callers per the audit
  • All Storybook scaffold files: default templates with no real coverage
  • debug-auth.ts: removing debug scripts is a security positive
  • landing-header-old.tsx, OnChainTrust, etc.: consistent with the earlier landing page cleanup

Bottom line: Verify the two medium items (static image references + encryption key repo) and this is merge-ready. The reachability tool is a valuable addition to the toolchain.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
README.md (1)

218-218: Fix incorrect plugin identifier mapping in docs.

Line 218 claims plugin-cloud-bootstrap/ maps to @eliza-cloud/plugin-assistant, but the implementation exports cloudBootstrapPlugin (name: "cloud-bootstrap") in packages/lib/eliza/plugin-cloud-bootstrap/index.ts (Lines 170-193). This is a stale/incorrect identifier reference and can misdirect integrations.

Proposed doc fix
-│   │   └── plugin-cloud-bootstrap/  # Cloud bootstrap plugin (`@eliza-cloud/plugin-assistant` id)
+│   │   └── plugin-cloud-bootstrap/  # Cloud bootstrap plugin (name: "cloud-bootstrap")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 218, Update the README entry that maps plugin directories
to package identifiers: replace the incorrect mapping of plugin-cloud-bootstrap/
-> `@eliza-cloud/plugin-assistant` with the actual exported identifier used in
code; reference the exported symbol cloudBootstrapPlugin (name:
"cloud-bootstrap") from packages/lib/eliza/plugin-cloud-bootstrap/index.ts and
update the docs to point to the cloud-bootstrap identifier (or the correct
package name matching cloudBootstrapPlugin) so integrations are directed to the
correct plugin.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/scripts/dead-code-reachability.ts`:
- Around line 150-158: The current resolver accepts any specifier starting with
"@elizaos/" but only maps "@elizaos/cloud-ui", causing other workspace packages
to be dropped; update the import resolution in the block handling trimmed to
either (a) explicitly map each supported workspace package (e.g., add cases for
"@elizaos/<pkg>" and "@elizaos/<pkg>/" to return join(ROOT, "packages/<pkg>/src"
or "packages/<pkg>/src/index.ts")) or (b) tighten the guard so only
"@elizaos/cloud-ui" is accepted (change the initial if that checks
trimmed.startsWith("@elizaos/") to only allow "@elizaos/cloud-ui"), using the
same join(ROOT, ...) pattern shown for cloud-ui to ensure all valid "@elizaos/*"
imports resolve into the graph.
- Around line 236-240: The code currently swallows readFileSync errors by using
a try/catch that does "continue", producing incomplete graphs; replace the
silent continue with a fail-fast throw that includes the failing file path and
the original error (e.g., catch (err) { throw new Error(`Failed to read ${file}:
${err}`); }) so that the readFileSync/file failure surfaces immediately and
aborts processing instead of continuing with a partial result.

---

Nitpick comments:
In `@README.md`:
- Line 218: Update the README entry that maps plugin directories to package
identifiers: replace the incorrect mapping of plugin-cloud-bootstrap/ ->
`@eliza-cloud/plugin-assistant` with the actual exported identifier used in code;
reference the exported symbol cloudBootstrapPlugin (name: "cloud-bootstrap")
from packages/lib/eliza/plugin-cloud-bootstrap/index.ts and update the docs to
point to the cloud-bootstrap identifier (or the correct package name matching
cloudBootstrapPlugin) so integrations are directed to the correct plugin.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 609446e5-cfa0-415a-bff7-79d61e24921b

📥 Commits

Reviewing files that changed from the base of the PR and between e7c31f1 and 01327e8.

⛔ Files ignored due to path filters (23)
  • packages/ui/src/stories/assets/accessibility.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/accessibility.svg is excluded by !**/*.svg
  • packages/ui/src/stories/assets/addon-library.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/assets.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/context.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/discord.svg is excluded by !**/*.svg
  • packages/ui/src/stories/assets/docs.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/figma-plugin.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/github.svg is excluded by !**/*.svg
  • packages/ui/src/stories/assets/share.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/styling.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/testing.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/theming.png is excluded by !**/*.png
  • packages/ui/src/stories/assets/tutorials.svg is excluded by !**/*.svg
  • packages/ui/src/stories/assets/youtube.svg is excluded by !**/*.svg
  • public/cloud-agent-samples/1.png is excluded by !**/*.png
  • public/cloud-agent-samples/2.png is excluded by !**/*.png
  • public/cloud-agent-samples/3.png is excluded by !**/*.png
  • public/cloud-agent-samples/4.png is excluded by !**/*.png
  • public/cloud-agent-samples/5.png is excluded by !**/*.png
  • public/cloud-agent-samples/6.png is excluded by !**/*.png
  • public/cloud-agent-samples/7.png is excluded by !**/*.png
  • public/cloud-agent-samples/8.png is excluded by !**/*.png
📒 Files selected for processing (48)
  • README.md
  • app/actions/apps.ts
  • app/actions/conversations.ts
  • app/auth/error/page-old.tsx
  • app/globals.css
  • app/login/page-old.tsx
  • packages/db/repositories/organization-encryption-keys.ts
  • packages/lib/eliza/plugin-assistant/actions/image-generation.ts
  • packages/lib/eliza/plugin-assistant/handler.ts
  • packages/lib/eliza/plugin-assistant/index.ts
  • packages/lib/eliza/plugin-assistant/prompts/chat-assistant-prompts.ts
  • packages/lib/eliza/plugin-assistant/providers/actions.ts
  • packages/lib/eliza/plugin-assistant/providers/current-run-context.ts
  • packages/lib/eliza/plugin-assistant/providers/providers.ts
  • packages/scripts/backfill-agent-usernames.ts
  • packages/scripts/backfill-metrics.ts
  • packages/scripts/dead-code-reachability.ts
  • packages/scripts/debug-auth.ts
  • packages/scripts/fix-ai-element-imports-2.ts
  • packages/scripts/fix-ai-element-imports.ts
  • packages/scripts/fix-ai-elements-v3.ts
  • packages/scripts/fix-ai-elements-v4.ts
  • packages/scripts/lib/env-utils.ts
  • packages/scripts/migrate-encrypt-user-database-uris.ts
  • packages/scripts/remove-hubspot-connections.ts
  • packages/scripts/restore-ai-element-imports.ts
  • packages/scripts/test-image-simple.ts
  • packages/ui/src/components/ai-elements/connection.tsx
  • packages/ui/src/components/ai-elements/edge.tsx
  • packages/ui/src/components/landing/BayerDitheringBackgroundLazy.tsx
  • packages/ui/src/components/landing/Installation.tsx
  • packages/ui/src/components/landing/MicropaymentNetwork.tsx
  • packages/ui/src/components/landing/MicropaymentNetworkLazy.tsx
  • packages/ui/src/components/landing/OnChainTrust.tsx
  • packages/ui/src/components/landing/TopHero.tsx
  • packages/ui/src/components/landing/landing-page.tsx
  • packages/ui/src/components/layout/landing-header-old.tsx
  • packages/ui/src/stories/Button.stories.ts
  • packages/ui/src/stories/Button.tsx
  • packages/ui/src/stories/Configure.mdx
  • packages/ui/src/stories/Header.stories.ts
  • packages/ui/src/stories/Header.tsx
  • packages/ui/src/stories/Page.stories.ts
  • packages/ui/src/stories/Page.tsx
  • packages/ui/src/stories/assets/avif-test-image.avif
  • packages/ui/src/stories/button.css
  • packages/ui/src/stories/header.css
  • packages/ui/src/stories/page.css
💤 Files with no reviewable changes (45)
  • app/globals.css
  • packages/ui/src/components/landing/MicropaymentNetworkLazy.tsx
  • packages/ui/src/stories/header.css
  • packages/lib/eliza/plugin-assistant/providers/providers.ts
  • packages/ui/src/stories/button.css
  • packages/scripts/remove-hubspot-connections.ts
  • packages/scripts/restore-ai-element-imports.ts
  • packages/ui/src/components/landing/Installation.tsx
  • packages/lib/eliza/plugin-assistant/providers/actions.ts
  • packages/ui/src/components/ai-elements/connection.tsx
  • packages/ui/src/stories/page.css
  • packages/scripts/fix-ai-element-imports.ts
  • packages/scripts/backfill-metrics.ts
  • packages/scripts/fix-ai-elements-v4.ts
  • packages/ui/src/components/landing/BayerDitheringBackgroundLazy.tsx
  • packages/ui/src/stories/Button.stories.ts
  • packages/lib/eliza/plugin-assistant/index.ts
  • packages/ui/src/stories/Page.tsx
  • packages/scripts/test-image-simple.ts
  • packages/scripts/fix-ai-element-imports-2.ts
  • packages/ui/src/stories/Button.tsx
  • packages/scripts/backfill-agent-usernames.ts
  • packages/ui/src/components/landing/OnChainTrust.tsx
  • packages/ui/src/components/layout/landing-header-old.tsx
  • packages/scripts/fix-ai-elements-v3.ts
  • packages/lib/eliza/plugin-assistant/providers/current-run-context.ts
  • packages/ui/src/components/landing/landing-page.tsx
  • packages/scripts/debug-auth.ts
  • app/login/page-old.tsx
  • packages/ui/src/stories/Header.stories.ts
  • packages/ui/src/stories/Configure.mdx
  • packages/ui/src/components/landing/TopHero.tsx
  • packages/ui/src/components/landing/MicropaymentNetwork.tsx
  • app/actions/apps.ts
  • packages/lib/eliza/plugin-assistant/prompts/chat-assistant-prompts.ts
  • packages/ui/src/stories/Page.stories.ts
  • app/actions/conversations.ts
  • packages/ui/src/stories/Header.tsx
  • packages/lib/eliza/plugin-assistant/handler.ts
  • packages/db/repositories/organization-encryption-keys.ts
  • packages/scripts/lib/env-utils.ts
  • packages/scripts/migrate-encrypt-user-database-uris.ts
  • app/auth/error/page-old.tsx
  • packages/lib/eliza/plugin-assistant/actions/image-generation.ts
  • packages/ui/src/components/ai-elements/edge.tsx

Comment on lines +55 to +56
const rel = relative(ROOT, abs);
if (st.isDirectory()) walkDirs(abs, pred, acc);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
python - <<'PY'
import ntpath

root = r"C:\repo"
app_file = r"C:\repo\app\demo\page.tsx"
test_file = r"C:\repo\packages\lib\__tests__\sample.ts"

rel_app = ntpath.relpath(app_file, root)
rel_test = ntpath.relpath(test_file, root)
base = app_file[:-4]  # strip ".tsx"

print("rel_app =", rel_app)
print('rel_app.startswith("app/") ->', rel_app.startswith("app/"))
print("rel_test =", rel_test)
print('"__tests__/" in rel_test ->', "__tests__/" in rel_test)
print('base.split("/")[-1] ->', base.split("/")[-1])
print("ntpath.basename(base) ->", ntpath.basename(base))
PY

Repository: elizaOS/cloud

Length of output: 273


🏁 Script executed:

head -100 packages/scripts/dead-code-reachability.ts | tail -50

Repository: elizaOS/cloud

Length of output: 1747


🏁 Script executed:

cat -n packages/scripts/dead-code-reachability.ts | sed -n '90,110p'

Repository: elizaOS/cloud

Length of output: 860


🏁 Script executed:

cat -n packages/scripts/dead-code-reachability.ts | sed -n '260,290p'

Repository: elizaOS/cloud

Length of output: 1180


🏁 Script executed:

cat -n packages/scripts/dead-code-reachability.ts | sed -n '300,315p'

Repository: elizaOS/cloud

Length of output: 863


🏁 Script executed:

cat -n packages/scripts/dead-code-reachability.ts | sed -n '1,50p'

Repository: elizaOS/cloud

Length of output: 1492


🏁 Script executed:

cat -n packages/scripts/dead-code-reachability.ts | sed -n '230,245p'

Repository: elizaOS/cloud

Length of output: 575


Normalize repo-relative paths to POSIX format before slash-based matching.

relative() returns backslashes on Windows, breaking the checks at lines 96, 277, 282, 287, 309 (startsWith("app/"), includes("__tests__/"), includes("/tests__/")) and the basename extraction at line 98 (split("/").pop()). This causes false negatives/positives in test/route detection and the audit report. Use relative() output with .replaceAll("\\", "/") once, then match against normalized strings.

Also applies to lines 62-69, 95-99, 262-263, 272-287, 307-309.

Additionally, replace the try/catch at lines 237-240 with fail-fast: these are internal file paths, not user-supplied data. Use expect/throw pattern instead of silently continuing on read failures.

Comment on lines +150 to +158
if (!trimmed.startsWith(".") && !trimmed.startsWith("@/") && !trimmed.startsWith("@elizaos/")) {
return null;
}
if (trimmed === "@elizaos/cloud-ui") {
return join(ROOT, "packages/ui/src/index.ts");
}
if (trimmed.startsWith("@elizaos/cloud-ui/")) {
return join(ROOT, "packages/ui/src", trimmed.slice("@elizaos/cloud-ui/".length));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

@elizaos/* imports are only partially resolved.

Line 150 admits every @elizaos/ specifier, but the resolver only handles @elizaos/cloud-ui. Any other workspace package import gets dropped from the graph, so files reachable only through those imports can be reported as dead. Either add the missing package mappings or narrow the accepted alias set.

Minimal guard if @elizaos/cloud-ui is the only supported workspace alias
-  if (!trimmed.startsWith(".") && !trimmed.startsWith("@/") && !trimmed.startsWith("@elizaos/")) {
+  const isSupportedWorkspaceAlias =
+    trimmed === "@elizaos/cloud-ui" || trimmed.startsWith("@elizaos/cloud-ui/");
+  if (!trimmed.startsWith(".") && !trimmed.startsWith("@/") && !isSupportedWorkspaceAlias) {
     return null;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!trimmed.startsWith(".") && !trimmed.startsWith("@/") && !trimmed.startsWith("@elizaos/")) {
return null;
}
if (trimmed === "@elizaos/cloud-ui") {
return join(ROOT, "packages/ui/src/index.ts");
}
if (trimmed.startsWith("@elizaos/cloud-ui/")) {
return join(ROOT, "packages/ui/src", trimmed.slice("@elizaos/cloud-ui/".length));
}
const isSupportedWorkspaceAlias =
trimmed === "@elizaos/cloud-ui" || trimmed.startsWith("@elizaos/cloud-ui/");
if (!trimmed.startsWith(".") && !trimmed.startsWith("@/") && !isSupportedWorkspaceAlias) {
return null;
}
if (trimmed === "@elizaos/cloud-ui") {
return join(ROOT, "packages/ui/src/index.ts");
}
if (trimmed.startsWith("@elizaos/cloud-ui/")) {
return join(ROOT, "packages/ui/src", trimmed.slice("@elizaos/cloud-ui/".length));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/scripts/dead-code-reachability.ts` around lines 150 - 158, The
current resolver accepts any specifier starting with "@elizaos/" but only maps
"@elizaos/cloud-ui", causing other workspace packages to be dropped; update the
import resolution in the block handling trimmed to either (a) explicitly map
each supported workspace package (e.g., add cases for "@elizaos/<pkg>" and
"@elizaos/<pkg>/" to return join(ROOT, "packages/<pkg>/src" or
"packages/<pkg>/src/index.ts")) or (b) tighten the guard so only
"@elizaos/cloud-ui" is accepted (change the initial if that checks
trimmed.startsWith("@elizaos/") to only allow "@elizaos/cloud-ui"), using the
same join(ROOT, ...) pattern shown for cloud-ui to ensure all valid "@elizaos/*"
imports resolve into the graph.

Comment on lines +236 to +240
let source: string;
try {
source = readFileSync(file, "utf8");
} catch {
continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fail fast when a module can't be read.

Skipping unreadable files silently gives you a partial graph and false dead-code results. This utility should surface the failing path and abort instead of continue.

Minimal fix
-    let source: string;
-    try {
-      source = readFileSync(file, "utf8");
-    } catch {
-      continue;
-    }
+    const source = readFileSync(file, "utf8");

Based on learnings: Applies to **/*.{ts,tsx}: "Use expect/throw pattern for error handling; always aim to catch errors and throw instead of hiding errors and falling back" and "Do not use try/catch blocks unless absolutely necessary or handling user-supplied data; avoid defensive programming and implement clean code with fail-fast patterns".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/scripts/dead-code-reachability.ts` around lines 236 - 240, The code
currently swallows readFileSync errors by using a try/catch that does
"continue", producing incomplete graphs; replace the silent continue with a
fail-fast throw that includes the failing file path and the original error
(e.g., catch (err) { throw new Error(`Failed to read ${file}: ${err}`); }) so
that the readFileSync/file failure surfaces immediately and aborts processing
instead of continuing with a partial result.

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