@agent-native/core 0.103.0 → 0.104.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (572) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +36 -0
  3. package/corpus/core/package.json +9 -2
  4. package/corpus/core/src/agent/engine/credential-errors.ts +2 -2
  5. package/corpus/core/src/agent/production-agent.ts +30 -0
  6. package/corpus/core/src/agent/run-store.ts +12 -2
  7. package/corpus/core/src/cli/create.ts +1 -0
  8. package/corpus/core/src/cli/skills-content/visual-plan-skill.ts +30 -11
  9. package/corpus/core/src/cli/templates-meta.ts +4 -3
  10. package/corpus/core/src/client/AgentAskPopover.tsx +89 -0
  11. package/corpus/core/src/client/AgentChatHome.tsx +4 -0
  12. package/corpus/core/src/client/AgentPanel.tsx +321 -223
  13. package/corpus/core/src/client/AssistantChat.tsx +6 -10
  14. package/corpus/core/src/client/MultiTabAssistantChat.tsx +53 -372
  15. package/corpus/core/src/client/agent-chat-adapter.ts +13 -1
  16. package/corpus/core/src/client/agent-page/AgentContextTab.tsx +133 -149
  17. package/corpus/core/src/client/agent-page/AgentEmptyState.tsx +44 -0
  18. package/corpus/core/src/client/agent-page/AgentJobsTab.tsx +153 -82
  19. package/corpus/core/src/client/agent-page/AgentTabFrame.tsx +39 -0
  20. package/corpus/core/src/client/agent-page/AgentTabsPage.tsx +368 -356
  21. package/corpus/core/src/client/agent-page/types.ts +1 -1
  22. package/corpus/core/src/client/analytics.ts +51 -5
  23. package/corpus/core/src/client/chat/run-recovery.tsx +12 -4
  24. package/corpus/core/src/client/composer/PromptComposer.tsx +5 -15
  25. package/corpus/core/src/client/composer/TiptapComposer.tsx +32 -3
  26. package/corpus/core/src/client/dynamic-suggestions.ts +3 -3
  27. package/corpus/core/src/client/index.ts +16 -1
  28. package/corpus/core/src/client/resources/ResourceTree.tsx +249 -38
  29. package/corpus/core/src/client/resources/ResourcesPanel.tsx +307 -140
  30. package/corpus/core/src/client/session-replay.ts +158 -5
  31. package/corpus/core/src/client/settings/AutomationsSection.tsx +30 -10
  32. package/corpus/core/src/client/settings/SettingsPanel.tsx +3 -2
  33. package/corpus/core/src/client/settings/SettingsTabsPage.tsx +2 -0
  34. package/corpus/core/src/client/settings/agent-settings-search.ts +2 -2
  35. package/corpus/core/src/client/use-chat-threads.ts +2 -0
  36. package/corpus/core/src/connections/catalog.ts +49 -7
  37. package/corpus/core/src/db/index.ts +6 -1
  38. package/corpus/core/src/extensions/actions.ts +106 -16
  39. package/corpus/core/src/extensions/content-patch.ts +22 -0
  40. package/corpus/core/src/extensions/routes.ts +18 -0
  41. package/corpus/core/src/extensions/store.ts +8 -0
  42. package/corpus/core/src/index.ts +3 -0
  43. package/corpus/core/src/ingestion/docx.ts +158 -0
  44. package/corpus/core/src/ingestion/figma-node-to-html.ts +1860 -0
  45. package/corpus/core/src/ingestion/figma.ts +548 -0
  46. package/corpus/core/src/ingestion/index.ts +107 -0
  47. package/corpus/core/src/ingestion/media.ts +264 -0
  48. package/corpus/core/src/ingestion/notion.ts +121 -0
  49. package/corpus/core/src/ingestion/office.ts +214 -0
  50. package/corpus/core/src/ingestion/orchestration.ts +160 -0
  51. package/corpus/core/src/ingestion/pptx.ts +333 -0
  52. package/corpus/core/src/ingestion/selection.ts +81 -0
  53. package/corpus/core/src/ingestion/website.ts +151 -0
  54. package/corpus/core/src/integrations/plugin.ts +45 -37
  55. package/corpus/core/src/localization/default-messages.ts +35 -12
  56. package/corpus/core/src/observability/hosted-model-experiment.ts +118 -0
  57. package/corpus/core/src/observability/traces.ts +5 -3
  58. package/corpus/core/src/provider-api/index.ts +452 -8
  59. package/corpus/core/src/scripts/agent-engines/list-agent-engines.ts +18 -1
  60. package/corpus/core/src/search-utils/index.ts +112 -0
  61. package/corpus/core/src/secrets/register-framework-secrets.ts +61 -0
  62. package/corpus/core/src/server/action-discovery.ts +33 -8
  63. package/corpus/core/src/server/agent-chat/framework-prompts.ts +2 -2
  64. package/corpus/core/src/server/agent-chat/prompt-resources.ts +144 -0
  65. package/corpus/core/src/server/agent-chat-plugin.ts +6 -0
  66. package/corpus/core/src/server/core-routes-plugin.ts +12 -0
  67. package/corpus/core/src/server/index.ts +30 -0
  68. package/corpus/core/src/server/workspace-provider-oauth.ts +583 -0
  69. package/corpus/core/src/styles/agent-native.css +9 -0
  70. package/corpus/core/src/templates/default/app/i18n/en-US.ts +3 -3
  71. package/corpus/core/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
  72. package/corpus/core/src/templates/workspace-root/.env.example +12 -0
  73. package/corpus/core/src/vite/client.ts +2 -0
  74. package/corpus/core/src/workspace-connections/index.ts +6 -0
  75. package/corpus/core/src/workspace-connections/lifecycle.ts +43 -0
  76. package/corpus/core/src/workspace-connections/store.ts +16 -0
  77. package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +46 -3
  78. package/corpus/templates/analytics/AGENTS.md +9 -0
  79. package/corpus/templates/analytics/actions/dashboard-mutation-api.ts +120 -6
  80. package/corpus/templates/analytics/actions/mutate-dashboard.ts +92 -30
  81. package/corpus/templates/analytics/actions/update-dashboard.ts +5 -5
  82. package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +313 -220
  83. package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +2 -2
  84. package/corpus/templates/analytics/app/components/layout/Layout.tsx +9 -6
  85. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +90 -64
  86. package/corpus/templates/analytics/app/i18n-data.ts +3 -3
  87. package/corpus/templates/analytics/app/lib/dashboard-list-loading.ts +25 -0
  88. package/corpus/templates/analytics/app/lib/item-popularity.ts +13 -4
  89. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/DashboardFilterBar.tsx +1 -1
  90. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/pivot.ts +8 -3
  91. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/types.ts +1 -0
  92. package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +15 -3
  93. package/corpus/templates/analytics/changelog/2026-07-16-dashboard-filter-defaults-can-now-be-changed-reliably-withou.md +6 -0
  94. package/corpus/templates/analytics/changelog/2026-07-16-dashboard-lists-load-in-one-stable-order-without-popping-bet.md +6 -0
  95. package/corpus/templates/analytics/changelog/2026-07-16-fixed-dashboard-filter-dropdown-text-alignment.md +6 -0
  96. package/corpus/templates/analytics/changelog/2026-07-16-recurring-signed-in-users-can-now-be-viewed-as-weekly-bars-b.md +6 -0
  97. package/corpus/templates/analytics/changelog/2026-07-16-the-analytics-agent-can-now-duplicate-a-chart-and-place-the-.md +6 -0
  98. package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +41 -1
  99. package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +1 -1
  100. package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +47 -1
  101. package/corpus/templates/analytics/server/lib/session-replay.ts +68 -0
  102. package/corpus/templates/analytics/server/plugins/agent-chat.ts +1 -0
  103. package/corpus/templates/analytics/server/routes/sessions/lookup.get.ts +47 -0
  104. package/corpus/templates/assets/.agents/skills/asset-generation/SKILL.md +16 -9
  105. package/corpus/templates/assets/.agents/skills/creative-context/SKILL.md +86 -0
  106. package/corpus/templates/assets/AGENTS.md +10 -0
  107. package/corpus/templates/assets/actions/create-generation-session.ts +59 -1
  108. package/corpus/templates/assets/actions/edit-image.ts +2 -0
  109. package/corpus/templates/assets/actions/generate-asset.ts +52 -0
  110. package/corpus/templates/assets/actions/generate-image-batch.ts +55 -0
  111. package/corpus/templates/assets/actions/generate-image.ts +219 -1
  112. package/corpus/templates/assets/actions/open-asset-picker.ts +14 -0
  113. package/corpus/templates/assets/actions/refine-image.ts +3 -0
  114. package/corpus/templates/assets/actions/restyle-image.ts +2 -0
  115. package/corpus/templates/assets/agent-native.app-skill.json +4 -0
  116. package/corpus/templates/assets/app/components/layout/Layout.tsx +2 -0
  117. package/corpus/templates/assets/app/i18n/zh-TW.ts +3 -0
  118. package/corpus/templates/assets/app/i18n-data.ts +29 -13
  119. package/corpus/templates/assets/app/routes/agent.tsx +7 -1
  120. package/corpus/templates/assets/app/routes/library.tsx +9 -0
  121. package/corpus/templates/assets/app/routes/settings.tsx +3 -0
  122. package/corpus/templates/assets/changelog/2026-07-16-creative-context-library.md +6 -0
  123. package/corpus/templates/assets/package.json +1 -0
  124. package/corpus/templates/assets/server/lib/image-processing.ts +1 -22
  125. package/corpus/templates/assets/server/plugins/creative-context.ts +205 -0
  126. package/corpus/templates/brain/app/i18n-data.ts +3 -3
  127. package/corpus/templates/brain/app/lib/brain.ts +1 -1
  128. package/corpus/templates/brain/server/lib/search.ts +17 -67
  129. package/corpus/templates/calendar/app/i18n-data.ts +3 -3
  130. package/corpus/templates/calendar/app/pages/BookingLinksPage.tsx +19 -18
  131. package/corpus/templates/chat/app/i18n/en-US.ts +3 -3
  132. package/corpus/templates/chat/app/lib/agent-page.tsx +10 -1
  133. package/corpus/templates/clips/.agents/skills/meetings/SKILL.md +1 -1
  134. package/corpus/templates/clips/AGENTS.md +4 -0
  135. package/corpus/templates/clips/actions/cleanup-transcript.ts +35 -4
  136. package/corpus/templates/clips/actions/create-meeting.ts +6 -2
  137. package/corpus/templates/clips/actions/create-organization.ts +3 -2
  138. package/corpus/templates/clips/actions/create-recording.ts +4 -1
  139. package/corpus/templates/clips/actions/finalize-recording.ts +44 -7
  140. package/corpus/templates/clips/actions/import-loom-recording.ts +4 -1
  141. package/corpus/templates/clips/actions/lib/create-recording-schema.ts +2 -2
  142. package/corpus/templates/clips/actions/list-meetings.ts +23 -5
  143. package/corpus/templates/clips/actions/list-organization-state.ts +1 -1
  144. package/corpus/templates/clips/actions/remove-silences.ts +10 -1
  145. package/corpus/templates/clips/actions/request-transcript.ts +53 -11
  146. package/corpus/templates/clips/actions/search-recordings-utils.ts +7 -0
  147. package/corpus/templates/clips/actions/search-recordings.ts +5 -8
  148. package/corpus/templates/clips/actions/set-organization-branding.ts +2 -2
  149. package/corpus/templates/clips/actions/stitch-recordings.ts +10 -5
  150. package/corpus/templates/clips/actions/update-ai-request-status.ts +38 -0
  151. package/corpus/templates/clips/app/components/editor/editor-layout.tsx +3 -4
  152. package/corpus/templates/clips/app/components/editor/editor-selection.ts +19 -0
  153. package/corpus/templates/clips/app/components/editor/stitch-manager.tsx +10 -10
  154. package/corpus/templates/clips/app/components/library/bulk-action-toolbar.tsx +1 -2
  155. package/corpus/templates/clips/app/components/library/library-grid.tsx +101 -93
  156. package/corpus/templates/clips/app/components/player/video-player.tsx +11 -0
  157. package/corpus/templates/clips/app/components/workspace/branding-editor.tsx +53 -1
  158. package/corpus/templates/clips/app/i18n/ar-SA.ts +7 -1
  159. package/corpus/templates/clips/app/i18n/de-DE.ts +7 -1
  160. package/corpus/templates/clips/app/i18n/en-US.ts +10 -4
  161. package/corpus/templates/clips/app/i18n/es-ES.ts +7 -1
  162. package/corpus/templates/clips/app/i18n/fr-FR.ts +7 -1
  163. package/corpus/templates/clips/app/i18n/hi-IN.ts +7 -1
  164. package/corpus/templates/clips/app/i18n/ja-JP.ts +7 -1
  165. package/corpus/templates/clips/app/i18n/ko-KR.ts +7 -1
  166. package/corpus/templates/clips/app/i18n/pt-BR.ts +7 -1
  167. package/corpus/templates/clips/app/i18n/zh-CN.ts +6 -1
  168. package/corpus/templates/clips/app/i18n/zh-TW.ts +6 -1
  169. package/corpus/templates/clips/app/routes/_app.settings._index.tsx +5 -9
  170. package/corpus/templates/clips/app/routes/_app.settings.organization.tsx +6 -2
  171. package/corpus/templates/clips/app/routes/r.$recordingId.tsx +129 -27
  172. package/corpus/templates/clips/app/routes/record.tsx +23 -2
  173. package/corpus/templates/clips/app/routes/share.$shareId.tsx +6 -2
  174. package/corpus/templates/clips/changelog/2026-07-16-authorized-viewers-can-open-shared-private-clips-without-a-m.md +6 -0
  175. package/corpus/templates/clips/changelog/2026-07-16-camera-bubble-hover-controls-appear-above-the-face.md +6 -0
  176. package/corpus/templates/clips/changelog/2026-07-16-chrome-extension-recovers-stale-recorder-state.md +6 -0
  177. package/corpus/templates/clips/changelog/2026-07-16-clips-agent-chat-no-longer-shows-a-separate-workspace-header.md +6 -0
  178. package/corpus/templates/clips/changelog/2026-07-16-clips-search-now-matches-recording-content-without-requiring.md +6 -0
  179. package/corpus/templates/clips/changelog/2026-07-16-declined-meetings-no-longer-show-desktop-reminders.md +6 -0
  180. package/corpus/templates/clips/changelog/2026-07-16-failed-desktop-saves-now-show-their-local-recovery-copy.md +6 -0
  181. package/corpus/templates/clips/changelog/2026-07-16-long-desktop-clips-now-preserve-complete-playback-synced-aud.md +6 -0
  182. package/corpus/templates/clips/changelog/2026-07-16-long-recording-lists-keep-stitch-and-library-actions-visible.md +6 -0
  183. package/corpus/templates/clips/changelog/2026-07-16-organization-admins-can-choose-new-recording-visibility.md +6 -0
  184. package/corpus/templates/clips/changelog/2026-07-16-remove-silences-now-shows-queued-active-completed-and-failed.md +6 -0
  185. package/corpus/templates/clips/changelog/2026-07-16-settings-no-longer-repeats-the-builder-connection-status-in-.md +6 -0
  186. package/corpus/templates/clips/changelog/2026-07-16-transcripts-now-appear-from-native-browser-speech-sooner-wit.md +6 -0
  187. package/corpus/templates/clips/chrome-extension/public/manifest.json +1 -1
  188. package/corpus/templates/clips/chrome-extension/src/background.ts +73 -1
  189. package/corpus/templates/clips/chrome-extension/src/native-recording-state.ts +32 -0
  190. package/corpus/templates/clips/chrome-extension/src/native-transcription.ts +248 -0
  191. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +106 -0
  192. package/corpus/templates/clips/desktop/src/app.tsx +66 -28
  193. package/corpus/templates/clips/desktop/src/lib/recorder.ts +335 -285
  194. package/corpus/templates/clips/desktop/src/lib/single-flight.ts +7 -0
  195. package/corpus/templates/clips/desktop/src/lib/upload-verification.ts +51 -0
  196. package/corpus/templates/clips/desktop/src/overlays/bubble.tsx +2 -2
  197. package/corpus/templates/clips/desktop/src/overlays/finalizing.tsx +10 -2
  198. package/corpus/templates/clips/desktop/src/styles.css +13 -11
  199. package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +8 -9
  200. package/corpus/templates/clips/desktop/src-tauri/src/meetings_watcher.rs +1 -0
  201. package/corpus/templates/clips/desktop/src-tauri/src/native_screen/custom_capture.rs +88 -13
  202. package/corpus/templates/clips/desktop/src-tauri/src/native_screen/live_upload.rs +13 -2
  203. package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +241 -6
  204. package/corpus/templates/clips/server/db/schema.ts +2 -2
  205. package/corpus/templates/clips/server/lib/builder-media-compression.ts +64 -67
  206. package/corpus/templates/clips/server/lib/calendar-event-classification.ts +19 -0
  207. package/corpus/templates/clips/server/lib/google-calendar-client.ts +1 -0
  208. package/corpus/templates/clips/server/lib/recordings.ts +40 -1
  209. package/corpus/templates/clips/server/plugins/agent-chat.ts +1 -0
  210. package/corpus/templates/clips/server/plugins/db.ts +2 -2
  211. package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +1 -1
  212. package/corpus/templates/clips/server/routes/api/public-recording.get.ts +14 -5
  213. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/chunk.post.ts +51 -1
  214. package/corpus/templates/clips/server/routes/api/video/[recordingId].get.ts +1 -64
  215. package/corpus/templates/clips/shared/media-worker-contract.ts +32 -15
  216. package/corpus/templates/content/.agents/skills/content/SKILL.md +16 -0
  217. package/corpus/templates/content/.agents/skills/creative-context/SKILL.md +85 -0
  218. package/corpus/templates/content/.agents/skills/notion-integration/SKILL.md +8 -0
  219. package/corpus/templates/content/AGENTS.md +9 -0
  220. package/corpus/templates/content/actions/create-document.ts +94 -0
  221. package/corpus/templates/content/actions/edit-document.ts +144 -4
  222. package/corpus/templates/content/actions/update-document.ts +138 -0
  223. package/corpus/templates/content/agent-native.app-skill.json +4 -0
  224. package/corpus/templates/content/app/components/layout/Layout.tsx +2 -0
  225. package/corpus/templates/content/app/i18n/zh-TW.ts +3 -0
  226. package/corpus/templates/content/app/i18n-data.ts +13 -4
  227. package/corpus/templates/content/app/routes/_app.agent.tsx +2 -1
  228. package/corpus/templates/content/app/routes/_app.settings.tsx +3 -0
  229. package/corpus/templates/content/changelog/2026-07-16-creative-context-library.md +6 -0
  230. package/corpus/templates/content/package.json +1 -0
  231. package/corpus/templates/content/server/plugins/creative-context.ts +31 -0
  232. package/corpus/templates/design/.agents/skills/creative-context/SKILL.md +116 -0
  233. package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +16 -0
  234. package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +8 -0
  235. package/corpus/templates/design/AGENTS.md +6 -0
  236. package/corpus/templates/design/actions/clone-creative-context-design.ts +176 -0
  237. package/corpus/templates/design/actions/edit-design.ts +128 -0
  238. package/corpus/templates/design/actions/generate-design.ts +278 -14
  239. package/corpus/templates/design/actions/generate-screens.ts +42 -1
  240. package/corpus/templates/design/agent-native.app-skill.json +4 -0
  241. package/corpus/templates/design/app/components/layout/Layout.tsx +7 -3
  242. package/corpus/templates/design/app/i18n/zh-TW.ts +3 -0
  243. package/corpus/templates/design/app/i18n-data.ts +10 -4
  244. package/corpus/templates/design/app/routes/agent.tsx +2 -1
  245. package/corpus/templates/design/app/routes/settings.tsx +3 -0
  246. package/corpus/templates/design/changelog/2026-07-16-creative-context-library.md +6 -0
  247. package/corpus/templates/design/changelog/2026-07-16-design-agent-chat-no-longer-shows-a-separate-workspace-header.md +6 -0
  248. package/corpus/templates/design/package.json +1 -0
  249. package/corpus/templates/design/server/lib/figma-design-context.ts +5 -335
  250. package/corpus/templates/design/server/lib/figma-node-to-html.ts +1 -1859
  251. package/corpus/templates/design/server/lib/import-design-files.ts +6 -8
  252. package/corpus/templates/design/server/plugins/creative-context.ts +31 -0
  253. package/corpus/templates/design/shared/generation-session.ts +7 -0
  254. package/corpus/templates/dispatch/app/i18n-data.ts +3 -3
  255. package/corpus/templates/forms/app/i18n/en-US.ts +3 -3
  256. package/corpus/templates/macros/app/i18n/en-US.ts +3 -3
  257. package/corpus/templates/mail/app/components/email/EmailThread.tsx +35 -5
  258. package/corpus/templates/mail/app/i18n/en-US.ts +3 -3
  259. package/corpus/templates/mail/changelog/2026-07-16-mail-previews-now-expand-to-show-the-full-message-without-an.md +6 -0
  260. package/corpus/templates/plan/.agents/skills/visual-plan/SKILL.md +30 -11
  261. package/corpus/templates/plan/AGENTS.md +21 -1
  262. package/corpus/templates/plan/actions/get-visual-plan.ts +1 -1
  263. package/corpus/templates/plan/actions/patch-visual-plan-source.ts +161 -0
  264. package/corpus/templates/plan/actions/read-visual-plan-source.ts +1 -1
  265. package/corpus/templates/plan/actions/update-visual-plan.ts +126 -10
  266. package/corpus/templates/plan/app/hooks/use-plans.ts +2 -0
  267. package/corpus/templates/plan/app/i18n/en-US.ts +3 -3
  268. package/corpus/templates/plan/app/pages/PlansPage.tsx +65 -62
  269. package/corpus/templates/plan/changelog/2026-07-16-local-plan-previews-now-load-annotations-containing-html-lik.md +6 -0
  270. package/corpus/templates/plan/changelog/2026-07-16-plan-agents-now-prevent-stale-edits-from-overwriting-newer-p.md +6 -0
  271. package/corpus/templates/plan/server/plan-mdx.ts +75 -2
  272. package/corpus/templates/slides/.agents/skills/create-deck/SKILL.md +21 -4
  273. package/corpus/templates/slides/.agents/skills/creative-context/SKILL.md +122 -0
  274. package/corpus/templates/slides/.agents/skills/design-systems/SKILL.md +11 -0
  275. package/corpus/templates/slides/.agents/skills/slide-editing/SKILL.md +12 -3
  276. package/corpus/templates/slides/AGENTS.md +6 -0
  277. package/corpus/templates/slides/actions/add-slide.ts +230 -14
  278. package/corpus/templates/slides/actions/clone-context-slide.ts +302 -0
  279. package/corpus/templates/slides/actions/create-deck.ts +130 -0
  280. package/corpus/templates/slides/actions/extract-pdf.ts +6 -2
  281. package/corpus/templates/slides/actions/import-file.ts +5 -4
  282. package/corpus/templates/slides/actions/patch-deck.ts +200 -10
  283. package/corpus/templates/slides/actions/update-slide.ts +208 -15
  284. package/corpus/templates/slides/app/components/layout/Layout.tsx +2 -0
  285. package/corpus/templates/slides/app/components/visual-editor/CanvasCommentPins.tsx +16 -1
  286. package/corpus/templates/slides/app/i18n/ar-SA.ts +3 -0
  287. package/corpus/templates/slides/app/i18n/de-DE.ts +3 -0
  288. package/corpus/templates/slides/app/i18n/en-US.ts +6 -3
  289. package/corpus/templates/slides/app/i18n/es-ES.ts +3 -0
  290. package/corpus/templates/slides/app/i18n/fr-FR.ts +3 -0
  291. package/corpus/templates/slides/app/i18n/hi-IN.ts +3 -0
  292. package/corpus/templates/slides/app/i18n/ja-JP.ts +3 -0
  293. package/corpus/templates/slides/app/i18n/ko-KR.ts +3 -0
  294. package/corpus/templates/slides/app/i18n/pt-BR.ts +3 -0
  295. package/corpus/templates/slides/app/i18n/zh-CN.ts +3 -0
  296. package/corpus/templates/slides/app/i18n/zh-TW.ts +3 -0
  297. package/corpus/templates/slides/app/lib/validate-native-slide-html.ts +176 -0
  298. package/corpus/templates/slides/app/routes/agent.tsx +7 -1
  299. package/corpus/templates/slides/app/routes/settings.tsx +3 -0
  300. package/corpus/templates/slides/changelog/2026-07-16-creative-context-library.md +6 -0
  301. package/corpus/templates/slides/changelog/2026-07-16-google-slides-native-cloning.md +6 -0
  302. package/corpus/templates/slides/package.json +1 -0
  303. package/corpus/templates/slides/server/handlers/import/docx-parser.ts +4 -85
  304. package/corpus/templates/slides/server/handlers/import/pptx-parser.ts +7 -421
  305. package/corpus/templates/slides/server/plugins/creative-context.ts +166 -0
  306. package/dist/agent/engine/credential-errors.d.ts +1 -1
  307. package/dist/agent/engine/credential-errors.d.ts.map +1 -1
  308. package/dist/agent/engine/credential-errors.js +2 -2
  309. package/dist/agent/engine/credential-errors.js.map +1 -1
  310. package/dist/agent/production-agent.d.ts.map +1 -1
  311. package/dist/agent/production-agent.js +25 -0
  312. package/dist/agent/production-agent.js.map +1 -1
  313. package/dist/agent/run-store.d.ts.map +1 -1
  314. package/dist/agent/run-store.js +12 -2
  315. package/dist/agent/run-store.js.map +1 -1
  316. package/dist/cli/create.d.ts.map +1 -1
  317. package/dist/cli/create.js +1 -0
  318. package/dist/cli/create.js.map +1 -1
  319. package/dist/cli/skills-content/visual-plan-skill.d.ts +1 -1
  320. package/dist/cli/skills-content/visual-plan-skill.d.ts.map +1 -1
  321. package/dist/cli/skills-content/visual-plan-skill.js +30 -11
  322. package/dist/cli/skills-content/visual-plan-skill.js.map +1 -1
  323. package/dist/cli/templates-meta.d.ts.map +1 -1
  324. package/dist/cli/templates-meta.js +4 -3
  325. package/dist/cli/templates-meta.js.map +1 -1
  326. package/dist/client/AgentAskPopover.d.ts +11 -0
  327. package/dist/client/AgentAskPopover.d.ts.map +1 -0
  328. package/dist/client/AgentAskPopover.js +30 -0
  329. package/dist/client/AgentAskPopover.js.map +1 -0
  330. package/dist/client/AgentChatHome.d.ts +1 -1
  331. package/dist/client/AgentChatHome.d.ts.map +1 -1
  332. package/dist/client/AgentChatHome.js +2 -2
  333. package/dist/client/AgentChatHome.js.map +1 -1
  334. package/dist/client/AgentPanel.d.ts +9 -19
  335. package/dist/client/AgentPanel.d.ts.map +1 -1
  336. package/dist/client/AgentPanel.js +119 -80
  337. package/dist/client/AgentPanel.js.map +1 -1
  338. package/dist/client/AssistantChat.d.ts.map +1 -1
  339. package/dist/client/AssistantChat.js +4 -4
  340. package/dist/client/AssistantChat.js.map +1 -1
  341. package/dist/client/MultiTabAssistantChat.d.ts +3 -9
  342. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  343. package/dist/client/MultiTabAssistantChat.js +49 -189
  344. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  345. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  346. package/dist/client/agent-chat-adapter.js +12 -1
  347. package/dist/client/agent-chat-adapter.js.map +1 -1
  348. package/dist/client/agent-page/AgentContextTab.d.ts.map +1 -1
  349. package/dist/client/agent-page/AgentContextTab.js +26 -28
  350. package/dist/client/agent-page/AgentContextTab.js.map +1 -1
  351. package/dist/client/agent-page/AgentEmptyState.d.ts +13 -0
  352. package/dist/client/agent-page/AgentEmptyState.d.ts.map +1 -0
  353. package/dist/client/agent-page/AgentEmptyState.js +6 -0
  354. package/dist/client/agent-page/AgentEmptyState.js.map +1 -0
  355. package/dist/client/agent-page/AgentJobsTab.d.ts +1 -1
  356. package/dist/client/agent-page/AgentJobsTab.d.ts.map +1 -1
  357. package/dist/client/agent-page/AgentJobsTab.js +90 -58
  358. package/dist/client/agent-page/AgentJobsTab.js.map +1 -1
  359. package/dist/client/agent-page/AgentTabFrame.d.ts +12 -0
  360. package/dist/client/agent-page/AgentTabFrame.d.ts.map +1 -0
  361. package/dist/client/agent-page/AgentTabFrame.js +7 -0
  362. package/dist/client/agent-page/AgentTabFrame.js.map +1 -0
  363. package/dist/client/agent-page/AgentTabsPage.d.ts +9 -1
  364. package/dist/client/agent-page/AgentTabsPage.d.ts.map +1 -1
  365. package/dist/client/agent-page/AgentTabsPage.js +135 -99
  366. package/dist/client/agent-page/AgentTabsPage.js.map +1 -1
  367. package/dist/client/agent-page/types.d.ts +1 -1
  368. package/dist/client/agent-page/types.d.ts.map +1 -1
  369. package/dist/client/agent-page/types.js.map +1 -1
  370. package/dist/client/analytics.d.ts +10 -3
  371. package/dist/client/analytics.d.ts.map +1 -1
  372. package/dist/client/analytics.js +37 -2
  373. package/dist/client/analytics.js.map +1 -1
  374. package/dist/client/chat/run-recovery.d.ts.map +1 -1
  375. package/dist/client/chat/run-recovery.js +10 -3
  376. package/dist/client/chat/run-recovery.js.map +1 -1
  377. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  378. package/dist/client/composer/PromptComposer.js +2 -2
  379. package/dist/client/composer/PromptComposer.js.map +1 -1
  380. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  381. package/dist/client/composer/TiptapComposer.js +15 -3
  382. package/dist/client/composer/TiptapComposer.js.map +1 -1
  383. package/dist/client/dynamic-suggestions.js +3 -3
  384. package/dist/client/dynamic-suggestions.js.map +1 -1
  385. package/dist/client/index.d.ts +4 -3
  386. package/dist/client/index.d.ts.map +1 -1
  387. package/dist/client/index.js +3 -2
  388. package/dist/client/index.js.map +1 -1
  389. package/dist/client/resources/ResourceTree.d.ts +5 -1
  390. package/dist/client/resources/ResourceTree.d.ts.map +1 -1
  391. package/dist/client/resources/ResourceTree.js +74 -5
  392. package/dist/client/resources/ResourceTree.js.map +1 -1
  393. package/dist/client/resources/ResourcesPanel.d.ts +11 -2
  394. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  395. package/dist/client/resources/ResourcesPanel.js +105 -31
  396. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  397. package/dist/client/session-replay.d.ts +28 -0
  398. package/dist/client/session-replay.d.ts.map +1 -1
  399. package/dist/client/session-replay.js +122 -8
  400. package/dist/client/session-replay.js.map +1 -1
  401. package/dist/client/settings/AutomationsSection.d.ts +3 -1
  402. package/dist/client/settings/AutomationsSection.d.ts.map +1 -1
  403. package/dist/client/settings/AutomationsSection.js +16 -6
  404. package/dist/client/settings/AutomationsSection.js.map +1 -1
  405. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  406. package/dist/client/settings/SettingsPanel.js +3 -3
  407. package/dist/client/settings/SettingsPanel.js.map +1 -1
  408. package/dist/client/settings/SettingsTabsPage.d.ts +2 -0
  409. package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
  410. package/dist/client/settings/SettingsTabsPage.js.map +1 -1
  411. package/dist/client/settings/agent-settings-search.js +2 -2
  412. package/dist/client/settings/agent-settings-search.js.map +1 -1
  413. package/dist/client/use-chat-threads.d.ts +2 -0
  414. package/dist/client/use-chat-threads.d.ts.map +1 -1
  415. package/dist/client/use-chat-threads.js.map +1 -1
  416. package/dist/collab/awareness.d.ts +2 -2
  417. package/dist/collab/awareness.d.ts.map +1 -1
  418. package/dist/collab/routes.d.ts +1 -1
  419. package/dist/connections/catalog.d.ts +41 -7
  420. package/dist/connections/catalog.d.ts.map +1 -1
  421. package/dist/connections/catalog.js +40 -7
  422. package/dist/connections/catalog.js.map +1 -1
  423. package/dist/db/index.d.ts +2 -2
  424. package/dist/db/index.d.ts.map +1 -1
  425. package/dist/db/index.js +2 -2
  426. package/dist/db/index.js.map +1 -1
  427. package/dist/extensions/actions.d.ts.map +1 -1
  428. package/dist/extensions/actions.js +85 -15
  429. package/dist/extensions/actions.js.map +1 -1
  430. package/dist/extensions/content-patch.d.ts +4 -0
  431. package/dist/extensions/content-patch.d.ts.map +1 -1
  432. package/dist/extensions/content-patch.js +18 -0
  433. package/dist/extensions/content-patch.js.map +1 -1
  434. package/dist/extensions/routes.d.ts.map +1 -1
  435. package/dist/extensions/routes.js +14 -0
  436. package/dist/extensions/routes.js.map +1 -1
  437. package/dist/extensions/store.d.ts +1 -0
  438. package/dist/extensions/store.d.ts.map +1 -1
  439. package/dist/extensions/store.js +4 -1
  440. package/dist/extensions/store.js.map +1 -1
  441. package/dist/file-upload/actions/upload-image.d.ts +1 -1
  442. package/dist/index.d.ts +1 -1
  443. package/dist/index.d.ts.map +1 -1
  444. package/dist/index.js +1 -1
  445. package/dist/index.js.map +1 -1
  446. package/dist/ingestion/docx.d.ts +16 -0
  447. package/dist/ingestion/docx.d.ts.map +1 -0
  448. package/dist/ingestion/docx.js +129 -0
  449. package/dist/ingestion/docx.js.map +1 -0
  450. package/dist/ingestion/figma-node-to-html.d.ts +304 -0
  451. package/dist/ingestion/figma-node-to-html.d.ts.map +1 -0
  452. package/dist/ingestion/figma-node-to-html.js +1292 -0
  453. package/dist/ingestion/figma-node-to-html.js.map +1 -0
  454. package/dist/ingestion/figma.d.ts +115 -0
  455. package/dist/ingestion/figma.d.ts.map +1 -0
  456. package/dist/ingestion/figma.js +399 -0
  457. package/dist/ingestion/figma.js.map +1 -0
  458. package/dist/ingestion/index.d.ts +11 -0
  459. package/dist/ingestion/index.d.ts.map +1 -0
  460. package/dist/ingestion/index.js +11 -0
  461. package/dist/ingestion/index.js.map +1 -0
  462. package/dist/ingestion/media.d.ts +36 -0
  463. package/dist/ingestion/media.d.ts.map +1 -0
  464. package/dist/ingestion/media.js +178 -0
  465. package/dist/ingestion/media.js.map +1 -0
  466. package/dist/ingestion/notion.d.ts +12 -0
  467. package/dist/ingestion/notion.d.ts.map +1 -0
  468. package/dist/ingestion/notion.js +104 -0
  469. package/dist/ingestion/notion.js.map +1 -0
  470. package/dist/ingestion/office.d.ts +45 -0
  471. package/dist/ingestion/office.d.ts.map +1 -0
  472. package/dist/ingestion/office.js +141 -0
  473. package/dist/ingestion/office.js.map +1 -0
  474. package/dist/ingestion/orchestration.d.ts +52 -0
  475. package/dist/ingestion/orchestration.d.ts.map +1 -0
  476. package/dist/ingestion/orchestration.js +89 -0
  477. package/dist/ingestion/orchestration.js.map +1 -0
  478. package/dist/ingestion/pptx.d.ts +28 -0
  479. package/dist/ingestion/pptx.d.ts.map +1 -0
  480. package/dist/ingestion/pptx.js +255 -0
  481. package/dist/ingestion/pptx.js.map +1 -0
  482. package/dist/ingestion/selection.d.ts +20 -0
  483. package/dist/ingestion/selection.d.ts.map +1 -0
  484. package/dist/ingestion/selection.js +52 -0
  485. package/dist/ingestion/selection.js.map +1 -0
  486. package/dist/ingestion/website.d.ts +27 -0
  487. package/dist/ingestion/website.d.ts.map +1 -0
  488. package/dist/ingestion/website.js +100 -0
  489. package/dist/ingestion/website.js.map +1 -0
  490. package/dist/integrations/plugin.d.ts.map +1 -1
  491. package/dist/integrations/plugin.js +32 -27
  492. package/dist/integrations/plugin.js.map +1 -1
  493. package/dist/localization/default-messages.d.ts +22 -0
  494. package/dist/localization/default-messages.d.ts.map +1 -1
  495. package/dist/localization/default-messages.js +31 -9
  496. package/dist/localization/default-messages.js.map +1 -1
  497. package/dist/observability/hosted-model-experiment.d.ts +39 -0
  498. package/dist/observability/hosted-model-experiment.d.ts.map +1 -0
  499. package/dist/observability/hosted-model-experiment.js +90 -0
  500. package/dist/observability/hosted-model-experiment.js.map +1 -0
  501. package/dist/observability/routes.d.ts +5 -5
  502. package/dist/observability/traces.d.ts.map +1 -1
  503. package/dist/observability/traces.js +5 -3
  504. package/dist/observability/traces.js.map +1 -1
  505. package/dist/progress/routes.d.ts +1 -1
  506. package/dist/provider-api/index.d.ts +35 -4
  507. package/dist/provider-api/index.d.ts.map +1 -1
  508. package/dist/provider-api/index.js +339 -8
  509. package/dist/provider-api/index.js.map +1 -1
  510. package/dist/resources/handlers.d.ts +1 -1
  511. package/dist/scripts/agent-engines/list-agent-engines.d.ts.map +1 -1
  512. package/dist/scripts/agent-engines/list-agent-engines.js +18 -1
  513. package/dist/scripts/agent-engines/list-agent-engines.js.map +1 -1
  514. package/dist/search-utils/index.d.ts +12 -0
  515. package/dist/search-utils/index.d.ts.map +1 -0
  516. package/dist/search-utils/index.js +95 -0
  517. package/dist/search-utils/index.js.map +1 -0
  518. package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
  519. package/dist/secrets/register-framework-secrets.js +57 -0
  520. package/dist/secrets/register-framework-secrets.js.map +1 -1
  521. package/dist/secrets/routes.d.ts +9 -9
  522. package/dist/server/action-discovery.d.ts +8 -0
  523. package/dist/server/action-discovery.d.ts.map +1 -1
  524. package/dist/server/action-discovery.js +26 -9
  525. package/dist/server/action-discovery.js.map +1 -1
  526. package/dist/server/agent-chat/framework-prompts.js +2 -2
  527. package/dist/server/agent-chat/framework-prompts.js.map +1 -1
  528. package/dist/server/agent-chat/prompt-resources.d.ts +19 -0
  529. package/dist/server/agent-chat/prompt-resources.d.ts.map +1 -1
  530. package/dist/server/agent-chat/prompt-resources.js +95 -0
  531. package/dist/server/agent-chat/prompt-resources.js.map +1 -1
  532. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  533. package/dist/server/agent-chat-plugin.js +7 -0
  534. package/dist/server/agent-chat-plugin.js.map +1 -1
  535. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  536. package/dist/server/core-routes-plugin.js +5 -0
  537. package/dist/server/core-routes-plugin.js.map +1 -1
  538. package/dist/server/index.d.ts +5 -1
  539. package/dist/server/index.d.ts.map +1 -1
  540. package/dist/server/index.js +5 -1
  541. package/dist/server/index.js.map +1 -1
  542. package/dist/server/workspace-provider-oauth.d.ts +48 -0
  543. package/dist/server/workspace-provider-oauth.d.ts.map +1 -0
  544. package/dist/server/workspace-provider-oauth.js +415 -0
  545. package/dist/server/workspace-provider-oauth.js.map +1 -0
  546. package/dist/styles/agent-native.css +9 -0
  547. package/dist/templates/chat/app/i18n/en-US.ts +3 -3
  548. package/dist/templates/chat/app/lib/agent-page.tsx +10 -1
  549. package/dist/templates/default/app/i18n/en-US.ts +3 -3
  550. package/dist/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
  551. package/dist/templates/workspace-root/.env.example +12 -0
  552. package/dist/vite/client.d.ts.map +1 -1
  553. package/dist/vite/client.js +2 -0
  554. package/dist/vite/client.js.map +1 -1
  555. package/dist/workspace-connections/index.d.ts +1 -0
  556. package/dist/workspace-connections/index.d.ts.map +1 -1
  557. package/dist/workspace-connections/index.js +1 -0
  558. package/dist/workspace-connections/index.js.map +1 -1
  559. package/dist/workspace-connections/lifecycle.d.ts +16 -0
  560. package/dist/workspace-connections/lifecycle.d.ts.map +1 -0
  561. package/dist/workspace-connections/lifecycle.js +14 -0
  562. package/dist/workspace-connections/lifecycle.js.map +1 -0
  563. package/dist/workspace-connections/store.d.ts.map +1 -1
  564. package/dist/workspace-connections/store.js +16 -0
  565. package/dist/workspace-connections/store.js.map +1 -1
  566. package/package.json +10 -3
  567. package/src/templates/chat/app/i18n/en-US.ts +3 -3
  568. package/src/templates/chat/app/lib/agent-page.spec.tsx +10 -1
  569. package/src/templates/chat/app/lib/agent-page.tsx +10 -1
  570. package/src/templates/default/app/i18n/en-US.ts +3 -3
  571. package/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
  572. package/src/templates/workspace-root/.env.example +12 -0
