Skip to content

Remove dead code and dedupe shared logic across the monorepo - #3583

Merged
SawyerHood merged 1 commit into
mainfrom
bb/can-you-scan-this-code-for-any-unused-code-and-l-thr_ekk8rv4cd5
Sep 12, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/can-you-scan-this-code-for-any-unused-code-and-l-thr_ekk8rv4cd5

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The monorepo had accumulated dead and duplicated code: files and exports nothing imports, props and options no caller passes, branches no input can reach, production helpers that only their own tests call, dependencies nothing resolves, and several helpers implemented two to four times across packages. A knip scan flagged 412 unused exports, 597 unused types and 96 unused dependencies. jscpd found 279 copy-paste clones (4,777 duplicated lines).

What changed

One commit deletes the dead code and consolidates the duplicates. Net change: +17.3K / −39.4K lines across 1,317 files (63 files deleted).

Every change went through the same pipeline:

  • Find: knip and jscpd over the whole repo, plus 27 read-only auditors, one per slice and five cross-cutting (clones, generic helpers, dead interfaces, dependencies, legacy shims). They produced 488 findings.
  • Verify: an independent reviewer tried to refute each finding. 439 survived and 48 were rejected.
  • Apply: implementers applied the surviving findings slice by slice, then cross-slice, then dependency removals. Each unit typechecked its packages and ran related tests.
  • Review: a second slice-by-slice review of the full diff confirmed 23 issues (0 high, 2 medium, 21 low). Most were deleted tests that still covered live behavior. All 23 are fixed and coverage is restored.

Largest areas (net lines):

  • apps/mobile (about −6.1K): leftovers from before the WebView shell: query-key catalogue, realtime invalidation, diff-patch cache, mutation-error toasts, and 15 unused UI primitives. The icon maps are pruned to the 22 icons in use, and stale READMEs are rewritten.
  • apps/app (about −4.7K): never-passed props, always-true flags, pass-through wrappers, and repeated components (branch picker, settings rows, sidebar chrome, loading rows).
  • apps/server (about −2.4K): a test-only timeline build path and execution-option helper, dead ownership modes, and plugin registration and configure validators that were copied into the SDK fake plugin host. The validators now have one home in @get-bb/plugin-sdk internals.
  • plugins/provider-claude-code (about −1.2K): the unreachable readonly permission mode and leftovers from the idle-release feature.
  • Host packages and apps/desktop: duplicated lock implementations merged into bb-environment-provider-host; path-containment, debounce and child-process-exit helpers moved into existing shared packages.
  • apps/web: about 470 lines of app-shell CSS the site never used.
  • Dependencies: 22 UI-kit dependencies left in apps/app after the kit moved to @bb/shared-ui, plus unused dependencies in 12 other manifests. pnpm-lock.yaml is refreshed.

Contracts:

  • No server/daemon wire changes, so HOST_DAEMON_PROTOCOL_VERSION is unchanged.
  • No DB schema changes.
  • No public plugin SDK exports removed, and the deprecated SDK aliases still in their documented removal window are kept.
  • @get-bb/plugin-sdk is bumped to 0.4.87 because published SDK content changed.

Deliberately not included; each needs an owner decision:

  • The host.file_metadata daemon RPC has no sender. Removing it requires a protocol version bump.
  • The terminal WebSocket close client message has no sender. Same protocol question.
  • The connect-db audit_log table is never read or written. Dropping it needs a migration.

How you verified

  • pnpm exec turbo run typecheck: all 95 packages pass on the rebased branch.
  • pnpm exec turbo run lint: passes.
  • pnpm install --frozen-lockfile: succeeds.
  • oxfmt --check passes on every changed file that was formatted at baseline.
  • Full pnpm exec turbo run test: 34 failing tests under full-suite load; unmodified main had 137 under similar load. 25 of the 34 were already failing on unmodified main. The other 9 all pass when re-run alone: @bb/server install-machine-script, timeline-in-turn-window, git-plugin-dependencies and plugin-install (4 files, 124 tests), and @bb/templates plugin-scaffold-external (2 tests).
  • The review-fix tests fail when the protected logic is temporarily broken.
  • A second knip pass on the modified tree surfaced only 2 more orphaned re-exports, and they are removed.
  • After the change, jscpd reports 111 clones (down from 279) and 1,829 duplicated lines (down from 4,777). knip reports 238 unused exports (down from 412) and 60 unused dependencies (down from 96).

