Skip to content

[Deploy preview] Add an experimental "Ask about this profile" chat using profiler-cli - #6450

Draft
canova wants to merge 27 commits into
firefox-devtools:mainfrom
canova:chat
Draft

canova wants to merge 27 commits into
firefox-devtools:mainfrom
canova:chat

Conversation

@canova

@canova canova commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Main | Deploy preview

This PR adds an experimental chat drawer that answers questions about the open profile. The model inspects the profile by running profiler-cli (pq) commands against the live Redux store, so commands like thread select or zoom push also update the view.

  • Requests go straight from the browser to a provider the user picks: Anthropic, OpenAI, OpenRouter (with a "Connect OpenRouter" sign-in), a local server or any OpenAI-compatible one. There is no server on our side.
  • The first commits make ProfileQuerier and the pq command definitions browser-safe, so the CLI and the chat share them.
  • Hidden behind window.experimental.enableProfileChat().

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.44578% with 308 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.71%. Comparing base (bcc5a09) to head (bd8db2d).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/profile-query/cli/execute.ts 25.00% 111 Missing ⚠️
src/components/chat/ChatTranscript.tsx 50.61% 38 Missing and 2 partials ⚠️
src/profile-query/node.ts 51.35% 18 Missing ⚠️
src/app-logic/profile-chat/providers/transcript.ts 86.40% 15 Missing and 2 partials ⚠️
src/components/chat/ChatProviderSettings.tsx 93.36% 13 Missing ⚠️
src/app-logic/profile-chat/providers/anthropic.ts 83.33% 11 Missing ⚠️
src/actions/chat.ts 91.80% 10 Missing ⚠️
src/app-logic/profile-chat/pq-browser-executor.ts 90.38% 10 Missing ⚠️
src/profile-query/cli/commands/profile.ts 23.07% 10 Missing ⚠️
src/reducers/chat.ts 85.71% 9 Missing ⚠️
... and 20 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6450      +/-   ##
==========================================
- Coverage   85.22%   82.71%   -2.52%     
==========================================
  Files         372      414      +42     
  Lines       40786    44193    +3407     
  Branches    11686    12918    +1232     
==========================================
+ Hits        34760    36554    +1794     
- Misses       5586     7195    +1609     
- Partials      440      444       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

canova added 27 commits December 3, 2026 16:59
Move the Node-only parts of ProfileQuerier (loading a profile from a file or
URL, saving it to disk, reading source map files and the in-thread source map
runner) into a ProfileQuerierNode subclass in profile-query/node.ts.

Also narrow the store the querier needs to a QuerierStore type with just
getState and dispatch, so a thunk can query the live app store.
Move the command and result types, the text formatters, the permalink view
mapping, and the command dispatch that used to live in Daemon.processCommand
into src/profile-query/cli/, so the web app can run pq commands against its
own store. The daemon now calls executeClientCommand and passes itself the
file system commands (profile save, sourcemap apply) that only it can run.
Move the commander definitions of the query commands into
src/profile-query/cli/commands/. Instead of talking to the daemon directly,
they now get a CommandContext from the entry point that says how to run a
command, print extra output, report a failure, and access local files.
Commands that need local files are left out when there is no file system.
runProfilerCliCommand parses a pq command line with the shared commander
definitions and runs it with a ProfileQuerier on the app's live store, so
commands like thread select and zoom push change the UI. Output is captured
as text, usage and query errors are reported instead of thrown, and long
output is truncated.

commander imports a few Node built-ins at module level, so the web build now
redirects those imports to small browser shims.
The chat sends the conversation to the Anthropic Messages API straight from
the browser with a key the user provides, and gives the model one tool,
run_profiler_cli, that runs pq commands on the live store through the
browser executor. The system prompt is the pq guide and schemas, cached,
and each user message ends with a description of the current view.

runChatTurn is the agentic loop, kept free of Redux. It keeps the history
append-only and answers every tool call, also when a turn is cancelled, cut
off or hits the tool call limit. The thunks in actions/chat.ts load the SDK
and the executor on demand, throttle the streamed text, and drop the results
of a turn whose conversation was reset in the meantime.
A full-height drawer on the right of the profile viewer, opened from a new
menu button. It asks for an Anthropic API key first, with a note on what is
sent to Anthropic, then shows the conversation: the user's messages, the
answers rendered as markdown, and every profiler-cli command the model ran
as a collapsed chip that expands to its output. The drawer is loaded lazily
so the markdown renderer stays out of the main bundle.

The feature is hidden unless enabled from the console with
localStorage.setItem('profiler.chat.enabled', 'true').

Turn notices and errors are now stored as typed values instead of English
strings, so the drawer can localize them.

A rejected key is no longer forgotten: the drawer shows the API's error
message instead, because a 401 can also mean the organization doesn't allow
browser requests, in which case the key is valid.
Move the Anthropic streaming code behind a ChatProvider interface, so the
agentic loop can run against other wire formats. The conversation is now
stored in the provider's own message format, tagged with that format, and
the transcript is derived from it in an SDK-free module.
Add a provider for the OpenAI Chat Completions API, which OpenAI, local
servers such as Ollama or LM Studio, and gateways all implement. The API
key form becomes a provider settings form with the presets Anthropic,
OpenAI, Local and Custom. OpenAI-compatible presets need a model, which
the form suggests from the server's model list.

Settings are stored per preset in localStorage, and switching provider
starts a new chat, as conversations are kept in each provider's own
message format.
Add an OpenRouter preset whose API key comes from OpenRouter's OAuth PKCE
flow, so that people can use the chat with an account rather than an API
key from a provider console, without a server on our side.

The auth page opens in a popup, so that the profile isn't unloaded, and
redirects to a static callback page that hands the code back over a
BroadcastChannel. The code is then exchanged for a key, which is stored
right away. Pasting a key still works, and the model list only shows
models that support tool calling.
Describe the presets and their settings, the "Connect OpenRouter" flow,
how to let a local model server accept requests from the profiler, and
where each provider sends the data.
OpenAI's Chat Completions endpoint rejects function tools together with
reasoning on some models, e.g. gpt-6-luna, which fails every request
since the chat relies on its profiler-cli tool. Add a provider for the
Responses API, which supports both, and use it for the OpenAI preset.
The other OpenAI-compatible presets stay on Chat Completions, which is
what those servers implement.

Requests use store: false, and the encrypted reasoning items are sent
back unchanged so that the model keeps its reasoning across tool calls.
Strict tool schemas were only used for OpenAI, so Chat Completions
requests no longer have that option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant