@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,405 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { logVerbose } from "../logging";
|
|
5
|
+
import { parseClaudeTranscript } from "./claudeTranscript";
|
|
6
|
+
import { storeClaudeTranscriptTurns } from "./conversations";
|
|
7
|
+
import { broadcastMessage } from "./protocol";
|
|
8
|
+
import type { PersistedTerminal, TerminalSession } from "./types";
|
|
9
|
+
|
|
10
|
+
const MAX_AUTO_NAME_LENGTH = 50;
|
|
11
|
+
|
|
12
|
+
const deriveTerminalNameFromPrompt = (prompt: string): string => {
|
|
13
|
+
const normalized = prompt.replace(/\s+/g, " ").trim();
|
|
14
|
+
if (normalized.length <= MAX_AUTO_NAME_LENGTH) {
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Truncate at the last space before the limit to avoid cutting mid-word.
|
|
19
|
+
const truncated = normalized.slice(0, MAX_AUTO_NAME_LENGTH);
|
|
20
|
+
const lastSpace = truncated.lastIndexOf(" ");
|
|
21
|
+
return lastSpace > 0 ? `${truncated.slice(0, lastSpace)}…` : `${truncated}…`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const createHookProcessor = (deps: {
|
|
25
|
+
terminals: Map<string, PersistedTerminal>;
|
|
26
|
+
sessions: Map<string, TerminalSession>;
|
|
27
|
+
transcriptDirectoryPath: string;
|
|
28
|
+
getApiBaseUrl: () => string;
|
|
29
|
+
persistRegistry: () => void;
|
|
30
|
+
deliverChannelMessages: (terminalId: string) => void;
|
|
31
|
+
onStateChange?: (
|
|
32
|
+
terminalId: string,
|
|
33
|
+
state: TerminalSession["agentState"],
|
|
34
|
+
toolName?: string,
|
|
35
|
+
) => void;
|
|
36
|
+
}) => {
|
|
37
|
+
const {
|
|
38
|
+
terminals,
|
|
39
|
+
sessions,
|
|
40
|
+
transcriptDirectoryPath,
|
|
41
|
+
getApiBaseUrl,
|
|
42
|
+
persistRegistry,
|
|
43
|
+
deliverChannelMessages,
|
|
44
|
+
onStateChange,
|
|
45
|
+
} = deps;
|
|
46
|
+
|
|
47
|
+
const parseSettingsObject = (fileContents: string): Record<string, unknown> | null => {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(fileContents) as unknown;
|
|
50
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return parsed as Record<string, unknown>;
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const mergeHookEntries = (
|
|
60
|
+
existingValue: unknown,
|
|
61
|
+
eventName: string,
|
|
62
|
+
nextEntries: unknown[],
|
|
63
|
+
): Record<string, unknown> => {
|
|
64
|
+
const nextHooks =
|
|
65
|
+
existingValue && typeof existingValue === "object" && !Array.isArray(existingValue)
|
|
66
|
+
? { ...(existingValue as Record<string, unknown>) }
|
|
67
|
+
: {};
|
|
68
|
+
const existingEntries = Array.isArray(nextHooks[eventName])
|
|
69
|
+
? [...(nextHooks[eventName] as unknown[])]
|
|
70
|
+
: [];
|
|
71
|
+
const mergedEntries = [...existingEntries];
|
|
72
|
+
|
|
73
|
+
for (const nextEntry of nextEntries) {
|
|
74
|
+
const serializedNextEntry = JSON.stringify(nextEntry);
|
|
75
|
+
const alreadyPresent = existingEntries.some(
|
|
76
|
+
(existingEntry) => JSON.stringify(existingEntry) === serializedNextEntry,
|
|
77
|
+
);
|
|
78
|
+
if (!alreadyPresent) {
|
|
79
|
+
mergedEntries.push(nextEntry);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
nextHooks[eventName] = mergedEntries;
|
|
84
|
+
return nextHooks;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const installHooksInDirectory = (targetCwd: string) => {
|
|
88
|
+
const targetClaudeDir = join(targetCwd, ".claude");
|
|
89
|
+
const targetSettingsPath = join(targetClaudeDir, "settings.json");
|
|
90
|
+
const apiBaseUrl = getApiBaseUrl();
|
|
91
|
+
|
|
92
|
+
const hooksConfig = {
|
|
93
|
+
hooks: {
|
|
94
|
+
SessionStart: [
|
|
95
|
+
{
|
|
96
|
+
matcher: "*",
|
|
97
|
+
hooks: [
|
|
98
|
+
{
|
|
99
|
+
type: "command",
|
|
100
|
+
command: `curl -s -X POST "${apiBaseUrl}/api/hooks/session-start?octogent_session=$OCTOGENT_SESSION_ID" -H 'Content-Type: application/json' -d @- || true`,
|
|
101
|
+
timeout: 5,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
UserPromptSubmit: [
|
|
107
|
+
{
|
|
108
|
+
matcher: "*",
|
|
109
|
+
hooks: [
|
|
110
|
+
{
|
|
111
|
+
type: "command",
|
|
112
|
+
command: `curl -s -X POST "${apiBaseUrl}/api/hooks/user-prompt-submit?octogent_session=$OCTOGENT_SESSION_ID" -H 'Content-Type: application/json' -d @- || true`,
|
|
113
|
+
timeout: 5,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
PreToolUse: [
|
|
119
|
+
{
|
|
120
|
+
matcher: "*",
|
|
121
|
+
hooks: [
|
|
122
|
+
{
|
|
123
|
+
type: "http",
|
|
124
|
+
url: `${apiBaseUrl}/api/hooks/pre-tool-use`,
|
|
125
|
+
headers: { "X-Octogent-Session": "$OCTOGENT_SESSION_ID" },
|
|
126
|
+
allowedEnvVars: ["OCTOGENT_SESSION_ID"],
|
|
127
|
+
timeout: 5,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
PostToolUse: [
|
|
133
|
+
{
|
|
134
|
+
matcher: "Edit|Write",
|
|
135
|
+
hooks: [
|
|
136
|
+
{
|
|
137
|
+
type: "http",
|
|
138
|
+
url: `${apiBaseUrl}/api/code-intel/events`,
|
|
139
|
+
headers: { "X-Octogent-Session": "$OCTOGENT_SESSION_ID" },
|
|
140
|
+
allowedEnvVars: ["OCTOGENT_SESSION_ID"],
|
|
141
|
+
timeout: 5,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
Notification: [
|
|
147
|
+
{
|
|
148
|
+
matcher: "*",
|
|
149
|
+
hooks: [
|
|
150
|
+
{
|
|
151
|
+
type: "http",
|
|
152
|
+
url: `${apiBaseUrl}/api/hooks/notification`,
|
|
153
|
+
headers: { "X-Octogent-Session": "$OCTOGENT_SESSION_ID" },
|
|
154
|
+
allowedEnvVars: ["OCTOGENT_SESSION_ID"],
|
|
155
|
+
timeout: 5,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
Stop: [
|
|
161
|
+
{
|
|
162
|
+
matcher: "*",
|
|
163
|
+
hooks: [
|
|
164
|
+
{
|
|
165
|
+
type: "command",
|
|
166
|
+
command: `curl -s -X POST "${apiBaseUrl}/api/hooks/stop?octogent_session=$OCTOGENT_SESSION_ID" -H 'Content-Type: application/json' -d @- || true`,
|
|
167
|
+
timeout: 15,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
mkdirSync(targetClaudeDir, { recursive: true });
|
|
177
|
+
const existingSettings = existsSync(targetSettingsPath)
|
|
178
|
+
? parseSettingsObject(readFileSync(targetSettingsPath, "utf8"))
|
|
179
|
+
: null;
|
|
180
|
+
const mergedSettings =
|
|
181
|
+
existingSettings && typeof existingSettings === "object" ? { ...existingSettings } : {};
|
|
182
|
+
|
|
183
|
+
let mergedHooks =
|
|
184
|
+
mergedSettings.hooks &&
|
|
185
|
+
typeof mergedSettings.hooks === "object" &&
|
|
186
|
+
!Array.isArray(mergedSettings.hooks)
|
|
187
|
+
? { ...(mergedSettings.hooks as Record<string, unknown>) }
|
|
188
|
+
: {};
|
|
189
|
+
|
|
190
|
+
for (const [eventName, eventEntries] of Object.entries(hooksConfig.hooks)) {
|
|
191
|
+
mergedHooks = mergeHookEntries(mergedHooks, eventName, eventEntries);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
mergedSettings.hooks = mergedHooks;
|
|
195
|
+
writeFileSync(targetSettingsPath, `${JSON.stringify(mergedSettings, null, 2)}\n`, "utf8");
|
|
196
|
+
} catch {
|
|
197
|
+
// Best-effort
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const handleHook = (
|
|
202
|
+
hookName: string,
|
|
203
|
+
payload: unknown,
|
|
204
|
+
octogentSessionId?: string,
|
|
205
|
+
): { ok: boolean } => {
|
|
206
|
+
logVerbose(
|
|
207
|
+
`[Hook] Received hook: ${hookName} octogentSession=${octogentSessionId ?? "(none)"}`,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (!payload || typeof payload !== "object") {
|
|
211
|
+
return { ok: true };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const hookPayloadRecord = payload as Record<string, unknown>;
|
|
215
|
+
|
|
216
|
+
if (hookName === "notification") {
|
|
217
|
+
if (!octogentSessionId) {
|
|
218
|
+
return { ok: true };
|
|
219
|
+
}
|
|
220
|
+
const session = sessions.get(octogentSessionId);
|
|
221
|
+
if (!session) {
|
|
222
|
+
logVerbose(`[Hook] notification: no session for ${octogentSessionId}, skipping.`);
|
|
223
|
+
return { ok: true };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const notificationType =
|
|
227
|
+
typeof hookPayloadRecord.notification_type === "string"
|
|
228
|
+
? hookPayloadRecord.notification_type
|
|
229
|
+
: null;
|
|
230
|
+
|
|
231
|
+
logVerbose(`[Hook] notification: type=${notificationType} session=${octogentSessionId}`);
|
|
232
|
+
|
|
233
|
+
if (notificationType === "permission_prompt") {
|
|
234
|
+
session.agentState = "waiting_for_permission";
|
|
235
|
+
session.stateTracker.forceState("waiting_for_permission");
|
|
236
|
+
onStateChange?.(octogentSessionId, "waiting_for_permission", session.lastToolName);
|
|
237
|
+
broadcastMessage(session, {
|
|
238
|
+
type: "state",
|
|
239
|
+
state: "waiting_for_permission",
|
|
240
|
+
...(session.lastToolName ? { toolName: session.lastToolName } : {}),
|
|
241
|
+
});
|
|
242
|
+
} else if (notificationType === "idle_prompt") {
|
|
243
|
+
session.agentState = "idle";
|
|
244
|
+
session.stateTracker.forceState("idle");
|
|
245
|
+
onStateChange?.(octogentSessionId, "idle");
|
|
246
|
+
broadcastMessage(session, { type: "state", state: "idle" });
|
|
247
|
+
|
|
248
|
+
// Deliver any queued channel messages now that the agent is idle.
|
|
249
|
+
deliverChannelMessages(octogentSessionId);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return { ok: true };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (hookName === "pre-tool-use") {
|
|
256
|
+
if (!octogentSessionId) {
|
|
257
|
+
return { ok: true };
|
|
258
|
+
}
|
|
259
|
+
const session = sessions.get(octogentSessionId);
|
|
260
|
+
if (!session) {
|
|
261
|
+
return { ok: true };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const toolName =
|
|
265
|
+
typeof hookPayloadRecord.tool_name === "string" ? hookPayloadRecord.tool_name : null;
|
|
266
|
+
|
|
267
|
+
logVerbose(`[Hook] pre-tool-use: tool=${toolName} session=${octogentSessionId}`);
|
|
268
|
+
|
|
269
|
+
if (toolName) {
|
|
270
|
+
session.lastToolName = toolName;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (toolName === "AskUserQuestion") {
|
|
274
|
+
session.agentState = "waiting_for_user";
|
|
275
|
+
session.stateTracker.forceState("waiting_for_user");
|
|
276
|
+
onStateChange?.(octogentSessionId, "waiting_for_user");
|
|
277
|
+
broadcastMessage(session, { type: "state", state: "waiting_for_user" });
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return { ok: true };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (hookName === "user-prompt-submit") {
|
|
284
|
+
if (!octogentSessionId) {
|
|
285
|
+
return { ok: true };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const terminal = terminals.get(octogentSessionId);
|
|
289
|
+
if (!terminal) {
|
|
290
|
+
return { ok: true };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Update last-active timestamp (determines active/inactive on the canvas).
|
|
294
|
+
terminal.lastActiveAt = new Date().toISOString();
|
|
295
|
+
|
|
296
|
+
// The user submitted a prompt, so the agent is about to start processing.
|
|
297
|
+
// Transition state out of waiting/idle to processing immediately.
|
|
298
|
+
const activitySession = sessions.get(terminal.terminalId);
|
|
299
|
+
if (activitySession) {
|
|
300
|
+
activitySession.agentState = "processing";
|
|
301
|
+
activitySession.lastToolName = undefined;
|
|
302
|
+
activitySession.stateTracker.forceState("processing");
|
|
303
|
+
onStateChange?.(terminal.terminalId, "processing");
|
|
304
|
+
broadcastMessage(activitySession, { type: "state", state: "processing" });
|
|
305
|
+
broadcastMessage(activitySession, { type: "activity" });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Auto-name the terminal from the first prompt when it still has its default name.
|
|
309
|
+
if (terminal.nameOrigin === "generated") {
|
|
310
|
+
const prompt =
|
|
311
|
+
typeof hookPayloadRecord.prompt === "string" ? hookPayloadRecord.prompt.trim() : "";
|
|
312
|
+
const renameContext = terminal.autoRenamePromptContext?.trim() || prompt;
|
|
313
|
+
if (renameContext.length > 0) {
|
|
314
|
+
const derived = deriveTerminalNameFromPrompt(renameContext);
|
|
315
|
+
terminal.tentacleName = derived;
|
|
316
|
+
terminal.nameOrigin = "prompt";
|
|
317
|
+
terminal.autoRenamePromptContext = undefined;
|
|
318
|
+
logVerbose(`[Hook] Auto-named terminal ${terminal.terminalId} → "${derived}"`);
|
|
319
|
+
|
|
320
|
+
const session = sessions.get(terminal.terminalId);
|
|
321
|
+
if (session) {
|
|
322
|
+
broadcastMessage(session, { type: "rename", tentacleName: derived });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
persistRegistry();
|
|
328
|
+
return { ok: true };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (hookName !== "stop") {
|
|
332
|
+
return { ok: true };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const hookPayload = payload as Record<string, unknown>;
|
|
336
|
+
const transcriptPath =
|
|
337
|
+
typeof hookPayload.transcript_path === "string" ? hookPayload.transcript_path : null;
|
|
338
|
+
const hookCwd = typeof hookPayload.cwd === "string" ? hookPayload.cwd : null;
|
|
339
|
+
|
|
340
|
+
logVerbose(`[Hook] Stop hook: transcriptPath=${transcriptPath}, hookCwd=${hookCwd}`);
|
|
341
|
+
|
|
342
|
+
if (!transcriptPath || !hookCwd) {
|
|
343
|
+
logVerbose("[Hook] Missing transcriptPath or hookCwd, skipping.");
|
|
344
|
+
return { ok: true };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
let matchedSessionId: string | null = null;
|
|
348
|
+
|
|
349
|
+
if (octogentSessionId && sessions.has(octogentSessionId)) {
|
|
350
|
+
matchedSessionId = octogentSessionId;
|
|
351
|
+
logVerbose(`[Hook] Matched session by octogent_session param: ${matchedSessionId}`);
|
|
352
|
+
} else if (octogentSessionId) {
|
|
353
|
+
logVerbose(
|
|
354
|
+
`[Hook] octogent_session=${octogentSessionId} not found in active sessions, skipping.`,
|
|
355
|
+
);
|
|
356
|
+
return { ok: true };
|
|
357
|
+
} else {
|
|
358
|
+
logVerbose("[Hook] No octogent_session param — ignoring hook from external Claude session.");
|
|
359
|
+
return { ok: true };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
logVerbose(`[Hook] Matched session: ${matchedSessionId}, parsing transcript...`);
|
|
363
|
+
const turns = parseClaudeTranscript(transcriptPath);
|
|
364
|
+
logVerbose(`[Hook] Parsed ${turns?.length ?? 0} turns from transcript.`);
|
|
365
|
+
|
|
366
|
+
const lastAssistantMessage =
|
|
367
|
+
typeof hookPayload.last_assistant_message === "string"
|
|
368
|
+
? hookPayload.last_assistant_message.trim()
|
|
369
|
+
: null;
|
|
370
|
+
|
|
371
|
+
if (lastAssistantMessage && lastAssistantMessage.length > 0) {
|
|
372
|
+
const effectiveTurns = turns ?? [];
|
|
373
|
+
const lastTurn = effectiveTurns.length > 0 ? effectiveTurns[effectiveTurns.length - 1] : null;
|
|
374
|
+
|
|
375
|
+
if (!lastTurn || lastTurn.role !== "assistant" || lastTurn.content !== lastAssistantMessage) {
|
|
376
|
+
const now = new Date().toISOString();
|
|
377
|
+
effectiveTurns.push({
|
|
378
|
+
turnId: `turn-${effectiveTurns.length + 1}`,
|
|
379
|
+
role: "assistant",
|
|
380
|
+
content: lastAssistantMessage,
|
|
381
|
+
startedAt: now,
|
|
382
|
+
endedAt: now,
|
|
383
|
+
});
|
|
384
|
+
logVerbose("[Hook] Appended last_assistant_message as final turn.");
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (effectiveTurns.length > 0) {
|
|
388
|
+
storeClaudeTranscriptTurns(transcriptDirectoryPath, matchedSessionId, effectiveTurns);
|
|
389
|
+
logVerbose(`[Hook] Stored ${effectiveTurns.length} turns for session ${matchedSessionId}.`);
|
|
390
|
+
}
|
|
391
|
+
} else if (turns && turns.length > 0) {
|
|
392
|
+
storeClaudeTranscriptTurns(transcriptDirectoryPath, matchedSessionId, turns);
|
|
393
|
+
logVerbose(`[Hook] Stored ${turns.length} turns for session ${matchedSessionId}.`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Deliver any queued channel messages now that the agent is idle.
|
|
397
|
+
if (matchedSessionId) {
|
|
398
|
+
deliverChannelMessages(matchedSessionId);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return { ok: true };
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
return { handleHook, installHooksInDirectory };
|
|
405
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
|
|
3
|
+
import type { WebSocket } from "ws";
|
|
4
|
+
|
|
5
|
+
import type { TerminalServerMessage, TerminalSession } from "./types";
|
|
6
|
+
|
|
7
|
+
export const getTerminalId = (request: IncomingMessage) => {
|
|
8
|
+
if (!request.url) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let url: URL;
|
|
13
|
+
try {
|
|
14
|
+
url = new URL(request.url, "http://localhost");
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const match = url.pathname.match(/^\/api\/terminals\/([^/]+)\/ws$/);
|
|
20
|
+
if (!match) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return decodeURIComponent(match[1] ?? "");
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const sendMessage = (client: WebSocket, message: TerminalServerMessage) => {
|
|
32
|
+
if (client.readyState !== 1) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
client.send(JSON.stringify(message));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const broadcastMessage = (session: TerminalSession, message: TerminalServerMessage) => {
|
|
40
|
+
for (const client of session.clients) {
|
|
41
|
+
sendMessage(client, message);
|
|
42
|
+
}
|
|
43
|
+
for (const listener of session.directListeners) {
|
|
44
|
+
listener(message);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { chmodSync, existsSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
|
|
7
|
+
export const createShellEnvironment = (options?: { octogentSessionId?: string }) => {
|
|
8
|
+
const env: Record<string, string> = {};
|
|
9
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
10
|
+
if (typeof value === "string") {
|
|
11
|
+
env[key] = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
env.TERM = "xterm-256color";
|
|
15
|
+
env.COLORTERM = "truecolor";
|
|
16
|
+
if (options?.octogentSessionId) {
|
|
17
|
+
env.OCTOGENT_SESSION_ID = options.octogentSessionId;
|
|
18
|
+
}
|
|
19
|
+
return env;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const ensureNodePtySpawnHelperExecutable = () => {
|
|
23
|
+
if (process.platform === "win32") {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const packageJsonPath = require.resolve("node-pty/package.json");
|
|
29
|
+
const packageDir = dirname(packageJsonPath);
|
|
30
|
+
const helperCandidates = [
|
|
31
|
+
join(packageDir, "build", "Release", "spawn-helper"),
|
|
32
|
+
join(packageDir, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper"),
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
for (const helperPath of helperCandidates) {
|
|
36
|
+
if (!existsSync(helperPath)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const currentMode = statSync(helperPath).mode;
|
|
41
|
+
if ((currentMode & 0o111) !== 0) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
chmodSync(helperPath, currentMode | 0o755);
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
// Let node-pty throw the actionable error if helper lookup/setup fails.
|
|
49
|
+
}
|
|
50
|
+
};
|