@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,255 @@
|
|
|
1
|
+
import { type PersistedUiState, isTerminalCompletionSoundId } from "../terminalRuntime";
|
|
2
|
+
|
|
3
|
+
export const parseUiStatePatch = (
|
|
4
|
+
payload: unknown,
|
|
5
|
+
): { patch: PersistedUiState | null; error: string | null } => {
|
|
6
|
+
if (payload === null || payload === undefined || typeof payload !== "object") {
|
|
7
|
+
return {
|
|
8
|
+
patch: null,
|
|
9
|
+
error: "Expected a JSON object body.",
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const record = payload as Record<string, unknown>;
|
|
14
|
+
const patch: PersistedUiState = {};
|
|
15
|
+
|
|
16
|
+
if (record.activePrimaryNav !== undefined) {
|
|
17
|
+
if (
|
|
18
|
+
typeof record.activePrimaryNav !== "number" ||
|
|
19
|
+
!Number.isInteger(record.activePrimaryNav) ||
|
|
20
|
+
record.activePrimaryNav < 1
|
|
21
|
+
) {
|
|
22
|
+
return {
|
|
23
|
+
patch: null,
|
|
24
|
+
error: "activePrimaryNav must be a positive integer.",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
patch.activePrimaryNav = record.activePrimaryNav;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (record.isAgentsSidebarVisible !== undefined) {
|
|
31
|
+
if (typeof record.isAgentsSidebarVisible !== "boolean") {
|
|
32
|
+
return {
|
|
33
|
+
patch: null,
|
|
34
|
+
error: "isAgentsSidebarVisible must be a boolean.",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
patch.isAgentsSidebarVisible = record.isAgentsSidebarVisible;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (record.sidebarWidth !== undefined) {
|
|
41
|
+
if (typeof record.sidebarWidth !== "number" || !Number.isFinite(record.sidebarWidth)) {
|
|
42
|
+
return {
|
|
43
|
+
patch: null,
|
|
44
|
+
error: "sidebarWidth must be a finite number.",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
patch.sidebarWidth = record.sidebarWidth;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (record.isActiveAgentsSectionExpanded !== undefined) {
|
|
51
|
+
if (typeof record.isActiveAgentsSectionExpanded !== "boolean") {
|
|
52
|
+
return {
|
|
53
|
+
patch: null,
|
|
54
|
+
error: "isActiveAgentsSectionExpanded must be a boolean.",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
patch.isActiveAgentsSectionExpanded = record.isActiveAgentsSectionExpanded;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (record.isRuntimeStatusStripVisible !== undefined) {
|
|
61
|
+
if (typeof record.isRuntimeStatusStripVisible !== "boolean") {
|
|
62
|
+
return {
|
|
63
|
+
patch: null,
|
|
64
|
+
error: "isRuntimeStatusStripVisible must be a boolean.",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
patch.isRuntimeStatusStripVisible = record.isRuntimeStatusStripVisible;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (record.isMonitorVisible !== undefined) {
|
|
71
|
+
if (typeof record.isMonitorVisible !== "boolean") {
|
|
72
|
+
return {
|
|
73
|
+
patch: null,
|
|
74
|
+
error: "isMonitorVisible must be a boolean.",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
patch.isMonitorVisible = record.isMonitorVisible;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (record.isBottomTelemetryVisible !== undefined) {
|
|
81
|
+
if (typeof record.isBottomTelemetryVisible !== "boolean") {
|
|
82
|
+
return {
|
|
83
|
+
patch: null,
|
|
84
|
+
error: "isBottomTelemetryVisible must be a boolean.",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
patch.isBottomTelemetryVisible = record.isBottomTelemetryVisible;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (record.isCodexUsageVisible !== undefined) {
|
|
91
|
+
if (typeof record.isCodexUsageVisible !== "boolean") {
|
|
92
|
+
return {
|
|
93
|
+
patch: null,
|
|
94
|
+
error: "isCodexUsageVisible must be a boolean.",
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
patch.isCodexUsageVisible = record.isCodexUsageVisible;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (record.isClaudeUsageVisible !== undefined) {
|
|
101
|
+
if (typeof record.isClaudeUsageVisible !== "boolean") {
|
|
102
|
+
return {
|
|
103
|
+
patch: null,
|
|
104
|
+
error: "isClaudeUsageVisible must be a boolean.",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
patch.isClaudeUsageVisible = record.isClaudeUsageVisible;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (record.isClaudeUsageSectionExpanded !== undefined) {
|
|
111
|
+
if (typeof record.isClaudeUsageSectionExpanded !== "boolean") {
|
|
112
|
+
return {
|
|
113
|
+
patch: null,
|
|
114
|
+
error: "isClaudeUsageSectionExpanded must be a boolean.",
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
patch.isClaudeUsageSectionExpanded = record.isClaudeUsageSectionExpanded;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (record.isCodexUsageSectionExpanded !== undefined) {
|
|
121
|
+
if (typeof record.isCodexUsageSectionExpanded !== "boolean") {
|
|
122
|
+
return {
|
|
123
|
+
patch: null,
|
|
124
|
+
error: "isCodexUsageSectionExpanded must be a boolean.",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
patch.isCodexUsageSectionExpanded = record.isCodexUsageSectionExpanded;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const completionSoundKey = record.terminalCompletionSound;
|
|
131
|
+
if (completionSoundKey !== undefined) {
|
|
132
|
+
if (!isTerminalCompletionSoundId(completionSoundKey)) {
|
|
133
|
+
return {
|
|
134
|
+
patch: null,
|
|
135
|
+
error: "terminalCompletionSound must be one of the supported sound identifiers.",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
patch.terminalCompletionSound = completionSoundKey;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const minimizedKey = record.minimizedTerminalIds;
|
|
142
|
+
if (minimizedKey !== undefined) {
|
|
143
|
+
if (!Array.isArray(minimizedKey)) {
|
|
144
|
+
return {
|
|
145
|
+
patch: null,
|
|
146
|
+
error: "minimizedTerminalIds must be an array of strings.",
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const minimizedTerminalIds = minimizedKey.filter((id): id is string => typeof id === "string");
|
|
151
|
+
if (minimizedTerminalIds.length !== minimizedKey.length) {
|
|
152
|
+
return {
|
|
153
|
+
patch: null,
|
|
154
|
+
error: "minimizedTerminalIds must be an array of strings.",
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
patch.minimizedTerminalIds = [...new Set(minimizedTerminalIds)];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const widthsKey = record.terminalWidths;
|
|
161
|
+
if (widthsKey !== undefined) {
|
|
162
|
+
if (widthsKey === null || typeof widthsKey !== "object" || Array.isArray(widthsKey)) {
|
|
163
|
+
return {
|
|
164
|
+
patch: null,
|
|
165
|
+
error: "terminalWidths must be an object map of numbers.",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const terminalWidths = Object.entries(widthsKey).reduce<Record<string, number>>(
|
|
170
|
+
(acc, [id, width]) => {
|
|
171
|
+
if (typeof width === "number" && Number.isFinite(width)) {
|
|
172
|
+
acc[id] = width;
|
|
173
|
+
}
|
|
174
|
+
return acc;
|
|
175
|
+
},
|
|
176
|
+
{},
|
|
177
|
+
);
|
|
178
|
+
if (Object.keys(terminalWidths).length !== Object.keys(widthsKey).length) {
|
|
179
|
+
return {
|
|
180
|
+
patch: null,
|
|
181
|
+
error: "terminalWidths must be an object map of numbers.",
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
patch.terminalWidths = terminalWidths;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (record.canvasOpenTerminalIds !== undefined) {
|
|
188
|
+
if (!Array.isArray(record.canvasOpenTerminalIds)) {
|
|
189
|
+
return {
|
|
190
|
+
patch: null,
|
|
191
|
+
error: "canvasOpenTerminalIds must be an array of strings.",
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const canvasOpenTerminalIds = record.canvasOpenTerminalIds.filter(
|
|
196
|
+
(id): id is string => typeof id === "string",
|
|
197
|
+
);
|
|
198
|
+
if (canvasOpenTerminalIds.length !== record.canvasOpenTerminalIds.length) {
|
|
199
|
+
return {
|
|
200
|
+
patch: null,
|
|
201
|
+
error: "canvasOpenTerminalIds must be an array of strings.",
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
patch.canvasOpenTerminalIds = canvasOpenTerminalIds;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (record.canvasOpenTentacleIds !== undefined) {
|
|
208
|
+
if (!Array.isArray(record.canvasOpenTentacleIds)) {
|
|
209
|
+
return {
|
|
210
|
+
patch: null,
|
|
211
|
+
error: "canvasOpenTentacleIds must be an array of strings.",
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const canvasOpenTentacleIds = record.canvasOpenTentacleIds.filter(
|
|
216
|
+
(id): id is string => typeof id === "string",
|
|
217
|
+
);
|
|
218
|
+
if (canvasOpenTentacleIds.length !== record.canvasOpenTentacleIds.length) {
|
|
219
|
+
return {
|
|
220
|
+
patch: null,
|
|
221
|
+
error: "canvasOpenTentacleIds must be an array of strings.",
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
patch.canvasOpenTentacleIds = canvasOpenTentacleIds;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (record.canvasTerminalsPanelWidth !== undefined) {
|
|
228
|
+
if (
|
|
229
|
+
typeof record.canvasTerminalsPanelWidth !== "number" ||
|
|
230
|
+
!Number.isFinite(record.canvasTerminalsPanelWidth)
|
|
231
|
+
) {
|
|
232
|
+
return {
|
|
233
|
+
patch: null,
|
|
234
|
+
error: "canvasTerminalsPanelWidth must be a finite number.",
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
patch.canvasTerminalsPanelWidth = record.canvasTerminalsPanelWidth;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (record.terminalInactivityThresholdMs !== undefined) {
|
|
241
|
+
if (
|
|
242
|
+
typeof record.terminalInactivityThresholdMs !== "number" ||
|
|
243
|
+
!Number.isFinite(record.terminalInactivityThresholdMs) ||
|
|
244
|
+
record.terminalInactivityThresholdMs <= 0
|
|
245
|
+
) {
|
|
246
|
+
return {
|
|
247
|
+
patch: null,
|
|
248
|
+
error: "terminalInactivityThresholdMs must be a positive number.",
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
patch.terminalInactivityThresholdMs = record.terminalInactivityThresholdMs;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return { patch, error: null };
|
|
255
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import type { Socket } from "node:net";
|
|
3
|
+
|
|
4
|
+
import { isAllowedHostHeader, isAllowedOriginHeader, readHeaderValue } from "./security";
|
|
5
|
+
|
|
6
|
+
type TerminalRuntime = ReturnType<typeof import("../terminalRuntime").createTerminalRuntime>;
|
|
7
|
+
|
|
8
|
+
type CreateUpgradeHandlerOptions = {
|
|
9
|
+
runtime: TerminalRuntime;
|
|
10
|
+
allowRemoteAccess: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const createUpgradeHandler = ({
|
|
14
|
+
runtime,
|
|
15
|
+
allowRemoteAccess,
|
|
16
|
+
}: CreateUpgradeHandlerOptions) => {
|
|
17
|
+
return (request: IncomingMessage, socket: Socket, head: Buffer) => {
|
|
18
|
+
const originHeader = readHeaderValue(request.headers.origin);
|
|
19
|
+
const hostHeader = readHeaderValue(request.headers.host);
|
|
20
|
+
if (!isAllowedHostHeader(hostHeader, allowRemoteAccess)) {
|
|
21
|
+
socket.destroy();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!isAllowedOriginHeader(originHeader, allowRemoteAccess)) {
|
|
26
|
+
socket.destroy();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
if (!runtime.handleUpgrade(request, socket, head)) {
|
|
32
|
+
socket.destroy();
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
socket.destroy();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ApiRouteHandler } from "./routeHelpers";
|
|
2
|
+
import { writeJson, writeMethodNotAllowed } from "./routeHelpers";
|
|
3
|
+
|
|
4
|
+
export const handleCodexUsageRoute: ApiRouteHandler = async (
|
|
5
|
+
{ request, response, requestUrl, corsOrigin },
|
|
6
|
+
{ readCodexUsageSnapshot },
|
|
7
|
+
) => {
|
|
8
|
+
if (requestUrl.pathname !== "/api/codex/usage") {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (request.method !== "GET") {
|
|
13
|
+
writeMethodNotAllowed(response, corsOrigin);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const payload = await readCodexUsageSnapshot();
|
|
18
|
+
writeJson(response, 200, payload, corsOrigin);
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const handleClaudeUsageRoute: ApiRouteHandler = async (
|
|
23
|
+
{ request, response, requestUrl, corsOrigin },
|
|
24
|
+
{ readClaudeUsageSnapshot, readClaudeOauthUsageSnapshot, readClaudeCliUsageSnapshot },
|
|
25
|
+
) => {
|
|
26
|
+
if (
|
|
27
|
+
requestUrl.pathname !== "/api/claude/usage" &&
|
|
28
|
+
requestUrl.pathname !== "/api/claude/usage/oauth" &&
|
|
29
|
+
requestUrl.pathname !== "/api/claude/usage/cli"
|
|
30
|
+
) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (request.method !== "GET") {
|
|
35
|
+
writeMethodNotAllowed(response, corsOrigin);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const payload =
|
|
40
|
+
requestUrl.pathname === "/api/claude/usage/oauth"
|
|
41
|
+
? await readClaudeOauthUsageSnapshot()
|
|
42
|
+
: requestUrl.pathname === "/api/claude/usage/cli"
|
|
43
|
+
? await readClaudeCliUsageSnapshot()
|
|
44
|
+
: await readClaudeUsageSnapshot();
|
|
45
|
+
writeJson(response, 200, payload, corsOrigin);
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const handleUsageHeatmapRoute: ApiRouteHandler = async (
|
|
50
|
+
{ request, response, requestUrl, corsOrigin },
|
|
51
|
+
{ scanUsageHeatmap },
|
|
52
|
+
) => {
|
|
53
|
+
if (requestUrl.pathname !== "/api/analytics/usage-heatmap") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (request.method !== "GET") {
|
|
58
|
+
writeMethodNotAllowed(response, corsOrigin);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const scope = requestUrl.searchParams.get("scope") === "project" ? "project" : "all";
|
|
63
|
+
const payload = await scanUsageHeatmap(scope);
|
|
64
|
+
writeJson(response, 200, payload, corsOrigin);
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const handleGithubSummaryRoute: ApiRouteHandler = async (
|
|
69
|
+
{ request, response, requestUrl, corsOrigin },
|
|
70
|
+
{ readGithubRepoSummary },
|
|
71
|
+
) => {
|
|
72
|
+
if (requestUrl.pathname !== "/api/github/summary") {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (request.method !== "GET") {
|
|
77
|
+
writeMethodNotAllowed(response, corsOrigin);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const payload = await readGithubRepoSummary();
|
|
82
|
+
writeJson(response, 200, payload, corsOrigin);
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { cpSync, existsSync as fsExistsSync, mkdirSync, readdirSync } from "node:fs";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
import { scanClaudeUsageChart } from "./claudeSessionScanner";
|
|
6
|
+
import {
|
|
7
|
+
invalidateUsageCache as invalidateUsageCacheDefault,
|
|
8
|
+
readClaudeCliUsageSnapshot as readClaudeCliUsageSnapshotDefault,
|
|
9
|
+
readClaudeOauthUsageSnapshot as readClaudeOauthUsageSnapshotDefault,
|
|
10
|
+
readClaudeUsageSnapshot as readClaudeUsageSnapshotDefault,
|
|
11
|
+
} from "./claudeUsage";
|
|
12
|
+
import { createCodeIntelStore } from "./codeIntelStore";
|
|
13
|
+
import { readCodexUsageSnapshot as readCodexUsageSnapshotDefault } from "./codexUsage";
|
|
14
|
+
import { createApiRequestHandler } from "./createApiServer/requestHandler";
|
|
15
|
+
import type { CreateApiServerOptions } from "./createApiServer/types";
|
|
16
|
+
import { createUpgradeHandler } from "./createApiServer/upgradeHandler";
|
|
17
|
+
import { readGithubRepoSummary as readGithubRepoSummaryDefault } from "./githubRepoSummary";
|
|
18
|
+
import { createMonitorService } from "./monitor";
|
|
19
|
+
import { createTerminalRuntime } from "./terminalRuntime";
|
|
20
|
+
|
|
21
|
+
export const createApiServer = ({
|
|
22
|
+
workspaceCwd,
|
|
23
|
+
projectStateDir,
|
|
24
|
+
promptsDir,
|
|
25
|
+
webDistDir,
|
|
26
|
+
apiBaseUrl,
|
|
27
|
+
gitClient,
|
|
28
|
+
readClaudeUsageSnapshot,
|
|
29
|
+
readClaudeOauthUsageSnapshot,
|
|
30
|
+
readClaudeCliUsageSnapshot,
|
|
31
|
+
readCodexUsageSnapshot = readCodexUsageSnapshotDefault,
|
|
32
|
+
readGithubRepoSummary,
|
|
33
|
+
scanUsageHeatmap,
|
|
34
|
+
monitorService,
|
|
35
|
+
invalidateClaudeUsageCache = invalidateUsageCacheDefault,
|
|
36
|
+
allowRemoteAccess = false,
|
|
37
|
+
}: CreateApiServerOptions = {}) => {
|
|
38
|
+
const resolvedWorkspaceCwd = workspaceCwd ?? process.cwd();
|
|
39
|
+
// State lives in ~/.octogent/projects/<name>/ when provided, else falls back to <project>/.octogent/
|
|
40
|
+
const resolvedStateDir = projectStateDir ?? join(resolvedWorkspaceCwd, ".octogent");
|
|
41
|
+
let resolvedApiBaseUrl = apiBaseUrl ?? "http://127.0.0.1:8787";
|
|
42
|
+
const getApiBaseUrl = () => resolvedApiBaseUrl;
|
|
43
|
+
const getApiPort = () => {
|
|
44
|
+
try {
|
|
45
|
+
return String(new URL(resolvedApiBaseUrl).port || 80);
|
|
46
|
+
} catch {
|
|
47
|
+
return "8787";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const resolvedUserPromptsDir = join(resolvedStateDir, "prompts");
|
|
51
|
+
const resolvedCorePromptsDir = join(resolvedStateDir, "prompts", "core");
|
|
52
|
+
|
|
53
|
+
// Sync builtin prompts into the project state dir on every start so prompt
|
|
54
|
+
// changes in the repo take effect without requiring manual cache cleanup.
|
|
55
|
+
const sourceDir = promptsDir ?? join(resolvedWorkspaceCwd, "prompts");
|
|
56
|
+
if (fsExistsSync(sourceDir)) {
|
|
57
|
+
mkdirSync(resolvedCorePromptsDir, { recursive: true });
|
|
58
|
+
for (const file of readdirSync(sourceDir)) {
|
|
59
|
+
if (file.endsWith(".md")) {
|
|
60
|
+
cpSync(join(sourceDir, file), join(resolvedCorePromptsDir, file));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Read builtin prompts from the live source directory when available so new
|
|
66
|
+
// prompt files and prompt edits take effect without restarting the API.
|
|
67
|
+
// Keep the mirrored state copy as a fallback for packaged/runtime setups
|
|
68
|
+
// where the source prompts directory is unavailable.
|
|
69
|
+
const resolvedPromptsDir = fsExistsSync(sourceDir) ? sourceDir : resolvedCorePromptsDir;
|
|
70
|
+
const readClaudeUsageSnapshotWithDefault =
|
|
71
|
+
readClaudeUsageSnapshot ??
|
|
72
|
+
(() =>
|
|
73
|
+
readClaudeUsageSnapshotDefault({
|
|
74
|
+
projectStateDir: resolvedStateDir,
|
|
75
|
+
backgroundRefreshOnly: true,
|
|
76
|
+
}));
|
|
77
|
+
const readClaudeOauthUsageSnapshotWithDefault =
|
|
78
|
+
readClaudeOauthUsageSnapshot ??
|
|
79
|
+
(() =>
|
|
80
|
+
readClaudeOauthUsageSnapshotDefault({
|
|
81
|
+
projectStateDir: resolvedStateDir,
|
|
82
|
+
}));
|
|
83
|
+
const readClaudeCliUsageSnapshotWithDefault =
|
|
84
|
+
readClaudeCliUsageSnapshot ??
|
|
85
|
+
(() =>
|
|
86
|
+
readClaudeCliUsageSnapshotDefault({
|
|
87
|
+
projectStateDir: resolvedStateDir,
|
|
88
|
+
}));
|
|
89
|
+
const readGithubRepoSummaryWithDefault =
|
|
90
|
+
readGithubRepoSummary ??
|
|
91
|
+
(() =>
|
|
92
|
+
readGithubRepoSummaryDefault({
|
|
93
|
+
cwd: resolvedWorkspaceCwd,
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
const runtimeOptions: Parameters<typeof createTerminalRuntime>[0] = {
|
|
97
|
+
workspaceCwd: resolvedWorkspaceCwd,
|
|
98
|
+
projectStateDir: resolvedStateDir,
|
|
99
|
+
getApiBaseUrl,
|
|
100
|
+
};
|
|
101
|
+
if (gitClient) {
|
|
102
|
+
runtimeOptions.gitClient = gitClient;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const runtime = createTerminalRuntime(runtimeOptions);
|
|
106
|
+
const monitorServiceWithDefault =
|
|
107
|
+
monitorService ??
|
|
108
|
+
createMonitorService({
|
|
109
|
+
projectStateDir: resolvedStateDir,
|
|
110
|
+
});
|
|
111
|
+
const scanUsageHeatmapWithDefault =
|
|
112
|
+
scanUsageHeatmap ??
|
|
113
|
+
((scope: "all" | "project") => scanClaudeUsageChart(scope, resolvedWorkspaceCwd));
|
|
114
|
+
|
|
115
|
+
const codeIntelStore = createCodeIntelStore(resolvedStateDir);
|
|
116
|
+
|
|
117
|
+
const requestHandler = createApiRequestHandler({
|
|
118
|
+
runtime,
|
|
119
|
+
workspaceCwd: resolvedWorkspaceCwd,
|
|
120
|
+
projectStateDir: resolvedStateDir,
|
|
121
|
+
promptsDir: resolvedPromptsDir,
|
|
122
|
+
userPromptsDir: resolvedUserPromptsDir,
|
|
123
|
+
webDistDir,
|
|
124
|
+
getApiBaseUrl,
|
|
125
|
+
getApiPort,
|
|
126
|
+
readClaudeUsageSnapshot: readClaudeUsageSnapshotWithDefault,
|
|
127
|
+
readClaudeOauthUsageSnapshot: readClaudeOauthUsageSnapshotWithDefault,
|
|
128
|
+
readClaudeCliUsageSnapshot: readClaudeCliUsageSnapshotWithDefault,
|
|
129
|
+
readCodexUsageSnapshot,
|
|
130
|
+
readGithubRepoSummary: readGithubRepoSummaryWithDefault,
|
|
131
|
+
scanUsageHeatmap: scanUsageHeatmapWithDefault,
|
|
132
|
+
monitorService: monitorServiceWithDefault,
|
|
133
|
+
invalidateClaudeUsageCache,
|
|
134
|
+
codeIntelStore,
|
|
135
|
+
allowRemoteAccess,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const server = createServer(requestHandler);
|
|
139
|
+
|
|
140
|
+
server.on(
|
|
141
|
+
"upgrade",
|
|
142
|
+
createUpgradeHandler({
|
|
143
|
+
runtime,
|
|
144
|
+
allowRemoteAccess,
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
server,
|
|
150
|
+
async start(port = 8787, host = "127.0.0.1") {
|
|
151
|
+
await new Promise<void>((resolveStart, rejectStart) => {
|
|
152
|
+
server.listen(port, host, () => resolveStart());
|
|
153
|
+
server.once("error", rejectStart);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const address = server.address();
|
|
157
|
+
const resolvedPort = typeof address === "object" && address ? address.port : port;
|
|
158
|
+
resolvedApiBaseUrl = `http://${host}:${resolvedPort}`;
|
|
159
|
+
|
|
160
|
+
return { host, port: resolvedPort };
|
|
161
|
+
},
|
|
162
|
+
async stop() {
|
|
163
|
+
await runtime.close();
|
|
164
|
+
await new Promise<void>((resolveStop, rejectStop) => {
|
|
165
|
+
server.close((error) => {
|
|
166
|
+
if (error) {
|
|
167
|
+
rejectStop(error);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
resolveStop();
|
|
171
|
+
});
|
|
172
|
+
server.closeAllConnections();
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
};
|