Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/agent-client/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,18 +665,27 @@ async function main() {
}

if (command === 'eval') {
let expression = rest.join(' ');
const { tabId, rest: evalArgs } = extractTabFlag(rest);
// --await: wait for the result if the expression returns a Promise
const awaitIndex = evalArgs.indexOf('--await');
const awaitPromise = awaitIndex !== -1;
if (awaitIndex !== -1) evalArgs.splice(awaitIndex, 1);

let expression = evalArgs.join(' ');
if (!expression || expression === '-') expression = await readStdin();
if (!expression)
throw new Error('Usage: eval <expression> (or pipe via stdin: echo "expr" | bbx eval -)');
throw new Error(
'Usage: eval [--tab <id>] [--await] <expression> (or pipe via stdin: echo "expr" | bbx eval -)'
);
const response = await requestBridge(
client,
'page.evaluate',
{
expression,
returnByValue: true,
...(awaitPromise ? { awaitPromise: true } : {}),
},
{ source: REQUEST_SOURCE }
{ source: REQUEST_SOURCE, tabId }
);
await printSummary(response);
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-client/src/command-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const CLI_HELP_SECTIONS = Object.freeze([
{
title: 'Page',
lines: [
'bbx eval <expression> Evaluate JS in page context (use - for stdin)',
'bbx eval [--await] <expression> Evaluate JS in page context (--await for async, - for stdin)',
...[
'console',
'network',
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-client/test/cli-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,6 @@ test('bbx eval with empty stdin reports the usage error', async () => {
assert.equal(payload.evidence, null);
assert.equal(
payload.summary,
'ERROR: Usage: eval <expression> (or pipe via stdin: echo "expr" | bbx eval -)'
'ERROR: Usage: eval [--tab <id>] [--await] <expression> (or pipe via stdin: echo "expr" | bbx eval -)'
);
});