@@ -12,6 +12,57 @@ import { parseSkillFrontmatter } from "./skill-frontmatter.js";
12
12
  const SHARED_PROMPT_RESOURCE_MAX_CHARS = 30_000;
13
13
  export const COMPACT_PROMPT_RESOURCE_MAX_CHARS = 6_000;
14
14
  const COMPACT_PROMPT_RESOURCES_TOTAL_MAX_CHARS = 48_000;
15
+ const PROMPT_CONTEXT_PROVIDER_MAX_CHARS = 8_000;
16
+ const promptContextProviders = new Map();
17
+ /** Register a package-owned, request-scoped system-context contribution. */
18
+ export function registerPromptContextProvider(provider) {
19
+ const id = provider.id.trim();
20
+ if (!/^[a-z][a-z0-9-]{1,63}$/.test(id)) {
21
+ throw new Error("Prompt context provider ids must be 2-64 lowercase letters, digits, or hyphens");
22
+ }
23
+ const registered = { ...provider, id };
24
+ promptContextProviders.set(id, registered);
25
+ return () => {
26
+ if (promptContextProviders.get(id) === registered) {
27
+ promptContextProviders.delete(id);
28
+ }
29
+ };
30
+ }
31
+ function xmlAttributeEscape(value) {
32
+ return value
33
+ .replace(/&/g, "&")
34
+ .replace(/"/g, """)
35
+ .replace(/</g, "&lt;")
36
+ .replace(/>/g, "&gt;");
37
+ }
38
+ async function loadPromptContextProviderBlocks(context) {
39
+ const providers = [...promptContextProviders.values()].sort((a, b) => a.id.localeCompare(b.id));
40
+ const settled = await Promise.allSettled(providers.map(async (provider) => ({
41
+ provider,
42
+ contribution: await provider.load(context),
43
+ })));
44
+ const blocks = [];
45
+ for (const result of settled) {
46
+ if (result.status !== "fulfilled")
47
+ continue;
48
+ const { provider, contribution } = result.value;
49
+ if (!contribution)
50
+ continue;
51
+ const content = contribution.content.trim();
52
+ if (!content)
53
+ continue;
54
+ const boundedContent = content.length <= PROMPT_CONTEXT_PROVIDER_MAX_CHARS
55
+ ? content
56
+ : `${content.slice(0, PROMPT_CONTEXT_PROVIDER_MAX_CHARS)}\n[truncated after ${PROMPT_CONTEXT_PROVIDER_MAX_CHARS.toLocaleString()} characters]`;
57
+ const label = contribution.label?.trim() || provider.id;
58
+ const provenance = contribution.provenance ?? "runtime-context";
59
+ const governance = contribution.governance ?? "inherited";
60
+ const sourceScope = contribution.sourceRef?.scope?.trim() || "provider";
61
+ const sourcePath = contribution.sourceRef?.path?.trim() || provider.id;
62
+ blocks.push(`<prompt-context-provider id="${xmlAttributeEscape(provider.id)}" label="${xmlAttributeEscape(label)}" provenance="${provenance}" governance="${governance}" scope="${xmlAttributeEscape(sourceScope)}" path="${xmlAttributeEscape(sourcePath)}">\n${boundedContent.replace(/<\/prompt-context-provider>/gi, "&lt;/prompt-context-provider&gt;")}\n</prompt-context-provider>`);
63
+ }
64
+ return blocks;
65
+ }
15
66
  export function compactPromptLine(value, maxChars) {
16
67
  const line = value.replace(/\s+/g, " ").trim();
17
68
  if (line.length <= maxChars)
@@ -97,6 +148,44 @@ export function promptResourceManifestSections(prompt) {
97
148
  },
98
149
  });
