@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.
Files changed (299) hide show
  1. package/README.md +1295 -0
  2. package/apps/octogent/.github/workflows/ci.yml +40 -0
  3. package/apps/octogent/.shims/claude +4 -0
  4. package/apps/octogent/AGENTS.md +71 -0
  5. package/apps/octogent/CONTRIBUTING.md +72 -0
  6. package/apps/octogent/LICENSE +21 -0
  7. package/apps/octogent/README.md +184 -0
  8. package/apps/octogent/apps/api/AGENTS.md +32 -0
  9. package/apps/octogent/apps/api/package.json +19 -0
  10. package/apps/octogent/apps/api/src/agentStateDetection.ts +181 -0
  11. package/apps/octogent/apps/api/src/claudeSessionScanner.ts +235 -0
  12. package/apps/octogent/apps/api/src/claudeSkills.ts +182 -0
  13. package/apps/octogent/apps/api/src/claudeUsage.ts +922 -0
  14. package/apps/octogent/apps/api/src/cli.ts +595 -0
  15. package/apps/octogent/apps/api/src/codeIntelStore.ts +46 -0
  16. package/apps/octogent/apps/api/src/codexUsage.ts +278 -0
  17. package/apps/octogent/apps/api/src/createApiServer/codeIntelRoutes.ts +60 -0
  18. package/apps/octogent/apps/api/src/createApiServer/conversationRoutes.ts +128 -0
  19. package/apps/octogent/apps/api/src/createApiServer/deckRoutes.ts +873 -0
  20. package/apps/octogent/apps/api/src/createApiServer/gitParsers.ts +140 -0
  21. package/apps/octogent/apps/api/src/createApiServer/gitRoutes.ts +214 -0
  22. package/apps/octogent/apps/api/src/createApiServer/miscRoutes.ts +316 -0
  23. package/apps/octogent/apps/api/src/createApiServer/monitorParsers.ts +137 -0
  24. package/apps/octogent/apps/api/src/createApiServer/monitorRoutes.ts +95 -0
  25. package/apps/octogent/apps/api/src/createApiServer/requestHandler.ts +311 -0
  26. package/apps/octogent/apps/api/src/createApiServer/requestParsers.ts +25 -0
  27. package/apps/octogent/apps/api/src/createApiServer/routeHelpers.ts +97 -0
  28. package/apps/octogent/apps/api/src/createApiServer/security.ts +70 -0
  29. package/apps/octogent/apps/api/src/createApiServer/terminalParsers.ts +167 -0
  30. package/apps/octogent/apps/api/src/createApiServer/terminalRoutes.ts +315 -0
  31. package/apps/octogent/apps/api/src/createApiServer/types.ts +24 -0
  32. package/apps/octogent/apps/api/src/createApiServer/uiStateParsers.ts +255 -0
  33. package/apps/octogent/apps/api/src/createApiServer/upgradeHandler.ts +38 -0
  34. package/apps/octogent/apps/api/src/createApiServer/usageRoutes.ts +84 -0
  35. package/apps/octogent/apps/api/src/createApiServer.ts +176 -0
  36. package/apps/octogent/apps/api/src/deck/readDeckTentacles.ts +595 -0
  37. package/apps/octogent/apps/api/src/githubRepoSummary.ts +397 -0
  38. package/apps/octogent/apps/api/src/logging.ts +9 -0
  39. package/apps/octogent/apps/api/src/monitor/defaults.ts +3 -0
  40. package/apps/octogent/apps/api/src/monitor/index.ts +8 -0
  41. package/apps/octogent/apps/api/src/monitor/repository.ts +303 -0
  42. package/apps/octogent/apps/api/src/monitor/service.ts +349 -0
  43. package/apps/octogent/apps/api/src/monitor/types.ts +120 -0
  44. package/apps/octogent/apps/api/src/monitor/xProvider.ts +587 -0
  45. package/apps/octogent/apps/api/src/projectPersistence.ts +377 -0
  46. package/apps/octogent/apps/api/src/prompts/index.ts +10 -0
  47. package/apps/octogent/apps/api/src/prompts/promptResolver.ts +145 -0
  48. package/apps/octogent/apps/api/src/runtimeMetadata.ts +69 -0
  49. package/apps/octogent/apps/api/src/server.ts +80 -0
  50. package/apps/octogent/apps/api/src/setupState.ts +80 -0
  51. package/apps/octogent/apps/api/src/setupStatus.ts +174 -0
  52. package/apps/octogent/apps/api/src/startupPrerequisites.ts +146 -0
  53. package/apps/octogent/apps/api/src/terminalRuntime/channelMessaging.ts +87 -0
  54. package/apps/octogent/apps/api/src/terminalRuntime/claudeTranscript.ts +279 -0
  55. package/apps/octogent/apps/api/src/terminalRuntime/constants.ts +15 -0
  56. package/apps/octogent/apps/api/src/terminalRuntime/conversations.ts +492 -0
  57. package/apps/octogent/apps/api/src/terminalRuntime/gitOperations.ts +341 -0
  58. package/apps/octogent/apps/api/src/terminalRuntime/hookProcessor.ts +405 -0
  59. package/apps/octogent/apps/api/src/terminalRuntime/protocol.ts +46 -0
  60. package/apps/octogent/apps/api/src/terminalRuntime/ptyEnvironment.ts +50 -0
  61. package/apps/octogent/apps/api/src/terminalRuntime/registry.ts +423 -0
  62. package/apps/octogent/apps/api/src/terminalRuntime/sessionRuntime.ts +671 -0
  63. package/apps/octogent/apps/api/src/terminalRuntime/systemClients.ts +432 -0
  64. package/apps/octogent/apps/api/src/terminalRuntime/types.ts +157 -0
  65. package/apps/octogent/apps/api/src/terminalRuntime/worktreeManager.ts +135 -0
  66. package/apps/octogent/apps/api/src/terminalRuntime.ts +567 -0
  67. package/apps/octogent/apps/api/src/usageUtils.ts +16 -0
  68. package/apps/octogent/apps/api/src/ws-shim.d.ts +28 -0
  69. package/apps/octogent/apps/api/tests/agentStateDetection.test.ts +67 -0
  70. package/apps/octogent/apps/api/tests/claudeUsage.test.ts +583 -0
  71. package/apps/octogent/apps/api/tests/codexUsage.test.ts +107 -0
  72. package/apps/octogent/apps/api/tests/createApiServer.test.ts +3207 -0
  73. package/apps/octogent/apps/api/tests/githubRepoSummary.test.ts +100 -0
  74. package/apps/octogent/apps/api/tests/logging.test.ts +33 -0
  75. package/apps/octogent/apps/api/tests/monitorApi.test.ts +467 -0
  76. package/apps/octogent/apps/api/tests/monitorCore.test.ts +104 -0
  77. package/apps/octogent/apps/api/tests/promptResolver.test.ts +109 -0
  78. package/apps/octogent/apps/api/tests/protocol.test.ts +14 -0
  79. package/apps/octogent/apps/api/tests/sessionRuntime.test.ts +608 -0
  80. package/apps/octogent/apps/api/tests/startupPrerequisites.test.ts +70 -0
  81. package/apps/octogent/apps/api/tests/upgradeHandler.test.ts +40 -0
  82. package/apps/octogent/apps/api/tests/xMonitorProvider.test.ts +109 -0
  83. package/apps/octogent/apps/api/tsconfig.json +7 -0
  84. package/apps/octogent/apps/api/vitest.config.ts +7 -0
  85. package/apps/octogent/apps/web/AGENTS.md +38 -0
  86. package/apps/octogent/apps/web/index.html +13 -0
  87. package/apps/octogent/apps/web/package.json +32 -0
  88. package/apps/octogent/apps/web/public/octopus-favicon.svg +26 -0
  89. package/apps/octogent/apps/web/src/App.tsx +646 -0
  90. package/apps/octogent/apps/web/src/app/canvas/types.ts +34 -0
  91. package/apps/octogent/apps/web/src/app/codeIntelAggregation.ts +278 -0
  92. package/apps/octogent/apps/web/src/app/constants.ts +28 -0
  93. package/apps/octogent/apps/web/src/app/conversationNormalizers.ts +135 -0
  94. package/apps/octogent/apps/web/src/app/formatTimestamp.ts +18 -0
  95. package/apps/octogent/apps/web/src/app/githubMetrics.ts +76 -0
  96. package/apps/octogent/apps/web/src/app/githubNormalizers.ts +91 -0
  97. package/apps/octogent/apps/web/src/app/hooks/useAgentRuntimeStates.ts +18 -0
  98. package/apps/octogent/apps/web/src/app/hooks/useBackendLivenessPolling.ts +53 -0
  99. package/apps/octogent/apps/web/src/app/hooks/useCanvasGraphData.ts +449 -0
  100. package/apps/octogent/apps/web/src/app/hooks/useCanvasTransform.ts +260 -0
  101. package/apps/octogent/apps/web/src/app/hooks/useClaudeUsagePolling.ts +40 -0
  102. package/apps/octogent/apps/web/src/app/hooks/useClickOutside.ts +30 -0
  103. package/apps/octogent/apps/web/src/app/hooks/useCodeIntelRuntime.ts +83 -0
  104. package/apps/octogent/apps/web/src/app/hooks/useCodexUsagePolling.ts +35 -0
  105. package/apps/octogent/apps/web/src/app/hooks/useConsoleKeyboardShortcuts.ts +31 -0
  106. package/apps/octogent/apps/web/src/app/hooks/useConversationsRuntime.ts +377 -0
  107. package/apps/octogent/apps/web/src/app/hooks/useForceSimulation.ts +319 -0
  108. package/apps/octogent/apps/web/src/app/hooks/useGitHubPrimaryViewModel.ts +143 -0
  109. package/apps/octogent/apps/web/src/app/hooks/useGithubSummaryPolling.ts +28 -0
  110. package/apps/octogent/apps/web/src/app/hooks/useInitialColumnsHydration.ts +64 -0
  111. package/apps/octogent/apps/web/src/app/hooks/useMonitorRuntime.ts +220 -0
  112. package/apps/octogent/apps/web/src/app/hooks/usePersistedUiState.ts +536 -0
  113. package/apps/octogent/apps/web/src/app/hooks/usePollingData.ts +79 -0
  114. package/apps/octogent/apps/web/src/app/hooks/usePromptLibrary.ts +185 -0
  115. package/apps/octogent/apps/web/src/app/hooks/useTentacleGitLifecycle.ts +530 -0
  116. package/apps/octogent/apps/web/src/app/hooks/useTerminalCompletionNotification.ts +94 -0
  117. package/apps/octogent/apps/web/src/app/hooks/useTerminalMutations.ts +266 -0
  118. package/apps/octogent/apps/web/src/app/hooks/useTerminalStateReconciliation.ts +23 -0
  119. package/apps/octogent/apps/web/src/app/hooks/useUsageHeatmapPolling.ts +43 -0
  120. package/apps/octogent/apps/web/src/app/hooks/useWorkspaceSetup.ts +80 -0
  121. package/apps/octogent/apps/web/src/app/hotkeys.ts +31 -0
  122. package/apps/octogent/apps/web/src/app/monitorNormalizers.ts +145 -0
  123. package/apps/octogent/apps/web/src/app/notificationSounds.ts +164 -0
  124. package/apps/octogent/apps/web/src/app/terminalRuntimeStateStore.ts +261 -0
  125. package/apps/octogent/apps/web/src/app/terminalState.ts +21 -0
  126. package/apps/octogent/apps/web/src/app/types.ts +42 -0
  127. package/apps/octogent/apps/web/src/app/uiStateNormalizers.ts +113 -0
  128. package/apps/octogent/apps/web/src/app/usageNormalizers.ts +58 -0
  129. package/apps/octogent/apps/web/src/components/ActiveAgentsSidebar.tsx +60 -0
  130. package/apps/octogent/apps/web/src/components/ActivityPrimaryView.tsx +21 -0
  131. package/apps/octogent/apps/web/src/components/AgentStateBadge.tsx +47 -0
  132. package/apps/octogent/apps/web/src/components/CanvasPrimaryView.tsx +1532 -0
  133. package/apps/octogent/apps/web/src/components/ClearAllConversationsDialog.tsx +33 -0
  134. package/apps/octogent/apps/web/src/components/CodeIntelArcDiagram.tsx +245 -0
  135. package/apps/octogent/apps/web/src/components/CodeIntelPrimaryView.tsx +104 -0
  136. package/apps/octogent/apps/web/src/components/CodeIntelTreemap.tsx +138 -0
  137. package/apps/octogent/apps/web/src/components/ConsolePrimaryNav.tsx +31 -0
  138. package/apps/octogent/apps/web/src/components/ConversationsPrimaryView.tsx +243 -0
  139. package/apps/octogent/apps/web/src/components/DeckPrimaryView.tsx +613 -0
  140. package/apps/octogent/apps/web/src/components/DeleteTentacleDialog.tsx +91 -0
  141. package/apps/octogent/apps/web/src/components/EmptyOctopus.tsx +715 -0
  142. package/apps/octogent/apps/web/src/components/GitHubPrimaryView.tsx +494 -0
  143. package/apps/octogent/apps/web/src/components/MonitorPrimaryView.tsx +475 -0
  144. package/apps/octogent/apps/web/src/components/PrimaryViewRouter.tsx +99 -0
  145. package/apps/octogent/apps/web/src/components/PromptsPrimaryView.tsx +243 -0
  146. package/apps/octogent/apps/web/src/components/RuntimeStatusStrip.tsx +273 -0
  147. package/apps/octogent/apps/web/src/components/SettingsPrimaryView.tsx +92 -0
  148. package/apps/octogent/apps/web/src/components/SidebarActionPanel.tsx +124 -0
  149. package/apps/octogent/apps/web/src/components/SidebarConversationsList.tsx +279 -0
  150. package/apps/octogent/apps/web/src/components/SidebarPromptsList.tsx +116 -0
  151. package/apps/octogent/apps/web/src/components/TelemetryTape.tsx +106 -0
  152. package/apps/octogent/apps/web/src/components/TentacleGitActionsDialog.tsx +341 -0
  153. package/apps/octogent/apps/web/src/components/Terminal.tsx +524 -0
  154. package/apps/octogent/apps/web/src/components/TerminalPromptPicker.tsx +140 -0
  155. package/apps/octogent/apps/web/src/components/UsageHeatmap.tsx +702 -0
  156. package/apps/octogent/apps/web/src/components/canvas/CanvasTentaclePanel.tsx +485 -0
  157. package/apps/octogent/apps/web/src/components/canvas/CanvasTerminalColumn.tsx +89 -0
  158. package/apps/octogent/apps/web/src/components/canvas/DeleteAllTerminalsDialog.tsx +221 -0
  159. package/apps/octogent/apps/web/src/components/canvas/OctopusNode.tsx +307 -0
  160. package/apps/octogent/apps/web/src/components/canvas/SessionNode.tsx +185 -0
  161. package/apps/octogent/apps/web/src/components/deck/ActionCards.tsx +118 -0
  162. package/apps/octogent/apps/web/src/components/deck/AddTentacleForm.tsx +269 -0
  163. package/apps/octogent/apps/web/src/components/deck/DeckBottomActions.tsx +56 -0
  164. package/apps/octogent/apps/web/src/components/deck/TentaclePod.tsx +334 -0
  165. package/apps/octogent/apps/web/src/components/deck/WorkspaceSetupCard.tsx +105 -0
  166. package/apps/octogent/apps/web/src/components/deck/octopusVisuals.ts +72 -0
  167. package/apps/octogent/apps/web/src/components/terminalReplay.ts +62 -0
  168. package/apps/octogent/apps/web/src/components/terminalWheel.ts +54 -0
  169. package/apps/octogent/apps/web/src/components/ui/ActionButton.tsx +34 -0
  170. package/apps/octogent/apps/web/src/components/ui/ConfirmationDialog.tsx +86 -0
  171. package/apps/octogent/apps/web/src/components/ui/MarkdownContent.tsx +43 -0
  172. package/apps/octogent/apps/web/src/components/ui/SettingsToggle.tsx +34 -0
  173. package/apps/octogent/apps/web/src/components/ui/StatusBadge.tsx +24 -0
  174. package/apps/octogent/apps/web/src/main.tsx +17 -0
  175. package/apps/octogent/apps/web/src/runtime/HttpTerminalSnapshotReader.ts +87 -0
  176. package/apps/octogent/apps/web/src/runtime/runtimeEndpoints.ts +412 -0
  177. package/apps/octogent/apps/web/src/styles/chrome-and-buttons.css +272 -0
  178. package/apps/octogent/apps/web/src/styles/console-canvas-activity.css +358 -0
  179. package/apps/octogent/apps/web/src/styles/console-canvas-canvas.css +1843 -0
  180. package/apps/octogent/apps/web/src/styles/console-canvas-code-intel.css +227 -0
  181. package/apps/octogent/apps/web/src/styles/console-canvas-conversations.css +705 -0
  182. package/apps/octogent/apps/web/src/styles/console-canvas-deck.css +1524 -0
  183. package/apps/octogent/apps/web/src/styles/console-canvas-github.css +541 -0
  184. package/apps/octogent/apps/web/src/styles/console-canvas-monitor.css +595 -0
  185. package/apps/octogent/apps/web/src/styles/console-canvas-pixpack.css +81 -0
  186. package/apps/octogent/apps/web/src/styles/console-canvas-prompts.css +474 -0
  187. package/apps/octogent/apps/web/src/styles/console-canvas-settings.css +207 -0
  188. package/apps/octogent/apps/web/src/styles/console-chrome-status-nav.css +441 -0
  189. package/apps/octogent/apps/web/src/styles/console-overrides-telemetry.css +320 -0
  190. package/apps/octogent/apps/web/src/styles/console-theme-tokens.css +25 -0
  191. package/apps/octogent/apps/web/src/styles/cortex-theme.css +412 -0
  192. package/apps/octogent/apps/web/src/styles/foundation.css +100 -0
  193. package/apps/octogent/apps/web/src/styles/sidebar-and-scrollbars.css +447 -0
  194. package/apps/octogent/apps/web/src/styles/terminal-and-status.css +356 -0
  195. package/apps/octogent/apps/web/src/styles.css +25 -0
  196. package/apps/octogent/apps/web/src/types/ws.d.ts +23 -0
  197. package/apps/octogent/apps/web/tests/CanvasPrimaryView.test.tsx +347 -0
  198. package/apps/octogent/apps/web/tests/HttpTerminalSnapshotReader.test.tsx +54 -0
  199. package/apps/octogent/apps/web/tests/RuntimeStatusStrip.test.tsx +70 -0
  200. package/apps/octogent/apps/web/tests/Terminal.test.tsx +87 -0
  201. package/apps/octogent/apps/web/tests/add-tentacle-form.test.tsx +48 -0
  202. package/apps/octogent/apps/web/tests/app-github-runtime.test.tsx +162 -0
  203. package/apps/octogent/apps/web/tests/app-monitor-runtime.test.tsx +657 -0
  204. package/apps/octogent/apps/web/tests/app-shell-navigation.test.tsx +109 -0
  205. package/apps/octogent/apps/web/tests/app-swarm-refresh.test.tsx +268 -0
  206. package/apps/octogent/apps/web/tests/app-ui-state-persistence.test.tsx +116 -0
  207. package/apps/octogent/apps/web/tests/app-workspace-setup.test.tsx +217 -0
  208. package/apps/octogent/apps/web/tests/canvas-tentacle-panel.test.tsx +195 -0
  209. package/apps/octogent/apps/web/tests/delete-all-terminals-dialog.test.tsx +76 -0
  210. package/apps/octogent/apps/web/tests/githubMetrics.test.tsx +52 -0
  211. package/apps/octogent/apps/web/tests/hotkeys.test.tsx +44 -0
  212. package/apps/octogent/apps/web/tests/runtimeEndpoints.test.tsx +240 -0
  213. package/apps/octogent/apps/web/tests/setup.ts +39 -0
  214. package/apps/octogent/apps/web/tests/tentacle-pod.test.tsx +62 -0
  215. package/apps/octogent/apps/web/tests/terminalReplay.test.ts +71 -0
  216. package/apps/octogent/apps/web/tests/terminalState.test.tsx +49 -0
  217. package/apps/octogent/apps/web/tests/terminalWheel.test.tsx +51 -0
  218. package/apps/octogent/apps/web/tests/test-utils/appTestHarness.ts +48 -0
  219. package/apps/octogent/apps/web/tests/uiPrimitives.test.tsx +31 -0
  220. package/apps/octogent/apps/web/tests/useAgentRuntimeStates.test.tsx +47 -0
  221. package/apps/octogent/apps/web/tsconfig.json +8 -0
  222. package/apps/octogent/apps/web/vite.api.bundle.config.mts +32 -0
  223. package/apps/octogent/apps/web/vite.config.ts +22 -0
  224. package/apps/octogent/bin/octogent +3 -0
  225. package/apps/octogent/biome.json +21 -0
  226. package/apps/octogent/docs/concepts/mental-model.md +79 -0
  227. package/apps/octogent/docs/concepts/runtime-and-api.md +60 -0
  228. package/apps/octogent/docs/concepts/tentacles.md +85 -0
  229. package/apps/octogent/docs/getting-started/installation.md +54 -0
  230. package/apps/octogent/docs/getting-started/quickstart.md +79 -0
  231. package/apps/octogent/docs/guides/inter-agent-messaging.md +43 -0
  232. package/apps/octogent/docs/guides/orchestrating-child-agents.md +49 -0
  233. package/apps/octogent/docs/guides/working-with-todos.md +56 -0
  234. package/apps/octogent/docs/index.md +40 -0
  235. package/apps/octogent/docs/reference/api.md +103 -0
  236. package/apps/octogent/docs/reference/cli.md +71 -0
  237. package/apps/octogent/docs/reference/experimental-features.md +28 -0
  238. package/apps/octogent/docs/reference/filesystem-layout.md +62 -0
  239. package/apps/octogent/docs/reference/troubleshooting.md +49 -0
  240. package/apps/octogent/package.json +35 -0
  241. package/apps/octogent/packages/core/AGENTS.md +31 -0
  242. package/apps/octogent/packages/core/package.json +12 -0
  243. package/apps/octogent/packages/core/src/adapters/InMemoryTerminalSnapshotReader.ts +10 -0
  244. package/apps/octogent/packages/core/src/application/buildTerminalList.ts +13 -0
  245. package/apps/octogent/packages/core/src/domain/agentRuntime.ts +18 -0
  246. package/apps/octogent/packages/core/src/domain/channel.ts +8 -0
  247. package/apps/octogent/packages/core/src/domain/completionSound.ts +14 -0
  248. package/apps/octogent/packages/core/src/domain/conversation.ts +48 -0
  249. package/apps/octogent/packages/core/src/domain/deck.ts +33 -0
  250. package/apps/octogent/packages/core/src/domain/git.ts +32 -0
  251. package/apps/octogent/packages/core/src/domain/monitor.ts +62 -0
  252. package/apps/octogent/packages/core/src/domain/setup.ts +27 -0
  253. package/apps/octogent/packages/core/src/domain/terminal.ts +17 -0
  254. package/apps/octogent/packages/core/src/domain/uiState.ts +22 -0
  255. package/apps/octogent/packages/core/src/domain/usage.ts +60 -0
  256. package/apps/octogent/packages/core/src/index.ts +15 -0
  257. package/apps/octogent/packages/core/src/ports/TerminalSnapshotReader.ts +5 -0
  258. package/apps/octogent/packages/core/src/util/typeCoercion.ts +20 -0
  259. package/apps/octogent/packages/core/tests/buildTerminalList.test.ts +75 -0
  260. package/apps/octogent/packages/core/tsconfig.json +7 -0
  261. package/apps/octogent/packages/core/tsconfig.tsbuildinfo +1 -0
  262. package/apps/octogent/packages/core/vitest.config.ts +7 -0
  263. package/apps/octogent/pnpm-lock.yaml +3212 -0
  264. package/apps/octogent/pnpm-workspace.yaml +3 -0
  265. package/apps/octogent/prompts/meta-prompt-generator.md +223 -0
  266. package/apps/octogent/prompts/octoboss-clean-contexts.md +30 -0
  267. package/apps/octogent/prompts/octoboss-reorganize-tentacles.md +29 -0
  268. package/apps/octogent/prompts/octoboss-reorganize-todos.md +27 -0
  269. package/apps/octogent/prompts/sandbox-init.md +3 -0
  270. package/apps/octogent/prompts/swarm-parent.md +83 -0
  271. package/apps/octogent/prompts/swarm-worker.md +50 -0
  272. package/apps/octogent/prompts/tentacle-context-init.md +1 -0
  273. package/apps/octogent/prompts/tentacle-planner.md +110 -0
  274. package/apps/octogent/prompts/tentacle-reorganize-todos.md +20 -0
  275. package/apps/octogent/prompts/tentacle-update-tentacle.md +18 -0
  276. package/apps/octogent/scripts/build-package.mjs +23 -0
  277. package/apps/octogent/scripts/dev.mjs +158 -0
  278. package/apps/octogent/scripts/smoke-public-install.mjs +271 -0
  279. package/apps/octogent/static/images/octogent-header.png +0 -0
  280. package/apps/octogent/static/images/preview_1.jpg +0 -0
  281. package/apps/octogent/static/images/preview_2.jpg +0 -0
  282. package/apps/octogent/static/images/preview_3.jpg +0 -0
  283. package/apps/octogent/static/images/preview_4.jpg +0 -0
  284. package/apps/octogent/static/images/preview_5.jpg +0 -0
  285. package/apps/octogent/static/images/preview_6.jpg +0 -0
  286. package/apps/octogent/tsconfig.base.json +16 -0
  287. package/bin/AGI +3 -0
  288. package/bin/AGI-install-app +71 -0
  289. package/bin/AGI-ui +16 -0
  290. package/bin/AGI-voice +15 -0
  291. package/bin/AGI-web +16 -0
  292. package/bin/cortex +109 -0
  293. package/bin/cortex-octogent +99 -0
  294. package/bin/import-specifier.mjs +13 -0
  295. package/bin/import-specifier.test.mjs +13 -0
  296. package/bin/octo +150 -0
  297. package/dist/cli.mjs +555650 -0
  298. package/package.json +157 -0
  299. package/scripts/setup-wizard.ts +390 -0
