From c011c40a42a1ef913ccd6bfd131864be11f9b669 Mon Sep 17 00:00:00 2001 From: Agando Date: Sun, 18 Oct 2026 16:30:46 +0200 Subject: newOS4 v4.6.30: per-agent session isolation (D1) --- modules/core/core-bundle.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'modules/core/core-bundle.js') diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js index ddfad31..6022a37 100644 --- a/modules/core/core-bundle.js +++ b/modules/core/core-bundle.js @@ -8029,6 +8029,7 @@ class ServerMonitorModule { }; this.terminal = null; this.systemPrompt = this.buildSystemPrompt(); this.context = []; this.maxContext = 10; + this._sessions = new Map(); // agentTag -> {context, profile}; 'main' aliases this.context this.maxContextTokens = 2000; this.MAX_TOOL_TURNS = 8; this._pendingConfirmation = null; @@ -8782,6 +8783,13 @@ buildSystemPrompt() { this.commands['vaultmind-query'] = (args) => this._vaultmindQueryCmd(args); this.commands['wallet-lookup'] = (args) => this._walletLookupCmd(args); } + _sessionCtx(tag) { + const k = tag || 'main'; + // main is always the live this.context (commands like `ai-clear`/`load` reassign it) + if (k === 'main') return { context: this.context, profile: null }; + if (!this._sessions.has(k)) this._sessions.set(k, { context: [], profile: null }); + return this._sessions.get(k); + } async chat(args, opts = {}) { const userMessage = args.join(' '); if (!userMessage) { @@ -8816,12 +8824,14 @@ buildSystemPrompt() { this._loadContext(); // Compress context if it exceeds the token threshold this._compressContext(); + // Per-agent session: 'main' aliases this.context, agents get their own history. + const sess = this._sessionCtx(opts.agentTag); let loopResult; try { const messages = [ { role: 'system', content: this.systemPrompt } ]; - this.context.slice().forEach(msg => messages.push(msg)); + sess.context.slice().forEach(msg => messages.push(msg)); messages.push({ role: 'user', content: userMessage }); this.terminal.print('🤖 WebX11AI thinking...', 'info'); // Auto-load skills relevant to the user's query (awaited, not fire-and-forget) @@ -8884,12 +8894,12 @@ buildSystemPrompt() { } catch (e) { /* world model not available */ } loopResult = await this.agenticLoop(messages, opts); - this.context.push({ role: 'user', content: userMessage }); + sess.context.push({ role: 'user', content: userMessage }); if (loopResult.finalAnswer) { - this.context.push({ role: 'assistant', content: loopResult.finalAnswer }); + sess.context.push({ role: 'assistant', content: loopResult.finalAnswer }); } - if (this.context.length > this.maxContext * 2) { - this.context = this.context.slice(-this.maxContext * 2); + if (sess.context.length > this.maxContext * 2) { + sess.context.splice(0, sess.context.length - this.maxContext * 2); } // Reflection: after complex tasks, run health scan and auto-skill creation if (loopResult.toolTurns >= 2 && !this._cancelled) { @@ -15962,7 +15972,9 @@ class OrchestratorModule { try { const aiModule = this.terminal.moduleManager.modules['WebX11AIAssistantModule']; if (aiModule && typeof aiModule.chat === 'function') { - const result = await aiModule.chat([`[DELEGATED] ${task}`], { agentTag: agent.id + '/' + (agent.role || 'worker') }); + const _agentTag = agent.id + '/' + (agent.role || 'worker'); + const result = await aiModule.chat([`[DELEGATED] ${task}`], { agentTag: _agentTag }); + try { aiModule._sessions.delete(_agentTag); } catch (_e) {} agent.status = 'completed'; // Write result to outbox -- cgit v1.2.3