@promptbook/cli 0.112.0-99 → 0.113.0-0

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 (850) hide show
  1. package/README.md +76 -44
  2. package/agents/default/developer.book +24 -0
  3. package/apps/agents-server/README.md +19 -2
  4. package/apps/agents-server/env-manual/GITHUB_APP.md +1 -1
  5. package/apps/agents-server/next.config.ts +41 -1
  6. package/apps/agents-server/package.json +1 -1
  7. package/apps/agents-server/playwright.config.ts +3 -0
  8. package/apps/agents-server/public/promptbook-logo-blue.png +0 -0
  9. package/apps/agents-server/public/promptbook-logo-white.png +0 -0
  10. package/apps/agents-server/scripts/prerender-homepage.js +76 -1
  11. package/apps/agents-server/src/app/AddAgentButton.tsx +0 -5
  12. package/apps/agents-server/src/app/[agentName]/layout.tsx +1 -0
  13. package/apps/agents-server/src/app/actions.ts +70 -9
  14. package/apps/agents-server/src/app/admin/about/page.tsx +1 -1
  15. package/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +4 -1
  16. package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +3 -0
  17. package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackTable.tsx +13 -8
  18. package/apps/agents-server/src/app/admin/chat-feedback/page.tsx +2 -4
  19. package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +3 -0
  20. package/apps/agents-server/src/app/admin/chat-history/ChatHistoryTable.tsx +13 -8
  21. package/apps/agents-server/src/app/admin/chat-history/page.tsx +2 -4
  22. package/apps/agents-server/src/app/admin/cli-access/CliAccessClient.tsx +1 -3
  23. package/apps/agents-server/src/app/admin/code-runners/CodeRunnersClient.tsx +19 -11
  24. package/apps/agents-server/src/app/admin/custom-css/CustomCssClient.tsx +4 -0
  25. package/apps/agents-server/src/app/admin/custom-css/CustomCssEditorPanel.tsx +7 -1
  26. package/apps/agents-server/src/app/admin/custom-css/CustomCssFilesPanel.tsx +7 -1
  27. package/apps/agents-server/src/app/admin/custom-js/CustomJsClient.tsx +11 -0
  28. package/apps/agents-server/src/app/admin/custom-js/CustomJsEditorPanel.tsx +7 -1
  29. package/apps/agents-server/src/app/admin/custom-js/CustomJsFilesPanel.tsx +7 -1
  30. package/apps/agents-server/src/app/admin/files/FilesGalleryClient.tsx +4 -0
  31. package/apps/agents-server/src/app/admin/files/FilesGalleryGrid.tsx +9 -11
  32. package/apps/agents-server/src/app/admin/files/FilesGalleryTable.tsx +9 -8
  33. package/apps/agents-server/src/app/admin/image-generator-test/ImageAttachmentsEditor.tsx +30 -9
  34. package/apps/agents-server/src/app/admin/images/ImagesGalleryClient.tsx +4 -0
  35. package/apps/agents-server/src/app/admin/images/ImagesGalleryGrid.tsx +16 -11
  36. package/apps/agents-server/src/app/admin/images/ImagesGalleryTable.tsx +18 -9
  37. package/apps/agents-server/src/app/admin/limits/LimitsClient.tsx +11 -12
  38. package/apps/agents-server/src/app/admin/login-methods/shibboleth/page.tsx +355 -0
  39. package/apps/agents-server/src/app/admin/logs/LogsClient.tsx +9 -3
  40. package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +7 -6
  41. package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +671 -45
  42. package/apps/agents-server/src/app/admin/servers/CreateServerDialog.tsx +22 -1
  43. package/apps/agents-server/src/app/admin/servers/ServersRegistryTable.tsx +14 -13
  44. package/apps/agents-server/src/app/admin/servers/useCreateServerWizard.ts +57 -20
  45. package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +4 -2
  46. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +14 -15
  47. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTasksCard.tsx +4 -1
  48. package/apps/agents-server/src/app/admin/task-manager/useTaskManagerState.ts +6 -9
  49. package/apps/agents-server/src/app/admin/update/CustomCommitPicker.tsx +258 -0
  50. package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +627 -137
  51. package/apps/agents-server/src/app/admin/usage/UsageClient.tsx +4 -2
  52. package/apps/agents-server/src/app/admin/usage/UsageClientAnalyticsPanels.tsx +6 -4
  53. package/apps/agents-server/src/app/admin/usage/UsageClientFormatting.ts +6 -12
  54. package/apps/agents-server/src/app/admin/usage/UsageClientTimelineChart.tsx +7 -4
  55. package/apps/agents-server/src/app/admin/usage/useUsageClientState.ts +12 -4
  56. package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +27 -15
  57. package/apps/agents-server/src/app/agents/[agentName]/ActiveAgentBreadcrumbBinder.tsx +30 -0
  58. package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +13 -2
  59. package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +20 -25
  60. package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +7 -5
  61. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +2 -0
  62. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/messages/route.ts +4 -11
  63. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +85 -56
  64. package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +7 -1
  65. package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorHistory.ts +9 -2
  66. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryPayloadState.ts +38 -4
  67. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistorySyncOperations.ts +4 -1
  68. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatPageLayout.tsx +2 -2
  69. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +19 -13
  70. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +30 -16
  71. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistoryClientState.ts +2 -15
  72. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistorySyncEffects.ts +7 -13
  73. package/apps/agents-server/src/app/agents/[agentName]/chat/useCanonicalAgentChatPanelState.ts +58 -7
  74. package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +6 -1
  75. package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/route.ts +6 -2
  76. package/apps/agents-server/src/app/agents/[agentName]/integration/CalendarIntegrationSection.tsx +23 -5
  77. package/apps/agents-server/src/app/agents/[agentName]/layout.tsx +47 -1
  78. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +4 -2
  79. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +9 -4
  80. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +4 -1
  81. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +10 -3
  82. package/apps/agents-server/src/app/api/admin/cli-access/route.ts +27 -123
  83. package/apps/agents-server/src/app/api/admin/code-runners/authentication/route.ts +33 -125
  84. package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
  85. package/apps/agents-server/src/app/api/admin/servers/route.ts +5 -0
  86. package/apps/agents-server/src/app/api/admin/update/commits/route.ts +35 -0
  87. package/apps/agents-server/src/app/api/admin/update/log/route.ts +42 -0
  88. package/apps/agents-server/src/app/api/admin/update/route.ts +10 -2
  89. package/apps/agents-server/src/app/api/agent-folders/[folderId]/visibility/route.ts +19 -7
  90. package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +39 -25
  91. package/apps/agents-server/src/app/api/agents/export/route.ts +67 -0
  92. package/apps/agents-server/src/app/api/agents/import/route.ts +168 -0
  93. package/apps/agents-server/src/app/api/auth/change-password/route.ts +53 -6
  94. package/apps/agents-server/src/app/api/auth/login/route.ts +17 -16
  95. package/apps/agents-server/src/app/api/auth/logout/route.ts +2 -10
  96. package/apps/agents-server/src/app/api/auth/shibboleth/acs/route.ts +112 -0
  97. package/apps/agents-server/src/app/api/auth/shibboleth/login/route.ts +70 -0
  98. package/apps/agents-server/src/app/api/auth/shibboleth/metadata/route.ts +15 -0
  99. package/apps/agents-server/src/app/api/auth/shibboleth/status/route.ts +17 -0
  100. package/apps/agents-server/src/app/api/chat/citation-label/route.ts +133 -0
  101. package/apps/agents-server/src/app/api/chat/export/pdf/route.ts +167 -2
  102. package/apps/agents-server/src/app/api/chat/route.ts +29 -7
  103. package/apps/agents-server/src/app/api/chat-feedback/export/route.ts +2 -2
  104. package/apps/agents-server/src/app/api/chat-feedback/route.ts +3 -3
  105. package/apps/agents-server/src/app/api/chat-history/[id]/route.ts +2 -2
  106. package/apps/agents-server/src/app/api/chat-history/export/route.ts +2 -2
  107. package/apps/agents-server/src/app/api/chat-history/route.ts +3 -3
  108. package/apps/agents-server/src/app/api/chat-streaming/route.ts +29 -0
  109. package/apps/agents-server/src/app/api/elevenlabs/tts/route.ts +60 -2
  110. package/apps/agents-server/src/app/api/emails/incoming/sendgrid/route.ts +24 -2
  111. package/apps/agents-server/src/app/api/federated-agents/route.ts +1 -1
  112. package/apps/agents-server/src/app/api/health/route.ts +18 -0
  113. package/apps/agents-server/src/app/api/images/[filename]/route.ts +108 -2
  114. package/apps/agents-server/src/app/api/internal/agent-runner-limits/route.ts +52 -0
  115. package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +17 -4
  116. package/apps/agents-server/src/app/api/metadata/export/route.ts +34 -0
  117. package/apps/agents-server/src/app/api/metadata/import/route.ts +47 -0
  118. package/apps/agents-server/src/app/api/metadata/route.ts +4 -0
  119. package/apps/agents-server/src/app/api/openai/v1/audio/transcriptions/route.ts +111 -2
  120. package/apps/agents-server/src/app/api/page-preview/check/route.ts +49 -0
  121. package/apps/agents-server/src/app/api/page-preview/screenshot/route.ts +64 -0
  122. package/apps/agents-server/src/app/api/scrape/route.ts +18 -0
  123. package/apps/agents-server/src/app/api/team-agent-profile/route.ts +20 -0
  124. package/apps/agents-server/src/app/api/upload/route.ts +204 -220
  125. package/apps/agents-server/src/app/api/users/[username]/route.ts +3 -2
  126. package/apps/agents-server/src/app/api/users/route.ts +8 -7
  127. package/apps/agents-server/src/app/api/v1/agents/[agentId]/route.ts +17 -8
  128. package/apps/agents-server/src/app/api/v1/agents/route.ts +2 -0
  129. package/apps/agents-server/src/app/dashboard/page.tsx +12 -17
  130. package/apps/agents-server/src/app/docs/[docId]/page.tsx +1 -1
  131. package/apps/agents-server/src/app/docs/page.tsx +1 -1
  132. package/apps/agents-server/src/app/globals.css +179 -0
  133. package/apps/agents-server/src/app/layout.tsx +33 -4
  134. package/apps/agents-server/src/app/recycle-bin/actions.ts +3 -0
  135. package/apps/agents-server/src/app/recycle-bin/page.tsx +1 -1
  136. package/apps/agents-server/src/app/s3/[first]/[second]/[hash]/[filename]/route.ts +52 -0
  137. package/apps/agents-server/src/app/swagger/SwaggerApiKeysPanel.tsx +4 -1
  138. package/apps/agents-server/src/app/system/settings/KeybindingsSettingsClient.tsx +13 -7
  139. package/apps/agents-server/src/app/system/user-memory/UserMemoryClient.tsx +4 -2
  140. package/apps/agents-server/src/app/system/user-wallet/UserWalletClient.tsx +3 -0
  141. package/apps/agents-server/src/app/system/user-wallet/UserWalletRecordsTable.tsx +5 -1
  142. package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorClient.tsx +3 -0
  143. package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorSidebar.tsx +7 -8
  144. package/apps/agents-server/src/components/AdminTerminal/AdminTerminalCard.tsx +13 -70
  145. package/apps/agents-server/src/components/AdminTerminal/AdminXtermTerminal.tsx +330 -0
  146. package/apps/agents-server/src/components/AdminTerminal/useAdminTerminalSession.ts +45 -5
  147. package/apps/agents-server/src/components/AgentContextMenu/useAgentContextMenuItems.ts +27 -19
  148. package/apps/agents-server/src/components/AgentProfile/AgentCapabilityChips.tsx +39 -5
  149. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +4 -7
  150. package/apps/agents-server/src/components/AgentProfile/AgentProfileImage.tsx +8 -2
  151. package/apps/agents-server/src/components/ApplicationErrorPage/ApplicationErrorPage.tsx +118 -12
  152. package/apps/agents-server/src/components/DocsToolbar/DocsToolbar.tsx +4 -4
  153. package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +9 -9
  154. package/apps/agents-server/src/components/FileUploadAvailability/FileUploadAvailabilityContext.tsx +50 -0
  155. package/apps/agents-server/src/components/FileUploadAvailability/FileUploadUnavailableNotice.tsx +45 -0
  156. package/apps/agents-server/src/components/Footer/Footer.tsx +10 -9
  157. package/apps/agents-server/src/components/Footer/getCommitFooterEmoji.ts +112 -0
  158. package/apps/agents-server/src/components/Header/ActiveAgentBreadcrumbContext.tsx +82 -0
  159. package/apps/agents-server/src/components/Header/Header.tsx +24 -15
  160. package/apps/agents-server/src/components/Header/HeaderTypes.ts +6 -0
  161. package/apps/agents-server/src/components/Header/buildHeaderSystemMenuItems.ts +51 -1
  162. package/apps/agents-server/src/components/Header/useHeaderActiveAgent.ts +26 -7
  163. package/apps/agents-server/src/components/Header/useHeaderAgentMenus.tsx +0 -5
  164. package/apps/agents-server/src/components/Homepage/AgentCard.tsx +7 -1
  165. package/apps/agents-server/src/components/Homepage/AgentsList.tsx +22 -1
  166. package/apps/agents-server/src/components/Homepage/AgentsListHeader.tsx +85 -1
  167. package/apps/agents-server/src/components/Homepage/AgentsListListView.tsx +6 -0
  168. package/apps/agents-server/src/components/Homepage/AgentsListViewContent.tsx +6 -0
  169. package/apps/agents-server/src/components/Homepage/Card.tsx +1 -1
  170. package/apps/agents-server/src/components/Homepage/Section.tsx +3 -1
  171. package/apps/agents-server/src/components/Homepage/SortableFolderCard.tsx +7 -1
  172. package/apps/agents-server/src/components/Homepage/hiddenFolders.ts +104 -0
  173. package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +525 -0
  174. package/apps/agents-server/src/components/Homepage/useAgentsListQueryState.ts +35 -0
  175. package/apps/agents-server/src/components/Homepage/useAgentsListState.ts +38 -4
  176. package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +93 -70
  177. package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +52 -12
  178. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoNewAgentWizard.tsx +151 -0
  179. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoOnboardingNavigation.tsx +50 -0
  180. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/BookLanguagePanel.tsx +125 -0
  181. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/DropZone.tsx +83 -0
  182. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/EmailTestRun.tsx +216 -0
  183. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/KnowledgeList.tsx +79 -0
  184. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/Logo.tsx +20 -0
  185. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownBookEditor.tsx +154 -0
  186. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownPreview.tsx +188 -0
  187. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/RailStepper.tsx +115 -0
  188. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/StepFrame.tsx +47 -0
  189. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/TestChat.tsx +159 -0
  190. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/WizardShell.tsx +114 -0
  191. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/brand/RailArtwork.tsx +60 -0
  192. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/BookStep.tsx +135 -0
  193. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/DoneStep.tsx +215 -0
  194. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/KnowledgeStep.tsx +152 -0
  195. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/TestStep.tsx +262 -0
  196. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/ZadaniStep.tsx +64 -0
  197. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Badge.tsx +41 -0
  198. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Banner.tsx +69 -0
  199. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Button.tsx +77 -0
  200. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Card.tsx +33 -0
  201. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Field.tsx +103 -0
  202. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/IconButton.tsx +40 -0
  203. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Spinner.tsx +14 -0
  204. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/tokens.ts +37 -0
  205. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/bookSections.ts +62 -0
  206. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/emailScenarios.ts +22 -0
  207. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/steps.ts +46 -0
  208. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/index.ts +11 -0
  209. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/cn.ts +4 -0
  210. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/format.ts +9 -0
  211. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/id.ts +11 -0
  212. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentEvalService.ts +30 -0
  213. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentTestService.ts +69 -0
  214. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/bookService.ts +21 -0
  215. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/createManGoAgentSource.ts +107 -0
  216. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/draftService.ts +45 -0
  217. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/uploadService.ts +27 -0
  218. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/OnboardingProvider.tsx +121 -0
  219. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/types.ts +52 -0
  220. package/apps/agents-server/src/components/NewAgentDialog/NewAgentDialog.tsx +7 -3
  221. package/apps/agents-server/src/components/NewAgentDialog/NewAgentWizardKnowledgeStep.tsx +6 -0
  222. package/apps/agents-server/src/components/NewAgentDialog/createNewAgentWizardSource.ts +1 -1
  223. package/apps/agents-server/src/components/NewAgentDialog/trackNewAgentCreationEvent.ts +1 -1
  224. package/apps/agents-server/src/components/NewAgentDialog/useNewAgentDialog.tsx +113 -14
  225. package/apps/agents-server/src/components/NewAgentDialog/useNewAgentWizardKnowledgeState.ts +8 -1
  226. package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +4 -2
  227. package/apps/agents-server/src/components/Skeleton/ConsolePageLoadingSkeleton.tsx +1 -1
  228. package/apps/agents-server/src/components/Skeleton/DocumentationRouteLoadingSkeleton.tsx +1 -1
  229. package/apps/agents-server/src/components/Skeleton/HomepageLoadingSkeleton.tsx +1 -1
  230. package/apps/agents-server/src/components/UsersList/UsersList.tsx +24 -6
  231. package/apps/agents-server/src/components/UsersList/useUsersAdmin.ts +2 -7
  232. package/apps/agents-server/src/constants/defaultAgentAvatarVisual.ts +1 -1
  233. package/apps/agents-server/src/constants/newAgentWizard.ts +17 -8
  234. package/apps/agents-server/src/constants/serverLimits.ts +41 -2
  235. package/apps/agents-server/src/constants/shibbolethAuth.ts +139 -0
  236. package/apps/agents-server/src/database/$provideClientSql.ts +37 -0
  237. package/apps/agents-server/src/database/$provideSupabaseForServer.ts +41 -0
  238. package/apps/agents-server/src/database/customJavascript.ts +62 -1
  239. package/apps/agents-server/src/database/customStylesheet.ts +60 -1
  240. package/apps/agents-server/src/database/getMetadata.ts +121 -4
  241. package/apps/agents-server/src/database/loadAgentsServerEnvFile.ts +29 -0
  242. package/apps/agents-server/src/database/metadataDefaults.ts +85 -31
  243. package/apps/agents-server/src/database/migrate.ts +8 -2
  244. package/apps/agents-server/src/database/migrations/2026-06-0100-shibboleth-auth.sql +136 -0
  245. package/apps/agents-server/src/database/migrations/2026-06-0200-default-agent-avatar-visual-octopus3d3.sql +16 -0
  246. package/apps/agents-server/src/database/migrations/2026-06-1300-user-chat-active-read-indexes.sql +7 -0
  247. package/apps/agents-server/src/database/migrations/2026-06-2200-new-agent-wizard-metadata-key.sql +27 -0
  248. package/apps/agents-server/src/database/migrations/2026-06-2201-new-agent-wizard-mango-default.sql +11 -0
  249. package/apps/agents-server/src/database/migrations/2026-06-2600-agent-directory-performance-indexes.sql +14 -0
  250. package/apps/agents-server/src/database/migrations/2026-06-2700-default-agent-avatar-visual-octopus3d4.sql +16 -0
  251. package/apps/agents-server/src/database/seedCoreAgents.ts +234 -0
  252. package/apps/agents-server/src/database/seedDefaultAgents.ts +223 -0
  253. package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +234 -41
  254. package/apps/agents-server/src/generated/reservedPaths.ts +3 -0
  255. package/apps/agents-server/src/instrumentation-client.ts +28 -0
  256. package/apps/agents-server/src/instrumentation.ts +19 -0
  257. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +4 -0
  258. package/apps/agents-server/src/languages/translations/czech.yaml +5 -1
  259. package/apps/agents-server/src/languages/translations/english.yaml +5 -1
  260. package/apps/agents-server/src/message-providers/email/sendgrid/verifySendgridInboundParseWebhook.ts +345 -0
  261. package/apps/agents-server/src/middleware/applyEmbeddingHeader.ts +4 -2
  262. package/apps/agents-server/src/middleware/contentSecurityPolicy.ts +97 -0
  263. package/apps/agents-server/src/middleware/resolveAccessControlResponse.ts +3 -2
  264. package/apps/agents-server/src/middleware/resolveMiddlewareResponse.ts +8 -3
  265. package/apps/agents-server/src/middleware.ts +15 -32
  266. package/apps/agents-server/src/search/createDefaultServerSearchProviders/createFederatedAgentsSearchProvider.ts +1 -1
  267. package/apps/agents-server/src/sentry.edge.config.ts +18 -0
  268. package/apps/agents-server/src/sentry.server.config.ts +19 -0
  269. package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +2 -9
  270. package/apps/agents-server/src/tools/$provideCdnForServer.ts +187 -15
  271. package/apps/agents-server/src/tools/BrowserConnectionProvider.ts +2 -19
  272. package/apps/agents-server/src/tools/agent_progress.ts +4 -10
  273. package/apps/agents-server/src/tools/createAgentProgressTools.ts +8 -4
  274. package/apps/agents-server/src/tools/createChatAttachmentToolFunctions.ts +8 -4
  275. package/apps/agents-server/src/tools/createServerChromiumLaunchOptions.ts +44 -0
  276. package/apps/agents-server/src/utils/agentOwnership.ts +54 -5
  277. package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +101 -19
  278. package/apps/agents-server/src/utils/agentVisibility.ts +25 -62
  279. package/apps/agents-server/src/utils/agentsTransfer/createAgentsExportZipStream.ts +81 -0
  280. package/apps/agents-server/src/utils/agentsTransfer/importAgentsFromFiles.ts +852 -0
  281. package/apps/agents-server/src/utils/assertSafeUrl.ts +136 -0
  282. package/apps/agents-server/src/utils/authenticateUser.ts +112 -4
  283. package/apps/agents-server/src/utils/authenticationAttemptRateLimit.ts +504 -0
  284. package/apps/agents-server/src/utils/backup/createBooksBackupZipStream.ts +91 -7
  285. package/apps/agents-server/src/utils/cdn/classes/DigitalOceanSpaces.ts +48 -4
  286. package/apps/agents-server/src/utils/cdn/classes/TrackedFilesStorage.ts +6 -5
  287. package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +5 -0
  288. package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +10 -3
  289. package/apps/agents-server/src/utils/chat/resolveAgentsServerCitationLabel.ts +130 -0
  290. package/apps/agents-server/src/utils/chat/resolveCitationSourceLabel.ts +436 -0
  291. package/apps/agents-server/src/utils/chatExport/renderHtmlToPdfOnServer.ts +66 -17
  292. package/apps/agents-server/src/utils/chatExport/sanitizeChatPdfExportHtml.ts +193 -0
  293. package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
  294. package/apps/agents-server/src/utils/createAdminTerminalRouteHandlers.ts +264 -0
  295. package/apps/agents-server/src/utils/createAgentWithDefaultVisibility.ts +3 -1
  296. package/apps/agents-server/src/utils/currentUserIdentity.ts +22 -9
  297. package/apps/agents-server/src/utils/defaultAgents/loadDefaultAgentBooks.ts +145 -0
  298. package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
  299. package/apps/agents-server/src/utils/errorReporting/applicationErrorHandling.ts +45 -0
  300. package/apps/agents-server/src/utils/errorReporting/refreshApplicationDocument.ts +10 -0
  301. package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +381 -0
  302. package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +43 -152
  303. package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
  304. package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +187 -0
  305. package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
  306. package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +15 -8
  307. package/apps/agents-server/src/utils/findAgentForCallerWriteAccess.ts +36 -0
  308. package/apps/agents-server/src/utils/getCurrentUser.ts +2 -1
  309. package/apps/agents-server/src/utils/getFederatedServers.ts +3 -74
  310. package/apps/agents-server/src/utils/getUserById.ts +19 -5
  311. package/apps/agents-server/src/utils/getWellKnownAgentUrl.ts +10 -4
  312. package/apps/agents-server/src/utils/iframe/checkIfUrlCanBeEmbedded.ts +68 -0
  313. package/apps/agents-server/src/utils/interactiveTerminalSession.ts +9 -4
  314. package/apps/agents-server/src/utils/isAdminPasswordEqual.ts +28 -0
  315. package/apps/agents-server/src/utils/isUserGlobalAdmin.ts +3 -1
  316. package/apps/agents-server/src/utils/knowledge/createInlineKnowledgeSourceUploader.ts +24 -5
  317. package/apps/agents-server/src/utils/knowledge/resolveWebsiteKnowledgeSourcesForServer.ts +10 -1
  318. package/apps/agents-server/src/utils/localChatRunner/LocalUserChatJobMetadata.ts +15 -5
  319. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +24 -18
  320. package/apps/agents-server/src/utils/localization/formatServerLanguageHumanReadableDate.ts +70 -0
  321. package/apps/agents-server/src/utils/localization/getRequestServerLanguage.ts +32 -0
  322. package/apps/agents-server/src/utils/metadataConfigurationTransfer.ts +442 -0
  323. package/apps/agents-server/src/utils/paidApiRequestGuard.ts +241 -0
  324. package/apps/agents-server/src/utils/publicUser.ts +59 -0
  325. package/apps/agents-server/src/utils/serverLimits.ts +28 -1
  326. package/apps/agents-server/src/utils/serverManagement/createManagedServer/bootstrapManagedServer.ts +5 -6
  327. package/apps/agents-server/src/utils/serverManagement/createManagedServer/normalizeCreateServerInput.ts +6 -0
  328. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +162 -0
  329. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +7 -87
  330. package/apps/agents-server/src/utils/serverManagement/createManagedServer.ts +5 -0
  331. package/apps/agents-server/src/utils/session.ts +72 -30
  332. package/apps/agents-server/src/utils/shareTargetPayloads.ts +37 -66
  333. package/apps/agents-server/src/utils/shibbolethAuthentication.ts +957 -0
  334. package/apps/agents-server/src/utils/transpilers/resolveTranspiledTeamExport.ts +10 -10
  335. package/apps/agents-server/src/utils/upload/createBookEditorUploadHandler.ts +19 -28
  336. package/apps/agents-server/src/utils/upload/fileUploadAvailability.ts +91 -0
  337. package/apps/agents-server/src/utils/upload/uploadFileToServer.ts +157 -0
  338. package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +26 -12
  339. package/apps/agents-server/src/utils/userChat/createRunUserChatJobExecutionContext.ts +45 -0
  340. package/apps/agents-server/src/utils/userChat/createRunUserChatJobPersistenceController.ts +17 -11
  341. package/apps/agents-server/src/utils/userChat/createUserChatDetailPayload.ts +33 -18
  342. package/apps/agents-server/src/utils/userChat/createUserChatHarnessProgressCard.ts +93 -0
  343. package/apps/agents-server/src/utils/userChat/createUserChatRunnerProgressCard.ts +57 -0
  344. package/apps/agents-server/src/utils/userChat/hasPotentiallyPendingAssistantMessages.ts +26 -0
  345. package/apps/agents-server/src/utils/userChat/listUserChats.ts +117 -6
  346. package/apps/agents-server/src/utils/userChat/persistUserChatJobProgressCard.ts +40 -0
  347. package/apps/agents-server/src/utils/userChat/resolveUserChatProgressToolHighlights.ts +100 -0
  348. package/apps/agents-server/src/utils/userChat/resolveUserChatWorkerInternalToken.ts +63 -9
  349. package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +1 -1
  350. package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +30 -0
  351. package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
  352. package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +69 -1
  353. package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +360 -0
  354. package/apps/agents-server/src/utils/validateApiKey.ts +7 -3
  355. package/apps/agents-server/src/utils/vpsConfiguration.ts +8 -1
  356. package/apps/agents-server/src/utils/vpsSelfUpdate.ts +935 -64
  357. package/esm/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
  358. package/esm/apps/agents-server/src/constants/serverLimits.d.ts +224 -0
  359. package/esm/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
  360. package/esm/index.es.js +24308 -18655
  361. package/esm/index.es.js.map +1 -1
  362. package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
  363. package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
  364. package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
  365. package/esm/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
  366. package/esm/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
  367. package/esm/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
  368. package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
  369. package/esm/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
  370. package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
  371. package/esm/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
  372. package/esm/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
  373. package/esm/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
  374. package/esm/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
  375. package/esm/scripts/run-codex-prompts/common/parseDuration.d.ts +19 -0
  376. package/esm/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
  377. package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
  378. package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
  379. package/esm/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
  380. package/esm/scripts/run-codex-prompts/common/sleepWithCountdown.d.ts +27 -0
  381. package/esm/scripts/run-codex-prompts/common/waitForPause.d.ts +12 -0
  382. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -1
  383. package/esm/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
  384. package/esm/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
  385. package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +5 -3
  386. package/esm/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
  387. package/esm/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +50 -0
  388. package/esm/scripts/run-codex-prompts/server/buildCoderServerRunState.d.ts +23 -0
  389. package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
  390. package/esm/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +35 -0
  391. package/esm/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
  392. package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -0
  393. package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +1 -0
  394. package/esm/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +5 -1
  395. package/esm/scripts/run-codex-prompts/ui/renderCoderRunUi.d.ts +1 -0
  396. package/esm/src/_packages/components.index.d.ts +4 -0
  397. package/esm/src/_packages/core.index.d.ts +22 -2
  398. package/esm/src/_packages/node.index.d.ts +40 -0
  399. package/esm/src/_packages/types.index.d.ts +20 -0
  400. package/esm/src/avatars/avatarAnimationScheduler.d.ts +4 -0
  401. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  402. package/esm/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
  403. package/esm/src/avatars/visuals/octopus3d4AvatarVisual.d.ts +7 -0
  404. package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
  405. package/esm/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
  406. package/esm/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
  407. package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
  408. package/esm/src/book-3.0/CliAgent.d.ts +66 -0
  409. package/esm/src/book-3.0/CliAgent.test.d.ts +1 -0
  410. package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
  411. package/esm/src/book-3.0/LiteAgent.test.d.ts +1 -0
  412. package/esm/src/book-3.0/agentFolderPaths.d.ts +30 -0
  413. package/esm/src/book-3.0/cliAgentEnv.d.ts +33 -0
  414. package/esm/src/book-components/BookEditor/BookEditor.d.ts +6 -5
  415. package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
  416. package/esm/src/book-components/BookEditor/BookEditorBrowserConfig.d.ts +2 -0
  417. package/esm/src/book-components/BookEditor/BookEditorForClient.d.ts +7 -0
  418. package/esm/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +2 -0
  419. package/esm/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
  420. package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +9 -0
  421. package/esm/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
  422. package/esm/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
  423. package/esm/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
  424. package/esm/src/book-components/Chat/Chat/ChatCitationModal.d.ts +2 -0
  425. package/esm/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
  426. package/esm/src/book-components/Chat/Chat/ChatMessageList.d.ts +4 -0
  427. package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  428. package/esm/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +2 -0
  429. package/esm/src/book-components/Chat/Chat/ChatToolCallModalContent.d.ts +3 -1
  430. package/esm/src/book-components/Chat/Chat/CitationIframePreview.d.ts +20 -0
  431. package/esm/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +2 -0
  432. package/esm/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  433. package/esm/src/book-components/Chat/SourceChip/SourceChip.d.ts +6 -1
  434. package/esm/src/book-components/Chat/hooks/useResolvedCitationLabel.d.ts +12 -0
  435. package/esm/src/book-components/Chat/types/ChatMessage.d.ts +4 -0
  436. package/esm/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  437. package/esm/src/book-components/Chat/types/CitationLabelResolver.d.ts +8 -0
  438. package/esm/src/book-components/Chat/utils/citationHelpers.d.ts +9 -0
  439. package/esm/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.d.ts +14 -0
  440. package/esm/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.test.d.ts +1 -0
  441. package/esm/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +10 -0
  442. package/esm/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +4 -0
  443. package/esm/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
  444. package/esm/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +1 -1
  445. package/esm/src/book-components/_common/Modal/Modal.d.ts +1 -1
  446. package/esm/src/book-components/icons/AboutIcon.d.ts +1 -1
  447. package/esm/src/book-components/icons/DownloadIcon.d.ts +1 -1
  448. package/esm/src/book-components/icons/ExitFullscreenIcon.d.ts +1 -1
  449. package/esm/src/book-components/icons/FullscreenIcon.d.ts +1 -1
  450. package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
  451. package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
  452. package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
  453. package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
  454. package/esm/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +2 -24
  455. package/esm/src/cli/cli-commands/agent.d.ts +14 -0
  456. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +23 -1
  457. package/esm/src/cli/cli-commands/agents-server/run.d.ts +6 -0
  458. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +9 -2
  459. package/esm/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
  460. package/esm/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
  461. package/esm/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
  462. package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
  463. package/esm/src/cli/cli-commands/coder/server.d.ts +13 -0
  464. package/esm/src/cli/cli-commands/coder/waitOptions.d.ts +14 -0
  465. package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -25
  466. package/esm/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
  467. package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
  468. package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
  469. package/esm/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
  470. package/esm/src/commitments/_common/teamInternalAgentAccess.d.ts +9 -1
  471. package/esm/src/commitments/index.d.ts +2 -1
  472. package/esm/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  473. package/esm/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  474. package/esm/src/scrapers/website/utils/createShowdownConverter.d.ts +2 -2
  475. package/esm/src/utils/isTimingSafeEqualString.d.ts +25 -0
  476. package/esm/src/utils/validators/url/isValidAgentUrl.d.ts +5 -0
  477. package/esm/src/version.d.ts +1 -1
  478. package/package.json +6 -1
  479. package/servers.ts +1 -16
  480. package/src/_packages/components.index.ts +4 -0
  481. package/src/_packages/core.index.ts +22 -2
  482. package/src/_packages/node.index.ts +40 -0
  483. package/src/_packages/types.index.ts +20 -0
  484. package/src/avatars/avatarAnimationScheduler.ts +76 -4
  485. package/src/avatars/types/AvatarVisualDefinition.ts +2 -0
  486. package/src/avatars/visuals/avatarVisualRegistry.ts +4 -0
  487. package/src/avatars/visuals/fractalAvatarVisual.ts +5 -4
  488. package/src/avatars/visuals/minecraft2AvatarVisual.ts +16 -11
  489. package/src/avatars/visuals/minecraftAvatarVisual.ts +21 -7
  490. package/src/avatars/visuals/octopus3d2AvatarVisual.ts +175 -38
  491. package/src/avatars/visuals/octopus3d3AvatarVisual.ts +1068 -0
  492. package/src/avatars/visuals/octopus3d4AvatarVisual.ts +1295 -0
  493. package/src/avatars/visuals/octopus3dAvatarVisual.ts +69 -17
  494. package/src/book-2.0/agent-source/AgentBasicInformation.ts +2 -0
  495. package/src/book-2.0/agent-source/agentSourceVisibility.ts +214 -0
  496. package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/augmentAgentModelRequirementsFromSource.ts +18 -2
  497. package/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.ts +17 -0
  498. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +1 -0
  499. package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +7 -1
  500. package/src/book-3.0/Book.ts +3 -1
  501. package/src/book-3.0/BookNodeAgentSource.ts +135 -0
  502. package/src/book-3.0/CliAgent.ts +252 -0
  503. package/src/book-3.0/LiteAgent.ts +468 -0
  504. package/src/book-3.0/agentFolderPaths.ts +38 -0
  505. package/src/book-3.0/cliAgentEnv.ts +46 -0
  506. package/src/book-components/BookEditor/BookEditor.module.css +61 -0
  507. package/src/book-components/BookEditor/BookEditor.tsx +16 -13
  508. package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +72 -0
  509. package/src/book-components/BookEditor/BookEditorActionbar.tsx +35 -5
  510. package/src/book-components/BookEditor/BookEditorBrowserConfig.ts +11 -0
  511. package/src/book-components/BookEditor/BookEditorForClient.tsx +33 -0
  512. package/src/book-components/BookEditor/BookEditorMonaco.tsx +4 -2
  513. package/src/book-components/BookEditor/BookEditorMonacoTokenization.ts +89 -27
  514. package/src/book-components/BookEditor/BookEditorTheme.ts +32 -0
  515. package/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.ts +11 -0
  516. package/src/book-components/BookEditor/useBookEditorMonacoLanguage.ts +62 -92
  517. package/src/book-components/BookEditor/useBookEditorMonacoLifecycle.ts +1 -5
  518. package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +3 -2
  519. package/src/book-components/BookEditor/useBookEditorMonacoUploads.ts +1 -1
  520. package/src/book-components/Chat/Chat/Chat.module.css +50 -0
  521. package/src/book-components/Chat/Chat/Chat.tsx +4 -0
  522. package/src/book-components/Chat/Chat/ChatCitationModal.tsx +19 -5
  523. package/src/book-components/Chat/Chat/ChatMessageItem.tsx +22 -2
  524. package/src/book-components/Chat/Chat/ChatMessageList.tsx +6 -0
  525. package/src/book-components/Chat/Chat/ChatProps.tsx +6 -0
  526. package/src/book-components/Chat/Chat/ChatToolCallModal.tsx +4 -0
  527. package/src/book-components/Chat/Chat/ChatToolCallModalContent.tsx +4 -0
  528. package/src/book-components/Chat/Chat/CitationIframePreview.tsx +78 -0
  529. package/src/book-components/Chat/Chat/TeamToolCallModalContent.tsx +16 -3
  530. package/src/book-components/Chat/Chat/createChatMessageToolCallRenderModel.ts +2 -9
  531. package/src/book-components/Chat/Chat/useChatPostprocessedMessages.ts +13 -2
  532. package/src/book-components/Chat/MarkdownContent/MarkdownContent.tsx +63 -4
  533. package/src/book-components/Chat/SourceChip/SourceChip.module.css +8 -0
  534. package/src/book-components/Chat/SourceChip/SourceChip.tsx +19 -5
  535. package/src/book-components/Chat/hooks/useResolvedCitationLabel.ts +65 -0
  536. package/src/book-components/Chat/save/html/htmlSaveFormatDefinition.ts +315 -88
  537. package/src/book-components/Chat/save/react/reactSaveFormatDefinition.ts +7 -1
  538. package/src/book-components/Chat/types/ChatMessage.ts +5 -0
  539. package/src/book-components/Chat/types/ChatParticipant.ts +1 -1
  540. package/src/book-components/Chat/types/CitationLabelResolver.ts +9 -0
  541. package/src/book-components/Chat/utils/citationHelpers.ts +90 -2
  542. package/src/book-components/Chat/utils/createCitationFootnoteRenderModel.ts +3 -0
  543. package/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.ts +178 -0
  544. package/src/book-components/Chat/utils/isVisibleChatToolCall.ts +23 -0
  545. package/src/book-components/Chat/utils/parseCitationsFromContent.ts +6 -0
  546. package/src/book-components/Chat/utils/renderMarkdown.ts +3 -2
  547. package/src/book-components/_common/Dropdown/Dropdown.tsx +1 -1
  548. package/src/book-components/_common/MenuHoisting/MenuHoistingContext.tsx +1 -1
  549. package/src/book-components/_common/Modal/Modal.tsx +1 -1
  550. package/src/book-components/icons/AboutIcon.tsx +1 -1
  551. package/src/book-components/icons/DownloadIcon.tsx +1 -1
  552. package/src/book-components/icons/ExitFullscreenIcon.tsx +1 -1
  553. package/src/book-components/icons/FullscreenIcon.tsx +1 -1
  554. package/src/cli/cli-commands/agent/agentCliOptions.ts +92 -0
  555. package/src/cli/cli-commands/agent/chat.ts +54 -0
  556. package/src/cli/cli-commands/agent/exec.ts +60 -0
  557. package/src/cli/cli-commands/agent-folder/agentProjectPaths.ts +15 -28
  558. package/src/cli/cli-commands/agent.ts +44 -0
  559. package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +325 -33
  560. package/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.ts +15 -2
  561. package/src/cli/cli-commands/agents-server/run.ts +103 -31
  562. package/src/cli/cli-commands/agents-server/startAgentsServer.ts +270 -41
  563. package/src/cli/cli-commands/agents-server.ts +7 -1
  564. package/src/cli/cli-commands/coder/ThinkingLevel.ts +3 -1
  565. package/src/cli/cli-commands/coder/agentCodingFile.ts +1 -1
  566. package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +79 -0
  567. package/src/cli/cli-commands/coder/find-unwritten.ts +58 -0
  568. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +2 -2
  569. package/src/cli/cli-commands/coder/init.ts +6 -1
  570. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +10 -0
  571. package/src/cli/cli-commands/coder/printInitializationSummary.ts +3 -0
  572. package/src/cli/cli-commands/coder/run.ts +108 -13
  573. package/src/cli/cli-commands/coder/server.ts +259 -0
  574. package/src/cli/cli-commands/coder/waitOptions.ts +24 -0
  575. package/src/cli/cli-commands/coder.ts +6 -0
  576. package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +33 -49
  577. package/src/cli/common/$deprecateCliCommand.ts +10 -1
  578. package/src/cli/promptbookCli.ts +2 -0
  579. package/src/collection/agent-collection/CreateAgentInput.ts +10 -5
  580. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +98 -17
  581. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords.ts +7 -4
  582. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.ts +44 -8
  583. package/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.ts +2 -2
  584. package/src/commitments/GOAL/GOAL.ts +7 -2
  585. package/src/commitments/LANGUAGE/LANGUAGE.ts +7 -2
  586. package/src/commitments/META_VISIBILITY/META_VISIBILITY.ts +78 -0
  587. package/src/commitments/TEAM/TEAM.ts +12 -1
  588. package/src/commitments/USE_PROJECT/createUseProjectToolFunctions.ts +8 -1
  589. package/src/commitments/_common/teamInternalAgentAccess.ts +14 -8
  590. package/src/commitments/index.ts +2 -0
  591. package/src/execution/createPipelineExecutor/getKnowledgeForTask.ts +1 -1
  592. package/src/formats/csv/CsvFormatParser.ts +4 -4
  593. package/src/formats/csv/utils/csvParse.ts +2 -2
  594. package/src/import-plugins/JsonFileImportPlugin.ts +15 -2
  595. package/src/import-plugins/TextFileImportPlugin.ts +8 -1
  596. package/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.ts +1 -1
  597. package/src/llm-providers/_common/register/$provideLlmToolsFromEnv.ts +1 -1
  598. package/src/llm-providers/_common/register/$registeredLlmToolsMessage.ts +6 -1
  599. package/src/llm-providers/agent/AgentLlmExecutionTools.ts +2 -2
  600. package/src/llm-providers/agent/AgentLlmExecutionToolsAgentKitRunner.ts +2 -2
  601. package/src/llm-providers/agent/AgentLlmExecutionToolsOpenAiAssistantRunner.ts +2 -2
  602. package/src/llm-providers/anthropic-claude/register-configuration.ts +6 -3
  603. package/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.ts +3 -1
  604. package/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.ts +1 -1
  605. package/src/llm-providers/openai/OpenAiVectorStoreKnowledgeSourcePreparer.ts +1 -1
  606. package/src/other/templates/getTemplatesPipelineCollection.ts +817 -702
  607. package/src/scrapers/_common/utils/getScraperIntermediateSource.ts +2 -2
  608. package/src/scrapers/website/WebsiteScraper.ts +1 -1
  609. package/src/scrapers/website/utils/createShowdownConverter.ts +2 -2
  610. package/src/scripting/javascript/JavascriptEvalExecutionTools.ts +1 -1
  611. package/src/utils/agents/resolveAgentAvatarImageUrl.ts +1 -1
  612. package/src/utils/chat/chatAttachments/resolveChatAttachmentContent.ts +8 -1
  613. package/src/utils/isTimingSafeEqualString.ts +43 -0
  614. package/src/utils/misc/computeHash.ts +2 -2
  615. package/src/utils/random/$randomToken.ts +2 -2
  616. package/src/utils/validators/url/isValidAgentUrl.ts +5 -7
  617. package/src/version.ts +2 -2
  618. package/src/versions.txt +33 -0
  619. package/umd/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
  620. package/umd/apps/agents-server/src/constants/serverLimits.d.ts +224 -0
  621. package/umd/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
  622. package/umd/index.umd.js +24336 -18681
  623. package/umd/index.umd.js.map +1 -1
  624. package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
  625. package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
  626. package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
  627. package/umd/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
  628. package/umd/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
  629. package/umd/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
  630. package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
  631. package/umd/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
  632. package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
  633. package/umd/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
  634. package/umd/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
  635. package/umd/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
  636. package/umd/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
  637. package/umd/scripts/run-codex-prompts/common/parseDuration.d.ts +19 -0
  638. package/umd/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
  639. package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
  640. package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
  641. package/umd/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
  642. package/umd/scripts/run-codex-prompts/common/sleepWithCountdown.d.ts +27 -0
  643. package/umd/scripts/run-codex-prompts/common/waitForPause.d.ts +12 -0
  644. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -1
  645. package/umd/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
  646. package/umd/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
  647. package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +5 -3
  648. package/umd/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
  649. package/umd/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +50 -0
  650. package/umd/scripts/run-codex-prompts/server/buildCoderServerRunState.d.ts +23 -0
  651. package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
  652. package/umd/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +35 -0
  653. package/umd/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
  654. package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -0
  655. package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +1 -0
  656. package/umd/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +5 -1
  657. package/umd/scripts/run-codex-prompts/ui/renderCoderRunUi.d.ts +1 -0
  658. package/umd/src/_packages/components.index.d.ts +4 -0
  659. package/umd/src/_packages/core.index.d.ts +22 -2
  660. package/umd/src/_packages/node.index.d.ts +40 -0
  661. package/umd/src/_packages/types.index.d.ts +20 -0
  662. package/umd/src/avatars/avatarAnimationScheduler.d.ts +4 -0
  663. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  664. package/umd/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
  665. package/umd/src/avatars/visuals/octopus3d4AvatarVisual.d.ts +7 -0
  666. package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
  667. package/umd/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
  668. package/umd/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
  669. package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
  670. package/umd/src/book-3.0/CliAgent.d.ts +66 -0
  671. package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
  672. package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
  673. package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
  674. package/umd/src/book-3.0/agentFolderPaths.d.ts +30 -0
  675. package/umd/src/book-3.0/cliAgentEnv.d.ts +33 -0
  676. package/umd/src/book-components/BookEditor/BookEditor.d.ts +6 -5
  677. package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
  678. package/umd/src/book-components/BookEditor/BookEditorBrowserConfig.d.ts +2 -0
  679. package/umd/src/book-components/BookEditor/BookEditorForClient.d.ts +7 -0
  680. package/umd/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +2 -0
  681. package/umd/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
  682. package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +9 -0
  683. package/umd/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
  684. package/umd/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
  685. package/umd/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
  686. package/umd/src/book-components/Chat/Chat/ChatCitationModal.d.ts +2 -0
  687. package/umd/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
  688. package/umd/src/book-components/Chat/Chat/ChatMessageList.d.ts +4 -0
  689. package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  690. package/umd/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +2 -0
  691. package/umd/src/book-components/Chat/Chat/ChatToolCallModalContent.d.ts +3 -1
  692. package/umd/src/book-components/Chat/Chat/CitationIframePreview.d.ts +20 -0
  693. package/umd/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +2 -0
  694. package/umd/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  695. package/umd/src/book-components/Chat/SourceChip/SourceChip.d.ts +6 -1
  696. package/umd/src/book-components/Chat/hooks/useResolvedCitationLabel.d.ts +12 -0
  697. package/umd/src/book-components/Chat/types/ChatMessage.d.ts +4 -0
  698. package/umd/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  699. package/umd/src/book-components/Chat/types/CitationLabelResolver.d.ts +8 -0
  700. package/umd/src/book-components/Chat/utils/citationHelpers.d.ts +9 -0
  701. package/umd/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.d.ts +14 -0
  702. package/umd/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.test.d.ts +1 -0
  703. package/umd/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +10 -0
  704. package/umd/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +4 -0
  705. package/umd/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
  706. package/umd/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +1 -1
  707. package/umd/src/book-components/_common/Modal/Modal.d.ts +1 -1
  708. package/umd/src/book-components/icons/AboutIcon.d.ts +1 -1
  709. package/umd/src/book-components/icons/DownloadIcon.d.ts +1 -1
  710. package/umd/src/book-components/icons/ExitFullscreenIcon.d.ts +1 -1
  711. package/umd/src/book-components/icons/FullscreenIcon.d.ts +1 -1
  712. package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
  713. package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
  714. package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
  715. package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
  716. package/umd/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +2 -24
  717. package/umd/src/cli/cli-commands/agent.d.ts +14 -0
  718. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +23 -1
  719. package/umd/src/cli/cli-commands/agents-server/run.d.ts +6 -0
  720. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +9 -2
  721. package/umd/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
  722. package/umd/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
  723. package/umd/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
  724. package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
  725. package/umd/src/cli/cli-commands/coder/server.d.ts +13 -0
  726. package/umd/src/cli/cli-commands/coder/waitOptions.d.ts +14 -0
  727. package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -25
  728. package/umd/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
  729. package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
  730. package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
  731. package/umd/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
  732. package/umd/src/commitments/_common/teamInternalAgentAccess.d.ts +9 -1
  733. package/umd/src/commitments/index.d.ts +2 -1
  734. package/umd/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  735. package/umd/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  736. package/umd/src/scrapers/website/utils/createShowdownConverter.d.ts +2 -2
  737. package/umd/src/utils/isTimingSafeEqualString.d.ts +25 -0
  738. package/umd/src/utils/validators/url/isValidAgentUrl.d.ts +5 -0
  739. package/umd/src/version.d.ts +1 -1
  740. package/apps/agents-server/src/app/api/long-streaming/route.ts +0 -23
  741. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +0 -108
  742. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +0 -117
  743. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +0 -119
  744. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +0 -74
  745. package/apps/agents-server/src/utils/defaultFederatedAgents/DefaultFederatedAgentsSyncOptions.ts +0 -9
  746. package/apps/agents-server/src/utils/defaultFederatedAgents/ensureDefaultFederatedAgentExists.ts +0 -277
  747. package/apps/agents-server/src/utils/defaultFederatedAgents/fetchCoreOrganizationPayload.ts +0 -39
  748. package/apps/agents-server/src/utils/defaultFederatedAgents/fetchFederatedAgentBook.ts +0 -43
  749. package/apps/agents-server/src/utils/defaultFederatedAgents/fetchWithDefaultFederatedAgentTimeout.ts +0 -28
  750. package/apps/agents-server/src/utils/defaultFederatedAgents/getDefaultFederatedAgentSyncPool.ts +0 -38
  751. package/apps/agents-server/src/utils/defaultFederatedAgents/loadActiveLocalAgentIdsByNormalizedName.ts +0 -41
  752. package/apps/agents-server/src/utils/defaultFederatedAgents/loadDefaultFederatedAgentSyncMetadata.ts +0 -76
  753. package/apps/agents-server/src/utils/defaultFederatedAgents/quoteIdentifier.ts +0 -11
  754. package/apps/agents-server/src/utils/defaultFederatedAgents/scheduleDefaultFederatedAgentsSync.ts +0 -88
  755. package/apps/agents-server/src/utils/defaultFederatedAgents/selectDefaultFederatedAgentsFromOrganizationPayload.ts +0 -181
  756. package/apps/agents-server/src/utils/defaultFederatedAgents/synchronizeDefaultFederatedAgents.ts +0 -77
  757. package/apps/agents-server/src/utils/shibboleth/createShibbolethAuthenticationLogPayload.ts +0 -173
  758. package/apps/agents-server/src/utils/shibboleth/writeShibbolethAuthenticationLog.ts +0 -27
  759. package/apps/agents-server/tests/e2e/authentication-and-navigation.spec.ts.todo +0 -178
  760. package/src/_packages/browser.index.ts +0 -31
  761. package/src/_packages/browser.readme.md +0 -43
  762. package/src/book-2.0/agent-source/parseAgentSourceWithCommitments.test.ts.todo +0 -265
  763. package/src/book-components/BookEditor/BookEditorMonaco.test.tsx.todo +0 -115
  764. package/src/book-components/Chat/utils/renderMarkdown.test.ts.tmp +0 -199
  765. package/src/collection/agent-collection/constructors/agent-collection-in-directory/AgentCollectionInDirectory.test.ts.todo +0 -131
  766. package/src/commands/_common/parseCommand.test.ts.todo +0 -48
  767. package/src/commitments/META_LINK/META_LINK.test.ts.todo +0 -75
  768. package/src/conversion/validation/pipelineStringToJson-errors.test.ts.todo +0 -33
  769. package/src/dialogs/simple-prompt/SimplePromptInterfaceTools.ts +0 -51
  770. package/src/executables/browsers/locateSafari.test.ts.tmp +0 -15
  771. package/src/execution/PromptbookFetch.test-type.ts +0 -14
  772. package/src/execution/createPipelineExecutor/00-createPipelineExecutor.test.ts.todo +0 -0
  773. package/src/execution/execution-report/executionReportJsonToString.test.ts.todo +0 -83
  774. package/src/execution/utils/usageToHuman.test.ts.todo +0 -80
  775. package/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.ts +0 -76
  776. package/src/llm-providers/_common/utils/assertUniqueModels.ts +0 -27
  777. package/src/llm-providers/_multiple/playground/playground.ts +0 -141
  778. package/src/llm-providers/_multiple/playground/tsconfig.json +0 -19
  779. package/src/llm-providers/agent/playground/playground.ts +0 -190
  780. package/src/llm-providers/agent/playground/tsconfig.json +0 -19
  781. package/src/llm-providers/anthropic-claude/playground/playground.ts +0 -99
  782. package/src/llm-providers/anthropic-claude/playground/tsconfig.json +0 -19
  783. package/src/llm-providers/azure-openai/playground/playground.ts +0 -101
  784. package/src/llm-providers/azure-openai/playground/tsconfig.json +0 -19
  785. package/src/llm-providers/ollama/playground/playground.ts +0 -120
  786. package/src/llm-providers/ollama/playground/tsconfig.json +0 -19
  787. package/src/llm-providers/openai/playground/playground.ts +0 -406
  788. package/src/llm-providers/openai/playground/tsconfig.json +0 -19
  789. package/src/llm-providers/remote/playground/playground.ts +0 -144
  790. package/src/llm-providers/remote/playground/tsconfig.json +0 -19
  791. package/src/llm-providers/vercel/playground/playground.ts +0 -133
  792. package/src/llm-providers/vercel/playground/tsconfig.json +0 -19
  793. package/src/personas/preparePersona.test.ts.todo +0 -126
  794. package/src/playground/backup/_playground-boilerplate.ts.txt +0 -37
  795. package/src/playground/backup/playground-agent-os.txt +0 -62
  796. package/src/playground/backup/playground-brj-app.ts.txt +0 -302
  797. package/src/playground/backup/playground-browser-playwright.txt +0 -110
  798. package/src/playground/backup/playground-claude-mcp.txt +0 -43
  799. package/src/playground/backup/playground-document-conversion.txt +0 -84
  800. package/src/playground/backup/playground-glob.ts.txt +0 -42
  801. package/src/playground/backup/playground-mcp-server.txt +0 -1
  802. package/src/playground/backup/playground-openai-agent-kit.txt +0 -73
  803. package/src/playground/backup/playground-openai-function-calling.txt +0 -131
  804. package/src/playground/backup/playground-openai-streaming.ts.txt +0 -68
  805. package/src/playground/backup/playground-scrape-knowledge.txt +0 -65
  806. package/src/playground/backup/playground-scraperFetch.ts.txt +0 -44
  807. package/src/playground/backup/playground-using-openai-compatible-route-on-agents-server.ts.txt +0 -49
  808. package/src/playground/backup/playground-write-pavolhejny-bio.txt +0 -120
  809. package/src/playground/permanent/_boilerplate.ts +0 -54
  810. package/src/playground/permanent/agent-with-browser-playground.ts +0 -92
  811. package/src/playground/permanent/error-handling-playground.ts +0 -103
  812. package/src/playground/playground.ts +0 -36
  813. package/src/playground/tsconfig.json +0 -19
  814. package/src/scrapers/_boilerplate/BoilerplateScraper.test.ts.todo +0 -73
  815. package/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.ts +0 -79
  816. package/src/scrapers/_boilerplate/playground/tsconfig.json +0 -19
  817. package/src/scrapers/_common/utils/files/blobToDataurl.test.ts.todo +0 -17
  818. package/src/scrapers/_common/utils/files/dataurlToBlob.test.ts.todo +0 -52
  819. package/src/scrapers/_common/utils/files/isValidDataurl.test.ts.todo +0 -42
  820. package/src/scrapers/_common/utils/files/shorten.test.ts.todo +0 -13
  821. package/src/scrapers/document/playground/document-scraper-playground.ts +0 -80
  822. package/src/scrapers/document/playground/tsconfig.json +0 -19
  823. package/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.ts +0 -80
  824. package/src/scrapers/document-legacy/playground/tsconfig.json +0 -19
  825. package/src/scrapers/markdown/playground/markdown-scraper-playground.ts +0 -74
  826. package/src/scrapers/markdown/playground/tsconfig.json +0 -19
  827. package/src/scrapers/markitdown/MarkitdownScraper.test.ts.todo +0 -132
  828. package/src/scrapers/markitdown/playground/markitdown-scraper-playground.ts +0 -91
  829. package/src/scrapers/markitdown/playground/tsconfig.json +0 -19
  830. package/src/scrapers/pdf/PdfScraper.test.ts.todo +0 -52
  831. package/src/scrapers/pdf/playground/pdf-scraper-playground.ts +0 -75
  832. package/src/scrapers/pdf/playground/tsconfig.json +0 -19
  833. package/src/scrapers/website/playground/tsconfig.json +0 -19
  834. package/src/scrapers/website/playground/website-scraper-playground.ts +0 -82
  835. package/src/storage/_common/PromptbookStorage.test-type.ts +0 -14
  836. package/src/storage/local-storage/getIndexedDbStorage.ts +0 -36
  837. package/src/storage/local-storage/getLocalStorage.ts +0 -33
  838. package/src/storage/local-storage/getSessionStorage.ts +0 -33
  839. package/src/storage/local-storage/utils/IndexedDbStorageOptions.ts +0 -16
  840. package/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.ts +0 -58
  841. package/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.ts +0 -45
  842. package/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.test.ts.todo +0 -35
  843. package/src/transpilers/openai-sdk/playground/playground.ts +0 -85
  844. package/src/transpilers/openai-sdk/playground/tmp/chatbot-openaisdk-1.js +0 -194
  845. package/src/transpilers/openai-sdk/playground/tmp/package.json +0 -3
  846. package/src/transpilers/openai-sdk/playground/tsconfig.json +0 -18
  847. package/src/utils/editable/utils/findUsableParameters.test.ts.todo +0 -43
  848. package/src/utils/editable/utils/stringifyPipelineJson.test.ts.todo +0 -38
  849. package/src/utils/markdown/prettifyMarkdown.test.ts.tmp +0 -42
  850. package/src/utils/serialization/serializeToPromptbookJavascript.test.ts.todo +0 -116
