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.

fix: Codex streaming arg repair + Agent filesystem awareness

PurpleDoubleD1f6d49bddc61
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 15c01ec4..155fb751 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -1,6 +1,7 @@
import { useRef, useState, useCallback } from 'react'
import { v4 as uuid } from 'uuid'
import { chatNonStreaming } from '../api/agents'
+import { setActiveChatId, clearActiveChatId } from '../api/agent-context'
import { useChatStore } from '../stores/chatStore'
import { agentVariantExists, createAgentVariant, getAgentModelName, canFixModel } from '../api/model-template-fix'
import { useModelStore } from '../stores/modelStore'
@@ -260,6 +261,11 @@ export function useAgentChat() {
convId = store.createConversation(activeModel, persona?.systemPrompt || '')
}
+ // Publish the conversation id so built-in tools land in
+ // `~/agent-workspace/<convId>/` — each LU agent chat gets an isolated
+ // workspace folder. Cleared in the finally block further down.
+ setActiveChatId(convId)
+
// Add user message
const userMessage = {
id: uuid(),
@@ -766,6 +772,9 @@ export function useAgentChat() {
setIsAgentRunning(false)
runningRef.current = false
abortRef.current = null
+ // Drop the per-run workspace scope so standalone tool calls from
+ // other tabs don't accidentally land in this chat's folder.
+ clearActiveChatId()
// Reject any pending approvals so their promises don't hang forever
for (const entry of approvalQueueRef.current) entry.resolve(false)
approvalQueueRef.current = []
@@ -819,18 +828,22 @@ export function useAgentChat() {
// ── Agent System Prompt Builder ─────────────────────────────────
function buildAgentSystemPrompt(basePrompt: string): string {
- const agentInstructions = `You are an autonomous AI agent. You MUST use tools — NEVER answer from memory.
-
-IMPORTANT: web_search returns ONLY short snippets, NOT real data. You MUST ALWAYS call web_fetch on the best URL to read the actual page content before answering.
-
-Workflow:
-1. web_search → get URLs
-2. web_fetch → read actual page content from the best URL
-3. Answer based on real data from web_fetch
-
-Other tools: file_read, file_write, code_execute, image_generate.
-Chain multiple tools as needed. If a tool fails, try a different approach.
-Respond in the same language the user uses.`
+ const agentInstructions = `You are an autonomous AI agent inside Locally Uncensored with full access to this computer.
+
+Available tools:
+- Filesystem: file_read, file_write, file_list, file_search
+- Web: web_search, web_fetch
+- System: shell_execute, code_execute, system_info, screenshot, process_list, get_current_time
+- Creative: image_generate, run_workflow
+
+Rules:
+- You MUST use tools — NEVER answer from memory or guess file contents.
+- For filesystem tasks: ALWAYS call file_list first to explore, then file_read to inspect, then act.
+- For web tasks: web_search → web_fetch on the best URL → answer based on real data.
+- web_search returns ONLY short snippets, NOT full content. ALWAYS call web_fetch to read the actual page.
+- If you need to know the OS, paths, or hardware: call system_info once at the start.
+- Chain multiple tools as needed. If a tool fails, try a different approach.
+- Respond in the same language the user uses.`
if (basePrompt) {
return `${agentInstructions}\n\n${basePrompt}`
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index b4511642..0222cc44 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -23,6 +23,7 @@ import { explainError as explainToolError } from '../api/agents/error-hints'
import { budgetFromSettings } from '../api/agents/budget'
import { finalStripThinkingTags } from '../lib/thinking-stripper'
import { ollamaUrl, localFetchStream } from '../api/backend'
+import { repairToolCallArgs } from '../lib/tool-call-repair'
const CODEX_SYSTEM_PROMPT = `You are Codex, an autonomous coding agent inside Locally Uncensored. You execute coding tasks end-to-end by reading files, writing code, and running shell commands. You MUST use tools — never guess file contents.
@@ -142,7 +143,7 @@ async function streamWithTools(
// Ollama may split tool_calls across chunks — append, don't overwrite
if (j.message.tool_calls && Array.isArray(j.message.tool_calls)) {
toolCalls = [...toolCalls, ...j.message.tool_calls.map((tc: any) => ({
- function: { name: tc.function.name, arguments: tc.function.arguments },
+ function: { name: tc.function.name, arguments: repairToolCallArgs(tc.function.arguments) },
}))]
}
}
@@ -156,7 +157,7 @@ async function streamWithTools(
const j = JSON.parse(buf.trim())
if (j.message?.tool_calls && Array.isArray(j.message.tool_calls)) {
toolCalls = [...toolCalls, ...j.message.tool_calls.map((tc: any) => ({
- function: { name: tc.function.name, arguments: tc.function.arguments },
+ function: { name: tc.function.name, arguments: repairToolCallArgs(tc.function.arguments) },
}))]
}
if (j.message?.content) {