@promptbook/cli 0.114.0-5 → 0.114.0-8

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 (296) hide show
  1. package/agents/default/developer.book +1 -0
  2. package/apps/agents-server/next.config.ts +22 -0
  3. package/apps/agents-server/package.json +6 -6
  4. package/apps/agents-server/scripts/build-agents-server.js +43 -7
  5. package/apps/agents-server/scripts/build-e2e.js +12 -2
  6. package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +30 -16
  7. package/apps/agents-server/scripts/kill-port.js +163 -0
  8. package/apps/agents-server/scripts/run-e2e-tests.js +21 -8
  9. package/apps/agents-server/scripts/run-npm.js +81 -5
  10. package/apps/agents-server/src/app/actions.ts +3 -0
  11. package/apps/agents-server/src/app/admin/email-server/page.tsx +17 -18
  12. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +2 -0
  13. package/apps/agents-server/src/app/admin/task-manager/[taskId]/TaskManagerTaskDetailClient.tsx +2 -0
  14. package/apps/agents-server/src/app/admin/task-manager/taskManagerTaskPresentation.tsx +23 -0
  15. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +7 -0
  16. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/[timeoutId]/route.ts +10 -153
  17. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/route.ts +9 -4
  18. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/route.ts +3 -0
  19. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +2 -0
  20. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/resolveUserChatScope.ts +8 -1
  21. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/route.ts +15 -7
  22. package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorSaving.ts +18 -28
  23. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryClient.tsx +19 -1
  24. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +17 -5
  25. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatNotice.tsx +23 -0
  26. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +153 -0
  27. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatPanel.tsx +6 -0
  28. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +13 -0
  29. package/apps/agents-server/src/app/agents/[agentName]/chat/ExternalUserChatAdminActions.tsx +51 -3
  30. package/apps/agents-server/src/app/agents/[agentName]/chat/TeamMemberFrozenChatPrimaryAgentLink.tsx +31 -0
  31. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatSidebarState.ts +26 -2
  32. package/apps/agents-server/src/app/agents/[agentName]/goal/page.tsx +35 -0
  33. package/apps/agents-server/src/app/agents/[agentName]/projects/[projectName]/page.tsx +2 -2
  34. package/apps/agents-server/src/app/api/admin/dns-records/cloudflare/route.ts +26 -16
  35. package/apps/agents-server/src/app/api/emails/incoming/stalwart/route.ts +9 -2
  36. package/apps/agents-server/src/app/superadmin/servers/ServersRegistryTable.tsx +31 -39
  37. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +10 -3
  38. package/apps/agents-server/src/components/AgentProjects/AgentProjectIcon.tsx +137 -0
  39. package/apps/agents-server/src/components/AgentProjects/AgentProjectItem.tsx +26 -10
  40. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsApiTokenImportStep.tsx +5 -6
  41. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsCheckStep.tsx +6 -5
  42. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsManualStep.tsx +10 -14
  43. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsWizard.tsx +11 -20
  44. package/apps/agents-server/src/components/CloudflareDnsWizard/useCloudflareDnsRecordImport.ts +5 -6
  45. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsInstructions.tsx +91 -57
  46. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionPanel.tsx +63 -0
  47. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionVariantTabs.tsx +67 -0
  48. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsTable.tsx +40 -0
  49. package/apps/agents-server/src/components/Header/buildActiveAgentViewItems.ts +5 -4
  50. package/apps/agents-server/src/components/Header/createAgentViewLabel.tsx +4 -4
  51. package/apps/agents-server/src/components/Header/resolveActiveAgentNavigation.ts +2 -2
  52. package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +22 -10
  53. package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +1 -1
  54. package/apps/agents-server/src/database/migratePrefix.ts +13 -12
  55. package/apps/agents-server/src/database/migrations/2026-08-0100-agent-goal-chat-source.sql +10 -0
  56. package/apps/agents-server/src/generated/reservedPaths.ts +42 -42
  57. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +9 -1
  58. package/apps/agents-server/src/languages/translations/czech.yaml +9 -1
  59. package/apps/agents-server/src/languages/translations/english.yaml +9 -1
  60. package/apps/agents-server/src/message-providers/email/stalwart/parseInboundStalwartEmail.ts +17 -2
  61. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.ts +9 -0
  62. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatIdentity.ts +28 -0
  63. package/apps/agents-server/src/utils/agentGoalChat/appendAgentGoalChatNote.ts +43 -0
  64. package/apps/agents-server/src/utils/agentGoalChat/canAccessAgentGoalChat.ts +14 -0
  65. package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +69 -0
  66. package/apps/agents-server/src/utils/agentGoalChat/ensureAgentGoalChat.ts +66 -0
  67. package/apps/agents-server/src/utils/agentGoalChat/prependAgentGoalChatSummarySeed.ts +40 -0
  68. package/apps/agents-server/src/utils/agentGoalChat/recordAgentGoalChatLifecycleNote.ts +36 -0
  69. package/apps/agents-server/src/utils/agentGoalChat/resolveAgentGoalChatOwnerUserId.ts +104 -0
  70. package/apps/agents-server/src/utils/agentGoalChat/scheduleAgentGoalChatModifiedNote.ts +82 -0
  71. package/apps/agents-server/src/utils/agentGoalChat.ts +19 -0
  72. package/apps/agents-server/src/utils/agentProjects/AgentProjectInfo.ts +10 -1
  73. package/apps/agents-server/src/utils/agentProjects/AgentProjectReferenceInfo.ts +5 -2
  74. package/apps/agents-server/src/utils/agentProjects/agentProjectFileNames.ts +21 -0
  75. package/apps/agents-server/src/utils/agentProjects/agentProjectHrefs.ts +20 -11
  76. package/apps/agents-server/src/utils/agentProjects/agentProjectsPaths.ts +15 -5
  77. package/apps/agents-server/src/utils/agentProjects/createAgentProjectInitials.ts +36 -0
  78. package/apps/agents-server/src/utils/agentProjects/createAgentProjectMarkdownReferences.ts +11 -9
  79. package/apps/agents-server/src/utils/agentProjects/createAgentProjectsDnsRecordsSection.ts +113 -0
  80. package/apps/agents-server/src/utils/agentProjects/createStaticAgentProjectServer.ts +2 -6
  81. package/apps/agents-server/src/utils/agentProjects/humanizeAgentProjectName.ts +25 -0
  82. package/apps/agents-server/src/utils/agentProjects/listAgentProjectChatReferences.ts +10 -3
  83. package/apps/agents-server/src/utils/agentProjects/parseAgentProjectIndexHtml.ts +167 -0
  84. package/apps/agents-server/src/utils/agentProjects/readAgentProjectIndexHtmlProfile.ts +24 -0
  85. package/apps/agents-server/src/utils/agentProjects/readAgentProjectReadme.ts +3 -53
  86. package/apps/agents-server/src/utils/agentProjects/readAgentProjectRootTextFile.ts +73 -0
  87. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectFaviconRelativePath.ts +108 -0
  88. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectInfo.ts +12 -3
  89. package/apps/agents-server/src/utils/agentProjects/{resolveAgentProjectReadmeProfile.ts → resolveAgentProjectProfile.ts} +33 -33
  90. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectPublicUrls.ts +34 -0
  91. package/apps/agents-server/src/utils/bookLanguageDocumentation/createBookLanguageDocumentationPdfResponse.ts +19 -17
  92. package/apps/agents-server/src/utils/chatTasksAdmin.ts +9 -0
  93. package/apps/agents-server/src/utils/dnsRecords/DnsRecordInstruction.ts +20 -0
  94. package/apps/agents-server/src/utils/dnsRecords/DnsRecordsSection.ts +77 -0
  95. package/apps/agents-server/src/utils/dnsRecords/createServerDnsRecordsSections.ts +58 -0
  96. package/apps/agents-server/src/utils/dnsRecords/createServerDomainDnsRecordsSection.ts +48 -0
  97. package/apps/agents-server/src/utils/dnsRecords/dnsRecordGroups.ts +52 -0
  98. package/apps/agents-server/src/utils/dnsRecords/resolveDnsRecordBatchPlan.ts +47 -1
  99. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskSqlQuery.ts +41 -36
  100. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskFallbackRows.ts +3 -0
  101. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskSqlRows.ts +2 -0
  102. package/apps/agents-server/src/utils/localChatRunner/parseLocalTeamConversations.ts +281 -0
  103. package/apps/agents-server/src/utils/localChatRunner/persistLocalTeamConversations.ts +71 -0
  104. package/apps/agents-server/src/utils/localChatRunner/prepareLocalTeamConversationWorkspace.ts +233 -0
  105. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +37 -6
  106. package/apps/agents-server/src/utils/serverManagement/createManagedServer/insertManagedServerRegistryRow.ts +2 -2
  107. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +7 -6
  108. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +5 -4
  109. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerMetadata.ts +3 -2
  110. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerUsers.ts +3 -2
  111. package/apps/agents-server/src/utils/serverManagement/deleteManagedServer.ts +2 -2
  112. package/apps/agents-server/src/utils/stalwart/createEmailDnsRecordsSection.ts +53 -0
  113. package/apps/agents-server/src/utils/userChat/UserChatRecord.ts +13 -0
  114. package/apps/agents-server/src/utils/userChat/UserChatSource.ts +14 -0
  115. package/apps/agents-server/src/utils/userChat/createUserChatSummary.ts +10 -2
  116. package/apps/agents-server/src/utils/userChat/finalizeUserChatJob.ts +3 -2
  117. package/apps/agents-server/src/utils/userChat/getUserChat.ts +16 -1
  118. package/apps/agents-server/src/utils/userChat/getUserChatForJobRunner.ts +31 -0
  119. package/apps/agents-server/src/utils/userChat/listUserChats.ts +113 -110
  120. package/apps/agents-server/src/utils/userChat/persistFrozenUserChat.ts +21 -6
  121. package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +2 -6
  122. package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +2 -6
  123. package/apps/agents-server/src/utils/userChat/teamMemberUserChatContext.ts +63 -0
  124. package/apps/agents-server/src/utils/userChat.ts +5 -1
  125. package/apps/agents-server/src/utils/userChatClient/cancelAgentUserTimeout.ts +2 -2
  126. package/apps/agents-server/src/utils/userChatClient/fetchAgentUserTimeouts.ts +2 -2
  127. package/apps/agents-server/src/utils/userChatClient.ts +9 -31
  128. package/apps/agents-server/src/utils/userChatTimeout/UserChatTimeoutRecord.ts +10 -2
  129. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/claimNextDueUserChatTimeout.ts +28 -25
  130. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/getAgentScopedUserChatTimeout.ts +8 -4
  131. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/listAgentUserChatTimeouts.ts +4 -1
  132. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/recoverExpiredRunningUserChatTimeouts.ts +3 -2
  133. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +53 -0
  134. package/esm/index.es.js +1534 -401
  135. package/esm/index.es.js.map +1 -1
  136. package/esm/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
  137. package/esm/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
  138. package/esm/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
  139. package/esm/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
  140. package/esm/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
  141. package/esm/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
  142. package/esm/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
  143. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
  144. package/esm/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
  145. package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
  146. package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
  147. package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
  148. package/esm/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
  149. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
  150. package/esm/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
  151. package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
  152. package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +12 -3
  153. package/esm/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
  154. package/esm/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
  155. package/esm/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.d.ts → npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
  156. package/{umd/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → esm/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
  157. package/esm/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
  158. package/esm/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
  159. package/esm/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
  160. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
  161. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
  162. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
  163. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
  164. package/esm/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
  165. package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
  166. package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
  167. package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
  168. package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
  169. package/esm/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
  170. package/esm/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
  171. package/esm/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
  172. package/esm/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
  173. package/esm/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
  174. package/esm/src/utils/misc/debounce.d.ts +4 -2
  175. package/esm/src/utils/misc/debounce.test.d.ts +1 -0
  176. package/esm/src/version.d.ts +1 -1
  177. package/package.json +1 -1
  178. package/src/avatars/renderAvatarVisualTerminalText.ts +249 -0
  179. package/src/avatars/types/AvatarVisualDefinition.ts +60 -0
  180. package/src/avatars/visuals/asciiOctopusAvatarVisual.ts +144 -22
  181. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +4 -4
  182. package/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.ts +1 -4
  183. package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +4 -17
  184. package/src/book-3.0/AgentTeamConversationWorkspace.ts +172 -0
  185. package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +56 -55
  186. package/src/book-components/Chat/Chat/Chat.module.css +1 -8
  187. package/src/book-components/Chat/Chat/ChatMessageMap.tsx +8 -4
  188. package/src/book-components/Chat/Chat/ChatProps.tsx +3 -2
  189. package/src/book-components/Chat/MarkdownContent/MarkdownContent.module.css +14 -14
  190. package/src/book-components/Chat/save/react/exports/chat-preview-2025-10-13 (1).jsx +95 -5
  191. package/src/book-components/Chat/utils/renderMarkdown.ts +535 -89
  192. package/src/cli/cli-commands/coder/add.ts +3 -3
  193. package/src/cli/cli-commands/coder/boilerplateCount.ts +1 -1
  194. package/src/cli/cli-commands/coder/generate-boilerplates.ts +27 -27
  195. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +5 -4
  196. package/src/cli/cli-commands/coder/init.ts +3 -3
  197. package/src/cli/cli-commands/coder/run.ts +10 -2
  198. package/src/cli/cli-commands/common/coderGitSyncCliOptions.ts +6 -2
  199. package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +2 -2
  200. package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +4 -4
  201. package/src/cli/cli-commands/common/harness/$resolveInstalledHarnessVersion.ts +2 -2
  202. package/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.ts → npm/$askForNpmPackageInstallationApproval.ts} +3 -3
  203. package/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.ts +49 -0
  204. package/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.ts +25 -0
  205. package/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.ts → npm/isNpmPackageVersionOutdated.ts} +6 -4
  206. package/src/cli/cli-commands/common/projectInitialization.ts +10 -1
  207. package/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.ts +73 -0
  208. package/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.ts +94 -0
  209. package/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.ts +223 -0
  210. package/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.ts +53 -0
  211. package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.ts +46 -0
  212. package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.ts +32 -0
  213. package/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.ts +22 -0
  214. package/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.ts +47 -0
  215. package/src/commands/FORMAT/formatCommandParser.ts +2 -2
  216. package/src/llm-providers/openai/utils/buildToolInvocationScript.ts +21 -18
  217. package/src/other/templates/getTemplatesPipelineCollection.ts +866 -686
  218. package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +80 -27
  219. package/src/utils/agents/terminalAgentAvatarVisual.ts +31 -3
  220. package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +9 -109
  221. package/src/utils/ascii-art/createAnsiColorCode.ts +132 -0
  222. package/src/utils/misc/debounce.ts +26 -5
  223. package/src/version.ts +2 -2
  224. package/src/versions.txt +2 -0
  225. package/umd/index.umd.js +1533 -400
  226. package/umd/index.umd.js.map +1 -1
  227. package/umd/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
  228. package/umd/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
  229. package/umd/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
  230. package/umd/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
  231. package/umd/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
  232. package/umd/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
  233. package/umd/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
  234. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
  235. package/umd/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
  236. package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
  237. package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
  238. package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
  239. package/umd/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
  240. package/umd/src/avatars/renderAvatarVisualTerminalText.test.d.ts +1 -0
  241. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
  242. package/umd/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
  243. package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
  244. package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +12 -3
  245. package/umd/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
  246. package/umd/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
  247. package/umd/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.d.ts → npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
  248. package/{esm/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
  249. package/umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.test.d.ts +1 -0
  250. package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
  251. package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.test.d.ts +1 -0
  252. package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
  253. package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.test.d.ts +1 -0
  254. package/umd/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
  255. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
  256. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
  257. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
  258. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
  259. package/umd/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
  260. package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
  261. package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
  262. package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
  263. package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
  264. package/umd/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
  265. package/umd/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
  266. package/umd/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
  267. package/umd/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
  268. package/umd/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
  269. package/umd/src/utils/misc/debounce.d.ts +4 -2
  270. package/umd/src/utils/misc/debounce.test.d.ts +1 -0
  271. package/umd/src/version.d.ts +1 -1
  272. package/apps/agents-server/scripts/ignore-kill-eperm.js +0 -31
  273. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/actions/route.ts +0 -103
  274. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +0 -43
  275. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsEditDialog.tsx +0 -98
  276. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +0 -75
  277. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsHeader.tsx +0 -53
  278. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsSummaryMetrics.tsx +0 -70
  279. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +0 -58
  280. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +0 -242
  281. package/apps/agents-server/src/app/agents/[agentName]/timeouts/loading.tsx +0 -15
  282. package/apps/agents-server/src/app/agents/[agentName]/timeouts/page.tsx +0 -28
  283. package/apps/agents-server/src/app/agents/[agentName]/timeouts/useAgentTimeoutsClientState.ts +0 -769
  284. package/apps/agents-server/src/components/AgentProjectDnsInstructions/AgentProjectDnsInstructions.tsx +0 -182
  285. package/apps/agents-server/src/utils/userChatClient/runAgentUserTimeoutBulkAction.ts +0 -24
  286. package/apps/agents-server/src/utils/userChatClient/updateAgentUserTimeout.ts +0 -25
  287. package/esm/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
  288. package/esm/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
  289. package/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.ts +0 -34
  290. package/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.ts +0 -28
  291. package/umd/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
  292. package/umd/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
  293. /package/esm/src/{cli/cli-commands/common/harness/extractHarnessVersionFromOutput.test.d.ts → avatars/renderAvatarVisualTerminalText.test.d.ts} +0 -0
  294. /package/esm/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.test.d.ts → npm/$resolveLatestNpmPackageVersion.test.d.ts} +0 -0
  295. /package/{umd/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.test.d.ts → esm/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.test.d.ts} +0 -0
  296. /package/{umd/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.test.d.ts → esm/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.test.d.ts} +0 -0