@@ -5,37 +5,76 @@ import { dirname, resolve } from 'path';
5
5
  import { promisify } from 'util';
6
6
  import { NotAllowed } from '../../../../src/errors/NotAllowed';
7
7
  import { spaceTrim } from 'spacetrim';
8
- import { createVpsInstallerCommandEnvironment, resolveVpsEnvironmentFilePath, resolveVpsInstallerScriptPath } from './vpsConfiguration';
8
+ import {
9
+ createVpsInstallerCommandEnvironment,
10
+ resolveVpsEnvironmentFilePath,
11
+ resolveVpsInstallerScriptPath,
12
+ } from './vpsConfiguration';
9
13
 
10
14
  const execFileAsync = promisify(execFile);
11
15
 
16
+ /**
17
+ * Fallback error used when a running self-update process disappears without writing a terminal status.
18
+ */
19
+ const VPS_SELF_UPDATE_STALE_ERROR_MESSAGE =
20
+ 'The previous background update process stopped unexpectedly before writing its final status.';
21
+
22
+ /**
23
+ * Success step shown when the server proves a stale-looking job completed across a process restart.
24
+ */
25
+ const VPS_SELF_UPDATE_RESTART_SUCCESS_STEP =
26
+ 'Standalone VPS self-update finished successfully after restarting the server.';
27
+
28
+ /**
29
+ * Default upstream repository URL used when no custom origin is configured.
30
+ */
31
+ export const VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL = 'https://github.com/webgptorg/promptbook.git';
32
+
33
+ /**
34
+ * Identifier of the synthetic environment that allows targeting an arbitrary git ref.
35
+ */
36
+ export const VPS_SELF_UPDATE_CUSTOM_ENVIRONMENT_ID = 'custom' as const;
37
+
12
38
  /**
13
39
  * Supported standalone VPS update environments.
40
+ *
41
+ * Order matters: it is the order presented to the super-admin in the UI.
14
42
  */