99
150
  }
151
+ const providerPattern = /<prompt-context-provider\b([^>]*)>([\s\S]*?)<\/prompt-context-provider>/g;
152
+ while ((match = providerPattern.exec(prompt))) {
153
+ const attrs = match[1] ?? "";
154
+ const id = xmlAttribute(attrs, "id") ?? "prompt-context-provider";
155
+ const label = xmlAttribute(attrs, "label") ?? id;
156
+ const provenanceValue = xmlAttribute(attrs, "provenance");
157
+ const governanceValue = xmlAttribute(attrs, "governance");
158
+ const provenance = [
159
+ "framework-core",
160
+ "actions-prompt",
161
+ "template",
162
+ "enterprise-workspace-core",
163
+ "sql-workspace",
164
+ "legacy-app-default",
165
+ "organization",
166
+ "personal",
167
+ "memory",
168
+ "db-schema",
169
+ "tools",
170
+ "model-overlay",
171
+ "runtime-context",
172
+ ].includes(provenanceValue)
173
+ ? provenanceValue
174
+ : "runtime-context";
175
+ const governance = ["required", "inherited", "user"].includes(governanceValue)
176
+ ? governanceValue
177
+ : "inherited";
178
+ sections.push({
179
+ label,
180
+ provenance,
181
+ governance,
182
+ content: match[2] ?? "",
183
+ sourceRef: {
184
+ path: xmlAttribute(attrs, "path") ?? id,
185
+ scope: xmlAttribute(attrs, "scope") ?? "provider",
186
+ },
187
+ });
188
+ }
100
189
  const taggedSections = [
101
190
  {
102
191
  tag: "skills-summary",
@@ -630,6 +719,12 @@ export async function loadResourcesForPrompt(owner, compact = false, selfAppId,
630
719
  if (organizationResourceIndex)
631
720
  sections.push(organizationResourceIndex);
632
721
  }
722
+ sections.push(...(await loadPromptContextProviderBlocks({
723
+ owner,
724
+ compact,
725
+ selfAppId,
726
+ orgId,
727
+ })));
633
728
  try {
634
729
  const agents = (await discoverAgents(selfAppId)).slice(0, 30);
635
730
  if (agents.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-resources.js","sourceRoot":"","sources":["../../../src/server/agent-chat/prompt-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,8EAA8E;AAC9E,uEAAuE;AACvE,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,8EAA8E;AAE9E,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAChD,MAAM,CAAC,MAAM,iCAAiC,GAAG,KAAK,CAAC;AACvD,MAAM,wCAAwC,GAAG,MAAM,CAAC;AAExD,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,QAAgB;IAC/D,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,C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AO,KAAK,CAAC,WAAW,IAAI,mBAAmB,EAAE,CAChF,CAAC;YACF,QAAQ,CAAC,IAAI,CACX,oEAAoE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,yKAAyK,CAC9P,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,gEAAgE;IAClE,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,gBAAgB,GAAG,OAAO;QAC9B,CAAC,CAAC,gCAAgC,CAC9B,QAAQ,EACR,wCAAwC,CACzC;QACH,CAAC,CAAC,QAAQ,CAAC;IACb,OAAO,CACL,wIAAwI;QACxI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import {\n getFrontmatterValue,\n getSkillNameFromPath,\n parseFrontmatter,\n} from \"../../resources/metadata.js\";\nimport {\n ensurePersonalDefaults,\n organizationIdFromResourceOwner,\n resourceGet,\n resourceGetByPath,\n resourceList,\n resourceListAccessible,\n SHARED_OWNER,\n sharedResourceOwner,\n WORKSPACE_OWNER,\n} from \"../../resources/store.js\";\nimport type {\n ContextGovernanceTier,\n ContextManifestSourceRef,\n ContextSystemProvenance,\n} from \"../../shared/context-xray.js\";\nimport { discoverAgents } from \"../agent-discovery.js\";\nimport { getRequestOrgId } from \"../request-context.js\";\nimport { parseSkillFrontmatter } from \"./skill-frontmatter.js\";\n\n// ---------------------------------------------------------------------------\n// System-prompt resource loading: AGENTS.md, instructions/*.md, skills\n// summaries, and the shared/workspace resource index. Assembled by\n// `loadResourcesForPrompt`, the top-level orchestrator called once per\n// request to build the \"here's what you should know\" context block.\n// ---------------------------------------------------------------------------\n\nconst SHARED_PROMPT_RESOURCE_MAX_CHARS = 30_000;\nexport const COMPACT_PROMPT_RESOURCE_MAX_CHARS = 6_000;\nconst COMPACT_PROMPT_RESOURCES_TOTAL_MAX_CHARS = 48_000;\n\nexport function compactPromptLine(value: string, maxChars: number): string {\n const line = value.replace(/\\s+/g, \" \").trim();\n if (line.length <= maxChars) return line;\n return `${line.slice(0, maxChars - 1)}…`;\n}\nconst SHARED_RESOURCE_INDEX_LIMIT = 40;\nconst PROMPT_SKILL_SUMMARY_LIMIT = 40;\nconst PROMPT_SKILL_METADATA_READ_LIMIT = 80;\nconst PROMPT_INSTRUCTION_SUMMARY_LIMIT = 20;\nconst PROMPT_SUMMARY_DESCRIPTION_MAX_CHARS = 180;\n\nexport interface PromptResourceManifestSection {\n label: string;\n provenance: ContextSystemProvenance;\n governance: ContextGovernanceTier;\n content: string;\n sourceRef?: ContextManifestSourceRef;\n}\n\nfunction normalizeResourcePathForPrompt(path: string): string {\n return path.replace(/^\\/+/, \"\").trim();\n}\n\nfunction xmlAttribute(attrs: string, name: string): string | undefined {\n const match = new RegExp(`\\\\b${name}=\"([^\"]*)\"`).exec(attrs);\n return match?.[1];\n}\n\nfunction resourceManifestClassification(\n scope: string,\n path: string,\n index: number,\n): {\n provenance: ContextSystemProvenance;\n governance: ContextGovernanceTier;\n} {\n const normalizedPath = normalizeResourcePathForPrompt(path);\n if (scope === \"template\") {\n return { provenance: \"template\", governance: \"inherited\" };\n }\n if (scope.startsWith(\"workspace\")) {\n return {\n provenance:\n scope === \"workspace\" && index === 0\n ? \"enterprise-workspace-core\"\n : \"sql-workspace\",\n governance:\n scope === \"workspace\" && index === 0 ? \"required\" : \"inherited\",\n };\n }\n if (scope.startsWith(\"personal\")) {\n return {\n provenance: normalizedPath === \"memory/MEMORY.md\" ? \"memory\" : \"personal\",\n governance: \"user\",\n };\n }\n if (scope.startsWith(\"app-default\")) {\n return { provenance: \"legacy-app-default\", governance: \"inherited\" };\n }\n if (scope.startsWith(\"organization\")) {\n return { provenance: \"organization\", governance: \"inherited\" };\n }\n if (scope.startsWith(\"shared\")) {\n return {\n provenance:\n normalizedPath === \"LEARNINGS.md\"\n ? \"organization\"\n : \"legacy-app-default\",\n governance: \"inherited\",\n };\n }\n return { provenance: \"template\", governance: \"inherited\" };\n}\n\n/**\n * Extracts bounded-in-memory metadata from the already-composed resource\n * prompt. The caller turns these inputs into hashed/previews before anything\n * is persisted; this helper never writes or returns the full manifest.\n */\nexport function promptResourceManifestSections(\n prompt: string,\n): PromptResourceManifestSection[] {\n const sections: PromptResourceManifestSection[] = [];\n const resourcePattern = /<resource\\b([^>]*)>([\\s\\S]*?)<\\/resource>/g;\n let match: RegExpExecArray | null;\n let workspaceIndex = 0;\n let sharedIndex = 0;\n while ((match = resourcePattern.exec(prompt))) {\n const attrs = match[1] ?? \"\";\n const scope = xmlAttribute(attrs, \"scope\") ?? \"resource\";\n const path =\n xmlAttribute(attrs, \"path\") ?? xmlAttribute(attrs, \"name\") ?? \"\";\n const name = xmlAttribute(attrs, \"name\") ?? (path || \"resource\");\n const index = scope.startsWith(\"workspace\")\n ? workspaceIndex++\n : scope.startsWith(\"shared\")\n ? sharedIndex++\n : 0;\n const classification = resourceManifestClassification(scope, path, index);\n sections.push({\n label: name,\n ...classification,\n content: match[2] ?? \"\",\n sourceRef: {\n ...(path ? { path } : {}),\n scope,\n },\n });\n }\n\n const taggedSections = [\n {\n tag: \"skills-summary\",\n label: \"Workspace skills index\",\n provenance: \"template\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"resource-skills\",\n label: \"Workspace resource skills\",\n provenance: \"template\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"instruction-resources\",\n label: \"Instruction resources index\",\n provenance: \"sql-workspace\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"workspace-resources\",\n label: \"Workspace reference resources\",\n provenance: \"sql-workspace\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"context-note\",\n label: \"Resource availability note\",\n provenance: \"framework-core\" as const,\n governance: \"required\" as const,\n },\n {\n tag: \"context-budget-note\",\n label: \"Context budget note\",\n provenance: \"framework-core\" as const,\n governance: \"required\" as const,\n },\n {\n tag: \"available-apps\",\n label: \"Available workspace apps\",\n provenance: \"tools\" as const,\n governance: \"required\" as const,\n },\n ];\n for (const tagged of taggedSections) {\n const pattern = new RegExp(\n `<${tagged.tag}\\\\b[^>]*>([\\\\s\\\\S]*?)</${tagged.tag}>`,\n \"g\",\n );\n let taggedMatch: RegExpExecArray | null;\n while ((taggedMatch = pattern.exec(prompt))) {\n const taggedAttrs =\n taggedMatch[0]?.slice(tagged.tag.length + 1).split(\">\")[0] ?? \"\";\n const taggedScope = xmlAttribute(taggedAttrs, \"scope\");\n const taggedClassification =\n tagged.tag === \"instruction-resources\" && taggedScope\n ? resourceManifestClassification(taggedScope, \"\", 0)\n : {\n provenance: tagged.provenance,\n governance: tagged.governance,\n };\n sections.push({\n label: tagged.label,\n ...taggedClassification,\n content: taggedMatch[1] ?? \"\",\n ...(taggedScope ? { sourceRef: { scope: taggedScope } } : {}),\n });\n }\n }\n return sections;\n}\n\nfunction resourceToolHint(\n action: \"list\" | \"read\" | \"effective\" | \"write\" | \"delete\" | \"promote\",\n extra?: string,\n): string {\n return `Use the \\`resources\\` tool with \\`action: \"${action}\"\\`${extra ? `, ${extra}` : \"\"}.`;\n}\n\nfunction skillDocsSlug(name: string): string {\n return `skill-${name\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")}`;\n}\n\nfunction ensureSentence(value: string): string {\n const trimmed = value.trim();\n if (!trimmed) return \"\";\n return /[.!?]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\n\nfunction escapeXmlAttribute(value: string): string {\n return value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n}\n\nfunction truncatePromptResourceContent(\n content: string,\n path: string,\n maxChars = SHARED_PROMPT_RESOURCE_MAX_CHARS,\n readHint?: string,\n): string {\n const trimmed = content.trim();\n if (trimmed.length <= maxChars) return trimmed;\n const omitted = trimmed.length - maxChars;\n const hint =\n readHint ??\n resourceToolHint(\n \"read\",\n `\\`path: \"${path}\"\\` and the resource's \\`scope\\` for the full content`,\n );\n return `${trimmed.slice(0, maxChars)}\\n\\n[Resource ${path} truncated after ${maxChars.toLocaleString()} characters; ${omitted.toLocaleString()} characters omitted. ${hint}]`;\n}\n\nfunction promptResourceBlock(input: {\n name: string;\n scope: string;\n content: string;\n path?: string;\n maxChars?: number;\n readHint?: string;\n}): string | null {\n const normalizedPath = input.path\n ? normalizeResourcePathForPrompt(input.path)\n : undefined;\n const content = truncatePromptResourceContent(\n input.content,\n normalizedPath ?? input.name,\n input.maxChars,\n input.readHint,\n );\n if (!content) return null;\n const pathAttr = normalizedPath\n ? ` path=\"${escapeXmlAttribute(normalizedPath)}\"`\n : \"\";\n return `<resource name=\"${escapeXmlAttribute(input.name)}\" scope=\"${escapeXmlAttribute(input.scope)}\"${pathAttr}>\\n${content}\\n</resource>`;\n}\n\nfunction selectPromptSectionsWithinBudget(\n sections: string[],\n maxChars: number,\n): string[] {\n const omissionNote = `<context-budget-note>Some startup context sections were omitted to keep the first model request responsive. Use \\`resources\\` with \\`action: \"list\"\\` or \\`\"read\"\\`, \\`docs-search\\`, and \\`tool-search\\` to retrieve relevant depth on demand.</context-budget-note>`;\n const contentBudget = Math.max(0, maxChars - omissionNote.length - 2);\n const selected: string[] = [];\n let used = 0;\n let omitted = 0;\n\n for (const section of sections) {\n const separatorChars = selected.length > 0 ? 2 : 0;\n if (used + separatorChars + section.length <= contentBudget) {\n selected.push(section);\n used += separatorChars + section.length;\n } else {\n omitted++;\n }\n }\n\n if (omitted > 0) selected.push(omissionNote);\n return selected;\n}\n\nfunction isAutoLoadedInstructionPath(path: string): boolean {\n const normalized = normalizeResourcePathForPrompt(path);\n return normalized.startsWith(\"instructions/\") && normalized.endsWith(\".md\");\n}\n\nfunction isSpecialPromptResourcePath(path: string): boolean {\n const normalized = normalizeResourcePathForPrompt(path);\n return (\n normalized === \"AGENTS.md\" ||\n normalized === \"LEARNINGS.md\" ||\n normalized.startsWith(\"instructions/\") ||\n normalized.startsWith(\"skills/\") ||\n normalized.startsWith(\"agents/\") ||\n normalized.startsWith(\"remote-agents/\") ||\n normalized.startsWith(\"jobs/\") ||\n normalized.startsWith(\"memory/\")\n );\n}\n\nfunction isTextLikeResource(mimeType: string): boolean {\n return (\n mimeType.startsWith(\"text/\") ||\n mimeType === \"application/json\" ||\n mimeType === \"application/yaml\" ||\n mimeType === \"application/x-yaml\"\n );\n}\n\nfunction getResourceSummaryFromContent(content: string): string | null {\n const frontmatter = parseFrontmatter(content);\n const title =\n getFrontmatterValue(frontmatter, \"title\") ||\n getFrontmatterValue(frontmatter, \"name\");\n const description = getFrontmatterValue(frontmatter, \"description\");\n if (title && description) return `${title}: ${description}`;\n if (title) return title;\n if (description) return description;\n\n const heading = content\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find((line) => /^#{1,3}\\s+\\S/.test(line));\n if (heading) return heading.replace(/^#{1,3}\\s+/, \"\").trim();\n return null;\n}\n\nexport function resourceScopeForOwner(\n owner: string,\n currentOwner?: string,\n): string {\n if (owner === WORKSPACE_OWNER) return \"workspace\";\n if (owner === SHARED_OWNER || organizationIdFromResourceOwner(owner)) {\n return \"shared\";\n }\n if (currentOwner && owner === currentOwner) return \"personal\";\n return \"resource\";\n}\n\nasync function loadAgentsResourceForPrompt(\n owner: string,\n scope: string,\n maxChars = SHARED_PROMPT_RESOURCE_MAX_CHARS,\n): Promise<string | null> {\n try {\n const agents = await resourceGetByPath(owner, \"AGENTS.md\");\n if (!agents?.content?.trim()) return null;\n return promptResourceBlock({\n name: \"AGENTS.md\",\n scope,\n path: \"AGENTS.md\",\n content: agents.content,\n maxChars,\n });\n } catch {\n return null;\n }\n}\n\nasync function loadInstructionResourcesForPrompt(\n owner: string,\n scope: string,\n maxChars = SHARED_PROMPT_RESOURCE_MAX_CHARS,\n summaryOnly = false,\n): Promise<string[]> {\n try {\n const resources = await resourceList(owner, \"instructions/\");\n const sorted = resources\n .filter((resource) => isAutoLoadedInstructionPath(resource.path))\n .sort((a, b) => a.path.localeCompare(b.path));\n\n if (summaryOnly) {\n if (sorted.length === 0) return [];\n const resourceScope = scope.startsWith(\"workspace\")\n ? \"workspace\"\n : scope.startsWith(\"personal\")\n ? \"personal\"\n : \"shared\";\n const listed = sorted.slice(0, PROMPT_INSTRUCTION_SUMMARY_LIMIT);\n const lines = listed.map(\n (resource) =>\n `- \\`${resource.path}\\` - ${resourceToolHint(\"read\", `\\`path: \"${resource.path}\"\\` and \\`scope: \"${resourceScope}\"\\` when it applies`)}`,\n );\n if (sorted.length > listed.length) {\n lines.push(\n `- ...${sorted.length - listed.length} more instruction files. ${resourceToolHint(\"list\", `\\`scope: \"${resourceScope}\"\\` and \\`prefix: \"instructions/\"\\``)}`,\n );\n }\n return [\n `<instruction-resources scope=\"${escapeXmlAttribute(scope)}\">\\nDetailed instruction files are loaded on demand so the first model request stays compact. Read a relevant file before following its workflow.\\n\\n${lines.join(\"\\n\")}\\n</instruction-resources>`,\n ];\n }\n\n const fullResources = await Promise.all(\n sorted.map((resource) => resourceGet(resource.id).catch(() => null)),\n );\n const blocks: string[] = [];\n for (let index = 0; index < sorted.length; index++) {\n const resource = sorted[index]!;\n const full = fullResources[index];\n if (!full?.content?.trim()) continue;\n const block = promptResourceBlock({\n name: resource.path,\n scope,\n path: resource.path,\n content: full.content,\n maxChars,\n });\n if (block) blocks.push(block);\n }\n return blocks;\n } catch {\n return [];\n }\n}\n\nasync function loadResourceSkillsPromptBlock(\n owner: string,\n orgId?: string | null,\n): Promise<string | null> {\n try {\n const organizationOwner = sharedResourceOwner(orgId);\n const resources =\n owner === SHARED_OWNER\n ? [\n ...(await resourceList(SHARED_OWNER, \"skills/\")),\n ...(await resourceList(WORKSPACE_OWNER, \"skills/\")),\n ]\n : await resourceListAccessible(owner, \"skills/\", { orgId });\n const sorted = resources.sort((a, b) => {\n const ownerOrder =\n (a.owner === owner\n ? 0\n : a.owner === organizationOwner\n ? 1\n : a.owner === SHARED_OWNER\n ? 2\n : a.owner === WORKSPACE_OWNER\n ? 3\n : 4) -\n (b.owner === owner\n ? 0\n : b.owner === organizationOwner\n ? 1\n : b.owner === SHARED_OWNER\n ? 2\n : b.owner === WORKSPACE_OWNER\n ? 3\n : 4);\n if (ownerOrder !== 0) return ownerOrder;\n return a.path.localeCompare(b.path);\n });\n const skillCandidates = sorted.slice(0, PROMPT_SKILL_METADATA_READ_LIMIT);\n const loaded = await Promise.all(\n skillCandidates.map(async (resource) => ({\n resource,\n full: await resourceGet(resource.id).catch(() => null),\n })),\n );\n const seen = new Set<string>();\n const lines: string[] = [];\n for (const { resource, full } of loaded) {\n if (!full?.content) continue;\n const meta = parseSkillFrontmatter(full.content);\n if (meta.userInvocable === false) continue;\n if (meta.scope === \"dev\") continue;\n const name = meta.name || getSkillNameFromPath(resource.path);\n if (!name || seen.has(name)) continue;\n seen.add(name);\n const scope = resourceScopeForOwner(resource.owner, owner);\n const description = compactPromptLine(\n meta.description || \"(no description)\",\n PROMPT_SUMMARY_DESCRIPTION_MAX_CHARS,\n );\n lines.push(\n `- \\`${name}\\` at resource \\`${resource.path}\\` (${scope}) - ${ensureSentence(description)} ${resourceToolHint(\n \"read\",\n `\\`path: \"${resource.path}\"\\` and \\`scope: \"${scope}\"\\` before starting a task it applies to`,\n )}`,\n );\n if (lines.length >= PROMPT_SKILL_SUMMARY_LIMIT) break;\n }\n if (lines.length === 0) return null;\n if (\n sorted.length > skillCandidates.length ||\n loaded.length > PROMPT_SKILL_SUMMARY_LIMIT\n ) {\n lines.push(\n `- ...more skills omitted from the startup summary. ${resourceToolHint(\"list\", '`prefix: \"skills/\"` to inspect the full catalog')}`,\n );\n }\n return `<resource-skills>\\nThe following workspace skills are available in addition to codebase skills. They may come from SQL resources, Dispatch workspace resources, or local file mode. Read a matching skill before starting a task it applies to.\\n\\n${lines.join(\"\\n\")}\\n</resource-skills>`;\n } catch {\n return null;\n }\n}\n\nasync function loadResourceIndexForPrompt(\n owner: string,\n scope: \"workspace\" | \"shared\",\n): Promise<string | null> {\n try {\n const resources = (await resourceList(owner))\n .filter(\n (resource) =>\n !isSpecialPromptResourcePath(resource.path) &&\n isTextLikeResource(resource.mimeType),\n )\n .sort((a, b) => a.path.localeCompare(b.path));\n if (resources.length === 0) return null;\n\n const listed = resources.slice(0, SHARED_RESOURCE_INDEX_LIMIT);\n const lines: string[] = [];\n const fullResources = await Promise.all(\n listed.map((resource) => resourceGet(resource.id).catch(() => null)),\n );\n for (let index = 0; index < listed.length; index++) {\n const resource = listed[index]!;\n const full = fullResources[index];\n const summary = full?.content\n ? getResourceSummaryFromContent(full.content)\n : null;\n lines.push(`- \\`${resource.path}\\`${summary ? ` - ${summary}` : \"\"}`);\n }\n if (resources.length > listed.length) {\n lines.push(\n `- ...${resources.length - listed.length} more ${scope} resources. ${resourceToolHint(\n \"list\",\n `\\`scope: \"${scope}\"\\` to inspect them`,\n )}`,\n );\n }\n\n const label =\n scope === \"workspace\"\n ? \"Workspace reference resources are inherited by every app and are available for company, brand, positioning, persona, product, or domain context.\"\n : \"Shared app/organization reference resources are available for app-specific or team context.\";\n return `<workspace-resources scope=\"${scope}\">\\n${label} ${resourceToolHint(\n \"read\",\n `\\`path: <path>\\` and \\`scope: \"${scope}\"\\` when a task may depend on them`,\n )} Do not assume their contents without reading the relevant file.\\n\\n${lines.join(\"\\n\")}\\n</workspace-resources>`;\n } catch {\n return null;\n }\n}\n\n/**\n * Pre-load the agent's context: AGENTS.md (workspace/template/runtime\n * instructions), the skills index, shared LEARNINGS.md (team notes), a shared\n * resource index, and memory/MEMORY.md (personal structured memory index).\n * These all get appended to the system prompt so the agent has everything it\n * needs from the first turn.\n *\n * Six sources are layered:\n *\n * 1. `<workspace>` — AGENTS.md from the enterprise workspace core.\n * 2. `<template>` — AGENTS.md + skills index from the Vite plugin bundle.\n * 3. `<workspace>` — SQL workspace AGENTS.md and instructions/*.md.\n * Runtime global defaults managed from Dispatch and inherited by apps.\n * 4. `<app-default>` — legacy app-wide SQL defaults.\n * 5. `<shared>` — organization AGENTS.md, instructions, and LEARNINGS.md.\n * These are isolated by active org and override app/workspace defaults.\n * 6. `<personal>` — memory/MEMORY.md from the SQL personal scope. The\n * current user's structured memory index.\n *\n * Each source is read independently — no copying between them. Editing\n * AGENTS.md and restarting the server is all it takes; Vite HMR invalidates\n * the bundle in dev so changes land instantly.\n */\nexport async function loadResourcesForPrompt(\n owner: string,\n compact = false,\n selfAppId?: string,\n orgId: string | null = getRequestOrgId() ?? null,\n): Promise<string> {\n await ensurePersonalDefaults(owner);\n\n const sections: string[] = [];\n const promptResourceMaxChars = compact\n ? COMPACT_PROMPT_RESOURCE_MAX_CHARS\n : SHARED_PROMPT_RESOURCE_MAX_CHARS;\n\n // 1. Workspace AGENTS.md + skills merged into the template bundle.\n try {\n const { loadAgentsBundle, generateSkillsPromptBlock, getRuntimeSkills } =\n await import(\"../agents-bundle.js\");\n const bundle = await loadAgentsBundle();\n\n // Workspace-core AGENTS.md (enterprise-wide instructions), if present.\n if (bundle.workspaceAgentsMd && bundle.workspaceAgentsMd.trim()) {\n const block = promptResourceBlock({\n name: \"AGENTS.md\",\n scope: \"workspace\",\n path: \"AGENTS.md\",\n content: bundle.workspaceAgentsMd,\n maxChars: promptResourceMaxChars,\n readHint:\n 'Use docs-search --slug \"agents-workspace\" to read the full workspace AGENTS.md.',\n });\n if (block) sections.push(block);\n }\n\n // 2. Template AGENTS.md — always included (critical template instructions).\n if (bundle.agentsMd.trim()) {\n const block = promptResourceBlock({\n name: \"AGENTS.md\",\n scope: \"template\",\n path: \"AGENTS.md\",\n content: bundle.agentsMd,\n maxChars: promptResourceMaxChars,\n readHint:\n 'Use docs-search --slug \"agents-template\" to read the full template AGENTS.md.',\n });\n if (block) sections.push(block);\n }\n\n // In compact mode, skip the full skills block — the agent can use\n // `docs-search` to find skills when it needs them. Either way, `scope: dev`\n // skills are excluded: they're for the human's coding agent, not runtime.\n const runtimeSkills = getRuntimeSkills(bundle);\n if (!compact) {\n const skillsBlock = generateSkillsPromptBlock(bundle);\n if (skillsBlock) sections.push(skillsBlock);\n } else if (runtimeSkills.length > 0) {\n const listedSkills = runtimeSkills.slice(0, PROMPT_SKILL_SUMMARY_LIMIT);\n const lines = listedSkills.map((s) => {\n const description = s.meta.description?.trim()\n ? ` - ${ensureSentence(compactPromptLine(s.meta.description, PROMPT_SUMMARY_DESCRIPTION_MAX_CHARS))}`\n : \"\";\n return `- \\`${s.meta.name}\\`${description} Read with \\`docs-search --slug \"${skillDocsSlug(s.meta.name)}\"\\` before starting a task it applies to.`;\n });\n if (runtimeSkills.length > listedSkills.length) {\n lines.push(\n `- ...${runtimeSkills.length - listedSkills.length} more codebase skills. Use \\`docs-search --query \"<topic>\"\\` to discover the relevant one.`,\n );\n }\n sections.push(\n `<skills-summary>\\nCodebase skills bundled from \\`.agents/skills/\\` (or legacy \\`.agent/skills/\\`) are available as docs-search pages. Do not use MCP resource reads for these skills.\\n\\n${lines.join(\"\\n\")}\\n</skills-summary>`,\n );\n }\n } catch {}\n\n // 3. Runtime workspace resources. These are global defaults inherited by\n // every app in the workspace, not copied into app scopes. They may come from\n // SQL, Dispatch, or local file mode.\n const workspaceAgents = await loadAgentsResourceForPrompt(\n WORKSPACE_OWNER,\n \"workspace\",\n promptResourceMaxChars,\n );\n if (workspaceAgents) sections.push(workspaceAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n WORKSPACE_OWNER,\n \"workspace-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n\n const organizationOwner = sharedResourceOwner(orgId);\n\n // 4. Legacy app-wide defaults. Existing deployments keep their seeded\n // shared guidance as an inherited fallback; organization writes never\n // mutate this owner.\n const appDefaultAgents = await loadAgentsResourceForPrompt(\n SHARED_OWNER,\n organizationOwner === SHARED_OWNER ? \"shared\" : \"app-default\",\n promptResourceMaxChars,\n );\n if (appDefaultAgents) sections.push(appDefaultAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n SHARED_OWNER,\n organizationOwner === SHARED_OWNER\n ? \"shared-instruction\"\n : \"app-default-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n\n // 5. Active organization resources. These are the durable team rules and\n // learnings that Slack/integration runs share with interactive app chat.\n if (organizationOwner !== SHARED_OWNER) {\n const organizationAgents = await loadAgentsResourceForPrompt(\n organizationOwner,\n \"organization\",\n promptResourceMaxChars,\n );\n if (organizationAgents) sections.push(organizationAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n organizationOwner,\n \"organization-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n }\n\n // 6. Personal SQL resources. These come last in the instruction stack so a\n // user can narrow or override organization/app and workspace defaults.\n if (owner !== SHARED_OWNER && owner !== WORKSPACE_OWNER) {\n const personalAgents = await loadAgentsResourceForPrompt(\n owner,\n \"personal\",\n promptResourceMaxChars,\n );\n if (personalAgents) sections.push(personalAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n owner,\n \"personal-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n }\n\n const resourceSkillsBlock = await loadResourceSkillsPromptBlock(owner, orgId);\n if (resourceSkillsBlock) sections.push(resourceSkillsBlock);\n\n let sharedLearnings: Awaited<ReturnType<typeof resourceGetByPath>> = null;\n try {\n sharedLearnings =\n (organizationOwner !== SHARED_OWNER\n ? await resourceGetByPath(organizationOwner, \"LEARNINGS.md\")\n : null) ?? (await resourceGetByPath(SHARED_OWNER, \"LEARNINGS.md\"));\n } catch {}\n\n if (compact) {\n // Integration/Slack turns use compact context, but organization learnings\n // are operational routing input, not optional background. Preload the\n // bounded shared file so canonical destinations/fields are available on\n // the first turn; keep personal memory on-demand to preserve the compact\n // budget.\n if (sharedLearnings?.content?.trim()) {\n const block = promptResourceBlock({\n name: \"LEARNINGS.md\",\n scope: \"shared\",\n path: \"LEARNINGS.md\",\n content: sharedLearnings.content,\n maxChars: COMPACT_PROMPT_RESOURCE_MAX_CHARS,\n });\n if (block) sections.push(block);\n }\n sections.push(\n `<context-note>Organization learnings above and your personal memory (memory/MEMORY.md) are available via the \\`resources\\` tool. Save durable team facts and routing conventions to shared LEARNINGS.md; keep personal preferences in save-memory.</context-note>`,\n );\n } else {\n // LEARNINGS.md from SQL (template-level instructions are in AGENTS.md\n // above). Capped like every other prompt resource — an unbounded team\n // notes file would otherwise inline in full on every non-lazy request.\n if (sharedLearnings?.content?.trim()) {\n const block = promptResourceBlock({\n name: \"LEARNINGS.md\",\n scope: \"shared\",\n path: \"LEARNINGS.md\",\n content: sharedLearnings.content,\n maxChars: SHARED_PROMPT_RESOURCE_MAX_CHARS,\n });\n if (block) sections.push(block);\n }\n\n // 3. Personal memory index (skip if owner is the shared sentinel).\n // Same cap as LEARNINGS.md — a large personal MEMORY.md index must not\n // inline without bound just because this request opted out of lazy\n // context.\n if (owner !== SHARED_OWNER) {\n try {\n const memoryIndex = await resourceGetByPath(owner, \"memory/MEMORY.md\");\n if (memoryIndex?.content?.trim()) {\n const block = promptResourceBlock({\n name: \"memory/MEMORY.md\",\n scope: \"personal\",\n path: \"memory/MEMORY.md\",\n content: memoryIndex.content,\n maxChars: SHARED_PROMPT_RESOURCE_MAX_CHARS,\n });\n if (block) sections.push(block);\n }\n } catch {}\n }\n }\n\n const workspaceResourceIndex = await loadResourceIndexForPrompt(\n WORKSPACE_OWNER,\n \"workspace\",\n );\n if (workspaceResourceIndex) sections.push(workspaceResourceIndex);\n\n const appDefaultResourceIndex = await loadResourceIndexForPrompt(\n SHARED_OWNER,\n \"shared\",\n );\n if (appDefaultResourceIndex) sections.push(appDefaultResourceIndex);\n if (organizationOwner !== SHARED_OWNER) {\n const organizationResourceIndex = await loadResourceIndexForPrompt(\n organizationOwner,\n \"shared\",\n );\n if (organizationResourceIndex) sections.push(organizationResourceIndex);\n }\n\n try {\n const agents = (await discoverAgents(selfAppId)).slice(0, 30);\n if (agents.length > 0) {\n const lines = agents.map(\n (agent) =>\n `- ${agent.name} (${agent.id}) — ${agent.description || \"Connected A2A app\"}`,\n );\n sections.push(\n `<available-apps>\\nWorkspace apps available over A2A/call-agent:\\n${lines.join(\"\\n\")}\\n\\nUse \\`call-agent\\` with the app id when another app owns the work or data. Use tool-search or app-specific actions for details only when needed.\\n</available-apps>`,\n );\n }\n } catch {\n // Agent discovery is helpful context, not required for the run.\n }\n\n if (sections.length === 0) return \"\";\n const selectedSections = compact\n ? selectPromptSectionsWithinBudget(\n sections,\n COMPACT_PROMPT_RESOURCES_TOTAL_MAX_CHARS,\n )\n : sections;\n return (\n \"\\n\\nThe following resources contain template-specific instructions and user context. Use the information in them to help the user.\\n\\n\" +\n selectedSections.join(\"\\n\\n\")\n );\n}\n"]}
1
+ {"version":3,"file":"prompt-resources.js","sourceRoot":"","sources":["../../../src/server/agent-chat/prompt-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,8EAA8E;AAC9E,uEAAuE;AACvE,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,8EAA8E;AAE9E,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAChD,MAAM,CAAC,MAAM,iCAAiC,GAAG,KAAK,CAAC;AACvD,MAAM,wCAAwC,GAAG,MAAM,CAAC;AACxD,MAAM,iCAAiC,GAAG,KAAK,CAAC;AA4BhD,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAiC,CAAC;AAExE,4EAA4E;AAC5E,MAAM,UAAU,6BAA6B,CAC3C,QAA+B;IAE/B,MAAM,EAAE,GAAG,QAAQ,CAAC,E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C,IAAI,CACX,GAAG,CAAC,MAAM,+BAA+B,CAAC;QACxC,KAAK;QACL,OAAO;QACP,SAAS;QACT,KAAK;KACN,CAAC,CAAC,CACJ,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CACtB,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC,WAAW,IAAI,mBAAmB,EAAE,CAChF,CAAC;YACF,QAAQ,CAAC,IAAI,CACX,oEAAoE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,yKAAyK,CAC9P,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,gEAAgE;IAClE,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,gBAAgB,GAAG,OAAO;QAC9B,CAAC,CAAC,gCAAgC,CAC9B,QAAQ,EACR,wCAAwC,CACzC;QACH,CAAC,CAAC,QAAQ,CAAC;IACb,OAAO,CACL,wIAAwI;QACxI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import {\n getFrontmatterValue,\n getSkillNameFromPath,\n parseFrontmatter,\n} from \"../../resources/metadata.js\";\nimport {\n ensurePersonalDefaults,\n organizationIdFromResourceOwner,\n resourceGet,\n resourceGetByPath,\n resourceList,\n resourceListAccessible,\n SHARED_OWNER,\n sharedResourceOwner,\n WORKSPACE_OWNER,\n} from \"../../resources/store.js\";\nimport type {\n ContextGovernanceTier,\n ContextManifestSourceRef,\n ContextSystemProvenance,\n} from \"../../shared/context-xray.js\";\nimport { discoverAgents } from \"../agent-discovery.js\";\nimport { getRequestOrgId } from \"../request-context.js\";\nimport { parseSkillFrontmatter } from \"./skill-frontmatter.js\";\n\n// ---------------------------------------------------------------------------\n// System-prompt resource loading: AGENTS.md, instructions/*.md, skills\n// summaries, and the shared/workspace resource index. Assembled by\n// `loadResourcesForPrompt`, the top-level orchestrator called once per\n// request to build the \"here's what you should know\" context block.\n// ---------------------------------------------------------------------------\n\nconst SHARED_PROMPT_RESOURCE_MAX_CHARS = 30_000;\nexport const COMPACT_PROMPT_RESOURCE_MAX_CHARS = 6_000;\nconst COMPACT_PROMPT_RESOURCES_TOTAL_MAX_CHARS = 48_000;\nconst PROMPT_CONTEXT_PROVIDER_MAX_CHARS = 8_000;\n\nexport interface PromptContextProviderContext {\n owner: string;\n compact: boolean;\n selfAppId?: string;\n orgId: string | null;\n}\n\nexport interface PromptContextProviderContribution {\n content: string;\n label?: string;\n provenance?: ContextSystemProvenance;\n governance?: ContextGovernanceTier;\n sourceRef?: ContextManifestSourceRef;\n}\n\nexport interface PromptContextProvider {\n id: string;\n load(\n context: PromptContextProviderContext,\n ):\n | Promise<PromptContextProviderContribution | null | undefined>\n | PromptContextProviderContribution\n | null\n | undefined;\n}\n\nconst promptContextProviders = new Map<string, PromptContextProvider>();\n\n/** Register a package-owned, request-scoped system-context contribution. */\nexport function registerPromptContextProvider(\n provider: PromptContextProvider,\n): () => void {\n const id = provider.id.trim();\n if (!/^[a-z][a-z0-9-]{1,63}$/.test(id)) {\n throw new Error(\n \"Prompt context provider ids must be 2-64 lowercase letters, digits, or hyphens\",\n );\n }\n const registered = { ...provider, id };\n promptContextProviders.set(id, registered);\n return () => {\n if (promptContextProviders.get(id) === registered) {\n promptContextProviders.delete(id);\n }\n };\n}\n\nfunction xmlAttributeEscape(value: string): string {\n return value\n .replace(/&/g, \"&amp;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n\nasync function loadPromptContextProviderBlocks(\n context: PromptContextProviderContext,\n): Promise<string[]> {\n const providers = [...promptContextProviders.values()].sort((a, b) =>\n a.id.localeCompare(b.id),\n );\n const settled = await Promise.allSettled(\n providers.map(async (provider) => ({\n provider,\n contribution: await provider.load(context),\n })),\n );\n const blocks: string[] = [];\n for (const result of settled) {\n if (result.status !== \"fulfilled\") continue;\n const { provider, contribution } = result.value;\n if (!contribution) continue;\n const content = contribution.content.trim();\n if (!content) continue;\n const boundedContent =\n content.length <= PROMPT_CONTEXT_PROVIDER_MAX_CHARS\n ? content\n : `${content.slice(0, PROMPT_CONTEXT_PROVIDER_MAX_CHARS)}\\n[truncated after ${PROMPT_CONTEXT_PROVIDER_MAX_CHARS.toLocaleString()} characters]`;\n const label = contribution.label?.trim() || provider.id;\n const provenance = contribution.provenance ?? \"runtime-context\";\n const governance = contribution.governance ?? \"inherited\";\n const sourceScope = contribution.sourceRef?.scope?.trim() || \"provider\";\n const sourcePath = contribution.sourceRef?.path?.trim() || provider.id;\n blocks.push(\n `<prompt-context-provider id=\"${xmlAttributeEscape(provider.id)}\" label=\"${xmlAttributeEscape(label)}\" provenance=\"${provenance}\" governance=\"${governance}\" scope=\"${xmlAttributeEscape(sourceScope)}\" path=\"${xmlAttributeEscape(sourcePath)}\">\\n${boundedContent.replace(/<\\/prompt-context-provider>/gi, \"&lt;/prompt-context-provider&gt;\")}\\n</prompt-context-provider>`,\n );\n }\n return blocks;\n}\n\nexport function compactPromptLine(value: string, maxChars: number): string {\n const line = value.replace(/\\s+/g, \" \").trim();\n if (line.length <= maxChars) return line;\n return `${line.slice(0, maxChars - 1)}…`;\n}\nconst SHARED_RESOURCE_INDEX_LIMIT = 40;\nconst PROMPT_SKILL_SUMMARY_LIMIT = 40;\nconst PROMPT_SKILL_METADATA_READ_LIMIT = 80;\nconst PROMPT_INSTRUCTION_SUMMARY_LIMIT = 20;\nconst PROMPT_SUMMARY_DESCRIPTION_MAX_CHARS = 180;\n\nexport interface PromptResourceManifestSection {\n label: string;\n provenance: ContextSystemProvenance;\n governance: ContextGovernanceTier;\n content: string;\n sourceRef?: ContextManifestSourceRef;\n}\n\nfunction normalizeResourcePathForPrompt(path: string): string {\n return path.replace(/^\\/+/, \"\").trim();\n}\n\nfunction xmlAttribute(attrs: string, name: string): string | undefined {\n const match = new RegExp(`\\\\b${name}=\"([^\"]*)\"`).exec(attrs);\n return match?.[1];\n}\n\nfunction resourceManifestClassification(\n scope: string,\n path: string,\n index: number,\n): {\n provenance: ContextSystemProvenance;\n governance: ContextGovernanceTier;\n} {\n const normalizedPath = normalizeResourcePathForPrompt(path);\n if (scope === \"template\") {\n return { provenance: \"template\", governance: \"inherited\" };\n }\n if (scope.startsWith(\"workspace\")) {\n return {\n provenance:\n scope === \"workspace\" && index === 0\n ? \"enterprise-workspace-core\"\n : \"sql-workspace\",\n governance:\n scope === \"workspace\" && index === 0 ? \"required\" : \"inherited\",\n };\n }\n if (scope.startsWith(\"personal\")) {\n return {\n provenance: normalizedPath === \"memory/MEMORY.md\" ? \"memory\" : \"personal\",\n governance: \"user\",\n };\n }\n if (scope.startsWith(\"app-default\")) {\n return { provenance: \"legacy-app-default\", governance: \"inherited\" };\n }\n if (scope.startsWith(\"organization\")) {\n return { provenance: \"organization\", governance: \"inherited\" };\n }\n if (scope.startsWith(\"shared\")) {\n return {\n provenance:\n normalizedPath === \"LEARNINGS.md\"\n ? \"organization\"\n : \"legacy-app-default\",\n governance: \"inherited\",\n };\n }\n return { provenance: \"template\", governance: \"inherited\" };\n}\n\n/**\n * Extracts bounded-in-memory metadata from the already-composed resource\n * prompt. The caller turns these inputs into hashed/previews before anything\n * is persisted; this helper never writes or returns the full manifest.\n */\nexport function promptResourceManifestSections(\n prompt: string,\n): PromptResourceManifestSection[] {\n const sections: PromptResourceManifestSection[] = [];\n const resourcePattern = /<resource\\b([^>]*)>([\\s\\S]*?)<\\/resource>/g;\n let match: RegExpExecArray | null;\n let workspaceIndex = 0;\n let sharedIndex = 0;\n while ((match = resourcePattern.exec(prompt))) {\n const attrs = match[1] ?? \"\";\n const scope = xmlAttribute(attrs, \"scope\") ?? \"resource\";\n const path =\n xmlAttribute(attrs, \"path\") ?? xmlAttribute(attrs, \"name\") ?? \"\";\n const name = xmlAttribute(attrs, \"name\") ?? (path || \"resource\");\n const index = scope.startsWith(\"workspace\")\n ? workspaceIndex++\n : scope.startsWith(\"shared\")\n ? sharedIndex++\n : 0;\n const classification = resourceManifestClassification(scope, path, index);\n sections.push({\n label: name,\n ...classification,\n content: match[2] ?? \"\",\n sourceRef: {\n ...(path ? { path } : {}),\n scope,\n },\n });\n }\n\n const providerPattern =\n /<prompt-context-provider\\b([^>]*)>([\\s\\S]*?)<\\/prompt-context-provider>/g;\n while ((match = providerPattern.exec(prompt))) {\n const attrs = match[1] ?? \"\";\n const id = xmlAttribute(attrs, \"id\") ?? \"prompt-context-provider\";\n const label = xmlAttribute(attrs, \"label\") ?? id;\n const provenanceValue = xmlAttribute(attrs, \"provenance\");\n const governanceValue = xmlAttribute(attrs, \"governance\");\n const provenance = (\n [\n \"framework-core\",\n \"actions-prompt\",\n \"template\",\n \"enterprise-workspace-core\",\n \"sql-workspace\",\n \"legacy-app-default\",\n \"organization\",\n \"personal\",\n \"memory\",\n \"db-schema\",\n \"tools\",\n \"model-overlay\",\n \"runtime-context\",\n ] as const\n ).includes(provenanceValue as ContextSystemProvenance)\n ? (provenanceValue as ContextSystemProvenance)\n : \"runtime-context\";\n const governance = ([\"required\", \"inherited\", \"user\"] as const).includes(\n governanceValue as ContextGovernanceTier,\n )\n ? (governanceValue as ContextGovernanceTier)\n : \"inherited\";\n sections.push({\n label,\n provenance,\n governance,\n content: match[2] ?? \"\",\n sourceRef: {\n path: xmlAttribute(attrs, \"path\") ?? id,\n scope: xmlAttribute(attrs, \"scope\") ?? \"provider\",\n },\n });\n }\n\n const taggedSections = [\n {\n tag: \"skills-summary\",\n label: \"Workspace skills index\",\n provenance: \"template\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"resource-skills\",\n label: \"Workspace resource skills\",\n provenance: \"template\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"instruction-resources\",\n label: \"Instruction resources index\",\n provenance: \"sql-workspace\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"workspace-resources\",\n label: \"Workspace reference resources\",\n provenance: \"sql-workspace\" as const,\n governance: \"inherited\" as const,\n },\n {\n tag: \"context-note\",\n label: \"Resource availability note\",\n provenance: \"framework-core\" as const,\n governance: \"required\" as const,\n },\n {\n tag: \"context-budget-note\",\n label: \"Context budget note\",\n provenance: \"framework-core\" as const,\n governance: \"required\" as const,\n },\n {\n tag: \"available-apps\",\n label: \"Available workspace apps\",\n provenance: \"tools\" as const,\n governance: \"required\" as const,\n },\n ];\n for (const tagged of taggedSections) {\n const pattern = new RegExp(\n `<${tagged.tag}\\\\b[^>]*>([\\\\s\\\\S]*?)</${tagged.tag}>`,\n \"g\",\n );\n let taggedMatch: RegExpExecArray | null;\n while ((taggedMatch = pattern.exec(prompt))) {\n const taggedAttrs =\n taggedMatch[0]?.slice(tagged.tag.length + 1).split(\">\")[0] ?? \"\";\n const taggedScope = xmlAttribute(taggedAttrs, \"scope\");\n const taggedClassification =\n tagged.tag === \"instruction-resources\" && taggedScope\n ? resourceManifestClassification(taggedScope, \"\", 0)\n : {\n provenance: tagged.provenance,\n governance: tagged.governance,\n };\n sections.push({\n label: tagged.label,\n ...taggedClassification,\n content: taggedMatch[1] ?? \"\",\n ...(taggedScope ? { sourceRef: { scope: taggedScope } } : {}),\n });\n }\n }\n return sections;\n}\n\nfunction resourceToolHint(\n action: \"list\" | \"read\" | \"effective\" | \"write\" | \"delete\" | \"promote\",\n extra?: string,\n): string {\n return `Use the \\`resources\\` tool with \\`action: \"${action}\"\\`${extra ? `, ${extra}` : \"\"}.`;\n}\n\nfunction skillDocsSlug(name: string): string {\n return `skill-${name\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")}`;\n}\n\nfunction ensureSentence(value: string): string {\n const trimmed = value.trim();\n if (!trimmed) return \"\";\n return /[.!?]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\n\nfunction escapeXmlAttribute(value: string): string {\n return value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n}\n\nfunction truncatePromptResourceContent(\n content: string,\n path: string,\n maxChars = SHARED_PROMPT_RESOURCE_MAX_CHARS,\n readHint?: string,\n): string {\n const trimmed = content.trim();\n if (trimmed.length <= maxChars) return trimmed;\n const omitted = trimmed.length - maxChars;\n const hint =\n readHint ??\n resourceToolHint(\n \"read\",\n `\\`path: \"${path}\"\\` and the resource's \\`scope\\` for the full content`,\n );\n return `${trimmed.slice(0, maxChars)}\\n\\n[Resource ${path} truncated after ${maxChars.toLocaleString()} characters; ${omitted.toLocaleString()} characters omitted. ${hint}]`;\n}\n\nfunction promptResourceBlock(input: {\n name: string;\n scope: string;\n content: string;\n path?: string;\n maxChars?: number;\n readHint?: string;\n}): string | null {\n const normalizedPath = input.path\n ? normalizeResourcePathForPrompt(input.path)\n : undefined;\n const content = truncatePromptResourceContent(\n input.content,\n normalizedPath ?? input.name,\n input.maxChars,\n input.readHint,\n );\n if (!content) return null;\n const pathAttr = normalizedPath\n ? ` path=\"${escapeXmlAttribute(normalizedPath)}\"`\n : \"\";\n return `<resource name=\"${escapeXmlAttribute(input.name)}\" scope=\"${escapeXmlAttribute(input.scope)}\"${pathAttr}>\\n${content}\\n</resource>`;\n}\n\nfunction selectPromptSectionsWithinBudget(\n sections: string[],\n maxChars: number,\n): string[] {\n const omissionNote = `<context-budget-note>Some startup context sections were omitted to keep the first model request responsive. Use \\`resources\\` with \\`action: \"list\"\\` or \\`\"read\"\\`, \\`docs-search\\`, and \\`tool-search\\` to retrieve relevant depth on demand.</context-budget-note>`;\n const contentBudget = Math.max(0, maxChars - omissionNote.length - 2);\n const selected: string[] = [];\n let used = 0;\n let omitted = 0;\n\n for (const section of sections) {\n const separatorChars = selected.length > 0 ? 2 : 0;\n if (used + separatorChars + section.length <= contentBudget) {\n selected.push(section);\n used += separatorChars + section.length;\n } else {\n omitted++;\n }\n }\n\n if (omitted > 0) selected.push(omissionNote);\n return selected;\n}\n\nfunction isAutoLoadedInstructionPath(path: string): boolean {\n const normalized = normalizeResourcePathForPrompt(path);\n return normalized.startsWith(\"instructions/\") && normalized.endsWith(\".md\");\n}\n\nfunction isSpecialPromptResourcePath(path: string): boolean {\n const normalized = normalizeResourcePathForPrompt(path);\n return (\n normalized === \"AGENTS.md\" ||\n normalized === \"LEARNINGS.md\" ||\n normalized.startsWith(\"instructions/\") ||\n normalized.startsWith(\"skills/\") ||\n normalized.startsWith(\"agents/\") ||\n normalized.startsWith(\"remote-agents/\") ||\n normalized.startsWith(\"jobs/\") ||\n normalized.startsWith(\"memory/\")\n );\n}\n\nfunction isTextLikeResource(mimeType: string): boolean {\n return (\n mimeType.startsWith(\"text/\") ||\n mimeType === \"application/json\" ||\n mimeType === \"application/yaml\" ||\n mimeType === \"application/x-yaml\"\n );\n}\n\nfunction getResourceSummaryFromContent(content: string): string | null {\n const frontmatter = parseFrontmatter(content);\n const title =\n getFrontmatterValue(frontmatter, \"title\") ||\n getFrontmatterValue(frontmatter, \"name\");\n const description = getFrontmatterValue(frontmatter, \"description\");\n if (title && description) return `${title}: ${description}`;\n if (title) return title;\n if (description) return description;\n\n const heading = content\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find((line) => /^#{1,3}\\s+\\S/.test(line));\n if (heading) return heading.replace(/^#{1,3}\\s+/, \"\").trim();\n return null;\n}\n\nexport function resourceScopeForOwner(\n owner: string,\n currentOwner?: string,\n): string {\n if (owner === WORKSPACE_OWNER) return \"workspace\";\n if (owner === SHARED_OWNER || organizationIdFromResourceOwner(owner)) {\n return \"shared\";\n }\n if (currentOwner && owner === currentOwner) return \"personal\";\n return \"resource\";\n}\n\nasync function loadAgentsResourceForPrompt(\n owner: string,\n scope: string,\n maxChars = SHARED_PROMPT_RESOURCE_MAX_CHARS,\n): Promise<string | null> {\n try {\n const agents = await resourceGetByPath(owner, \"AGENTS.md\");\n if (!agents?.content?.trim()) return null;\n return promptResourceBlock({\n name: \"AGENTS.md\",\n scope,\n path: \"AGENTS.md\",\n content: agents.content,\n maxChars,\n });\n } catch {\n return null;\n }\n}\n\nasync function loadInstructionResourcesForPrompt(\n owner: string,\n scope: string,\n maxChars = SHARED_PROMPT_RESOURCE_MAX_CHARS,\n summaryOnly = false,\n): Promise<string[]> {\n try {\n const resources = await resourceList(owner, \"instructions/\");\n const sorted = resources\n .filter((resource) => isAutoLoadedInstructionPath(resource.path))\n .sort((a, b) => a.path.localeCompare(b.path));\n\n if (summaryOnly) {\n if (sorted.length === 0) return [];\n const resourceScope = scope.startsWith(\"workspace\")\n ? \"workspace\"\n : scope.startsWith(\"personal\")\n ? \"personal\"\n : \"shared\";\n const listed = sorted.slice(0, PROMPT_INSTRUCTION_SUMMARY_LIMIT);\n const lines = listed.map(\n (resource) =>\n `- \\`${resource.path}\\` - ${resourceToolHint(\"read\", `\\`path: \"${resource.path}\"\\` and \\`scope: \"${resourceScope}\"\\` when it applies`)}`,\n );\n if (sorted.length > listed.length) {\n lines.push(\n `- ...${sorted.length - listed.length} more instruction files. ${resourceToolHint(\"list\", `\\`scope: \"${resourceScope}\"\\` and \\`prefix: \"instructions/\"\\``)}`,\n );\n }\n return [\n `<instruction-resources scope=\"${escapeXmlAttribute(scope)}\">\\nDetailed instruction files are loaded on demand so the first model request stays compact. Read a relevant file before following its workflow.\\n\\n${lines.join(\"\\n\")}\\n</instruction-resources>`,\n ];\n }\n\n const fullResources = await Promise.all(\n sorted.map((resource) => resourceGet(resource.id).catch(() => null)),\n );\n const blocks: string[] = [];\n for (let index = 0; index < sorted.length; index++) {\n const resource = sorted[index]!;\n const full = fullResources[index];\n if (!full?.content?.trim()) continue;\n const block = promptResourceBlock({\n name: resource.path,\n scope,\n path: resource.path,\n content: full.content,\n maxChars,\n });\n if (block) blocks.push(block);\n }\n return blocks;\n } catch {\n return [];\n }\n}\n\nasync function loadResourceSkillsPromptBlock(\n owner: string,\n orgId?: string | null,\n): Promise<string | null> {\n try {\n const organizationOwner = sharedResourceOwner(orgId);\n const resources =\n owner === SHARED_OWNER\n ? [\n ...(await resourceList(SHARED_OWNER, \"skills/\")),\n ...(await resourceList(WORKSPACE_OWNER, \"skills/\")),\n ]\n : await resourceListAccessible(owner, \"skills/\", { orgId });\n const sorted = resources.sort((a, b) => {\n const ownerOrder =\n (a.owner === owner\n ? 0\n : a.owner === organizationOwner\n ? 1\n : a.owner === SHARED_OWNER\n ? 2\n : a.owner === WORKSPACE_OWNER\n ? 3\n : 4) -\n (b.owner === owner\n ? 0\n : b.owner === organizationOwner\n ? 1\n : b.owner === SHARED_OWNER\n ? 2\n : b.owner === WORKSPACE_OWNER\n ? 3\n : 4);\n if (ownerOrder !== 0) return ownerOrder;\n return a.path.localeCompare(b.path);\n });\n const skillCandidates = sorted.slice(0, PROMPT_SKILL_METADATA_READ_LIMIT);\n const loaded = await Promise.all(\n skillCandidates.map(async (resource) => ({\n resource,\n full: await resourceGet(resource.id).catch(() => null),\n })),\n );\n const seen = new Set<string>();\n const lines: string[] = [];\n for (const { resource, full } of loaded) {\n if (!full?.content) continue;\n const meta = parseSkillFrontmatter(full.content);\n if (meta.userInvocable === false) continue;\n if (meta.scope === \"dev\") continue;\n const name = meta.name || getSkillNameFromPath(resource.path);\n if (!name || seen.has(name)) continue;\n seen.add(name);\n const scope = resourceScopeForOwner(resource.owner, owner);\n const description = compactPromptLine(\n meta.description || \"(no description)\",\n PROMPT_SUMMARY_DESCRIPTION_MAX_CHARS,\n );\n lines.push(\n `- \\`${name}\\` at resource \\`${resource.path}\\` (${scope}) - ${ensureSentence(description)} ${resourceToolHint(\n \"read\",\n `\\`path: \"${resource.path}\"\\` and \\`scope: \"${scope}\"\\` before starting a task it applies to`,\n )}`,\n );\n if (lines.length >= PROMPT_SKILL_SUMMARY_LIMIT) break;\n }\n if (lines.length === 0) return null;\n if (\n sorted.length > skillCandidates.length ||\n loaded.length > PROMPT_SKILL_SUMMARY_LIMIT\n ) {\n lines.push(\n `- ...more skills omitted from the startup summary. ${resourceToolHint(\"list\", '`prefix: \"skills/\"` to inspect the full catalog')}`,\n );\n }\n return `<resource-skills>\\nThe following workspace skills are available in addition to codebase skills. They may come from SQL resources, Dispatch workspace resources, or local file mode. Read a matching skill before starting a task it applies to.\\n\\n${lines.join(\"\\n\")}\\n</resource-skills>`;\n } catch {\n return null;\n }\n}\n\nasync function loadResourceIndexForPrompt(\n owner: string,\n scope: \"workspace\" | \"shared\",\n): Promise<string | null> {\n try {\n const resources = (await resourceList(owner))\n .filter(\n (resource) =>\n !isSpecialPromptResourcePath(resource.path) &&\n isTextLikeResource(resource.mimeType),\n )\n .sort((a, b) => a.path.localeCompare(b.path));\n if (resources.length === 0) return null;\n\n const listed = resources.slice(0, SHARED_RESOURCE_INDEX_LIMIT);\n const lines: string[] = [];\n const fullResources = await Promise.all(\n listed.map((resource) => resourceGet(resource.id).catch(() => null)),\n );\n for (let index = 0; index < listed.length; index++) {\n const resource = listed[index]!;\n const full = fullResources[index];\n const summary = full?.content\n ? getResourceSummaryFromContent(full.content)\n : null;\n lines.push(`- \\`${resource.path}\\`${summary ? ` - ${summary}` : \"\"}`);\n }\n if (resources.length > listed.length) {\n lines.push(\n `- ...${resources.length - listed.length} more ${scope} resources. ${resourceToolHint(\n \"list\",\n `\\`scope: \"${scope}\"\\` to inspect them`,\n )}`,\n );\n }\n\n const label =\n scope === \"workspace\"\n ? \"Workspace reference resources are inherited by every app and are available for company, brand, positioning, persona, product, or domain context.\"\n : \"Shared app/organization reference resources are available for app-specific or team context.\";\n return `<workspace-resources scope=\"${scope}\">\\n${label} ${resourceToolHint(\n \"read\",\n `\\`path: <path>\\` and \\`scope: \"${scope}\"\\` when a task may depend on them`,\n )} Do not assume their contents without reading the relevant file.\\n\\n${lines.join(\"\\n\")}\\n</workspace-resources>`;\n } catch {\n return null;\n }\n}\n\n/**\n * Pre-load the agent's context: AGENTS.md (workspace/template/runtime\n * instructions), the skills index, shared LEARNINGS.md (team notes), a shared\n * resource index, and memory/MEMORY.md (personal structured memory index).\n * These all get appended to the system prompt so the agent has everything it\n * needs from the first turn.\n *\n * Six sources are layered:\n *\n * 1. `<workspace>` — AGENTS.md from the enterprise workspace core.\n * 2. `<template>` — AGENTS.md + skills index from the Vite plugin bundle.\n * 3. `<workspace>` — SQL workspace AGENTS.md and instructions/*.md.\n * Runtime global defaults managed from Dispatch and inherited by apps.\n * 4. `<app-default>` — legacy app-wide SQL defaults.\n * 5. `<shared>` — organization AGENTS.md, instructions, and LEARNINGS.md.\n * These are isolated by active org and override app/workspace defaults.\n * 6. `<personal>` — memory/MEMORY.md from the SQL personal scope. The\n * current user's structured memory index.\n *\n * Each source is read independently — no copying between them. Editing\n * AGENTS.md and restarting the server is all it takes; Vite HMR invalidates\n * the bundle in dev so changes land instantly.\n */\nexport async function loadResourcesForPrompt(\n owner: string,\n compact = false,\n selfAppId?: string,\n orgId: string | null = getRequestOrgId() ?? null,\n): Promise<string> {\n await ensurePersonalDefaults(owner);\n\n const sections: string[] = [];\n const promptResourceMaxChars = compact\n ? COMPACT_PROMPT_RESOURCE_MAX_CHARS\n : SHARED_PROMPT_RESOURCE_MAX_CHARS;\n\n // 1. Workspace AGENTS.md + skills merged into the template bundle.\n try {\n const { loadAgentsBundle, generateSkillsPromptBlock, getRuntimeSkills } =\n await import(\"../agents-bundle.js\");\n const bundle = await loadAgentsBundle();\n\n // Workspace-core AGENTS.md (enterprise-wide instructions), if present.\n if (bundle.workspaceAgentsMd && bundle.workspaceAgentsMd.trim()) {\n const block = promptResourceBlock({\n name: \"AGENTS.md\",\n scope: \"workspace\",\n path: \"AGENTS.md\",\n content: bundle.workspaceAgentsMd,\n maxChars: promptResourceMaxChars,\n readHint:\n 'Use docs-search --slug \"agents-workspace\" to read the full workspace AGENTS.md.',\n });\n if (block) sections.push(block);\n }\n\n // 2. Template AGENTS.md — always included (critical template instructions).\n if (bundle.agentsMd.trim()) {\n const block = promptResourceBlock({\n name: \"AGENTS.md\",\n scope: \"template\",\n path: \"AGENTS.md\",\n content: bundle.agentsMd,\n maxChars: promptResourceMaxChars,\n readHint:\n 'Use docs-search --slug \"agents-template\" to read the full template AGENTS.md.',\n });\n if (block) sections.push(block);\n }\n\n // In compact mode, skip the full skills block — the agent can use\n // `docs-search` to find skills when it needs them. Either way, `scope: dev`\n // skills are excluded: they're for the human's coding agent, not runtime.\n const runtimeSkills = getRuntimeSkills(bundle);\n if (!compact) {\n const skillsBlock = generateSkillsPromptBlock(bundle);\n if (skillsBlock) sections.push(skillsBlock);\n } else if (runtimeSkills.length > 0) {\n const listedSkills = runtimeSkills.slice(0, PROMPT_SKILL_SUMMARY_LIMIT);\n const lines = listedSkills.map((s) => {\n const description = s.meta.description?.trim()\n ? ` - ${ensureSentence(compactPromptLine(s.meta.description, PROMPT_SUMMARY_DESCRIPTION_MAX_CHARS))}`\n : \"\";\n return `- \\`${s.meta.name}\\`${description} Read with \\`docs-search --slug \"${skillDocsSlug(s.meta.name)}\"\\` before starting a task it applies to.`;\n });\n if (runtimeSkills.length > listedSkills.length) {\n lines.push(\n `- ...${runtimeSkills.length - listedSkills.length} more codebase skills. Use \\`docs-search --query \"<topic>\"\\` to discover the relevant one.`,\n );\n }\n sections.push(\n `<skills-summary>\\nCodebase skills bundled from \\`.agents/skills/\\` (or legacy \\`.agent/skills/\\`) are available as docs-search pages. Do not use MCP resource reads for these skills.\\n\\n${lines.join(\"\\n\")}\\n</skills-summary>`,\n );\n }\n } catch {}\n\n // 3. Runtime workspace resources. These are global defaults inherited by\n // every app in the workspace, not copied into app scopes. They may come from\n // SQL, Dispatch, or local file mode.\n const workspaceAgents = await loadAgentsResourceForPrompt(\n WORKSPACE_OWNER,\n \"workspace\",\n promptResourceMaxChars,\n );\n if (workspaceAgents) sections.push(workspaceAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n WORKSPACE_OWNER,\n \"workspace-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n\n const organizationOwner = sharedResourceOwner(orgId);\n\n // 4. Legacy app-wide defaults. Existing deployments keep their seeded\n // shared guidance as an inherited fallback; organization writes never\n // mutate this owner.\n const appDefaultAgents = await loadAgentsResourceForPrompt(\n SHARED_OWNER,\n organizationOwner === SHARED_OWNER ? \"shared\" : \"app-default\",\n promptResourceMaxChars,\n );\n if (appDefaultAgents) sections.push(appDefaultAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n SHARED_OWNER,\n organizationOwner === SHARED_OWNER\n ? \"shared-instruction\"\n : \"app-default-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n\n // 5. Active organization resources. These are the durable team rules and\n // learnings that Slack/integration runs share with interactive app chat.\n if (organizationOwner !== SHARED_OWNER) {\n const organizationAgents = await loadAgentsResourceForPrompt(\n organizationOwner,\n \"organization\",\n promptResourceMaxChars,\n );\n if (organizationAgents) sections.push(organizationAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n organizationOwner,\n \"organization-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n }\n\n // 6. Personal SQL resources. These come last in the instruction stack so a\n // user can narrow or override organization/app and workspace defaults.\n if (owner !== SHARED_OWNER && owner !== WORKSPACE_OWNER) {\n const personalAgents = await loadAgentsResourceForPrompt(\n owner,\n \"personal\",\n promptResourceMaxChars,\n );\n if (personalAgents) sections.push(personalAgents);\n sections.push(\n ...(await loadInstructionResourcesForPrompt(\n owner,\n \"personal-instruction\",\n promptResourceMaxChars,\n compact,\n )),\n );\n }\n\n const resourceSkillsBlock = await loadResourceSkillsPromptBlock(owner, orgId);\n if (resourceSkillsBlock) sections.push(resourceSkillsBlock);\n\n let sharedLearnings: Awaited<ReturnType<typeof resourceGetByPath>> = null;\n try {\n sharedLearnings =\n (organizationOwner !== SHARED_OWNER\n ? await resourceGetByPath(organizationOwner, \"LEARNINGS.md\")\n : null) ?? (await resourceGetByPath(SHARED_OWNER, \"LEARNINGS.md\"));\n } catch {}\n\n if (compact) {\n // Integration/Slack turns use compact context, but organization learnings\n // are operational routing input, not optional background. Preload the\n // bounded shared file so canonical destinations/fields are available on\n // the first turn; keep personal memory on-demand to preserve the compact\n // budget.\n if (sharedLearnings?.content?.trim()) {\n const block = promptResourceBlock({\n name: \"LEARNINGS.md\",\n scope: \"shared\",\n path: \"LEARNINGS.md\",\n content: sharedLearnings.content,\n maxChars: COMPACT_PROMPT_RESOURCE_MAX_CHARS,\n });\n if (block) sections.push(block);\n }\n sections.push(\n `<context-note>Organization learnings above and your personal memory (memory/MEMORY.md) are available via the \\`resources\\` tool. Save durable team facts and routing conventions to shared LEARNINGS.md; keep personal preferences in save-memory.</context-note>`,\n );\n } else {\n // LEARNINGS.md from SQL (template-level instructions are in AGENTS.md\n // above). Capped like every other prompt resource — an unbounded team\n // notes file would otherwise inline in full on every non-lazy request.\n if (sharedLearnings?.content?.trim()) {\n const block = promptResourceBlock({\n name: \"LEARNINGS.md\",\n scope: \"shared\",\n path: \"LEARNINGS.md\",\n content: sharedLearnings.content,\n maxChars: SHARED_PROMPT_RESOURCE_MAX_CHARS,\n });\n if (block) sections.push(block);\n }\n\n // 3. Personal memory index (skip if owner is the shared sentinel).\n // Same cap as LEARNINGS.md — a large personal MEMORY.md index must not\n // inline without bound just because this request opted out of lazy\n // context.\n if (owner !== SHARED_OWNER) {\n try {\n const memoryIndex = await resourceGetByPath(owner, \"memory/MEMORY.md\");\n if (memoryIndex?.content?.trim()) {\n const block = promptResourceBlock({\n name: \"memory/MEMORY.md\",\n scope: \"personal\",\n path: \"memory/MEMORY.md\",\n content: memoryIndex.content,\n maxChars: SHARED_PROMPT_RESOURCE_MAX_CHARS,\n });\n if (block) sections.push(block);\n }\n } catch {}\n }\n }\n\n const workspaceResourceIndex = await loadResourceIndexForPrompt(\n WORKSPACE_OWNER,\n \"workspace\",\n );\n if (workspaceResourceIndex) sections.push(workspaceResourceIndex);\n\n const appDefaultResourceIndex = await loadResourceIndexForPrompt(\n SHARED_OWNER,\n \"shared\",\n );\n if (appDefaultResourceIndex) sections.push(appDefaultResourceIndex);\n if (organizationOwner !== SHARED_OWNER) {\n const organizationResourceIndex = await loadResourceIndexForPrompt(\n organizationOwner,\n \"shared\",\n );\n if (organizationResourceIndex) sections.push(organizationResourceIndex);\n }\n\n sections.push(\n ...(await loadPromptContextProviderBlocks({\n owner,\n compact,\n selfAppId,\n orgId,\n })),\n );\n\n try {\n const agents = (await discoverAgents(selfAppId)).slice(0, 30);\n if (agents.length > 0) {\n const lines = agents.map(\n (agent) =>\n `- ${agent.name} (${agent.id}) — ${agent.description || \"Connected A2A app\"}`,\n );\n sections.push(\n `<available-apps>\\nWorkspace apps available over A2A/call-agent:\\n${lines.join(\"\\n\")}\\n\\nUse \\`call-agent\\` with the app id when another app owns the work or data. Use tool-search or app-specific actions for details only when needed.\\n</available-apps>`,\n );\n }\n } catch {\n // Agent discovery is helpful context, not required for the run.\n }\n\n if (sections.length === 0) return \"\";\n const selectedSections = compact\n ? selectPromptSectionsWithinBudget(\n sections,\n COMPACT_PROMPT_RESOURCES_TOTAL_MAX_CHARS,\n )\n : sections;\n return (\n \"\\n\\nThe following resources contain template-specific instructions and user context. Use the information in them to help the user.\\n\\n\" +\n selectedSections.join(\"\\n\\n\")\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat-plugin.d.ts","sourceRoot":"","sources":["../../src/server/agent-chat-plugin.ts"],"names":[],"mappings":"AA4IA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EACL,yBAAyB,EACzB,KAAK,6BAA6B,EACnC,MAAM,+BAA+B,CAAC;AAkCvC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AACrC,YAAY,EAAE,6BAA6B,EAAE,CAAC;AAuB9C,OAAO,EACL,0BAA0B,EAK1B,eAAe,EACf,eAAe,EACf,wBAA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AAE,cAAwC,CAAC;AAE9E,OAAO,EAEL,mBAAmB,EACnB,uBAAuB,EAGxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -256,6 +256,13 @@ export function createAgentChatPlugin(options) {
256
256
  // Filesystem discovery unavailable (serverless bundle) — skip.
257
257
  }
258
258
  }
259
+ try {
260
+ const { mergePackageActions } = await import("./action-discovery.js");
261
+ mergePackageActions(templateScriptsAll);
262
+ }
263
+ catch {
264
+ // Package action registration is optional.
265
+ }
259
266
  // Resource, chat, docs, db, and cross-agent scripts are available in both prod and dev modes
260
267
  const resourceScripts = await createResourceScriptEntries();
261
268
  const docsScripts = await createDocsScriptEntries();