@promptbook/cli 0.114.0-4 → 0.114.0-6

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 (329) hide show
  1. package/README.md +3 -3
  2. package/agents/default/developer.book +1 -0
  3. package/apps/agents-server/next.config.ts +22 -0
  4. package/apps/agents-server/package.json +6 -6
  5. package/apps/agents-server/scripts/build-agents-server.js +43 -7
  6. package/apps/agents-server/scripts/build-e2e.js +12 -2
  7. package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +30 -16
  8. package/apps/agents-server/scripts/kill-port.js +163 -0
  9. package/apps/agents-server/scripts/run-e2e-tests.js +21 -8
  10. package/apps/agents-server/scripts/run-npm.js +81 -5
  11. package/apps/agents-server/src/app/actions.ts +3 -0
  12. package/apps/agents-server/src/app/admin/email-server/page.tsx +17 -18
  13. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +2 -0
  14. package/apps/agents-server/src/app/admin/task-manager/[taskId]/TaskManagerTaskDetailClient.tsx +2 -0
  15. package/apps/agents-server/src/app/admin/task-manager/taskManagerTaskPresentation.tsx +23 -0
  16. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +7 -0
  17. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/[timeoutId]/route.ts +10 -153
  18. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/route.ts +9 -4
  19. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/route.ts +3 -0
  20. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +2 -0
  21. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/resolveUserChatScope.ts +8 -1
  22. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/route.ts +15 -7
  23. package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorSaving.ts +18 -28
  24. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryClient.tsx +19 -1
  25. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +17 -5
  26. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatNotice.tsx +23 -0
  27. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +153 -0
  28. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatPanel.tsx +6 -0
  29. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +13 -0
  30. package/apps/agents-server/src/app/agents/[agentName]/chat/ExternalUserChatAdminActions.tsx +51 -3
  31. package/apps/agents-server/src/app/agents/[agentName]/chat/TeamMemberFrozenChatPrimaryAgentLink.tsx +31 -0
  32. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatSidebarState.ts +26 -2
  33. package/apps/agents-server/src/app/agents/[agentName]/goal/page.tsx +35 -0
  34. package/apps/agents-server/src/app/agents/[agentName]/projects/[projectName]/page.tsx +2 -2
  35. package/apps/agents-server/src/app/api/admin/dns-records/cloudflare/route.ts +26 -16
  36. package/apps/agents-server/src/app/api/emails/incoming/stalwart/route.ts +9 -2
  37. package/apps/agents-server/src/app/superadmin/servers/ServersRegistryTable.tsx +31 -39
  38. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +10 -3
  39. package/apps/agents-server/src/components/AgentProjects/AgentProjectIcon.tsx +137 -0
  40. package/apps/agents-server/src/components/AgentProjects/AgentProjectItem.tsx +26 -10
  41. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsApiTokenImportStep.tsx +5 -6
  42. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsCheckStep.tsx +6 -5
  43. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsManualStep.tsx +10 -14
  44. package/apps/agents-server/src/components/CloudflareDnsWizard/CloudflareDnsWizard.tsx +11 -20
  45. package/apps/agents-server/src/components/CloudflareDnsWizard/useCloudflareDnsRecordImport.ts +5 -6
  46. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsInstructions.tsx +91 -57
  47. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionPanel.tsx +63 -0
  48. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsSectionVariantTabs.tsx +67 -0
  49. package/apps/agents-server/src/components/DnsRecordsInstructions/DnsRecordsTable.tsx +40 -0
  50. package/apps/agents-server/src/components/Header/buildActiveAgentViewItems.ts +5 -4
  51. package/apps/agents-server/src/components/Header/createAgentViewLabel.tsx +4 -4
  52. package/apps/agents-server/src/components/Header/resolveActiveAgentNavigation.ts +2 -2
  53. package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +22 -10
  54. package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +1 -1
  55. package/apps/agents-server/src/database/migratePrefix.ts +13 -12
  56. package/apps/agents-server/src/database/migrations/2026-08-0100-agent-goal-chat-source.sql +10 -0
  57. package/apps/agents-server/src/generated/reservedPaths.ts +42 -42
  58. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +9 -1
  59. package/apps/agents-server/src/languages/translations/czech.yaml +9 -1
  60. package/apps/agents-server/src/languages/translations/english.yaml +9 -1
  61. package/apps/agents-server/src/message-providers/email/stalwart/parseInboundStalwartEmail.ts +17 -2
  62. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.ts +9 -0
  63. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatIdentity.ts +28 -0
  64. package/apps/agents-server/src/utils/agentGoalChat/appendAgentGoalChatNote.ts +43 -0
  65. package/apps/agents-server/src/utils/agentGoalChat/canAccessAgentGoalChat.ts +14 -0
  66. package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +69 -0
  67. package/apps/agents-server/src/utils/agentGoalChat/ensureAgentGoalChat.ts +66 -0
  68. package/apps/agents-server/src/utils/agentGoalChat/prependAgentGoalChatSummarySeed.ts +40 -0
  69. package/apps/agents-server/src/utils/agentGoalChat/recordAgentGoalChatLifecycleNote.ts +36 -0
  70. package/apps/agents-server/src/utils/agentGoalChat/resolveAgentGoalChatOwnerUserId.ts +104 -0
  71. package/apps/agents-server/src/utils/agentGoalChat/scheduleAgentGoalChatModifiedNote.ts +82 -0
  72. package/apps/agents-server/src/utils/agentGoalChat.ts +19 -0
  73. package/apps/agents-server/src/utils/agentProjects/AgentProjectInfo.ts +10 -1
  74. package/apps/agents-server/src/utils/agentProjects/AgentProjectReferenceInfo.ts +5 -2
  75. package/apps/agents-server/src/utils/agentProjects/agentProjectFileNames.ts +21 -0
  76. package/apps/agents-server/src/utils/agentProjects/agentProjectHrefs.ts +20 -11
  77. package/apps/agents-server/src/utils/agentProjects/agentProjectsPaths.ts +15 -5
  78. package/apps/agents-server/src/utils/agentProjects/createAgentProjectInitials.ts +36 -0
  79. package/apps/agents-server/src/utils/agentProjects/createAgentProjectMarkdownReferences.ts +10 -9
  80. package/apps/agents-server/src/utils/agentProjects/createAgentProjectsDnsRecordsSection.ts +113 -0
  81. package/apps/agents-server/src/utils/agentProjects/createStaticAgentProjectServer.ts +2 -6
  82. package/apps/agents-server/src/utils/agentProjects/humanizeAgentProjectName.ts +25 -0
  83. package/apps/agents-server/src/utils/agentProjects/listAgentProjectChatReferences.ts +10 -3
  84. package/apps/agents-server/src/utils/agentProjects/parseAgentProjectIndexHtml.ts +167 -0
  85. package/apps/agents-server/src/utils/agentProjects/readAgentProjectIndexHtmlProfile.ts +24 -0
  86. package/apps/agents-server/src/utils/agentProjects/readAgentProjectReadme.ts +3 -53
  87. package/apps/agents-server/src/utils/agentProjects/readAgentProjectRootTextFile.ts +73 -0
  88. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectFaviconRelativePath.ts +108 -0
  89. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectInfo.ts +12 -3
  90. package/apps/agents-server/src/utils/agentProjects/{resolveAgentProjectReadmeProfile.ts → resolveAgentProjectProfile.ts} +33 -33
  91. package/apps/agents-server/src/utils/agentProjects/resolveAgentProjectPublicUrls.ts +34 -0
  92. package/apps/agents-server/src/utils/bookLanguageDocumentation/createBookLanguageDocumentationPdfResponse.ts +19 -17
  93. package/apps/agents-server/src/utils/chatTasksAdmin.ts +9 -0
  94. package/apps/agents-server/src/utils/dnsRecords/DnsRecordInstruction.ts +20 -0
  95. package/apps/agents-server/src/utils/dnsRecords/DnsRecordsSection.ts +77 -0
  96. package/apps/agents-server/src/utils/dnsRecords/createServerDnsRecordsSections.ts +58 -0
  97. package/apps/agents-server/src/utils/dnsRecords/createServerDomainDnsRecordsSection.ts +48 -0
  98. package/apps/agents-server/src/utils/dnsRecords/dnsRecordGroups.ts +52 -0
  99. package/apps/agents-server/src/utils/dnsRecords/resolveDnsRecordBatchPlan.ts +47 -1
  100. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskSqlQuery.ts +41 -36
  101. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskFallbackRows.ts +3 -0
  102. package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskSqlRows.ts +2 -0
  103. package/apps/agents-server/src/utils/localChatRunner/parseLocalTeamConversations.ts +281 -0
  104. package/apps/agents-server/src/utils/localChatRunner/persistLocalTeamConversations.ts +71 -0
  105. package/apps/agents-server/src/utils/localChatRunner/prepareLocalTeamConversationWorkspace.ts +233 -0
  106. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +37 -6
  107. package/apps/agents-server/src/utils/serverManagement/createManagedServer/insertManagedServerRegistryRow.ts +2 -2
  108. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +7 -6
  109. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +5 -4
  110. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerMetadata.ts +3 -2
  111. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerUsers.ts +3 -2
  112. package/apps/agents-server/src/utils/serverManagement/deleteManagedServer.ts +2 -2
  113. package/apps/agents-server/src/utils/stalwart/createEmailDnsRecordsSection.ts +53 -0
  114. package/apps/agents-server/src/utils/userChat/UserChatRecord.ts +13 -0
  115. package/apps/agents-server/src/utils/userChat/UserChatSource.ts +14 -0
  116. package/apps/agents-server/src/utils/userChat/createUserChatSummary.ts +10 -2
  117. package/apps/agents-server/src/utils/userChat/finalizeUserChatJob.ts +3 -2
  118. package/apps/agents-server/src/utils/userChat/getUserChat.ts +16 -1
  119. package/apps/agents-server/src/utils/userChat/getUserChatForJobRunner.ts +31 -0
  120. package/apps/agents-server/src/utils/userChat/listUserChats.ts +113 -110
  121. package/apps/agents-server/src/utils/userChat/persistFrozenUserChat.ts +21 -6
  122. package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +2 -6
  123. package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +2 -6
  124. package/apps/agents-server/src/utils/userChat/teamMemberUserChatContext.ts +63 -0
  125. package/apps/agents-server/src/utils/userChat.ts +5 -1
  126. package/apps/agents-server/src/utils/userChatClient/cancelAgentUserTimeout.ts +2 -2
  127. package/apps/agents-server/src/utils/userChatClient/fetchAgentUserTimeouts.ts +2 -2
  128. package/apps/agents-server/src/utils/userChatClient.ts +9 -31
  129. package/apps/agents-server/src/utils/userChatTimeout/UserChatTimeoutRecord.ts +10 -2
  130. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/claimNextDueUserChatTimeout.ts +28 -25
  131. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/getAgentScopedUserChatTimeout.ts +8 -4
  132. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/listAgentUserChatTimeouts.ts +4 -1
  133. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/recoverExpiredRunningUserChatTimeouts.ts +3 -2
  134. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +53 -0
  135. package/esm/index.es.js +1801 -474
  136. package/esm/index.es.js.map +1 -1
  137. package/esm/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
  138. package/esm/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
  139. package/esm/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
  140. package/esm/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
  141. package/esm/scripts/run-codex-prompts/common/createCoderRunStepTracker.d.ts +48 -0
  142. package/esm/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
  143. package/esm/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
  144. package/esm/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
  145. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
  146. package/esm/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
  147. package/esm/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +43 -0
  148. package/esm/scripts/run-codex-prompts/prompts/formatCoderRunSteps.d.ts +6 -3
  149. package/esm/scripts/run-codex-prompts/prompts/isPromptSectionUnfinished.d.ts +8 -0
  150. package/esm/scripts/run-codex-prompts/prompts/markPromptDone.d.ts +1 -1
  151. package/esm/scripts/run-codex-prompts/prompts/markPromptInProgress.d.ts +27 -0
  152. package/esm/scripts/run-codex-prompts/prompts/resolvePromptStatusLine.d.ts +19 -0
  153. package/esm/scripts/run-codex-prompts/prompts/writePromptStatusLine.d.ts +9 -0
  154. package/esm/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +1 -1
  155. package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
  156. package/esm/scripts/run-codex-prompts/server/updatePromptSection.d.ts +1 -1
  157. package/esm/scripts/run-codex-prompts/testing/runPromptWithTestFeedback.d.ts +6 -0
  158. package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
  159. package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
  160. package/esm/scripts/verify-prompts/$orderPromptFiles.d.ts +9 -0
  161. package/esm/scripts/verify-prompts/VerifyPromptsOrder.d.ts +26 -0
  162. package/esm/scripts/verify-prompts/verify-prompts.d.ts +3 -2
  163. package/esm/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
  164. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
  165. package/esm/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
  166. package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
  167. package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +5 -3
  168. package/esm/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
  169. package/esm/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
  170. package/esm/src/cli/cli-commands/coder/verify.d.ts +1 -1
  171. package/{umd/src/cli/cli-commands/common/harness/$askForHarnessInstallationApproval.d.ts → esm/src/cli/cli-commands/common/npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
  172. package/{umd/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → esm/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
  173. package/esm/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
  174. package/esm/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
  175. package/esm/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
  176. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
  177. package/esm/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
  178. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
  179. package/esm/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
  180. package/esm/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
  181. package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
  182. package/esm/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
  183. package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
  184. package/esm/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
  185. package/esm/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
  186. package/esm/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
  187. package/esm/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
  188. package/esm/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
  189. package/esm/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
  190. package/esm/src/utils/misc/debounce.d.ts +4 -2
  191. package/esm/src/utils/misc/debounce.test.d.ts +1 -0
  192. package/esm/src/version.d.ts +1 -1
  193. package/package.json +1 -1
  194. package/src/avatars/renderAvatarVisualTerminalText.ts +249 -0
  195. package/src/avatars/types/AvatarVisualDefinition.ts +60 -0
  196. package/src/avatars/visuals/asciiOctopusAvatarVisual.ts +144 -22
  197. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +4 -4
  198. package/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.ts +1 -4
  199. package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +4 -17
  200. package/src/book-3.0/AgentTeamConversationWorkspace.ts +172 -0
  201. package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +56 -55
  202. package/src/book-components/Chat/Chat/Chat.module.css +1 -8
  203. package/src/book-components/Chat/Chat/ChatMessageMap.tsx +8 -4
  204. package/src/book-components/Chat/Chat/ChatProps.tsx +3 -2
  205. package/src/book-components/Chat/save/react/exports/chat-preview-2025-10-13 (1).jsx +95 -5
  206. package/src/book-components/Chat/utils/renderMarkdown.ts +306 -87
  207. package/src/cli/cli-commands/coder/add.ts +3 -3
  208. package/src/cli/cli-commands/coder/boilerplateCount.ts +1 -1
  209. package/src/cli/cli-commands/coder/generate-boilerplates.ts +27 -27
  210. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +5 -4
  211. package/src/cli/cli-commands/coder/init.ts +3 -3
  212. package/src/cli/cli-commands/coder/run.ts +10 -2
  213. package/src/cli/cli-commands/coder/verify.ts +29 -5
  214. package/src/cli/cli-commands/common/coderGitSyncCliOptions.ts +6 -2
  215. package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +2 -2
  216. package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +4 -4
  217. package/src/cli/cli-commands/common/harness/$resolveInstalledHarnessVersion.ts +2 -2
  218. package/src/cli/cli-commands/common/{harness/$askForHarnessInstallationApproval.ts → npm/$askForNpmPackageInstallationApproval.ts} +3 -3
  219. package/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.ts +49 -0
  220. package/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.ts +25 -0
  221. package/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.ts → npm/isNpmPackageVersionOutdated.ts} +6 -4
  222. package/src/cli/cli-commands/common/projectInitialization.ts +10 -1
  223. package/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.ts +73 -0
  224. package/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.ts +94 -0
  225. package/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.ts +223 -0
  226. package/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.ts +53 -0
  227. package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.ts +46 -0
  228. package/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.ts +32 -0
  229. package/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.ts +22 -0
  230. package/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.ts +47 -0
  231. package/src/commands/FORMAT/formatCommandParser.ts +2 -2
  232. package/src/llm-providers/openai/utils/buildToolInvocationScript.ts +21 -18
  233. package/src/other/templates/getTemplatesPipelineCollection.ts +813 -768
  234. package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +80 -27
  235. package/src/utils/agents/terminalAgentAvatarVisual.ts +31 -3
  236. package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +9 -109
  237. package/src/utils/ascii-art/createAnsiColorCode.ts +132 -0
  238. package/src/utils/misc/debounce.ts +26 -5
  239. package/src/version.ts +2 -2
  240. package/src/versions.txt +2 -0
  241. package/umd/index.umd.js +1800 -473
  242. package/umd/index.umd.js.map +1 -1
  243. package/umd/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +7 -1
  244. package/umd/scripts/run-agent-messages/messages/buildAgentTeamPromptSection.d.ts +12 -0
  245. package/umd/scripts/run-agent-messages/messages/finalizeAgentTeamConversationWorkspace.d.ts +16 -0
  246. package/umd/scripts/run-agent-messages/messages/loadAgentTeamConversationWorkspace.d.ts +6 -0
  247. package/umd/scripts/run-codex-prompts/common/createCoderRunStepTracker.d.ts +48 -0
  248. package/umd/scripts/run-codex-prompts/common/normalizeLineEndingsInChangedFiles.d.ts +2 -3
  249. package/umd/scripts/run-codex-prompts/git/coderCommitScope.d.ts +31 -0
  250. package/umd/scripts/run-codex-prompts/git/coderGitSync.d.ts +15 -2
  251. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +9 -3
  252. package/umd/scripts/run-codex-prompts/git/workingTreeChanges.d.ts +40 -0
  253. package/umd/scripts/run-codex-prompts/prompts/buildPromptStatusDetails.d.ts +43 -0
  254. package/umd/scripts/run-codex-prompts/prompts/formatCoderRunSteps.d.ts +6 -3
  255. package/umd/scripts/run-codex-prompts/prompts/isPromptSectionUnfinished.d.ts +8 -0
  256. package/umd/scripts/run-codex-prompts/prompts/markPromptDone.d.ts +1 -1
  257. package/umd/scripts/run-codex-prompts/prompts/markPromptInProgress.d.ts +27 -0
  258. package/umd/scripts/run-codex-prompts/prompts/resolvePromptStatusLine.d.ts +19 -0
  259. package/umd/scripts/run-codex-prompts/prompts/writePromptStatusLine.d.ts +9 -0
  260. package/umd/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +1 -1
  261. package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +1 -1
  262. package/umd/scripts/run-codex-prompts/server/updatePromptSection.d.ts +1 -1
  263. package/umd/scripts/run-codex-prompts/testing/runPromptWithTestFeedback.d.ts +6 -0
  264. package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +5 -5
  265. package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiTerminalFrameUpdate.d.ts +27 -0
  266. package/umd/scripts/verify-prompts/$orderPromptFiles.d.ts +9 -0
  267. package/umd/scripts/verify-prompts/VerifyPromptsOrder.d.ts +26 -0
  268. package/umd/scripts/verify-prompts/verify-prompts.d.ts +3 -2
  269. package/umd/src/avatars/renderAvatarVisualTerminalText.d.ts +80 -0
  270. package/umd/src/avatars/renderAvatarVisualTerminalText.test.d.ts +1 -0
  271. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +54 -0
  272. package/umd/src/book-3.0/AgentTeamConversationWorkspace.d.ts +85 -0
  273. package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +3 -2
  274. package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +5 -3
  275. package/umd/src/cli/cli-commands/coder/boilerplateCount.d.ts +1 -1
  276. package/umd/src/cli/cli-commands/coder/generate-boilerplates.d.ts +1 -1
  277. package/umd/src/cli/cli-commands/coder/verify.d.ts +1 -1
  278. package/{esm/src/cli/cli-commands/common/harness/$askForHarnessInstallationApproval.d.ts → umd/src/cli/cli-commands/common/npm/$askForNpmPackageInstallationApproval.d.ts} +2 -2
  279. package/{esm/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.d.ts → umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.d.ts} +2 -3
  280. package/umd/src/cli/cli-commands/common/npm/$resolveLatestNpmPackageVersion.test.d.ts +1 -0
  281. package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.d.ts +12 -0
  282. package/umd/src/cli/cli-commands/common/npm/extractNpmPackageVersionFromOutput.test.d.ts +1 -0
  283. package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.d.ts +9 -0
  284. package/umd/src/cli/cli-commands/common/npm/isNpmPackageVersionOutdated.test.d.ts +1 -0
  285. package/umd/src/cli/cli-commands/common/promptbook-cli/$checkPromptbookCliInstallations.d.ts +9 -0
  286. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.d.ts +14 -0
  287. package/umd/src/cli/cli-commands/common/promptbook-cli/$ensurePromptbookCliInstallations.test.d.ts +1 -0
  288. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.d.ts +12 -0
  289. package/umd/src/cli/cli-commands/common/promptbook-cli/$resolvePromptbookCliInstallations.test.d.ts +1 -0
  290. package/umd/src/cli/cli-commands/common/promptbook-cli/$updatePromptbookCliInstallation.d.ts +10 -0
  291. package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallation.d.ts +39 -0
  292. package/umd/src/cli/cli-commands/common/promptbook-cli/PromptbookCliInstallationStatus.d.ts +26 -0
  293. package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.d.ts +7 -0
  294. package/umd/src/cli/cli-commands/common/promptbook-cli/buildPromptbookCliInstallCommand.test.d.ts +1 -0
  295. package/umd/src/cli/cli-commands/common/promptbook-cli/formatPromptbookCliInstallationWarning.d.ts +7 -0
  296. package/umd/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.d.ts +3 -3
  297. package/umd/src/utils/agents/terminalAgentAvatarVisual.d.ts +5 -2
  298. package/umd/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +6 -0
  299. package/umd/src/utils/ascii-art/createAnsiColorCode.d.ts +46 -0
  300. package/umd/src/utils/misc/debounce.d.ts +4 -2
  301. package/umd/src/utils/misc/debounce.test.d.ts +1 -0
  302. package/umd/src/version.d.ts +1 -1
  303. package/apps/agents-server/scripts/ignore-kill-eperm.js +0 -31
  304. package/apps/agents-server/src/app/agents/[agentName]/api/timeouts/actions/route.ts +0 -103
  305. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +0 -43
  306. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsEditDialog.tsx +0 -98
  307. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +0 -75
  308. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsHeader.tsx +0 -53
  309. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsSummaryMetrics.tsx +0 -70
  310. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +0 -58
  311. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +0 -242
  312. package/apps/agents-server/src/app/agents/[agentName]/timeouts/loading.tsx +0 -15
  313. package/apps/agents-server/src/app/agents/[agentName]/timeouts/page.tsx +0 -28
  314. package/apps/agents-server/src/app/agents/[agentName]/timeouts/useAgentTimeoutsClientState.ts +0 -769
  315. package/apps/agents-server/src/components/AgentProjectDnsInstructions/AgentProjectDnsInstructions.tsx +0 -182
  316. package/apps/agents-server/src/utils/userChatClient/runAgentUserTimeoutBulkAction.ts +0 -24
  317. package/apps/agents-server/src/utils/userChatClient/updateAgentUserTimeout.ts +0 -25
  318. package/esm/scripts/run-codex-prompts/prompts/replacePromptTodoStatusLine.d.ts +0 -7
  319. package/esm/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
  320. package/esm/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
  321. package/src/cli/cli-commands/common/harness/$resolveLatestHarnessVersion.ts +0 -34
  322. package/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.ts +0 -28
  323. package/umd/scripts/run-codex-prompts/prompts/replacePromptTodoStatusLine.d.ts +0 -7
  324. package/umd/src/cli/cli-commands/common/harness/extractHarnessVersionFromOutput.d.ts +0 -11
  325. package/umd/src/cli/cli-commands/common/harness/isHarnessVersionOutdated.d.ts +0 -9
  326. /package/esm/src/{cli/cli-commands/common/harness/extractHarnessVersionFromOutput.test.d.ts → avatars/renderAvatarVisualTerminalText.test.d.ts} +0 -0
  327. /package/esm/src/cli/cli-commands/common/{harness/isHarnessVersionOutdated.test.d.ts → npm/$resolveLatestNpmPackageVersion.test.d.ts} +0 -0
  328. /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
  329. /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
@@ -267,14 +267,46 @@ const DETAILS_PLACEHOLDER_WRAPPED_REGEX = new RegExp(`<p>\\s*(${DETAILS_PLACEHOL
267
267
  const INLINE_REFERENCE_REGEX = /\[\[([^\]\r\n]+?)\]\]/g;
268
268
 
269
269
  /**
270
- * Pattern matching ordinary markdown links that can be promoted to inline reference chips.
270
+ * Prefix for INLINE REFERENCE PLACEHOLDER.
271
271
  *
272
- * Images are intentionally captured separately and left unchanged by the replacement helper.
272
+ * @private utility of `renderMarkdown`
273
+ */
274
+ const INLINE_REFERENCE_PLACEHOLDER_PREFIX = '@@PROMPTBOOK_INLINE_REFERENCE_PLACEHOLDER__';
275
+
276
+ /**
277
+ * Pattern matching INLINE REFERENCE PLACEHOLDER.
278
+ *
279
+ * @private utility of `renderMarkdown`
280
+ */
281
+ const INLINE_REFERENCE_PLACEHOLDER_REGEX = new RegExp(`${INLINE_REFERENCE_PLACEHOLDER_PREFIX}(\\d+)__`, 'g');
282
+
283
+ /**
284
+ * Pattern matching markdown links and images together with their raw target.
285
+ *
286
+ * @private utility of `renderMarkdown`
287
+ */
288
+ const MARKDOWN_LINK_REGEX = /(!?)\[([^\]\r\n]*)\]\(\s*(<[^>\r\n]*>|[^()\s]+)(?:\s+(?:"[^"]*"|'[^']*'))?\s*\)/g;
289
+
290
+ /**
291
+ * Pattern matching bare `http(s)` URLs written directly into markdown text.
292
+ *
293
+ * @private utility of `renderMarkdown`
294
+ */
295
+ const BARE_URL_REGEX = /(^|\s)(https?:\/\/[^\s<>()[\]"']+)/g;
296
+
297
+ /**
298
+ * Sentence punctuation which trails a bare URL instead of belonging to it.
273
299
  *
274
300
  * @private utility of `renderMarkdown`
275
301
  */
276
- const MARKDOWN_INLINE_REFERENCE_LINK_REGEX =
277
- /(!?)\[([^\]\r\n]*)\]\(\s*(<[^>\r\n]+>|[^)\s]+)(?:\s+(?:"[^"\r\n]*"|'[^'\r\n]*'|\([^)]*\)))?\s*\)/g;
302
+ const BARE_URL_TRAILING_PUNCTUATION_REGEX = /[.,;:!?]+$/;
303
+
304
+ /**
305
+ * Pattern splitting one URL into its scheme, host and remaining part.
306
+ *
307
+ * @private utility of `renderMarkdown`
308
+ */
309
+ const ABSOLUTE_URL_REGEX = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)(.*)$/i;
278
310
 
279
311
  /**
280
312
  * Markdown patterns that are strong enough to identify content as markdown.
@@ -344,10 +376,12 @@ export type MarkdownInlineReference = {
344
376
  readonly href: string;
345
377
 
346
378
  /**
347
- * Markdown link destination prefixes that should render as this reference as well.
379
+ * Optional URL prefixes which also identify this reference in the authored markdown.
348
380
  *
349
- * This supports legacy links such as an Agents Server project file URL while keeping
350
- * `reference` as the canonical `[[project]]` token.
381
+ * A markdown link or a bare URL pointing to one of these prefixes is rendered as the same chip
382
+ * as the `[[reference]]` token. Both absolute URLs (for example `https://project.example.com`)
383
+ * and application paths (for example `/agents/agent/projects/website`) are supported; a path
384
+ * prefix matches on any host so that both relative and absolute links are recognized.
351
385
  */
352
386
  readonly sourceHrefPrefixes?: ReadonlyArray<string>;
353
387
 
@@ -696,12 +730,11 @@ const CHAT_MARKDOWN_CONVERTER = createChatMarkdownConverter();
696
730
  * outer `<details>` and optional `<summary>` markup untouched.
697
731
  *
698
732
  * @param detailsBlock - Raw `<details>...</details>` HTML captured from markdown.
699
- * @param options - Markdown rendering options to reuse for the details body.
700
733
  * @returns `<details>` HTML whose body has been converted from markdown to HTML.
701
734
  *
702
735
  * @private utility of `renderMarkdown`
703
736
  */
704
- function renderDetailsBlock(detailsBlock: string, options?: RenderMarkdownOptions): string_html {
737
+ function renderDetailsBlock(detailsBlock: string): string_html {
705
738
  const openTagMatch = detailsBlock.match(/^<details\b[^>]*>/i);
706
739
  const closeTagMatch = detailsBlock.match(/<\/details\s*>$/i);
707
740
 
@@ -715,7 +748,7 @@ function renderDetailsBlock(detailsBlock: string, options?: RenderMarkdownOption
715
748
  const summaryMatch = innerContent.match(/^(\s*<summary\b[^>]*>[\s\S]*?<\/summary\s*>)([\s\S]*)$/i);
716
749
  const summaryHtml = summaryMatch?.[1] ?? '';
717
750
  const bodyMarkdown = (summaryMatch?.[2] ?? innerContent) as string_markdown;
718
- const renderedBody = renderMarkdown(bodyMarkdown, options);
751
+ const renderedBody = renderMarkdown(bodyMarkdown);
719
752
 
720
753
  return `${openTag}${summaryHtml}${renderedBody}${closeTag}` as string_html;
721
754
  }
@@ -759,18 +792,17 @@ function maskMarkdownCodeSegments(markdown: string_markdown): MaskedCodeSegments
759
792
  * processes their content.
760
793
  *
761
794
  * @param markdown - Markdown text that may contain raw HTML `<details>` blocks.
762
- * @param options - Markdown rendering options to reuse for the details body.
763
795
  * @returns Masked markdown and a restore helper that returns `string_html`.
764
796
  *
765
797
  * @private utility of `renderMarkdown`
766
798
  */
767
- function maskDetailsBlocks(markdown: string_markdown, options?: RenderMarkdownOptions): MaskedDetailsBlocksResult {
799
+ function maskDetailsBlocks(markdown: string_markdown): MaskedDetailsBlocksResult {
768
800
  const blocks: string_html[] = [];
769
801
 
770
802
  DETAILS_BLOCK_REGEX.lastIndex = 0;
771
803
  const masked = markdown.replace(DETAILS_BLOCK_REGEX, (match) => {
772
804
  const placeholder = `${DETAILS_PLACEHOLDER_PREFIX}${blocks.length}__`;
773
- blocks.push(renderDetailsBlock(match, options));
805
+ blocks.push(renderDetailsBlock(match));
774
806
  return placeholder;
775
807
  }) as string_markdown;
776
808
 
@@ -885,90 +917,181 @@ function createMarkdownInlineReferenceByKey(
885
917
  }
886
918
 
887
919
  /**
888
- * Returns whether a href starts with a configured source href prefix.
920
+ * Comparable parts of one URL used to recognize inline references written as links or bare URLs.
889
921
  *
890
- * @param href - Markdown link destination.
891
- * @param sourceHrefPrefix - Configured source href prefix.
892
- * @returns Whether the href belongs to the source prefix.
922
+ * @private utility of `renderMarkdown`
923
+ */
924
+ type ComparableUrlParts = {
925
+ /**
926
+ * Lowercase host of an absolute URL, or an empty string for a host-independent application path.
927
+ */
928
+ readonly host: string;
929
+
930
+ /**
931
+ * Lowercase decoded path without query, hash and trailing slashes.
932
+ */
933
+ readonly path: string;
934
+ };
935
+
936
+ /**
937
+ * One inline reference together with its comparable source URL prefixes.
893
938
  *
894
939
  * @private utility of `renderMarkdown`
895
940
  */
896
- function doesHrefStartWithSourceHrefPrefix(href: string, sourceHrefPrefix: string): boolean {
897
- if (href === sourceHrefPrefix) {
898
- return true;
899
- }
941
+ type MarkdownInlineReferenceHrefMatcher = {
942
+ /**
943
+ * Reference rendered when one of its source prefixes matches.
944
+ */
945
+ readonly reference: MarkdownInlineReference;
900
946
 
901
- const normalizedSourceHrefPrefix = sourceHrefPrefix.endsWith('/') ? sourceHrefPrefix : `${sourceHrefPrefix}/`;
947
+ /**
948
+ * Comparable form of the reference source URL prefixes.
949
+ */
950
+ readonly sourceHrefPrefixes: ReadonlyArray<ComparableUrlParts>;
951
+ };
902
952
 
903
- return href.startsWith(normalizedSourceHrefPrefix);
904
- }
953
+ /**
954
+ * Renders one matched reference and returns the placeholder standing for it.
955
+ *
956
+ * @private utility of `renderMarkdown`
957
+ */
958
+ type CreateMarkdownInlineReferencePlaceholder = (reference: MarkdownInlineReference) => string;
905
959
 
906
960
  /**
907
- * Returns a comparable path for an absolute href when the configured source prefix is relative.
961
+ * Decodes percent-encoded characters without failing on malformed input.
908
962
  *
909
- * @param href - Href to normalize.
910
- * @returns Absolute URL pathname or the original href when it is relative/invalid.
963
+ * @param value - Raw URL part.
964
+ * @returns Decoded value, or the original value when it cannot be decoded.
911
965
  *
912
966
  * @private utility of `renderMarkdown`
913
967
  */
914
- function resolveAbsoluteHrefPath(href: string): string {
968
+ function decodeUrlPartSafely(value: string): string {
915
969
  try {
916
- return new URL(href).pathname;
970
+ return decodeURIComponent(value);
917
971
  } catch {
918
- return href;
972
+ return value;
919
973
  }
920
974
  }
921
975
 
922
976
  /**
923
- * Returns whether one markdown link destination belongs to one inline reference.
977
+ * Normalizes one URL path so that encoding, casing and trailing slashes do not break matching.
924
978
  *
925
- * Relative project paths also match absolute URLs on the current server, which keeps
926
- * server-generated relative links and model-generated absolute links consistent.
979
+ * @param path - Raw path including an optional query and hash.
980
+ * @returns Comparable path.
927
981
  *
928
- * @param reference - Candidate inline reference.
929
- * @param href - Markdown link destination.
930
- * @returns Whether the href should render as the reference chip.
982
+ * @private utility of `renderMarkdown`
983
+ */
984
+ function normalizeUrlPathForComparison(path: string): string {
985
+ const pathWithoutQuery = path.split(/[?#]/, 1)[0] || '';
986
+
987
+ return decodeUrlPartSafely(pathWithoutQuery).toLowerCase().replace(/\/+$/, '');
988
+ }
989
+
990
+ /**
991
+ * Splits one absolute URL or application path into its comparable parts.
992
+ *
993
+ * @param url - Raw link target written in markdown.
994
+ * @returns Comparable URL parts, or `null` when the value cannot address a reference.
931
995
  *
932
996
  * @private utility of `renderMarkdown`
933
997
  */
934
- function doesMarkdownInlineReferenceMatchHref(reference: MarkdownInlineReference, href: string): boolean {
935
- const normalizedHref = href.trim();
998
+ function createComparableUrlParts(url: string): ComparableUrlParts | null {
999
+ const trimmedUrl = url
1000
+ .trim()
1001
+ .replace(/^<([\s\S]*)>$/, '$1')
1002
+ .trim();
936
1003
 
937
- return (reference.sourceHrefPrefixes || []).some((sourceHrefPrefix) => {
938
- const normalizedSourceHrefPrefix = sourceHrefPrefix.trim();
939
- if (!normalizedSourceHrefPrefix) {
940
- return false;
941
- }
1004
+ if (trimmedUrl === '') {
1005
+ return null;
1006
+ }
942
1007
 
943
- if (doesHrefStartWithSourceHrefPrefix(normalizedHref, normalizedSourceHrefPrefix)) {
944
- return true;
945
- }
1008
+ const absoluteUrlMatch = trimmedUrl.match(ABSOLUTE_URL_REGEX);
1009
+ if (absoluteUrlMatch) {
1010
+ return {
1011
+ host: absoluteUrlMatch[1]!.toLowerCase(),
1012
+ path: normalizeUrlPathForComparison(absoluteUrlMatch[2] || ''),
1013
+ };
1014
+ }
946
1015
 
947
- const isRelativeSourceHrefPrefix = !/^[a-z][a-z0-9+.-]*:/i.test(normalizedSourceHrefPrefix);
948
- const isAbsoluteHref = /^[a-z][a-z0-9+.-]*:/i.test(normalizedHref);
1016
+ if (!trimmedUrl.startsWith('/')) {
1017
+ return null;
1018
+ }
949
1019
 
950
- return (
951
- isRelativeSourceHrefPrefix &&
952
- isAbsoluteHref &&
953
- doesHrefStartWithSourceHrefPrefix(resolveAbsoluteHrefPath(normalizedHref), normalizedSourceHrefPrefix)
954
- );
955
- });
1020
+ return {
1021
+ host: '',
1022
+ path: normalizeUrlPathForComparison(trimmedUrl),
1023
+ };
956
1024
  }
957
1025
 
958
1026
  /**
959
- * Finds the inline reference represented by a markdown link destination.
1027
+ * Returns whether one URL points into one reference source prefix.
1028
+ *
1029
+ * @param url - Comparable parts of the link target written in markdown.
1030
+ * @param prefix - Comparable parts of one reference source prefix.
1031
+ * @returns `true` when the URL belongs to the reference.
960
1032
  *
961
- * @param references - Inline references available to the markdown renderer.
962
- * @param href - Markdown link destination.
963
- * @returns Matching reference or `undefined` when the href is unrelated.
1033
+ * @private utility of `renderMarkdown`
1034
+ */
1035
+ function isUrlWithinReferencePrefix(url: ComparableUrlParts, prefix: ComparableUrlParts): boolean {
1036
+ if (prefix.host !== '' && prefix.host !== url.host) {
1037
+ return false;
1038
+ }
1039
+
1040
+ if (prefix.path === '') {
1041
+ // Note: A prefix without a path covers the whole host, a prefix without both would cover everything
1042
+ return prefix.host !== '';
1043
+ }
1044
+
1045
+ return url.path === prefix.path || url.path.startsWith(`${prefix.path}/`);
1046
+ }
1047
+
1048
+ /**
1049
+ * Builds matchers for references which can also be written as a markdown link or a bare URL.
1050
+ *
1051
+ * @param references - References available to this markdown render.
1052
+ * @returns Matchers of references declaring at least one usable source prefix.
964
1053
  *
965
1054
  * @private utility of `renderMarkdown`
966
1055
  */
967
- function findMarkdownInlineReferenceByHref(
1056
+ function createMarkdownInlineReferenceHrefMatchers(
968
1057
  references: ReadonlyArray<MarkdownInlineReference>,
1058
+ ): ReadonlyArray<MarkdownInlineReferenceHrefMatcher> {
1059
+ return references
1060
+ .map((reference) => ({
1061
+ reference,
1062
+ sourceHrefPrefixes: (reference.sourceHrefPrefixes || [])
1063
+ .map((sourceHrefPrefix) => createComparableUrlParts(sourceHrefPrefix))
1064
+ .filter((sourceHrefPrefix): sourceHrefPrefix is ComparableUrlParts => sourceHrefPrefix !== null),
1065
+ }))
1066
+ .filter((matcher) => matcher.sourceHrefPrefixes.length !== 0);
1067
+ }
1068
+
1069
+ /**
1070
+ * Finds the reference which owns one link target.
1071
+ *
1072
+ * @param href - Raw link target written in markdown.
1073
+ * @param matchers - Reference matchers of this markdown render.
1074
+ * @returns Matching reference or `null`.
1075
+ *
1076
+ * @private utility of `renderMarkdown`
1077
+ */
1078
+ function findMarkdownInlineReferenceForHref(
969
1079
  href: string,
970
- ): MarkdownInlineReference | undefined {
971
- return references.find((reference) => doesMarkdownInlineReferenceMatchHref(reference, href));
1080
+ matchers: ReadonlyArray<MarkdownInlineReferenceHrefMatcher>,
1081
+ ): MarkdownInlineReference | null {
1082
+ const urlParts = createComparableUrlParts(href);
1083
+
1084
+ if (urlParts === null) {
1085
+ return null;
1086
+ }
1087
+
1088
+ const matcher = matchers.find((candidateMatcher) =>
1089
+ candidateMatcher.sourceHrefPrefixes.some((sourceHrefPrefix) =>
1090
+ isUrlWithinReferencePrefix(urlParts, sourceHrefPrefix),
1091
+ ),
1092
+ );
1093
+
1094
+ return matcher?.reference || null;
972
1095
  }
973
1096
 
974
1097
  /**
@@ -1042,11 +1165,113 @@ function renderMarkdownInlineReferenceMenuOptionHtml(option: MarkdownInlineRefer
1042
1165
  }
1043
1166
 
1044
1167
  /**
1045
- * Replaces known `[[reference]]` tokens with link chips while leaving unknown tokens unchanged.
1168
+ * Replaces known `[[reference]]` tokens with chip placeholders while leaving unknown tokens unchanged.
1169
+ *
1170
+ * @param markdown - Markdown content after code masking.
1171
+ * @param references - References available to this markdown render.
1172
+ * @param createPlaceholder - Renders one matched reference into a placeholder.
1173
+ * @returns Markdown with known reference tokens replaced by placeholders.
1174
+ *
1175
+ * @private utility of `renderMarkdown`
1176
+ */
1177
+ function replaceMarkdownInlineReferenceTokens(
1178
+ markdown: string_markdown,
1179
+ references: ReadonlyArray<MarkdownInlineReference>,
1180
+ createPlaceholder: CreateMarkdownInlineReferencePlaceholder,
1181
+ ): string_markdown {
1182
+ const referenceByKey = createMarkdownInlineReferenceByKey(references);
1183
+
1184
+ if (referenceByKey.size === 0) {
1185
+ return markdown;
1186
+ }
1187
+
1188
+ return markdown.replace(INLINE_REFERENCE_REGEX, (match, rawReference: string) => {
1189
+ const reference = referenceByKey.get(normalizeMarkdownInlineReferenceKey(rawReference));
1190
+
1191
+ return reference ? createPlaceholder(reference) : match;
1192
+ }) as string_markdown;
1193
+ }
1194
+
1195
+ /**
1196
+ * Replaces markdown links pointing to a known reference with chip placeholders.
1197
+ *
1198
+ * Images keep their original markdown so that pictures served by a reference stay visible.
1199
+ *
1200
+ * @param markdown - Markdown content after code masking.
1201
+ * @param matchers - Reference matchers of this markdown render.
1202
+ * @param createPlaceholder - Renders one matched reference into a placeholder.
1203
+ * @returns Markdown with known reference links replaced by placeholders.
1204
+ *
1205
+ * @private utility of `renderMarkdown`
1206
+ */
1207
+ function replaceMarkdownInlineReferenceLinks(
1208
+ markdown: string_markdown,
1209
+ matchers: ReadonlyArray<MarkdownInlineReferenceHrefMatcher>,
1210
+ createPlaceholder: CreateMarkdownInlineReferencePlaceholder,
1211
+ ): string_markdown {
1212
+ return markdown.replace(MARKDOWN_LINK_REGEX, (match, imageMarker: string, _label: string, rawHref: string) => {
1213
+ if (imageMarker !== '') {
1214
+ return match;
1215
+ }
1216
+
1217
+ const reference = findMarkdownInlineReferenceForHref(rawHref, matchers);
1218
+
1219
+ return reference ? createPlaceholder(reference) : match;
1220
+ }) as string_markdown;
1221
+ }
1222
+
1223
+ /**
1224
+ * Replaces bare URLs of known references with chip placeholders.
1225
+ *
1226
+ * @param markdown - Markdown content after reference links were replaced.
1227
+ * @param matchers - Reference matchers of this markdown render.
1228
+ * @param createPlaceholder - Renders one matched reference into a placeholder.
1229
+ * @returns Markdown with known reference URLs replaced by placeholders.
1230
+ *
1231
+ * @private utility of `renderMarkdown`
1232
+ */
1233
+ function replaceMarkdownInlineReferenceBareUrls(
1234
+ markdown: string_markdown,
1235
+ matchers: ReadonlyArray<MarkdownInlineReferenceHrefMatcher>,
1236
+ createPlaceholder: CreateMarkdownInlineReferencePlaceholder,
1237
+ ): string_markdown {
1238
+ return markdown.replace(BARE_URL_REGEX, (match, leadingWhitespace: string, rawUrl: string) => {
1239
+ const trailingPunctuation = rawUrl.match(BARE_URL_TRAILING_PUNCTUATION_REGEX)?.[0] || '';
1240
+ const url = rawUrl.slice(0, rawUrl.length - trailingPunctuation.length);
1241
+ const reference = findMarkdownInlineReferenceForHref(url, matchers);
1242
+
1243
+ return reference ? `${leadingWhitespace}${createPlaceholder(reference)}${trailingPunctuation}` : match;
1244
+ }) as string_markdown;
1245
+ }
1246
+
1247
+ /**
1248
+ * Restores chips which replaced references during the reference passes.
1249
+ *
1250
+ * @param markdown - Markdown containing reference placeholders.
1251
+ * @param renderedChips - Chip HTML indexed by placeholder number.
1252
+ * @returns Markdown with inline references rendered as HTML chips.
1253
+ *
1254
+ * @private utility of `renderMarkdown`
1255
+ */
1256
+ function restoreMarkdownInlineReferenceChips(
1257
+ markdown: string_markdown,
1258
+ renderedChips: ReadonlyArray<string>,
1259
+ ): string_markdown {
1260
+ return markdown.replace(
1261
+ INLINE_REFERENCE_PLACEHOLDER_REGEX,
1262
+ (_match, index) => renderedChips[Number(index)] ?? '',
1263
+ ) as string_markdown;
1264
+ }
1265
+
1266
+ /**
1267
+ * Replaces known `[[reference]]` tokens, reference links and bare reference URLs with link chips.
1268
+ *
1269
+ * Every matched reference is first replaced by a placeholder so that the rendered chip HTML is
1270
+ * never processed again by a later pass.
1046
1271
  *
1047
1272
  * @param markdown - Markdown content after code masking.
1048
1273
  * @param options - Markdown render options.
1049
- * @returns Markdown with known inline references rendered as HTML anchors.
1274
+ * @returns Markdown with known inline references rendered as HTML chips.
1050
1275
  *
1051
1276
  * @private utility of `renderMarkdown`
1052
1277
  */
@@ -1058,33 +1283,27 @@ function applyMarkdownInlineReferences(markdown: string_markdown, options?: Rend
1058
1283
  return markdown;
1059
1284
  }
1060
1285
 
1061
- const referenceByKey = createMarkdownInlineReferenceByKey(references);
1062
- if (referenceByKey.size === 0) {
1063
- return markdown;
1064
- }
1065
-
1066
- const markdownWithInlineReferenceTokens = markdown.replace(
1067
- INLINE_REFERENCE_REGEX,
1068
- (match, rawReference: string) => {
1069
- const reference = referenceByKey.get(normalizeMarkdownInlineReferenceKey(rawReference));
1286
+ const renderedChips: Array<string> = [];
1287
+ const createPlaceholder: CreateMarkdownInlineReferencePlaceholder = (reference) => {
1288
+ const placeholder = `${INLINE_REFERENCE_PLACEHOLDER_PREFIX}${renderedChips.length}__`;
1289
+ renderedChips.push(renderMarkdownInlineReferenceHtml(reference, className));
1070
1290
 
1071
- return reference ? renderMarkdownInlineReferenceHtml(reference, className) : match;
1072
- },
1073
- );
1291
+ return placeholder;
1292
+ };
1074
1293
 
1075
- return markdownWithInlineReferenceTokens.replace(
1076
- MARKDOWN_INLINE_REFERENCE_LINK_REGEX,
1077
- (match, imageMarker: string, _linkLabel: string, rawHref: string) => {
1078
- if (imageMarker) {
1079
- return match;
1080
- }
1294
+ const hrefMatchers = createMarkdownInlineReferenceHrefMatchers(references);
1295
+ let referencedMarkdown = replaceMarkdownInlineReferenceTokens(markdown, references, createPlaceholder);
1081
1296
 
1082
- const href = rawHref.replace(/^<|>$/g, '');
1083
- const reference = findMarkdownInlineReferenceByHref(references, href);
1297
+ if (hrefMatchers.length !== 0) {
1298
+ referencedMarkdown = replaceMarkdownInlineReferenceLinks(referencedMarkdown, hrefMatchers, createPlaceholder);
1299
+ referencedMarkdown = replaceMarkdownInlineReferenceBareUrls(
1300
+ referencedMarkdown,
1301
+ hrefMatchers,
1302
+ createPlaceholder,
1303
+ );
1304
+ }
1084
1305
 
1085
- return reference ? renderMarkdownInlineReferenceHtml(reference, className) : match;
1086
- },
1087
- ) as string_markdown;
1306
+ return restoreMarkdownInlineReferenceChips(referencedMarkdown, renderedChips);
1088
1307
  }
1089
1308
 
1090
1309
  /**
@@ -1129,7 +1348,7 @@ export function renderMarkdown(markdown: string_markdown, options?: RenderMarkdo
1129
1348
 
1130
1349
  try {
1131
1350
  const normalizedMarkdown = normalizeMarkdownSublists(markdown);
1132
- const { masked: maskedMarkdown, restore: restoreDetails } = maskDetailsBlocks(normalizedMarkdown, options);
1351
+ const { masked: maskedMarkdown, restore: restoreDetails } = maskDetailsBlocks(normalizedMarkdown);
1133
1352
  const { masked: codeMaskedMarkdown, restore: restoreCode } = maskMarkdownCodeSegments(maskedMarkdown);
1134
1353
  const referencedMarkdown = applyMarkdownInlineReferences(codeMaskedMarkdown, options);
1135
1354
  const inlineReferenceMarkdown = restoreCode(referencedMarkdown);
@@ -102,11 +102,11 @@ export function $initializeCoderAddCommand(program: Program): $side_effect {
102
102
  const description = await resolveCoderPromptDescription(descriptionArgument);
103
103
 
104
104
  // Note: Import the git synchronization dynamically to keep the CLI fast for runs without `--commit`
105
- const { $commitCoderChanges, $pullCoderChanges } = await import(
105
+ const { $commitCoderChanges, $startCoderGitSync } = await import(
106
106
  '../../../../scripts/run-codex-prompts/git/coderGitSync'
107
107
  );
108
108
 
109
- await $pullCoderChanges({ gitSync, projectPath });
109
+ const commitScope = await $startCoderGitSync({ gitSync, projectPath });
110
110
 
111
111
  const { /* filePath,*/ emojiTag } = await addCoderPrompt({
112
112
  projectPath,
@@ -117,7 +117,7 @@ export function $initializeCoderAddCommand(program: Program): $side_effect {
117
117
 
118
118
  await $commitCoderChanges({
119
119
  gitSync,
120
- projectPath,
120
+ commitScope,
121
121
  commitMessage: `${emojiTag} Add prompt`,
122
122
  });
123
123
  }),
@@ -29,7 +29,7 @@ export type BoilerplateCount = {
29
29
  * Number of prompts written into each generated file.
30
30
  *
31
31
  * Note: More than one prompt per file is an advanced option - each prompt is one separate
32
- * coding task separated by `---` and tagged with its own fresh emoji tag.
32
+ * coding task separated by `---`, with all prompts in the file sharing its fresh emoji tag.
33
33
  */
34
34
  readonly promptsPerFileCount: number;
35
35
  };