15
43
  export const VPS_SELF_UPDATE_ENVIRONMENTS = [
16
- {
17
- id: 'production',
18
- branch: 'production',
19
- label: 'Production',
20
- description: 'Recommended stable deployment branch for standalone servers.',
21
- },
22
44
  {
23
45
  id: 'main',
24
46
  branch: 'main',
25
47
  label: 'Live',
26
48
  description: 'Tracks the latest commit from the main development branch.',
49
+ isCustom: false,
27
50
  },
28
51
  {
29
52
  id: 'preview',
30
53
  branch: 'preview',
31
54
  label: 'Preview',
32
55
  description: 'Follows the preview branch before changes reach production.',
56
+ isCustom: false,
57
+ },
58
+ {
59
+ id: 'production',
60
+ branch: 'production',
61
+ label: 'Production',
62
+ description: 'Recommended stable deployment branch for standalone servers.',
63
+ isCustom: false,
33
64
  },
34
65
  {
35
66
  id: 'lts',
36
67
  branch: 'lts',
37
68
  label: 'LTS',
38
69
  description: 'Keeps the server on the long-term-support branch.',
70
+ isCustom: false,
71
+ },
72
+ {
73
+ id: VPS_SELF_UPDATE_CUSTOM_ENVIRONMENT_ID,
74
+ branch: '',
75
+ label: 'Custom',
76
+ description: 'Pick an arbitrary commit, tag, or branch — advanced and potentially unstable.',
77
+ isCustom: true,
39
78
  },
40
79
  ] as const;
