The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(agent): scrolling the LU browser is not a loop (C59, for P-L's browser tools)
purpledc186d1ac359
diff --git a/src/lib/__tests__/loop-guard-scrolling.test.ts b/src/lib/__tests__/loop-guard-scrolling.test.tsnew file mode 100644index 00000000..1669eb10--- /dev/null+++ b/src/lib/__tests__/loop-guard-scrolling.test.ts@@ -0,0 +1,22 @@+/** browser_scroll (P-L, C53) repeats its arguments by design; only a long scroll streak meets the guard. */+import { describe, it, expect } from 'vitest'+import { AgentLoopGuard } from '../agent-loop-guard'++const scroll = { name: 'browser_scroll', args: '{"direction":"down"}' }++describe('scrolling is not a loop', () => {+ it('nine identical scrolls pass, the tenth steers, the twentieth halts', () => {+ const g = new AgentLoopGuard()+ const v = Array.from({ length: 20 }, () => g.recordBatch([scroll]).action)+ expect(v.slice(0, 9).every((a) => a === 'ok')).toBe(true)+ expect(v[9]).toBe('steer')+ expect(v[19]).toBe('halt')+ })++ it('anything else in between starts the streak again', () => {+ const g = new AgentLoopGuard()+ for (let i = 0; i < 9; i++) g.recordBatch([scroll])+ g.recordBatch([{ name: 'browser_snapshot', args: '{}' }])+ expect(g.recordBatch([scroll]).action).toBe('ok')+ })+})diff --git a/src/lib/agent-loop-guard.ts b/src/lib/agent-loop-guard.tsindex 4684b420..5ff11e70 100644--- a/src/lib/agent-loop-guard.ts+++ b/src/lib/agent-loop-guard.ts@@ -118,6 +118,11 @@ const EXEC_FAIL_HALT_AT = 6const DECLINED_STEER_AT = 3const DECLINED_HALT_AT = 6+/** Scrolling moves the page with the same arguments each time (P-L, C53). */+const SCROLL_TOOLS = new Set<string>(['browser_scroll'])+const SCROLL_STEER_AT = 10+const SCROLL_HALT_AT = 20+/** Tools whose args carry a shell command whose first token names the work. */const EXEC_TOOLS = new Set<string>(['shell_execute', 'shell_execute_background'])@@ -166,6 +171,9 @@ export class AgentLoopGuard {private steeredKeys = new Set<string>()/** Detectors 1, 2, 4 (in a row): the signature that has been warned once. */private consecutiveSteered = false+ /** Batches of nothing but browser_scroll in a row (P-L, C53). */+ private scrollStreak = 0+ private scrollSteered = falseprivate windowSteered = new Set<string>()private narrationRowSteered = falseprivate lastNarration = ''@@ -201,6 +209,26 @@ export class AgentLoopGuard {opts: { trimmedReadKeys?: ReadonlySet<string> } = {},): LoopGuardVerdict {if (!this.enabled || calls.length === 0) return { action: 'ok' }+ // browser_scroll (P-L, C53) repeats its arguments by design: every call+ // moves the page and its answer names the new position. A batch of+ // nothing but scrolls is therefore not a repeat; it gets its own, wider+ // count instead, so a model scrolling forever still meets the guard.+ if (calls.every((c) => SCROLL_TOOLS.has(c.name))) {+ this.scrollStreak+++ if (this.scrollStreak >= SCROLL_HALT_AT) {+ return { action: 'halt', reason: `${this.scrollStreak} scroll steps in a row without reading or doing anything else` }+ }+ if (this.scrollStreak >= SCROLL_STEER_AT && !this.scrollSteered) {+ this.scrollSteered = true+ return {+ action: 'steer',+ message: `You scrolled ${this.scrollStreak} times in a row. Use what the page has shown so far: answer, or open a better page. Scroll on only if the part you need is still below.`,+ }+ }+ return { action: 'ok' }+ }+ this.scrollStreak = 0+ this.scrollSteered = falseconst keys = calls.map((c) => `${c.name}|${c.args}`)const sig = [...keys].sort().join('||')const trimmed = opts.trimmedReadKeys