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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/agents/planner-executor/boundary-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,20 @@ function urlPredicateSignals(verify: PredicateSpec[] | undefined): string[] {
return signals;
}

function isProductNavigationIntent(step: {
action?: string;
intent?: string;
input?: string;
verify?: PredicateSpec[];
}): boolean {
const action = (step.action || '').toUpperCase();
if (action !== 'CLICK') {
return false;
}
const cues = `${normalizeIntentText(step.intent)} ${normalizeIntentText(step.input)}`;
return /\b(product|result|details?|item|listing)\b/.test(cues);
}

export function isSearchLikeTypeAndSubmit(
step: { action?: string; intent?: string; input?: string; verify?: PredicateSpec[] },
element?: Pick<SnapshotElement, 'role' | 'text' | 'name' | 'ariaLabel'> | null
Expand Down Expand Up @@ -330,6 +344,18 @@ export function isUrlChangeRelevantToIntent(
return true;
}

if (isProductNavigationIntent(step)) {
const productUrlHints = ['/dp/', '/product/', '/item/', '/sku/', '/p/'];
if (productUrlHints.some(hint => normalizeIntentText(nextUrl).includes(hint))) {
return true;
}
const terms = [...queryTerms(step.input), ...queryTerms(step.intent)];
if (terms.length > 0) {
return terms.some(term => nextSignals.some(signal => signal.includes(term)));
}
return false;
}

if (!isSearchLikeTypeAndSubmit(step, element)) {
return true;
}
Expand Down
22 changes: 21 additions & 1 deletion src/agents/planner-executor/category-pruner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ function nearbyTextOf(element: SnapshotElement): string {
return String(element.nearbyText || '').toLowerCase();
}

function combinedTextOf(element: SnapshotElement): string {
return [element.text, element.name, element.ariaLabel, element.nearbyText, element.href]
.filter((value): value is string => Boolean(value))
.join(' ')
.toLowerCase();
}

function hasSearchCue(element: SnapshotElement): boolean {
const combined = combinedTextOf(element);
return (
combined.includes('search') ||
combined.includes('keyword') ||
combined.includes('find') ||
combined.includes('query')
);
}

function roleOf(element: SnapshotElement): string {
return String(element.role || '').toLowerCase();
}
Expand Down Expand Up @@ -62,7 +79,10 @@ function allowShopping(element: SnapshotElement): boolean {
if (text.includes('$') || nearbyText.includes('price')) {
return true;
}
if (['textbox', 'searchbox', 'combobox'].includes(role) && text.includes('search')) {
if (role === 'searchbox') {
return true;
}
if (['textbox', 'combobox', 'input', 'textarea'].includes(role) && hasSearchCue(element)) {
return true;
}
return Boolean(element.inDominantGroup && text.trim().length >= 3);
Expand Down
7 changes: 7 additions & 0 deletions src/agents/planner-executor/plan-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ function normalizeStep(step: Record<string, unknown>): Record<string, unknown> {
delete normalizedStep.url;
}

if ('target' in normalizedStep && typeof normalizedStep.target === 'number') {
normalizedStep.target = String(normalizedStep.target);
}
if ('target' in normalizedStep && normalizedStep.target === null) {
delete normalizedStep.target;
}

if ('id' in normalizedStep && typeof normalizedStep.id === 'string') {
const parsed = parseInt(normalizedStep.id, 10);
if (!isNaN(parsed)) {
Expand Down
Loading
Loading