@promptbook/cli 0.114.0-5 → 0.114.0-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +976 -668
  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
@@ -2,6 +2,7 @@ Developer
2
2
 
3
3
 
4
4
 
5
+ META VISUAL ascii-octopus
5
6
  META VISIBILITY PRIVATE
6
7
 
7
8
  RULE
@@ -34,6 +34,15 @@ const AGENTS_SERVER_BUILD_WORKER_COUNT = parseAgentsServerBuildWorkerCount(
34
34
  process.env.PTBK_AGENTS_SERVER_BUILD_WORKER_COUNT,
35
35
  );
36
36
 
37
+ /**
38
+ * Whether this build has to stay inside a small memory budget.
39
+ *
40
+ * Standalone VPS self-updates request a single build worker because they compile the replacement
41
+ * server while the current one is still serving traffic, so such a build must not start additional
42
+ * concurrent work either.
43
+ */
44
+ const IS_MEMORY_CONSTRAINED_BUILD = AGENTS_SERVER_BUILD_WORKER_COUNT === 1;
45
+
37
46
  /**
38
47
  * Whether Sentry source maps can be uploaded during production builds.
39
48
  */
@@ -69,6 +78,19 @@ const nextConfig: NextConfig = {
69
78
 
70
79
  experimental: {
71
80
  externalDir: true,
81
+
82
+ // Note: Next.js turns its build workers off as soon as a `webpack` function is configured, and
83
+ // that also turns off the parallel output file tracing pass. The `webpack` function below
84
+ // only adds aliases, fallbacks and loaders, so the workers are asked for explicitly.
85
+ // Compiling each target in a separate short-lived process also releases its memory as
86
+ // soon as that target is done.
87
+ webpackBuildWorker: true,
88
+
89
+ // Note: Collecting the output file traces takes about two minutes and used to run alone between
90
+ // the compilation and the static generation. It now runs next to the remaining compilation
91
+ // and page generation - except for a build which has to save memory rather than time.
92
+ parallelServerBuildTraces: !IS_MEMORY_CONSTRAINED_BUILD,
93
+
72
94
  ...(AGENTS_SERVER_BUILD_WORKER_COUNT ? { cpus: AGENTS_SERVER_BUILD_WORKER_COUNT } : {}),
73
95
  },
74
96
 
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "promptbook-agents-server",
3
3
  "scripts": {
4
- "generate-reserved-paths": "ts-node ./scripts/generate-reserved-paths/generate-reserved-paths.ts",
5
- "prebuild": "npm run generate-reserved-paths && node ./scripts/clearNextGeneratedTypes.js && npx kill-port 4440 || exit 0",
6
- "predev": "npm run generate-reserved-paths && npx kill-port 4440 || exit 0",
4
+ "generate-reserved-paths": "ts-node --transpile-only ./scripts/generate-reserved-paths/generate-reserved-paths.ts",
5
+ "prebuild": "npm run generate-reserved-paths && node ./scripts/clearNextGeneratedTypes.js && node ./scripts/kill-port.js 4440",
6
+ "predev": "npm run generate-reserved-paths && node ./scripts/kill-port.js 4440",
7
7
  "dev": "next dev -p 4440",
8
8
  "test": "npm run test-e2e",
9
9
  "test-e2e": "node ./scripts/run-e2e-tests.js",
10
- "pretest-build": "npx kill-port 4021 4440 || exit 0",
10
+ "pretest-build": "node ./scripts/kill-port.js 4021 4440",
11
11
  "test-build": "npm run build",
12
- "pretest-e2e": "npx kill-port 4021 4440 || exit 0",
12
+ "pretest-e2e": "node ./scripts/kill-port.js 4021 4440",
13
13
  "build": "node ./scripts/build-agents-server.js",
14
14
  "build-e2e": "node ./scripts/build-e2e.js",
15
15
  "start": "next start -p 4440",
16
- "lint": "eslint src/ --max-warnings=0",
16
+ "lint": "eslint src/ --max-warnings=0 --cache --cache-location ./node_modules/.cache/eslint/agents-server-src.json",
17
17
  "postinstall": "node ./scripts/ensure-root-dependencies.js"
18
18
  }
19
19
  }
