@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,135 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { TENTACLE_WORKTREE_BRANCH_PREFIX, TENTACLE_WORKTREE_RELATIVE_PATH } from "./constants";
|
|
5
|
+
import { toErrorMessage } from "./systemClients";
|
|
6
|
+
import type { GitClient, PersistedTerminal } from "./types";
|
|
7
|
+
import { RuntimeInputError } from "./types";
|
|
8
|
+
|
|
9
|
+
type CreateWorktreeManagerOptions = {
|
|
10
|
+
workspaceCwd: string;
|
|
11
|
+
gitClient: GitClient;
|
|
12
|
+
terminals: Map<string, PersistedTerminal>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type RemoveTentacleWorktreeOptions = {
|
|
16
|
+
bestEffort?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Resolve the effective worktree identifier for a terminal. */
|
|
20
|
+
const getEffectiveWorktreeId = (terminal: PersistedTerminal): string =>
|
|
21
|
+
terminal.worktreeId ?? terminal.tentacleId;
|
|
22
|
+
|
|
23
|
+
/** Find any terminal whose effective worktree identifier matches. */
|
|
24
|
+
const findTerminalForWorktree = (
|
|
25
|
+
terminals: Map<string, PersistedTerminal>,
|
|
26
|
+
worktreeIdentifier: string,
|
|
27
|
+
): PersistedTerminal | undefined => {
|
|
28
|
+
for (const terminal of terminals.values()) {
|
|
29
|
+
if (getEffectiveWorktreeId(terminal) === worktreeIdentifier) {
|
|
30
|
+
return terminal;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const createWorktreeManager = ({
|
|
37
|
+
workspaceCwd,
|
|
38
|
+
gitClient,
|
|
39
|
+
terminals,
|
|
40
|
+
}: CreateWorktreeManagerOptions) => {
|
|
41
|
+
const getTentacleWorktreePath = (tentacleId: string) =>
|
|
42
|
+
join(workspaceCwd, TENTACLE_WORKTREE_RELATIVE_PATH, tentacleId);
|
|
43
|
+
const getTentacleBranchName = (tentacleId: string) =>
|
|
44
|
+
`${TENTACLE_WORKTREE_BRANCH_PREFIX}${tentacleId}`;
|
|
45
|
+
|
|
46
|
+
const getTentacleWorkspaceCwd = (worktreeIdentifier: string) => {
|
|
47
|
+
const terminal = findTerminalForWorktree(terminals, worktreeIdentifier);
|
|
48
|
+
if (!terminal) {
|
|
49
|
+
throw new Error(`No terminal found for worktree: ${worktreeIdentifier}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (terminal.workspaceMode === "worktree") {
|
|
53
|
+
return getTentacleWorktreePath(worktreeIdentifier);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return workspaceCwd;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const assertWorktreeCreationSupported = () => {
|
|
60
|
+
gitClient.assertAvailable();
|
|
61
|
+
if (!gitClient.isRepository(workspaceCwd)) {
|
|
62
|
+
throw new RuntimeInputError(
|
|
63
|
+
"Worktree terminals require a git repository at the workspace root.",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const createTentacleWorktree = (tentacleId: string, baseRef = "HEAD") => {
|
|
69
|
+
assertWorktreeCreationSupported();
|
|
70
|
+
const worktreePath = getTentacleWorktreePath(tentacleId);
|
|
71
|
+
if (existsSync(worktreePath)) {
|
|
72
|
+
throw new RuntimeInputError(`Worktree path already exists: ${worktreePath}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
gitClient.addWorktree({
|
|
77
|
+
cwd: workspaceCwd,
|
|
78
|
+
path: worktreePath,
|
|
79
|
+
branchName: `${TENTACLE_WORKTREE_BRANCH_PREFIX}${tentacleId}`,
|
|
80
|
+
baseRef,
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error(`Unable to create worktree for ${tentacleId}: ${toErrorMessage(error)}`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const hasTentacleWorktree = (tentacleId: string): boolean =>
|
|
88
|
+
existsSync(getTentacleWorktreePath(tentacleId));
|
|
89
|
+
|
|
90
|
+
const removeTentacleWorktree = (
|
|
91
|
+
tentacleId: string,
|
|
92
|
+
options: RemoveTentacleWorktreeOptions = {},
|
|
93
|
+
) => {
|
|
94
|
+
const { bestEffort = false } = options;
|
|
95
|
+
const worktreePath = getTentacleWorktreePath(tentacleId);
|
|
96
|
+
const branchName = getTentacleBranchName(tentacleId);
|
|
97
|
+
|
|
98
|
+
if (existsSync(worktreePath)) {
|
|
99
|
+
try {
|
|
100
|
+
gitClient.removeWorktree({
|
|
101
|
+
cwd: workspaceCwd,
|
|
102
|
+
path: worktreePath,
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (bestEffort) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
throw new RuntimeInputError(
|
|
109
|
+
`Unable to remove worktree for ${tentacleId}: ${toErrorMessage(error)}`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
gitClient.removeBranch({
|
|
116
|
+
cwd: workspaceCwd,
|
|
117
|
+
branchName,
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (bestEffort) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
throw new RuntimeInputError(
|
|
124
|
+
`Unable to remove branch for ${tentacleId}: ${toErrorMessage(error)}`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
getTentacleWorkspaceCwd,
|
|
131
|
+
createTentacleWorktree,
|
|
132
|
+
hasTentacleWorktree,
|
|
133
|
+
removeTentacleWorktree,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { Duplex } from "node:stream";
|
|
4
|
+
|
|
5
|
+
import type { TerminalSnapshot } from "@octogent/core";
|
|
6
|
+
import type { WebSocket } from "ws";
|
|
7
|
+
import { WebSocketServer } from "ws";
|
|
8
|
+
|
|
9
|
+
import { createChannelMessaging } from "./terminalRuntime/channelMessaging";
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_AGENT_PROVIDER,
|
|
12
|
+
DEFAULT_TERMINAL_INACTIVITY_THRESHOLD_MS,
|
|
13
|
+
TERMINAL_ID_PREFIX,
|
|
14
|
+
} from "./terminalRuntime/constants";
|
|
15
|
+
import {
|
|
16
|
+
conversationExportMarkdown,
|
|
17
|
+
deleteAllConversations,
|
|
18
|
+
deleteConversation,
|
|
19
|
+
listConversationSessions,
|
|
20
|
+
readConversationSession,
|
|
21
|
+
searchConversations,
|
|
22
|
+
} from "./terminalRuntime/conversations";
|
|
23
|
+
import { createGitOperations } from "./terminalRuntime/gitOperations";
|
|
24
|
+
import { createHookProcessor } from "./terminalRuntime/hookProcessor";
|
|
25
|
+
import {
|
|
26
|
+
createTerminalRegistryPersistence,
|
|
27
|
+
loadTerminalRegistry,
|
|
28
|
+
pruneUiStateTerminalReferences,
|
|
29
|
+
} from "./terminalRuntime/registry";
|
|
30
|
+
import { createSessionRuntime } from "./terminalRuntime/sessionRuntime";
|
|
31
|
+
import { createDefaultGitClient } from "./terminalRuntime/systemClients";
|
|
32
|
+
import type { DirectSessionListener } from "./terminalRuntime/types";
|
|
33
|
+
import {
|
|
34
|
+
type CreateTerminalRuntimeOptions,
|
|
35
|
+
type PersistedTerminal,
|
|
36
|
+
type PersistedUiState,
|
|
37
|
+
RuntimeInputError,
|
|
38
|
+
type TentacleWorkspaceMode,
|
|
39
|
+
type TerminalAgentProvider,
|
|
40
|
+
type TerminalNameOrigin,
|
|
41
|
+
type TerminalSession,
|
|
42
|
+
} from "./terminalRuntime/types";
|
|
43
|
+
import { createWorktreeManager } from "./terminalRuntime/worktreeManager";
|
|
44
|
+
|
|
45
|
+
export type {
|
|
46
|
+
GitClient,
|
|
47
|
+
PersistedUiState,
|
|
48
|
+
TerminalAgentProvider,
|
|
49
|
+
TerminalNameOrigin,
|
|
50
|
+
TentacleWorkspaceMode,
|
|
51
|
+
} from "./terminalRuntime/types";
|
|
52
|
+
export { isTerminalAgentProvider, isTerminalCompletionSoundId } from "./terminalRuntime/types";
|
|
53
|
+
export { RuntimeInputError } from "./terminalRuntime/types";
|
|
54
|
+
|
|
55
|
+
export const MAX_CHILDREN_PER_PARENT = 9;
|
|
56
|
+
|
|
57
|
+
export const createTerminalRuntime = ({
|
|
58
|
+
workspaceCwd,
|
|
59
|
+
projectStateDir,
|
|
60
|
+
gitClient = createDefaultGitClient(),
|
|
61
|
+
getApiBaseUrl = () => process.env.OCTOGENT_API_ORIGIN ?? "http://127.0.0.1:8787",
|
|
62
|
+
}: CreateTerminalRuntimeOptions) => {
|
|
63
|
+
const stateDir = projectStateDir ?? join(workspaceCwd, ".octogent");
|
|
64
|
+
const sessions = new Map<string, TerminalSession>();
|
|
65
|
+
const websocketServer = new WebSocketServer({ noServer: true });
|
|
66
|
+
const terminalEventsWebsocketServer = new WebSocketServer({ noServer: true });
|
|
67
|
+
const terminalEventClients = new Set<WebSocket>();
|
|
68
|
+
const registryPath = join(stateDir, "state", "tentacles.json");
|
|
69
|
+
const registryState = loadTerminalRegistry(registryPath);
|
|
70
|
+
const registryPersistence = createTerminalRegistryPersistence(registryPath);
|
|
71
|
+
const terminals = registryState.terminals;
|
|
72
|
+
let uiState = registryState.uiState;
|
|
73
|
+
const isDebugPtyLogsEnabled = process.env.OCTOGENT_DEBUG_PTY_LOGS === "1";
|
|
74
|
+
const ptyLogDir = process.env.OCTOGENT_DEBUG_PTY_LOG_DIR ?? join(stateDir, "logs");
|
|
75
|
+
const transcriptDirectoryPath = join(stateDir, "state", "transcripts");
|
|
76
|
+
const persistRegistry = () => {
|
|
77
|
+
uiState = pruneUiStateTerminalReferences(uiState, terminals);
|
|
78
|
+
registryPersistence.schedulePersist({
|
|
79
|
+
terminals,
|
|
80
|
+
uiState,
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const worktreeManager = createWorktreeManager({
|
|
85
|
+
workspaceCwd,
|
|
86
|
+
gitClient,
|
|
87
|
+
terminals,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const resolveTerminalSession = (
|
|
91
|
+
terminalId: string,
|
|
92
|
+
): { sessionId: string; tentacleId: string } | null => {
|
|
93
|
+
const terminal = terminals.get(terminalId);
|
|
94
|
+
if (terminal) {
|
|
95
|
+
return {
|
|
96
|
+
sessionId: terminalId,
|
|
97
|
+
tentacleId: terminal.worktreeId ?? terminal.tentacleId,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const broadcastTerminalStateChanged = (
|
|
105
|
+
terminalId: string,
|
|
106
|
+
agentRuntimeState: string,
|
|
107
|
+
toolName?: string,
|
|
108
|
+
) => {
|
|
109
|
+
broadcastTerminalEvent({
|
|
110
|
+
type: "terminal-state-changed",
|
|
111
|
+
terminalId,
|
|
112
|
+
agentRuntimeState,
|
|
113
|
+
...(toolName ? { toolName } : {}),
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const sessionRuntime = createSessionRuntime({
|
|
118
|
+
websocketServer,
|
|
119
|
+
terminals,
|
|
120
|
+
sessions,
|
|
121
|
+
resolveTerminalSession,
|
|
122
|
+
getTentacleWorkspaceCwd: worktreeManager.getTentacleWorkspaceCwd,
|
|
123
|
+
isDebugPtyLogsEnabled,
|
|
124
|
+
ptyLogDir,
|
|
125
|
+
transcriptDirectoryPath,
|
|
126
|
+
onStateChange: broadcastTerminalStateChanged,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const gitOps = createGitOperations({
|
|
130
|
+
terminals,
|
|
131
|
+
worktreeManager,
|
|
132
|
+
gitClient,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const channelMessaging = createChannelMessaging({
|
|
136
|
+
terminals,
|
|
137
|
+
sessions,
|
|
138
|
+
writeInput: (terminalId: string, data: string) => sessionRuntime.writeInput(terminalId, data),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const hookProcessor = createHookProcessor({
|
|
142
|
+
terminals,
|
|
143
|
+
sessions,
|
|
144
|
+
transcriptDirectoryPath,
|
|
145
|
+
getApiBaseUrl,
|
|
146
|
+
persistRegistry,
|
|
147
|
+
deliverChannelMessages: channelMessaging.deliverChannelMessages,
|
|
148
|
+
onStateChange: broadcastTerminalStateChanged,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const allocateTerminalId = () => {
|
|
152
|
+
let candidateNumber = 1;
|
|
153
|
+
while (candidateNumber < Number.MAX_SAFE_INTEGER) {
|
|
154
|
+
const candidateId = `${TERMINAL_ID_PREFIX}${candidateNumber}`;
|
|
155
|
+
if (terminals.has(candidateId)) {
|
|
156
|
+
candidateNumber += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (sessions.has(candidateId)) {
|
|
161
|
+
candidateNumber += 1;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (worktreeManager.hasTentacleWorktree(candidateId)) {
|
|
166
|
+
candidateNumber += 1;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return candidateId;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
throw new Error("Unable to allocate terminal id.");
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const allocateDefaultTerminalName = (): string => {
|
|
177
|
+
const usedNumbers = new Set<number>();
|
|
178
|
+
const pattern = /^Octogent Terminal (\d+)$/;
|
|
179
|
+
for (const t of terminals.values()) {
|
|
180
|
+
const match = pattern.exec(t.tentacleName);
|
|
181
|
+
if (match) usedNumbers.add(Number(match[1]));
|
|
182
|
+
}
|
|
183
|
+
let n = 1;
|
|
184
|
+
while (usedNumbers.has(n)) n++;
|
|
185
|
+
return `Octogent Terminal ${n}`;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const isTerminalRecentlyActive = (terminal: PersistedTerminal): boolean => {
|
|
189
|
+
if (!terminal.lastActiveAt) return false;
|
|
190
|
+
const thresholdMs =
|
|
191
|
+
uiState.terminalInactivityThresholdMs ?? DEFAULT_TERMINAL_INACTIVITY_THRESHOLD_MS;
|
|
192
|
+
return Date.now() - new Date(terminal.lastActiveAt).getTime() < thresholdMs;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const toTerminalSnapshot = (terminal: PersistedTerminal): TerminalSnapshot => {
|
|
196
|
+
const session = sessions.get(terminal.terminalId);
|
|
197
|
+
return {
|
|
198
|
+
terminalId: terminal.terminalId,
|
|
199
|
+
label: terminal.terminalId,
|
|
200
|
+
state: "live",
|
|
201
|
+
tentacleId: terminal.tentacleId,
|
|
202
|
+
tentacleName: terminal.tentacleName,
|
|
203
|
+
workspaceMode: terminal.workspaceMode,
|
|
204
|
+
createdAt: terminal.createdAt,
|
|
205
|
+
hasUserPrompt: isTerminalRecentlyActive(terminal),
|
|
206
|
+
...(terminal.parentTerminalId ? { parentTerminalId: terminal.parentTerminalId } : {}),
|
|
207
|
+
...(session ? { agentRuntimeState: session.agentState } : {}),
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const broadcastTerminalEvent = (event: Record<string, unknown>) => {
|
|
212
|
+
const payload = JSON.stringify(event);
|
|
213
|
+
for (const client of terminalEventClients) {
|
|
214
|
+
if (client.readyState !== 1) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
client.send(payload);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const broadcastTerminalListChanged = () => {
|
|
222
|
+
broadcastTerminalEvent({ type: "terminal-list-changed" });
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const collectTerminalCascade = (rootTerminalId: string): string[] => {
|
|
226
|
+
const toDelete = new Set<string>();
|
|
227
|
+
const queue = [rootTerminalId];
|
|
228
|
+
|
|
229
|
+
while (queue.length > 0) {
|
|
230
|
+
const currentTerminalId = queue.shift();
|
|
231
|
+
if (!currentTerminalId || toDelete.has(currentTerminalId)) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
toDelete.add(currentTerminalId);
|
|
236
|
+
for (const terminal of terminals.values()) {
|
|
237
|
+
if (terminal.parentTerminalId === currentTerminalId) {
|
|
238
|
+
queue.push(terminal.terminalId);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return Array.from(toDelete);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const createTerminal = ({
|
|
247
|
+
terminalId: requestedTerminalId,
|
|
248
|
+
tentacleId: requestedTentacleId,
|
|
249
|
+
worktreeId: requestedWorktreeId,
|
|
250
|
+
tentacleName,
|
|
251
|
+
workspaceMode = "shared",
|
|
252
|
+
agentProvider,
|
|
253
|
+
initialPrompt,
|
|
254
|
+
initialInputDraft,
|
|
255
|
+
baseRef,
|
|
256
|
+
parentTerminalId,
|
|
257
|
+
nameOrigin,
|
|
258
|
+
autoRenamePromptContext,
|
|
259
|
+
}: {
|
|
260
|
+
terminalId?: string;
|
|
261
|
+
tentacleId?: string;
|
|
262
|
+
worktreeId?: string;
|
|
263
|
+
tentacleName?: string;
|
|
264
|
+
workspaceMode?: TentacleWorkspaceMode;
|
|
265
|
+
agentProvider?: TerminalAgentProvider;
|
|
266
|
+
initialPrompt?: string;
|
|
267
|
+
initialInputDraft?: string;
|
|
268
|
+
baseRef?: string;
|
|
269
|
+
parentTerminalId?: string;
|
|
270
|
+
nameOrigin?: TerminalNameOrigin;
|
|
271
|
+
autoRenamePromptContext?: string;
|
|
272
|
+
}): TerminalSnapshot => {
|
|
273
|
+
// Enforce max children per parent.
|
|
274
|
+
if (parentTerminalId) {
|
|
275
|
+
const childCount = [...terminals.values()].filter(
|
|
276
|
+
(t) => t.parentTerminalId === parentTerminalId,
|
|
277
|
+
).length;
|
|
278
|
+
if (childCount >= MAX_CHILDREN_PER_PARENT) {
|
|
279
|
+
throw new RuntimeInputError(
|
|
280
|
+
`Parent terminal "${parentTerminalId}" already has ${MAX_CHILDREN_PER_PARENT} children (limit reached).`,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const terminalId =
|
|
286
|
+
requestedTerminalId && !terminals.has(requestedTerminalId)
|
|
287
|
+
? requestedTerminalId
|
|
288
|
+
: allocateTerminalId();
|
|
289
|
+
|
|
290
|
+
// Allow explicit tentacleId so multiple terminals can share a tentacle context (e.g. swarm workers).
|
|
291
|
+
const tentacleId = requestedTentacleId ?? terminalId;
|
|
292
|
+
const effectiveName = tentacleName ?? allocateDefaultTerminalName();
|
|
293
|
+
|
|
294
|
+
// Auto-allocate a unique worktreeId when creating a worktree terminal
|
|
295
|
+
// so multiple worktree terminals can coexist (each gets its own directory).
|
|
296
|
+
const worktreeId =
|
|
297
|
+
requestedWorktreeId ?? (workspaceMode === "worktree" ? terminalId : undefined);
|
|
298
|
+
|
|
299
|
+
const terminal: PersistedTerminal = {
|
|
300
|
+
terminalId,
|
|
301
|
+
tentacleId,
|
|
302
|
+
...(worktreeId ? { worktreeId } : {}),
|
|
303
|
+
tentacleName: effectiveName,
|
|
304
|
+
nameOrigin: nameOrigin ?? (tentacleName ? "user" : "generated"),
|
|
305
|
+
...(autoRenamePromptContext ? { autoRenamePromptContext } : {}),
|
|
306
|
+
createdAt: new Date().toISOString(),
|
|
307
|
+
workspaceMode,
|
|
308
|
+
agentProvider: agentProvider ?? DEFAULT_AGENT_PROVIDER,
|
|
309
|
+
...(initialPrompt ? { initialPrompt } : {}),
|
|
310
|
+
...(initialInputDraft ? { initialInputDraft } : {}),
|
|
311
|
+
...(initialPrompt ? { lastActiveAt: new Date().toISOString() } : {}),
|
|
312
|
+
...(parentTerminalId ? { parentTerminalId } : {}),
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const effectiveWorktreeId = worktreeId ?? tentacleId;
|
|
316
|
+
const shouldCreateWorktree = workspaceMode === "worktree";
|
|
317
|
+
if (shouldCreateWorktree) {
|
|
318
|
+
worktreeManager.createTentacleWorktree(effectiveWorktreeId, baseRef);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (terminal.agentProvider === "claude-code") {
|
|
322
|
+
// Claude hooks should only be installed for Claude-backed terminals.
|
|
323
|
+
try {
|
|
324
|
+
const hookTargetCwd = shouldCreateWorktree
|
|
325
|
+
? worktreeManager.getTentacleWorkspaceCwd(effectiveWorktreeId)
|
|
326
|
+
: workspaceCwd;
|
|
327
|
+
hookProcessor.installHooksInDirectory(hookTargetCwd);
|
|
328
|
+
} catch {
|
|
329
|
+
// Best-effort: hook installation should not block terminal creation.
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
terminals.set(terminalId, terminal);
|
|
334
|
+
persistRegistry();
|
|
335
|
+
broadcastTerminalEvent({
|
|
336
|
+
type: "terminal-created",
|
|
337
|
+
snapshot: toTerminalSnapshot(terminal),
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
if (initialPrompt) {
|
|
341
|
+
sessionRuntime.startSession(terminalId);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return toTerminalSnapshot(terminal);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const readUiState = (): PersistedUiState => {
|
|
348
|
+
const normalized = pruneUiStateTerminalReferences(uiState, terminals);
|
|
349
|
+
const result: PersistedUiState = { ...normalized };
|
|
350
|
+
if (normalized.minimizedTerminalIds) {
|
|
351
|
+
result.minimizedTerminalIds = [...normalized.minimizedTerminalIds];
|
|
352
|
+
}
|
|
353
|
+
if (normalized.terminalWidths) {
|
|
354
|
+
result.terminalWidths = { ...normalized.terminalWidths };
|
|
355
|
+
}
|
|
356
|
+
if (normalized.terminalCompletionSound !== undefined) {
|
|
357
|
+
result.terminalCompletionSound = normalized.terminalCompletionSound;
|
|
358
|
+
}
|
|
359
|
+
return result;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
listTerminalSnapshots(): TerminalSnapshot[] {
|
|
364
|
+
const snapshots: TerminalSnapshot[] = [];
|
|
365
|
+
for (const terminal of terminals.values()) {
|
|
366
|
+
snapshots.push(toTerminalSnapshot(terminal));
|
|
367
|
+
}
|
|
368
|
+
return snapshots;
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
listConversationSessions() {
|
|
372
|
+
return listConversationSessions(transcriptDirectoryPath);
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
readConversationSession(sessionId: string) {
|
|
376
|
+
return readConversationSession(transcriptDirectoryPath, sessionId);
|
|
377
|
+
},
|
|
378
|
+
|
|
379
|
+
exportConversationSession(sessionId: string, format: "json" | "md") {
|
|
380
|
+
const conversation = readConversationSession(transcriptDirectoryPath, sessionId);
|
|
381
|
+
if (!conversation) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (format === "json") {
|
|
386
|
+
const exported = {
|
|
387
|
+
turns: conversation.turns,
|
|
388
|
+
};
|
|
389
|
+
return `${JSON.stringify(exported, null, 2)}\n`;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return conversationExportMarkdown(conversation);
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
deleteConversationSession(sessionId: string) {
|
|
396
|
+
deleteConversation(transcriptDirectoryPath, sessionId);
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
deleteAllConversationSessions() {
|
|
400
|
+
deleteAllConversations(transcriptDirectoryPath);
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
searchConversations(query: string) {
|
|
404
|
+
return searchConversations(transcriptDirectoryPath, query);
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
readUiState,
|
|
408
|
+
|
|
409
|
+
patchUiState(patch: PersistedUiState): PersistedUiState {
|
|
410
|
+
if (patch.activePrimaryNav !== undefined) {
|
|
411
|
+
uiState.activePrimaryNav = patch.activePrimaryNav;
|
|
412
|
+
}
|
|
413
|
+
if (patch.isAgentsSidebarVisible !== undefined) {
|
|
414
|
+
uiState.isAgentsSidebarVisible = patch.isAgentsSidebarVisible;
|
|
415
|
+
}
|
|
416
|
+
if (patch.sidebarWidth !== undefined) {
|
|
417
|
+
uiState.sidebarWidth = patch.sidebarWidth;
|
|
418
|
+
}
|
|
419
|
+
if (patch.isActiveAgentsSectionExpanded !== undefined) {
|
|
420
|
+
uiState.isActiveAgentsSectionExpanded = patch.isActiveAgentsSectionExpanded;
|
|
421
|
+
}
|
|
422
|
+
if (patch.isRuntimeStatusStripVisible !== undefined) {
|
|
423
|
+
uiState.isRuntimeStatusStripVisible = patch.isRuntimeStatusStripVisible;
|
|
424
|
+
}
|
|
425
|
+
if (patch.isMonitorVisible !== undefined) {
|
|
426
|
+
uiState.isMonitorVisible = patch.isMonitorVisible;
|
|
427
|
+
}
|
|
428
|
+
if (patch.isBottomTelemetryVisible !== undefined) {
|
|
429
|
+
uiState.isBottomTelemetryVisible = patch.isBottomTelemetryVisible;
|
|
430
|
+
}
|
|
431
|
+
if (patch.isCodexUsageVisible !== undefined) {
|
|
432
|
+
uiState.isCodexUsageVisible = patch.isCodexUsageVisible;
|
|
433
|
+
}
|
|
434
|
+
if (patch.isClaudeUsageVisible !== undefined) {
|
|
435
|
+
uiState.isClaudeUsageVisible = patch.isClaudeUsageVisible;
|
|
436
|
+
}
|
|
437
|
+
if (patch.isClaudeUsageSectionExpanded !== undefined) {
|
|
438
|
+
uiState.isClaudeUsageSectionExpanded = patch.isClaudeUsageSectionExpanded;
|
|
439
|
+
}
|
|
440
|
+
if (patch.isCodexUsageSectionExpanded !== undefined) {
|
|
441
|
+
uiState.isCodexUsageSectionExpanded = patch.isCodexUsageSectionExpanded;
|
|
442
|
+
}
|
|
443
|
+
if (patch.terminalCompletionSound !== undefined) {
|
|
444
|
+
uiState.terminalCompletionSound = patch.terminalCompletionSound;
|
|
445
|
+
}
|
|
446
|
+
if (patch.minimizedTerminalIds !== undefined) {
|
|
447
|
+
uiState.minimizedTerminalIds = [...patch.minimizedTerminalIds];
|
|
448
|
+
}
|
|
449
|
+
if (patch.terminalWidths !== undefined) {
|
|
450
|
+
uiState.terminalWidths = { ...patch.terminalWidths };
|
|
451
|
+
}
|
|
452
|
+
if (patch.canvasOpenTerminalIds !== undefined) {
|
|
453
|
+
uiState.canvasOpenTerminalIds = [...patch.canvasOpenTerminalIds];
|
|
454
|
+
}
|
|
455
|
+
if (patch.canvasOpenTentacleIds !== undefined) {
|
|
456
|
+
uiState.canvasOpenTentacleIds = [...patch.canvasOpenTentacleIds];
|
|
457
|
+
}
|
|
458
|
+
if (patch.canvasTerminalsPanelWidth !== undefined) {
|
|
459
|
+
uiState.canvasTerminalsPanelWidth = patch.canvasTerminalsPanelWidth;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
persistRegistry();
|
|
463
|
+
return readUiState();
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
...gitOps,
|
|
467
|
+
|
|
468
|
+
createTerminal,
|
|
469
|
+
|
|
470
|
+
renameTerminal(terminalId: string, tentacleName: string): TerminalSnapshot | null {
|
|
471
|
+
const terminal = terminals.get(terminalId);
|
|
472
|
+
if (!terminal) {
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
terminal.tentacleName = tentacleName;
|
|
477
|
+
terminal.nameOrigin = "user";
|
|
478
|
+
terminal.autoRenamePromptContext = undefined;
|
|
479
|
+
persistRegistry();
|
|
480
|
+
broadcastTerminalEvent({
|
|
481
|
+
type: "terminal-updated",
|
|
482
|
+
snapshot: toTerminalSnapshot(terminal),
|
|
483
|
+
});
|
|
484
|
+
return toTerminalSnapshot(terminal);
|
|
485
|
+
},
|
|
486
|
+
|
|
487
|
+
deleteTerminal(terminalId: string): boolean {
|
|
488
|
+
const terminal = terminals.get(terminalId);
|
|
489
|
+
if (!terminal) {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const cascadeTerminalIds = collectTerminalCascade(terminalId);
|
|
494
|
+
for (const cascadeTerminalId of cascadeTerminalIds) {
|
|
495
|
+
const cascadeTerminal = terminals.get(cascadeTerminalId);
|
|
496
|
+
if (!cascadeTerminal) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
sessionRuntime.closeSession(cascadeTerminalId);
|
|
501
|
+
if (cascadeTerminal.workspaceMode === "worktree") {
|
|
502
|
+
worktreeManager.removeTentacleWorktree(
|
|
503
|
+
cascadeTerminal.worktreeId ?? cascadeTerminal.tentacleId,
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
terminals.delete(cascadeTerminalId);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
persistRegistry();
|
|
510
|
+
for (const cascadeTerminalId of cascadeTerminalIds) {
|
|
511
|
+
broadcastTerminalEvent({
|
|
512
|
+
type: "terminal-deleted",
|
|
513
|
+
terminalId: cascadeTerminalId,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return true;
|
|
517
|
+
},
|
|
518
|
+
|
|
519
|
+
...channelMessaging,
|
|
520
|
+
|
|
521
|
+
handleHook: hookProcessor.handleHook,
|
|
522
|
+
|
|
523
|
+
handleUpgrade(request: IncomingMessage, socket: Duplex, head: Buffer): boolean {
|
|
524
|
+
let requestUrl: URL;
|
|
525
|
+
try {
|
|
526
|
+
requestUrl = new URL(request.url ?? "/", "http://localhost");
|
|
527
|
+
} catch {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (requestUrl.pathname === "/api/terminal-events/ws") {
|
|
532
|
+
terminalEventsWebsocketServer.handleUpgrade(request, socket, head, (websocket) => {
|
|
533
|
+
terminalEventClients.add(websocket);
|
|
534
|
+
websocket.on("close", () => {
|
|
535
|
+
terminalEventClients.delete(websocket);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return sessionRuntime.handleUpgrade(request, socket, head);
|
|
542
|
+
},
|
|
543
|
+
|
|
544
|
+
connectDirect(terminalId: string, listener: DirectSessionListener): (() => void) | null {
|
|
545
|
+
return sessionRuntime.connectDirect(terminalId, listener);
|
|
546
|
+
},
|
|
547
|
+
|
|
548
|
+
writeInput(terminalId: string, data: string): boolean {
|
|
549
|
+
return sessionRuntime.writeInput(terminalId, data);
|
|
550
|
+
},
|
|
551
|
+
|
|
552
|
+
resizeTerminal(terminalId: string, cols: number, rows: number): boolean {
|
|
553
|
+
return sessionRuntime.resizeSession(terminalId, cols, rows);
|
|
554
|
+
},
|
|
555
|
+
|
|
556
|
+
async close() {
|
|
557
|
+
await registryPersistence.close();
|
|
558
|
+
sessionRuntime.close();
|
|
559
|
+
for (const client of terminalEventClients) {
|
|
560
|
+
client.close();
|
|
561
|
+
}
|
|
562
|
+
terminalEventClients.clear();
|
|
563
|
+
terminalEventsWebsocketServer.close();
|
|
564
|
+
websocketServer.close();
|
|
565
|
+
},
|
|
566
|
+
};
|
|
567
|
+
};
|