Repository navigation
Move a local plugin to a new directory without losing its settings - #2125
Conversation
|
🚨 SLOP COP 🚨 · I am the Slop Cop. I am reviewing this pull request for security, code quality, performance, architecture, and the full user flow. |
| identity.sourceIntent, | ||
| ) | ||
| ) && | ||
| !isPathSourceMove(existing, identity) |
There was a problem hiding this comment.
🚨 slopcop/review — Any direct path can receive the saved plugin identity.
This check uses only the path type and the self-declared plugin ID. It does not verify the expected old source. Another local plugin can receive the saved secrets and schedules. Add an explicit move request with the expected old canonical path.
| if (!sameDirectory(existing.rootDir, args.rootDir)) { | ||
| forgetMutableRoot(existing.rootDir); | ||
| } | ||
| logger.info( |
There was a problem hiding this comment.
🚨 slopcop/review — A failed start still completes the move.
loadOne() records a factory error and returns. This code then writes a success log and keeps the failed source. I reproduced this result with a valid package whose factory throws. The CLI reported Installed, but the plugin had an error state. Keep the old registration until the new plugin starts successfully.
| description={ | ||
| pluginIsLocalSource(deleteTarget) | ||
| ? `Remove "${deleteTarget.id}" from bb? Its source files will stay on disk.` | ||
| ? `Remove "${deleteTarget.id}" from bb and delete its settings? Its source files will stay on disk.` |
There was a problem hiding this comment.
🚨 slopcop/review — The warning omits deleted secrets and schedules.
The server deletes settings, secrets, and schedules. This dialog lists only settings. Both mobile dialogs also give incorrect information. They say that settings and data stay after removal. Update all three user surfaces with the same deletion policy.
| } | ||
| throw error; | ||
| } | ||
| if (existing !== undefined && existing.rootDir !== args.rootDir) { |
There was a problem hiding this comment.
🚨 slopcop/review — A move starts a disabled plugin.
The move block runs after the upsert sets enabled: true. A move must keep existing.enabled. I disabled version 0.2.0 and moved it. Version 0.1.0 then ran without an enable command.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain English summary: This change lets bb move a local plugin to another folder without deleting saved configuration. The normal move works. However, several edge cases can start unwanted code or replace healthy code.
Priority findings:
-
P1 — Add an explicit move contract. The server accepts any direct path with the same self-declared plugin ID. That code receives the existing settings, secrets, and schedules. The request must include the expected old canonical path.
-
P1 — Do not commit a failed start. A valid plugin whose factory throws replaces the healthy plugin. The CLI still reports
Installedwith an error state. The new test checks only an invalid manifest before the server changes live state. -
P1 — Preserve the disabled state. The upsert always sets
enabled: true. A move therefore starts a plugin that the user disabled. -
P1 — Correct every removal warning. The desktop dialog omits secrets and schedules. Both mobile dialogs say that settings and data stay. The server deletes settings, secrets, and schedules.
Other findings:
- The built-in CLI skill still tells agents to remove and reinstall a changed pinned source. That advice can delete the state this change protects.
- The new directory check repeats runtime canonical-path logic. A changed old symlink can leave its prior mutable root in the module resolver.
- Use the managed activation flow in
plugin-activation.ts. It already checks runtime errors and restores the old registration. - A shared registration classifier can return
same-source,path-move, orconflict. This result can control validation, state, cleanup, and logs.
Verification:
- The A-to-B CLI move kept
floor=1,token=[set], and the schedule. - A disabled move became a running plugin.
- A valid factory failure returned
Installedwith an error state. - Doobie showed the changed desktop removal dialog.
- All GitHub checks pass.
I found no other security issue or hot-path performance problem. The issues above block a safe merge.
Installing a path: source for a plugin id that was already installed from another local directory was refused with "remove it first", and remove() deletes the plugin's settings, secrets, and schedules. Re-pointing a local plugin at a new checkout therefore silently reset it to defaults, and the CLI help, guide, and local-plugin dialog described remove as non-destructive. Treat a direct path -> path install of the same id as a move: dispose the old instance, upsert the row with the new source and rootDir, load it, and forget the old mutable root. Settings, secrets, and schedules are keyed by plugin id, so they survive. Log the move and the remove, and say in the CLI description, guide, skill, and app dialog that remove deletes configuration. Fixes #1766 Co-Authored-By: Claude <[email protected]>
…start Round 1 of #2125. Automated review reproduced two defects in the path move: the move block ran after the upsert forced enabled: true, so a user-disabled plugin started after a move; and loadOne records a throwing factory as an error status and returns, so a valid package whose factory throws replaced the healthy install while the CLI reported Installed. A move is now a direct path -> path install of the same id from a different directory (same-directory reinstall keeps its re-enable behavior). The upsert carries the previous enabled flag. After loadOne, any runtime status other than running, disabled, or needs-configuration fails the move: the candidate is disposed, restoreRegistration() puts the old row back, the old instance reloads, and the install throws with the failure and the kept source. Align every removal dialog (desktop detail, browse tab, both mobile sheets) with remove(): settings, secrets, and schedules are deleted; a local plugin's files stay; install the new path to move it. The mobile sheets said settings and data were kept, which was wrong. Update the skill, guide, and the pinned-source CLI/server messages to describe the in-place path move instead of remove + reinstall. The CLI confirmation for a path install now names the install it moves ("This moves <id> from <old dir>; its settings, secrets, and schedules are kept") by reading the local package.json it already parses and listing plugins, so a move is never silent at the human gate. No wire change. Co-Authored-By: Claude <[email protected]>
a7b27b2 to
8dd6016
Compare
## What was wrong The codebase carried a lot of code that nothing reached: symbols and files with no consumer, options that no caller passes, branches the types make impossible, feature flags that graduated but kept their `if` guards, pass-through wrappers that only forward arguments, barrel files that re-export hundreds of names nobody imports through them, and the same small helper copied into many files. This code has no effect on behavior, but every reader must still parse it. ## What changed Net −16k lines across 1,732 files. No behavior change. Four commits, two per pass: 1. **Remove dead code, pass-through wrappers, and stale barrels** — unused symbols and files, dead branches, unused params/options, single-use wrappers inlined, dead barrel lines, tests and stories that existed only for deleted code. Drops the unused `cronstrue` dependency from `apps/app`. 2. **Drop export from module-private symbols** — ~900 declarations that were exported but only used inside their own file. 3. **Remove more dead code, duplicate helpers, and unused options** — second pass over the same ground plus repo-wide sweeps for duplicate helpers and legacy/compat paths. Folds byte-identical helper copies into one shared module where the consumer already depends on it (e.g. `describeError` ×11, `createDeferred` ×15 → `@bb/test-helpers`, `DelayedLoading` ×4 → `@bb/shared-ui`). Removes unused `ws`/`@types/ws`/`tsx` devDependencies from `apps/connect` and an unused `@radix-ui/react-slot` from `apps/web`. 4. **Drop export from more module-private symbols** — ~700 more. Out of scope on purpose: `@get-bb/plugin-sdk` and `@bb/sdk` exports (public API), CLI commands and flags, server routes, DB schema and migrations, generated code, wire payload shapes between the server and host daemon (`HOST_DAEMON_PROTOCOL_VERSION` is unchanged), and parsers for persisted or legacy data. Every removal was found by one agent, adversarially verified by a second agent that searched the whole repo (including strings, configs, docs, `.ladle`, and stories) for any remaining reference, and then applied by a third. 41 proposals were rejected at verification or apply time, and I reverted 2 more by hand. ## How you verified - `pnpm exec turbo run typecheck` — 74/74 packages pass - `pnpm exec turbo run lint` — passes - `pnpm exec turbo run build` for `@bb/app`, `@bb/server`, `@bb/host-daemon`, `@bb/cli`, and all `plugins/*` — passes - `pnpm exec turbo run test` — all packages pass except `internal-skill-trees.test.ts`, which fails identically on `main` on this machine (local umask 0002; passes in CI) - Rebased onto `main` after #2125, #2132, #2128, #2126, #2112 landed; re-ran typecheck, lint, and tests for the touched packages Fixes # > AGENT GENERATED: by Claude Opus 5 --------- Co-authored-by: Claude <[email protected]>
What was wrong
A plugin installed from a local directory could not be re-pointed at another directory.
assertInstallRegistrationAvailableinapps/server/src/services/plugins/plugin-registration.tsrefused a same-idpath:install whose canonical path differed ("already installed from path:...; remove it first"), andbb plugin updateis a no-op for path rows. The only route wasbb plugin remove+bb plugin install, andPluginService.remove()deletes the plugin'splugin_settingsrows,plugin_schedulesrows, and secrets directory. Nothing said so: the CLI help described remove as leaving local sources "alone", the guide and skill did not mention settings, the local-plugin dialog in the app said only "Its source files will stay on disk", both mobile removal sheets said "Its settings and data are kept for a reinstall", and the server logged nothing. Reinstalling from a new checkout silently reset the plugin to defaults.Issue: #1766. Report: https://get-bb.github.io/reports/issues/1766.html
Review round 1 (SlopCop on
a7b27b219) reproduced two defects in the first version of the move: a user-disabled plugin started after a move because the upsert forcedenabled: true, and a valid package whose factory throws replaced the healthy install (loadOne records the error as status and returns) while the CLI reportedInstalled.What changed
Server (
apps/server/src/services/plugins/):plugin-registration.ts: a move is a directpath:install of an id that is already registered from a different local directory (pathSourceMoveFrom). Reinstalling the same directory is not a move and keeps its existing "reinstall re-enables" behavior (covered by the existing test). For a move:enabledflag, so a disabled plugin stays disabled and does not start (round 1, finding 1);loadOne, any runtime status other thanrunning,disabled, orneeds-configurationfails the move: the candidate is disposed,restoreRegistration()puts the old row back, the old instance is reloaded, and the install throwsplugin "<id>" failed to start from path:<new>: <detail>; the install at path:<old> was kept, so the CLI and app report a failure instead ofInstalled(round 1, finding 2). The registration context now receives the runtimestatusesmap for this check. The managed activation flow inplugin-activation.tswas not reused: it is artifact-based (toArtifactId, on-disk state snapshots, rollback-pending rows) and path sources have no artifacts; the registration module already ownsrestoreRegistration, which is all a path move needs;removedoes) unless both paths resolve to the same directory, and the server logs the move.plugin-service.ts:remove()logs what it deleted; passesstatusesto the registration module.plugin-updates.ts:bb plugin update <path plugin>no longer tells the user to "remove and reinstall"; it says to edit in place +bb plugin reload, orbb plugin install path:<new directory>to move it (settings kept). The git/npm pinned message is unchanged.CLI (
apps/cli/src/commands/plugin.ts):bb plugin removedescribes what it deletes (round 0).path:source names the install it replaces: the CLI already reads the localpackage.jsonfor the summary; it now derives the plugin id, lists installed plugins, and printsThis moves "<id>" from <old dir>; its settings, secrets, and schedules are kept.before the full-trust prompt. Best effort inside the existing try; a failed list falls back to the plain summary.bb plugin update --allpinned message now says remove deletes settings and that path plugins reload/move instead (round 1, finding 4). Existing assertion text preserved.App and mobile (round 1, finding 3): one deletion-policy statement per client, used by every removal dialog.
apps/app/src/components/tools/PluginDetail.tsx:pluginRemovalDescription(); used by the desktop detail dialog inToolsView.tsx.BrowsePluginsTab.tsxuninstall dialog aligned too (it said "Plugin data may be retained").apps/mobile/src/data/plugins/plugin-model.ts:pluginRemovalDescription(); used by bothPluginsScreen.tsxandPluginDetailScreen.tsxsheets, replacing "Its settings and data are kept for a reinstall".Docs (round 1, finding 4):
apps/server/src/services/skills/builtin-skills/bb-cli/SKILL.mdandpackages/templates/src/templates/bb-guide-plugins.mdnow say a pinned git:/npm: source changes through remove (deletes settings) + install, while a local path plugin is never removed to change it: reload in place or install the new path to move it; both keep configuration.No wire change between server and host daemon, so no
HOST_DAEMON_PROTOCOL_VERSIONbump.On the proposed explicit move contract (round 1, finding 5)
Not implemented. The proposal was to carry the expected old canonical path in the install request so a different local plugin that self-declares an installed id cannot inherit its secrets. A local plugin's identity has always been its id:
bb plugin reloadalready runs whatever is in the registered directory with the same settings and secrets, and a same-path reinstall does too, so directory contents were never a trust boundary; kv rows anddata.dbare keyed by id and already survive remove + reinstall. The install is an explicit user action behind a full-trust confirmation that now names the exact install being replaced and its old directory, and the server logs the move. AnexpectedPreviousPathrequest field would be filled only by the CLI (the app has no path-install flow) and would be accepted-but-unused by every other caller, which AGENTS.md forbids. The ungated variant is the one the report listed as acceptable.How you verified
Tests in
apps/server/test/services/plugins/plugin-service.test.ts:origin/mainwithError: plugin id "moved" is already installed from path:.../a/bb-plugin-moved; remove it firstatplugin-registration.ts:257.AssertionError: expected { id: 'dormant', …(24) } to match object { id: 'dormant', enabled: false, …(2) }(the moved plugin came backenabled: true, status: "running").AssertionError: promise resolved "{ id: 'brittle', …(24) }" instead of rejecting. With the fix it asserts the rejection message, that the DB row is back at checkout A (version 0.2.0,enabled: true), that checkout A's factory ran again,getApi()is defined, and the secret is still set.App: new test in
apps/app/src/views/ToolsView.plugin-detail.test.tsx("warns that removing a local plugin deletes its settings, secrets, and schedules and names the move path") rendersToolsViewwith apath:plugin from a stubbed/api/v1/plugins, opens the actions menu, clicks "Remove from bb", and asserts the dialog copy. Mobile:plugin-model.test.tsassertspluginRemovalDescriptionfor both branches and that the old "kept for a reinstall" wording is gone.Commands (all from this branch, rebased on
origin/main2ff85986e):pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/app --filter=@bb/mobile --filter=@bb/templates: 8/8 tasks.pnpm exec turbo run test --filter=@bb/server --filter=@bb/templates: templates 6 files passed; server 194/195 files passed, the one failure is the pre-existinginternal-skill-trees.test.tsfile-mode assertion (local umask 0002 artifact, passes in CI).pnpm exec turbo run test --filter=@bb/cli --filter=@bb/mobile: cli 48 files passed, mobile 123 files passed.apps/app:vitest run src/views/ToolsView.plugin-detail.test.tsx src/components/plugin/management src/components/tools: 14 files passed.Manual repro on my own dev instance of this branch (server :22310, CLI built from this branch with
BB_CLI_REEXEC=1so the daemon'sBB_CLIhop did not swap in another checkout's binary):bb plugin install --yes path:.../a/bb-plugin-mover,config set floor 7,config set token s3cret,bb plugin disable mover.bb plugin install --yes path:.../b/bb-plugin-mover→[email protected] disabled,source: path:.../b/...; server logplugin mover source moved from path:.../a/... to path:.../b/...; settings, secrets, and schedules were kept. (Round 0 started it.)bb plugin config movershowsfloor = "7",token = [set].bb plugin install path:.../c/bb-plugin-mover(valid package, factory throws) printsThis moves "mover" from .../b/bb-plugin-mover; its settings, secrets, and schedules are kept.at the confirmation, then with--yes:Error: HTTP 422: plugin "mover" failed to start from path:.../c/...: boom at startup; the install at path:.../b/... was kept. Afterwards/api/v1/pluginsshowsmover 0.2.0 running path:.../b/...andbb plugin config moverstill shows7/[set]. (Round 0 reportedInstalledwith the plugin inerror.)POST /api/v1/plugins/mover/updatereturns the new path-specific message.Fixes #1766
Independent verification (round 0, on
a7b27b219; findings addressed above)Checked out
a7b27b219(this PR's head) into a fresh worktree branched fromFETCH_HEAD;origin/main(c9aef7514) is an ancestor, no conflicts.Commands:
pnpm install --frozen-lockfile --prefer-offline && pnpm exec turbo run build(18/18 tasks).git checkout origin/main -- <the 6 non-test files>thenpnpm exec vitest run test/services/plugins/plugin-service.test.ts -t "re-points a path plugin"inapps/server. Result:1 failed,Error: plugin id "moved" is already installed from path:/tmp/bb-plugin-test-cJ0tMv/a/bb-plugin-moved; remove it firstatplugin-registration.ts:258.plugin-service.test.ts: 25/25 passed.mvof the checkout (old dir gone) then install from the new path keeps settings and reloads; installing a symlink alias of the same directory keeps the mutable root live (reload picks up edits); a same-id managedgit:row still refuses apath:install; a new checkout whose factory throws registers inerrorstate pointing at the new dir with settings rows intact (same as a same-path reinstall today).pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/app --filter=@bb/templates: 7/7.pnpm exec turbo run test --filter=@bb/server: 1819/1820 passed; the one failure isinternal-skill-trees.test.tsmode 420 vs 436 (local umask artifact, passes in CI).@bb/cli453 passed,@bb/templates6 files passed,@bb/app3187 passed with oneTimelineRowDetails.output-preview15s timeout that passed on rerun (unrelated to this change).bb plugin install --yes path:.../checkout-a, setalertFloorMinutes=1,staleWindowMinutes=3,token=s3cret;bb plugin install --yes path:.../checkout-bsucceeded (was HTTP 422 on main);bb plugin config watchdogstill shows1/3/[set];bb plugin source watchdogshowspath:.../checkout-b; server log:plugin watchdog source moved from path:.../checkout-a to path:.../checkout-b; settings, secrets, and schedules were kept.bb plugin remove --helpfrom this branch's CLI build prints the new description. The original bug no longer reproduces.Residual risks noted in round 0 (all addressed in round 1):
SKILL.mdsaid "changing a pinned source requires reinstalling it after removal". Reworded for git/npm vs path.Independent verification (round 2, on
8dd601638)Checked out
bb/fix-1766-plugin-source-replaceat8dd601638in a fresh worktree (based on2ff85986e; a trialgit merge origin/mainat703213a77is clean). Diff against the merge-base: 16 files, +444/-29. No server/daemon wire change, so noHOST_DAEMON_PROTOCOL_VERSIONbump is needed. No accepted-but-ignored fields, no casts outside tests, guide template and bb-cli skill updated for the changedremovehelp and the move behavior.Fail-before / pass-after. With
apps/server/src/services/plugins/{plugin-registration,plugin-service,plugin-updates}.tsreverted toorigin/main, all three move tests fail (Error: plugin id "moved" is already installed from path:.../a/bb-plugin-moved; remove it first; brittle:expected [Function] to throw error matching /failed to start from path:.*boom at s…/ but got 'plugin id "brittle" is already instal…'). With those files at the round-0 commitdfdf9a9d6, the two round-1 tests still fail:expected { id: 'dormant', …(24) } to match object { id: 'dormant', enabled: false, …(2) }andpromise resolved "{ id: 'brittle', …(24) }" instead of rejecting. Restored to the PR head: 6/6 move-related tests pass. App test against main'sPluginDetail.tsx/ToolsView.tsx:expected 'Remove "github" from bb? Its source f…' to contain 'delete its settings, secrets, and sch…'; mobile test against main'splugin-model.ts:TypeError: pluginRemovalDescription is not a function. Both pass on the PR head.Turbo.
turbo run typecheckfor@bb/server,@bb/cli,@bb/app,@bb/mobile,@bb/templates: 8/8 pass.turbo run test: templates 6/6 files, cli 48/48, mobile 123/123. Server: 25 files timed out at 5s under load (dev instance and build were starting concurrently); re-run in isolation 24/25 pass, the one remaining failure is the pre-existing localinternal-skill-treesumask (0644 vs 0664) failure, which passes in CI. App: 14 files / 157 tests forcomponents/plugin/management,components/tools,ToolsView.plugin-detailpass. GitHub CI on8dd601638: all checks pass (Checks, Package Smoke x2, Tests app-1/2/3, integration, packages, server).Manual repro on my own dev instance (server :23641, own data dir, CLI from this branch with
BB_CLI_REEXEC=1). Fixture = the report's watchdog plugin in three directories: A (0.1.0), B (0.2.0), C (0.3.0, valid manifest, factory throwsboom at startup).alertFloorMinutes=1,staleWindowMinutes=3,token=s3cret;bb plugin install --yes path:BprintsThis moves "watchdog" from .../a; its settings, secrets, and schedules are kept.and[email protected] runningatpath:.../b;bb plugin config watchdogstill shows1/3/[set],plugin_schedulesstill hassweep. Server log:plugin watchdog source moved from path:.../a to path:.../b; settings, secrets, and schedules were kept. No longer reproduces.bb plugin disable watchdog, theninstall --yes path:A->[email protected] disabled,plugins.enabled = 0in the DB, noloadedlog line for the move.install --yes path:C->Error: HTTP 422: plugin "watchdog" failed to start from path:.../c: boom at startup; the install at path:.../b was kept, exit 1;bb plugin listshows[email protected] runningat B, settings1/3/[set], schedule and secrets file still present, DB rowenabled=1 root_dir=.../b version=0.2.0.pluginRemovalDescription()per client and name settings, secrets, and schedules; the browse-tab uninstall dialog no longer claims data may be retained.bb plugin remove watchdoglogs... removed from path:.../b; its settings, secrets, and schedules were deletedand the rows are gone.POST /plugins/watchdog/updateon a path row returns the new reload-or-install-the-new-path message;bb plugin update --allprints the new pinned message.bb plugin reloadpicks up a new setting; after moving back to B (whose root was forgotten), editing B and reloading picks up the change.Residual risks. A move while the plugin is disabled does not validate the new checkout (loadOne short-circuits to
disabled), soinstall path:Cwhile disabled succeeds and the factory error surfaces only on enable; settings are still kept and this matches how a disabled plugin behaves on reload. The move check covers only the immediate post-load status, as the body notes. A same-id local plugin from a different directory inherits settings and secrets by design; the CLI confirmation names the replaced install, but--yesskips it.