Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: retain activated tool families for the current mind turn (#9854)
Adam Eivy53cd06e955df
diff --git a/server/lib/persistentMindToolActivation.js b/server/lib/persistentMindToolActivation.jsindex 0fdbd05358..c0ca798e21 100644--- a/server/lib/persistentMindToolActivation.js+++ b/server/lib/persistentMindToolActivation.js@@ -93,8 +93,8 @@ export function agePersistentMindToolActivation(leases) {/*** Activate one or more families for a fresh `retentionTurns`-turn window.* `retentionTurns <= 0` persists nothing — the family is still exposed for- * whatever turn calls this (the caller re-reads `leases` afterward), but- * ages away immediately rather than surviving into the next user turn.+ * whatever turn calls this via the adapter's turn-local selection, without+ * surviving into the next user or self-directed turn.*/export function activatePersistentMindToolActivationFamilies(leases, families, retentionTurns) {const normalized = normalizePersistentMindToolActivation({ leases }).leases;diff --git a/server/services/cosToolRegistry.js b/server/services/cosToolRegistry.jsindex 23c2de19dc..5460dbc8a9 100644--- a/server/services/cosToolRegistry.js+++ b/server/services/cosToolRegistry.js@@ -822,7 +822,7 @@ const logToolExposureTrace = (stats) => {*/export const buildPersistentMindToolPrompt = async (capabilities, recipes = [], {turnId = null, isUserTurn = false, trace = false, maxChars = Infinity, requiredToolNames = [],- requestedToolNames = [], onSelection,+ requestedToolNames = [], activatedFamilies = [], onSelection,} = {}) => {const grants = normalizePersistentMindCapabilities(capabilities);const catalog = getCosToolCatalog({ scope: 'mind', capabilities, recipes });@@ -870,7 +870,7 @@ Semantic tool access is OFF. Return an empty toolCalls array. Never invent a too}const requested = new Set(requestedToolNames);- const exposedFamilies = new Set(Object.keys(activation.leases));+ const exposedFamilies = new Set([...Object.keys(activation.leases), ...activatedFamilies]);const controlTools = granted.filter((tool) => ['tools.activate', 'tools.deactivate'].includes(tool.name));const exposedTools = [];const discoverableByFamily = new Map();diff --git a/server/services/persistentMindAdapter.js b/server/services/persistentMindAdapter.jsindex 9649d755fc..7a84c14557 100644--- a/server/services/persistentMindAdapter.js+++ b/server/services/persistentMindAdapter.js@@ -566,13 +566,15 @@ export function createPersistentMindTurnAdapter() {// Set after the first tool round: what a continuation prompt carries.let continuation = null;const requestedToolNames = new Map();+ // Selection lasts for this adapter run independently of persisted leases.+ const activatedFamilies = new Set();const composeRoundPrompt = async (namePrompt) => {// Rebuilds never age the lease or trace (isUserTurn/trace omitted).let exposedToolNames = [];const buildTools = (maxChars) => (continuation? buildPersistentMindToolPrompt(continuation.capabilities, continuation.recipes, {turnId, maxChars, requiredToolNames: continuation.requiredToolNames,- requestedToolNames: [...requestedToolNames.keys()], onSelection: (names) => { exposedToolNames = names; },+ requestedToolNames: [...requestedToolNames.keys()], activatedFamilies: [...activatedFamilies], onSelection: (names) => { exposedToolNames = names; },}): buildPersistentMindToolPrompt(taskAccess, recipeCatalog, { turnId, maxChars }));const annotateActivationResults = () => {@@ -753,12 +755,14 @@ export function createPersistentMindTurnAdapter() {completedToolResults.push(...toolResults);for (const receipt of toolResults) {if (receipt.state === 'completed' && ['tools.activate', 'tools_activate'].includes(receipt.name)) {+ for (const family of receipt.result?.activated || []) activatedFamilies.add(family);for (const name of receipt.result?.requestedToolNames || []) {requestedToolNames.set(name, receipt.result.targetFamilies?.[name]);}}if (receipt.state === 'completed' && ['tools.deactivate', 'tools_deactivate'].includes(receipt.name)) {const deactivated = new Set(receipt.result?.deactivated || []);+ for (const family of deactivated) activatedFamilies.delete(family);for (const [name, family] of requestedToolNames) {if (deactivated.has(family)) requestedToolNames.delete(name);}diff --git a/server/services/persistentMindAdapter.test.js b/server/services/persistentMindAdapter.test.jsindex 913efe134d..e5f4591a64 100644--- a/server/services/persistentMindAdapter.test.js+++ b/server/services/persistentMindAdapter.test.js@@ -1088,3 +1088,52 @@ describe('targeted activation through the public turn adapter', () => {for (const prompt of prompts.slice(1)) expect(prompt.match(/# PortOS semantic tools[\s\S]*?Supply distinct requestId values only when two intentionally identical actions must both run\./)[0].length).toBeLessThanOrEqual(24_000);});});+++describe('family activation through the public turn adapter', () => {+ const namesIn = (prompt) => prompt.includes('Semantic tool access is OFF.') ? [] : JSON.parse(prompt.split('# PortOS semantic tools\n')[1].split('\n\n')[1]).map(({ name }) => name);+ const activate = { name: 'tools.activate', arguments: { families: ['mind'] } };++ it('keeps zero-retention family schemas across continuations but not another user or self turn', async () => {+ mock.realToolExposure = true;+ mock.root.config.persistentMindCapabilities = { manageMind: true, toolExposureRetentionTurns: 0 };+ mock.executeToolCall.mockImplementation((request) => mock.realRegistry.executeCosToolCall(request));+ let round = 0;+ mock.runPrompt.mockImplementation(async ({ prompt }) => {+ const names = namesIn(prompt);+ expect(names).not.toContain('eidoverse.visit');+ expect(names.includes('mind.cleanup')).toBe(round > 0);+ round += 1;+ return { text: JSON.stringify({ message: 'Example response.', toolCalls: round <= 2 ? [{ ...activate, requestId: `activate-${round}` }] : [] }) };+ });+ const adapter = createPersistentMindTurnAdapter();+ await adapter.run({ ...profile, turnId: 'zero-retention', wake: { kind: 'message' }, context: { text: 'Example request.' } });+ expect(round).toBe(3);+ expect(mock.root.persistentMind.toolActivation.leases).toEqual({});+ mock.runPrompt.mockImplementation(async ({ prompt }) => {+ expect(namesIn(prompt)).not.toContain('mind.cleanup');+ return { text: JSON.stringify({ message: 'Example response.', toolCalls: [] }) };+ });+ for (const kind of ['self', 'message']) await adapter.run({ ...profile, turnId: `next-${kind}`, wake: { kind }, context: { text: 'Example next request.' } });+ });++ it.each(['deactivate', 'revoke'])('removes turn-local schemas after %s', async (change) => {+ mock.realToolExposure = true;+ mock.root.config.persistentMindCapabilities = { manageMind: true, toolExposureRetentionTurns: 0 };+ mock.executeToolCall.mockImplementation(async (request) => {+ const receipt = await mock.realRegistry.executeCosToolCall(request);+ if (change === 'revoke' && mock.executeToolCall.mock.calls.length === 2) mock.root.config.persistentMindCapabilities.manageMind = false;+ return receipt;+ });+ let round = 0;+ mock.runPrompt.mockImplementation(async ({ prompt }) => {+ expect(namesIn(prompt).includes('mind.cleanup')).toBe(round === 1);+ round += 1;+ const call = round === 1 ? { ...activate, requestId: 'initial' } : round === 2+ ? { ...(change === 'deactivate' ? { name: 'tools.deactivate', arguments: {} } : activate), requestId: 'change' } : null;+ return { text: JSON.stringify({ message: 'Example response.', toolCalls: call ? [call] : [] }) };+ });+ await createPersistentMindTurnAdapter().run({ ...profile, turnId: `zero-${change}`, wake: { kind: 'self' }, context: { text: 'Example request.' } });+ expect(round).toBe(3);+ });+});