aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-aiassist.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-06-10 06:00:30 +0200
committerAgando <roduccomm@gmail.com>2026-06-10 06:00:30 +0200
commit39b2df36ee5ccea52558d0537bfee87058558e94 (patch)
tree7cac66cf09b128c07fa0300da0a46d016d4459e5 /modules/core/module-aiassist.js
parente8d4985bbb60797936d31b65604a7f94c76bf623 (diff)
auto: 2026-06-10_06:00 changes
Diffstat (limited to 'modules/core/module-aiassist.js')
-rw-r--r--modules/core/module-aiassist.js119
1 files changed, 75 insertions, 44 deletions
diff --git a/modules/core/module-aiassist.js b/modules/core/module-aiassist.js
index ecd4637..3af7f9b 100644
--- a/modules/core/module-aiassist.js
+++ b/modules/core/module-aiassist.js
@@ -44,53 +44,31 @@
}
} catch (e) {}
}
- buildSystemPrompt() {
+buildSystemPrompt() {
+ // Check for user-overridden prompt in localStorage
+ try {
+ const saved = localStorage.getItem('webx11_ai_system_prompt');
+ if (saved) {
+ const now = new Date();
+ const dateStr = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
+ const timeStr = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
+ return `Current date: ${dateStr}\nCurrent time: ${timeStr}\n\n${saved}`;
+ }
+ } catch (e) {}
const now = new Date();
- const dateStr = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
- const timeStr = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
- const optimizationActive = this.terminal?.ollamaManager?.optimizationEnabled !== false;
- // Neural VFS staleness check
+ const dateStr = now.getFullYear() + '-' + String(now.getMonth()+1).padStart(2,'0') + '-' + String(now.getDate()).padStart(2,'0');
+ const nvfs = this.terminal?.moduleManager?.modules?.NeuralVFSModule;
let nvfsNote = '';
try {
- const nvfs = this.terminal?.moduleManager?.modules?.NeuralVFSModule;
if (nvfs && nvfs.lastScan && nvfs.lastScan !== '(loaded from disk)') {
const ageMs = Date.now() - new Date(nvfs.lastScan).getTime();
- if (ageMs > 14400000) { // > 4 hours
- nvfsNote = `\nNote: Neural VFS index is ${Math.floor(ageMs/3600000)}h old. nvfs-resolve results may be stale. Use list_files/read_file directly for live data.`;
- }
+ if (ageMs > 14400000) nvfsNote = ' |nvfs ' + Math.floor(ageMs/3600000) + 'h stale';
}
} catch (e) {}
- return `Current date: ${dateStr}
-Current time: ${timeStr}${nvfsNote}
-
-You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS → Modules → AI. You can edit your own modules via edit_module/test_module/reload_module.
-
-=== WORKFLOW ===
-1. Tool → Observe → Answer. Don't re-verify what a tool just told you.
-2. find_files("about X") → nvfs_resolve(X) FIRST. NVFS is built-in core, never WPM.
-3. load_skills("anti-loop-protocol") BEFORE tool #4 to prevent loops.
-4. If editing a module: load_skills("module-editing-workflow") FIRST.
-5. run_command may be blocked by security-level/guardrails — read the output.
-6. Concise. Bullets. If a tool fails, try another.
-
-=== CAPABILITY MAP ===
-[FS] list_files, read_file, write_file, make_directory, delete_file, get_current_dir
-[NVFS] nvfs_resolve(concept), run_command: nvfs-status, nvfs-index, nvfs-tree. Skills: vfs-content-search, neural-vfs-management.
-[MODULES] view_module, edit_module, test_module, reload_module, list_modified_modules, get_module_status. CORE modules (never WPM): NVFS, Floating, Config, Vault, Sandbox, Orchestrator, Memory-Graph, World-Model, Predictor, Neural-VFS.
-[WPM] wpm_install, wpm_search, list_available_modules
-[SEARCH] web_search, web_fetch
-[AGENTS] delegate_task, list_agents, spawn_agent. A2A: a2a-send, a2a-list. Leases: lease-create, lease-list, lease-revoke.
-[SANDBOX] run_command: sandbox-status, sandbox-run, sandbox-config
-[CONFIG] run_command: config, config-set, ai-config
-[SKILLS] load_skills, create_skill, patch_skill, list_skills
-[PROFILE/SESSION] user_get/set/list/forget, session_save/load/recent/stats/terminal
-[SMART-CTX] smart_context_list, smart_context_set
-[MINDS] create_mindmap
-[SAFETY] run_command: guardrail, guardrail-add/remove, shadow, shadow-commit, shadow-rollback
-[VAULT] run_command: secret-set/get/list/del, secret-setpin, secret-status
-[CHECKPOINTS] run_command: checkpoint, checkpoint-list, checkpoint-del, rollback
-[WEBDAV] run_command: webdav-config/ls/push/pull/backup/restore
-[ALL OTHERS] cron, theme, voice, edit, diff, alias, mindmap, ll, cls, trash, gui, server, modules, ollama, context, world-model, memgraph, model, webxai, predict, predictor-config, memgraph-export, tar, untar, wget`;
+ return 'Current date: ' + dateStr + nvfsNote + '\n'
+ + 'VFS\u2192Modules\u2192AI. nvfs-index for commands. Tool\u2192Observe\u2192Answer. nvfs-resolve. Destructive cmds need confirm.\n'
+ + 'FS: list/read/write/delete | NVFS: nvfs-resolve | Web: search/fetch | Mod: view/edit/test/reload | Config | Skills\n'
+ + 'Other: floating, webdav, cron, vault, sandbox, agents, wpm, mindmap, memgraph, guardrail, wget, tar, secret-* \u2014 discoverable via help';
}
getToolDefinitions() {
if (!this._toolDefs) this._toolDefs = this._buildToolDefs();
@@ -449,7 +427,9 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
'ai-ignore': 'ai-ignore — Suppress validator warnings for this session',
'ai-stop': 'ai-stop — Cancel current AI operation',
'ai-model': 'ai-model [model] — Show or set AI model',
- 'ai-config': 'ai-config [key] [value] — View or set AI loop config (max-turns, max-context, confirm-timeout(0=disabled))'
+ 'ai-config': 'ai-config [key] [value] — View or set AI loop config (max-turns, max-context, confirm-timeout(0=disabled))',
+ 'mem-debug': 'mem-debug — Show memory breakdown by component',
+ 'reset-mem': 'reset-mem — Reset AI memory (logs, patterns) without losing VFS or config'
};
}
registerCommands() {
@@ -472,6 +452,8 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
this.commands['shadow'] = (args) => this.shadowExec(args);
this.commands['shadow-commit'] = () => this.shadowCommit();
this.commands['shadow-rollback'] = () => this.shadowRollback();
+ this.commands['mem-debug'] = () => this.memDebug();
+ this.commands['reset-mem'] = () => this.resetMem();
}
async chat(args) {
const userMessage = args.join(' ');
@@ -735,6 +717,10 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
duration: t1,
error: this._isToolError(toolResult) ? true : false
});
+ // Auto-trim to 50 — prevents unbounded memory growth
+ if (this._toolCallLog.length > 50) {
+ this._toolCallLog = this._toolCallLog.slice(-50);
+ }
// Telemetry
const sm = this.terminal.moduleManager.modules['ServerMonitorModule'];
if (sm && sm.logToolCall) sm.logToolCall(fn.name, (t1 * 1000) || 1, this._isToolError(toolResult));
@@ -801,6 +787,10 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
duration: t1,
error: this._isToolError(toolResult) ? true : false
});
+ // Auto-trim to 50 — prevents unbounded memory growth
+ if (this._toolCallLog.length > 50) {
+ this._toolCallLog = this._toolCallLog.slice(-50);
+ }
// Telemetry
const sm2 = this.terminal.moduleManager.modules['ServerMonitorModule'];
if (sm2 && sm2.logToolCall) sm2.logToolCall(fn.name, (t1 * 1000) || 1, this._isToolError(toolResult));
@@ -1350,7 +1340,10 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
'cal','tree','find','grep','head','tail','sort','wc','du','diff','basename','dirname',
'yes','seq','cut','uniq','expand','printf','base64','help','clear','set','export',
'unalias','history','ll','h','mem','status','df','free','top','ps','health-check',
- 'system-health','modules','listmods','modules-list','get-help-info','alias']);
+ 'system-health','modules','listmods','modules-list','get-help-info','alias',
+ 'nvfs-index','nvfs-status','nvfs-resolve','nvfs-tree','nvfs-config','nvfs-alias','nvfs-sync',
+ 'floating-add','floating-remove','floating-list','floating-pos','floating-clear','floating-toggle',
+ 'mem-debug','reset-mem']);
return !safeRead.has(cmd);
}
return ['write_file','delete_file','make_directory','edit_module'].includes(name);
@@ -1843,6 +1836,7 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
}
} catch (e) {
this._errorLog.push({ tool: name, args: a, error: e.message, timestamp: Date.now() });
+ if (this._errorLog.length > 20) this._errorLog.shift();
return JSON.stringify({ error: e.message, stack: e.stack?.substring(0, 200) });
}
}
@@ -2007,6 +2001,7 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
}
} catch (e) {
this._errorLog.push({ tool: name, args: a, error: e.message, timestamp: Date.now() });
+ if (this._errorLog.length > 20) this._errorLog.shift();
return JSON.stringify({ error: e.message, stack: e.stack?.substring(0, 200) });
}
}
@@ -2049,10 +2044,46 @@ You are WebX11AI — embedded in the WebX11 newOS4 terminal. 3-layer system: VFS
}
setSystemPrompt(args) {
if (!args[0]) {
- this.terminal.print(`Current system prompt: ${this.systemPrompt.substring(0, 50)}...`, 'info'); return;
+ this.terminal.print('=== System Prompt ===', 'info');
+ this.systemPrompt.split('\n').forEach(line => this.terminal.print(line, 'text-muted'));
+ this.terminal.print(`=== End (${this.systemPrompt.length} chars) ===`, 'info');
+ return;
}
this.systemPrompt = args.join(' ');
- this.terminal.print('System prompt updated', 'success');
+ // Persist to localStorage — next page load will use this instead of built-in
+ try { localStorage.setItem('webx11_ai_system_prompt', this.systemPrompt); } catch (e) {}
+ this.terminal.print('System prompt updated (persisted)', 'success');
+ }
+ memDebug() {
+ const toolLogSize = this._toolCallLog.length;
+ const errLogSize = this._errorLog.length;
+ const freqKeys = Object.keys(this._commandFreq).length;
+ const contextSize = this.context.length;
+ const vfsSize = (localStorage.getItem('webx11_filesystem') || '').length +
+ (localStorage.getItem('webx11_filesystem_v2') || '').length;
+ const aiCtxSize = (localStorage.getItem('webx11_ai_context') || '').length;
+ this.terminal.print('=== Memory Debug ===', 'info');
+ this.terminal.print(` _toolCallLog: ${toolLogSize} entries (cap: 50)`, toolLogSize > 30 ? 'warning' : 'text-muted');
+ this.terminal.print(` _errorLog: ${errLogSize} entries (cap: 20)`, errLogSize > 10 ? 'warning' : 'text-muted');
+ this.terminal.print(` _commandFreq: ${freqKeys} tracked patterns`, freqKeys > 15 ? 'warning' : 'text-muted');
+ this.terminal.print(` AI context: ${contextSize} messages (max: ${this.maxContext * 2})`, 'text-muted');
+ this.terminal.print(` VFS localStorage: ${(vfsSize / 1024).toFixed(1)} KB`, 'text-muted');
+ this.terminal.print(` AI context localStorage: ${(aiCtxSize / 1024).toFixed(1)} KB`, 'text-muted');
+ const heap = performance.memory ? performance.memory.usedJSHeapSize : null;
+ if (heap) {
+ this.terminal.print(` JS heap: ${(heap / 1048576).toFixed(1)} MB / ${(performance.memory.jsHeapSizeLimit / 1048576).toFixed(1)} MB`, 'text-muted');
+ }
+ this.terminal.print('Use reset-mem to clear AI internal logs without touching VFS/config', 'info');
+ }
+ resetMem() {
+ this._toolCallLog = [];
+ this._errorLog = [];
+ this._commandFreq = {};
+ this.context = [];
+ localStorage.removeItem('webx11_ai_context');
+ localStorage.removeItem('webx11_ai_patterns');
+ this.terminal.print('AI memory reset: tool logs, error logs, command patterns, and context cleared', 'success');
+ this.terminal.print('VFS, config, skills, system prompt, and floating elements preserved', 'text-muted');
}
showModel(args) {
const om = this.terminal.ollamaManager;