AGENT GENERATED

Delete unused files, declarations, props, branches, dependencies, and
production code kept alive only by its own tests, and consolidate
duplicated helpers into existing shared packages. Candidates came from
knip and jscpd plus per-slice audits, and every change survived an
adversarial review before it was applied.

- apps/mobile: native-era query, cache, toast, and UI leftovers from before
  the WebView shell; icon maps pruned to the icons in use; stale READMEs
- apps/app, apps/server, apps/desktop, apps/web, host packages, plugins:
  never-passed props, unreachable branches, test-only helpers, duplicated
  lock, path, scheduler, manifest, and validator implementations
- provider-claude-code: unreachable readonly permission mode
- Unused dependencies from 13 manifests, with pnpm-lock.yaml refreshed
- @get-bb/plugin-sdk bumped to 0.4.87 for the changed published content

Wire protocols, persisted data, public plugin SDK exports, and deprecated
SDK aliases still in their removal window are unchanged. Lost coverage
for still-live behavior was restored.

Net: +17.3K / -39.4K lines. jscpd clones 279 -> 111; knip unused exports
412 -> 238 and unused dependencies 96 -> 60.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood merged commit 3b37d27 into main Sep 12, 2026
16 checks passed
@SawyerHood
SawyerHood deleted the bb/can-you-scan-this-code-for-any-unused-code-and-l-thr_ekk8rv4cd5 branch September 12, 2026 08:37
ratulsarna added a commit to ratulsarna/bb that referenced this pull request Sep 13, 2026
Upstream's dead-code sweep (get-bb#3583) hoisted the file-local sessionOptions
into FULL_ACCESS_SESSION_OPTIONS in fake-codex-app-server-harness.ts and
updated its own call sites. The fork's added tests kept the old name, so
the merge typechecked as five undefined references.

Same values, so this is a rename only.
ymichael added a commit that referenced this pull request Nov 3, 2026
## Human comments

## What was wrong

The phone app icon never showed a count. The mobile shell advertises the
`badge` capability and, when the app goes to the background, writes the
last count it received. But nothing in the web app has sent that message
since `shellSetBadge` was removed in #3583, so the shell wrote its
default of 0 and cleared any badge.

## What changed

- `apps/app/src/lib/native-shell/native-shell.ts`: adds
`shellSetBadge(count)`, which posts the existing `{ type: "badge", count
}` bridge message when the shell supports it.
- `apps/app/src/components/layout/AppLayout.tsx`: posts the
pending-thread count from `desktopAttentionThreads` whenever it changes.
This is the number the desktop Dock badge shows.

There are no mobile, push-payload, plugin SDK or daemon protocol
changes. The badge updates only while the WebView runs. Pushes do not
carry a badge count, so a question that arrives while the app is
suspended doesn't change the badge until the app is opened. A thread
that is only unread gets a dot on the Dock but no number on the phone.

## How you verified

- New `AppLayout.test.tsx` case: it checks that the page posts 2 for two
pending threads and one unread thread, then 0 once none are pending. It
fails without the AppLayout change.
- `pnpm exec turbo run typecheck lint --filter=@bb/app` passes, as do
the AppLayout and native-shell tests.
- iOS 26.5 simulator against `pnpm start:worktree`, with two threads
waiting on a question:
- Before the fix: a simulated push set the badge to 7, which shows the
app has badge permission. Opening the app and going home then cleared
it.
- After the fix: the badge showed 2. When one question was resolved, it
showed 1.

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant