Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Govern AI chat drawer shell ownership

rcourtman99efafac5240
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 3ff18ba967..59f8b6cba7 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -9,7 +9,7 @@
"contract_file": "docs/release-control/v6/internal/subsystems/ai-runtime.md",
"status_file": "docs/release-control/v6/internal/status.json",
"registry_file": "docs/release-control/v6/internal/subsystems/registry.json",
- "dependency_subsystem_ids": ["api-contracts", "frontend-primitives"]
+ "dependency_subsystem_ids": ["api-contracts", "cloud-paid", "frontend-primitives"]
}
```
@@ -39,14 +39,16 @@ runtime cost control, and shared AI transport surfaces.
17. `frontend-modern/src/utils/aiSessionDiffPresentation.ts`
18. `frontend-modern/src/utils/textPresentation.ts`
19. `frontend-modern/src/stores/aiRuntimeState.ts`
+20. `frontend-modern/src/stores/aiChat.ts`
## Shared Boundaries
1. `frontend-modern/src/api/ai.ts` shared with `api-contracts`: the AI frontend client is both an AI runtime control surface and a canonical API payload contract boundary.
2. `frontend-modern/src/api/patrol.ts` shared with `api-contracts`: the Patrol frontend client is both an AI runtime control surface and a canonical API payload contract boundary.
-3. `internal/api/ai_handler.go` shared with `api-contracts`: Pulse Assistant handlers are both an AI runtime control surface and a canonical API payload contract boundary.
-4. `internal/api/ai_handlers.go` shared with `api-contracts`: AI settings and remediation handlers are both an AI runtime control surface and a canonical API payload contract boundary.
-5. `internal/api/ai_intelligence_handlers.go` shared with `api-contracts`: AI intelligence handlers are both an AI runtime control surface and a canonical API payload contract boundary.
+3. `frontend-modern/src/stores/aiChat.ts` shared with `frontend-primitives`: the assistant drawer and session store is both an AI runtime control surface and a canonical app-shell presentation boundary.
+4. `internal/api/ai_handler.go` shared with `api-contracts`: Pulse Assistant handlers are both an AI runtime control surface and a canonical API payload contract boundary.
+5. `internal/api/ai_handlers.go` shared with `api-contracts`: AI settings and remediation handlers are both an AI runtime control surface and a canonical API payload contract boundary.
+6. `internal/api/ai_intelligence_handlers.go` shared with `api-contracts`: AI intelligence handlers are both an AI runtime control surface and a canonical API payload contract boundary.
## Extension Points
@@ -57,6 +59,7 @@ runtime cost control, and shared AI transport surfaces.
5. Add or change AI usage/cost dashboard presentation through `frontend-modern/src/components/AI/AICostDashboard.tsx` and `frontend-modern/src/utils/aiCostPresentation.ts`
6. Add or change AI provider, control-level, chat/session, or explore-state presentation through `frontend-modern/src/components/AI/Chat/`, `frontend-modern/src/utils/aiProviderPresentation.ts`, `frontend-modern/src/utils/aiProviderHealthPresentation.ts`, `frontend-modern/src/utils/aiControlLevelPresentation.ts`, `frontend-modern/src/utils/aiChatPresentation.ts`, `frontend-modern/src/utils/aiSessionDiffPresentation.ts`, and `frontend-modern/src/utils/aiExplorePresentation.ts`
7. Keep AI chat presentation helpers aligned through `frontend-modern/src/components/AI/Chat/` and the shared `frontend-modern/src/utils/textPresentation.ts`
+8. Keep assistant drawer context, session, and org-switch reset state aligned through the shared `frontend-modern/src/stores/aiChat.ts` boundary instead of letting `frontend-modern/src/App.tsx`, `frontend-modern/src/AppLayout.tsx`, or feature callers fork their own assistant shell state
## Forbidden Paths
@@ -194,10 +197,19 @@ reads used by chat, Patrol, and AI usage surfaces, while
`frontend-modern/src/components/Settings/useAISettingsState.ts` remains the
write-side settings owner. AI-owned surfaces must not fork their own mount-time
settings/model fetch loops once this store exists.
+The assistant drawer/session shell is a separate shared boundary:
+`frontend-modern/src/stores/aiChat.ts` owns open state, focused-input handoff,
+context accumulation, and org-switch clearing for the assistant drawer, while
+`frontend-modern/src/stores/aiRuntimeState.ts` owns the shared backend-backed
+settings and model catalog reads. AI runtime consumers must not move drawer
+shell state into page-local signals or teach `aiChat.ts` to bootstrap its own
+`/api/settings/ai` or `/api/ai/models` reads.
`docs/release-control/v6/internal/subsystems/registry.json` must therefore keep
`frontend-modern/src/stores/aiRuntimeState.ts` and
`frontend-modern/src/components/AI/Chat/` on the explicit AI runtime proof
-route instead of leaving the shared read model or chat shell unowned.
+route, and keep `frontend-modern/src/stores/aiChat.ts` on the shared
+AI-runtime/frontend-primitives proof boundary instead of leaving the chat shell
+or assistant drawer state unowned.
That same settings/runtime boundary now also governs BYOK first-run setup:
`frontend-modern/src/components/Settings/useAISettingsState.ts` may send only
provider credentials or base URLs when the operator connects a provider, and
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 1b1066a28d..352d8e5910 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -143,12 +143,14 @@ work extends shared components instead of creating new local variants.
121. `frontend-modern/src/stores/sessionPresentationPolicy.ts`
122. `frontend-modern/src/stores/licenseCommercial.ts`
123. `frontend-modern/src/useAppRuntimeState.ts`
+124. `frontend-modern/src/stores/aiChat.ts`
## Shared Boundaries
1. `frontend-modern/src/components/Settings/GeneralSettingsPanel.tsx` shared with `security-privacy`: the general settings privacy panel is both a security/privacy control surface and a canonical settings-shell presentation boundary.
2. `frontend-modern/src/components/Settings/SecurityAuthPanel.tsx` shared with `security-privacy`: the authentication settings surface is both a security/privacy control surface and a canonical settings-shell presentation boundary.
3. `frontend-modern/src/components/Settings/SecurityOverviewPanel.tsx` shared with `security-privacy`: the security overview settings surface is both a security/privacy control surface and a canonical settings-shell presentation boundary.
+4. `frontend-modern/src/stores/aiChat.ts` shared with `ai-runtime`: the assistant drawer and session store is both an AI runtime control surface and a canonical app-shell presentation boundary.
## Extension Points
@@ -211,13 +213,17 @@ work extends shared components instead of creating new local variants.
15. Keep assistant availability bootstrap on the shared app-shell boundary.
`frontend-modern/src/useAppRuntimeState.ts`,
`frontend-modern/src/App.tsx`,
+ `frontend-modern/src/stores/aiChat.ts`,
`frontend-modern/src/components/AI/Chat/index.tsx`, and
`frontend-modern/src/hooks/useDashboardActions.ts` must consume the
backend-owned `/api/security/status.sessionCapabilities.assistantEnabled`
fact instead of probing `/api/settings/ai` or `/api/ai/*` during ordinary
route bootstrap. Closed assistant chrome and non-AI settings panels may
not initialize assistant runtime state until an owned assistant or Patrol
- surface is actually open.
+ surface is actually open. `frontend-modern/src/stores/aiChat.ts` is the
+ shared drawer shell owner for assistant open/close state, focus handoff,
+ and tenant-local context/session persistence; the app shell must not fork
+ that state across `App.tsx`, `AppLayout.tsx`, or page-level helpers.
AI-owned frontend surfaces that need shared settings or model-catalog
truth must route those reads through
`frontend-modern/src/stores/aiRuntimeState.ts` rather than each feature
@@ -1934,12 +1940,17 @@ customer-facing surfaces.
That same shared app-shell boundary now also owns assistant bootstrap silence
on non-AI routes. `frontend-modern/src/useAppRuntimeState.ts`,
`frontend-modern/src/App.tsx`,
+`frontend-modern/src/stores/aiChat.ts`,
`frontend-modern/src/components/AI/Chat/index.tsx`, and
`frontend-modern/src/hooks/useDashboardActions.ts` must treat
`/api/security/status.sessionCapabilities.assistantEnabled` as the only
general-route assistant availability fact, while closed assistant chrome and
non-AI settings panels stay off `/api/settings/ai` and `/api/ai/*` until an
-owned assistant or Patrol surface is actually open. The governed browser
-proof in `tests/integration/tests/11-first-session.spec.ts` must continue to
-assert that plain settings routes render without assistant bootstrap traffic
-or console noise.
+owned assistant or Patrol surface is actually open. `frontend-modern/src/stores/aiChat.ts`
+must therefore stay presentation-only with respect to assistant bootstrap:
+org-switch cleanup, keyboard focus, drawer state, and local context/session
+persistence belong there, while backend settings/model reads stay on
+`frontend-modern/src/stores/aiRuntimeState.ts`. The governed browser proof in
+`tests/integration/tests/11-first-session.spec.ts` must continue to assert
+that plain settings routes render without assistant bootstrap traffic or
+console noise.
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index e2ac2041e8..b16d0898b0 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -361,6 +361,14 @@
"api-contracts"
]
},
+ {
+ "path": "frontend-modern/src/stores/aiChat.ts",
+ "rationale": "the assistant drawer and session store is both an AI runtime control surface and a canonical app-shell presentation boundary",
+ "subsystems": [
+ "ai-runtime",
+ "frontend-primitives"
+ ]
+ },
{
"path": "frontend-modern/src/utils/agentInstallCommand.ts",
"rationale": "the shared frontend install-command helper is both an agent lifecycle control surface and a canonical API/install transport contract boundary",
@@ -979,6 +987,7 @@
"frontend-modern/src/api/ai.ts",
"frontend-modern/src/api/patrol.ts",
"frontend-modern/src/components/AI/AICostDashboard.tsx",
+ "frontend-modern/src/stores/aiChat.ts",
"frontend-modern/src/stores/aiRuntimeState.ts",
"frontend-modern/src/utils/aiChatPresentation.ts",
"frontend-modern/src/utils/aiControlLevelPresentation.ts",
@@ -1042,6 +1051,7 @@
"frontend-modern/src/components/AI/Chat/"
],
"match_files": [
+ "frontend-modern/src/stores/aiChat.ts",
"frontend-modern/src/stores/aiRuntimeState.ts"
],
"allow_same_subsystem_tests": false,
@@ -1050,6 +1060,7 @@
],
"exact_files": [
"frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx",
+ "frontend-modern/src/stores/__tests__/aiChat.test.ts",
"tests/integration/tests/42-vmware-ai-chat-read-recovery.spec.ts"
]
},
@@ -2599,6 +2610,7 @@
"frontend-modern/src/features/operations/OperationsPageSurface.tsx",
"frontend-modern/src/hooks/createNonSuspendingQuery.ts",
"frontend-modern/src/pages/Operations.tsx",
+ "frontend-modern/src/stores/aiChat.ts",
"frontend-modern/src/utils/aiSettingsPresentation.ts",
"frontend-modern/src/utils/dashboardEmptyStatePresentation.ts",
"frontend-modern/src/utils/dashboardGuestPresentation.ts",
@@ -2808,6 +2820,21 @@
"frontend-modern/src/utils/__tests__/dashboardTrendPresentation.test.ts"
]
},
+ {
+ "id": "assistant-app-shell-bootstrap",
+ "label": "assistant app-shell bootstrap proof",
+ "match_prefixes": [],
+ "match_files": [
+ "frontend-modern/src/stores/aiChat.ts"
+ ],
+ "allow_same_subsystem_tests": false,
+ "test_prefixes": [],
+ "exact_files": [
+ "frontend-modern/src/__tests__/App.architecture.test.ts",
+ "frontend-modern/src/stores/__tests__/aiChat.test.ts",
+ "tests/integration/tests/11-first-session.spec.ts"
+ ]
+ },
{
"id": "shared-feedback-and-column-presentation",
"label": "shared feedback and column presentation proof",
diff --git a/frontend-modern/src/__tests__/App.architecture.test.ts b/frontend-modern/src/__tests__/App.architecture.test.ts
index 53a7327065..48267ded86 100644
--- a/frontend-modern/src/__tests__/App.architecture.test.ts
+++ b/frontend-modern/src/__tests__/App.architecture.test.ts
@@ -8,6 +8,7 @@ describe('App architecture', () => {
it('keeps App as the entry shell that delegates runtime and chrome ownership', () => {
expect(appSource).toContain('DASHBOARD_PATH,');
expect(appSource).toContain("import { AppLayout } from '@/AppLayout';");
+ expect(appSource).toContain("import { aiChatStore } from './stores/aiChat';");
expect(appSource).toContain(
"import { DarkModeContext, WebSocketContext, useWebSocket } from '@/contexts/appRuntime';",
);
@@ -42,10 +43,13 @@ describe('App architecture', () => {
expect(appSource).not.toContain('const [activeOrgID, setActiveOrgID] = createSignal(');
expect(appSource).not.toContain("import('./api/ai')");
expect(appSource).not.toContain('AIAPI.getSettings()');
+ expect(appSource).toContain("if (e.key === 'Escape' && aiChatStore.isOpen) {");
+ expect(appSource).toContain('<AIChat onClose={() => aiChatStore.close()} />');
});
it('keeps authenticated chrome in AppLayout and hosted bootstrap in useAppRuntimeState', () => {
expect(appLayoutSource).toContain('export function AppLayout(props: AppLayoutProps)');
+ expect(appLayoutSource).toContain("import { aiChatStore } from '@/stores/aiChat';");
expect(appLayoutSource).toContain('<OrgSwitcher');
expect(appLayoutSource).toContain('const status = () => props.connectionStatus();');
expect(appLayoutSource).toContain("status().kind === 'sync-reconnecting' || status().kind === 'reconnecting'");
@@ -60,12 +64,17 @@ describe('App architecture', () => {
expect(appLayoutSource).not.toContain('loadCommercialPosture');
expect(appLayoutSource).not.toContain('sessionPresentationPolicyResolved');
expect(appLayoutSource).not.toContain('presentationPolicyHidesCommercialSurfaces');
+ expect(appLayoutSource).toContain(
+ 'aiChatStore.enabled === true && !aiChatStore.isOpenSignal() && !kioskMode()',
+ );
+ expect(appLayoutSource).toContain('onClick={() => aiChatStore.toggle()}');
expect(appSource).not.toContain("eventBus.on('theme_changed'");
expect(appSource).not.toContain("eventBus.on('websocket_reconnected'");
expect(appSource).not.toContain("apiFetch('/api/security/status')");
expect(appLayoutSource).not.toContain("eventBus.on('theme_changed'");
expect(appLayoutSource).not.toContain("apiFetch('/api/security/status')");
expect(appRuntimeStateSource).toContain('export const useAppRuntimeState = () =>');
+ expect(appRuntimeStateSource).toContain("import { aiChatStore } from '@/stores/aiChat';");
expect(appRuntimeStateSource).toContain('const connectionStatus = createMemo<AppConnectionStatus>(() => {');
expect(appRuntimeStateSource).toContain('const beginAuthenticatedRuntime = async () =>');
expect(appRuntimeStateSource).toContain("const [backendHealthy, setBackendHealthy] = createSignal(false);");
diff --git a/frontend-modern/src/stores/__tests__/aiChat.test.ts b/frontend-modern/src/stores/__tests__/aiChat.test.ts
index ee112af06e..5cb2d25914 100644
--- a/frontend-modern/src/stores/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/stores/__tests__/aiChat.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it, beforeEach } from 'vitest';
import { aiChatStore } from '@/stores/aiChat';
+import { eventBus } from '@/stores/events';
describe('aiChatStore', () => {
beforeEach(() => {
@@ -97,4 +98,29 @@ describe('aiChatStore', () => {
textarea.remove();
});
+
+ it('resets assistant drawer session state on org switch', () => {
+ const previousSessionId = aiChatStore.sessionId;
+
+ aiChatStore.open();
+ aiChatStore.addContextItem('vm', 'vm-101', 'vm-101', { name: 'vm-101' });
+ aiChatStore.setMessages([
+ {
+ id: 'msg-1',
+ role: 'user',
+ content: 'hello',
+ timestamp: new Date('2026-04-08T10:00:00.000Z'),
+ },
+ ]);
+ aiChatStore.setTitle('Session title');
+
+ eventBus.emit('org_switched', 'org-2');
+
+ expect(aiChatStore.messages).toHaveLength(0);
+ expect(aiChatStore.contextItems).toHaveLength(0);
+ expect(aiChatStore.context.targetId).toBeUndefined();
+ expect(aiChatStore.title).toBe('');
+ expect(aiChatStore.sessionId).not.toBe(previousSessionId);
+ expect(localStorage.getItem('pulse:ai_chat_session_id')).toBe(aiChatStore.sessionId);
+ });
});
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 1b97f521ac..4812daf2b0 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -4732,7 +4732,7 @@ class SubsystemLookupTest(unittest.TestCase):
),
_contract_reference(
"docs/release-control/v6/internal/subsystems/ai-runtime.md",
- "3. `internal/api/ai_handler.go` shared with `api-contracts`",
+ "4. `internal/api/ai_handler.go` shared with `api-contracts`",
"internal/api/ai_handler.go",
),
_contract_reference(