Repository navigation
Add a usable local Cloud development workflow - #1168
Conversation
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request for security, code quality, performance, duplication, architecture, and end-to-end behavior. |
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5: This pull request adds one command for local Cloud work. The main server flow starts, but several security and machine paths still fail.
I found six issues:
- P1: Seeded authentication is reachable from LAN and Tailscale clients because Vite listens on every interface.
- P1: The
--github-authmode cannot authorize an HTTP<label>.localhostgate. - P1: Machine creation and revocation call the Connect port instead of the separate account port.
- P1: Machine enrollment, tunnels, shares, and the machine page still require the production HTTPS topology.
- P2: HTTP 500 readiness responses cause a tight retry loop and leave response bodies unread.
- P2: Bind failures and the 100 ms shutdown path can leave detached services active.
The architecture still infers an account origin from a gate origin in several places. Carry both origins explicitly through each contract. Centralize loopback validation so IPv4, IPv6, protocol, and port rules cannot drift.
Validation passed for all affected Turbo tests and type checks. The app ran 2,415 tests, and the desktop ran 231 tests. The Cloud launcher started successfully in a real browser smoke test. The dashboard claimed a handle, generated a pairing code, and rendered the offline gate.
A LAN browser also received the seeded account state without authentication. Chromium rejected the insecure __Secure- desktop cookie for the HTTP gate.
I left a comment-only review, as required.
c74f570 to
cddc599
Compare
cddc599 to
9e1556e
Compare
|
Addressed the valid findings from the follow-up review in
Verification: all 12 affected-package typecheck tasks and all 13 affected-package test tasks pass. A production Web build with local variables present stayed on production config. Live local Cloud sign-up/session, routed readiness, and SIGHUP cleanup also passed. |
|
Fixed the paired-status issues in a18a1ed:
Verified with affected Turbo typechecks/tests (230 tests), a production web build, and a live local Cloud credential-revocation smoke test. |
… exports (#1377) Dead-code sweep based on the de-slop audit (`plans/deslop-report.md` on the audit branch, section 5). Every deletion below was re-verified against the current tree by repo-wide reference counting (apps/, packages/, plugins/, examples/, tests/, scripts/, docs/ — any occurrence of the identifier anywhere, including strings, JSON, and markdown, counted as a reference). Net delta: **+67 / −2,565 lines across 77 files**. ## 1. Historical QA log - `qa/manual-pass-log.md` (668 lines) — a single manual QA run log full of dead thread/environment IDs. Zero references. The root `qa/` directory is unrelated to the live `tests/qa/` package; only this log was deleted (the runbooks in `qa/` stay). ## 2. Stale plans (deleted 2 of 5, kept 3) | Plan | Classification | Action | | --- | --- | --- | | `environment-archive-grace-period.md` | **Completed** — its own header says "implemented 2026-06-17"; `managedEnvironmentRetireGraceMs` and the `retireRequestedAt` grace clock are live in `apps/server` | Deleted (precedent: #958 deletes shipped plans) | | `composer-extraction.md` | **Self-invalidated** — its own 2026-08-03 status says the premise moved: the side-chat site now shares hooks via `EmbeddedThreadChat` and the motivating 4th call site never landed | Deleted | | `bb-browser.md` | Never started, but deliberately kept and annotated by #958 one week ago; reads as live roadmap | **Kept** | | `bb-settings.md` | Partially overtaken (`bb settings` shipped in a different shape) but its own status re-scopes it to the remaining browser-link-settings work | **Kept** | | `in-app-browser-open-behavior-improvements.md` | Never started; companion to the two above, also kept by #958 | **Kept** | ## 3. Orphaned files (6 found, all with zero importers) - `apps/app/src/lib/child-thread-environment.ts` — `resolveChildThreadEnvironment` has no callers - `packages/db/src/data/cursor-pagination.ts` — not re-exported by the `@bb/db` barrel, no callers - `apps/app/src/components/icons/CodexIcon.tsx` — the codex provider renders `OpenAiIcon` (`provider-icon.ts`) - `apps/app/src/components/promptbox/mentions/file-mention.ts` (+ its test) — only its own test referenced it - `apps/server/src/services/lib/json-parsing.ts` — module never imported - `apps/app/src/views/thread-detail/useThreadTimelinePages.ts` — a pure rename-alias re-export shim over `useThreadTimelineController`. Its 400-line test covered merge helpers the controller's own test does not, so the test moved to `apps/app/src/components/thread/timeline/useThreadTimelineController.merge.test.ts` and imports the real module; only the shim was deleted. ## 4. Dead runtime exports (~40 symbols) Re-verified individually: zero references outside the defining file and its own test, and unused inside the defining file (declaration-only). Symbol-level `git log -S` confirmed none are recent/in-flight work. Deleted, with their arg-type interfaces and now-orphaned test blocks: - **apps/app**: `isPluginSlotInstanceCrashed`, `isFileOpenerPanelTab`, `PROMPT_STACK_COMPACT_INLAY_INSET_CLASS`, `PROMPT_STACK_COMPACT_INLAY_SEGMENT_CLASS`, `promptMentionArgumentHintPlaceholder`, `commandTriggerForComposerActions`, `resolveShowPanelControl` (plus the now-unreachable `"show-panel"` action variant + presentation entry), `isHostFilePreviewTab`, `getOpenSecondaryPanelTab`, `SIDEBAR_PLUGIN_WORKING_STATUS_COLOR_CLASS`, `isKnownSkillScope`, `seedSystemExecutionOptionsCache`, `hydrateSystemConfigCache`, `beginThreadTitleTransaction` (alias of live `beginThreadMetadataTransaction`; its test retargeted to the real function), `useReorderProject`, `usePluginCatalogStatus` (plus its private `fetchPluginCatalogStatus`/`toPluginCatalogStatus`/`PluginCatalogStatus` chain), `allThreadTabsQueryKeyPrefix`, `threadHostFilePreviewQueryKeyPrefix`, `useUpdateSkill`, `fetchHostId`, `looksLikeUrl` (its test cases are fully duplicated by the `resolveBrowserAddressInput` suite), `findFileOpenersForPath`, `interpretPluginFrontends` (dead duplicate — `plugin-frontend.ts` inlines the same logic), `getPluginFrontendRecords`, `getPullRequestSignalDisplays`, `buildQueuedMessageReorderRequest`, `getToolsRoutePath`, `isBusyThread`, the whole `workspace-open-target-preference.ts` guard family (`isWorkspaceDirectoryOpenTarget`, `isWorkspaceFileOpenTarget`, `isRemoteSshWorkspaceDirectoryOpenTarget`, `isRemoteSshWorkspaceFileOpenTarget`), `RootComposeRoute` (routes register through `SplitWorkspaceRoute` in `App.tsx`; `LegacyProjectComposeRedirect` is still live and stays), `reconcileLayoutForRoute`, `focusedThreadRoute`, `resolveThreadLocalWorkspaceRootPath`, `CreateViaPromptExamples` - **apps/host-daemon**: `resolveLocalBbExecutableDirectory` (5-line `dirname` wrapper; its 4 tests covered real entry-path validation and were retargeted to `resolveLocalBbExecutablePath`) - **apps/server**: `assertPrimaryHostId` (+ private `unsupportedHostError`), `directoryExists`, `swapDirIntoPlace` (superseded by the durable-promote path in the same file), `getTurnExecutionOptions` - **packages/db**: `listTrackedThreadStorageTargetsOnHost` - **packages/domain**: `ALL_REASONING_EFFORTS`, `threadProvisioningReasonSchema`, `turnLifecycleEventDataSchema` - **packages/host-daemon-contract**: `hostDaemonRetryableOnlineRpcCommandSchema` (+ its private union builder and descriptor filter). Runtime-value only; the `HostDaemonRetryableOnlineRpcCommand` *type* used by `online-rpc.ts` is untouched, nothing on the wire changes, so no `HOST_DAEMON_PROTOCOL_VERSION` bump. - **packages/host-workspace**: `decodeGitQuotedPath` - **packages/server-contract**: `environmentActionTypeSchema`, `domainErrorCodeSchema`, and the three alias-shim consts `hostPathsExistResponseSchema`, `hostPickFolderResponseSchema`, `hostProviderCliStatusResponseSchema` (their type aliases are still consumed and stay) ## 5. `BB_CLI_ENV` definition orphan `packages/config/src/env-vars.ts` defined `BB_CLI_ENV` but nothing imported it — all four call sites (`bb-cli-reexec.ts`, `runtime-shell-env.ts`, tests) read/write `env.BB_CLI` directly, and `defineEnvVar` has no global registry, so the definition served nothing. Deleted the definition only; call sites untouched. ## 6. `.gitattributes` Marked the committed generated artifacts as `linguist-generated` so they collapse in review diffs: - `packages/plugin-sdk/bundled-types/**` - `packages/templates/src/generated/**` ## Deliberately NOT deleted - **`packages/shared-ui/src/components/ui/**` + Radix deps** — intentional scaffold library, owner said keep (audit's largest line item, excluded by instruction). - **`packages/agent-runtime/**`** — a separate in-flight PR owns dead-code removal there (`./capture` subpath, `resolveAdapterPermissionPolicy`, test-harness exports). - **All `.stories.tsx` exports** — Storybook collects named exports by convention; they are framework-reachable, not dead. - **Test seams**: `__testing` (`apps/host-daemon/src/provider-usage.ts`) and `getPromptDecorationSet` (prompt-decoration extension) — exported only for their own tests, which verify live production behavior through them. - **`createBBSdk`** (`packages/bb-app/src/public-sdk.ts`) — a `package.json` exports entry point of the published `bb-app` package; external consumers are invisible to repo-wide grep. - **`createMachineCodeFn`** (`apps/web/src/server/fns.ts`) — unused TanStack server fn, but the file was touched yesterday by the Cloud dev-workflow PR (#1168); plausibly in-flight, left alone. - **`CLOUD_PAT_PREFIX`** (`packages/connect-db/src/constants.ts`) — unreferenced, but it is a documented policy constant ("token prefixes mirror bb's host-key convention") in a deliberate policy-constants file; ambiguous scaffold, left alone. - **Exported-but-internally-used symbols** (e.g. the `workspaceOpenTargetPreferenceAtom` atoms, storage-key consts) — de-exporting them deletes no lines; skipped to keep the diff pure deletion. - **Anything in `plugin-build/src/runtime-export-manifest.ts`** — the plugin runtime ABI was checked before every deletion; no deleted symbol appears in it. ## Verification - `pnpm exec turbo run typecheck` — all 58 tasks pass. - `pnpm exec turbo run test` for every touched package — all pass: `@bb/app` 2529, `@bb/server` 1436, `@bb/host-daemon` 541, `@bb/db` 379, `@bb/host-workspace` 194, `@bb/domain` 128, `@bb/config` 106, `@bb/host-daemon-contract` 49, `@bb/server-contract` 42 tests. (One guardrail test, `cache-owner-registry.test.ts`, correctly flagged a stale allowlist entry for the deleted `seedSystemExecutionOptionsCache` import; the entry was removed.) - No `package.json` dependencies were removed, so the lockfile is unchanged. > AGENT GENERATED: by Claude Fable 5 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <[email protected]>
## Summary - add `pnpm cloud:dev` as the one-command local workflow for the Cloud dashboard and Connect worker - run both services against one worktree-local D1 database and local Durable Objects - use real Better Auth email/password accounts and sessions in local Cloud instead of a seeded-user authentication bypass - route `bb.localhost` to the dashboard and `<handle>.bb.localhost` through Connect, including WebSocket upgrades - use the existing Vite app as the tunneled origin when a source-development bb pairs with local Cloud - make `pnpm dev` point unpaired Connect settings and code-only pairing at the matching local Cloud; explicit `--server` and `--base-url` targets still override it - support local machine creation, revocation, `ws:` machine tunnels, and `http:` machine share URLs while keeping non-local machine enrollment HTTPS-only - preflight all local ports, wait for the routed services to become ready, await child shutdown with SIGKILL escalation, handle SIGHUP, and tolerate clients closing rejected WebSocket upgrades ## Auth behavior Email/password endpoints and controls are enabled only when the launcher supplies the fail-closed local auth flag on an HTTP `*.localhost` origin. Production remains GitHub-only and keeps the secure production cookie names. Local sessions use non-secure cookie names scoped to `.bb.localhost`, allowing the same real session to authenticate the dashboard and handle subdomains. The existing GitHub control remains in the UI, but this workflow does not configure a local GitHub OAuth application; the launcher continues to supply placeholder OAuth credentials. Local D1 state is stored under `.wrangler/cloud-dev`. ## Review follow-up - readiness uses Node HTTP so the routing `Host` header is preserved, response bodies are drained, and failures back off - local Vite/auth overrides apply only to `vite serve`; a production build ignores them even if they are present in the shell - local Connect sign-in reconstructs the public handle URL, preserving `returnTo` - HTTP versus HTTPS is derived centrally from the trusted base domain and stays off the daemon wire, so no protocol bump is needed - gateway ports cannot overlap worker ports, and detached children are cleaned up on SIGHUP - removed dead account payload, duplicated auth configuration/header constants, redundant cookie defaults/re-exports, and formatting-only churn - added coverage for forwarded-header stripping, URL-template host validation, HTTP-to-WebSocket conversion, public machine origins, and the launcher regressions ## Verification - Turbo typechecks passed for all 11 affected packages (12 tasks including the plugin SDK build) - Turbo tests passed across 13 tasks: Connect Cloud 95, Web 53, config 96, scripts 85, Connect client 8, daemon contract 49, host daemon 505, plugin SDK 74, server 1,379, templates 23, and Connect plugin 77 - production Web build passed with local Cloud variables deliberately present; the emitted config remained on `https://getbb.app`, production D1, with no dev-auth flag or local secret - local auth smoke passed: dashboard 200, email/password sign-up, and authenticated session lookup - launcher smoke passed: routed readiness, bold ready URL, SIGHUP cleanup, and release of all three worktree ports
Summary
pnpm cloud:devas the one-command local workflow for the Cloud dashboard and Connect workerbb.localhostto the dashboard and<handle>.bb.localhostthrough Connect, including WebSocket upgradespnpm devpoint unpaired Connect settings and code-only pairing at the matching local Cloud; explicit--serverand--base-urltargets still override itws:machine tunnels, andhttp:machine share URLs while keeping non-local machine enrollment HTTPS-onlyAuth behavior
Email/password endpoints and controls are enabled only when the launcher supplies the fail-closed local auth flag on an HTTP
*.localhostorigin. Production remains GitHub-only and keeps the secure production cookie names. Local sessions use non-secure cookie names scoped to.bb.localhost, allowing the same real session to authenticate the dashboard and handle subdomains.The existing GitHub control remains in the UI, but this workflow does not configure a local GitHub OAuth application; the launcher continues to supply placeholder OAuth credentials.
Local D1 state is stored under
.wrangler/cloud-dev.Review follow-up
Hostheader is preserved, response bodies are drained, and failures back offvite serve; a production build ignores them even if they are present in the shellreturnToVerification
https://getbb.app, production D1, with no dev-auth flag or local secret