Automattic / Automattic/data-liberation-agent
Platform detection is implemented twice, and one of the two is dead code
- Dominant language
- TypeScript
- Stars
- 31
- Forks
- 3
- Avg merge
- 10h 14m
- Merged PRs (30d)
- 81
Description
Platform detection is implemented twice. One of the two implementations is unreachable, and the two disagree by construction because nothing keeps them in sync.
## The live implementation
`src/lib/detect-platform/detect-platform.ts` runs four tiers — URL patterns, response headers, source markers, path probes — and returns `{ platform, confidence, signals }`. `captureWebsite` calls it in `src/lib/capture.ts` and routes the result through `findAdapter`.
## The dead implementation
`PlatformAdapter.detect(url): boolean` is declared in `src/types.ts` and implemented by all nine adapters. It has **zero call sites**. The only occurrence of `.detect(` anywhere in `src/` is a comment in `src/adapters/default/index.ts` explaining that nothing calls it:
```
// the pipeline selects adapters by their .detect() method anyway.
```
Adapter selection is by id, in `src/adapters/resolve-adapter.ts`.
Six of the nine implementations already unconditionally `return false`, each with its own comment saying detection really happens in `detect-platform.ts` — `default`, `godaddy-wm`, `hostinger`, and `hubspot` all say so explicitly. The method has been understood as dead for a while; it just was not removed.
The remaining five carry regexes that are literal duplicates of the live `URL_PATTERNS` table:
| Adapter | Regex, duplicated in both `adapters//index.ts` and `detect-platform.ts` |
|---|---|
| wix | `/wixsite\.com\|wix\.com/i` |
| shopify | `/myshopify\.com\|shopify\.com/i` |
| squarespace | `/squarespace\.com/i` |
| webflow | `/webflow\.io\|webflow\.com/i` |
| weebly | `/weebly\.com/i` |
Adding or correcting a platform pattern means editing two files, and editing only one produces no error.
`PlatformAdapter.probe?` is in the same state: declared in `src/types.ts`, zero implementations, zero call sites.
Counting only what is live on `main`, `PlatformAdapter` has seven members, of which two are dead and one (`discover`) is `Promise` — tracked separately in #131.
## Proposed change, in two steps
**Step 1 — `detect`. Done in #135.** Delete it from `PlatformAdapter` and all nine adapters, leaving `detect-platform.ts` as the single source of platform identification, and migrate the URL-pattern coverage onto the live detector.
**Step 2 — `probe`. Sequenced after #119.** The two call sites live in `src/ui/inspect.tsx` and `src/mcp-server/handlers/inspect.ts`, and `inspect` is one of the ten CLI verbs #119 removes. Deleting them now means modify/delete conflicts against a −124k-line PR, to remove code already scheduled for removal. Once #119 lands, `inspect` is gone, both unreachable call sites go with it, and dropping the declaration is a one-line change against zero callers.
## Acceptance
- Exactly one place in the tree knows what a Wix URL looks like. *(step 1)*
- `PlatformAdapter` declares only members with call sites. *(step 2)*
- No behaviour change to detection results — both steps remove surfaces nothing reaches, so detection output must stay identical.
## Follow-up, deliberately not in scope
`tsconfig.json` sets `strict: true` but not `noUnusedLocals` / `noUnusedParameters`, which is the condition that lets dead declarations survive a clean `tsc --noEmit`. Turning both on today reports 51 errors on `main`, the majority in the WordPress-reconstruction tree that #119 deletes. Fixing them now would be work thrown away and merge conflict against a −124k-line open PR, so the flag change should land after #119 and is tracked separately.
---
*AI assistance: researched and written by Claude via Claude Code. The dead-code claims come from reading the tree and grepping for call sites; the 51-error figure is from running `tsc --noEmit --noUnusedLocals --noUnusedParameters` against `main`. Chris Huber orchestrated and reviewed the work and is responsible for what is filed here.*
*Correction: an earlier revision of this issue claimed orphaned imports in `src/types.ts` and `src/adapters/shared.ts`. That is wrong for `main` — those symbols are live there. They are orphaned only on the `refactor/remove-wordpress-reconstruction` branch, where the code they served was deleted and the imports were left behind. That belongs to #119 and has been removed from this issue.*
Contributor guide
Research direction
Start with src/types.ts, src/lib/detect-platform/detect-platform.ts, src/lib/capture.ts, src/adapters/resolve-adapter.ts, and the nine adapter index.ts files; compare the live detector with the adapter declarations and implementations. The probe call sites are src/ui/inspect.tsx and src/mcp-server/handlers/inspect.ts, but this step waits for #119. Done means only live members remain and detection output is unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100