41
80
 
@@ -148,6 +187,10 @@ export type VpsSelfUpdateOverview = {
148
187
  * Current local repository commit subject.
149
188
  */
150
189
  readonly currentCommitMessage: string | null;
190
+ /**
191
+ * Author timestamp of the currently deployed commit in ISO format.
192
+ */
193
+ readonly currentCommitDate: string | null;
151
194
  /**
152
195
  * Latest remote commit on the selected branch.
153
196
  */
@@ -156,16 +199,76 @@ export type VpsSelfUpdateOverview = {
156
199
  * Short latest remote commit.
157
200
  */
158
201
  readonly latestRemoteCommitShortSha: string | null;
202
+ /**
203
+ * Author timestamp of the latest remote commit in ISO format.
204
+ */
205
+ readonly latestRemoteCommitDate: string | null;
206
+ /**
207
+ * Latest remote commit subject.
208
+ */
209
+ readonly latestRemoteCommitMessage: string | null;
210
+ /**
211
+ * Number of commits the deployed checkout is behind the latest remote commit, or `null` when unknown.
212
+ */
213
+ readonly commitsBehindCount: number | null;
214
+ /**
215
+ * Commits that the deployed checkout is behind the latest remote commit (newest first).
216
+ */
217
+ readonly pendingCommits: ReadonlyArray<VpsSelfUpdatePendingCommit>;
159
218
  /**
160
219
  * Whether the remote branch contains a newer commit than the deployed checkout.
161
220
  */
162
221
  readonly isUpdateAvailable: boolean;
222
+ /**
223
+ * Configured upstream repository URL (defaults to `webgptorg/promptbook`).
224
+ */
225
+ readonly originRepositoryUrl: string;
226
+ /**
227
+ * Whether the configured origin matches the default upstream repository.
228
+ */
229
+ readonly isOriginRepositoryDefault: boolean;
230
+ /**
231
+ * Default upstream repository URL.
232
+ */
233
+ readonly defaultOriginRepositoryUrl: string;
163
234
  /**
164
235
  * Latest persisted update-job state.
165
236
  */
166
237
  readonly job: VpsSelfUpdateJobSnapshot;
167
238
  };
168
239
 
240
+ /**
241
+ * Repository state used to resolve a persisted self-update job for the browser overview.
242
+ */
243
+ export type VpsSelfUpdateJobOverviewContext = {
244
+ /**
245
+ * Environment currently configured in the running Agents Server.
246
+ */
247
+ readonly currentEnvironment: VpsSelfUpdateEnvironmentOption;
248
+ /**
249
+ * Current local repository commit observed by the running server.
250
+ */
251
+ readonly currentCommitSha: string | null;
252
+ };
253
+
254
+ /**
255
+ * Request payload accepted by {@link startVpsSelfUpdate}.
256
+ */
257
+ export type VpsSelfUpdateStartRequest = {
258
+ /**
259
+ * Predefined environment id (e.g. `production`) or `custom` to target an arbitrary ref.
260
+ */
261
+ readonly environmentId: string;
262
+ /**
263
+ * Optional arbitrary commit hash, tag, or branch used when `environmentId === 'custom'`.
264
+ */
265
+ readonly customRef?: string | null;
266
+ /**
267
+ * Optional override of the upstream repository URL (must be a `https://` git URL).
268
+ */
269
+ readonly originRepositoryUrl?: string | null;
270
+ };
271
+
169
272
  /**
170
273
  * Starts one detached VPS self-update run for the selected environment.
171
274
  *
@@ -173,10 +276,10 @@ export type VpsSelfUpdateOverview = {
173
276
  * helper writes the initial persisted state and detaches the background process so
174
277
  * the triggering HTTP request can finish before pm2 restarts the server.
175
278
  *
176
- * @param targetEnvironmentId - Deployment environment selected by the super admin.
279
+ * @param request - Update request payload.
177
280
  * @returns Fresh overview including the running background job.
178
281
  */
179
- export async function startVpsSelfUpdate(targetEnvironmentId: string): Promise<VpsSelfUpdateOverview> {
282
+ export async function startVpsSelfUpdate(request: VpsSelfUpdateStartRequest): Promise<VpsSelfUpdateOverview> {
180
283
  if (process.platform !== 'linux') {
181
284
  throw new NotAllowed(
182
285
  spaceTrim(`
@@ -185,7 +288,26 @@ export async function startVpsSelfUpdate(targetEnvironmentId: string): Promise<V
185
288
  );
186
289
  }
187
290
 
188
- const targetEnvironment = resolveVpsSelfUpdateEnvironment(targetEnvironmentId);
291
+ const targetEnvironment = resolveVpsSelfUpdateEnvironment(request.environmentId);
292
+ const isCustomEnvironment = targetEnvironment.isCustom;
293
+ const targetRef = isCustomEnvironment ? normalizeArbitraryRef(request.customRef) : targetEnvironment.branch;
294
+
295
+ if (isCustomEnvironment && !targetRef) {
296
+ throw new NotAllowed(
297
+ spaceTrim(`
298
+ A custom self-update requires a non-empty target ref (commit hash, tag, or branch).
299
+ `),
300
+ );
301
+ }
302
+
303
+ const requestedOriginUrl = normalizeOriginRepositoryUrl(request.originRepositoryUrl);
304
+ if (requestedOriginUrl !== null) {
305
+ await persistVpsSelfUpdateOriginRepositoryUrl(requestedOriginUrl);
306
+ }
307
+
308
+ const originRepositoryUrl =
309
+ requestedOriginUrl || (await readConfiguredVpsSelfUpdateOriginRepositoryUrl());
310
+
189
311
  const currentJob = await readPersistedVpsSelfUpdateJob();
190
312
  if (currentJob.status === 'running' && !currentJob.isStale) {
191
313
  throw new NotAllowed(
@@ -207,21 +329,26 @@ export async function startVpsSelfUpdate(targetEnvironmentId: string): Promise<V
207
329
  const logHandle = await open(logFilePath, 'a');
208
330
 
209
331
  try {
210
- const child = spawn('bash', [scriptPath, 'self-update', '--branch', targetEnvironment.branch], {
332
+ const installerArgs = isCustomEnvironment
333
+ ? [scriptPath, 'self-update', '--ref', targetRef]
334
+ : [scriptPath, 'self-update', '--branch', targetRef];
335
+
336
+ const child = spawn('bash', installerArgs, {
211
337
  detached: true,
212
338
  stdio: ['ignore', logHandle.fd, logHandle.fd],
213
339
  env: {
214
340
  ...createVpsInstallerCommandEnvironment(),
215
341
  PTBK_SELF_UPDATE_STATUS_FILE: statusFilePath,
216
342
  PTBK_SELF_UPDATE_LOG_FILE: logFilePath,
217
- PTBK_TARGET_REPOSITORY_REF: targetEnvironment.branch,
343
+ PTBK_TARGET_REPOSITORY_REF: targetRef,
344
+ PROMPTBOOK_REPOSITORY_URL: originRepositoryUrl,
218
345
  },
219
346
  });
220
347
 
221
348
  await writeVpsSelfUpdateStatusFile({
222
349
  STATUS: 'running',
223
350
  PID: String(child.pid ?? ''),
224
- TARGET_REF: targetEnvironment.branch,
351
+ TARGET_REF: targetRef,
225
352
  CURRENT_STEP_B64: encodeStatusField('Queued standalone VPS self-update.'),
226
353
  ERROR_MESSAGE_B64: '',
227
354
  STARTED_AT: startedAt,
@@ -239,6 +366,58 @@ export async function startVpsSelfUpdate(targetEnvironmentId: string): Promise<V
239
366
  return readVpsSelfUpdateOverview();
240
367
  }
241
368
 
369
+ /**
370
+ * Normalizes one free-form arbitrary git ref entered by the super admin.
371
+ *
372
+ * @param value - Raw user-provided ref.
373
+ * @returns Trimmed ref or empty string when invalid.
374
+ */
375
+ function normalizeArbitraryRef(value: string | null | undefined): string {
376
+ const trimmedValue = value?.trim() || '';
377
+ if (!trimmedValue) {
378
+ return '';
379
+ }
380
+
381
+ if (!/^[A-Za-z0-9._/-]+$/u.test(trimmedValue)) {
382
+ throw new NotAllowed(
383
+ spaceTrim(`
384
+ The provided git ref \`${trimmedValue}\` contains unsupported characters.
385
+
386
+ **Only letters, digits, dots, underscores, slashes, and dashes are allowed.**
387
+ `),
388
+ );
389
+ }
390
+
391
+ return trimmedValue;
392
+ }
393
+
394
+ /**
395
+ * Validates a user-provided upstream repository URL.
396
+ *
397
+ * @param value - Raw URL string.
398
+ * @returns Normalized URL or `null` when the user did not request an override.
399
+ */
400
+ function normalizeOriginRepositoryUrl(value: string | null | undefined): string | null {
401
+ if (value === null || value === undefined) {
402
+ return null;
403
+ }
404
+
405
+ const trimmedValue = value.trim();
406
+ if (!trimmedValue) {
407
+ return null;
408
+ }
409
+
410
+ if (!/^https:\/\/[\w.-]+\/[\w./-]+(?:\.git)?$/u.test(trimmedValue)) {
411
+ throw new NotAllowed(
412
+ spaceTrim(`
413
+ The upstream repository URL \`${trimmedValue}\` is not a valid public **https** git URL.
414
+ `),
415
+ );
416
+ }
417
+
418
+ return trimmedValue;
419
+ }
420
+
242
421
  /**
243
422
  * Reads the current standalone VPS self-update overview.
244
423
  *
@@ -249,63 +428,61 @@ export async function readVpsSelfUpdateOverview(): Promise<VpsSelfUpdateOverview
249
428
  const repositoryDirectory = await resolveManagedPromptbookRepositoryDirectory();
250
429
  const scriptPath = await resolveVpsInstallerScriptPath();
251
430
  const job = await readPersistedVpsSelfUpdateJob();
431
+ const originRepositoryUrl = await readConfiguredVpsSelfUpdateOriginRepositoryUrl();
252
432
 
253
433
  if (process.platform !== 'linux') {
254
- return {
255
- isAvailable: false,
256
- unavailableReason: 'Self-update is available only on the standalone Linux VPS deployment.',
257
- environments: VPS_SELF_UPDATE_ENVIRONMENTS,
434
+ return createUnavailableOverview({
258
435
  currentEnvironment,
259
436
  repositoryDirectory,
260
- currentCommitSha: null,
261
- currentCommitShortSha: null,
262
- currentCommitMessage: null,
263
- latestRemoteCommitSha: null,
264
- latestRemoteCommitShortSha: null,
265
- isUpdateAvailable: false,
266
437
  job,
267
- };
438
+ originRepositoryUrl,
439
+ unavailableReason: 'Self-update is available only on the standalone Linux VPS deployment.',
440
+ });
268
441
  }
269
442
 
270
443
  if (!scriptPath) {
271
- return {
272
- isAvailable: false,
273
- unavailableReason: 'The shared VPS installer script could not be found on this server.',
274
- environments: VPS_SELF_UPDATE_ENVIRONMENTS,
444
+ return createUnavailableOverview({
275
445
  currentEnvironment,
276
446
  repositoryDirectory,
277
- currentCommitSha: null,
278
- currentCommitShortSha: null,
279
- currentCommitMessage: null,
280
- latestRemoteCommitSha: null,
281
- latestRemoteCommitShortSha: null,
282
- isUpdateAvailable: false,
283
447
  job,
284
- };
448
+ originRepositoryUrl,
449
+ unavailableReason: 'The shared VPS installer script could not be found on this server.',
450
+ });
285
451
  }
286
452
 
287
453
  if (!repositoryDirectory) {
288
- return {
289
- isAvailable: false,
290
- unavailableReason: 'The managed Promptbook repository directory is not configured on this server.',
291
- environments: VPS_SELF_UPDATE_ENVIRONMENTS,
454
+ return createUnavailableOverview({
292
455
  currentEnvironment,
293
456
  repositoryDirectory: null,
294
- currentCommitSha: null,
295
- currentCommitShortSha: null,
296
- currentCommitMessage: null,
297
- latestRemoteCommitSha: null,
298
- latestRemoteCommitShortSha: null,
299
- isUpdateAvailable: false,
300
457
  job,
301
- };
458
+ originRepositoryUrl,
459
+ unavailableReason: 'The managed Promptbook repository directory is not configured on this server.',
460
+ });
302
461
  }
303
462
 
304
- const [currentCommitSha, currentCommitMessage, latestRemoteCommitSha] = await Promise.all([
305
- runGitInRepository(repositoryDirectory, ['rev-parse', 'HEAD']),
306
- runGitInRepository(repositoryDirectory, ['log', '-1', '--format=%s']),
307
- readRemoteCommitSha(repositoryDirectory, currentEnvironment.branch),
463
+ await refreshVpsSelfUpdateRemoteBranch(repositoryDirectory, currentEnvironment.branch, originRepositoryUrl);
464
+
465
+ const [currentCommit, latestRemoteCommitSha] = await Promise.all([
466
+ readCommitMetadataFromRepository(repositoryDirectory, 'HEAD'),
467
+ readLatestRemoteBranchCommitSha(repositoryDirectory, currentEnvironment.branch, originRepositoryUrl),
308
468
  ]);
469
+ const latestRemoteCommit = latestRemoteCommitSha
470
+ ? await readCommitMetadataFromRepository(repositoryDirectory, latestRemoteCommitSha)
471
+ : null;
472
+ const currentCommitSha = currentCommit?.commitSha ?? null;
473
+ const latestRemoteCommitResolvedSha = latestRemoteCommit?.commitSha ?? latestRemoteCommitSha;
474
+ const commitsBehindCount =
475
+ currentCommitSha && latestRemoteCommitResolvedSha
476
+ ? await countCommitsBetween(repositoryDirectory, currentCommitSha, latestRemoteCommitResolvedSha)
477
+ : null;
478
+ const pendingCommits =
479
+ currentCommitSha && latestRemoteCommitResolvedSha
480
+ ? await listCommitsBetween(repositoryDirectory, currentCommitSha, latestRemoteCommitResolvedSha)
481
+ : [];
482
+ const resolvedJob = resolveVpsSelfUpdateJobForOverview(job, {
483
+ currentEnvironment,
484
+ currentCommitSha,
485
+ });
309
486
 
310
487
  return {
311
488
  isAvailable: Boolean(currentCommitSha),
@@ -315,17 +492,423 @@ export async function readVpsSelfUpdateOverview(): Promise<VpsSelfUpdateOverview
315
492
  repositoryDirectory,
316
493
  currentCommitSha,
317
494
  currentCommitShortSha: abbreviateCommitSha(currentCommitSha),
318
- currentCommitMessage,
319
- latestRemoteCommitSha,
320
- latestRemoteCommitShortSha: abbreviateCommitSha(latestRemoteCommitSha),
321
- isUpdateAvailable: Boolean(currentCommitSha && latestRemoteCommitSha && currentCommitSha !== latestRemoteCommitSha),
322
- job,
495
+ currentCommitMessage: currentCommit?.subject ?? null,
496
+ currentCommitDate: currentCommit?.authoredAt ?? null,
497
+ latestRemoteCommitSha: latestRemoteCommitResolvedSha,
498
+ latestRemoteCommitShortSha: abbreviateCommitSha(latestRemoteCommitResolvedSha),
499
+ latestRemoteCommitDate: latestRemoteCommit?.authoredAt ?? null,
500
+ latestRemoteCommitMessage: latestRemoteCommit?.subject ?? null,
501
+ commitsBehindCount,
502
+ pendingCommits,
503
+ isUpdateAvailable: Boolean(
504
+ currentCommitSha && latestRemoteCommitResolvedSha && currentCommitSha !== latestRemoteCommitResolvedSha,
505
+ ),
506
+ originRepositoryUrl,
507
+ isOriginRepositoryDefault: originRepositoryUrl === VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL,
508
+ defaultOriginRepositoryUrl: VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL,
509
+ job: resolvedJob,
510
+ };
511
+ }
512
+
513
+ /**
514
+ * Browser-safe summary of one commit that the deployed checkout is behind the latest remote commit.
515
+ */
516
+ export type VpsSelfUpdatePendingCommit = {
517
+ /**
518
+ * Full commit hash.
519
+ */
520
+ readonly commitSha: string;
521
+ /**
522
+ * Short commit hash (first 7 chars).
523
+ */
524
+ readonly shortCommitSha: string;
525
+ /**
526
+ * Single-line commit subject.
527
+ */
528
+ readonly subject: string;
529
+ /**
530
+ * Author timestamp in ISO format or `null` when unknown.
531
+ */
532
+ readonly authoredAt: string | null;
533
+ };
534
+
535
+ /**
536
+ * Browser-safe metadata read from one git commit object.
537
+ */
538
+ type VpsSelfUpdateCommitMetadata = {
539
+ /**
540
+ * Full commit hash.
541
+ */
542
+ readonly commitSha: string;
543
+ /**
544
+ * Single-line commit subject.
545
+ */
546
+ readonly subject: string;
547
+ /**
548
+ * Author timestamp in ISO format or `null` when unknown.
549
+ */
550
+ readonly authoredAt: string | null;
551
+ };
552
+
553
+ /**
554
+ * Hard ceiling for the pending-commits listing returned in the overview to avoid huge payloads on a long-stale server.
555
+ */
556
+ const VPS_SELF_UPDATE_MAX_PENDING_COMMITS = 100;
557
+
558
+ /**
559
+ * Number of latest branch commits fetched for the update overview.
560
+ */
561
+ const VPS_SELF_UPDATE_OVERVIEW_FETCH_DEPTH = VPS_SELF_UPDATE_MAX_PENDING_COMMITS + 1;
562
+
563
+ /**
564
+ * Browser-safe summary of one commit that the super admin can pick from the custom-target picker.
565
+ */
566
+ export type VpsSelfUpdateCandidateCommit = {
567
+ /**
568
+ * Full commit hash.
569
+ */
570
+ readonly commitSha: string;
571
+ /**
572
+ * Short commit hash (first 7 chars).
573
+ */
574
+ readonly shortCommitSha: string;
575
+ /**
576
+ * Single-line commit subject.
577
+ */
578
+ readonly subject: string;
579
+ /**
580
+ * Author name.
581
+ */
582
+ readonly authorName: string;
583
+ /**
584
+ * Author email.
585
+ */
586
+ readonly authorEmail: string;
587
+ /**
588
+ * Author timestamp in ISO format.
589
+ */
590
+ readonly authoredAt: string;
591
+ /**
592
+ * Branches that point at this commit (origin-prefixed names stripped).
593
+ */
594
+ readonly branches: ReadonlyArray<string>;
595
+ /**
596
+ * Tags that point at this commit.
597
+ */
598
+ readonly tags: ReadonlyArray<string>;
599
+ /**
600
+ * Whether at least one tag points at the commit (used to flag stable releases).
601
+ */
602
+ readonly isReleaseTag: boolean;
603
+ };
604
+
605
+ /**
606
+ * Filter applied to the candidate-commit listing.
607
+ */
608
+ export type VpsSelfUpdateCandidateCommitsFilter = {
609
+ /**
610
+ * Free-text search across subject, author name, hash, branch and tag names.
611
+ */
612
+ readonly searchText?: string | null;
613
+ /**
614
+ * Restrict to commits authored on or after this ISO date.
615
+ */
616
+ readonly authoredAfter?: string | null;
617
+ /**
618
+ * Restrict to commits authored on or before this ISO date.
619
+ */
620
+ readonly authoredBefore?: string | null;
621
+ /**
622
+ * Hard limit on returned commits (default 200).
623
+ */
624
+ readonly limit?: number | null;
625
+ };
626
+
627
+ /**
628
+ * Hard ceiling for the candidate-commit listing to avoid streaming the entire repository to the browser.
629
+ */
630
+ const VPS_SELF_UPDATE_MAX_CANDIDATE_COMMITS = 500;
631
+
632
+ /**
633
+ * Field separator used between commit fields in the `git log` machine output.
634
+ */
635
+ const GIT_LOG_FIELD_SEPARATOR = '\x1f';
636
+
637
+ /**
638
+ * Lists commits from the managed repository for the custom-target picker.
639
+ *
640
+ * Fetches the latest refs from the configured upstream first so the picker can include
641
+ * recent commits that have not been deployed yet, then resolves branches/tags per commit.
642
+ *
643
+ * @param filter - Filter applied to the result.
644
+ * @returns Browser-safe commit list.
645
+ */
646
+ export async function listVpsSelfUpdateCandidateCommits(
647
+ filter: VpsSelfUpdateCandidateCommitsFilter = {},
648
+ ): Promise<ReadonlyArray<VpsSelfUpdateCandidateCommit>> {
649
+ if (process.platform !== 'linux') {
650
+ return [];
651
+ }
652
+
653
+ const repositoryDirectory = await resolveManagedPromptbookRepositoryDirectory();
654
+ if (!repositoryDirectory) {
655
+ return [];
656
+ }
657
+
658
+ const originRepositoryUrl = await readConfiguredVpsSelfUpdateOriginRepositoryUrl();
659
+ await runGitInRepository(repositoryDirectory, [
660
+ 'fetch',
661
+ '--no-tags',
662
+ '--prune',
663
+ '--depth=200',
664
+ originRepositoryUrl,
665
+ '+refs/heads/*:refs/remotes/origin/*',
666
+ ]);
667
+ await runGitInRepository(repositoryDirectory, [
668
+ 'fetch',
669
+ '--tags',
670
+ '--force',
671
+ originRepositoryUrl,
672
+ '+refs/tags/*:refs/tags/*',
673
+ ]);
674
+
675
+ const limit = clampCandidateCommitLimit(filter.limit);
676
+ const logArgs = [
677
+ 'log',
678
+ `--max-count=${VPS_SELF_UPDATE_MAX_CANDIDATE_COMMITS}`,
679
+ '--all',
680
+ `--format=%H${GIT_LOG_FIELD_SEPARATOR}%aI${GIT_LOG_FIELD_SEPARATOR}%an${GIT_LOG_FIELD_SEPARATOR}%ae${GIT_LOG_FIELD_SEPARATOR}%s`,
681
+ ];
682
+
683
+ if (filter.authoredAfter) {
684
+ logArgs.push(`--since=${filter.authoredAfter}`);
685
+ }
686
+ if (filter.authoredBefore) {
687
+ logArgs.push(`--until=${filter.authoredBefore}`);
688
+ }
689
+
690
+ const logOutput = await runGitInRepository(repositoryDirectory, logArgs);
691
+ if (!logOutput) {
692
+ return [];
693
+ }
694
+
695
+ const branchesByCommit = await readRefsByCommit(repositoryDirectory, 'refs/remotes/origin');
696
+ const tagsByCommit = await readRefsByCommit(repositoryDirectory, 'refs/tags');
697
+ const searchText = filter.searchText?.trim().toLowerCase() || '';
698
+
699
+ const commits: Array<VpsSelfUpdateCandidateCommit> = [];
700
+ for (const line of logOutput.split('\n')) {
701
+ if (!line) {
702
+ continue;
703
+ }
704
+
705
+ const fields = line.split(GIT_LOG_FIELD_SEPARATOR);
706
+ const commitSha = fields[0] ?? '';
707
+ if (!commitSha) {
708
+ continue;
709
+ }
710
+
711
+ const authoredAt = fields[1] ?? '';
712
+ const authorName = fields[2] ?? '';
713
+ const authorEmail = fields[3] ?? '';
714
+ const subject = fields.slice(4).join(GIT_LOG_FIELD_SEPARATOR);
715
+ const branches = branchesByCommit.get(commitSha) ?? [];
716
+ const tags = tagsByCommit.get(commitSha) ?? [];
717
+
718
+ if (searchText && !matchesCandidateCommitSearchText(searchText, commitSha, subject, authorName, branches, tags)) {
719
+ continue;
720
+ }
721
+
722
+ commits.push({
723
+ commitSha,
724
+ shortCommitSha: commitSha.slice(0, 7),
725
+ subject,
726
+ authorName,
727
+ authorEmail,
728
+ authoredAt,
729
+ branches,
730
+ tags,
731
+ isReleaseTag: tags.length > 0,
732
+ });
733
+
734
+ if (commits.length >= limit) {
735
+ break;
736
+ }
737
+ }
738
+
739
+ return commits;
740
+ }
741
+
742
+ /**
743
+ * Clamps an external limit value to the safe candidate-commit range.
744
+ *
745
+ * @param value - Raw user-provided limit.
746
+ * @returns Clamped value.
747
+ */
748
+ function clampCandidateCommitLimit(value: number | null | undefined): number {
749
+ const defaultLimit = 200;
750
+ if (value === null || value === undefined || !Number.isFinite(value)) {
751
+ return defaultLimit;
752
+ }
753
+
754
+ return Math.max(1, Math.min(VPS_SELF_UPDATE_MAX_CANDIDATE_COMMITS, Math.floor(value)));
755
+ }
756
+
757
+ /**
758
+ * Returns `true` when one commit matches the free-text filter applied to the picker.
759
+ *
760
+ * @param searchText - Lower-cased search text.
761
+ * @param commitSha - Full commit hash.
762
+ * @param subject - Commit subject.
763
+ * @param authorName - Author display name.
764
+ * @param branches - Branches pointing at the commit.
765
+ * @param tags - Tags pointing at the commit.
766
+ * @returns `true` when the commit should be included.
767
+ */
768
+ function matchesCandidateCommitSearchText(
769
+ searchText: string,
770
+ commitSha: string,
771
+ subject: string,
772
+ authorName: string,
773
+ branches: ReadonlyArray<string>,
774
+ tags: ReadonlyArray<string>,
775
+ ): boolean {
776
+ if (commitSha.toLowerCase().startsWith(searchText)) {
777
+ return true;
778
+ }
779
+
780
+ if (subject.toLowerCase().includes(searchText)) {
781
+ return true;
782
+ }
783
+
784
+ if (authorName.toLowerCase().includes(searchText)) {
785
+ return true;
786
+ }
787
+
788
+ if (branches.some((branch) => branch.toLowerCase().includes(searchText))) {
789
+ return true;
790
+ }
791
+
792
+ return tags.some((tag) => tag.toLowerCase().includes(searchText));
793
+ }
794
+
795
+ /**
796
+ * Reads refs grouped by commit hash so the picker can annotate each commit with its branches/tags.
797
+ *
798
+ * @param repositoryDirectory - Repository checkout path.
799
+ * @param refPrefix - Ref namespace passed to `git for-each-ref` (e.g. `refs/tags`).
800
+ * @returns Map keyed by commit hash.
801
+ */
802
+ async function readRefsByCommit(
803
+ repositoryDirectory: string,
804
+ refPrefix: string,
805
+ ): Promise<Map<string, Array<string>>> {
806
+ const output = await runGitInRepository(repositoryDirectory, [
807
+ 'for-each-ref',
808
+ '--format=%(objectname)\x1f%(refname:short)',
809
+ refPrefix,
810
+ ]);
811
+ const refsByCommit = new Map<string, Array<string>>();
812
+
813
+ if (!output) {
814
+ return refsByCommit;
815
+ }
816
+
817
+ for (const line of output.split('\n')) {
818
+ const [commitSha, refName] = line.split('\x1f');
819
+ if (!commitSha || !refName) {
820
+ continue;
821
+ }
822
+
823
+ const cleanRefName = refName.replace(/^origin\//u, '');
824
+ const list = refsByCommit.get(commitSha) ?? [];
825
+ list.push(cleanRefName);
826
+ refsByCommit.set(commitSha, list);
827
+ }
828
+
829
+ return refsByCommit;
830
+ }
831
+
832
+ /**
833
+ * Builds the placeholder overview used when self-update is unavailable on the host.
834
+ *
835
+ * @param context - Fields shared across every unavailable-overview branch.
836
+ * @returns Browser-safe placeholder overview.
837
+ */
838
+ function createUnavailableOverview(context: {
839
+ readonly currentEnvironment: VpsSelfUpdateEnvironmentOption;
840
+ readonly repositoryDirectory: string | null;
841
+ readonly job: VpsSelfUpdateJobSnapshot;
842
+ readonly originRepositoryUrl: string;
843
+ readonly unavailableReason: string;
844
+ }): VpsSelfUpdateOverview {
845
+ return {
846
+ isAvailable: false,
847
+ unavailableReason: context.unavailableReason,
848
+ environments: VPS_SELF_UPDATE_ENVIRONMENTS,
849
+ currentEnvironment: context.currentEnvironment,
850
+ repositoryDirectory: context.repositoryDirectory,
851
+ currentCommitSha: null,
852
+ currentCommitShortSha: null,
853
+ currentCommitMessage: null,
854
+ currentCommitDate: null,
855
+ latestRemoteCommitSha: null,
856
+ latestRemoteCommitShortSha: null,
857
+ latestRemoteCommitDate: null,
858
+ latestRemoteCommitMessage: null,
859
+ commitsBehindCount: null,
860
+ pendingCommits: [],
861
+ isUpdateAvailable: false,
862
+ originRepositoryUrl: context.originRepositoryUrl,
863
+ isOriginRepositoryDefault: context.originRepositoryUrl === VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL,
864
+ defaultOriginRepositoryUrl: VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL,
865
+ job: context.job,
866
+ };
867
+ }
868
+
869
+ /**
870
+ * Converts the persisted shell status into the status that should be shown in the admin overview.
871
+ *
872
+ * A successful self-update may restart the old Agents Server process before the browser sees the final
873
+ * `STATUS=succeeded` write. In that case the stale PID alone is not enough to call the update failed:
874
+ * if the running server is already on the recorded target branch and target commit, the update succeeded.
875
+ *
876
+ * @param job - Persisted self-update job snapshot.
877
+ * @param context - Current repository state observed by the running server.
878
+ * @returns Job snapshot resolved for browser display.
879
+ */
880
+ export function resolveVpsSelfUpdateJobForOverview(
881
+ job: VpsSelfUpdateJobSnapshot,
882
+ context: VpsSelfUpdateJobOverviewContext,
883
+ ): VpsSelfUpdateJobSnapshot {
884
+ const isRestartedSuccessfulUpdate =
885
+ job.status === 'failed' &&
886
+ job.isStale &&
887
+ (!job.errorMessage || job.errorMessage === VPS_SELF_UPDATE_STALE_ERROR_MESSAGE) &&
888
+ job.targetBranch === context.currentEnvironment.branch &&
889
+ job.targetCommitSha !== null &&
890
+ context.currentCommitSha !== null &&
891
+ job.targetCommitSha === context.currentCommitSha;
892
+
893
+ if (!isRestartedSuccessfulUpdate) {
894
+ return job;
895
+ }
896
+
897
+ return {
898
+ ...job,
899
+ status: 'succeeded',
900
+ currentStep: VPS_SELF_UPDATE_RESTART_SUCCESS_STEP,
901
+ currentCommitSha: context.currentCommitSha,
902
+ errorMessage: null,
903
+ isStale: false,
323
904
  };
324
905
  }
325
906
 
326
907
  /**
327
908
  * Resolves one environment id or branch name to the canonical environment object.
328
909
  *
910
+ * Unknown values fall back to the production environment to preserve the historical default.
911
+ *
329
912
  * @param value - Raw environment id, branch name, or label.
330
913
  * @returns Canonical environment metadata.
331
914
  */
@@ -333,11 +916,41 @@ export function resolveVpsSelfUpdateEnvironment(value: string | null | undefined
333
916
  const normalizedValue = value?.trim().toLowerCase() || 'production';
334
917
  return (
335
918
  VPS_SELF_UPDATE_ENVIRONMENTS.find(
336
- (environment) => environment.id === normalizedValue || environment.branch === normalizedValue,
337
- ) ?? VPS_SELF_UPDATE_ENVIRONMENTS[0]
919
+ (environment) =>
920
+ !environment.isCustom &&
921
+ (environment.id === normalizedValue || environment.branch === normalizedValue),
922
+ ) ?? getDefaultVpsSelfUpdateEnvironment()
338
923
  );
339
924
  }
340
925
 
926
+ /**
927
+ * Returns the canonical production environment used as the default fallback.
928
+ *
929
+ * @returns Production environment option.
930
+ */
931
+ export function getDefaultVpsSelfUpdateEnvironment(): VpsSelfUpdateEnvironmentOption {
932
+ const productionEnvironment = VPS_SELF_UPDATE_ENVIRONMENTS.find((environment) => environment.id === 'production');
933
+ if (!productionEnvironment) {
934
+ throw new Error('Production environment is missing from VPS_SELF_UPDATE_ENVIRONMENTS.');
935
+ }
936
+ return productionEnvironment;
937
+ }
938
+
939
+ /**
940
+ * Returns the canonical custom environment option.
941
+ *
942
+ * @returns Custom environment metadata.
943
+ */
944
+ export function getCustomVpsSelfUpdateEnvironment(): VpsSelfUpdateEnvironmentOption {
945
+ const customEnvironment = VPS_SELF_UPDATE_ENVIRONMENTS.find(
946
+ (environment) => environment.id === VPS_SELF_UPDATE_CUSTOM_ENVIRONMENT_ID,
947
+ );
948
+ if (!customEnvironment) {
949
+ throw new Error('Custom environment is missing from VPS_SELF_UPDATE_ENVIRONMENTS.');
950
+ }
951
+ return customEnvironment;
952
+ }
953
+
341
954
  /**
342
955
  * Resolves the filesystem path of the persisted self-update log file.
343
956
  *
@@ -376,6 +989,50 @@ async function readCurrentVpsSelfUpdateEnvironment(): Promise<VpsSelfUpdateEnvir
376
989
  return resolveVpsSelfUpdateEnvironment(configuredBranch);
377
990
  }
378
991
 
992
+ /**
993
+ * Reads the configured upstream repository URL from `.env` (falling back to the default upstream).
994
+ *
995
+ * @returns Configured upstream URL.
996
+ */
997
+ async function readConfiguredVpsSelfUpdateOriginRepositoryUrl(): Promise<string> {
998
+ const configuredUrl = await readConfiguredVpsEnvironmentValue('PROMPTBOOK_REPOSITORY_URL');
999
+ return configuredUrl?.trim() || VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL;
1000
+ }
1001
+
1002
+ /**
1003
+ * Persists the configured upstream repository URL into the standalone VPS `.env` file.
1004
+ *
1005
+ * Setting the value to the default upstream URL removes any previous override so that the
1006
+ * installer falls back to the bundled default the next time it runs.
1007
+ *
1008
+ * @param originRepositoryUrl - Normalized upstream URL.
1009
+ */
1010
+ async function persistVpsSelfUpdateOriginRepositoryUrl(originRepositoryUrl: string): Promise<void> {
1011
+ const envFilePath = resolveVpsEnvironmentFilePath();
1012
+ let existingContent = '';
1013
+ try {
1014
+ existingContent = await readFile(envFilePath, 'utf-8');
1015
+ } catch (error) {
1016
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
1017
+ throw error;
1018
+ }
1019
+ }
1020
+
1021
+ const lines = existingContent.split(/\r?\n/u);
1022
+ const keyPattern = /^\s*(?:export\s+)?PROMPTBOOK_REPOSITORY_URL=/u;
1023
+ const isDefaultUpstream = originRepositoryUrl === VPS_SELF_UPDATE_DEFAULT_ORIGIN_REPOSITORY_URL;
1024
+ const filteredLines = lines.filter((line) => !keyPattern.test(line));
1025
+
1026
+ if (!isDefaultUpstream) {
1027
+ filteredLines.push(`PROMPTBOOK_REPOSITORY_URL=${originRepositoryUrl}`);
1028
+ }
1029
+
1030
+ const nextContent = `${filteredLines.join('\n').replace(/\n+$/u, '')}\n`;
1031
+ await mkdir(dirname(envFilePath), { recursive: true });
1032
+ await writeFile(envFilePath, nextContent, { encoding: 'utf-8', mode: 0o600 });
1033
+ process.env.PROMPTBOOK_REPOSITORY_URL = isDefaultUpstream ? '' : originRepositoryUrl;
1034
+ }
1035
+
379
1036
  /**
380
1037
  * Resolves the state-directory path used for persistent update logs and status files.
381
1038
  *
@@ -410,10 +1067,7 @@ async function readPersistedVpsSelfUpdateJob(): Promise<VpsSelfUpdateJobSnapshot
410
1067
  currentStep,
411
1068
  currentCommitSha: statusEntries.get('CURRENT_COMMIT') || null,
412
1069
  targetCommitSha: statusEntries.get('TARGET_COMMIT') || null,
413
- errorMessage:
414
- isStale && !errorMessage
415
- ? 'The previous background update process stopped unexpectedly before writing its final status.'
416
- : errorMessage,
1070
+ errorMessage: isStale && !errorMessage ? VPS_SELF_UPDATE_STALE_ERROR_MESSAGE : errorMessage,
417
1071
  startedAt: statusEntries.get('STARTED_AT') || null,
418
1072
  finishedAt: statusEntries.get('FINISHED_AT') || null,
419
1073
  isStale,
@@ -513,7 +1167,9 @@ async function readConfiguredVpsEnvironmentValue(key: string): Promise<string |
513
1167
  */
514
1168
  async function resolveManagedPromptbookRepositoryDirectory(): Promise<string | null> {
515
1169
  const configuredDirectory =
516
- (await readConfiguredVpsEnvironmentValue('PTBK_REPOSITORY_DIR')) || process.env.PTBK_REPOSITORY_DIR?.trim() || '';
1170
+ (await readConfiguredVpsEnvironmentValue('PTBK_REPOSITORY_DIR')) ||
1171
+ process.env.PTBK_REPOSITORY_DIR?.trim() ||
1172
+ '';
517
1173
 
518
1174
  if (configuredDirectory) {
519
1175
  return resolve(configuredDirectory);
@@ -546,18 +1202,233 @@ async function runGitInRepository(repositoryDirectory: string, args: ReadonlyArr
546
1202
  }
547
1203
  }
548
1204
 
1205
+ /**
1206
+ * Fetches the tracked remote branch into the local object database before building the browser overview.
1207
+ *
1208
+ * @param repositoryDirectory - Repository checkout path.
1209
+ * @param branch - Target branch.
1210
+ * @param originRepositoryUrl - Configured upstream repository URL.
1211
+ */
1212
+ async function refreshVpsSelfUpdateRemoteBranch(
1213
+ repositoryDirectory: string,
1214
+ branch: string,
1215
+ originRepositoryUrl: string,
1216
+ ): Promise<void> {
1217
+ if (!branch) {
1218
+ return;
1219
+ }
1220
+
1221
+ await runGitInRepository(repositoryDirectory, [
1222
+ 'fetch',
1223
+ '--no-tags',
1224
+ '--prune',
1225
+ `--depth=${VPS_SELF_UPDATE_OVERVIEW_FETCH_DEPTH}`,
1226
+ originRepositoryUrl,
1227
+ `+refs/heads/${branch}:${createVpsSelfUpdateRemoteBranchReference(branch)}`,
1228
+ ]);
1229
+ }
1230
+
1231
+ /**
1232
+ * Reads the latest tracked-branch commit from the local remote-tracking ref, falling back to `ls-remote`.
1233
+ *
1234
+ * @param repositoryDirectory - Repository checkout path.
1235
+ * @param branch - Target branch.
1236
+ * @param originRepositoryUrl - Configured upstream repository URL.
1237
+ * @returns Remote branch commit sha or `null`.
1238
+ */
1239
+ async function readLatestRemoteBranchCommitSha(
1240
+ repositoryDirectory: string,
1241
+ branch: string,
1242
+ originRepositoryUrl: string,
1243
+ ): Promise<string | null> {
1244
+ if (!branch) {
1245
+ return null;
1246
+ }
1247
+
1248
+ const remoteBranchReference = createVpsSelfUpdateRemoteBranchReference(branch);
1249
+ const localCommitSha = await runGitInRepository(repositoryDirectory, [
1250
+ 'rev-parse',
1251
+ '--verify',
1252
+ `${remoteBranchReference}^{commit}`,
1253
+ ]);
1254
+
1255
+ return localCommitSha || readRemoteCommitSha(repositoryDirectory, branch, originRepositoryUrl);
1256
+ }
1257
+
549
1258
  /**
550
1259
  * Reads the latest remote branch commit without mutating the local checkout.
551
1260
  *
552
1261
  * @param repositoryDirectory - Repository checkout path.
553
1262
  * @param branch - Target branch.
1263
+ * @param originRepositoryUrl - Configured upstream repository URL.
554
1264
  * @returns Remote commit sha or `null`.
555
1265
  */
556
- async function readRemoteCommitSha(repositoryDirectory: string, branch: string): Promise<string | null> {
557
- const output = await runGitInRepository(repositoryDirectory, ['ls-remote', 'origin', `refs/heads/${branch}`]);
1266
+ async function readRemoteCommitSha(
1267
+ repositoryDirectory: string,
1268
+ branch: string,
1269
+ originRepositoryUrl: string,
1270
+ ): Promise<string | null> {
1271
+ if (!branch) {
1272
+ return null;
1273
+ }
1274
+
1275
+ const output = await runGitInRepository(repositoryDirectory, [
1276
+ 'ls-remote',
1277
+ originRepositoryUrl,
1278
+ `refs/heads/${branch}`,
1279
+ ]);
558
1280
  return output?.split(/\s+/u)[0] || null;
559
1281
  }
560
1282
 
1283
+ /**
1284
+ * Creates the local remote-tracking reference used for the update overview fetch.
1285
+ *
1286
+ * @param branch - Target branch.
1287
+ * @returns Local remote-tracking reference.
1288
+ */
1289
+ function createVpsSelfUpdateRemoteBranchReference(branch: string): string {
1290
+ return `refs/remotes/origin/${branch}`;
1291
+ }
1292
+
1293
+ /**
1294
+ * Reads hash, subject and author timestamp for one known commit from the local repository.
1295
+ *
1296
+ * @param repositoryDirectory - Repository checkout path.
1297
+ * @param commitReference - Commit hash or git revision reference to look up.
1298
+ * @returns Commit metadata or `null` when the commit cannot be resolved locally.
1299
+ */
1300
+ async function readCommitMetadataFromRepository(
1301
+ repositoryDirectory: string,
1302
+ commitReference: string,
1303
+ ): Promise<VpsSelfUpdateCommitMetadata | null> {
1304
+ const output = await runGitInRepository(repositoryDirectory, [
1305
+ 'log',
1306
+ '-1',
1307
+ `--format=%H${GIT_LOG_FIELD_SEPARATOR}%aI${GIT_LOG_FIELD_SEPARATOR}%s`,
1308
+ commitReference,
1309
+ ]);
1310
+ if (!output) {
1311
+ return null;
1312
+ }
1313
+
1314
+ const fields = output.split(GIT_LOG_FIELD_SEPARATOR);
1315
+ const commitSha = fields[0] ?? '';
1316
+ if (!commitSha) {
1317
+ return null;
1318
+ }
1319
+
1320
+ return {
1321
+ commitSha,
1322
+ authoredAt: fields[1] || null,
1323
+ subject: fields.slice(2).join(GIT_LOG_FIELD_SEPARATOR),
1324
+ };
1325
+ }
1326
+
1327
+ /**
1328
+ * Counts how many commits separate two commits in the local repository.
1329
+ *
1330
+ * Returns `null` when either commit cannot be resolved (typical for a shallow clone that has not been deepened yet).
1331
+ *
1332
+ * @param repositoryDirectory - Repository checkout path.
1333
+ * @param fromCommitSha - Older commit hash.
1334
+ * @param toCommitSha - Newer commit hash.
1335
+ * @returns Commit count or `null`.
1336
+ */
1337
+ async function countCommitsBetween(
1338
+ repositoryDirectory: string,
1339
+ fromCommitSha: string,
1340
+ toCommitSha: string,
1341
+ ): Promise<number | null> {
1342
+ if (fromCommitSha === toCommitSha) {
1343
+ return 0;
1344
+ }
1345
+
1346
+ const output = await runGitInRepository(repositoryDirectory, [
1347
+ 'rev-list',
1348
+ '--count',
1349
+ `${fromCommitSha}..${toCommitSha}`,
1350
+ ]);
1351
+ if (output === null) {
1352
+ return null;
1353
+ }
1354
+
1355
+ const parsedCount = Number.parseInt(output, 10);
1356
+ return Number.isFinite(parsedCount) ? parsedCount : null;
1357
+ }
1358
+
1359
+ /**
1360
+ * Lists commits that separate two commits in the local repository so the admin UI can show subject/hash/date for each one.
1361
+ *
1362
+ * Returns an empty list when either commit cannot be resolved (typical for a shallow clone that has not been deepened yet)
1363
+ * or when both commits are identical.
1364
+ *
1365
+ * @param repositoryDirectory - Repository checkout path.
1366
+ * @param fromCommitSha - Older commit hash (deployed commit).
1367
+ * @param toCommitSha - Newer commit hash (latest remote commit).
1368
+ * @returns Browser-safe pending-commit list (newest first).
1369
+ */
1370
+ async function listCommitsBetween(
1371
+ repositoryDirectory: string,
1372
+ fromCommitSha: string,
1373
+ toCommitSha: string,
1374
+ ): Promise<ReadonlyArray<VpsSelfUpdatePendingCommit>> {
1375
+ if (fromCommitSha === toCommitSha) {
1376
+ return [];
1377
+ }
1378
+
1379
+ const output = await runGitInRepository(repositoryDirectory, [
1380
+ 'log',
1381
+ `--max-count=${VPS_SELF_UPDATE_MAX_PENDING_COMMITS}`,
1382
+ `--format=%H${GIT_LOG_FIELD_SEPARATOR}%aI${GIT_LOG_FIELD_SEPARATOR}%s`,
1383
+ `${fromCommitSha}..${toCommitSha}`,
1384
+ ]);
1385
+ if (!output) {
1386
+ return [];
1387
+ }
1388
+
1389
+ const pendingCommits: Array<VpsSelfUpdatePendingCommit> = [];
1390
+ for (const line of output.split('\n')) {
1391
+ if (!line) {
1392
+ continue;
1393
+ }
1394
+
1395
+ const fields = line.split(GIT_LOG_FIELD_SEPARATOR);
1396
+ const commitSha = fields[0] ?? '';
1397
+ if (!commitSha) {
1398
+ continue;
1399
+ }
1400
+
1401
+ const authoredAt = fields[1] || null;
1402
+ const subject = fields.slice(2).join(GIT_LOG_FIELD_SEPARATOR);
1403
+
1404
+ pendingCommits.push({
1405
+ commitSha,
1406
+ shortCommitSha: commitSha.slice(0, 7),
1407
+ subject,
1408
+ authoredAt,
1409
+ });
1410
+ }
1411
+
1412
+ return pendingCommits;
1413
+ }
1414
+
1415
+ /**
1416
+ * Reads the full persisted standalone VPS self-update log so the super admin can copy/download it for debugging.
1417
+ *
1418
+ * @returns Log file content or `null` when the file does not exist yet.
1419
+ */
1420
+ export async function readVpsSelfUpdateLogFileContent(): Promise<string | null> {
1421
+ const logFilePath = resolveVpsSelfUpdateLogFilePath();
1422
+ try {
1423
+ return await readFile(logFilePath, 'utf-8');
1424
+ } catch (error) {
1425
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
1426
+ return null;
1427
+ }
1428
+ throw error;
1429
+ }
1430
+ }
1431
+
561
1432
  /**
562
1433
  * Checks whether a detached update process is still alive.
563
1434
  *