@@ -0,0 +1,185 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+
3
+ import { buildPromptItemUrl, buildPromptsUrl } from "../../runtime/runtimeEndpoints";
4
+ import type { PromptDetail, PromptLibraryEntry } from "../types";
5
+
6
+ type UsePromptLibraryOptions = {
7
+ enabled?: boolean;
8
+ };
9
+
10
+ type UsePromptLibraryResult = {
11
+ prompts: PromptLibraryEntry[];
12
+ selectedPromptName: string | null;
13
+ selectedPromptDetail: PromptDetail | null;
14
+ isLoadingPrompts: boolean;
15
+ isLoadingDetail: boolean;
16
+ isEditing: boolean;
17
+ editDraft: string;
18
+ errorMessage: string | null;
19
+ refreshPrompts: () => Promise<void>;
20
+ selectPrompt: (name: string) => void;
21
+ savePrompt: (name: string, content: string) => Promise<boolean>;
22
+ deletePrompt: (name: string) => Promise<boolean>;
23
+ startEditing: () => void;
24
+ cancelEditing: () => void;
25
+ setEditDraft: (draft: string) => void;
26
+ submitEdit: () => Promise<boolean>;
27
+ };
28
+
29
+ export const usePromptLibrary = ({
30
+ enabled = true,
31
+ }: UsePromptLibraryOptions = {}): UsePromptLibraryResult => {
32
+ const [prompts, setPrompts] = useState<PromptLibraryEntry[]>([]);
33
+ const [selectedPromptName, setSelectedPromptName] = useState<string | null>(null);
34
+ const [selectedPromptDetail, setSelectedPromptDetail] = useState<PromptDetail | null>(null);
35
+ const [isLoadingPrompts, setIsLoadingPrompts] = useState(false);
36
+ const [isLoadingDetail, setIsLoadingDetail] = useState(false);
37
+ const [isEditing, setIsEditing] = useState(false);
38
+ const [editDraft, setEditDraft] = useState("");
39
+ const [errorMessage, setErrorMessage] = useState<string | null>(null);
40
+ const detailRequestRef = useRef(0);
41
+
42
+ const refreshPrompts = useCallback(async () => {
43
+ setIsLoadingPrompts(true);
44
+ setErrorMessage(null);
45
+ try {
46
+ const res = await fetch(buildPromptsUrl());
47
+ if (!res.ok) throw new Error("Failed to load prompts");
48
+ const data = (await res.json()) as { prompts: PromptLibraryEntry[] };
49
+ setPrompts(data.prompts);
50
+ } catch (err) {
51
+ setErrorMessage(err instanceof Error ? err.message : "Failed to load prompts");
52
+ } finally {
53
+ setIsLoadingPrompts(false);
54
+ }
55
+ }, []);
56
+
57
+ const selectPrompt = useCallback((name: string) => {
58
+ setSelectedPromptName(name);
59
+ setIsEditing(false);
60
+ setIsLoadingDetail(true);
61
+ setErrorMessage(null);
62
+
63
+ const requestId = ++detailRequestRef.current;
64
+
65
+ fetch(buildPromptItemUrl(name))
66
+ .then(async (res) => {
67
+ if (requestId !== detailRequestRef.current) return;
68
+ if (!res.ok) throw new Error("Prompt not found");
69
+ const data = (await res.json()) as PromptDetail;
70
+ setSelectedPromptDetail(data);
71
+ })
72
+ .catch((err) => {
73
+ if (requestId !== detailRequestRef.current) return;
74
+ setSelectedPromptDetail(null);
75
+ setErrorMessage(err instanceof Error ? err.message : "Failed to load prompt");
76
+ })
77
+ .finally(() => {
78
+ if (requestId === detailRequestRef.current) {
79
+ setIsLoadingDetail(false);
80
+ }
81
+ });
82
+ }, []);
83
+
84
+ const savePrompt = useCallback(
85
+ async (name: string, content: string): Promise<boolean> => {
86
+ setErrorMessage(null);
87
+ try {
88
+ const res = await fetch(buildPromptsUrl(), {
89
+ method: "POST",
90
+ headers: { "Content-Type": "application/json" },
91
+ body: JSON.stringify({ name, content }),
92
+ });
93
+ if (!res.ok) {
94
+ const data = (await res.json()) as { error?: string };
95
+ throw new Error(data.error ?? "Failed to save prompt");
96
+ }
97
+ await refreshPrompts();
98
+ return true;
99
+ } catch (err) {
100
+ setErrorMessage(err instanceof Error ? err.message : "Failed to save prompt");
101
+ return false;
102
+ }
103
+ },
104
+ [refreshPrompts],
105
+ );
106
+
107
+ const deletePrompt = useCallback(
108
+ async (name: string): Promise<boolean> => {
109
+ setErrorMessage(null);
110
+ try {
111
+ const res = await fetch(buildPromptItemUrl(name), { method: "DELETE" });
112
+ if (!res.ok) throw new Error("Failed to delete prompt");
113
+ if (selectedPromptName === name) {
114
+ setSelectedPromptName(null);
115
+ setSelectedPromptDetail(null);
116
+ }
117
+ await refreshPrompts();
118
+ return true;
119
+ } catch (err) {
120
+ setErrorMessage(err instanceof Error ? err.message : "Failed to delete prompt");
121
+ return false;
122
+ }
123
+ },
124
+ [refreshPrompts, selectedPromptName],
125
+ );
126
+
127
+ const startEditing = useCallback(() => {
128
+ if (selectedPromptDetail) {
129
+ setEditDraft(selectedPromptDetail.content);
130
+ setIsEditing(true);
131
+ }
132
+ }, [selectedPromptDetail]);
133
+
134
+ const cancelEditing = useCallback(() => {
135
+ setIsEditing(false);
136
+ setEditDraft("");
137
+ }, []);
138
+
139
+ const submitEdit = useCallback(async (): Promise<boolean> => {
140
+ if (!selectedPromptName) return false;
141
+ setErrorMessage(null);
142
+ try {
143
+ const res = await fetch(buildPromptItemUrl(selectedPromptName), {
144
+ method: "PUT",
145
+ headers: { "Content-Type": "application/json" },
146
+ body: JSON.stringify({ content: editDraft }),
147
+ });
148
+ if (!res.ok) throw new Error("Failed to update prompt");
149
+ const data = (await res.json()) as PromptDetail;
150
+ setSelectedPromptDetail(data);
151
+ setIsEditing(false);
152
+ setEditDraft("");
153
+ await refreshPrompts();
154
+ return true;
155
+ } catch (err) {
156
+ setErrorMessage(err instanceof Error ? err.message : "Failed to update prompt");
157
+ return false;
158
+ }
159
+ }, [selectedPromptName, editDraft, refreshPrompts]);
160
+
161
+ useEffect(() => {
162
+ if (enabled) {
163
+ void refreshPrompts();
164
+ }
165
+ }, [enabled, refreshPrompts]);
166
+
167
+ return {
168
+ prompts,
169
+ selectedPromptName,
170
+ selectedPromptDetail,
171
+ isLoadingPrompts,
172
+ isLoadingDetail,
173
+ isEditing,
174
+ editDraft,
175
+ errorMessage,
176
+ refreshPrompts,
177
+ selectPrompt,
178
+ savePrompt,
179
+ deletePrompt,
180
+ startEditing,
181
+ cancelEditing,
182
+ setEditDraft,
183
+ submitEdit,
184
+ };
185
+ };
@@ -0,0 +1,530 @@
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import type { Dispatch, SetStateAction } from "react";
3
+
4
+ import {
5
+ buildTentacleGitCommitUrl,
6
+ buildTentacleGitPullRequestMergeUrl,
7
+ buildTentacleGitPullRequestUrl,
8
+ buildTentacleGitPushUrl,
9
+ buildTentacleGitStatusUrl,
10
+ buildTentacleGitSyncUrl,
11
+ } from "../../runtime/runtimeEndpoints";
12
+ import type {
13
+ TentacleGitStatusSnapshot,
14
+ TentaclePullRequestSnapshot,
15
+ TerminalView,
16
+ } from "../types";
17
+
18
+ type UseTentacleGitLifecycleOptions = {
19
+ columns: TerminalView;
20
+ };
21
+
22
+ type UseTentacleGitLifecycleResult = {
23
+ gitStatusByTentacleId: Record<string, TentacleGitStatusSnapshot>;
24
+ gitStatusLoadingByTentacleId: Record<string, boolean>;
25
+ pullRequestByTentacleId: Record<string, TentaclePullRequestSnapshot>;
26
+ pullRequestLoadingByTentacleId: Record<string, boolean>;
27
+ openGitTentacleId: string | null;
28
+ openGitTentacleStatus: TentacleGitStatusSnapshot | null;
29
+ openGitTentaclePullRequest: TentaclePullRequestSnapshot | null;
30
+ gitCommitMessageDraft: string;
31
+ gitDialogError: string | null;
32
+ isGitDialogLoading: boolean;
33
+ isGitDialogMutating: boolean;
34
+ setGitCommitMessageDraft: Dispatch<SetStateAction<string>>;
35
+ openTentacleGitActions: (tentacleId: string) => void;
36
+ closeTentacleGitActions: () => void;
37
+ commitTentacleChanges: () => Promise<void>;
38
+ commitAndPushTentacleBranch: () => Promise<void>;
39
+ pushTentacleBranch: () => Promise<void>;
40
+ syncTentacleBranch: () => Promise<void>;
41
+ mergeTentaclePullRequest: () => Promise<void>;
42
+ };
43
+
44
+ const parseGitError = async (response: Response, fallback: string) => {
45
+ try {
46
+ const payload = (await response.json()) as { error?: unknown };
47
+ if (typeof payload.error === "string" && payload.error.trim().length > 0) {
48
+ return payload.error.trim();
49
+ }
50
+ } catch {
51
+ return fallback;
52
+ }
53
+
54
+ return fallback;
55
+ };
56
+
57
+ const parseTentacleGitStatus = (payload: unknown): TentacleGitStatusSnapshot | null => {
58
+ if (payload === null || payload === undefined || typeof payload !== "object") {
59
+ return null;
60
+ }
61
+
62
+ const record = payload as Record<string, unknown>;
63
+ if (
64
+ typeof record.tentacleId !== "string" ||
65
+ (record.workspaceMode !== "shared" && record.workspaceMode !== "worktree") ||
66
+ typeof record.branchName !== "string" ||
67
+ (record.upstreamBranchName !== null && typeof record.upstreamBranchName !== "string") ||
68
+ typeof record.isDirty !== "boolean" ||
69
+ typeof record.aheadCount !== "number" ||
70
+ typeof record.behindCount !== "number" ||
71
+ typeof record.hasConflicts !== "boolean" ||
72
+ !Array.isArray(record.changedFiles) ||
73
+ !record.changedFiles.every((file) => typeof file === "string") ||
74
+ (record.defaultBaseBranchName !== null && typeof record.defaultBaseBranchName !== "string")
75
+ ) {
76
+ return null;
77
+ }
78
+
79
+ return {
80
+ tentacleId: record.tentacleId,
81
+ workspaceMode: record.workspaceMode,
82
+ branchName: record.branchName,
83
+ upstreamBranchName: record.upstreamBranchName,
84
+ isDirty: record.isDirty,
85
+ aheadCount: record.aheadCount,
86
+ behindCount: record.behindCount,
87
+ insertedLineCount: typeof record.insertedLineCount === "number" ? record.insertedLineCount : 0,
88
+ deletedLineCount: typeof record.deletedLineCount === "number" ? record.deletedLineCount : 0,
89
+ hasConflicts: record.hasConflicts,
90
+ changedFiles: [...record.changedFiles],
91
+ defaultBaseBranchName: record.defaultBaseBranchName,
92
+ };
93
+ };
94
+
95
+ const parseTentaclePullRequest = (payload: unknown): TentaclePullRequestSnapshot | null => {
96
+ if (payload === null || payload === undefined || typeof payload !== "object") {
97
+ return null;
98
+ }
99
+
100
+ const record = payload as Record<string, unknown>;
101
+ if (
102
+ typeof record.tentacleId !== "string" ||
103
+ (record.workspaceMode !== "shared" && record.workspaceMode !== "worktree") ||
104
+ (record.status !== "none" &&
105
+ record.status !== "open" &&
106
+ record.status !== "merged" &&
107
+ record.status !== "closed") ||
108
+ (record.number !== null && typeof record.number !== "number") ||
109
+ (record.url !== null && typeof record.url !== "string") ||
110
+ (record.title !== null && typeof record.title !== "string") ||
111
+ (record.baseRef !== null && typeof record.baseRef !== "string") ||
112
+ (record.headRef !== null && typeof record.headRef !== "string") ||
113
+ (record.isDraft !== null && typeof record.isDraft !== "boolean") ||
114
+ (record.mergeable !== null &&
115
+ record.mergeable !== "MERGEABLE" &&
116
+ record.mergeable !== "CONFLICTING" &&
117
+ record.mergeable !== "UNKNOWN") ||
118
+ (record.mergeStateStatus !== null && typeof record.mergeStateStatus !== "string")
119
+ ) {
120
+ return null;
121
+ }
122
+
123
+ return {
124
+ tentacleId: record.tentacleId,
125
+ workspaceMode: record.workspaceMode,
126
+ status: record.status,
127
+ number: record.number,
128
+ url: record.url,
129
+ title: record.title,
130
+ baseRef: record.baseRef,
131
+ headRef: record.headRef,
132
+ isDraft: record.isDraft,
133
+ mergeable: record.mergeable,
134
+ mergeStateStatus: record.mergeStateStatus,
135
+ };
136
+ };
137
+
138
+ export const useTentacleGitLifecycle = ({
139
+ columns,
140
+ }: UseTentacleGitLifecycleOptions): UseTentacleGitLifecycleResult => {
141
+ const [gitStatusByTentacleId, setGitStatusByTentacleId] = useState<
142
+ Record<string, TentacleGitStatusSnapshot>
143
+ >({});
144
+ const [gitStatusLoadingByTentacleId, setGitStatusLoadingByTentacleId] = useState<
145
+ Record<string, boolean>
146
+ >({});
147
+ const [gitStatusAttemptedTentacleIds, setGitStatusAttemptedTentacleIds] = useState<
148
+ Record<string, boolean>
149
+ >({});
150
+ const [pullRequestByTentacleId, setPullRequestByTentacleId] = useState<
151
+ Record<string, TentaclePullRequestSnapshot>
152
+ >({});
153
+ const [pullRequestLoadingByTentacleId, setPullRequestLoadingByTentacleId] = useState<
154
+ Record<string, boolean>
155
+ >({});
156
+ const [pullRequestAttemptedTentacleIds, setPullRequestAttemptedTentacleIds] = useState<
157
+ Record<string, boolean>
158
+ >({});
159
+ const [openGitTentacleId, setOpenGitTentacleId] = useState<string | null>(null);
160
+ const [gitCommitMessageDraft, setGitCommitMessageDraft] = useState("");
161
+ const [gitDialogError, setGitDialogError] = useState<string | null>(null);
162
+ const [isGitDialogMutating, setIsGitDialogMutating] = useState(false);
163
+
164
+ const fetchTentacleGitStatus = useCallback(async (tentacleId: string) => {
165
+ setGitStatusLoadingByTentacleId((current) => ({
166
+ ...current,
167
+ [tentacleId]: true,
168
+ }));
169
+
170
+ try {
171
+ const response = await fetch(buildTentacleGitStatusUrl(tentacleId), {
172
+ method: "GET",
173
+ headers: {
174
+ Accept: "application/json",
175
+ },
176
+ });
177
+ if (!response.ok) {
178
+ const errorMessage = await parseGitError(
179
+ response,
180
+ `Unable to fetch git status (${response.status}).`,
181
+ );
182
+ throw new Error(errorMessage);
183
+ }
184
+
185
+ const payload = parseTentacleGitStatus(await response.json());
186
+ if (!payload) {
187
+ throw new Error("Unable to parse git status response.");
188
+ }
189
+
190
+ setGitStatusByTentacleId((current) => ({
191
+ ...current,
192
+ [tentacleId]: payload,
193
+ }));
194
+ return payload;
195
+ } finally {
196
+ setGitStatusLoadingByTentacleId((current) => ({
197
+ ...current,
198
+ [tentacleId]: false,
199
+ }));
200
+ }
201
+ }, []);
202
+
203
+ const fetchTentaclePullRequest = useCallback(async (tentacleId: string) => {
204
+ setPullRequestLoadingByTentacleId((current) => ({
205
+ ...current,
206
+ [tentacleId]: true,
207
+ }));
208
+
209
+ try {
210
+ const response = await fetch(buildTentacleGitPullRequestUrl(tentacleId), {
211
+ method: "GET",
212
+ headers: {
213
+ Accept: "application/json",
214
+ },
215
+ });
216
+ if (!response.ok) {
217
+ const errorMessage = await parseGitError(
218
+ response,
219
+ `Unable to fetch pull request status (${response.status}).`,
220
+ );
221
+ throw new Error(errorMessage);
222
+ }
223
+
224
+ const payload = parseTentaclePullRequest(await response.json());
225
+ if (!payload) {
226
+ throw new Error("Unable to parse pull request response.");
227
+ }
228
+
229
+ setPullRequestByTentacleId((current) => ({
230
+ ...current,
231
+ [tentacleId]: payload,
232
+ }));
233
+ return payload;
234
+ } finally {
235
+ setPullRequestLoadingByTentacleId((current) => ({
236
+ ...current,
237
+ [tentacleId]: false,
238
+ }));
239
+ }
240
+ }, []);
241
+
242
+ const worktreeTentacleIds = useMemo(
243
+ () =>
244
+ columns
245
+ .filter((column) => column.workspaceMode === "worktree")
246
+ .map((column) => column.tentacleId),
247
+ [columns],
248
+ );
249
+
250
+ useEffect(() => {
251
+ const activeTentacleIds = new Set(columns.map((column) => column.tentacleId));
252
+ setGitStatusByTentacleId((current) =>
253
+ Object.fromEntries(
254
+ Object.entries(current).filter(([tentacleId]) => activeTentacleIds.has(tentacleId)),
255
+ ),
256
+ );
257
+ setGitStatusLoadingByTentacleId((current) =>
258
+ Object.fromEntries(
259
+ Object.entries(current).filter(([tentacleId]) => activeTentacleIds.has(tentacleId)),
260
+ ),
261
+ );
262
+ setGitStatusAttemptedTentacleIds((current) =>
263
+ Object.fromEntries(
264
+ Object.entries(current).filter(([tentacleId]) => activeTentacleIds.has(tentacleId)),
265
+ ),
266
+ );
267
+ setPullRequestByTentacleId((current) =>
268
+ Object.fromEntries(
269
+ Object.entries(current).filter(([tentacleId]) => activeTentacleIds.has(tentacleId)),
270
+ ),
271
+ );
272
+ setPullRequestLoadingByTentacleId((current) =>
273
+ Object.fromEntries(
274
+ Object.entries(current).filter(([tentacleId]) => activeTentacleIds.has(tentacleId)),
275
+ ),
276
+ );
277
+ setPullRequestAttemptedTentacleIds((current) =>
278
+ Object.fromEntries(
279
+ Object.entries(current).filter(([tentacleId]) => activeTentacleIds.has(tentacleId)),
280
+ ),
281
+ );
282
+ if (openGitTentacleId && !activeTentacleIds.has(openGitTentacleId)) {
283
+ setOpenGitTentacleId(null);
284
+ setGitDialogError(null);
285
+ setGitCommitMessageDraft("");
286
+ }
287
+ }, [columns, openGitTentacleId]);
288
+
289
+ useEffect(() => {
290
+ for (const tentacleId of worktreeTentacleIds) {
291
+ if (gitStatusAttemptedTentacleIds[tentacleId]) {
292
+ continue;
293
+ }
294
+
295
+ setGitStatusAttemptedTentacleIds((current) => ({
296
+ ...current,
297
+ [tentacleId]: true,
298
+ }));
299
+ void fetchTentacleGitStatus(tentacleId).catch((error: unknown) => {
300
+ console.warn(`[git] Failed to fetch status for tentacle ${tentacleId}:`, error);
301
+ });
302
+ }
303
+ }, [fetchTentacleGitStatus, gitStatusAttemptedTentacleIds, worktreeTentacleIds]);
304
+
305
+ useEffect(() => {
306
+ for (const tentacleId of worktreeTentacleIds) {
307
+ if (pullRequestAttemptedTentacleIds[tentacleId]) {
308
+ continue;
309
+ }
310
+
311
+ setPullRequestAttemptedTentacleIds((current) => ({
312
+ ...current,
313
+ [tentacleId]: true,
314
+ }));
315
+ void fetchTentaclePullRequest(tentacleId).catch((error: unknown) => {
316
+ console.warn(`[git] Failed to fetch pull request for tentacle ${tentacleId}:`, error);
317
+ });
318
+ }
319
+ }, [fetchTentaclePullRequest, pullRequestAttemptedTentacleIds, worktreeTentacleIds]);
320
+
321
+ const openTentacleGitActions = useCallback(
322
+ (tentacleId: string) => {
323
+ setOpenGitTentacleId(tentacleId);
324
+ setGitDialogError(null);
325
+ setGitCommitMessageDraft("");
326
+
327
+ void Promise.all([
328
+ fetchTentacleGitStatus(tentacleId),
329
+ fetchTentaclePullRequest(tentacleId),
330
+ ]).catch((error: unknown) => {
331
+ setGitDialogError(
332
+ error instanceof Error ? error.message : "Unable to fetch git lifecycle data.",
333
+ );
334
+ });
335
+ },
336
+ [fetchTentacleGitStatus, fetchTentaclePullRequest],
337
+ );
338
+
339
+ const closeTentacleGitActions = useCallback(() => {
340
+ setOpenGitTentacleId(null);
341
+ setGitDialogError(null);
342
+ setGitCommitMessageDraft("");
343
+ }, []);
344
+
345
+ const runGitMutation = useCallback(
346
+ async (
347
+ action: "commit" | "push" | "sync",
348
+ request: { body?: string; headers?: Record<string, string> } = {},
349
+ ): Promise<TentacleGitStatusSnapshot | null> => {
350
+ if (!openGitTentacleId) {
351
+ return null;
352
+ }
353
+
354
+ const endpoint =
355
+ action === "commit"
356
+ ? buildTentacleGitCommitUrl(openGitTentacleId)
357
+ : action === "push"
358
+ ? buildTentacleGitPushUrl(openGitTentacleId)
359
+ : buildTentacleGitSyncUrl(openGitTentacleId);
360
+
361
+ setIsGitDialogMutating(true);
362
+ setGitDialogError(null);
363
+ try {
364
+ const response = await fetch(endpoint, {
365
+ method: "POST",
366
+ headers: {
367
+ Accept: "application/json",
368
+ ...request.headers,
369
+ },
370
+ body: request.body ?? null,
371
+ });
372
+
373
+ if (!response.ok) {
374
+ const errorMessage = await parseGitError(
375
+ response,
376
+ `Unable to ${action} (${response.status}).`,
377
+ );
378
+ throw new Error(errorMessage);
379
+ }
380
+
381
+ const payload = parseTentacleGitStatus(await response.json());
382
+ if (!payload) {
383
+ throw new Error("Unable to parse git lifecycle response.");
384
+ }
385
+
386
+ setGitStatusByTentacleId((current) => ({
387
+ ...current,
388
+ [openGitTentacleId]: payload,
389
+ }));
390
+ return payload;
391
+ } catch (error) {
392
+ setGitDialogError(
393
+ error instanceof Error ? error.message : `Unable to ${action} tentacle worktree.`,
394
+ );
395
+ return null;
396
+ } finally {
397
+ setIsGitDialogMutating(false);
398
+ }
399
+ },
400
+ [openGitTentacleId],
401
+ );
402
+
403
+ const runPullRequestMutation = useCallback(
404
+ async (request: { body?: string; headers?: Record<string, string> } = {}) => {
405
+ if (!openGitTentacleId) {
406
+ return;
407
+ }
408
+
409
+ const endpoint = buildTentacleGitPullRequestMergeUrl(openGitTentacleId);
410
+
411
+ setIsGitDialogMutating(true);
412
+ setGitDialogError(null);
413
+ try {
414
+ const response = await fetch(endpoint, {
415
+ method: "POST",
416
+ headers: {
417
+ Accept: "application/json",
418
+ ...request.headers,
419
+ },
420
+ body: request.body ?? null,
421
+ });
422
+
423
+ if (!response.ok) {
424
+ const errorMessage = await parseGitError(
425
+ response,
426
+ `Unable to merge pull request (${response.status}).`,
427
+ );
428
+ throw new Error(errorMessage);
429
+ }
430
+
431
+ const payload = parseTentaclePullRequest(await response.json());
432
+ if (!payload) {
433
+ throw new Error("Unable to parse pull request response.");
434
+ }
435
+
436
+ setPullRequestByTentacleId((current) => ({
437
+ ...current,
438
+ [openGitTentacleId]: payload,
439
+ }));
440
+ } catch (error) {
441
+ setGitDialogError(error instanceof Error ? error.message : "Unable to merge pull request.");
442
+ } finally {
443
+ setIsGitDialogMutating(false);
444
+ }
445
+ },
446
+ [openGitTentacleId],
447
+ );
448
+
449
+ const commitTentacleChanges = useCallback(async () => {
450
+ const message = gitCommitMessageDraft.trim();
451
+ if (message.length === 0) {
452
+ setGitDialogError("Commit message cannot be empty.");
453
+ return;
454
+ }
455
+
456
+ const committed = await runGitMutation("commit", {
457
+ headers: {
458
+ "Content-Type": "application/json",
459
+ },
460
+ body: JSON.stringify({ message }),
461
+ });
462
+ if (committed) {
463
+ setGitCommitMessageDraft("");
464
+ }
465
+ }, [gitCommitMessageDraft, runGitMutation]);
466
+
467
+ const commitAndPushTentacleBranch = useCallback(async () => {
468
+ const message = gitCommitMessageDraft.trim();
469
+ if (message.length === 0) {
470
+ setGitDialogError("Commit message cannot be empty.");
471
+ return;
472
+ }
473
+
474
+ const committed = await runGitMutation("commit", {
475
+ headers: {
476
+ "Content-Type": "application/json",
477
+ },
478
+ body: JSON.stringify({ message }),
479
+ });
480
+ if (!committed) {
481
+ return;
482
+ }
483
+ setGitCommitMessageDraft("");
484
+ await runGitMutation("push");
485
+ }, [gitCommitMessageDraft, runGitMutation]);
486
+
487
+ const pushTentacleBranch = useCallback(async () => {
488
+ await runGitMutation("push");
489
+ }, [runGitMutation]);
490
+
491
+ const syncTentacleBranch = useCallback(async () => {
492
+ await runGitMutation("sync");
493
+ }, [runGitMutation]);
494
+
495
+ const mergeTentaclePullRequest = useCallback(async () => {
496
+ await runPullRequestMutation();
497
+ }, [runPullRequestMutation]);
498
+
499
+ const openGitTentacleStatus =
500
+ openGitTentacleId !== null ? (gitStatusByTentacleId[openGitTentacleId] ?? null) : null;
501
+ const openGitTentaclePullRequest =
502
+ openGitTentacleId !== null ? (pullRequestByTentacleId[openGitTentacleId] ?? null) : null;
503
+ const isGitDialogLoading =
504
+ openGitTentacleId !== null
505
+ ? (gitStatusLoadingByTentacleId[openGitTentacleId] ?? false) ||
506
+ (pullRequestLoadingByTentacleId[openGitTentacleId] ?? false)
507
+ : false;
508
+
509
+ return {
510
+ gitStatusByTentacleId,
511
+ gitStatusLoadingByTentacleId,
512
+ pullRequestByTentacleId,
513
+ pullRequestLoadingByTentacleId,
514
+ openGitTentacleId,
515
+ openGitTentacleStatus,
516
+ openGitTentaclePullRequest,
517
+ gitCommitMessageDraft,
518
+ gitDialogError,
519
+ isGitDialogLoading,
520
+ isGitDialogMutating,
521
+ setGitCommitMessageDraft,
522
+ openTentacleGitActions,
523
+ closeTentacleGitActions,
524
+ commitTentacleChanges,
525
+ commitAndPushTentacleBranch,
526
+ pushTentacleBranch,
527
+ syncTentacleBranch,
528
+ mergeTentaclePullRequest,
529
+ };
530
+ };