@@ -8,6 +8,11 @@ const path = require('node:path');
8
8
  */
9
9
  const APP_ROOT = path.resolve(__dirname, '..');
10
10
 
11
+ /**
12
+ * Root directory of the repository, which owns the shared build and test scripts.
13
+ */
14
+ const PROJECT_ROOT = path.resolve(APP_ROOT, '..', '..');
15
+
11
16
  /**
12
17
  * Maximum Node.js heap size used by the Next.js production build.
13
18
  */
@@ -17,13 +22,14 @@ const AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB = 8192;
17
22
  * Runs the shared Agents Server production build and its homepage prerender step.
18
23
  *
19
24
  * The optional `--no-lint` argument is used by the E2E runner after the same app
20
- * lint command has already completed successfully.
25
+ * lint command has already completed successfully. The optional `--no-homepage-prerender`
26
+ * argument is used by builds whose caller starts the very same production server right
27
+ * afterwards, which makes the extra prerender server a repetition of that work.
21
28
  */
22
29
  function buildAgentsServer() {
23
30
  const nextBuildArguments = [
24
- `--max-old-space-size=${AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB}`,
25
31
  '-r',
26
- path.join(APP_ROOT, 'scripts', 'ignore-kill-eperm.js'),
32
+ path.join(PROJECT_ROOT, 'scripts', 'ignore-kill-eperm.js'),
27
33
  path.join(APP_ROOT, 'scripts', 'next-cli.js'),
28
34
  'build',
29
35
  ];
@@ -32,8 +38,34 @@ function buildAgentsServer() {
32
38
  nextBuildArguments.push('--no-lint');
33
39
  }
34
40
 
35
- runChildProcess(process.execPath, nextBuildArguments);
36
- runChildProcess(process.execPath, [path.join(APP_ROOT, 'scripts', 'prerender-homepage.js')]);
41
+ runChildProcess(process.execPath, nextBuildArguments, {
42
+ // Note: Next.js compiles each webpack target in its own build worker process, and a worker
43
+ // inherits the heap limit only through `NODE_OPTIONS` - not through the command line of
44
+ // the build process which spawned it. The same merge is done for the CLI-owned
45
+ // production build in `src/cli/cli-commands/agents-server/buildAgentsServer/runNextBuild.ts`.
46
+ NODE_OPTIONS: mergeNodeOptionsWithHeapSize(process.env.NODE_OPTIONS, AGENTS_SERVER_BUILD_MAX_OLD_SPACE_MIB),
47
+ });
48
+
49
+ if (!process.argv.includes('--no-homepage-prerender')) {
50
+ runChildProcess(process.execPath, [path.join(APP_ROOT, 'scripts', 'prerender-homepage.js')]);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Prepends `--max-old-space-size=<mib>` to `NODE_OPTIONS` unless the caller already set one.
56
+ *
57
+ * @param existingNodeOptions - Inherited `NODE_OPTIONS` value.
58
+ * @param maxOldSpaceMib - Maximum Node.js heap size in MiB.
59
+ * @returns `NODE_OPTIONS` value for the build process.
60
+ */
61
+ function mergeNodeOptionsWithHeapSize(existingNodeOptions, maxOldSpaceMib) {
62
+ if (existingNodeOptions !== undefined && /--max-old-space-size[= ]/u.test(existingNodeOptions)) {
63
+ return existingNodeOptions;
64
+ }
65
+
66
+ const heapFlag = `--max-old-space-size=${maxOldSpaceMib}`;
67
+
68
+ return existingNodeOptions ? `${heapFlag} ${existingNodeOptions}` : heapFlag;
37
69
  }
38
70
 
39
71
  /**
@@ -41,11 +73,15 @@ function buildAgentsServer() {
41
73
  *
42
74
  * @param executablePath - Executable to run.
43
75
  * @param argumentsList - Arguments passed to the executable.
76
+ * @param environmentOverrides - Environment variables added on top of the inherited environment.
44
77
  */
45
- function runChildProcess(executablePath, argumentsList) {
78
+ function runChildProcess(executablePath, argumentsList, environmentOverrides = {}) {
46
79
  const result = spawnSync(executablePath, argumentsList, {
47
80
  cwd: APP_ROOT,
48
- env: process.env,
81
+ env: {
82
+ ...process.env,
83
+ ...environmentOverrides,
84
+ },
49
85
  stdio: 'inherit',
50
86
  });
51
87
 
@@ -9,6 +9,16 @@ const { runNpm } = require('./run-npm.js');
9
9
  */
10
10
  const APP_ROOT = path.resolve(__dirname, '..');
11
11
 
12
+ /**
13
+ * Production build arguments which every E2E build applies.
14
+ *
15
+ * The homepage prerender starts one more production server only to download `/` into an HTML
16
+ * snapshot which nothing reads afterwards. Every E2E build is started by Playwright right after it
17
+ * is compiled, and the tests open the homepage against that very same server, so the snapshot would
18
+ * only repeat work the tests already do.
19
+ */
20
+ const E2E_BUILD_ARGUMENTS = ['--no-homepage-prerender'];
21
+
12
22
  /**
13
23
  * Builds the production bundle used by the Agents Server E2E tests.
14
24
  *
@@ -16,10 +26,10 @@ const APP_ROOT = path.resolve(__dirname, '..');
16
26
  * mocked Supabase URL are embedded consistently in browser bundles.
17
27
  */
18
28
  function buildE2eServer() {
19
- const buildArguments = ['run', 'build'];
29
+ const buildArguments = ['run', 'build', '--', ...E2E_BUILD_ARGUMENTS];
20
30
 
21
31
  if (process.argv.includes('--no-lint')) {
22
- buildArguments.push('--', '--no-lint');
32
+ buildArguments.push('--no-lint');
23
33
  }
24
34
 
25
35
  runNpm(buildArguments, {
@@ -1,3 +1,4 @@
1
+ import { spaceTrim } from 'spacetrim';
1
2
  import fs from 'fs';
2
3
  import path from 'path';
3
4
  import { GENERATOR_WARNING } from '../../../../src/config';
@@ -58,18 +59,20 @@ const allReservedPaths = [...new Set([...reservedPaths, ...publicPaths, ...addit
58
59
  /**
59
60
  * Constant for content.
60
61
  */
61
- const content = `/**
62
- * Reserved paths that should not be treated as agent names.
63
- * This file is auto-generated by scripts/generate-reserved-paths.js
64
- *
65
- * ${GENERATOR_WARNING}
66
- *
67
- * @see /apps/agents-server/src/app - source directory for routes
68
- * @see /apps/agents-server/public - source directory for static files
69
- * @see /apps/agents-server/src/middleware.ts - where this is used
70
- */
71
- export const RESERVED_PATHS: readonly string[] = ${JSON.stringify(allReservedPaths, null, 4)} as const;
72
- `;
62
+ const content = spaceTrim(
63
+ (block) => `/**
64
+ * Reserved paths that should not be treated as agent names.
65
+ * This file is auto-generated by scripts/generate-reserved-paths.js
66
+ *
67
+ * ${GENERATOR_WARNING}
68
+ *
69
+ * @see /apps/agents-server/src/app - source directory for routes
70
+ * @see /apps/agents-server/public - source directory for static files
71
+ * @see /apps/agents-server/src/middleware.ts - where this is used
72
+ */
73
+ export const RESERVED_PATHS: readonly string[] = ${block(JSON.stringify(allReservedPaths, null, 4))} as const;
74
+ `,
75
+ );
73
76
 
74
77
  // Ensure the generated directory exists
75
78
  /**
@@ -80,8 +83,19 @@ if (!fs.existsSync(generatedDir)) {
80
83
  fs.mkdirSync(generatedDir, { recursive: true });
81
84
  }
82
85
 
83
- // Write the file
84
- fs.writeFileSync(outputFile, content, 'utf-8');
86
+ // Note: Rewriting an unchanged file would only move its modification time forward, which invalidates
87
+ // the webpack and TypeScript caches of every build and every development server start.
88
+ /**
89
+ * Constant for current content.
90
+ */
91
+ const currentContent = fs.existsSync(outputFile) ? fs.readFileSync(outputFile, 'utf-8') : null;
85
92
 
86
- console.log(`Generated ${outputFile} with ${allReservedPaths.length} reserved paths:`);
87
- console.log(allReservedPaths.join(', '));
93
+ if (currentContent === content) {
94
+ console.log(`Kept ${outputFile} unchanged with ${allReservedPaths.length} reserved paths.`);
95
+ } else {
96
+ // Write the file
97
+ fs.writeFileSync(outputFile, content, 'utf-8');
98
+
99
+ console.log(`Generated ${outputFile} with ${allReservedPaths.length} reserved paths:`);
100
+ console.log(allReservedPaths.join(', '));
101
+ }
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ const { spawnSync } = require('node:child_process');
4
+
5
+ /**
6
+ * Frees the given TCP ports before a build, a development server, or an E2E run binds them again.
7
+ *
8
+ * This replaces `npx kill-port`, which resolved an undeclared package through the npm registry on
9
+ * every single invocation. Freeing a port is a best-effort cleanup step, so nothing here may ever
10
+ * fail the surrounding command.
11
+ *
12
+ * Usage: `node ./scripts/kill-port.js 4021 4440`
13
+ */
14
+ function killPorts() {
15
+ for (const port of parsePortArguments(process.argv.slice(2))) {
16
+ const listeningProcessIds = resolveListeningProcessIds(port);
17
+
18
+ if (listeningProcessIds.length === 0) {
19
+ console.log(`No process is listening on port ${port}.`);
20
+ continue;
21
+ }
22
+
23
+ for (const processId of listeningProcessIds) {
24
+ if (killProcess(processId)) {
25
+ console.log(`Freed port ${port} by stopping process ${processId}.`);
26
+ } else {
27
+ console.log(`Could not stop process ${processId} listening on port ${port}.`);
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Reads the TCP ports from the command line arguments.
35
+ *
36
+ * @param {ReadonlyArray<string>} argumentsList - Raw command line arguments.
37
+ * @returns {Array<number>} Valid TCP ports.
38
+ */
39
+ function parsePortArguments(argumentsList) {
40
+ return argumentsList.map((argument) => Number(argument)).filter(isPort);
41
+ }
42
+
43
+ /**
44
+ * Returns whether one value is a usable TCP port number.
45
+ *
46
+ * @param {number} value - Parsed command line argument.
47
+ * @returns {boolean} Whether the value can be freed.
48
+ */
49
+ function isPort(value) {
50
+ return Number.isInteger(value) && value > 0 && value <= 65535;
51
+ }
52
+
53
+ /**
54
+ * Resolves the process ids currently listening on one TCP port.
55
+ *
56
+ * @param {number} port - TCP port to inspect.
57
+ * @returns {Array<number>} Process ids of the listeners.
58
+ */
59
+ function resolveListeningProcessIds(port) {
60
+ if (process.platform === 'win32') {
61
+ return resolveWindowsListeningProcessIds(port);
62
+ }
63
+
64
+ return resolvePosixListeningProcessIds(port);
65
+ }
66
+
67
+ /**
68
+ * Resolves listeners of one TCP port through the Windows `netstat` utility.
69
+ *
70
+ * @param {number} port - TCP port to inspect.
71
+ * @returns {Array<number>} Process ids of the listeners.
72
+ */
73
+ function resolveWindowsListeningProcessIds(port) {
74
+ const netstatResult = spawnSync('netstat', ['-a', '-n', '-o', '-p', 'TCP'], { encoding: 'utf8' });
75
+
76
+ if (typeof netstatResult.stdout !== 'string') {
77
+ return [];
78
+ }
79
+
80
+ return dedupeProcessIds(
81
+ netstatResult.stdout
82
+ .split(/\r?\n/u)
83
+ .filter((line) => line.includes('LISTENING'))
84
+ .map((line) => line.trim().split(/\s+/u))
85
+ .filter((columns) => columns.length >= 5 && isAddressOnPort(columns[1], port))
86
+ .map((columns) => Number(columns[columns.length - 1])),
87
+ );
88
+ }
89
+
90
+ /**
91
+ * Resolves listeners of one TCP port through the POSIX `lsof` utility.
92
+ *
93
+ * @param {number} port - TCP port to inspect.
94
+ * @returns {Array<number>} Process ids of the listeners.
95
+ */
96
+ function resolvePosixListeningProcessIds(port) {
97
+ const listOpenFilesResult = spawnSync('lsof', ['-nP', `-iTCP:${port}`, '-sTCP:LISTEN', '-t'], {
98
+ encoding: 'utf8',
99
+ });
100
+
101
+ if (typeof listOpenFilesResult.stdout !== 'string') {
102
+ return [];
103
+ }
104
+
105
+ return dedupeProcessIds(listOpenFilesResult.stdout.split(/\s+/u).map((value) => Number(value)));
106
+ }
107
+
108
+ /**
109
+ * Returns whether one `netstat` local address belongs to the inspected port.
110
+ *
111
+ * The address is printed as `0.0.0.0:4440`, `127.0.0.1:4440`, or `[::]:4440`.
112
+ *
113
+ * @param {string} address - Local address column of one `netstat` row.
114
+ * @param {number} port - TCP port to inspect.
115
+ * @returns {boolean} Whether the row belongs to the port.
116
+ */
117
+ function isAddressOnPort(address, port) {
118
+ return address.endsWith(`:${port}`);
119
+ }
120
+
121
+ /**
122
+ * Keeps only distinct process ids which are safe to stop.
123
+ *
124
+ * The current process and its parent are excluded so that freeing a port can never stop the build,
125
+ * the test runner, or the shell which started them.
126
+ *
127
+ * @param {ReadonlyArray<number>} processIds - Raw process ids.
128
+ * @returns {Array<number>} Distinct stoppable process ids.
129
+ */
130
+ function dedupeProcessIds(processIds) {
131
+ return Array.from(
132
+ new Set(
133
+ processIds.filter(
134
+ (processId) =>
135
+ Number.isInteger(processId) &&
136
+ processId > 0 &&
137
+ processId !== process.pid &&
138
+ processId !== process.ppid,
139
+ ),
140
+ ),
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Stops one process which holds an inspected port.
146
+ *
147
+ * @param {number} processId - Process id of the listener.
148
+ * @returns {boolean} Whether the process was stopped.
149
+ */
150
+ function killProcess(processId) {
151
+ if (process.platform === 'win32') {
152
+ return spawnSync('taskkill', ['/F', '/PID', String(processId)], { stdio: 'ignore' }).status === 0;
153
+ }
154
+
155
+ try {
156
+ process.kill(processId, 'SIGKILL');
157
+ return true;
158
+ } catch {
159
+ return false;
160
+ }
161
+ }
162
+
163
+ killPorts();
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('node:path');
4
- const { runNpm } = require('./run-npm.js');
4
+ const { runNpm, startNpm, startNpmWithCollectedOutput } = require('./run-npm.js');
5
5
 
6
6
  /**
7
7
  * Root directory of the Agents Server app.
@@ -11,17 +11,30 @@ const APP_ROOT = path.resolve(__dirname, '..');
11
11
  /**
12
12
  * Runs the complete Agents Server E2E verification flow.
13
13
  *
14
- * App linting remains an explicit test phase. The production build then skips
15
- * its duplicate lint pass, and Playwright starts that same build instead of
16
- * compiling a second `.next-e2e` output through `webServer`.
14
+ * App linting remains an explicit test phase, but it reads only the sources and therefore does not
15
+ * depend on the production build. Both run at the same time and the flow waits for the slower one,
16
+ * which is always the build. The build then skips its duplicate lint pass, and Playwright starts
17
+ * that same build instead of compiling a second `.next-e2e` output through `webServer`.
17
18
  */
18
- function runE2eTests() {
19
+ async function runE2eTests() {
19
20
  const commandOptions = {
20
21
  cwd: APP_ROOT,
21
22
  };
22
23
 
23
- runNpm(['run', 'lint'], commandOptions);
24
- runNpm(['run', 'build-e2e', '--', '--no-lint'], commandOptions);
24
+ const lintCompletion = startNpmWithCollectedOutput(['run', 'lint'], commandOptions);
25
+ const buildStatus = await startNpm(['run', 'build-e2e', '--', '--no-lint'], commandOptions);
26
+ const lintResult = await lintCompletion;
27
+
28
+ console.log('\n> lint (ran next to the production build)\n');
29
+ process.stdout.write(lintResult.output);
30
+
31
+ if (lintResult.status !== 0) {
32
+ process.exit(lintResult.status);
33
+ }
34
+
35
+ if (buildStatus !== 0) {
36
+ process.exit(buildStatus);
37
+ }
25
38
 
26
39
  runNpm(['exec', '--', 'playwright', 'test', ...process.argv.slice(2)], {
27
40
  ...commandOptions,
@@ -31,4 +44,4 @@ function runE2eTests() {
31
44
  });
32
45
  }
33
46
 
34
- runE2eTests();
47
+ void runE2eTests();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { spawnSync } = require('node:child_process');
3
+ const { spawn, spawnSync } = require('node:child_process');
4
4
 
5
5
  /**
6
6
  * Platform-specific npm executable.
@@ -8,22 +8,34 @@ const { spawnSync } = require('node:child_process');
8
8
  const NPM_EXECUTABLE = process.platform === 'win32' ? 'npm.cmd' : 'npm';
9
9
 
10
10
  /**
11
- * Runs one npm command and forwards its output and exit status.
11
+ * Creates the spawn options shared by every npm command of the Agents Server scripts.
12
12
  *
13
13
  * Windows resolves npm through a `.cmd` shim, which needs shell execution when spawned from
14
14
  * Node.js on some supported Node versions.
15
15
  *
16
- * @param {ReadonlyArray<string>} argumentsList - Arguments passed to npm.
17
16
  * @param {{ cwd: string, environmentOverrides?: Readonly<Record<string, string>> }} options - Command options.
17
+ * @returns {{ cwd: string, env: Record<string, string|undefined>, shell: boolean }} Shared spawn options.
18
18
  */
19
- function runNpm(argumentsList, { cwd, environmentOverrides = {} }) {
20
- const result = spawnSync(NPM_EXECUTABLE, argumentsList, {
19
+ function createNpmSpawnOptions({ cwd, environmentOverrides = {} }) {
20
+ return {
21
21
  cwd,
22
22
  env: {
23
23
  ...process.env,
24
24
  ...environmentOverrides,
25
25
  },
26
26
  shell: process.platform === 'win32',
27
+ };
28
+ }
29
+
30
+ /**
31
+ * Runs one npm command, waits for it, and forwards its output and exit status.
32
+ *
33
+ * @param {ReadonlyArray<string>} argumentsList - Arguments passed to npm.
34
+ * @param {{ cwd: string, environmentOverrides?: Readonly<Record<string, string>> }} options - Command options.
35
+ */
36
+ function runNpm(argumentsList, options) {
37
+ const result = spawnSync(NPM_EXECUTABLE, argumentsList, {
38
+ ...createNpmSpawnOptions(options),
27
39
  stdio: 'inherit',
28
40
  });
29
41
 
@@ -37,6 +49,70 @@ function runNpm(argumentsList, { cwd, environmentOverrides = {} }) {
37
49
  }
38
50
  }
39
51
 
52
+ /**
53
+ * Starts one npm command without waiting for it and forwards its output to this terminal.
54
+ *
55
+ * @param {ReadonlyArray<string>} argumentsList - Arguments passed to npm.
56
+ * @param {{ cwd: string, environmentOverrides?: Readonly<Record<string, string>> }} options - Command options.
57
+ * @returns {Promise<number>} Exit status of the finished command.
58
+ */
59
+ function startNpm(argumentsList, options) {
60
+ return waitForNpm(
61
+ spawn(NPM_EXECUTABLE, argumentsList, {
62
+ ...createNpmSpawnOptions(options),
63
+ stdio: 'inherit',
64
+ }),
65
+ );
66
+ }
67
+
68
+ /**
69
+ * Starts one npm command without waiting for it and collects its output instead of printing it.
70
+ *
71
+ * Two commands running next to each other cannot share this terminal line by line, so the output of
72
+ * the quieter one is kept and printed as one readable block once it has finished.
73
+ *
74
+ * @param {ReadonlyArray<string>} argumentsList - Arguments passed to npm.
75
+ * @param {{ cwd: string, environmentOverrides?: Readonly<Record<string, string>> }} options - Command options.
76
+ * @returns {Promise<{ status: number, output: string }>} Exit status and collected output.
77
+ */
78
+ function startNpmWithCollectedOutput(argumentsList, options) {
79
+ const npmProcess = spawn(NPM_EXECUTABLE, argumentsList, {
80
+ ...createNpmSpawnOptions(options),
81
+ stdio: ['ignore', 'pipe', 'pipe'],
82
+ });
83
+
84
+ let output = '';
85
+ const collectOutput = (chunk) => {
86
+ output = `${output}${chunk.toString()}`;
87
+ };
88
+
89
+ npmProcess.stdout?.on('data', collectOutput);
90
+ npmProcess.stderr?.on('data', collectOutput);
91
+
92
+ return waitForNpm(npmProcess).then((status) => ({ status, output }));
93
+ }
94
+
95
+ /**
96
+ * Waits for one started npm command and reports its exit status.
97
+ *
98
+ * @param {import('node:child_process').ChildProcess} npmProcess - Started npm command.
99
+ * @returns {Promise<number>} Exit status of the finished command.
100
+ */
101
+ function waitForNpm(npmProcess) {
102
+ return new Promise((resolve) => {
103
+ npmProcess.once('error', (error) => {
104
+ console.error(`Failed to run ${NPM_EXECUTABLE}:`, error);
105
+ resolve(1);
106
+ });
107
+
108
+ npmProcess.once('close', (status) => {
109
+ resolve(status ?? 1);
110
+ });
111
+ });
112
+ }
113
+
40
114
  module.exports = {
41
115
  runNpm,
116
+ startNpm,
117
+ startNpmWithCollectedOutput,
42
118
  };
@@ -15,6 +15,7 @@ import { buildAgentChatHref, buildAgentProfileHref } from '../utils/agentRouting
15
15
  import { type AgentVisibility, parseAgentVisibility } from '../utils/agentVisibility';
16
16
  import { authenticateUserWithRateLimit } from '../utils/authenticateUser';
17
17
  import { resolveAuthenticationAttemptHeaderIp } from '../utils/authenticationAttemptRateLimit';
18
+ import { recordAgentGoalChatLifecycleNote } from '../utils/agentGoalChat';
18
19
  import { createAgentWithDefaultVisibility } from '../utils/createAgentWithDefaultVisibility';
19
20
  import { resolveCurrentUserIdentity } from '../utils/currentUserIdentity';
20
21
  import { isUserAdmin } from '../utils/isUserAdmin';
@@ -49,6 +50,7 @@ export async function $createAgentAction(): Promise<{ agentName: string_agent_na
49
50
  const { agentName, permanentId } = await createAgentWithDefaultVisibility(collection, agentSource, {
50
51
  userId: currentUserIdentity?.userId,
51
52
  });
53
+ await recordAgentGoalChatLifecycleNote({ event: 'CREATED', agentPermanentId: permanentId, agentName });
52
54
  revalidateCreatedAgentPaths(permanentId);
53
55
  await waitForCreatedAgentRoute(permanentId);
54
56
 
@@ -139,6 +141,7 @@ export async function $createAgentFromBookAction(
139
141
  visibility: visibility ?? undefined,
140
142
  userId: currentUserIdentity?.userId,
141
143
  });
144
+ await recordAgentGoalChatLifecycleNote({ event: 'CREATED', agentPermanentId: permanentId, agentName });
142
145
  revalidateCreatedAgentPaths(permanentId);
143
146
  await waitForCreatedAgentRoute(permanentId);
144
147