@tangle-network/browser-agent-driver 0.37.0 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brain/index.d.ts +3 -5
- package/dist/brain/index.d.ts.map +1 -1
- package/dist/brain/index.js +3 -3
- package/dist/brain/index.js.map +1 -1
- package/dist/brain/tasks/goal-verification.d.ts +29 -9
- package/dist/brain/tasks/goal-verification.d.ts.map +1 -1
- package/dist/brain/tasks/goal-verification.js +112 -41
- package/dist/brain/tasks/goal-verification.js.map +1 -1
- package/dist/domain-policy.d.ts +0 -2
- package/dist/domain-policy.d.ts.map +1 -1
- package/dist/domain-policy.js +0 -37
- package/dist/domain-policy.js.map +1 -1
- package/dist/drivers/cdp-snapshot.d.ts.map +1 -1
- package/dist/drivers/cdp-snapshot.js +42 -6
- package/dist/drivers/cdp-snapshot.js.map +1 -1
- package/dist/drivers/playwright.d.ts +3 -0
- package/dist/drivers/playwright.d.ts.map +1 -1
- package/dist/drivers/playwright.js +56 -54
- package/dist/drivers/playwright.js.map +1 -1
- package/dist/drivers/ref-binding.d.ts +18 -0
- package/dist/drivers/ref-binding.d.ts.map +1 -0
- package/dist/drivers/ref-binding.js +76 -0
- package/dist/drivers/ref-binding.js.map +1 -0
- package/dist/drivers/snapshot.d.ts +32 -0
- package/dist/drivers/snapshot.d.ts.map +1 -1
- package/dist/drivers/snapshot.js +41 -1
- package/dist/drivers/snapshot.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runner/completion-policy.d.ts +0 -31
- package/dist/runner/completion-policy.d.ts.map +1 -1
- package/dist/runner/completion-policy.js +0 -102
- package/dist/runner/completion-policy.js.map +1 -1
- package/dist/runner/deterministic-patterns.js +7 -4
- package/dist/runner/deterministic-patterns.js.map +1 -1
- package/dist/runner/direct-start.d.ts +0 -1
- package/dist/runner/direct-start.d.ts.map +1 -1
- package/dist/runner/direct-start.js +0 -25
- package/dist/runner/direct-start.js.map +1 -1
- package/dist/runner/goal-verification.d.ts +19 -7
- package/dist/runner/goal-verification.d.ts.map +1 -1
- package/dist/runner/goal-verification.js +23 -127
- package/dist/runner/goal-verification.js.map +1 -1
- package/dist/runner/google-flights-preflight.d.ts +1 -2
- package/dist/runner/google-flights-preflight.d.ts.map +1 -1
- package/dist/runner/google-flights-preflight.js +0 -27
- package/dist/runner/google-flights-preflight.js.map +1 -1
- package/dist/runner/index.d.ts +1 -1
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +1 -1
- package/dist/runner/index.js.map +1 -1
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +10 -169
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner.d.ts +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -1
- package/dist/runner.js.map +1 -1
- package/package.json +4 -4
package/dist/runner/runner.js
CHANGED
|
@@ -18,7 +18,6 @@ import { AppKnowledge } from '../memory/knowledge.js';
|
|
|
18
18
|
import { SelectorCache } from '../memory/selectors.js';
|
|
19
19
|
import { detectSupervisorSignal, formatSupervisorSignal } from '../supervisor/policy.js';
|
|
20
20
|
import { requestSupervisorDirective } from '../supervisor/critic.js';
|
|
21
|
-
import { shouldAcceptFirstPartyBoundaryCompletion } from '../domain-policy.js';
|
|
22
21
|
import { deriveWasteMetrics } from '../run-metrics.js';
|
|
23
22
|
import { RunState, DEFAULT_TOKEN_BUDGET } from '../run-state.js';
|
|
24
23
|
import { ContextBudget } from '../context-budget.js';
|
|
@@ -26,7 +25,7 @@ import { runOverridePipeline } from '../override-pipeline.js';
|
|
|
26
25
|
import { withRetry, findElementForRef, safeHostname, pushGoalVerificationEvidence, capFeedbackText, sanitizeRunScript, shouldRejectSurrender } from './utils.js';
|
|
27
26
|
import { runExtractWithIndex, formatExtractWithIndexResult } from '../drivers/extract-with-index.js';
|
|
28
27
|
import { buildSearchResultsGuidance, buildVisibleLinkRecommendation, getVisibleLinkRecommendation } from './search-guidance.js';
|
|
29
|
-
import {
|
|
28
|
+
import { collectPageEvidence, detectCompletionContentTypeMismatch } from './goal-verification.js';
|
|
30
29
|
import { detectAiTanglePartnerTemplateVisibleState, detectAiTangleVerifiedOutputState, shouldEscalateVision } from './page-analysis.js';
|
|
31
30
|
import { buildOverrideProducers, buildScoutLinkRecommendationText, buildBranchLinkRecommendationText } from './overrides.js';
|
|
32
31
|
import { buildSearchResultsScoutFeedbackImpl, buildVisibleLinkScoutRecommendationImpl, buildBranchLinkRecommendationImpl, } from './scout-feedback.js';
|
|
@@ -43,13 +42,13 @@ import { DecisionCache } from './decision-cache.js';
|
|
|
43
42
|
import { VerdictTracker, extractCurrentMarker, buildProgressLabel, } from './overlay-narration.js';
|
|
44
43
|
import { applyDemoOverride } from './demo-overrides.js';
|
|
45
44
|
import { matchDeterministicPattern } from './deterministic-patterns.js';
|
|
46
|
-
import { deriveDirectStartUrl
|
|
47
|
-
import { prepareGoogleFlightsSearch
|
|
45
|
+
import { deriveDirectStartUrl } from './direct-start.js';
|
|
46
|
+
import { prepareGoogleFlightsSearch } from './google-flights-preflight.js';
|
|
48
47
|
import { containsSelfContradictingCompletion } from './completion-language.js';
|
|
49
48
|
import { detectBatchFillOpportunity } from './batch-fill.js';
|
|
50
49
|
import { DEFAULT_MAX_TURNS, DEFAULT_RETRIES, DEFAULT_RETRY_DELAY_MS, DEFAULT_SUPERVISOR, EXTENSION_TURNS_GRANTED, } from './constants.js';
|
|
51
50
|
import { DEFI_BRAIN_CONTEXT } from './prompt-snippets.js';
|
|
52
|
-
import { hasPlaceholderPattern, isMeaningfulRunScriptOutput, synthesizeFinalTurnCompletion
|
|
51
|
+
import { hasPlaceholderPattern, isMeaningfulRunScriptOutput, synthesizeFinalTurnCompletion } from './completion-policy.js';
|
|
53
52
|
import { validateObservedSelector } from './selector-guard.js';
|
|
54
53
|
import { selectMicroPlanFollowUps } from './micro-plan.js';
|
|
55
54
|
import { decideMaxTurnsExtension } from './max-turns-extension.js';
|
|
@@ -1557,83 +1556,19 @@ export class BrowserAgent {
|
|
|
1557
1556
|
// Step 1: Goal verification — did the agent actually achieve the goal?
|
|
1558
1557
|
const shouldVerifyGoal = this.config.goalVerification !== false;
|
|
1559
1558
|
let goalResult;
|
|
1560
|
-
const persistentSearchEvidence = collectSearchWorkflowEvidence(scenario.goal, action.result || '', turns);
|
|
1561
1559
|
const verificationEvidence = [
|
|
1562
1560
|
...runState.goalVerificationEvidence,
|
|
1563
1561
|
...runState.extractedEvidence,
|
|
1564
|
-
...persistentSearchEvidence,
|
|
1565
1562
|
];
|
|
1566
1563
|
if (shouldVerifyGoal) {
|
|
1567
|
-
//
|
|
1568
|
-
//
|
|
1569
|
-
//
|
|
1570
|
-
//
|
|
1571
|
-
//
|
|
1572
|
-
// Content-aware gate: self-contradicting completion text forces
|
|
1573
|
-
// LLM verification instead of using the fast path.
|
|
1564
|
+
// Every completion is judged from page evidence: the final page,
|
|
1565
|
+
// earlier observations, and values the driver read. The agent's
|
|
1566
|
+
// result text is passed as a claim to check, never as evidence;
|
|
1567
|
+
// there is no accept path that skips the page.
|
|
1574
1568
|
const agentResult = action.result || '';
|
|
1575
|
-
const recentErrors = turns.slice(-2).filter(t => t.error).length;
|
|
1576
|
-
const hasScriptEvidence = verificationEvidence.some(e => e.startsWith('SCRIPT RESULT:'));
|
|
1577
|
-
// Detect when the agent's own text admits failure despite
|
|
1578
|
-
// claiming success.
|
|
1579
1569
|
const selfContradicting = containsSelfContradictingCompletion(agentResult);
|
|
1580
|
-
const
|
|
1581
|
-
|
|
1582
|
-
hasScriptEvidence &&
|
|
1583
|
-
!selfContradicting;
|
|
1584
|
-
// Deterministic corroboration: the claimed JSON echoes SCRIPT
|
|
1585
|
-
// RESULT values field-for-field, OR every quoted literal in the
|
|
1586
|
-
// goal appears verbatim in the final observation/evidence —
|
|
1587
|
-
// hallucination is impossible by construction, so skip the
|
|
1588
|
-
// verifier LLM entirely (the wave-1 over-conservatism case:
|
|
1589
|
-
// correct JSON re-prompted 3x).
|
|
1590
|
-
const corroborated = !selfContradicting
|
|
1591
|
-
&& (evidenceCorroboratesResult(agentResult, runState.goalVerificationEvidence)
|
|
1592
|
-
|| goalLiteralsCorroborated(scenario.goal, state.snapshot, runState.goalVerificationEvidence, turns.map((t) => t.state.snapshot),
|
|
1593
|
-
// Form-control state evidence: payloads of actions that
|
|
1594
|
-
// executed without error (driver-confirmed fills/selects).
|
|
1595
|
-
turns
|
|
1596
|
-
.filter((t) => !t.error)
|
|
1597
|
-
.flatMap((t) => [JSON.stringify(t.action), ...(t.executedActions ?? []).map((a) => JSON.stringify(a))])));
|
|
1598
|
-
let verificationPath;
|
|
1599
|
-
if (corroborated) {
|
|
1600
|
-
verificationPath = 'corroborated';
|
|
1601
|
-
goalResult = {
|
|
1602
|
-
achieved: true,
|
|
1603
|
-
confidence: 0.9,
|
|
1604
|
-
evidence: ['Evidence-corroborated: every claimed result field matches a SCRIPT RESULT value exactly.'],
|
|
1605
|
-
missing: [],
|
|
1606
|
-
};
|
|
1607
|
-
if (this.config.debug) {
|
|
1608
|
-
console.log('[Runner] Goal verification: accepted via script-evidence corroboration (no LLM call)');
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
else if (fastPathEligible) {
|
|
1612
|
-
verificationPath = 'fast-path';
|
|
1613
|
-
goalResult = {
|
|
1614
|
-
achieved: true,
|
|
1615
|
-
confidence: 0.9,
|
|
1616
|
-
evidence: ['Fast-path: agent provided detailed result with script-backed evidence, no recent errors, and no self-contradicting language.'],
|
|
1617
|
-
missing: [],
|
|
1618
|
-
};
|
|
1619
|
-
if (this.config.debug) {
|
|
1620
|
-
console.log('[Runner] Goal verification fast-path: skipped LLM call (strong evidence + no errors + no self-contradiction)');
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
else if (selfContradicting) {
|
|
1624
|
-
// Force LLM verification — the agent claims success but its
|
|
1625
|
-
// own text suggests failure. The LLM verifier reads the actual
|
|
1626
|
-
// content and makes the right call.
|
|
1627
|
-
verificationPath = hasScriptEvidence ? 'llm-slim' : 'llm';
|
|
1628
|
-
if (this.config.debug) {
|
|
1629
|
-
console.log('[Runner] Fast-path blocked: agent result contains self-contradicting language, forcing LLM verification');
|
|
1630
|
-
}
|
|
1631
|
-
goalResult = await this.brain.verifyGoalCompletion(state, scenario.goal, buildGoalVerificationClaim(agentResult, verificationEvidence), { skipPageState: hasScriptEvidence });
|
|
1632
|
-
}
|
|
1633
|
-
else {
|
|
1634
|
-
verificationPath = hasScriptEvidence ? 'llm-slim' : 'llm';
|
|
1635
|
-
goalResult = await this.brain.verifyGoalCompletion(state, scenario.goal, buildGoalVerificationClaim(agentResult, verificationEvidence), { skipPageState: hasScriptEvidence });
|
|
1636
|
-
}
|
|
1570
|
+
const verificationPath = 'llm';
|
|
1571
|
+
goalResult = await this.brain.verifyGoalCompletion(state, scenario.goal, agentResult, collectPageEvidence(turns, state, verificationEvidence));
|
|
1637
1572
|
// Record the verifier call's own token usage into run metrics —
|
|
1638
1573
|
// previously invisible in cost accounting (report.json totals and
|
|
1639
1574
|
// events.jsonl). Deterministic paths carry no usage fields.
|
|
@@ -1666,76 +1601,6 @@ export class BrowserAgent {
|
|
|
1666
1601
|
],
|
|
1667
1602
|
};
|
|
1668
1603
|
}
|
|
1669
|
-
if (!goalResult.achieved
|
|
1670
|
-
&& !selfContradicting
|
|
1671
|
-
&& shouldAcceptFirstPartyBoundaryCompletion(scenario.goal, state.url, goalResult, action.result || '')) {
|
|
1672
|
-
goalResult = {
|
|
1673
|
-
...goalResult,
|
|
1674
|
-
achieved: true,
|
|
1675
|
-
confidence: Math.max(goalResult.confidence, 0.8),
|
|
1676
|
-
evidence: [
|
|
1677
|
-
...goalResult.evidence,
|
|
1678
|
-
'Accepted under first-party sibling subdomain policy after substantive result evidence was captured.',
|
|
1679
|
-
],
|
|
1680
|
-
missing: [],
|
|
1681
|
-
};
|
|
1682
|
-
}
|
|
1683
|
-
if (!goalResult.achieved
|
|
1684
|
-
&& !selfContradicting
|
|
1685
|
-
&& shouldAcceptSearchWorkflowCompletion(scenario.goal, goalResult, action.result || '', verificationEvidence)) {
|
|
1686
|
-
goalResult = {
|
|
1687
|
-
...goalResult,
|
|
1688
|
-
achieved: true,
|
|
1689
|
-
confidence: Math.max(goalResult.confidence, 0.82),
|
|
1690
|
-
evidence: [
|
|
1691
|
-
...goalResult.evidence,
|
|
1692
|
-
'Accepted under persisted search-workflow evidence captured from an earlier turn before the agent navigated away.',
|
|
1693
|
-
],
|
|
1694
|
-
missing: [],
|
|
1695
|
-
};
|
|
1696
|
-
}
|
|
1697
|
-
if (!goalResult.achieved
|
|
1698
|
-
&& !selfContradicting
|
|
1699
|
-
&& shouldAcceptScriptBackedCompletion(scenario.goal, state, goalResult, action.result || '', verificationEvidence)) {
|
|
1700
|
-
goalResult = {
|
|
1701
|
-
...goalResult,
|
|
1702
|
-
achieved: true,
|
|
1703
|
-
confidence: Math.max(goalResult.confidence, 0.8),
|
|
1704
|
-
evidence: [
|
|
1705
|
-
...goalResult.evidence,
|
|
1706
|
-
'Accepted under script-backed extraction policy after supplemental tool evidence matched the claimed result.',
|
|
1707
|
-
],
|
|
1708
|
-
missing: [],
|
|
1709
|
-
};
|
|
1710
|
-
}
|
|
1711
|
-
if (!goalResult.achieved
|
|
1712
|
-
&& !selfContradicting
|
|
1713
|
-
&& shouldAcceptRolledBookingCompletion(directStart, goalResult, action.result || '', state)) {
|
|
1714
|
-
goalResult = {
|
|
1715
|
-
...goalResult,
|
|
1716
|
-
achieved: true,
|
|
1717
|
-
confidence: Math.max(goalResult.confidence, 0.82),
|
|
1718
|
-
evidence: [
|
|
1719
|
-
...goalResult.evidence,
|
|
1720
|
-
'Accepted under Booking direct-start date-roll policy: the stale benchmark dates were mapped to equivalent live bookable dates and the completion included concrete Booking evidence.',
|
|
1721
|
-
],
|
|
1722
|
-
missing: [],
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1725
|
-
if (!goalResult.achieved
|
|
1726
|
-
&& !selfContradicting
|
|
1727
|
-
&& shouldAcceptRolledGoogleFlightsCompletion(googleFlightsPreflight, goalResult, action.result || '', state)) {
|
|
1728
|
-
goalResult = {
|
|
1729
|
-
...goalResult,
|
|
1730
|
-
achieved: true,
|
|
1731
|
-
confidence: Math.max(goalResult.confidence, 0.82),
|
|
1732
|
-
evidence: [
|
|
1733
|
-
...goalResult.evidence,
|
|
1734
|
-
'Accepted under Google Flights preflight date-roll policy: stale benchmark flight dates were mapped to equivalent live Google Flights dates and the completion included concrete flight-result evidence.',
|
|
1735
|
-
],
|
|
1736
|
-
missing: [],
|
|
1737
|
-
};
|
|
1738
|
-
}
|
|
1739
1604
|
const contentTypeMismatch = detectCompletionContentTypeMismatch(scenario.goal, state, action.result || '', verificationEvidence);
|
|
1740
1605
|
if (contentTypeMismatch) {
|
|
1741
1606
|
runState.verificationRejectionCount++;
|
|
@@ -1747,30 +1612,6 @@ export class BrowserAgent {
|
|
|
1747
1612
|
this.onTurn?.(turn);
|
|
1748
1613
|
continue;
|
|
1749
1614
|
}
|
|
1750
|
-
if (!goalResult.achieved) {
|
|
1751
|
-
// Progressive acceptance: after prior rejections, accept near-misses
|
|
1752
|
-
// rather than burning turns in verification loops.
|
|
1753
|
-
// Tier A: 1+ rejection + confidence ≥0.55 + supplemental evidence → accept
|
|
1754
|
-
// Tier B: 2+ rejections + confidence ≥0.50 → accept (agent has tried hard enough)
|
|
1755
|
-
// Tier C: 3+ rejections + confidence ≥0.40 → accept (prevent total turn exhaustion)
|
|
1756
|
-
const hasSupplementalEvidence = verificationEvidence.length > 0;
|
|
1757
|
-
const priorRejections = runState.verificationRejectionCount;
|
|
1758
|
-
const shouldAccept = !selfContradicting && ((priorRejections >= 1 && goalResult.confidence >= 0.55 && hasSupplementalEvidence) ||
|
|
1759
|
-
(priorRejections >= 2 && goalResult.confidence >= 0.50) ||
|
|
1760
|
-
(priorRejections >= 3 && goalResult.confidence >= 0.40));
|
|
1761
|
-
if (shouldAccept) {
|
|
1762
|
-
goalResult = {
|
|
1763
|
-
...goalResult,
|
|
1764
|
-
achieved: true,
|
|
1765
|
-
confidence: goalResult.confidence,
|
|
1766
|
-
evidence: [
|
|
1767
|
-
...goalResult.evidence,
|
|
1768
|
-
`Accepted under progressive threshold after ${priorRejections} prior rejection(s)${hasSupplementalEvidence ? ' with supplemental evidence' : ''}.`,
|
|
1769
|
-
],
|
|
1770
|
-
missing: [],
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
1615
|
if (!goalResult.achieved) {
|
|
1775
1616
|
runState.verificationRejectionCount++;
|
|
1776
1617
|
turn.verificationFailure = goalResult.missing.join('; ') || 'Goal verification failed';
|