Better support for workflows that involve multiple source directories#7738
Better support for workflows that involve multiple source directories#7738
Conversation
* an agent skill.md and scripts for starting, stopping, and connecting to Bloom.ex * api/common/instanceInfo now gives information like the path to the exe file so that agents and tests can check that they are talking to the right bloom (vs. one in another worktree entirely) Future: allow multiple Blooms to be running. e.g. Add startup arguments for HTTP port and CDP port. Bypass the single-instance token when given the ports. Update the helper scripts to launch Bloom with explicit ports. Make sure agents and tests kill the exact bloom they ran; they should be able to determine the pid.
Allows tests or agents to launch their own copies of bloom.exe on their own ports, lessoning the chance of stepping on other running versions running from different code directories. Does not yet include any kind of principled random port choosing.
There was a problem hiding this comment.
Pull request overview
This PR improves developer/automation workflows for running multiple Bloom instances (and/or multiple worktrees) by adding explicit startup port/label support, reserving a larger port block, and providing Node/Playwright tooling to launch and attach to the embedded WebView2 via CDP.
Changes:
- Add startup parsing for
--http-port,--cdp-port,--vite-port, and--label, and use these to support multi-instance startup flows. - Reserve a 3-port HTTP block (http, websocket, +1 extra reserved), expose
common/instanceInfo, and improve Vite-dev port/origin handling. - Add automation scripts (
watchBloomExe.mjs,go.mjs, bloom-automation helpers) and exe-backed Playwright smoke tests.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/BloomTests/ProgramTests.cs | Adds unit tests for startup argument parsing and validation. |
| src/BloomExe/web/controllers/CommonApi.cs | Adds common/instanceInfo endpoint for automation/runtime discovery. |
| src/BloomExe/web/ReactControl.cs | Supports dynamic Vite dev ports and origin replacement; adds dev-server reachability checks. |
| src/BloomExe/web/BloomServer.cs | Reserves a 3-port block; checks companion port availability; centralizes websocket port calculation. |
| src/BloomExe/Workspace/WorkspaceView.cs | Replaces hard-coded websocket port math and supports Vite origin replacement in templates. |
| src/BloomExe/WebView2Browser.cs | Makes remote debugging port configurable via --cdp-port (defaulting to 9222 only in DEBUG). |
| src/BloomExe/Shell.cs | Updates window title to optionally show label and port summaries. |
| src/BloomExe/ProjectContext.cs | Uses centralized websocket port accessor. |
| src/BloomExe/Edit/ToolboxView.cs | Ensures Vite dev HTML templates use the correct origin when a non-default Vite port is chosen. |
| src/BloomExe/Edit/PageThumbnailList.cs | Rewrites Vite dev origin in thumbnail list template when applicable. |
| src/BloomExe/Edit/EditingModel.cs | Rewrites Vite dev origin in edit/page-list templates when applicable. |
| src/BloomExe/Book/Book.cs | Stops hard-coding Vite origin; uses helper to build Vite dev URLs. |
| src/BloomBrowserUI/scripts/go.mjs | New script to start Vite on a random/selected port, wait for readiness, then launch Bloom with matching --vite-port. |
| src/BloomBrowserUI/react_components/component-tester/playwright.bloom-exe.config.ts | Adds a Playwright config for exe-backed UI tests. |
| src/BloomBrowserUI/react_components/component-tester/bloomExeCdp.ts | Helpers to connect to Bloom’s embedded WebView2 over CDP and query workspace tab state. |
| src/BloomBrowserUI/react_components/TopBar/component-tests/bloom-exe-tabs.uitest.ts | Adds exe-backed Playwright tests for tab switching and basic console/network observability. |
| src/BloomBrowserUI/react_components/TopBar/CollectionTopBarControls/component-tests/bloom-exe-collection-topbar.uitest.ts | Adds an exe-backed Playwright smoke test for collection top bar controls. |
| src/BloomBrowserUI/package.json | Adds exe and go scripts to launch watch/run and combined Vite+Exe flow. |
| scripts/watchBloomExe.mjs | New repo-level launcher for dotnet watch run with explicit port leasing and readiness detection. |
| go.sh | Convenience wrapper for running the combined go.mjs flow from repo root. |
| ReadMe.md | Updates build/dev instructions to use ./go.sh; clarifies feedback env var guidance. |
| .github/skills/bloom-automation/webview2Targets.mjs | Adds helper to list CDP targets (optionally selecting an instance via common/instanceInfo). |
| .github/skills/bloom-automation/switchWorkspaceTab.mjs | Adds helper to attach via CDP and switch tabs by clicking the real top bar. |
| .github/skills/bloom-automation/killBloomProcess.mjs | Adds helper to terminate Bloom/dotnet-watch processes with instance targeting. |
| .github/skills/bloom-automation/bloomProcessStatus.mjs | Adds helper to report running Bloom/watch processes and endpoint reachability. |
| .github/skills/bloom-automation/bloomProcessCommon.mjs | Shared automation utilities: port leasing, instance discovery, process classification, and endpoint helpers. |
| .github/skills/bloom-automation/SKILL.md | Documents the new Bloom exe CDP automation workflow and helper commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const standardBloomStartingHttpPort = 8089; | ||
| const standardBloomPortIncrement = 2; |
| errorMessage = $"Bloom requires a value after {optionName}."; | ||
| return true; | ||
| } | ||
|
|
| && StartupCdpPort.Value <= StartupHttpPort.Value + 2 | ||
| ) | ||
| { | ||
| errorMessage = | ||
| "Bloom's --cdp-port must not overlap the reserved HTTP block (http, http+1, http+2)."; |
| { | ||
| for (var i = 0; !success && i < kNumberOfPortsToTry; i++) | ||
| { | ||
| BloomServer.portForHttp = kStartingPort + (i * kNumberOfPortsWeNeed); | ||
| success = | ||
| AreReservedCompanionPortsAvailable(BloomServer.portForHttp) | ||
| && AttemptToOpenPort(); | ||
| } |
| private static int? kDefaultRemoteDebuggingPort => | ||
| #if DEBUG | ||
| 9222; | ||
| #else | ||
| null; | ||
| #endif | ||
|
|
||
| public static int? RemoteDebuggingPort => | ||
| Program.StartupCdpPort ?? kDefaultRemoteDebuggingPort; |
There was a problem hiding this comment.
🚩 Remote debugging port now exposed in release builds when --cdp-port is passed
Previously, --remote-debugging-port=9222 was only added in DEBUG builds (src/BloomExe/WebView2Browser.cs:289-291 old code had #region DEBUG). Now RemoteDebuggingPort (src/BloomExe/WebView2Browser.cs:36-37) returns Program.StartupCdpPort ?? kDefaultRemoteDebuggingPort, where kDefaultRemoteDebuggingPort is 9222 in DEBUG and null in RELEASE. Passing --cdp-port on the command line would enable remote debugging in a release build. This is by design for automation, but worth noting that it opens a CDP port that could be accessed by other local processes.
Was this helpful? React with 👍 or 👎 to provide feedback.
nabalone
left a comment
There was a problem hiding this comment.
I didn't really review the .mjs scripts, thinking we would notice if there's something wrong with them. But let me know if I should
|
|
||
| var remainingArgs = new List<string>(); | ||
|
|
||
| for (var i = 0; i < args.Length; i++) |
There was a problem hiding this comment.
[Worded by Devin]
Suggestion: consider simplifying this hand-rolled argument loop
This codebase already uses the CommandLineParser NuGet library (imported at , used at lines 214–264 with attribute-decorated classes like HydrateParameters in ). The 120-line hand-rolled loop here is inconsistent with that existing pattern.
Duplication: The three port option blocks (lines 746–812) are near-identical copy-paste that differ only in the option name and backing property. A dictionary-driven approach or a small shared helper could cut the loop body to ~20 lines:
var portOptions = new Dictionary<string, Action>
{
["--http-port"] = v => StartupHttpPort = SetOnce(StartupHttpPort, v, "--http-port"),
["--cdp-port"] = v => StartupCdpPort = SetOnce(StartupCdpPort, v, "--cdp-port"),
["--vite-port"] = v => StartupVitePort = SetOnce(StartupVitePort, v, "--vite-port"),
};
Bug — --label swallows flags: TryParseStartupStringArgument (line 876) unconditionally accepts the next token as the value, so --label --help silently treats --help as the label. The Node.js helpers in this same PR explicitly reject values starting with -- (e.g. requireOptionValue in bloomProcessCommon.mjs), but the C# side doesn't.
Magic number: The overlap check at line 845 hard-codes + 2 instead of referencing BloomServer.ReservedPortBlockLength, as also noted in the existing Copilot review thread.
Not blocking, but worth a cleanup pass — especially the --label flag-swallowing issue.
There was a problem hiding this comment.
If we want to keep Program.cs clean I thought this might be worth doing, and an AI could do it quickly. But feel free to ignore and merge
This change is