@@ -4,11 +4,12 @@ import { ForbiddenPage } from '../../../components/ForbiddenPage/ForbiddenPage';
4
4
  import { StalwartSynchronizeButton } from '../../../components/StalwartSynchronizeButton/StalwartSynchronizeButton';
5
5
  import { $provideServer } from '../../../tools/$provideServer';
6
6
  import { isUserAdmin } from '../../../utils/isUserAdmin';
7
- import { createEmailDnsInstructions } from '../../../utils/stalwart/createEmailDnsInstructions';
7
+ import { createEmailDnsRecordsSection } from '../../../utils/stalwart/createEmailDnsRecordsSection';
8
8
  import {
9
9
  isStalwartEmailSnapshotOperational,
10
10
  readStalwartEmailSnapshot,
11
11
  } from '../../../utils/stalwart/readStalwartEmailSnapshot';
12
+ import { isManagedServerDnsDiagnosticIssue } from '../../superadmin/servers/ServersRegistryDnsTypes';
12
13
  import { AdminConfigurationShell } from '../_components/AdminConfigurationShell';
13
14
  import { $synchronizeStalwartEmailDomain } from './actions';
14
15
 
@@ -27,7 +28,12 @@ export default async function AdminEmailServerPage() {
27
28
 
28
29
  const server = await $provideServer();
29
30
  const snapshot = await readStalwartEmailSnapshot(server.publicUrl.hostname);
30
- const dnsInstructions = createEmailDnsInstructions(snapshot.domain, snapshot.mailDnsDiagnostic.publicIpAddress);
31
+ const emailDnsRecordsSection = createEmailDnsRecordsSection({
32
+ domain: snapshot.domain,
33
+ publicIpAddress: snapshot.mailDnsDiagnostic.publicIpAddress,
34
+ statusSummary: snapshot.mailDnsDiagnostic.summary,
35
+ isDnsIssue: isManagedServerDnsDiagnosticIssue(snapshot.mailDnsDiagnostic),
36
+ });
31
37
  const isOperational = isStalwartEmailSnapshotOperational(snapshot);
32
38
 
33
39
  return (
@@ -111,21 +117,14 @@ export default async function AdminEmailServerPage() {
111
117
  <div className="mt-4">
112
118
  <DnsRecordsInstructions
113
119
  description={
114
- snapshot.mailDnsDiagnostic.publicIpAddress ? (
115
- <p>
116
- Add these records at your DNS provider. The A records below use this VPS’s
117
- detected public address.
118
- </p>
119
- ) : (
120
- <p>
121
- Add these records at your DNS provider. Replace <code>&lt;VPS_PUBLIC_IP&gt;</code>{' '}
122
- with the public address of this VPS.
123
- </p>
124
- )
120
+ <p>
121
+ Add these records at your DNS provider. The complete DNS setup of this server -
122
+ including its own domain and its generated project domains - is configured together
123
+ on the Super Admin <span className="font-mono">/superadmin/servers</span> page.
124
+ </p>
125
125
  }
126
126
  domain={snapshot.domain}
127
- recordSelection="all"
128
- records={dnsInstructions}
127
+ sections={[emailDnsRecordsSection]}
129
128
  />
130
129
  </div>
131
130
  <div className="mt-4 space-y-2 rounded-lg bg-blue-50 p-4 text-sm text-blue-950">
@@ -148,9 +147,9 @@ export default async function AdminEmailServerPage() {
148
147
  that hostname.
149
148
  </p>
150
149
  <p>
151
- Open TCP port <code>25</code> publicly. Keep the submission port <code>465</code>{' '}
152
- firewalled unless external mail clients need it, and never expose the Stalwart management
153
- API on port <code>8080</code>.
150
+ Open TCP port <code>25</code> publicly. Keep the submission port <code>465</code> firewalled
151
+ unless external mail clients need it, and never expose the Stalwart management API on port{' '}
152
+ <code>8080</code>.
154
153
  </p>
155
154
  </div>
156
155
  <pre className="mt-4 overflow-auto whitespace-pre-wrap rounded-lg bg-gray-950 p-4 text-xs text-gray-100">
@@ -13,6 +13,7 @@ import {
13
13
  buildTaskRunReportRows,
14
14
  formatTaskDateTime,
15
15
  formatTaskDuration,
16
+ AgentGoalTaskBadge,
16
17
  formatTaskKind,
17
18
  getTaskQueueAgeMs,
18
19
  getTaskRuntimeDurationMs,
@@ -175,6 +176,7 @@ export function TaskManagerTaskRow({
175
176
  <span className="rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 font-medium text-gray-600">
176
177
  {formatTaskKind(task.kind)}
177
178
  </span>
179
+ <AgentGoalTaskBadge task={task} />
178
180
  </div>
179
181
  <div className="mt-2 space-y-1 text-[11px] text-gray-500">
180
182
  <div>
@@ -21,6 +21,7 @@ import {
21
21
  buildTaskRunReportRows,
22
22
  formatTaskDateTime,
23
23
  formatTaskDuration,
24
+ AgentGoalTaskBadge,
24
25
  formatTaskKind,
25
26
  getTaskQueueAgeMs,
26
27
  getTaskRuntimeDurationMs,
@@ -217,6 +218,7 @@ export function TaskManagerTaskDetailClient({ taskId, isSuperAdmin, serverDomain
217
218
  <span className="rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] font-medium text-gray-600">
218
219
  {formatTaskKind(task.kind)}
219
220
  </span>
221
+ <AgentGoalTaskBadge task={task} />
220
222
  {task.cancelRequestedAt ? (
221
223
  <span className="text-[11px] font-medium text-orange-700">Cancellation requested</span>
222
224
  ) : null}
@@ -96,6 +96,29 @@ export function TaskStatusBadge({ isStuck, task }: TaskStatusBadgeProps) {
96
96
  return <span className={`rounded-full border px-2 py-0.5 text-[11px] font-semibold ${tone}`}>{label}</span>;
97
97
  }
98
98
 
99
+ /**
100
+ * Compact badge marking the tasks an agent started for itself in its goal chat.
101
+ *
102
+ * Goal-chat tasks keep their normal kind, so this badge is what separates them from the
103
+ * user-invoked tasks in every task-manager surface.
104
+ *
105
+ * @private shared presentation of the admin task manager
106
+ */
107
+ export function AgentGoalTaskBadge({ task }: { task: AdminChatTaskRecord }) {
108
+ if (!task.isAgentGoalTask) {
109
+ return null;
110
+ }
111
+
112
+ return (
113
+ <span
114
+ className="rounded-full border border-indigo-200 bg-indigo-50 px-2 py-0.5 text-[11px] font-semibold text-indigo-700"
115
+ title="Started by the agent itself in its goal chat, not by a user"
116
+ >
117
+ Goal chat
118
+ </span>
119
+ );
120
+ }
121
+
99
122
  /**
100
123
  * Formats a durable task kind for display.
101
124
  *
@@ -1,4 +1,6 @@
1
1
  import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
2
+ import { $provideServer } from '@/src/tools/$provideServer';
3
+ import { scheduleAgentGoalChatModifiedNote } from '@/src/utils/agentGoalChat';
2
4
  import { $provideAgentReferenceResolver } from '@/src/utils/agentReferenceResolver/$provideAgentReferenceResolver';
3
5
  import { invalidateCachedActiveOrganizationSnapshots } from '@/src/utils/agentOrganization/loadAgentOrganizationState';
4
6
  import {
@@ -185,6 +187,11 @@ export async function PUT(request: Request, { params }: { params: Promise<{ agen
185
187
 
186
188
  const agentId = await collection.getAgentPermanentId(agentName);
187
189
  await collection.updateAgentSource(agentId, agentSource, { versionName });
190
+ scheduleAgentGoalChatModifiedNote({
191
+ agentPermanentId: agentId,
192
+ agentName,
193
+ server: await $provideServer(),
194
+ });
188
195
  invalidateCachedActiveOrganizationSnapshots();
189
196
  // <- TODO: [🐱‍🚀] Properly type as string_book
190
197
 
@@ -1,18 +1,12 @@
1
1
  import { NextResponse } from 'next/server';
2
2
  import { isPrivateModeEnabledFromRequest } from '@/src/utils/privateMode';
3
- import {
4
- cancelScheduledUserChatTimeout,
5
- getAgentScopedUserChatTimeout,
6
- notifyUserChatTimeoutScheduleChanged,
7
- updateAgentScopedUserChatTimeout,
8
- } from '@/src/utils/userChatTimeout';
9
- import type { UpdateAgentScopedUserChatTimeoutPatch } from '@/src/utils/userChatTimeout';
3
+ import { cancelScheduledUserChatTimeout, getAgentScopedUserChatTimeout } from '@/src/utils/userChatTimeout';
10
4
  import { resolveUserChatScope } from '../../user-chats/resolveUserChatScope';
11
5
 
12
6
  /**
13
- * Updates one durable timeout owned by current user for one agent.
7
+ * Cancels one planned message of the agent from its goal chat.
14
8
  */
15
- export async function PATCH(
9
+ export async function DELETE(
16
10
  request: Request,
17
11
  { params }: { params: Promise<{ agentName: string; timeoutId: string }> },
18
12
  ) {
@@ -37,170 +31,33 @@ export async function PATCH(
37
31
  return NextResponse.json({ error: 'Agent not found.' }, { status: 404 });
38
32
  }
39
33
 
40
- try {
41
- const existingTimeout = await getAgentScopedUserChatTimeout({
42
- userId: scopeResult.scope.userId,
43
- agentPermanentId: scopeResult.scope.agentPermanentId,
44
- timeoutId,
45
- });
46
-
47
- if (!existingTimeout) {
48
- return NextResponse.json({ error: 'Timeout not found.' }, { status: 404 });
49
- }
50
-
51
- if (
52
- existingTimeout.status === 'COMPLETED' ||
53
- existingTimeout.status === 'FAILED' ||
54
- existingTimeout.status === 'CANCELLED'
55
- ) {
56
- return NextResponse.json({ error: 'Timeout is already finished.' }, { status: 409 });
57
- }
58
-
59
- if (existingTimeout.status === 'RUNNING') {
60
- return NextResponse.json({ error: 'Running timeout cannot be edited.' }, { status: 409 });
61
- }
62
-
63
- const parsedPatch = await parseTimeoutPatchPayload(request);
64
- if (!parsedPatch) {
65
- return NextResponse.json({ error: 'No valid timeout fields provided.' }, { status: 400 });
66
- }
67
-
68
- const updatedTimeout = await updateAgentScopedUserChatTimeout({
69
- userId: scopeResult.scope.userId,
70
- agentPermanentId: scopeResult.scope.agentPermanentId,
71
- timeoutId,
72
- patch: parsedPatch,
73
- });
74
-
75
- if (!updatedTimeout) {
76
- return NextResponse.json({ error: 'Timeout not found.' }, { status: 404 });
77
- }
78
-
79
- notifyUserChatTimeoutScheduleChanged(updatedTimeout);
80
-
81
- return NextResponse.json(updatedTimeout);
82
- } catch (error) {
83
- return NextResponse.json(
84
- { error: error instanceof Error ? error.message : 'Failed to update timeout.' },
85
- { status: 400 },
86
- );
87
- }
88
- }
89
-
90
- /**
91
- * Cancels one durable timeout owned by current user for one agent.
92
- */
93
- export async function DELETE(
94
- request: Request,
95
- { params }: { params: Promise<{ agentName: string; timeoutId: string }> },
96
- ) {
97
- if (isPrivateModeEnabledFromRequest(request)) {
98
- return NextResponse.json({ error: 'Private mode is enabled.' }, { status: 403 });
99
- }
100
-
101
- const { agentName: rawAgentName, timeoutId: rawTimeoutId } = await params;
102
- const agentName = decodeURIComponent(rawAgentName);
103
- const timeoutId = decodeURIComponent(rawTimeoutId);
104
- const scopeResult = await resolveUserChatScope(agentName);
105
-
106
- if (!scopeResult.ok) {
107
- if (scopeResult.error === 'UNAUTHORIZED') {
108
- return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
109
- }
110
-
111
- if (scopeResult.error === 'FORBIDDEN') {
112
- return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
113
- }
114
-
115
- return NextResponse.json({ error: 'Agent not found.' }, { status: 404 });
34
+ if (!scopeResult.scope.viewerCanAccessAgentGoalChat) {
35
+ return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
116
36
  }
117
37
 
118
38
  try {
39
+ // Note: Planned messages belong to the agent, so the goal chat may cancel them across every
40
+ // chat and every user of the agent
119
41
  const existingTimeout = await getAgentScopedUserChatTimeout({
120
- userId: scopeResult.scope.userId,
121
42
  agentPermanentId: scopeResult.scope.agentPermanentId,
122
43
  timeoutId,
123
44
  });
124
45
 
125
46
  if (!existingTimeout) {
126
- return NextResponse.json({ error: 'Timeout not found.' }, { status: 404 });
47
+ return NextResponse.json({ error: 'Planned message not found.' }, { status: 404 });
127
48
  }
128
49
 
129
50
  const cancelledTimeout = await cancelScheduledUserChatTimeout(timeoutId);
130
51
 
131
52
  if (!cancelledTimeout) {
132
- return NextResponse.json({ error: 'Timeout not found.' }, { status: 404 });
53
+ return NextResponse.json({ error: 'Planned message not found.' }, { status: 404 });
133
54
  }
134
55
 
135
56
  return NextResponse.json(cancelledTimeout);
136
57
  } catch (error) {
137
58
  return NextResponse.json(
138
- { error: error instanceof Error ? error.message : 'Failed to cancel timeout.' },
59
+ { error: error instanceof Error ? error.message : 'Failed to cancel the planned message.' },
139
60
  { status: 500 },
140
61
  );
141
62
  }
142
63
  }
143
-
144
- /**
145
- * Parses and validates timeout update payload from one request.
146
- */
147
- async function parseTimeoutPatchPayload(request: Request): Promise<UpdateAgentScopedUserChatTimeoutPatch | null> {
148
- const payload = (await request.json().catch(() => ({}))) as {
149
- dueAt?: unknown;
150
- recurrenceIntervalMs?: unknown;
151
- message?: unknown;
152
- parameters?: unknown;
153
- paused?: unknown;
154
- extendByMs?: unknown;
155
- };
156
-
157
- const patch: UpdateAgentScopedUserChatTimeoutPatch = {};
158
-
159
- if (typeof payload.dueAt === 'string' && payload.dueAt.trim().length > 0) {
160
- const normalizedDueAt = payload.dueAt.trim();
161
- const dueAtTimestamp = Date.parse(normalizedDueAt);
162
- if (!Number.isFinite(dueAtTimestamp)) {
163
- throw new Error('`dueAt` must be a valid ISO timestamp.');
164
- }
165
- patch.dueAt = new Date(dueAtTimestamp).toISOString();
166
- }
167
-
168
- if (payload.recurrenceIntervalMs === null) {
169
- patch.recurrenceIntervalMs = null;
170
- } else if (typeof payload.recurrenceIntervalMs === 'number') {
171
- if (!Number.isFinite(payload.recurrenceIntervalMs) || payload.recurrenceIntervalMs <= 0) {
172
- throw new Error('`recurrenceIntervalMs` must be a positive number of milliseconds or `null`.');
173
- }
174
- patch.recurrenceIntervalMs = Math.floor(payload.recurrenceIntervalMs);
175
- }
176
-
177
- if (payload.message === null) {
178
- patch.message = null;
179
- } else if (typeof payload.message === 'string') {
180
- patch.message = payload.message;
181
- }
182
-
183
- if (payload.parameters !== undefined) {
184
- if (!payload.parameters || typeof payload.parameters !== 'object' || Array.isArray(payload.parameters)) {
185
- throw new Error('`parameters` must be a JSON object.');
186
- }
187
- patch.parameters = payload.parameters as Record<string, unknown>;
188
- }
189
-
190
- if (typeof payload.paused === 'boolean') {
191
- patch.pausedAt = payload.paused ? new Date().toISOString() : null;
192
- }
193
-
194
- if (typeof payload.extendByMs === 'number') {
195
- if (!Number.isFinite(payload.extendByMs) || payload.extendByMs <= 0) {
196
- throw new Error('`extendByMs` must be a positive number of milliseconds.');
197
- }
198
- patch.extendByMs = Math.floor(payload.extendByMs);
199
- }
200
-
201
- if (patch.dueAt !== undefined && patch.extendByMs !== undefined) {
202
- throw new Error('`dueAt` and `extendByMs` cannot be used together.');
203
- }
204
-
205
- return Object.keys(patch).length > 0 ? patch : null;
206
- }
@@ -5,12 +5,12 @@ import type { UserChatTimeoutRecord, UserChatTimeoutStatus } from '@/src/utils/u
5
5
  import { resolveUserChatScope } from '../user-chats/resolveUserChatScope';
6
6
 
7
7
  /**
8
- * Upper bound for one agent-wide timeout listing response.
8
+ * Upper bound for one agent-wide planned-message listing response.
9
9
  */
10
10
  const MAX_AGENT_TIMEOUT_MANAGER_ITEMS = 500;
11
11
 
12
12
  /**
13
- * Deterministic status order used in the timeout manager table.
13
+ * Deterministic status order used in the goal-chat planned-message list.
14
14
  */
15
15
  const TIMEOUT_STATUS_ORDER: Record<UserChatTimeoutStatus, number> = {
16
16
  RUNNING: 0,
@@ -21,7 +21,7 @@ const TIMEOUT_STATUS_ORDER: Record<UserChatTimeoutStatus, number> = {
21
21
  };
22
22
 
23
23
  /**
24
- * Lists all durable timeouts owned by current user for one agent across chats.
24
+ * Lists every planned message of one agent, as shown in its goal chat.
25
25
  */
26
26
  export async function GET(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
27
27
  if (isPrivateModeEnabledFromRequest(request)) {
@@ -44,9 +44,14 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
44
44
  return NextResponse.json({ error: 'Agent not found.' }, { status: 404 });
45
45
  }
46
46
 
47
+ if (!scopeResult.scope.viewerCanAccessAgentGoalChat) {
48
+ return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
49
+ }
50
+
47
51
  try {
52
+ // Note: Planned messages belong to the agent, so the goal chat lists them across every chat
53
+ // and every user of the agent
48
54
  const timeouts = await listAgentUserChatTimeouts({
49
- userId: scopeResult.scope.userId,
50
55
  agentPermanentId: scopeResult.scope.agentPermanentId,
51
56
  limit: MAX_AGENT_TIMEOUT_MANAGER_ITEMS,
52
57
  });
@@ -41,6 +41,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
41
41
  userId: scopeResult.scope.userId,
42
42
  viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
43
43
  viewerIsSuperAdmin: scopeResult.scope.viewerIsSuperAdmin,
44
+ viewerCanAccessAgentGoalChat: scopeResult.scope.viewerCanAccessAgentGoalChat,
44
45
  agentPermanentId: scopeResult.scope.agentPermanentId,
45
46
  chatId,
46
47
  });
@@ -86,6 +87,7 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ ag
86
87
  userId: scopeResult.scope.userId,
87
88
  viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
88
89
  viewerIsSuperAdmin: scopeResult.scope.viewerIsSuperAdmin,
90
+ viewerCanAccessAgentGoalChat: scopeResult.scope.viewerCanAccessAgentGoalChat,
89
91
  agentPermanentId: scopeResult.scope.agentPermanentId,
90
92
  chatId,
91
93
  });
@@ -201,6 +203,7 @@ export async function DELETE(request: Request, { params }: { params: Promise<{ a
201
203
  userId: scopeResult.scope.userId,
202
204
  viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
203
205
  viewerIsSuperAdmin: scopeResult.scope.viewerIsSuperAdmin,
206
+ viewerCanAccessAgentGoalChat: scopeResult.scope.viewerCanAccessAgentGoalChat,
204
207
  agentPermanentId: scopeResult.scope.agentPermanentId,
205
208
  chatId,
206
209
  });
@@ -66,6 +66,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
66
66
  const chat = await getUserChat({
67
67
  userId: scopeResult.scope.userId,
68
68
  viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
69
+ viewerCanAccessAgentGoalChat: scopeResult.scope.viewerCanAccessAgentGoalChat,
69
70
  agentPermanentId: scopeResult.scope.agentPermanentId,
70
71
  chatId,
71
72
  });
@@ -133,6 +134,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
133
134
  const currentChat = await getUserChat({
134
135
  userId: scopeResult.scope.userId,
135
136
  viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
137
+ viewerCanAccessAgentGoalChat: scopeResult.scope.viewerCanAccessAgentGoalChat,
136
138
  agentPermanentId: scopeResult.scope.agentPermanentId,
137
139
  chatId,
138
140
  });
@@ -1,4 +1,5 @@
1
1
  import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
2
+ import { canAccessAgentGoalChat } from '@/src/utils/agentGoalChat';
2
3
  import { canAccessAgentVisibility, resolveAgentVisibility } from '@/src/utils/agentAccess';
3
4
  import { resolveCurrentUserIdentity } from '@/src/utils/currentUserIdentity';
4
5
  import { isUserGlobalAdmin } from '@/src/utils/isUserGlobalAdmin';
@@ -15,6 +16,10 @@ export type ResolvedUserChatScope = {
15
16
  * who may browse all users' chats in a view-only mode.
16
17
  */
17
18
  viewerIsSuperAdmin: boolean;
19
+ /**
20
+ * True when the viewer may read the agent source book and therefore also the agent goal chat.
21
+ */
22
+ viewerCanAccessAgentGoalChat: boolean;
18
23
  agentPermanentId: string;
19
24
  };
20
25
 
@@ -38,9 +43,10 @@ export async function resolveUserChatScope(
38
43
 
39
44
  try {
40
45
  const collection = await $provideAgentCollectionForServer();
41
- const [agentPermanentId, viewerIsSuperAdmin] = await Promise.all([
46
+ const [agentPermanentId, viewerIsSuperAdmin, viewerCanAccessAgentGoalChat] = await Promise.all([
42
47
  collection.getAgentPermanentId(agentIdentifier),
43
48
  isUserGlobalAdmin(),
49
+ canAccessAgentGoalChat(),
44
50
  ]);
45
51
  const visibility = await resolveAgentVisibility(agentPermanentId);
46
52
  const isAllowed = canAccessAgentVisibility({
@@ -58,6 +64,7 @@ export async function resolveUserChatScope(
58
64
  userId: currentUserIdentity.userId,
59
65
  viewerIsAdmin: currentUserIdentity.isAdmin,
60
66
  viewerIsSuperAdmin,
67
+ viewerCanAccessAgentGoalChat,
61
68
  agentPermanentId,
62
69
  },
63
70
  };
@@ -1,3 +1,4 @@
1
+ import { isAgentGoalChatId, prependAgentGoalChatSummarySeed } from '@/src/utils/agentGoalChat';
1
2
  import { isPrivateModeEnabledFromRequest } from '@/src/utils/privateMode';
2
3
  import {
3
4
  createUserChat,
@@ -38,12 +39,16 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
38
39
  const requestUrl = new URL(request.url);
39
40
  const requestedChatId = normalizeOptionalString(requestUrl.searchParams.get('chat'));
40
41
  const showExternalChats = normalizeBooleanFlag(requestUrl.searchParams.get('showExternalChats'));
41
- const chatSummarySeeds = await listUserChatSummarySeeds({
42
- userId: scopeResult.scope.userId,
43
- viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
44
- viewerIsSuperAdmin: scopeResult.scope.viewerIsSuperAdmin,
42
+ const chatSummarySeeds = await prependAgentGoalChatSummarySeed({
43
+ chatSummarySeeds: await listUserChatSummarySeeds({
44
+ userId: scopeResult.scope.userId,
45
+ viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
46
+ viewerIsSuperAdmin: scopeResult.scope.viewerIsSuperAdmin,
47
+ agentPermanentId: scopeResult.scope.agentPermanentId,
48
+ includeExternalChats: showExternalChats,
49
+ }),
45
50
  agentPermanentId: scopeResult.scope.agentPermanentId,
46
- includeExternalChats: showExternalChats,
51
+ isAgentGoalChatVisible: scopeResult.scope.viewerCanAccessAgentGoalChat,
47
52
  });
48
53
  const activityUserId =
49
54
  (scopeResult.scope.viewerIsAdmin || scopeResult.scope.viewerIsSuperAdmin) && showExternalChats
@@ -62,15 +67,18 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
62
67
  }),
63
68
  ]);
64
69
 
70
+ // Note: The pinned goal chat is opened only on explicit request, never as the default thread
71
+ const defaultChatSummarySeed =
72
+ chatSummarySeeds.find((chat) => !isAgentGoalChatId(chat.id)) || chatSummarySeeds[0] || null;
65
73
  const activeChatSummarySeed =
66
74
  (requestedChatId ? chatSummarySeeds.find((chat) => chat.id === requestedChatId) : null) ||
67
- chatSummarySeeds[0] ||
68
- null;
75
+ defaultChatSummarySeed;
69
76
  const activeChat = activeChatSummarySeed
70
77
  ? await getUserChat({
71
78
  userId: scopeResult.scope.userId,
72
79
  viewerIsAdmin: scopeResult.scope.viewerIsAdmin,
73
80
  viewerIsSuperAdmin: scopeResult.scope.viewerIsSuperAdmin,
81
+ viewerCanAccessAgentGoalChat: scopeResult.scope.viewerCanAccessAgentGoalChat,
74
82
  agentPermanentId: scopeResult.scope.agentPermanentId,
75
83
  chatId: activeChatSummarySeed.id,
76
84
  })
@@ -1,5 +1,6 @@
1
1
  import type { string_book } from '@promptbook-local/types';
2
- import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { debounce } from '@promptbook-local/utils';
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
4
  import { resolveBookEditorApiErrorMessage } from './resolveBookEditorApiErrorMessage';
4
5
 
5
6
  /**
@@ -82,13 +83,6 @@ export function useBookEditorSaving({ agentName, initialAgentSource }: UseBookEd
82
83
  const [isSaveDebounced, setIsSaveDebounced] = useState(false);
83
84
  const [successfulSaveSequence, setSuccessfulSaveSequence] = useState(0);
84
85
 
85
- /**
86
- * Debounce timer ref so pending saves can be replaced before dispatch.
87
- *
88
- * @private function of useBookEditorWrapper
89
- */
90
- const debounceTimerRef = useRef<number | null>(null);
91
-
92
86
  /**
93
87
  * Stores the newest queued save request.
94
88
  *
@@ -175,6 +169,16 @@ export function useBookEditorSaving({ agentName, initialAgentSource }: UseBookEd
175
169
  [flushSaveQueue],
176
170
  );
177
171
 
172
+ /**
173
+ * Reuses the shared debounce utility while keeping source persistence separate from goal-chat notifications.
174
+ *
175
+ * @private function of useBookEditorWrapper
176
+ */
177
+ const debouncedEnqueueSave = useMemo(
178
+ () => debounce(enqueueSave, SAVE_DEBOUNCE_DELAY_MS),
179
+ [enqueueSave],
180
+ );
181
+
178
182
  /**
179
183
  * Schedules one autosave after the debounce delay.
180
184
  *
@@ -182,19 +186,12 @@ export function useBookEditorSaving({ agentName, initialAgentSource }: UseBookEd
182
186
  */
183
187
  const scheduleSave = useCallback(
184
188
  (nextSource: string_book, version: number) => {
185
- if (debounceTimerRef.current) {
186
- clearTimeout(debounceTimerRef.current);
187
- }
188
-
189
189
  setIsSaveDebounced(true);
190
190
  setSaveStatus('pending');
191
191
 
192
- debounceTimerRef.current = window.setTimeout(() => {
193
- debounceTimerRef.current = null;
194
- enqueueSave(nextSource, version, null);
195
- }, SAVE_DEBOUNCE_DELAY_MS);
192
+ debouncedEnqueueSave(nextSource, version, null);
196
193
  },
197
- [enqueueSave],
194
+ [debouncedEnqueueSave],
198
195
  );
199
196
 
200
197
  /**
@@ -218,14 +215,10 @@ export function useBookEditorSaving({ agentName, initialAgentSource }: UseBookEd
218
215
  * @private function of useBookEditorWrapper
219
216
  */
220
217
  const cancelPendingSave = useCallback(() => {
221
- if (debounceTimerRef.current) {
222
- clearTimeout(debounceTimerRef.current);
223
- debounceTimerRef.current = null;
224
- }
225
-
218
+ debouncedEnqueueSave.cancel();
226
219
  pendingSaveRef.current = null;
227
220
  setIsSaveDebounced(false);
228
- }, []);
221
+ }, [debouncedEnqueueSave]);
229
222
 
230
223
  /**
231
224
  * Retries saving the current editor content immediately.
@@ -297,11 +290,9 @@ export function useBookEditorSaving({ agentName, initialAgentSource }: UseBookEd
297
290
  */
298
291
  useEffect(() => {
299
292
  return () => {
300
- if (debounceTimerRef.current) {
301
- clearTimeout(debounceTimerRef.current);
302
- }
293
+ debouncedEnqueueSave.cancel();
303
294
  };
304
- }, []);
295
+ }, [debouncedEnqueueSave]);
305
296
 
306
297
  /**
307
298
  * Indicates whether the latest local source revision is already confirmed on the server.
@@ -329,5 +320,4 @@ export function useBookEditorSaving({ agentName, initialAgentSource }: UseBookEd
329
320
  };
330
321
  }
331
322
 
332
- // TODO: Prompt: Use `import { debounce } from '@promptbook-local/utils';` instead of custom debounce implementation
333
323
  // TODO: [🚗] Transfer the saving logic to `<BookEditor/>` be aware of CRDT / yjs approach to be implementable in future