@gokulvenkatareddy/cortex 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1295 -0
- package/apps/octogent/.github/workflows/ci.yml +40 -0
- package/apps/octogent/.shims/claude +4 -0
- package/apps/octogent/AGENTS.md +71 -0
- package/apps/octogent/CONTRIBUTING.md +72 -0
- package/apps/octogent/LICENSE +21 -0
- package/apps/octogent/README.md +184 -0
- package/apps/octogent/apps/api/AGENTS.md +32 -0
- package/apps/octogent/apps/api/package.json +19 -0
- package/apps/octogent/apps/api/src/agentStateDetection.ts +181 -0
- package/apps/octogent/apps/api/src/claudeSessionScanner.ts +235 -0
- package/apps/octogent/apps/api/src/claudeSkills.ts +182 -0
- package/apps/octogent/apps/api/src/claudeUsage.ts +922 -0
- package/apps/octogent/apps/api/src/cli.ts +595 -0
- package/apps/octogent/apps/api/src/codeIntelStore.ts +46 -0
- package/apps/octogent/apps/api/src/codexUsage.ts +278 -0
- package/apps/octogent/apps/api/src/createApiServer/codeIntelRoutes.ts +60 -0
- package/apps/octogent/apps/api/src/createApiServer/conversationRoutes.ts +128 -0
- package/apps/octogent/apps/api/src/createApiServer/deckRoutes.ts +873 -0
- package/apps/octogent/apps/api/src/createApiServer/gitParsers.ts +140 -0
- package/apps/octogent/apps/api/src/createApiServer/gitRoutes.ts +214 -0
- package/apps/octogent/apps/api/src/createApiServer/miscRoutes.ts +316 -0
- package/apps/octogent/apps/api/src/createApiServer/monitorParsers.ts +137 -0
- package/apps/octogent/apps/api/src/createApiServer/monitorRoutes.ts +95 -0
- package/apps/octogent/apps/api/src/createApiServer/requestHandler.ts +311 -0
- package/apps/octogent/apps/api/src/createApiServer/requestParsers.ts +25 -0
- package/apps/octogent/apps/api/src/createApiServer/routeHelpers.ts +97 -0
- package/apps/octogent/apps/api/src/createApiServer/security.ts +70 -0
- package/apps/octogent/apps/api/src/createApiServer/terminalParsers.ts +167 -0
- package/apps/octogent/apps/api/src/createApiServer/terminalRoutes.ts +315 -0
- package/apps/octogent/apps/api/src/createApiServer/types.ts +24 -0
- package/apps/octogent/apps/api/src/createApiServer/uiStateParsers.ts +255 -0
- package/apps/octogent/apps/api/src/createApiServer/upgradeHandler.ts +38 -0
- package/apps/octogent/apps/api/src/createApiServer/usageRoutes.ts +84 -0
- package/apps/octogent/apps/api/src/createApiServer.ts +176 -0
- package/apps/octogent/apps/api/src/deck/readDeckTentacles.ts +595 -0
- package/apps/octogent/apps/api/src/githubRepoSummary.ts +397 -0
- package/apps/octogent/apps/api/src/logging.ts +9 -0
- package/apps/octogent/apps/api/src/monitor/defaults.ts +3 -0
- package/apps/octogent/apps/api/src/monitor/index.ts +8 -0
- package/apps/octogent/apps/api/src/monitor/repository.ts +303 -0
- package/apps/octogent/apps/api/src/monitor/service.ts +349 -0
- package/apps/octogent/apps/api/src/monitor/types.ts +120 -0
- package/apps/octogent/apps/api/src/monitor/xProvider.ts +587 -0
- package/apps/octogent/apps/api/src/projectPersistence.ts +377 -0
- package/apps/octogent/apps/api/src/prompts/index.ts +10 -0
- package/apps/octogent/apps/api/src/prompts/promptResolver.ts +145 -0
- package/apps/octogent/apps/api/src/runtimeMetadata.ts +69 -0
- package/apps/octogent/apps/api/src/server.ts +80 -0
- package/apps/octogent/apps/api/src/setupState.ts +80 -0
- package/apps/octogent/apps/api/src/setupStatus.ts +174 -0
- package/apps/octogent/apps/api/src/startupPrerequisites.ts +146 -0
- package/apps/octogent/apps/api/src/terminalRuntime/channelMessaging.ts +87 -0
- package/apps/octogent/apps/api/src/terminalRuntime/claudeTranscript.ts +279 -0
- package/apps/octogent/apps/api/src/terminalRuntime/constants.ts +15 -0
- package/apps/octogent/apps/api/src/terminalRuntime/conversations.ts +492 -0
- package/apps/octogent/apps/api/src/terminalRuntime/gitOperations.ts +341 -0
- package/apps/octogent/apps/api/src/terminalRuntime/hookProcessor.ts +405 -0
- package/apps/octogent/apps/api/src/terminalRuntime/protocol.ts +46 -0
- package/apps/octogent/apps/api/src/terminalRuntime/ptyEnvironment.ts +50 -0
- package/apps/octogent/apps/api/src/terminalRuntime/registry.ts +423 -0
- package/apps/octogent/apps/api/src/terminalRuntime/sessionRuntime.ts +671 -0
- package/apps/octogent/apps/api/src/terminalRuntime/systemClients.ts +432 -0
- package/apps/octogent/apps/api/src/terminalRuntime/types.ts +157 -0
- package/apps/octogent/apps/api/src/terminalRuntime/worktreeManager.ts +135 -0
- package/apps/octogent/apps/api/src/terminalRuntime.ts +567 -0
- package/apps/octogent/apps/api/src/usageUtils.ts +16 -0
- package/apps/octogent/apps/api/src/ws-shim.d.ts +28 -0
- package/apps/octogent/apps/api/tests/agentStateDetection.test.ts +67 -0
- package/apps/octogent/apps/api/tests/claudeUsage.test.ts +583 -0
- package/apps/octogent/apps/api/tests/codexUsage.test.ts +107 -0
- package/apps/octogent/apps/api/tests/createApiServer.test.ts +3207 -0
- package/apps/octogent/apps/api/tests/githubRepoSummary.test.ts +100 -0
- package/apps/octogent/apps/api/tests/logging.test.ts +33 -0
- package/apps/octogent/apps/api/tests/monitorApi.test.ts +467 -0
- package/apps/octogent/apps/api/tests/monitorCore.test.ts +104 -0
- package/apps/octogent/apps/api/tests/promptResolver.test.ts +109 -0
- package/apps/octogent/apps/api/tests/protocol.test.ts +14 -0
- package/apps/octogent/apps/api/tests/sessionRuntime.test.ts +608 -0
- package/apps/octogent/apps/api/tests/startupPrerequisites.test.ts +70 -0
- package/apps/octogent/apps/api/tests/upgradeHandler.test.ts +40 -0
- package/apps/octogent/apps/api/tests/xMonitorProvider.test.ts +109 -0
- package/apps/octogent/apps/api/tsconfig.json +7 -0
- package/apps/octogent/apps/api/vitest.config.ts +7 -0
- package/apps/octogent/apps/web/AGENTS.md +38 -0
- package/apps/octogent/apps/web/index.html +13 -0
- package/apps/octogent/apps/web/package.json +32 -0
- package/apps/octogent/apps/web/public/octopus-favicon.svg +26 -0
- package/apps/octogent/apps/web/src/App.tsx +646 -0
- package/apps/octogent/apps/web/src/app/canvas/types.ts +34 -0
- package/apps/octogent/apps/web/src/app/codeIntelAggregation.ts +278 -0
- package/apps/octogent/apps/web/src/app/constants.ts +28 -0
- package/apps/octogent/apps/web/src/app/conversationNormalizers.ts +135 -0
- package/apps/octogent/apps/web/src/app/formatTimestamp.ts +18 -0
- package/apps/octogent/apps/web/src/app/githubMetrics.ts +76 -0
- package/apps/octogent/apps/web/src/app/githubNormalizers.ts +91 -0
- package/apps/octogent/apps/web/src/app/hooks/useAgentRuntimeStates.ts +18 -0
- package/apps/octogent/apps/web/src/app/hooks/useBackendLivenessPolling.ts +53 -0
- package/apps/octogent/apps/web/src/app/hooks/useCanvasGraphData.ts +449 -0
- package/apps/octogent/apps/web/src/app/hooks/useCanvasTransform.ts +260 -0
- package/apps/octogent/apps/web/src/app/hooks/useClaudeUsagePolling.ts +40 -0
- package/apps/octogent/apps/web/src/app/hooks/useClickOutside.ts +30 -0
- package/apps/octogent/apps/web/src/app/hooks/useCodeIntelRuntime.ts +83 -0
- package/apps/octogent/apps/web/src/app/hooks/useCodexUsagePolling.ts +35 -0
- package/apps/octogent/apps/web/src/app/hooks/useConsoleKeyboardShortcuts.ts +31 -0
- package/apps/octogent/apps/web/src/app/hooks/useConversationsRuntime.ts +377 -0
- package/apps/octogent/apps/web/src/app/hooks/useForceSimulation.ts +319 -0
- package/apps/octogent/apps/web/src/app/hooks/useGitHubPrimaryViewModel.ts +143 -0
- package/apps/octogent/apps/web/src/app/hooks/useGithubSummaryPolling.ts +28 -0
- package/apps/octogent/apps/web/src/app/hooks/useInitialColumnsHydration.ts +64 -0
- package/apps/octogent/apps/web/src/app/hooks/useMonitorRuntime.ts +220 -0
- package/apps/octogent/apps/web/src/app/hooks/usePersistedUiState.ts +536 -0
- package/apps/octogent/apps/web/src/app/hooks/usePollingData.ts +79 -0
- package/apps/octogent/apps/web/src/app/hooks/usePromptLibrary.ts +185 -0
- package/apps/octogent/apps/web/src/app/hooks/useTentacleGitLifecycle.ts +530 -0
- package/apps/octogent/apps/web/src/app/hooks/useTerminalCompletionNotification.ts +94 -0
- package/apps/octogent/apps/web/src/app/hooks/useTerminalMutations.ts +266 -0
- package/apps/octogent/apps/web/src/app/hooks/useTerminalStateReconciliation.ts +23 -0
- package/apps/octogent/apps/web/src/app/hooks/useUsageHeatmapPolling.ts +43 -0
- package/apps/octogent/apps/web/src/app/hooks/useWorkspaceSetup.ts +80 -0
- package/apps/octogent/apps/web/src/app/hotkeys.ts +31 -0
- package/apps/octogent/apps/web/src/app/monitorNormalizers.ts +145 -0
- package/apps/octogent/apps/web/src/app/notificationSounds.ts +164 -0
- package/apps/octogent/apps/web/src/app/terminalRuntimeStateStore.ts +261 -0
- package/apps/octogent/apps/web/src/app/terminalState.ts +21 -0
- package/apps/octogent/apps/web/src/app/types.ts +42 -0
- package/apps/octogent/apps/web/src/app/uiStateNormalizers.ts +113 -0
- package/apps/octogent/apps/web/src/app/usageNormalizers.ts +58 -0
- package/apps/octogent/apps/web/src/components/ActiveAgentsSidebar.tsx +60 -0
- package/apps/octogent/apps/web/src/components/ActivityPrimaryView.tsx +21 -0
- package/apps/octogent/apps/web/src/components/AgentStateBadge.tsx +47 -0
- package/apps/octogent/apps/web/src/components/CanvasPrimaryView.tsx +1532 -0
- package/apps/octogent/apps/web/src/components/ClearAllConversationsDialog.tsx +33 -0
- package/apps/octogent/apps/web/src/components/CodeIntelArcDiagram.tsx +245 -0
- package/apps/octogent/apps/web/src/components/CodeIntelPrimaryView.tsx +104 -0
- package/apps/octogent/apps/web/src/components/CodeIntelTreemap.tsx +138 -0
- package/apps/octogent/apps/web/src/components/ConsolePrimaryNav.tsx +31 -0
- package/apps/octogent/apps/web/src/components/ConversationsPrimaryView.tsx +243 -0
- package/apps/octogent/apps/web/src/components/DeckPrimaryView.tsx +613 -0
- package/apps/octogent/apps/web/src/components/DeleteTentacleDialog.tsx +91 -0
- package/apps/octogent/apps/web/src/components/EmptyOctopus.tsx +715 -0
- package/apps/octogent/apps/web/src/components/GitHubPrimaryView.tsx +494 -0
- package/apps/octogent/apps/web/src/components/MonitorPrimaryView.tsx +475 -0
- package/apps/octogent/apps/web/src/components/PrimaryViewRouter.tsx +99 -0
- package/apps/octogent/apps/web/src/components/PromptsPrimaryView.tsx +243 -0
- package/apps/octogent/apps/web/src/components/RuntimeStatusStrip.tsx +273 -0
- package/apps/octogent/apps/web/src/components/SettingsPrimaryView.tsx +92 -0
- package/apps/octogent/apps/web/src/components/SidebarActionPanel.tsx +124 -0
- package/apps/octogent/apps/web/src/components/SidebarConversationsList.tsx +279 -0
- package/apps/octogent/apps/web/src/components/SidebarPromptsList.tsx +116 -0
- package/apps/octogent/apps/web/src/components/TelemetryTape.tsx +106 -0
- package/apps/octogent/apps/web/src/components/TentacleGitActionsDialog.tsx +341 -0
- package/apps/octogent/apps/web/src/components/Terminal.tsx +524 -0
- package/apps/octogent/apps/web/src/components/TerminalPromptPicker.tsx +140 -0
- package/apps/octogent/apps/web/src/components/UsageHeatmap.tsx +702 -0
- package/apps/octogent/apps/web/src/components/canvas/CanvasTentaclePanel.tsx +485 -0
- package/apps/octogent/apps/web/src/components/canvas/CanvasTerminalColumn.tsx +89 -0
- package/apps/octogent/apps/web/src/components/canvas/DeleteAllTerminalsDialog.tsx +221 -0
- package/apps/octogent/apps/web/src/components/canvas/OctopusNode.tsx +307 -0
- package/apps/octogent/apps/web/src/components/canvas/SessionNode.tsx +185 -0
- package/apps/octogent/apps/web/src/components/deck/ActionCards.tsx +118 -0
- package/apps/octogent/apps/web/src/components/deck/AddTentacleForm.tsx +269 -0
- package/apps/octogent/apps/web/src/components/deck/DeckBottomActions.tsx +56 -0
- package/apps/octogent/apps/web/src/components/deck/TentaclePod.tsx +334 -0
- package/apps/octogent/apps/web/src/components/deck/WorkspaceSetupCard.tsx +105 -0
- package/apps/octogent/apps/web/src/components/deck/octopusVisuals.ts +72 -0
- package/apps/octogent/apps/web/src/components/terminalReplay.ts +62 -0
- package/apps/octogent/apps/web/src/components/terminalWheel.ts +54 -0
- package/apps/octogent/apps/web/src/components/ui/ActionButton.tsx +34 -0
- package/apps/octogent/apps/web/src/components/ui/ConfirmationDialog.tsx +86 -0
- package/apps/octogent/apps/web/src/components/ui/MarkdownContent.tsx +43 -0
- package/apps/octogent/apps/web/src/components/ui/SettingsToggle.tsx +34 -0
- package/apps/octogent/apps/web/src/components/ui/StatusBadge.tsx +24 -0
- package/apps/octogent/apps/web/src/main.tsx +17 -0
- package/apps/octogent/apps/web/src/runtime/HttpTerminalSnapshotReader.ts +87 -0
- package/apps/octogent/apps/web/src/runtime/runtimeEndpoints.ts +412 -0
- package/apps/octogent/apps/web/src/styles/chrome-and-buttons.css +272 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-activity.css +358 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-canvas.css +1843 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-code-intel.css +227 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-conversations.css +705 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-deck.css +1524 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-github.css +541 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-monitor.css +595 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-pixpack.css +81 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-prompts.css +474 -0
- package/apps/octogent/apps/web/src/styles/console-canvas-settings.css +207 -0
- package/apps/octogent/apps/web/src/styles/console-chrome-status-nav.css +441 -0
- package/apps/octogent/apps/web/src/styles/console-overrides-telemetry.css +320 -0
- package/apps/octogent/apps/web/src/styles/console-theme-tokens.css +25 -0
- package/apps/octogent/apps/web/src/styles/cortex-theme.css +412 -0
- package/apps/octogent/apps/web/src/styles/foundation.css +100 -0
- package/apps/octogent/apps/web/src/styles/sidebar-and-scrollbars.css +447 -0
- package/apps/octogent/apps/web/src/styles/terminal-and-status.css +356 -0
- package/apps/octogent/apps/web/src/styles.css +25 -0
- package/apps/octogent/apps/web/src/types/ws.d.ts +23 -0
- package/apps/octogent/apps/web/tests/CanvasPrimaryView.test.tsx +347 -0
- package/apps/octogent/apps/web/tests/HttpTerminalSnapshotReader.test.tsx +54 -0
- package/apps/octogent/apps/web/tests/RuntimeStatusStrip.test.tsx +70 -0
- package/apps/octogent/apps/web/tests/Terminal.test.tsx +87 -0
- package/apps/octogent/apps/web/tests/add-tentacle-form.test.tsx +48 -0
- package/apps/octogent/apps/web/tests/app-github-runtime.test.tsx +162 -0
- package/apps/octogent/apps/web/tests/app-monitor-runtime.test.tsx +657 -0
- package/apps/octogent/apps/web/tests/app-shell-navigation.test.tsx +109 -0
- package/apps/octogent/apps/web/tests/app-swarm-refresh.test.tsx +268 -0
- package/apps/octogent/apps/web/tests/app-ui-state-persistence.test.tsx +116 -0
- package/apps/octogent/apps/web/tests/app-workspace-setup.test.tsx +217 -0
- package/apps/octogent/apps/web/tests/canvas-tentacle-panel.test.tsx +195 -0
- package/apps/octogent/apps/web/tests/delete-all-terminals-dialog.test.tsx +76 -0
- package/apps/octogent/apps/web/tests/githubMetrics.test.tsx +52 -0
- package/apps/octogent/apps/web/tests/hotkeys.test.tsx +44 -0
- package/apps/octogent/apps/web/tests/runtimeEndpoints.test.tsx +240 -0
- package/apps/octogent/apps/web/tests/setup.ts +39 -0
- package/apps/octogent/apps/web/tests/tentacle-pod.test.tsx +62 -0
- package/apps/octogent/apps/web/tests/terminalReplay.test.ts +71 -0
- package/apps/octogent/apps/web/tests/terminalState.test.tsx +49 -0
- package/apps/octogent/apps/web/tests/terminalWheel.test.tsx +51 -0
- package/apps/octogent/apps/web/tests/test-utils/appTestHarness.ts +48 -0
- package/apps/octogent/apps/web/tests/uiPrimitives.test.tsx +31 -0
- package/apps/octogent/apps/web/tests/useAgentRuntimeStates.test.tsx +47 -0
- package/apps/octogent/apps/web/tsconfig.json +8 -0
- package/apps/octogent/apps/web/vite.api.bundle.config.mts +32 -0
- package/apps/octogent/apps/web/vite.config.ts +22 -0
- package/apps/octogent/bin/octogent +3 -0
- package/apps/octogent/biome.json +21 -0
- package/apps/octogent/docs/concepts/mental-model.md +79 -0
- package/apps/octogent/docs/concepts/runtime-and-api.md +60 -0
- package/apps/octogent/docs/concepts/tentacles.md +85 -0
- package/apps/octogent/docs/getting-started/installation.md +54 -0
- package/apps/octogent/docs/getting-started/quickstart.md +79 -0
- package/apps/octogent/docs/guides/inter-agent-messaging.md +43 -0
- package/apps/octogent/docs/guides/orchestrating-child-agents.md +49 -0
- package/apps/octogent/docs/guides/working-with-todos.md +56 -0
- package/apps/octogent/docs/index.md +40 -0
- package/apps/octogent/docs/reference/api.md +103 -0
- package/apps/octogent/docs/reference/cli.md +71 -0
- package/apps/octogent/docs/reference/experimental-features.md +28 -0
- package/apps/octogent/docs/reference/filesystem-layout.md +62 -0
- package/apps/octogent/docs/reference/troubleshooting.md +49 -0
- package/apps/octogent/package.json +35 -0
- package/apps/octogent/packages/core/AGENTS.md +31 -0
- package/apps/octogent/packages/core/package.json +12 -0
- package/apps/octogent/packages/core/src/adapters/InMemoryTerminalSnapshotReader.ts +10 -0
- package/apps/octogent/packages/core/src/application/buildTerminalList.ts +13 -0
- package/apps/octogent/packages/core/src/domain/agentRuntime.ts +18 -0
- package/apps/octogent/packages/core/src/domain/channel.ts +8 -0
- package/apps/octogent/packages/core/src/domain/completionSound.ts +14 -0
- package/apps/octogent/packages/core/src/domain/conversation.ts +48 -0
- package/apps/octogent/packages/core/src/domain/deck.ts +33 -0
- package/apps/octogent/packages/core/src/domain/git.ts +32 -0
- package/apps/octogent/packages/core/src/domain/monitor.ts +62 -0
- package/apps/octogent/packages/core/src/domain/setup.ts +27 -0
- package/apps/octogent/packages/core/src/domain/terminal.ts +17 -0
- package/apps/octogent/packages/core/src/domain/uiState.ts +22 -0
- package/apps/octogent/packages/core/src/domain/usage.ts +60 -0
- package/apps/octogent/packages/core/src/index.ts +15 -0
- package/apps/octogent/packages/core/src/ports/TerminalSnapshotReader.ts +5 -0
- package/apps/octogent/packages/core/src/util/typeCoercion.ts +20 -0
- package/apps/octogent/packages/core/tests/buildTerminalList.test.ts +75 -0
- package/apps/octogent/packages/core/tsconfig.json +7 -0
- package/apps/octogent/packages/core/tsconfig.tsbuildinfo +1 -0
- package/apps/octogent/packages/core/vitest.config.ts +7 -0
- package/apps/octogent/pnpm-lock.yaml +3212 -0
- package/apps/octogent/pnpm-workspace.yaml +3 -0
- package/apps/octogent/prompts/meta-prompt-generator.md +223 -0
- package/apps/octogent/prompts/octoboss-clean-contexts.md +30 -0
- package/apps/octogent/prompts/octoboss-reorganize-tentacles.md +29 -0
- package/apps/octogent/prompts/octoboss-reorganize-todos.md +27 -0
- package/apps/octogent/prompts/sandbox-init.md +3 -0
- package/apps/octogent/prompts/swarm-parent.md +83 -0
- package/apps/octogent/prompts/swarm-worker.md +50 -0
- package/apps/octogent/prompts/tentacle-context-init.md +1 -0
- package/apps/octogent/prompts/tentacle-planner.md +110 -0
- package/apps/octogent/prompts/tentacle-reorganize-todos.md +20 -0
- package/apps/octogent/prompts/tentacle-update-tentacle.md +18 -0
- package/apps/octogent/scripts/build-package.mjs +23 -0
- package/apps/octogent/scripts/dev.mjs +158 -0
- package/apps/octogent/scripts/smoke-public-install.mjs +271 -0
- package/apps/octogent/static/images/octogent-header.png +0 -0
- package/apps/octogent/static/images/preview_1.jpg +0 -0
- package/apps/octogent/static/images/preview_2.jpg +0 -0
- package/apps/octogent/static/images/preview_3.jpg +0 -0
- package/apps/octogent/static/images/preview_4.jpg +0 -0
- package/apps/octogent/static/images/preview_5.jpg +0 -0
- package/apps/octogent/static/images/preview_6.jpg +0 -0
- package/apps/octogent/tsconfig.base.json +16 -0
- package/bin/AGI +3 -0
- package/bin/AGI-install-app +71 -0
- package/bin/AGI-ui +16 -0
- package/bin/AGI-voice +15 -0
- package/bin/AGI-web +16 -0
- package/bin/cortex +109 -0
- package/bin/cortex-octogent +99 -0
- package/bin/import-specifier.mjs +13 -0
- package/bin/import-specifier.test.mjs +13 -0
- package/bin/octo +150 -0
- package/dist/cli.mjs +555650 -0
- package/package.json +157 -0
- package/scripts/setup-wizard.ts +390 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import type { Dispatch, SetStateAction } from "react";
|
|
3
|
+
|
|
4
|
+
import { buildUiStateUrl } from "../../runtime/runtimeEndpoints";
|
|
5
|
+
import type { PrimaryNavIndex } from "../constants";
|
|
6
|
+
import { MIN_SIDEBAR_WIDTH, PRIMARY_NAV_ITEMS, UI_STATE_SAVE_DEBOUNCE_MS } from "../constants";
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_TERMINAL_COMPLETION_SOUND,
|
|
9
|
+
type TerminalCompletionSoundId,
|
|
10
|
+
} from "../notificationSounds";
|
|
11
|
+
import { retainActiveTerminalEntries, retainActiveTerminalIds } from "../terminalState";
|
|
12
|
+
import type { FrontendUiStateSnapshot, TerminalView } from "../types";
|
|
13
|
+
import { clampSidebarWidth, normalizeFrontendUiStateSnapshot } from "../uiStateNormalizers";
|
|
14
|
+
|
|
15
|
+
type UsePersistedUiStateOptions = {
|
|
16
|
+
columns: TerminalView;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const DEFAULT_ACTIVE_PRIMARY_NAV: PrimaryNavIndex = 1;
|
|
20
|
+
const DEFAULT_IS_AGENTS_SIDEBAR_VISIBLE = true;
|
|
21
|
+
const DEFAULT_IS_ACTIVE_AGENTS_SECTION_EXPANDED = true;
|
|
22
|
+
const DEFAULT_IS_RUNTIME_STATUS_STRIP_VISIBLE = true;
|
|
23
|
+
const DEFAULT_IS_MONITOR_VISIBLE = true;
|
|
24
|
+
const DEFAULT_IS_BOTTOM_TELEMETRY_VISIBLE = true;
|
|
25
|
+
const DEFAULT_IS_CODEX_USAGE_VISIBLE = true;
|
|
26
|
+
const DEFAULT_IS_CLAUDE_USAGE_VISIBLE = true;
|
|
27
|
+
const DEFAULT_IS_CLAUDE_USAGE_SECTION_EXPANDED = true;
|
|
28
|
+
const DEFAULT_IS_CODEX_USAGE_SECTION_EXPANDED = true;
|
|
29
|
+
const DEFAULT_MINIMIZED_TERMINAL_IDS: string[] = [];
|
|
30
|
+
const DEFAULT_TERMINAL_WIDTHS: Record<string, number> = {};
|
|
31
|
+
const DEFAULT_CANVAS_OPEN_TERMINAL_IDS: string[] = [];
|
|
32
|
+
const DEFAULT_CANVAS_OPEN_TENTACLE_IDS: string[] = [];
|
|
33
|
+
|
|
34
|
+
const areStringArraysEqual = (left: string[] | undefined, right: string[] | undefined) => {
|
|
35
|
+
if (left === right) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const nextLeft = left ?? [];
|
|
40
|
+
const nextRight = right ?? [];
|
|
41
|
+
if (nextLeft.length !== nextRight.length) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return nextLeft.every((value, index) => value === nextRight[index]);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const areNumberRecordMapsEqual = (
|
|
49
|
+
left: Record<string, number> | undefined,
|
|
50
|
+
right: Record<string, number> | undefined,
|
|
51
|
+
) => {
|
|
52
|
+
if (left === right) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const leftEntries = Object.entries(left ?? {});
|
|
57
|
+
const rightEntries = right ?? {};
|
|
58
|
+
if (leftEntries.length !== Object.keys(rightEntries).length) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return leftEntries.every(([key, value]) => rightEntries[key] === value);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const buildPersistedUiStateSnapshot = ({
|
|
66
|
+
activePrimaryNav,
|
|
67
|
+
isAgentsSidebarVisible,
|
|
68
|
+
sidebarWidth,
|
|
69
|
+
isActiveAgentsSectionExpanded,
|
|
70
|
+
isRuntimeStatusStripVisible,
|
|
71
|
+
isMonitorVisible,
|
|
72
|
+
isBottomTelemetryVisible,
|
|
73
|
+
isCodexUsageVisible,
|
|
74
|
+
isClaudeUsageVisible,
|
|
75
|
+
isClaudeUsageSectionExpanded,
|
|
76
|
+
isCodexUsageSectionExpanded,
|
|
77
|
+
terminalCompletionSound,
|
|
78
|
+
minimizedTerminalIds,
|
|
79
|
+
terminalWidths,
|
|
80
|
+
canvasOpenTerminalIds,
|
|
81
|
+
canvasOpenTentacleIds,
|
|
82
|
+
canvasTerminalsPanelWidth,
|
|
83
|
+
}: {
|
|
84
|
+
activePrimaryNav: PrimaryNavIndex;
|
|
85
|
+
isAgentsSidebarVisible: boolean;
|
|
86
|
+
sidebarWidth: number;
|
|
87
|
+
isActiveAgentsSectionExpanded: boolean;
|
|
88
|
+
isRuntimeStatusStripVisible: boolean;
|
|
89
|
+
isMonitorVisible: boolean;
|
|
90
|
+
isBottomTelemetryVisible: boolean;
|
|
91
|
+
isCodexUsageVisible: boolean;
|
|
92
|
+
isClaudeUsageVisible: boolean;
|
|
93
|
+
isClaudeUsageSectionExpanded: boolean;
|
|
94
|
+
isCodexUsageSectionExpanded: boolean;
|
|
95
|
+
terminalCompletionSound: TerminalCompletionSoundId;
|
|
96
|
+
minimizedTerminalIds: string[];
|
|
97
|
+
terminalWidths: Record<string, number>;
|
|
98
|
+
canvasOpenTerminalIds: string[];
|
|
99
|
+
canvasOpenTentacleIds: string[];
|
|
100
|
+
canvasTerminalsPanelWidth: number | null;
|
|
101
|
+
}): FrontendUiStateSnapshot => ({
|
|
102
|
+
activePrimaryNav,
|
|
103
|
+
isAgentsSidebarVisible,
|
|
104
|
+
sidebarWidth: clampSidebarWidth(sidebarWidth),
|
|
105
|
+
isActiveAgentsSectionExpanded,
|
|
106
|
+
isRuntimeStatusStripVisible,
|
|
107
|
+
isMonitorVisible,
|
|
108
|
+
isBottomTelemetryVisible,
|
|
109
|
+
isCodexUsageVisible,
|
|
110
|
+
isClaudeUsageVisible,
|
|
111
|
+
isClaudeUsageSectionExpanded,
|
|
112
|
+
isCodexUsageSectionExpanded,
|
|
113
|
+
terminalCompletionSound,
|
|
114
|
+
minimizedTerminalIds,
|
|
115
|
+
terminalWidths,
|
|
116
|
+
canvasOpenTerminalIds,
|
|
117
|
+
canvasOpenTentacleIds,
|
|
118
|
+
...(canvasTerminalsPanelWidth != null ? { canvasTerminalsPanelWidth } : {}),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const areUiStateSnapshotsEqual = (
|
|
122
|
+
left: FrontendUiStateSnapshot | null,
|
|
123
|
+
right: FrontendUiStateSnapshot,
|
|
124
|
+
) =>
|
|
125
|
+
left !== null &&
|
|
126
|
+
left.activePrimaryNav === right.activePrimaryNav &&
|
|
127
|
+
left.isAgentsSidebarVisible === right.isAgentsSidebarVisible &&
|
|
128
|
+
left.sidebarWidth === right.sidebarWidth &&
|
|
129
|
+
left.isActiveAgentsSectionExpanded === right.isActiveAgentsSectionExpanded &&
|
|
130
|
+
left.isRuntimeStatusStripVisible === right.isRuntimeStatusStripVisible &&
|
|
131
|
+
left.isMonitorVisible === right.isMonitorVisible &&
|
|
132
|
+
left.isBottomTelemetryVisible === right.isBottomTelemetryVisible &&
|
|
133
|
+
left.isCodexUsageVisible === right.isCodexUsageVisible &&
|
|
134
|
+
left.isClaudeUsageVisible === right.isClaudeUsageVisible &&
|
|
135
|
+
left.isClaudeUsageSectionExpanded === right.isClaudeUsageSectionExpanded &&
|
|
136
|
+
left.isCodexUsageSectionExpanded === right.isCodexUsageSectionExpanded &&
|
|
137
|
+
left.terminalCompletionSound === right.terminalCompletionSound &&
|
|
138
|
+
areStringArraysEqual(left.minimizedTerminalIds, right.minimizedTerminalIds) &&
|
|
139
|
+
areNumberRecordMapsEqual(left.terminalWidths, right.terminalWidths) &&
|
|
140
|
+
areStringArraysEqual(left.canvasOpenTerminalIds, right.canvasOpenTerminalIds) &&
|
|
141
|
+
areStringArraysEqual(left.canvasOpenTentacleIds, right.canvasOpenTentacleIds) &&
|
|
142
|
+
left.canvasTerminalsPanelWidth === right.canvasTerminalsPanelWidth;
|
|
143
|
+
|
|
144
|
+
type UsePersistedUiStateResult = {
|
|
145
|
+
activePrimaryNav: PrimaryNavIndex;
|
|
146
|
+
setActivePrimaryNav: Dispatch<SetStateAction<PrimaryNavIndex>>;
|
|
147
|
+
isUiStateHydrated: boolean;
|
|
148
|
+
setIsUiStateHydrated: Dispatch<SetStateAction<boolean>>;
|
|
149
|
+
hasHydratedUiStateSnapshot: boolean;
|
|
150
|
+
isAgentsSidebarVisible: boolean;
|
|
151
|
+
setIsAgentsSidebarVisible: Dispatch<SetStateAction<boolean>>;
|
|
152
|
+
sidebarWidth: number;
|
|
153
|
+
setSidebarWidth: Dispatch<SetStateAction<number>>;
|
|
154
|
+
isActiveAgentsSectionExpanded: boolean;
|
|
155
|
+
setIsActiveAgentsSectionExpanded: Dispatch<SetStateAction<boolean>>;
|
|
156
|
+
isRuntimeStatusStripVisible: boolean;
|
|
157
|
+
setIsRuntimeStatusStripVisible: Dispatch<SetStateAction<boolean>>;
|
|
158
|
+
isMonitorVisible: boolean;
|
|
159
|
+
setIsMonitorVisible: Dispatch<SetStateAction<boolean>>;
|
|
160
|
+
isBottomTelemetryVisible: boolean;
|
|
161
|
+
setIsBottomTelemetryVisible: Dispatch<SetStateAction<boolean>>;
|
|
162
|
+
isCodexUsageVisible: boolean;
|
|
163
|
+
setIsCodexUsageVisible: Dispatch<SetStateAction<boolean>>;
|
|
164
|
+
isClaudeUsageVisible: boolean;
|
|
165
|
+
setIsClaudeUsageVisible: Dispatch<SetStateAction<boolean>>;
|
|
166
|
+
isClaudeUsageSectionExpanded: boolean;
|
|
167
|
+
setIsClaudeUsageSectionExpanded: Dispatch<SetStateAction<boolean>>;
|
|
168
|
+
isCodexUsageSectionExpanded: boolean;
|
|
169
|
+
setIsCodexUsageSectionExpanded: Dispatch<SetStateAction<boolean>>;
|
|
170
|
+
terminalCompletionSound: TerminalCompletionSoundId;
|
|
171
|
+
setTerminalCompletionSound: Dispatch<SetStateAction<TerminalCompletionSoundId>>;
|
|
172
|
+
minimizedTerminalIds: string[];
|
|
173
|
+
setMinimizedTerminalIds: Dispatch<SetStateAction<string[]>>;
|
|
174
|
+
terminalWidths: Record<string, number>;
|
|
175
|
+
setTerminalWidths: Dispatch<SetStateAction<Record<string, number>>>;
|
|
176
|
+
canvasOpenTerminalIds: string[];
|
|
177
|
+
setCanvasOpenTerminalIds: Dispatch<SetStateAction<string[]>>;
|
|
178
|
+
canvasOpenTentacleIds: string[];
|
|
179
|
+
setCanvasOpenTentacleIds: Dispatch<SetStateAction<string[]>>;
|
|
180
|
+
canvasTerminalsPanelWidth: number | null;
|
|
181
|
+
setCanvasTerminalsPanelWidth: Dispatch<SetStateAction<number | null>>;
|
|
182
|
+
readUiState: (signal?: AbortSignal) => Promise<FrontendUiStateSnapshot | null>;
|
|
183
|
+
applyHydratedUiState: (
|
|
184
|
+
snapshot: FrontendUiStateSnapshot | null,
|
|
185
|
+
nextColumns: TerminalView,
|
|
186
|
+
) => void;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const usePersistedUiState = ({
|
|
190
|
+
columns,
|
|
191
|
+
}: UsePersistedUiStateOptions): UsePersistedUiStateResult => {
|
|
192
|
+
const [activePrimaryNav, setActivePrimaryNav] = useState<PrimaryNavIndex>(
|
|
193
|
+
DEFAULT_ACTIVE_PRIMARY_NAV,
|
|
194
|
+
);
|
|
195
|
+
const [isAgentsSidebarVisible, setIsAgentsSidebarVisible] = useState(
|
|
196
|
+
DEFAULT_IS_AGENTS_SIDEBAR_VISIBLE,
|
|
197
|
+
);
|
|
198
|
+
const [sidebarWidth, setSidebarWidth] = useState(MIN_SIDEBAR_WIDTH);
|
|
199
|
+
const [isActiveAgentsSectionExpanded, setIsActiveAgentsSectionExpanded] = useState(
|
|
200
|
+
DEFAULT_IS_ACTIVE_AGENTS_SECTION_EXPANDED,
|
|
201
|
+
);
|
|
202
|
+
const [isRuntimeStatusStripVisible, setIsRuntimeStatusStripVisible] = useState(
|
|
203
|
+
DEFAULT_IS_RUNTIME_STATUS_STRIP_VISIBLE,
|
|
204
|
+
);
|
|
205
|
+
const [isMonitorVisible, setIsMonitorVisible] = useState(DEFAULT_IS_MONITOR_VISIBLE);
|
|
206
|
+
const [isBottomTelemetryVisible, setIsBottomTelemetryVisible] = useState(
|
|
207
|
+
DEFAULT_IS_BOTTOM_TELEMETRY_VISIBLE,
|
|
208
|
+
);
|
|
209
|
+
const [isCodexUsageVisible, setIsCodexUsageVisible] = useState(DEFAULT_IS_CODEX_USAGE_VISIBLE);
|
|
210
|
+
const [isClaudeUsageVisible, setIsClaudeUsageVisible] = useState(DEFAULT_IS_CLAUDE_USAGE_VISIBLE);
|
|
211
|
+
const [isClaudeUsageSectionExpanded, setIsClaudeUsageSectionExpanded] = useState(
|
|
212
|
+
DEFAULT_IS_CLAUDE_USAGE_SECTION_EXPANDED,
|
|
213
|
+
);
|
|
214
|
+
const [isCodexUsageSectionExpanded, setIsCodexUsageSectionExpanded] = useState(
|
|
215
|
+
DEFAULT_IS_CODEX_USAGE_SECTION_EXPANDED,
|
|
216
|
+
);
|
|
217
|
+
const [terminalCompletionSound, setTerminalCompletionSound] = useState<TerminalCompletionSoundId>(
|
|
218
|
+
DEFAULT_TERMINAL_COMPLETION_SOUND,
|
|
219
|
+
);
|
|
220
|
+
const [isUiStateHydrated, setIsUiStateHydrated] = useState(false);
|
|
221
|
+
const [hasHydratedUiStateSnapshot, setHasHydratedUiStateSnapshot] = useState(false);
|
|
222
|
+
const [minimizedTerminalIds, setMinimizedTerminalIds] = useState<string[]>(
|
|
223
|
+
DEFAULT_MINIMIZED_TERMINAL_IDS,
|
|
224
|
+
);
|
|
225
|
+
const [terminalWidths, setTerminalWidths] =
|
|
226
|
+
useState<Record<string, number>>(DEFAULT_TERMINAL_WIDTHS);
|
|
227
|
+
const [canvasOpenTerminalIds, setCanvasOpenTerminalIds] = useState<string[]>(
|
|
228
|
+
DEFAULT_CANVAS_OPEN_TERMINAL_IDS,
|
|
229
|
+
);
|
|
230
|
+
const [canvasOpenTentacleIds, setCanvasOpenTentacleIds] = useState<string[]>(
|
|
231
|
+
DEFAULT_CANVAS_OPEN_TENTACLE_IDS,
|
|
232
|
+
);
|
|
233
|
+
const [canvasTerminalsPanelWidth, setCanvasTerminalsPanelWidth] = useState<number | null>(null);
|
|
234
|
+
const lastPersistedUiStateRef = useRef<FrontendUiStateSnapshot | null>(null);
|
|
235
|
+
|
|
236
|
+
const readUiState = useCallback(async (signal?: AbortSignal) => {
|
|
237
|
+
try {
|
|
238
|
+
const requestOptions: {
|
|
239
|
+
method: "GET";
|
|
240
|
+
headers: { Accept: string };
|
|
241
|
+
signal?: AbortSignal;
|
|
242
|
+
} = {
|
|
243
|
+
method: "GET",
|
|
244
|
+
headers: {
|
|
245
|
+
Accept: "application/json",
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
if (signal) {
|
|
249
|
+
requestOptions.signal = signal;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const response = await fetch(buildUiStateUrl(), requestOptions);
|
|
253
|
+
if (!response.ok) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return normalizeFrontendUiStateSnapshot(await response.json());
|
|
258
|
+
} catch {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
}, []);
|
|
262
|
+
|
|
263
|
+
const applyHydratedUiState = useCallback(
|
|
264
|
+
(snapshot: FrontendUiStateSnapshot | null, nextColumns: TerminalView) => {
|
|
265
|
+
const activeTerminalIds = new Set(nextColumns.map((entry) => entry.terminalId));
|
|
266
|
+
const activeTentacleIds = new Set(nextColumns.map((entry) => entry.tentacleId));
|
|
267
|
+
const hasPersistedSnapshot = snapshot !== null && Object.keys(snapshot).length > 0;
|
|
268
|
+
setHasHydratedUiStateSnapshot(hasPersistedSnapshot);
|
|
269
|
+
|
|
270
|
+
if (!snapshot) {
|
|
271
|
+
lastPersistedUiStateRef.current = buildPersistedUiStateSnapshot({
|
|
272
|
+
activePrimaryNav: DEFAULT_ACTIVE_PRIMARY_NAV,
|
|
273
|
+
isAgentsSidebarVisible: DEFAULT_IS_AGENTS_SIDEBAR_VISIBLE,
|
|
274
|
+
sidebarWidth: MIN_SIDEBAR_WIDTH,
|
|
275
|
+
isActiveAgentsSectionExpanded: DEFAULT_IS_ACTIVE_AGENTS_SECTION_EXPANDED,
|
|
276
|
+
isRuntimeStatusStripVisible: DEFAULT_IS_RUNTIME_STATUS_STRIP_VISIBLE,
|
|
277
|
+
isMonitorVisible: DEFAULT_IS_MONITOR_VISIBLE,
|
|
278
|
+
isBottomTelemetryVisible: DEFAULT_IS_BOTTOM_TELEMETRY_VISIBLE,
|
|
279
|
+
isCodexUsageVisible: DEFAULT_IS_CODEX_USAGE_VISIBLE,
|
|
280
|
+
isClaudeUsageVisible: DEFAULT_IS_CLAUDE_USAGE_VISIBLE,
|
|
281
|
+
isClaudeUsageSectionExpanded: DEFAULT_IS_CLAUDE_USAGE_SECTION_EXPANDED,
|
|
282
|
+
isCodexUsageSectionExpanded: DEFAULT_IS_CODEX_USAGE_SECTION_EXPANDED,
|
|
283
|
+
terminalCompletionSound: DEFAULT_TERMINAL_COMPLETION_SOUND,
|
|
284
|
+
minimizedTerminalIds: DEFAULT_MINIMIZED_TERMINAL_IDS,
|
|
285
|
+
terminalWidths: DEFAULT_TERMINAL_WIDTHS,
|
|
286
|
+
canvasOpenTerminalIds: DEFAULT_CANVAS_OPEN_TERMINAL_IDS,
|
|
287
|
+
canvasOpenTentacleIds: DEFAULT_CANVAS_OPEN_TENTACLE_IDS,
|
|
288
|
+
canvasTerminalsPanelWidth: null,
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const nextMinimizedTerminalIds = snapshot.minimizedTerminalIds
|
|
294
|
+
? retainActiveTerminalIds(snapshot.minimizedTerminalIds, activeTerminalIds)
|
|
295
|
+
: DEFAULT_MINIMIZED_TERMINAL_IDS;
|
|
296
|
+
const nextTerminalWidths = snapshot.terminalWidths
|
|
297
|
+
? retainActiveTerminalEntries(snapshot.terminalWidths, activeTerminalIds)
|
|
298
|
+
: DEFAULT_TERMINAL_WIDTHS;
|
|
299
|
+
const nextCanvasOpenTerminalIds = snapshot.canvasOpenTerminalIds
|
|
300
|
+
? retainActiveTerminalIds(snapshot.canvasOpenTerminalIds, activeTerminalIds)
|
|
301
|
+
: DEFAULT_CANVAS_OPEN_TERMINAL_IDS;
|
|
302
|
+
const nextCanvasOpenTentacleIds = snapshot.canvasOpenTentacleIds
|
|
303
|
+
? retainActiveTerminalIds(snapshot.canvasOpenTentacleIds, activeTentacleIds)
|
|
304
|
+
: DEFAULT_CANVAS_OPEN_TENTACLE_IDS;
|
|
305
|
+
|
|
306
|
+
lastPersistedUiStateRef.current = buildPersistedUiStateSnapshot({
|
|
307
|
+
activePrimaryNav:
|
|
308
|
+
snapshot.activePrimaryNav !== undefined &&
|
|
309
|
+
snapshot.activePrimaryNav >= 1 &&
|
|
310
|
+
snapshot.activePrimaryNav <= PRIMARY_NAV_ITEMS.length
|
|
311
|
+
? (snapshot.activePrimaryNav as PrimaryNavIndex)
|
|
312
|
+
: DEFAULT_ACTIVE_PRIMARY_NAV,
|
|
313
|
+
isAgentsSidebarVisible:
|
|
314
|
+
snapshot.isAgentsSidebarVisible ?? DEFAULT_IS_AGENTS_SIDEBAR_VISIBLE,
|
|
315
|
+
sidebarWidth: snapshot.sidebarWidth ?? MIN_SIDEBAR_WIDTH,
|
|
316
|
+
isActiveAgentsSectionExpanded:
|
|
317
|
+
snapshot.isActiveAgentsSectionExpanded ?? DEFAULT_IS_ACTIVE_AGENTS_SECTION_EXPANDED,
|
|
318
|
+
isRuntimeStatusStripVisible:
|
|
319
|
+
snapshot.isRuntimeStatusStripVisible ?? DEFAULT_IS_RUNTIME_STATUS_STRIP_VISIBLE,
|
|
320
|
+
isMonitorVisible: snapshot.isMonitorVisible ?? DEFAULT_IS_MONITOR_VISIBLE,
|
|
321
|
+
isBottomTelemetryVisible:
|
|
322
|
+
snapshot.isBottomTelemetryVisible ?? DEFAULT_IS_BOTTOM_TELEMETRY_VISIBLE,
|
|
323
|
+
isCodexUsageVisible: snapshot.isCodexUsageVisible ?? DEFAULT_IS_CODEX_USAGE_VISIBLE,
|
|
324
|
+
isClaudeUsageVisible: snapshot.isClaudeUsageVisible ?? DEFAULT_IS_CLAUDE_USAGE_VISIBLE,
|
|
325
|
+
isClaudeUsageSectionExpanded:
|
|
326
|
+
snapshot.isClaudeUsageSectionExpanded ?? DEFAULT_IS_CLAUDE_USAGE_SECTION_EXPANDED,
|
|
327
|
+
isCodexUsageSectionExpanded:
|
|
328
|
+
snapshot.isCodexUsageSectionExpanded ?? DEFAULT_IS_CODEX_USAGE_SECTION_EXPANDED,
|
|
329
|
+
terminalCompletionSound:
|
|
330
|
+
snapshot.terminalCompletionSound ?? DEFAULT_TERMINAL_COMPLETION_SOUND,
|
|
331
|
+
minimizedTerminalIds: nextMinimizedTerminalIds,
|
|
332
|
+
terminalWidths: nextTerminalWidths,
|
|
333
|
+
canvasOpenTerminalIds: nextCanvasOpenTerminalIds,
|
|
334
|
+
canvasOpenTentacleIds: nextCanvasOpenTentacleIds,
|
|
335
|
+
canvasTerminalsPanelWidth: snapshot.canvasTerminalsPanelWidth ?? null,
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
if (
|
|
339
|
+
snapshot.activePrimaryNav !== undefined &&
|
|
340
|
+
snapshot.activePrimaryNav >= 1 &&
|
|
341
|
+
snapshot.activePrimaryNav <= PRIMARY_NAV_ITEMS.length
|
|
342
|
+
) {
|
|
343
|
+
setActivePrimaryNav(snapshot.activePrimaryNav as PrimaryNavIndex);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (snapshot.isAgentsSidebarVisible !== undefined) {
|
|
347
|
+
setIsAgentsSidebarVisible(snapshot.isAgentsSidebarVisible);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (snapshot.sidebarWidth !== undefined) {
|
|
351
|
+
setSidebarWidth(clampSidebarWidth(snapshot.sidebarWidth));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (snapshot.isActiveAgentsSectionExpanded !== undefined) {
|
|
355
|
+
setIsActiveAgentsSectionExpanded(snapshot.isActiveAgentsSectionExpanded);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (snapshot.isRuntimeStatusStripVisible !== undefined) {
|
|
359
|
+
setIsRuntimeStatusStripVisible(snapshot.isRuntimeStatusStripVisible);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (snapshot.isMonitorVisible !== undefined) {
|
|
363
|
+
setIsMonitorVisible(snapshot.isMonitorVisible);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (snapshot.isBottomTelemetryVisible !== undefined) {
|
|
367
|
+
setIsBottomTelemetryVisible(snapshot.isBottomTelemetryVisible);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (snapshot.isCodexUsageVisible !== undefined) {
|
|
371
|
+
setIsCodexUsageVisible(snapshot.isCodexUsageVisible);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (snapshot.isClaudeUsageVisible !== undefined) {
|
|
375
|
+
setIsClaudeUsageVisible(snapshot.isClaudeUsageVisible);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (snapshot.isCodexUsageSectionExpanded !== undefined) {
|
|
379
|
+
setIsCodexUsageSectionExpanded(snapshot.isCodexUsageSectionExpanded);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (snapshot.isClaudeUsageSectionExpanded !== undefined) {
|
|
383
|
+
setIsClaudeUsageSectionExpanded(snapshot.isClaudeUsageSectionExpanded);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (snapshot.terminalCompletionSound !== undefined) {
|
|
387
|
+
setTerminalCompletionSound(snapshot.terminalCompletionSound);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (snapshot.minimizedTerminalIds) {
|
|
391
|
+
setMinimizedTerminalIds(nextMinimizedTerminalIds);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (snapshot.terminalWidths) {
|
|
395
|
+
setTerminalWidths(nextTerminalWidths);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (snapshot.canvasOpenTerminalIds) {
|
|
399
|
+
setCanvasOpenTerminalIds(nextCanvasOpenTerminalIds);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (snapshot.canvasOpenTentacleIds) {
|
|
403
|
+
setCanvasOpenTentacleIds(nextCanvasOpenTentacleIds);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (snapshot.canvasTerminalsPanelWidth !== undefined) {
|
|
407
|
+
setCanvasTerminalsPanelWidth(snapshot.canvasTerminalsPanelWidth);
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
[],
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
useEffect(() => {
|
|
414
|
+
const activeTerminalIds = new Set(columns.map((entry) => entry.terminalId));
|
|
415
|
+
const activeTentacleIds = new Set(columns.map((entry) => entry.tentacleId));
|
|
416
|
+
setMinimizedTerminalIds((current) => retainActiveTerminalIds(current, activeTerminalIds));
|
|
417
|
+
setTerminalWidths((current) => retainActiveTerminalEntries(current, activeTerminalIds));
|
|
418
|
+
setCanvasOpenTerminalIds((current) => retainActiveTerminalIds(current, activeTerminalIds));
|
|
419
|
+
setCanvasOpenTentacleIds((current) => retainActiveTerminalIds(current, activeTentacleIds));
|
|
420
|
+
}, [columns]);
|
|
421
|
+
|
|
422
|
+
useEffect(() => {
|
|
423
|
+
if (!isUiStateHydrated) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const payload = buildPersistedUiStateSnapshot({
|
|
428
|
+
activePrimaryNav,
|
|
429
|
+
isAgentsSidebarVisible,
|
|
430
|
+
sidebarWidth,
|
|
431
|
+
isActiveAgentsSectionExpanded,
|
|
432
|
+
isRuntimeStatusStripVisible,
|
|
433
|
+
isMonitorVisible,
|
|
434
|
+
isBottomTelemetryVisible,
|
|
435
|
+
isCodexUsageVisible,
|
|
436
|
+
isClaudeUsageVisible,
|
|
437
|
+
isClaudeUsageSectionExpanded,
|
|
438
|
+
isCodexUsageSectionExpanded,
|
|
439
|
+
terminalCompletionSound,
|
|
440
|
+
minimizedTerminalIds,
|
|
441
|
+
terminalWidths,
|
|
442
|
+
canvasOpenTerminalIds,
|
|
443
|
+
canvasOpenTentacleIds,
|
|
444
|
+
canvasTerminalsPanelWidth,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
if (areUiStateSnapshotsEqual(lastPersistedUiStateRef.current, payload)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const timerId = window.setTimeout(() => {
|
|
452
|
+
void fetch(buildUiStateUrl(), {
|
|
453
|
+
method: "PATCH",
|
|
454
|
+
headers: {
|
|
455
|
+
Accept: "application/json",
|
|
456
|
+
"Content-Type": "application/json",
|
|
457
|
+
},
|
|
458
|
+
body: JSON.stringify(payload),
|
|
459
|
+
})
|
|
460
|
+
.then((response) => {
|
|
461
|
+
if (!response.ok) {
|
|
462
|
+
throw new Error(`Unexpected status ${response.status}`);
|
|
463
|
+
}
|
|
464
|
+
lastPersistedUiStateRef.current = payload;
|
|
465
|
+
})
|
|
466
|
+
.catch((error: unknown) => {
|
|
467
|
+
console.warn("[ui-state] Failed to persist UI state:", error);
|
|
468
|
+
});
|
|
469
|
+
}, UI_STATE_SAVE_DEBOUNCE_MS);
|
|
470
|
+
|
|
471
|
+
return () => {
|
|
472
|
+
window.clearTimeout(timerId);
|
|
473
|
+
};
|
|
474
|
+
}, [
|
|
475
|
+
activePrimaryNav,
|
|
476
|
+
canvasOpenTerminalIds,
|
|
477
|
+
canvasOpenTentacleIds,
|
|
478
|
+
canvasTerminalsPanelWidth,
|
|
479
|
+
isActiveAgentsSectionExpanded,
|
|
480
|
+
isAgentsSidebarVisible,
|
|
481
|
+
isBottomTelemetryVisible,
|
|
482
|
+
isRuntimeStatusStripVisible,
|
|
483
|
+
isMonitorVisible,
|
|
484
|
+
isCodexUsageVisible,
|
|
485
|
+
isClaudeUsageVisible,
|
|
486
|
+
isClaudeUsageSectionExpanded,
|
|
487
|
+
isCodexUsageSectionExpanded,
|
|
488
|
+
isUiStateHydrated,
|
|
489
|
+
minimizedTerminalIds,
|
|
490
|
+
sidebarWidth,
|
|
491
|
+
terminalCompletionSound,
|
|
492
|
+
terminalWidths,
|
|
493
|
+
]);
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
activePrimaryNav,
|
|
497
|
+
setActivePrimaryNav,
|
|
498
|
+
isUiStateHydrated,
|
|
499
|
+
setIsUiStateHydrated,
|
|
500
|
+
hasHydratedUiStateSnapshot,
|
|
501
|
+
isAgentsSidebarVisible,
|
|
502
|
+
setIsAgentsSidebarVisible,
|
|
503
|
+
sidebarWidth,
|
|
504
|
+
setSidebarWidth,
|
|
505
|
+
isActiveAgentsSectionExpanded,
|
|
506
|
+
setIsActiveAgentsSectionExpanded,
|
|
507
|
+
isRuntimeStatusStripVisible,
|
|
508
|
+
setIsRuntimeStatusStripVisible,
|
|
509
|
+
isMonitorVisible,
|
|
510
|
+
setIsMonitorVisible,
|
|
511
|
+
isBottomTelemetryVisible,
|
|
512
|
+
setIsBottomTelemetryVisible,
|
|
513
|
+
isCodexUsageVisible,
|
|
514
|
+
setIsCodexUsageVisible,
|
|
515
|
+
isClaudeUsageVisible,
|
|
516
|
+
setIsClaudeUsageVisible,
|
|
517
|
+
isClaudeUsageSectionExpanded,
|
|
518
|
+
setIsClaudeUsageSectionExpanded,
|
|
519
|
+
isCodexUsageSectionExpanded,
|
|
520
|
+
setIsCodexUsageSectionExpanded,
|
|
521
|
+
terminalCompletionSound,
|
|
522
|
+
setTerminalCompletionSound,
|
|
523
|
+
minimizedTerminalIds,
|
|
524
|
+
setMinimizedTerminalIds,
|
|
525
|
+
terminalWidths,
|
|
526
|
+
setTerminalWidths,
|
|
527
|
+
canvasOpenTerminalIds,
|
|
528
|
+
setCanvasOpenTerminalIds,
|
|
529
|
+
canvasOpenTentacleIds,
|
|
530
|
+
setCanvasOpenTentacleIds,
|
|
531
|
+
canvasTerminalsPanelWidth,
|
|
532
|
+
setCanvasTerminalsPanelWidth,
|
|
533
|
+
readUiState,
|
|
534
|
+
applyHydratedUiState,
|
|
535
|
+
};
|
|
536
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
type UsePollingDataOptions<T> = {
|
|
4
|
+
fetchUrl: string;
|
|
5
|
+
intervalMs: number;
|
|
6
|
+
normalize: (raw: unknown) => T | null;
|
|
7
|
+
fallback: () => T;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const usePollingData = <T>(options: UsePollingDataOptions<T>) => {
|
|
12
|
+
const { fetchUrl, intervalMs, enabled = true } = options;
|
|
13
|
+
const [data, setData] = useState<T | null>(null);
|
|
14
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
15
|
+
const isInFlightRef = useRef(false);
|
|
16
|
+
const isDisposedRef = useRef(false);
|
|
17
|
+
const hasQueuedRefreshRef = useRef(false);
|
|
18
|
+
|
|
19
|
+
const normalizeRef = useRef(options.normalize);
|
|
20
|
+
normalizeRef.current = options.normalize;
|
|
21
|
+
const fallbackRef = useRef(options.fallback);
|
|
22
|
+
fallbackRef.current = options.fallback;
|
|
23
|
+
|
|
24
|
+
const sync = useCallback(
|
|
25
|
+
async (force = false) => {
|
|
26
|
+
if (isDisposedRef.current) return;
|
|
27
|
+
if (isInFlightRef.current) {
|
|
28
|
+
if (force) {
|
|
29
|
+
hasQueuedRefreshRef.current = true;
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
isInFlightRef.current = true;
|
|
34
|
+
setIsLoading(true);
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(fetchUrl, {
|
|
37
|
+
method: "GET",
|
|
38
|
+
headers: { Accept: "application/json" },
|
|
39
|
+
cache: "no-store",
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) throw new Error(`Request failed (${response.status})`);
|
|
42
|
+
const parsed = normalizeRef.current(await response.json());
|
|
43
|
+
if (!isDisposedRef.current) setData(parsed ?? fallbackRef.current());
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (!isDisposedRef.current) {
|
|
46
|
+
console.warn(
|
|
47
|
+
`[polling] ${fetchUrl} failed:`,
|
|
48
|
+
error instanceof Error ? error.message : error,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
isInFlightRef.current = false;
|
|
53
|
+
if (!isDisposedRef.current) setIsLoading(false);
|
|
54
|
+
if (hasQueuedRefreshRef.current) {
|
|
55
|
+
hasQueuedRefreshRef.current = false;
|
|
56
|
+
void sync();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[fetchUrl],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!enabled) return;
|
|
65
|
+
isDisposedRef.current = false;
|
|
66
|
+
void sync();
|
|
67
|
+
const timerId = window.setInterval(() => void sync(), intervalMs);
|
|
68
|
+
return () => {
|
|
69
|
+
isDisposedRef.current = true;
|
|
70
|
+
window.clearInterval(timerId);
|
|
71
|
+
};
|
|
72
|
+
}, [enabled, intervalMs, sync]);
|
|
73
|
+
|
|
74
|
+
const refresh = useCallback(() => {
|
|
75
|
+
void sync(true);
|
|
76
|
+
}, [sync]);
|
|
77
|
+
|
|
78
|
+
return { data, isLoading, refresh };
|
|
79
|
+
};
|