From abe6cd64666e1fa61cc79ea4392cd78339e581d8 Mon Sep 17 00:00:00 2001 From: Agando Date: Tue, 27 Oct 2026 14:13:35 +0100 Subject: fix(newos4): connect to Ollama on first use, honest write_file, list_files sees /sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three defects, each re-probed first and covered by a test that is red on HEAD. - ollama-manager.js: nothing connects at boot; only the Ollama tab button called connect(), so a user's first message died with "Ollama not connected. Use ollamaconnect first." even when the endpoint was healthy. New _ensureConnected() runs from chat(), chatStream() and chatWithTools(): one attempt, shared by concurrent callers, a "Connecting…" hint, and only then the error — which now says the endpoint is unreachable instead of telling the user to run a command they already expected to work. - module-aiassist.js write_file tool: fs.writeFile()'s false return was dropped and the tool answered "File written: …" anyway, sending the model on to a read that found nothing (MAINT-012). It now returns "Write FAILED: … — parent directory missing or target is a directory; nothing was written". - module-aiassist.js list_files tool: the hand-rolled walk over root.content never resolved the virtual mounts, so /sys — a directory the UI and `ls` both show — answered "Directory not found" (MAINT-011). It now uses fs.readDir(), which resolves mounts and returns null for a genuinely missing path. Tests: modules/test/test-ai-fs-tools.js (7 asserts) and modules/test/test-ollama-autoconnect.js (11 asserts). RED on HEAD: ai tools 4 passed/3 FAILED (/sys → "Directory not found", write_file → "File written: …"), ollama 2 passed/9 FAILED ("Use ollamaconnect first"). GREEN now 7/7 and 11/11; maintain --fix reports "node tests 9/9 pass". Live on v4.6.105: connectedBefore=false, _ensureConnected()=true in 41 ms, 37 models. --- main.html | 6 +- modules/core/core-bundle.js | 92 +++++++++++++++++-------------- modules/core/module-aiassist.js | 54 +++++++----------- modules/core/module-loader.js | 2 +- modules/core/ollama-manager.js | 46 ++++++++++++++-- modules/test/test-ai-fs-tools.js | 74 +++++++++++++++++++++++++ modules/test/test-ollama-autoconnect.js | 98 +++++++++++++++++++++++++++++++++ 7 files changed, 287 insertions(+), 85 deletions(-) create mode 100644 modules/test/test-ai-fs-tools.js create mode 100644 modules/test/test-ollama-autoconnect.js diff --git a/main.html b/main.html index 78f156e..8f20ac2 100644 --- a/main.html +++ b/main.html @@ -1349,13 +1349,13 @@ - + - + - +