Skip to content

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.

feat(commands): /loop runs unlimited by default, in Agent as well as Code

purple6684e68b3f3f
diff --git a/src/components/chat/ChatView.tsx b/src/components/chat/ChatView.tsx
index 7456f9eb..c26c5a3a 100644
--- a/src/components/chat/ChatView.tsx
+++ b/src/components/chat/ChatView.tsx
@@ -16,6 +16,7 @@ import { FileText, ChevronDown, Download, Wrench, Radio, RefreshCw, X } from 'lu
import { PluginsDropdown } from './PluginsDropdown'
import { ModelSelector } from '../models/ModelSelector'
import { GoalBar } from './GoalBar'
+import { LoopBar } from './LoopBar'
import { MemoryDebugToggle } from './MemoryDebugPanel'
import { TokenCounter } from './TokenCounter'
import { ContextDropdown } from './ContextDropdown'
@@ -339,7 +340,7 @@ export function ChatView() {
slashCommands={isAgentActive}
onAttachDocs={appMode !== 'cloud' ? () => setRagPanelOpen(true) : undefined}
composerModel={<ModelSelector openUpward />}
- composerAbove={<GoalBar />}
+ composerAbove={<><LoopBar onStop={stopGeneration} /><GoalBar /></>}
composerActions={
<>
{/* Documents (RAG) — local-embeddings only, so hide in
diff --git a/src/components/chat/CodexView.tsx b/src/components/chat/CodexView.tsx
index 763a4dce..01d134dd 100644
--- a/src/components/chat/CodexView.tsx
+++ b/src/components/chat/CodexView.tsx
@@ -13,6 +13,7 @@ import { RealtimeCounter } from './RealtimeCounter'
import { PluginsDropdown } from './PluginsDropdown'
import { ModelSelector } from '../models/ModelSelector'
import { GoalBar } from './GoalBar'
+import { LoopBar } from './LoopBar'
import { TypingIndicator } from './TypingIndicator'
import { useSettingsStore } from '../../stores/settingsStore'
import { useModelStore } from '../../stores/modelStore'
@@ -502,7 +503,7 @@ export function CodexView() {
isGenerating={isRunning}
slashCommands
composerModel={<ModelSelector openUpward surface="code" />}
- composerAbove={<GoalBar />}
+ composerAbove={<><LoopBar onStop={stopCodex} /><GoalBar /></>}
composerActions={<PluginsDropdown openUpward />}
/>
</div>
diff --git a/src/components/chat/LoopBar.tsx b/src/components/chat/LoopBar.tsx
new file mode 100644
index 00000000..4326569a
--- /dev/null
+++ b/src/components/chat/LoopBar.tsx
@@ -0,0 +1,55 @@
+// The running /loop, above the composer, with the brake.
+//
+// A loop has no pass ceiling unless the user sets one, so it can genuinely run
+// all night. That is only honest if it is visible the whole time and one click
+// from stopping — an endless job you cannot see is not a feature, it is a bill.
+
+import { useEffect, useState } from 'react'
+import { RefreshCw, Square } from 'lucide-react'
+import { useAgentLoopStore } from '../../stores/agentLoopStore'
+import { useChatStore } from '../../stores/chatStore'
+
+interface Props {
+ /** Stops the run AND the pending pass. */
+ onStop: () => void
+}
+
+export function LoopBar({ onStop }: Props) {
+ const loop = useAgentLoopStore((s) => s.loop)
+ const activeConversationId = useChatStore((s) => s.activeConversationId)
+ // Re-render once a second so the countdown to the next pass actually counts.
+ const [, tick] = useState(0)
+ useEffect(() => {
+ if (!loop) return
+ const t = setInterval(() => tick((n) => n + 1), 1000)
+ return () => clearInterval(t)
+ }, [loop])
+
+ if (!loop || loop.conversationId !== activeConversationId) return null
+
+ const secs = Math.max(0, Math.ceil((loop.nextAt - Date.now()) / 1000))
+ const passLabel = loop.cap > 0 ? `pass ${loop.pass} of ${loop.cap}` : `pass ${loop.pass}`
+
+ return (
+ <div className="w-full max-w-[70%] mx-auto px-3 pb-1 flex justify-center">
+ <div className="w-full flex items-center gap-1.5 px-2 py-1 rounded-md border border-blue-500/25 bg-blue-500/[0.05]">
+ <RefreshCw size={9} className="text-blue-400 shrink-0 animate-spin" style={{ animationDuration: '3s' }} />
+ <span className="text-[0.55rem] uppercase tracking-wider text-gray-500 shrink-0">loop</span>
+ <span className="text-[0.6rem] text-gray-700 dark:text-gray-300 shrink-0">{passLabel}</span>
+ <span className="flex-1 min-w-0 truncate text-[0.6rem] text-gray-500" title={loop.task}>
+ {loop.task}
+ </span>
+ <span className="text-[0.55rem] text-gray-500 shrink-0 tabular-nums">
+ {secs > 0 ? `next in ${secs}s` : 'running'}
+ </span>
+ <button
+ onClick={onStop}
+ title="Stop the loop"
+ className="flex items-center gap-1 px-1.5 py-0.5 rounded text-[0.55rem] text-gray-600 dark:text-gray-300 hover:bg-gray-200/60 dark:hover:bg-white/10 transition-colors shrink-0"
+ >
+ <Square size={7} /> stop
+ </button>
+ </div>
+ </div>
+ )
+}
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index 13893db5..b7108866 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -703,6 +703,26 @@ function CodexAgentSettings() {
/>
</div>
+ {/* /loop — unlimited by default. The stop button and the loop bar above
+ the composer are the brake; a number here is only for people who want
+ a hard stop after N passes. */}
+ <div className="pt-1.5 border-t border-white/[0.04]" />
+ <div className="flex items-center justify-between gap-3 py-1">
+ <div className="min-w-0">
+ <div className="text-[0.7rem] text-gray-700 dark:text-gray-300">Maximum /loop passes</div>
+ <div className="text-[0.6rem] text-gray-500">
+ 0 means unlimited: the loop keeps checking until it reports done or you stop it.
+ </div>
+ </div>
+ <input
+ type="number"
+ min={0}
+ value={settings.loopMaxPasses}
+ onChange={(e) => updateSettings({ loopMaxPasses: Math.max(0, parseInt(e.target.value, 10) || 0) })}
+ className="w-16 shrink-0 px-1.5 py-0.5 rounded border border-gray-200 dark:border-white/10 bg-transparent text-[0.7rem] text-right text-gray-800 dark:text-gray-200"
+ />
+ </div>
+
{/* Stage + Review */}
<div className="pt-1.5 border-t border-white/[0.04]" />
<InlineToggle
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index a0ead42b..a1cf3300 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -40,6 +40,8 @@ import type { AgentBlock, AgentToolCall, OllamaChatMessage } from '../types/agen
import { selectRelevantToolsAsync } from '../lib/tool-selection'
import { MUTATING_TOOLS } from '../lib/mutating-tools'
import { useAgentGoalStore, renderGoalSection } from '../stores/agentGoalStore'
+import { useAgentLoopStore } from '../stores/agentLoopStore'
+import { buildLoopRecheck, loopPassSaysDone } from '../lib/agent-commands'
import { generateEmbeddings } from '../api/rag'
import { truncateToolResult } from '../lib/truncate-tool-result'
import { budgetFromSettings } from '../api/agents/budget'
@@ -97,6 +99,11 @@ export function useAgentChat() {
const [pendingApproval, setPendingApproval] = useState<AgentToolCall | null>(null)
const abortRef = useRef<AbortController | null>(null)
+ /** True once the user pressed stop, so the /loop driver does not start
+ * another pass on the run they just killed. */
+ const userStoppedRef = useRef(false)
+ /** The pending next /loop pass, so stop can cancel it mid-interval. */
+ const loopTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const approvalQueueRef = useRef<ApprovalEntry[]>([])
const contentRef = useRef('')
const thinkingRef = useRef('')
@@ -183,6 +190,8 @@ export function useAgentChat() {
// mutating tools for this turn so the command cannot do what it just
// told the user it would not do.
readOnly?: boolean
+ /** Carried by the /loop driver so a pass knows which pass it is. */
+ loop?: { pass: number; intervalMs: number; task: string; startedAt: number }
// Chat-tools router hint (David 2026-06-20): when a bare follow-up like
// "nochmal"/"ok generiere jetzt" continues an in-progress media task, the
// router passes the task kind + the prior generation's exact args so a weak
@@ -1478,12 +1487,66 @@ export function useAgentChat() {
if (memSettings.autoExtractEnabled && contentRef.current.trim() && convId) {
extractMemories(userContent, contentRef.current, convId).catch(() => {})
}
+
+ // ── /loop driver ───────────────────────────────────────────────────
+ // Same driver as Code, because a loop that only worked in one of the two
+ // agent surfaces is not a feature. No pass ceiling unless the user set
+ // one: a loop someone asked to keep going keeps going until it says done
+ // or they stop it. The loop bar above the composer is what keeps that
+ // honest rather than invisible.
+ if (opts?.loop && convId && !userStoppedRef.current) {
+ const loopState = opts.loop
+ const saidDone = loopPassSaysDone(contentRef.current.trim())
+ const cap = Math.max(0, useSettingsStore.getState().settings.loopMaxPasses ?? 0)
+ const nextPass = loopState.pass + 1
+
+ if (saidDone) {
+ useAgentLoopStore.getState().clear()
+ } else if (cap > 0 && nextPass > cap) {
+ useAgentLoopStore.getState().clear()
+ useChatStore.getState().addMessage(convId, {
+ id: uuid(), role: 'assistant', timestamp: Date.now(),
+ content: `Stopped after ${cap} passes, which is the limit set in Settings. What is above is where it got to. Raise the limit or set it to unlimited to keep going.`,
+ })
+ } else {
+ const convForLoop = convId
+ useAgentLoopStore.getState().start({
+ conversationId: convForLoop, pass: nextPass, cap,
+ task: loopState.task, intervalMs: loopState.intervalMs,
+ nextAt: Date.now() + loopState.intervalMs,
+ })
+ loopTimerRef.current = setTimeout(() => {
+ loopTimerRef.current = null
+ if (runningRef.current) return
+ if (useChatStore.getState().activeConversationId !== convForLoop) {
+ useAgentLoopStore.getState().clear()
+ return
+ }
+ void sendRef.current?.(buildLoopRecheck(loopState.task, nextPass), undefined, {
+ displayContent: cap > 0 ? `pass ${nextPass} of ${cap}` : `pass ${nextPass}`,
+ loop: { ...loopState, pass: nextPass },
+ })
+ }, loopState.intervalMs)
+ }
+ }
}
}, [])
+ // Self-reference so the /loop driver can start the next pass.
+ const sendRef = useRef<typeof sendAgentMessage | null>(null)
+ sendRef.current = sendAgentMessage
+
// ── Stop the agent ────────────────────────────────────────────
const stopAgent = useCallback(() => {
+ // Stop means stop: also cancel a /loop pass waiting out its interval,
+ // otherwise the run the user just killed comes back by itself.
+ userStoppedRef.current = true
+ if (loopTimerRef.current) {
+ clearTimeout(loopTimerRef.current)
+ loopTimerRef.current = null
+ }
+ useAgentLoopStore.getState().clear()
runningRef.current = false
abortRef.current?.abort()
abortRef.current = null
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index 87f92701..2bc17b2e 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -13,7 +13,7 @@ import { getModelContextCached } from "../api/ollama"
import { requestGenerationCancel } from "../api/vram-handoff"
import { effectiveContextWindow } from "../lib/context-window"
import { useAgentChat } from "./useAgentChat"
-import { parseAgentCommand } from '../lib/agent-commands'
+import { parseAgentCommand, parseLoopSpec } from '../lib/agent-commands'
import { applyGoalCommand } from '../lib/goal-command'
import { useMemory } from "./useMemory"
import { useAgentModeStore } from "../stores/agentModeStore"
@@ -87,9 +87,18 @@ export function useChat() {
return
}
if (slash) {
+ // /loop seeds the driver so pass 2 onward fires by itself, exactly as
+ // it does in Code. Nobody should have to re-type a loop.
+ const loop = slash.command.name === 'loop'
+ ? (() => {
+ const { intervalMs, rest } = parseLoopSpec(slash.args)
+ return { pass: 1, intervalMs, task: rest || content, startedAt: Date.now() }
+ })()
+ : undefined
return agentChat.sendAgentMessage(slash.expanded, images, {
displayContent: content,
readOnly: slash.command.readOnly === true,
+ ...(loop ? { loop } : {}),
})
}
return agentChat.sendAgentMessage(content, images)
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index 658b4920..a3ddde38 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -12,6 +12,7 @@ import { toolStrategyFor } from '../lib/tool-support'
import { MUTATING_TOOLS } from '../lib/mutating-tools'
import { applyGoalCommand } from '../lib/goal-command'
import { useAgentGoalStore, renderGoalSection } from '../stores/agentGoalStore'
+import { useAgentLoopStore } from '../stores/agentLoopStore'
import { CODEX_CONFIRM_TOOLS, codexConfirmEnabled } from './codexShellGate'
import { buildHermesToolPrompt, buildHermesToolResult, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'
import { chatNonStreaming } from '../api/agents'
@@ -20,8 +21,8 @@ import { resolveWorkspace } from '../api/agents/workspace-resolve'
import { useAgentModeStore } from '../stores/agentModeStore'
import { loadLurules, renderRulesSection, type RulesReader } from '../lib/lurules'
import {
- parseAgentCommand, parseLoopSpec, buildLoopRecheck, formatDuration,
- MAX_LOOP_PASSES, MAX_LOOP_TOTAL_MS, loopPassSaysDone,
+ parseAgentCommand, parseLoopSpec, buildLoopRecheck,
+ loopPassSaysDone,
} from '../lib/agent-commands'
import { useGenerationStore } from '../stores/generationStore'
import { backendCall, isOllamaLocal } from '../api/backend'
@@ -693,19 +694,6 @@ export function useCodex() {
// backstop. Floor of 1 so a stray 0 setting can't zero the loop.
const MAX_CODEX_ITERATIONS = Math.max(settings.agentMaxIterations ?? 200, 1)
for (let i = 0; i < MAX_CODEX_ITERATIONS && runningRef.current && !abort.signal.aborted; i++) {
- // A loop's TOTAL runtime ceiling, checked between iterations so a run is
- // never cut off inside a file_edit or a shell command. This is the
- // runaway guard across all passes, not a deadline for the work.
- if (loopState && Date.now() - loopState.startedAt > MAX_LOOP_TOTAL_MS && i > 0) {
- const done = fullContent.trim()
- useChatStore.getState().updateMessageContent(
- convId!,
- assistantMsg.id,
- (done ? done + '\n\n' : '') +
- `_(this loop has been running for ${formatDuration(MAX_LOOP_TOTAL_MS)} and stopped there. Nothing was cut off mid-step.)_`,
- )
- break
- }
budget.addIteration()
const bx = budget.exceeded()
if (bx.kind !== 'none') {
@@ -1743,36 +1731,43 @@ export function useCodex() {
// claim. That is the whole value, and it is why the interval is a pause
// between passes rather than a deadline for the task.
//
- // We stop on LOOP_DONE, on the pass cap, on the total-time ceiling, or
- // when the user hits stop (loopTimerRef is cleared there).
+ // It stops on LOOP_DONE, on the user's pass cap if they set one, or when
+ // they hit stop. There is NO built-in ceiling: a loop someone asked to
+ // keep going keeps going (David 2026-07-25). The stop button is the
+ // brake, and the loop bar above the composer makes sure it is never
+ // running invisibly.
if (loopState && convId && !userStoppedRef.current) {
- const answer = fullContent.trim()
- const saidDone = loopPassSaysDone(answer)
- const elapsed = Date.now() - loopState.startedAt
+ const saidDone = loopPassSaysDone(fullContent.trim())
+ const cap = Math.max(0, settings.loopMaxPasses ?? 0)
const nextPass = loopState.pass + 1
if (saidDone) {
// Nothing to do — the marker is stripped from the display by
// cleanCodexText, so the user just sees the answer.
- } else if (nextPass > MAX_LOOP_PASSES) {
+ useAgentLoopStore.getState().clear()
+ } else if (cap > 0 && nextPass > cap) {
+ useAgentLoopStore.getState().clear()
useChatStore.getState().addMessage(convId, {
id: uuid(), role: 'assistant', timestamp: Date.now(),
- content: `Stopped after ${MAX_LOOP_PASSES} passes without a clean finish. What is above is where it got to. Send /loop again to keep going, or take it from here yourself.`,
- })
- } else if (elapsed > MAX_LOOP_TOTAL_MS) {
- useChatStore.getState().addMessage(convId, {
- id: uuid(), role: 'assistant', timestamp: Date.now(),
- content: `Stopped after ${formatDuration(elapsed)} of looping. What is above is where it got to.`,
+ content: `Stopped after ${cap} passes, which is the limit set in Settings. What is above is where it got to. Raise the limit or set it to unlimited to keep going.`,
})
} else {
const convForLoop = convId
+ useAgentLoopStore.getState().start({
+ conversationId: convForLoop, pass: nextPass, cap,
+ task: loopState.task, intervalMs: loopState.intervalMs,
+ nextAt: Date.now() + loopState.intervalMs,
+ })
loopTimerRef.current = setTimeout(() => {
loopTimerRef.current = null
// Bail if the user moved on or started something else meanwhile.
if (runningRef.current) return
- if (useChatStore.getState().activeConversationId !== convForLoop) return
+ if (useChatStore.getState().activeConversationId !== convForLoop) {
+ useAgentLoopStore.getState().clear()
+ return
+ }
void sendRef.current?.(buildLoopRecheck(loopState.task, nextPass), {
- displayContent: `pass ${nextPass} of ${MAX_LOOP_PASSES}`,
+ displayContent: cap > 0 ? `pass ${nextPass} of ${cap}` : `pass ${nextPass}`,
loop: { ...loopState, pass: nextPass },
})
}, loopState.intervalMs)
@@ -1794,6 +1789,7 @@ export function useCodex() {
clearTimeout(loopTimerRef.current)
loopTimerRef.current = null
}
+ useAgentLoopStore.getState().clear()
runningRef.current = false
abortRef.current?.abort()
abortRef.current = null
diff --git a/src/lib/__tests__/agent-commands.test.ts b/src/lib/__tests__/agent-commands.test.ts
index 19933297..081483a0 100644
--- a/src/lib/__tests__/agent-commands.test.ts
+++ b/src/lib/__tests__/agent-commands.test.ts
@@ -9,7 +9,6 @@ import {
formatDuration,
DEFAULT_LOOP_INTERVAL_MS,
MAX_LOOP_INTERVAL_MS,
- MAX_LOOP_PASSES,
LOOP_DONE_MARKER,
LOOP_CONTINUE_MARKER,
loopPassSaysDone,
@@ -248,7 +247,9 @@ describe('/loop interval', () => {
const t = getAgentCommand('loop')!.build('30s make the tests pass')
expect(t).toContain('pass 1 of a LOOP')
expect(t).toContain('bring you back roughly every 30s')
- expect(t).toContain(`up to ${MAX_LOOP_PASSES} passes`)
+ // No pass ceiling is promised, because there is none by default.
+ expect(t).toContain('for as long as it takes')
+ expect(t).not.toMatch(/up to \d+ passes/)
// The exact wording that caused the misread must not come back.
expect(t).not.toContain('You have 30s')
expect(t).not.toMatch(/time is up|budget/i)
diff --git a/src/lib/__tests__/readonly-enforcement.test.ts b/src/lib/__tests__/readonly-enforcement.test.ts
index b22fd0b7..27e2e5c5 100644
--- a/src/lib/__tests__/readonly-enforcement.test.ts
+++ b/src/lib/__tests__/readonly-enforcement.test.ts
@@ -103,11 +103,32 @@ describe('/loop actually loops', () => {
expect(src).toContain('}, loopState.intervalMs)')
})
- it('stops on the done marker, the pass cap and the total ceiling', () => {
+ it('stops on the done marker or on a cap the user set, and NOTHING else', () => {
const src = read('../../hooks/useCodex.ts')
- expect(src).toContain('loopPassSaysDone(answer)')
- expect(src).toContain('nextPass > MAX_LOOP_PASSES')
- expect(src).toContain('elapsed > MAX_LOOP_TOTAL_MS')
+ expect(src).toContain('loopPassSaysDone(')
+ // The cap comes from settings and 0 means unlimited (David 2026-07-25:
+ // "loop darf keine maximal loops erhalten").
+ expect(src).toContain('settings.loopMaxPasses ?? 0')
+ expect(src).toContain('cap > 0 && nextPass > cap')
+ // No built-in ceilings may creep back in.
+ expect(src).not.toContain('MAX_LOOP_PASSES')
+ expect(src).not.toContain('MAX_LOOP_TOTAL_MS')
+ })
+
+ it('runs in Agent mode too, not only in Code', () => {
+ const src = read('../../hooks/useAgentChat.ts')
+ expect(src).toContain('buildLoopRecheck(loopState.task, nextPass)')
+ expect(src).toContain('settings.loopMaxPasses ?? 0')
+ // And the chat router has to seed pass 1, or nothing ever loops there.
+ expect(read('../../hooks/useChat.ts')).toContain("slash.command.name === 'loop'")
+ })
+
+ it('a running loop is visible and stoppable', () => {
+ // Unlimited is only defensible if the user can see it and stop it.
+ for (const f of ['../../hooks/useCodex.ts', '../../hooks/useAgentChat.ts']) {
+ expect(read(f)).toContain('useAgentLoopStore.getState().start(')
+ expect(read(f)).toContain('useAgentLoopStore.getState().clear()')
+ }
})
it('stop cancels a pass that is waiting out its interval', () => {
@@ -120,14 +141,4 @@ describe('/loop actually loops', () => {
expect(stopBody).toContain('userStoppedRef.current = true')
})
- it('the total ceiling is checked between iterations, never mid-tool', () => {
- const src = read('../../hooks/useCodex.ts')
- const loopHead = src.indexOf('for (let i = 0; i < MAX_CODEX_ITERATIONS')
- const ceiling = src.indexOf('MAX_LOOP_TOTAL_MS && i > 0')
- const firstExec = src.indexOf('budget.addToolCalls(')
- expect(ceiling).toBeGreaterThan(loopHead)
- // Cutting a run off inside file_edit or a shell command would leave the
- // workspace in a state nobody asked for.
- expect(ceiling).toBeLessThan(firstExec)
- })
})
diff --git a/src/lib/agent-commands.ts b/src/lib/agent-commands.ts
index 8243e860..76a8d487 100644
--- a/src/lib/agent-commands.ts
+++ b/src/lib/agent-commands.ts
@@ -50,11 +50,6 @@ export interface AgentCommand {
/** Shared closing line so every command nudges the agent to act, not narrate. */
const ACT = 'Use your tools to do this for real — do not just describe the steps. Be concise in text; the work happens in tool calls. Reply in the user\'s language.'
-/** How long the whole loop may run across all passes. A ceiling, not a deadline
- * for the work: a forgotten loop must not bill an afternoon of cloud. */
-export const MAX_LOOP_TOTAL_MS = 4 * 60 * 60 * 1000
-/** How many passes before we stop and hand back. */
-export const MAX_LOOP_PASSES = 10
/** Pause between passes when the user names none. Short, because the value of a
* loop is the re-check, not the waiting. */
export const DEFAULT_LOOP_INTERVAL_MS = 5 * 1000
@@ -173,7 +168,7 @@ export const AGENT_COMMANDS: AgentCommand[] = [
const task = rest || 'the task the user just described'
return `Work on this: ${task}
-This is pass 1 of a LOOP. The app will bring you back roughly every ${formatDuration(intervalMs)} to look at it again, up to ${MAX_LOOP_PASSES} passes, and each time you will be asked to prove what you claimed. So do not rush to a finish and do not pad the answer.
+This is pass 1 of a LOOP. The app will bring you back roughly every ${formatDuration(intervalMs)} to look at it again, for as long as it takes, and each time you will be asked to prove what you claimed. So do not rush to a finish and do not pad the answer. The loop only ends when you say it is done or the user stops it, so a premature finish just wastes everyone's time.
Each pass:
1) Do the next concrete step.
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index e04886df..2d921400 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -40,6 +40,8 @@ export const DEFAULT_SETTINGS: Settings = {
// surfaces in finite wall-clock.
agentMaxToolCalls: 400,
agentMaxIterations: 200,
+ // Unlimited by design — see the note on the type.
+ loopMaxPasses: 0,
hfDownloadPathOverride: '',
// Generation timeouts (Bug P v2.4.7)
imageGenTimeoutMinutes: 20,
diff --git a/src/stores/agentLoopStore.ts b/src/stores/agentLoopStore.ts
new file mode 100644
index 00000000..29ce6e02
--- /dev/null
+++ b/src/stores/agentLoopStore.ts
@@ -0,0 +1,37 @@
+/**
+ * The currently running `/loop`, so it is never invisible.
+ *
+ * A loop has no built-in pass ceiling by design: if someone asks it to keep
+ * going, it keeps going until it says done or they stop it. That is only
+ * defensible if the user can always SEE that a loop is live, which pass it is
+ * on, and stop it in one click. Hence this store and the bar it feeds.
+ *
+ * Runtime only — a loop does not survive a restart, and pretending otherwise
+ * by persisting it would leave a dead loop on screen after a crash.
+ */
+
+import { create } from 'zustand'
+
+export interface ActiveLoop {
+ conversationId: string
+ /** The pass that is about to start. */
+ pass: number
+ /** 0 = unlimited (settings.loopMaxPasses). */
+ cap: number
+ task: string
+ intervalMs: number
+ /** When the next pass fires, for the countdown. */
+ nextAt: number
+}
+
+interface AgentLoopState {
+ loop: ActiveLoop | null
+ start: (loop: ActiveLoop) => void
+ clear: () => void
+}
+
+export const useAgentLoopStore = create<AgentLoopState>((set) => ({
+ loop: null,
+ start: (loop) => set({ loop }),
+ clear: () => set({ loop: null }),
+}))
diff --git a/src/types/settings.ts b/src/types/settings.ts
index f5bbca46..a43a9927 100644
--- a/src/types/settings.ts
+++ b/src/types/settings.ts
@@ -68,6 +68,12 @@ export interface Settings {
agentMaxToolCalls: number
/** Hard cap on ReAct loop iterations per user turn. 0 = unlimited. */
agentMaxIterations: number
+ /**
+ * How many passes a `/loop` may run. 0 = unlimited, which is the default:
+ * a loop the user asked to keep going should keep going until it is done or
+ * they stop it (David 2026-07-25). The stop button is the brake, not a cap.
+ */
+ loopMaxPasses: number
/** Override for the HuggingFace GGUF download directory. Empty = auto-detect from active openai-compat provider (e.g. LM Studio models folder). */
hfDownloadPathOverride: string
// Generation timeouts (Bug P v2.4.7 — ake0n_official Discord 2026-05-19,