@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,492 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
ConversationSearchHit,
|
|
6
|
+
ConversationSearchResult,
|
|
7
|
+
ConversationSessionDetail,
|
|
8
|
+
ConversationSessionSummary,
|
|
9
|
+
ConversationTurn,
|
|
10
|
+
} from "@octogent/core";
|
|
11
|
+
|
|
12
|
+
import type { AgentRuntimeState } from "../agentStateDetection";
|
|
13
|
+
|
|
14
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
15
|
+
value !== null && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
|
|
17
|
+
const asString = (value: unknown): string | null => (typeof value === "string" ? value : null);
|
|
18
|
+
|
|
19
|
+
const parseRuntimeState = (value: unknown): AgentRuntimeState | null =>
|
|
20
|
+
value === "idle" || value === "processing" ? value : null;
|
|
21
|
+
|
|
22
|
+
export type ConversationTranscriptEventBase = {
|
|
23
|
+
eventId: string;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
tentacleId: string;
|
|
26
|
+
timestamp: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type SessionStartTranscriptEvent = ConversationTranscriptEventBase & {
|
|
30
|
+
type: "session_start";
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type InputSubmitTranscriptEvent = ConversationTranscriptEventBase & {
|
|
34
|
+
type: "input_submit";
|
|
35
|
+
submitId: string;
|
|
36
|
+
text: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type OutputChunkTranscriptEvent = ConversationTranscriptEventBase & {
|
|
40
|
+
type: "output_chunk";
|
|
41
|
+
chunkId: string;
|
|
42
|
+
text: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type StateChangeTranscriptEvent = ConversationTranscriptEventBase & {
|
|
46
|
+
type: "state_change";
|
|
47
|
+
state: AgentRuntimeState;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type SessionEndTranscriptEvent = ConversationTranscriptEventBase & {
|
|
51
|
+
type: "session_end";
|
|
52
|
+
reason: "pty_exit" | "session_close";
|
|
53
|
+
exitCode?: number;
|
|
54
|
+
signal?: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type ConversationTranscriptEvent =
|
|
58
|
+
| SessionStartTranscriptEvent
|
|
59
|
+
| InputSubmitTranscriptEvent
|
|
60
|
+
| OutputChunkTranscriptEvent
|
|
61
|
+
| StateChangeTranscriptEvent
|
|
62
|
+
| SessionEndTranscriptEvent;
|
|
63
|
+
|
|
64
|
+
export type ConversationTranscriptEventPayload =
|
|
65
|
+
| Omit<SessionStartTranscriptEvent, "eventId" | "sessionId" | "tentacleId">
|
|
66
|
+
| Omit<InputSubmitTranscriptEvent, "eventId" | "sessionId" | "tentacleId">
|
|
67
|
+
| Omit<OutputChunkTranscriptEvent, "eventId" | "sessionId" | "tentacleId">
|
|
68
|
+
| Omit<StateChangeTranscriptEvent, "eventId" | "sessionId" | "tentacleId">
|
|
69
|
+
| Omit<SessionEndTranscriptEvent, "eventId" | "sessionId" | "tentacleId">;
|
|
70
|
+
|
|
71
|
+
export type { ConversationTurn };
|
|
72
|
+
|
|
73
|
+
export const transcriptFilenameForSession = (sessionId: string) =>
|
|
74
|
+
`${encodeURIComponent(sessionId)}.jsonl`;
|
|
75
|
+
|
|
76
|
+
const parseTranscriptEvent = (value: unknown): ConversationTranscriptEvent | null => {
|
|
77
|
+
if (!isRecord(value)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const eventType = asString(value.type);
|
|
82
|
+
const eventId = asString(value.eventId);
|
|
83
|
+
const sessionId = asString(value.sessionId);
|
|
84
|
+
const tentacleId = asString(value.tentacleId);
|
|
85
|
+
const timestamp = asString(value.timestamp);
|
|
86
|
+
|
|
87
|
+
if (!eventType || !eventId || !sessionId || !tentacleId || !timestamp) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (eventType === "session_start") {
|
|
92
|
+
return {
|
|
93
|
+
type: "session_start",
|
|
94
|
+
eventId,
|
|
95
|
+
sessionId,
|
|
96
|
+
tentacleId,
|
|
97
|
+
timestamp,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (eventType === "input_submit") {
|
|
102
|
+
const submitId = asString(value.submitId);
|
|
103
|
+
const text = asString(value.text);
|
|
104
|
+
if (!submitId || text === null) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
type: "input_submit",
|
|
110
|
+
eventId,
|
|
111
|
+
sessionId,
|
|
112
|
+
tentacleId,
|
|
113
|
+
timestamp,
|
|
114
|
+
submitId,
|
|
115
|
+
text,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (eventType === "output_chunk") {
|
|
120
|
+
const chunkId = asString(value.chunkId);
|
|
121
|
+
const text = asString(value.text);
|
|
122
|
+
if (!chunkId || text === null) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
type: "output_chunk",
|
|
128
|
+
eventId,
|
|
129
|
+
sessionId,
|
|
130
|
+
tentacleId,
|
|
131
|
+
timestamp,
|
|
132
|
+
chunkId,
|
|
133
|
+
text,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (eventType === "state_change") {
|
|
138
|
+
const state = parseRuntimeState(value.state);
|
|
139
|
+
if (!state) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
type: "state_change",
|
|
145
|
+
eventId,
|
|
146
|
+
sessionId,
|
|
147
|
+
tentacleId,
|
|
148
|
+
timestamp,
|
|
149
|
+
state,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (eventType === "session_end") {
|
|
154
|
+
const reason = value.reason;
|
|
155
|
+
if (reason !== "pty_exit" && reason !== "session_close") {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const exitCode = typeof value.exitCode === "number" ? value.exitCode : undefined;
|
|
160
|
+
const signal = typeof value.signal === "number" ? value.signal : undefined;
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
type: "session_end",
|
|
164
|
+
eventId,
|
|
165
|
+
sessionId,
|
|
166
|
+
tentacleId,
|
|
167
|
+
timestamp,
|
|
168
|
+
reason,
|
|
169
|
+
...(exitCode !== undefined ? { exitCode } : {}),
|
|
170
|
+
...(signal !== undefined ? { signal } : {}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return null;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const buildConversationSummary = (
|
|
178
|
+
sessionId: string,
|
|
179
|
+
events: ConversationTranscriptEvent[],
|
|
180
|
+
turns: ConversationTurn[],
|
|
181
|
+
): ConversationSessionSummary => {
|
|
182
|
+
const userTurns = turns.filter((turn) => turn.role === "user");
|
|
183
|
+
const assistantTurns = turns.filter((turn) => turn.role === "assistant");
|
|
184
|
+
const firstEvent = events[0] ?? null;
|
|
185
|
+
const lastEvent = events.length > 0 ? events[events.length - 1] : null;
|
|
186
|
+
const lastSessionEnd =
|
|
187
|
+
[...events].reverse().find((event) => event.type === "session_end") ?? null;
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
sessionId,
|
|
191
|
+
tentacleId: firstEvent?.tentacleId ?? null,
|
|
192
|
+
startedAt: firstEvent?.timestamp ?? null,
|
|
193
|
+
endedAt: lastSessionEnd?.timestamp ?? null,
|
|
194
|
+
lastEventAt: lastEvent?.timestamp ?? null,
|
|
195
|
+
eventCount: events.length,
|
|
196
|
+
turnCount: turns.length,
|
|
197
|
+
userTurnCount: userTurns.length,
|
|
198
|
+
assistantTurnCount: assistantTurns.length,
|
|
199
|
+
firstUserTurnPreview: userTurns.length > 0 ? (userTurns[0]?.content ?? null) : null,
|
|
200
|
+
lastUserTurnPreview:
|
|
201
|
+
userTurns.length > 0 ? (userTurns[userTurns.length - 1]?.content ?? null) : null,
|
|
202
|
+
lastAssistantTurnPreview:
|
|
203
|
+
assistantTurns.length > 0
|
|
204
|
+
? (assistantTurns[assistantTurns.length - 1]?.content ?? null)
|
|
205
|
+
: null,
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const parseTranscriptLines = (rawJsonl: string): ConversationTranscriptEvent[] => {
|
|
210
|
+
const events: ConversationTranscriptEvent[] = [];
|
|
211
|
+
const lines = rawJsonl.split(/\r?\n/);
|
|
212
|
+
for (const line of lines) {
|
|
213
|
+
const trimmed = line.trim();
|
|
214
|
+
if (trimmed.length === 0) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const parsed = JSON.parse(trimmed) as unknown;
|
|
220
|
+
const event = parseTranscriptEvent(parsed);
|
|
221
|
+
if (event) {
|
|
222
|
+
events.push(event);
|
|
223
|
+
}
|
|
224
|
+
} catch {
|
|
225
|
+
// Ignore malformed lines to keep transcript parsing resilient.
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return events;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const readSessionEventsFromFile = (
|
|
233
|
+
transcriptDirectoryPath: string,
|
|
234
|
+
sessionId: string,
|
|
235
|
+
): ConversationTranscriptEvent[] => {
|
|
236
|
+
const transcriptPath = join(transcriptDirectoryPath, transcriptFilenameForSession(sessionId));
|
|
237
|
+
if (!existsSync(transcriptPath)) {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const rawJsonl = readFileSync(transcriptPath, "utf8");
|
|
242
|
+
return parseTranscriptLines(rawJsonl);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const parseSessionIdFromFilename = (filename: string): string | null => {
|
|
246
|
+
if (!filename.endsWith(".jsonl")) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const basename = filename.slice(0, -".jsonl".length);
|
|
251
|
+
if (basename.length === 0) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
return decodeURIComponent(basename);
|
|
257
|
+
} catch {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const truncatePreview = (value: string | null): string | null => {
|
|
263
|
+
if (!value) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
268
|
+
if (normalized.length <= 160) {
|
|
269
|
+
return normalized;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return `${normalized.slice(0, 157)}...`;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const readConversationSession = (
|
|
276
|
+
transcriptDirectoryPath: string,
|
|
277
|
+
sessionId: string,
|
|
278
|
+
): ConversationSessionDetail | null => {
|
|
279
|
+
const events = readSessionEventsFromFile(transcriptDirectoryPath, sessionId);
|
|
280
|
+
if (events.length === 0) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Only use clean turns from Claude Code's structured transcript (via Stop hook).
|
|
285
|
+
const turns = readClaudeTranscriptTurns(transcriptDirectoryPath, sessionId) ?? [];
|
|
286
|
+
const summary = buildConversationSummary(sessionId, events, turns);
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
...summary,
|
|
290
|
+
firstUserTurnPreview: truncatePreview(summary.firstUserTurnPreview),
|
|
291
|
+
lastUserTurnPreview: truncatePreview(summary.lastUserTurnPreview),
|
|
292
|
+
lastAssistantTurnPreview: truncatePreview(summary.lastAssistantTurnPreview),
|
|
293
|
+
turns,
|
|
294
|
+
events,
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export const listConversationSessions = (
|
|
299
|
+
transcriptDirectoryPath: string,
|
|
300
|
+
): ConversationSessionSummary[] => {
|
|
301
|
+
if (!existsSync(transcriptDirectoryPath)) {
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const sessionIds = readdirSync(transcriptDirectoryPath)
|
|
306
|
+
.map((filename) => parseSessionIdFromFilename(filename))
|
|
307
|
+
.filter((sessionId): sessionId is string => sessionId !== null);
|
|
308
|
+
|
|
309
|
+
const summaries = sessionIds
|
|
310
|
+
.map((sessionId) => {
|
|
311
|
+
const detail = readConversationSession(transcriptDirectoryPath, sessionId);
|
|
312
|
+
// Skip sessions that have no actual conversation turns — these are
|
|
313
|
+
// PTY sessions that were spawned but never received any user input.
|
|
314
|
+
if (!detail || detail.turnCount === 0) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
sessionId: detail.sessionId,
|
|
320
|
+
tentacleId: detail.tentacleId,
|
|
321
|
+
startedAt: detail.startedAt,
|
|
322
|
+
endedAt: detail.endedAt,
|
|
323
|
+
lastEventAt: detail.lastEventAt,
|
|
324
|
+
eventCount: detail.eventCount,
|
|
325
|
+
turnCount: detail.turnCount,
|
|
326
|
+
userTurnCount: detail.userTurnCount,
|
|
327
|
+
assistantTurnCount: detail.assistantTurnCount,
|
|
328
|
+
firstUserTurnPreview: detail.firstUserTurnPreview,
|
|
329
|
+
lastUserTurnPreview: detail.lastUserTurnPreview,
|
|
330
|
+
lastAssistantTurnPreview: detail.lastAssistantTurnPreview,
|
|
331
|
+
};
|
|
332
|
+
})
|
|
333
|
+
.filter((summary): summary is ConversationSessionSummary => summary !== null)
|
|
334
|
+
.map((summary) => ({
|
|
335
|
+
...summary,
|
|
336
|
+
firstUserTurnPreview: truncatePreview(summary.firstUserTurnPreview),
|
|
337
|
+
lastUserTurnPreview: truncatePreview(summary.lastUserTurnPreview),
|
|
338
|
+
lastAssistantTurnPreview: truncatePreview(summary.lastAssistantTurnPreview),
|
|
339
|
+
}));
|
|
340
|
+
|
|
341
|
+
return summaries.sort((left, right) => {
|
|
342
|
+
const leftTime = left.lastEventAt ? Date.parse(left.lastEventAt) : 0;
|
|
343
|
+
const rightTime = right.lastEventAt ? Date.parse(right.lastEventAt) : 0;
|
|
344
|
+
return rightTime - leftTime;
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export const ensureTranscriptDirectory = (transcriptDirectoryPath: string) => {
|
|
349
|
+
mkdirSync(transcriptDirectoryPath, { recursive: true });
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export const deleteConversation = (transcriptDirectoryPath: string, sessionId: string) => {
|
|
353
|
+
const transcriptFile = join(transcriptDirectoryPath, transcriptFilenameForSession(sessionId));
|
|
354
|
+
const turnsFile = join(
|
|
355
|
+
transcriptDirectoryPath,
|
|
356
|
+
`${encodeURIComponent(sessionId)}.claude-turns.json`,
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
if (existsSync(transcriptFile)) {
|
|
361
|
+
rmSync(transcriptFile);
|
|
362
|
+
}
|
|
363
|
+
} catch {
|
|
364
|
+
// Best-effort removal
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
try {
|
|
368
|
+
if (existsSync(turnsFile)) {
|
|
369
|
+
rmSync(turnsFile);
|
|
370
|
+
}
|
|
371
|
+
} catch {
|
|
372
|
+
// Best-effort removal
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export const deleteAllConversations = (transcriptDirectoryPath: string) => {
|
|
377
|
+
if (!existsSync(transcriptDirectoryPath)) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const files = readdirSync(transcriptDirectoryPath);
|
|
382
|
+
for (const file of files) {
|
|
383
|
+
if (file.endsWith(".jsonl") || file.endsWith(".claude-turns.json")) {
|
|
384
|
+
try {
|
|
385
|
+
rmSync(join(transcriptDirectoryPath, file));
|
|
386
|
+
} catch {
|
|
387
|
+
// Best-effort removal
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const claudeTurnsFilename = (sessionId: string) =>
|
|
394
|
+
`${encodeURIComponent(sessionId)}.claude-turns.json`;
|
|
395
|
+
|
|
396
|
+
export const storeClaudeTranscriptTurns = (
|
|
397
|
+
transcriptDirectoryPath: string,
|
|
398
|
+
sessionId: string,
|
|
399
|
+
turns: ConversationTurn[],
|
|
400
|
+
) => {
|
|
401
|
+
ensureTranscriptDirectory(transcriptDirectoryPath);
|
|
402
|
+
const filePath = join(transcriptDirectoryPath, claudeTurnsFilename(sessionId));
|
|
403
|
+
writeFileSync(filePath, JSON.stringify(turns), "utf8");
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const readClaudeTranscriptTurns = (
|
|
407
|
+
transcriptDirectoryPath: string,
|
|
408
|
+
sessionId: string,
|
|
409
|
+
): ConversationTurn[] | null => {
|
|
410
|
+
const filePath = join(transcriptDirectoryPath, claudeTurnsFilename(sessionId));
|
|
411
|
+
if (!existsSync(filePath)) {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
try {
|
|
416
|
+
const raw = readFileSync(filePath, "utf8");
|
|
417
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
418
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return parsed as ConversationTurn[];
|
|
423
|
+
} catch {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
const buildSearchSnippet = (content: string, query: string, contextChars = 80): string => {
|
|
429
|
+
const lowerContent = content.toLowerCase();
|
|
430
|
+
const lowerQuery = query.toLowerCase();
|
|
431
|
+
const matchIndex = lowerContent.indexOf(lowerQuery);
|
|
432
|
+
if (matchIndex === -1) {
|
|
433
|
+
return content
|
|
434
|
+
.slice(0, contextChars * 2)
|
|
435
|
+
.replace(/\s+/g, " ")
|
|
436
|
+
.trim();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const start = Math.max(0, matchIndex - contextChars);
|
|
440
|
+
const end = Math.min(content.length, matchIndex + query.length + contextChars);
|
|
441
|
+
let snippet = content.slice(start, end).replace(/\s+/g, " ").trim();
|
|
442
|
+
if (start > 0) snippet = `...${snippet}`;
|
|
443
|
+
if (end < content.length) snippet = `${snippet}...`;
|
|
444
|
+
return snippet;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
export const searchConversations = (
|
|
448
|
+
transcriptDirectoryPath: string,
|
|
449
|
+
query: string,
|
|
450
|
+
): ConversationSearchResult => {
|
|
451
|
+
if (!existsSync(transcriptDirectoryPath) || query.trim().length === 0) {
|
|
452
|
+
return { query, hits: [] };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const lowerQuery = query.toLowerCase();
|
|
456
|
+
const hits: ConversationSearchHit[] = [];
|
|
457
|
+
|
|
458
|
+
const sessionIds = readdirSync(transcriptDirectoryPath)
|
|
459
|
+
.map((filename) => parseSessionIdFromFilename(filename))
|
|
460
|
+
.filter((sessionId): sessionId is string => sessionId !== null);
|
|
461
|
+
|
|
462
|
+
for (const sessionId of sessionIds) {
|
|
463
|
+
const turns = readClaudeTranscriptTurns(transcriptDirectoryPath, sessionId) ?? [];
|
|
464
|
+
for (const turn of turns) {
|
|
465
|
+
if (turn.content.toLowerCase().includes(lowerQuery)) {
|
|
466
|
+
hits.push({
|
|
467
|
+
sessionId,
|
|
468
|
+
turnId: turn.turnId,
|
|
469
|
+
role: turn.role,
|
|
470
|
+
snippet: buildSearchSnippet(turn.content, query),
|
|
471
|
+
turnStartedAt: turn.startedAt,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return { query, hits };
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
export const conversationExportMarkdown = (conversation: ConversationSessionDetail): string => {
|
|
481
|
+
const lines: string[] = [];
|
|
482
|
+
|
|
483
|
+
for (const turn of conversation.turns) {
|
|
484
|
+
const roleLabel = turn.role === "user" ? "User" : "Assistant";
|
|
485
|
+
lines.push(`## ${roleLabel}`);
|
|
486
|
+
lines.push("");
|
|
487
|
+
lines.push(turn.content.length > 0 ? turn.content : "(empty)");
|
|
488
|
+
lines.push("");
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return `${lines.join("\n").trim()}\n`;
|
|
492
|
+
};
|