feat: self-reported prompts, client and used skills - #205
Conversation
WalkthroughThe agent now propagates MCP source attribution through WebSocket session creation and reconnection. Command execution forwards a prompt once, reports site-recipe outcomes, and safely handles batches without user-facing results. ChangesAgent session and reporting changes
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant browserless_agent
participant getOrCreateSession
participant connect
participant BrowserWebSocket
browserless_agent->>getOrCreateSession: open session with mcpSource.source
getOrCreateSession->>connect: pass source
connect->>BrowserWebSocket: upgrade with x-browserless-mcp-source
BrowserWebSocket-->>connect: establish browser session
browserless_agent->>getOrCreateSession: send commands
getOrCreateSession-->>browserless_agent: inject _prompt once and process reportSkillOutcome
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/tools/agent.ts (1)
683-683: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winTrack prompt delivery on
ActiveSession, not per tool invocation.
promptSentis recreated insiderunCommands, whilegetOrCreateSessionreuses persistent sessions. Subsequent calls can therefore send_promptagain, and concurrent calls can both pass the guard. Store the delivery state onActiveSessionand claim it synchronously before sending.Also applies to: 712-717
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tools/agent.ts` at line 683, Move prompt delivery tracking from the per-invocation promptSent variable in runCommands onto the persistent ActiveSession object reused by getOrCreateSession. In the _prompt delivery path around lines 712-717, synchronously check and claim the session-level state before sending so subsequent and concurrent calls send the prompt only once.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/agent-client.ts`:
- Around line 744-745: Update the ActiveSession state and its initialization to
retain the original compliant value, then replace the hard-coded false in the
reconnect flow with session.compliant. Ensure reconnects use the same compliance
setting as initial session creation.
- Line 630: Update getOrCreateSession so session cache and pending-session
lookups account for the source value, preventing calls with different
mcpSource.source values from reusing the same browser; alternatively, explicitly
reject source changes before reuse. Ensure the selected session always sends the
matching x-browserless-mcp-source header.
In `@src/skills/system-prompt.ts`:
- Line 15: Update the executor handling for reportSkillOutcome so it is treated
as a terminal internal command: exclude it from user-facing result selection and
automatic getDownloads post-processing, ensure it is sent exactly once only when
a recipe was loaded, and define cleanup ordering so it is dispatched as the
final WebSocket command without being blocked by close. Use the existing
executor command-processing and result-selection symbols near the system prompt
integration.
---
Nitpick comments:
In `@src/tools/agent.ts`:
- Line 683: Move prompt delivery tracking from the per-invocation promptSent
variable in runCommands onto the persistent ActiveSession object reused by
getOrCreateSession. In the _prompt delivery path around lines 712-717,
synchronously check and claim the session-level state before sending so
subsequent and concurrent calls send the prompt only once.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0d98d235-ed2e-456d-b1e6-d3bb22fb6392
📒 Files selected for processing (4)
src/@types/types.d.tssrc/lib/agent-client.tssrc/skills/system-prompt.tssrc/tools/agent.ts
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/tools/agent.ts (1)
683-683: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winScope
_promptto the session, not the batch.getOrCreateSession()reuses an existingActiveSession, sopromptSentresets on everyrunCommands()call and the same session can receive_promptagain on later tool calls. Store the flag onActiveSessionor change the comment to “once per batch.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tools/agent.ts` at line 683, Persist the prompt-sent state on ActiveSession rather than declaring promptSent inside runCommands, so getOrCreateSession() reuses it across calls and each session receives _prompt only once. Update the relevant ActiveSession definition and _prompt dispatch logic while preserving per-session behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tools/agent.ts`:
- Around line 698-705: Update the command/result tracking around the
reportSkillOutcome branch and the later lastCmd derivation so skipped
reportSkillOutcome commands cannot shift the association between recorded
results and originating commands. Preserve the existing send-and-ignore
behavior, while keeping each recorded result tied to its source command or
deriving lastCmd from that association so batches such as goto,
reportSkillOutcome, screenshot use screenshot for formatting and skill
detection.
---
Outside diff comments:
In `@src/tools/agent.ts`:
- Line 683: Persist the prompt-sent state on ActiveSession rather than declaring
promptSent inside runCommands, so getOrCreateSession() reuses it across calls
and each session receives _prompt only once. Update the relevant ActiveSession
definition and _prompt dispatch logic while preserving per-session behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8f42c280-5343-4c84-a9ce-18001a9e560b
📒 Files selected for processing (4)
src/@types/types.d.tssrc/lib/agent-client.tssrc/skills/system-prompt.tssrc/tools/agent.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/skills/system-prompt.ts
- src/@types/types.d.ts
- src/lib/agent-client.ts
🤖 I have created a release *beep* *boop* --- ## [1.16.0](v1.15.0...v1.16.0) (2026-07-27) ### Features * self-reported prompts, client and used skills ([#205](#205)) ([ee4f11a](ee4f11a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: browserless-actions-bot[bot] <186328842+browserless-actions-bot[bot]@users.noreply.github.com>
Summary by CodeRabbit
New Features
Bug Fixes