diff options
Diffstat (limited to 'modules/core/module-aiassist.js')
| -rw-r--r-- | modules/core/module-aiassist.js | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/modules/core/module-aiassist.js b/modules/core/module-aiassist.js index a9b8fcc..84127d2 100644 --- a/modules/core/module-aiassist.js +++ b/modules/core/module-aiassist.js @@ -5118,9 +5118,45 @@ maxFetchChars: this.maxFetchChars, } }; walk('/'); - data.vfs = { files: fileCount, dirs: dirCount, size: (JSON.stringify(fs.root || {}).length / 1024).toFixed(1) + 'KB' }; + // Stored bytes: the UTF-8 length of each FILE's content, summed. The + // old JSON.stringify(fs.root||{}).length counted UTF-16 code units + // plus the serialisation structure (braces, quotes, keys, commas) — + // ~2x for plain ASCII and wrong the other way for non-ASCII. This is + // the unit `vfs-size` and `doctor` report. + var u8 = function(s) { + if (typeof s !== 'string' || s.length === 0) return 0; + if (typeof Blob !== 'undefined') { try { return new Blob([s]).size; } catch (e) {} } + if (typeof TextEncoder !== 'undefined') { try { return new TextEncoder().encode(s).length; } catch (e) {} } + var n = 0; + for (var j = 0; j < s.length; j++) { + var cp = s.codePointAt(j); + if (cp > 0xffff) j++; // surrogate pair consumed + n += cp < 0x80 ? 1 : cp < 0x800 ? 2 : cp < 0x10000 ? 3 : 4; + } + return n; + }; + var measure = function(node, depth) { + var out = { bytes: 0, files: 0 }; + if (!node || !node.content || depth > 64) return out; + for (var k in node.content) { + if (!Object.prototype.hasOwnProperty.call(node.content, k)) continue; + var c = node.content[k]; + if (!c || typeof c !== 'object') continue; + if (c.type === 'file') { out.bytes += u8(c.content); out.files++; } + else { var sub = measure(c, depth + 1); out.bytes += sub.bytes; out.files += sub.files; } + } + return out; + }; + var vfsB = measure(fs.root, 0); + data.vfs = { + files: fileCount, dirs: dirCount, + sizeBytes: vfsB.bytes, + size: vfsB.bytes < 1024 ? vfsB.bytes + ' B' + : vfsB.bytes < 1048576 ? (vfsB.bytes / 1024).toFixed(1) + ' KB' + : (vfsB.bytes / 1048576).toFixed(2) + ' MB' + }; } - } catch (e) { data.vfs = { files: 0, dirs: 0, size: '0KB' }; } + } catch (e) { data.vfs = { files: 0, dirs: 0, size: '0 B', sizeBytes: 0 }; } // Ollama data.ollama = { @@ -5180,7 +5216,15 @@ maxFetchChars: this.maxFetchChars, data.health = { modules: data.modules.loaded + '/' + data.modules.total, vfsSize: data.vfs ? data.vfs.size : '?', - online: typeof navigator !== 'undefined' ? navigator.onLine : true, + vfsSizeBytes: data.vfs && typeof data.vfs.sizeBytes === 'number' ? data.vfs.sizeBytes : null, + // NO `online` boolean. `navigator.onLine` reports false on a fully + // connected Android WebView, which is how the debug panel and the + // dashboard told working users they were offline. `doctor` owns the only + // reachability verdict; SystemModule exposes no last verdict, so until one + // is probed the honest value is 'unknown'. + network: 'unknown', + networkKnown: false, + networkHint: 'run doctor for a live probe', errors: totalErrors, errorBreakdown: errCounts, predictorAccuracy: predictorAcc |