Repository navigation
Description
Summary
Starting bb from source in a fresh worktree can inject apps/cli/bin/bb into agent shells before its gitignored dist/index.js runtime exists. A sandboxed thread that runs bb then tries to bootstrap the CLI by writing into the source daemon worktree and fails with Operation not permitted; the injected CLI should be ready before any thread starts.
Versions and environment
- bb: 0.39.0, from source at
abbc3f91ccc4215889eaa317b0b234adc3cc6c1a - macOS 26.5.1 (25F80), Apple Silicon
- Node v22.23.1; pnpm 9.15.0
- Codex CLI 0.147.0
- Source daemon worktree:
env_ac99xb9nqm - Reproducing sandboxed thread worktree:
env_bnwjr7st7r - Thread:
thr_kbuh8i42fv
Steps to reproduce
- Create a fresh source checkout/worktree where
apps/cli/dist/index.jsdoes not exist. - Run
pnpm devfrom that checkout. - Create a sandboxed agent thread in another managed worktree.
- In that thread, run
bb status --json.
The source host daemon resolves the local wrapper for shell injection (source), but its Turbo dev task does not build @bb/cli first (source). The wrapper therefore falls into its lazy build path (source).
Expected vs actual
Expected: the injected bb CLI is already runnable and bb status --json returns status without modifying the daemon checkout.
Actual:
$ bb status --json
• turbo 2.8.3
• Packages in scope: @bb/cli, @bb/scripts
• Running build in 2 packages
• Remote caching disabled, using shared worktree cache
WARNING error creating log file directory: Custom { kind: PermissionDenied, error: Error { kind: CreateDir, source: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }, path: "/Users/michael/.bb/worktrees/env_ac99xb9nqm/bb/packages/scripts/.turbo" } }
x Internal errors encountered: error with cache: Failed to replay logs:
| Cannot write logs: failed to create directory `/Users/michael/.bb/
| worktrees/env_ac99xb9nqm/bb/packages/scripts/.turbo`
exit code 1
Evidence
The failing shell had BB_CLI set to the wrapper in env_ac99xb9nqm, while the active thread ran in env_bnwjr7st7r. Building the CLI inside the active worktree did not help because the built CLI re-executed the injected external BB_CLI; unsetting BB_CLI and running the local wrapper succeeded.
What was ruled out
- The target worktree CLI works after a local build when the injected
BB_CLIoverride is removed. - This is not a packaged-production CLI failure; the production bundle supplies its own executable directory.
- The permission error is not a general inability to run
bb; it comes from the lazy build targeting the separate daemon checkout. - Searches for
fresh worktree CLI,BB_CLI worktree,Operation not permitted .turbo, andMissing built bb CLIfound no matching issue or PR.
Suggested priority and effort
Medium priority, small effort. It blocks all injected bb commands for sandboxed threads when source development begins from an unbuilt worktree, with an unintuitive environment-unset workaround.
AGENT GENERATED: by GPT-5
Activity
Build source CLI before host daemon startup (get-bb#1971)