feat: add bsk network read-only command#8
Conversation
|
Thanks for following up on #2 and for putting this together. Since the issue was inactive for a while, I went ahead and implemented Because of that, we should not merge the console part of this PR as-is, since it would duplicate and partially regress the existing console API. The Happy to review that version. |
8e46308 to
f4c7e2d
Compare
|
Heads-up / coordination: I opened this right as #7 (your That leaves Want me to take |
|
Thanks, that sounds great. Please go ahead and refit this PR as Also, thanks for jumping in here as a first-time GitHub contributor. The For Once it’s rebased on current |
Add `bsk network` as a sibling of the `console` command from Tencent#7, reading the buffered network responses / failures for a tab. Fills the remaining half of the request in Tencent#2 (console landed in Tencent#7; network did not). Mirrors the console command's conventions exactly: bsk network --session <id> [--tab-id N] [--since C] [--limit N] [--max-text-chars N] The extension enables `Network` on attach (best-effort) and buffers `responseReceived` / `loadingFailed` events per tab with a monotonic sequence, correlating them to `requestWillBeSent` for method/URL. Reads are cursor-paginated (`since` -> `next_since`) and bounded (`limit`, `max_text_chars`) for agent-context safety, same as console. Entries carry the real HTTP status code (response) or the CDP failure reason (failure) — things `performance.getEntriesByType('resource')` can't give. Classified read-only (pass-through under the pending-interrupt gate); defaults to the Agent Window's active tab. Wires bsk-protocol (Method + params/result/entry structs + schema), bsk-cli (network subcommand + daemon dispatch allow-list) and the extension (handler + dispatcher route), with unit / parse / IPC tests paralleling the console command. Refs Tencent#2.
f4c7e2d to
965e922
Compare
|
Done — force-pushed the refit. This PR is now
|
There was a problem hiding this comment.
This PR adds bsk network in a way that generally follows the existing console command, but there are still several issues that should be addressed in this PR before merging: network event state isolation, Network.enable failure semantics, request metadata lifecycle, and shared helper extraction for duplicated buffered-read logic.
-
apps/extension/src/browser-driver/chromium-cdp.ts:networkRequestMetais currently a globalMap<string, NetworkRequestMeta>keyed only byrequestId. It is not scoped bytabId, andclearNetworkState(tabId)does not clear the request metadata for that tab.In multi-tab scenarios, if
requestIdvalues are reused or collide, a response/failure may pick up the URL/method/resourceType from another tab, producing incorrectly attributed network entries. Please make this per-tab, for exampleMap<number, Map<string, NetworkRequestMeta>>, and haverememberNetworkRequest,parseNetworkResponse, andparseNetworkFailureall look up and clean up metadata for the currenttabIdonly. -
apps/extension/src/browser-driver/chromium-cdp.ts:enableNetworkDomains()marks a tab as attempted before callingNetwork.enable, and then only debug-logs failures. After one failure, later calls will not retry, so an explicitbsk networkcall may just return an empty result, leaving the user with no indication that the Network domain failed to enable.Please separate best-effort attach-time behavior from explicit
ensureNetworkCapture()behavior. When the user explicitly reads network events, the code should either retry enabling the domain or return a clear failure to the handler, ultimately surfacing ascdp_failed. -
apps/extension/src/browser-driver/chromium-cdp.ts:networkRequestMetaentries are not removed afterresponseReceived/loadingFailed; they are only bounded byMAX_NETWORK_REQUEST_META. The stored URL is also the raw, untruncated URL. Network events can be high-volume, and long URLs or data URLs can make this map grow substantially in bytes even with an entry-count cap.Please limit stored metadata size when writing it, preserve truncation information, and remove the corresponding request metadata once a response/failure has been processed. This can be handled together with the per-tab metadata change.
-
apps/extension/src/browser-driver/chromium-cdp.ts:parseNetworkFailure()writes"(unknown)"into the structuredurlfield when request metadata is missing. That is a presentation-layer placeholder, but here it becomes part of the structured protocol result, and clients may treat it as a real URL.Please avoid putting display placeholders into the protocol layer. Options include making the URL optional in the protocol, carrying a request id / unknown marker, or displaying
unknownonly in the CLI human renderer. -
apps/extension/src/tools/network.ts/apps/extension/src/tools/shared.ts:ensureNetworkCapture?andnetworkEntriesSince?were added as optional methods onCdpRunner, which forceshandleNetworkto carry a runtime compatibility branch. In production,ChromiumCdpshould necessarily support these methods for the new command.Please define a more precise dependency type for the network handler where these methods are required, and remove the runtime
if (!deps.cdp.ensureNetworkCapture || !deps.cdp.networkEntriesSince)branch. Test fakes can implement that type directly, avoidingas unknown as CdpRunner. -
apps/extension/src/tools/network.ts:parseNetworkBounds()/boundedOptionalInteger()largely duplicate thesince/limit/max_text_charsparsing logic from the console handler. Since this PR introduces a second buffered-read command, this shared behavior should be factored out in this PR instead of duplicated.Please move the positive-integer bounds parsing, or a more specific cursor-read bounds parser, into
tools/shared.ts; for example, a sharedboundedOptionalInteger()orparseBufferedReadBounds(). This keeps console/network defaults, caps, and error messages from drifting over time. -
apps/extension/src/browser-driver/chromium-cdp.ts: the network bounded-buffer append, pagination, truncation aggregation, and text truncation logic closely duplicate the existing console logic. Since this PR explicitly aims for network to “mirror console exactly”, the consistency should be enforced by shared code rather than copy/paste.Please extract small, local helpers in this PR. Low-risk examples are
appendBoundedEntry()andtruncateText(); if the change remains contained, the buffered pagination logic can also be shared. This reduces the chance of future fixes landing on only one side. -
crates/bsk-protocol/src/tools/network.rs:NetworkEntryKind::as_str()is newly added but currently unused. Please remove it to avoid exposing unused API surface, or use it from the CLI renderer. -
crates/bsk-cli/src/cli/network.rs: the human failure output uses a Unicode—separator. CLI output should stay simple ASCII and consistent with nearby commands. Please use something like#{} FAILED {method} {} - {err}instead. -
apps/extension/src/tools/__tests__/network.test.ts: the network tests duplicate console test fixtures and bounds behavior coverage. Since the bounds parsing should become a shared helper, please move that coverage to tests for the shared helper, and keep the network handler tests focused on network-specific CDP forwarding, tab/session authorization, and error behavior.
Refit to
network-only per @BB-fat's go-ahead —consolelanded in #7, this fills the remaining half of #2.Adds
bsk networkas a sibling of theconsolecommand, reading buffered network responses / failures for a tab. It mirrors the console command's conventions exactly.What
The extension enables
Networkon attach (best-effort) and buffersresponseReceived/loadingFailedper tab with a monotonic sequence, correlating them torequestWillBeSentfor method/URL. Reads are cursor-paginated (since→next_since) and bounded (limit,max_text_chars) for agent-context safety — same shape asconsole. Entries carry the real HTTP status code (response) or the CDP failure reason (failure), whichperformance.getEntriesByType('resource')can't provide. Classified read-only; defaults to the Agent Window's active tab.Layers
Method::ToolNetwork,Network{Params,Result,Entry}+NetworkEntryKind, generated schema, read-only classification.networksubcommand (mirrorsconsole) + daemon dispatch allow-list.tools/network.tshandler + dispatcher route; buffering inchromium-cdp.ts(ensureNetworkCapture/networkEntriesSince).Testing
cargo check/cargo clippyclean;cargo testgreen for the touched units (protocol round-trips,cli_parse, method classification);rustfmtclean; schema regenerated viadump-schema(no drift to existing files).tools_ipcnetwork round-trip mirrors the console one.tscclean,vitestgreen (incl. newnetwork.test.tshandler tests),biomeclean.No
consolechanges remain — this is purely additive on top of #7. Refs #2.