@agent-native/core 0.113.0 → 0.114.1

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 (1638) hide show
  1. package/agent-native.eject.json +164 -0
  2. package/corpus/README.md +3 -3
  3. package/corpus/core/CHANGELOG.md +20 -0
  4. package/corpus/core/README.md +61 -174
  5. package/corpus/core/agent-native.eject.json +164 -0
  6. package/corpus/core/docs/content/agent-native-toolkit.mdx +38 -0
  7. package/corpus/core/docs/content/package-lifecycle.mdx +54 -4
  8. package/corpus/core/package.json +15 -2
  9. package/corpus/core/src/cli/eject.ts +1594 -0
  10. package/corpus/core/src/cli/index.ts +16 -0
  11. package/corpus/core/src/client/build-compatibility.ts +77 -0
  12. package/corpus/core/src/client/index.ts +4 -0
  13. package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +8 -2
  14. package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +7 -2
  15. package/corpus/core/src/client/resources/ResourcesPanel.tsx +17 -3
  16. package/corpus/core/src/client/resources/index.ts +19 -0
  17. package/corpus/core/src/client/resources/mcp-integration-catalog.ts +9 -1
  18. package/corpus/core/src/client/resources/runtime.ts +1 -0
  19. package/corpus/core/src/client/route-chunk-recovery/index.ts +1 -0
  20. package/corpus/core/src/client/setup-connections/catalog.ts +6 -0
  21. package/corpus/core/src/client/setup-connections/index.ts +1 -0
  22. package/corpus/core/src/client/setup-connections/runtime.ts +1 -0
  23. package/corpus/core/src/client/use-action.ts +32 -1
  24. package/corpus/core/src/connections/catalog.ts +41 -24
  25. package/corpus/core/src/connections/index.ts +1 -0
  26. package/corpus/core/src/connections/runtime.ts +1 -0
  27. package/corpus/core/src/deploy/build.ts +4 -1
  28. package/corpus/core/src/eject/provider-api-definitions.ts +193 -0
  29. package/corpus/core/src/eject/remote-mcp-presets.ts +137 -0
  30. package/corpus/core/src/eject/setup-readiness-ui.tsx +29 -0
  31. package/corpus/core/src/eject/workspace-connections.ts +92 -0
  32. package/corpus/core/src/index.ts +1 -0
  33. package/corpus/core/src/integrations/adapter-overrides.ts +12 -0
  34. package/corpus/core/src/integrations/eject/messaging-adapters.ts +85 -0
  35. package/corpus/core/src/integrations/index.ts +5 -1
  36. package/corpus/core/src/integrations/plugin.ts +34 -12
  37. package/corpus/core/src/integrations/runtime.ts +1 -0
  38. package/corpus/core/src/integrations/types.ts +3 -1
  39. package/corpus/core/src/org/context.ts +56 -30
  40. package/corpus/core/src/package-lifecycle/eject-manifest.ts +345 -0
  41. package/corpus/core/src/package-lifecycle/index.ts +1 -0
  42. package/corpus/core/src/provider-api/index.ts +46 -12
  43. package/corpus/core/src/provider-api/runtime.ts +1 -0
  44. package/corpus/core/src/server/action-routes.ts +52 -2
  45. package/corpus/core/src/server/auth-plugin.ts +9 -4
  46. package/corpus/core/src/server/better-auth-instance.ts +5 -1
  47. package/corpus/core/src/setup-connections/index.ts +1 -0
  48. package/corpus/core/src/shared/mcp-embed-headers.ts +1 -1
  49. package/corpus/core/src/shared/merge-by-id.ts +14 -0
  50. package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
  51. package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  52. package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
  53. package/corpus/core/src/templates/default/AGENTS.md +6 -5
  54. package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
  55. package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  56. package/corpus/core/src/templates/headless/AGENTS.md +5 -4
  57. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
  58. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
  59. package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  60. package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
  61. package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -4
  62. package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -4
  63. package/corpus/core/src/vite/client.ts +42 -2
  64. package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  65. package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +9 -6
  66. package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  67. package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +9 -6
  68. package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  69. package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +9 -6
  70. package/corpus/templates/brain/actions/remediate-legacy-capture-audiences.ts +167 -0
  71. package/corpus/templates/brain/app/lib/brain-chat-readiness.ts +6 -0
  72. package/corpus/templates/brain/app/routes/_index.tsx +8 -0
  73. package/corpus/templates/brain/app/routes.ts +1 -0
  74. package/corpus/templates/brain/changelog/2026-07-19-ask-starts-immediately-when-builder-s-managed-ai-connection-.md +6 -0
  75. package/corpus/templates/brain/changelog/2026-07-19-slack-and-granola-backfills-now-process-captures-concurrentl.md +6 -0
  76. package/corpus/templates/brain/changelog/2026-07-19-source-review-settings-now-control-knowledge-approval.md +6 -0
  77. package/corpus/templates/brain/changelog/2026-07-19-the-manage-agent-page-now-opens-correctly-from-brain-navigat.md +6 -0
  78. package/corpus/templates/brain/server/db/schema.ts +3 -0
  79. package/corpus/templates/brain/server/lib/brain.ts +41 -2
  80. package/corpus/templates/brain/server/lib/connectors.ts +379 -113
  81. package/corpus/templates/brain/server/lib/meeting-audience.ts +38 -0
  82. package/corpus/templates/brain/server/plugins/db.ts +10 -0
  83. package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +6 -4
  84. package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  85. package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +9 -6
  86. package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
  87. package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  88. package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
  89. package/corpus/templates/chat/AGENTS.md +3 -2
  90. package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  91. package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +9 -6
  92. package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  93. package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +9 -6
  94. package/corpus/templates/content/AGENTS.md +2 -0
  95. package/corpus/templates/content/actions/_content-database-personal-view.ts +49 -5
  96. package/corpus/templates/content/actions/_content-document-access.ts +21 -0
  97. package/corpus/templates/content/actions/_content-favorites.ts +91 -0
  98. package/corpus/templates/content/actions/_content-files.ts +79 -23
  99. package/corpus/templates/content/actions/_content-sidebar-state.ts +24 -0
  100. package/corpus/templates/content/actions/_content-space-access.ts +15 -17
  101. package/corpus/templates/content/actions/_content-space-catalog-guards.ts +20 -0
  102. package/corpus/templates/content/actions/_content-spaces.ts +364 -167
  103. package/corpus/templates/content/actions/_database-source-utils.ts +8 -0
  104. package/corpus/templates/content/actions/_database-utils.ts +249 -15
  105. package/corpus/templates/content/actions/_delete-content-space.ts +84 -0
  106. package/corpus/templates/content/actions/_files-system-properties.ts +499 -0
  107. package/corpus/templates/content/actions/_local-file-documents.ts +0 -1
  108. package/corpus/templates/content/actions/_property-utils.ts +18 -9
  109. package/corpus/templates/content/actions/bind-content-database-source-field.ts +3 -0
  110. package/corpus/templates/content/actions/configure-document-property.ts +3 -0
  111. package/corpus/templates/content/actions/create-content-database.ts +2 -2
  112. package/corpus/templates/content/actions/create-content-space.ts +34 -0
  113. package/corpus/templates/content/actions/create-document.ts +4 -1
  114. package/corpus/templates/content/actions/delete-content-space.ts +19 -0
  115. package/corpus/templates/content/actions/delete-database-items.ts +28 -1
  116. package/corpus/templates/content/actions/delete-document-property.ts +3 -0
  117. package/corpus/templates/content/actions/delete-document.ts +39 -2
  118. package/corpus/templates/content/actions/duplicate-database-item.ts +6 -0
  119. package/corpus/templates/content/actions/duplicate-database-items.ts +6 -0
  120. package/corpus/templates/content/actions/duplicate-document-property.ts +3 -0
  121. package/corpus/templates/content/actions/get-content-database.ts +11 -2
  122. package/corpus/templates/content/actions/get-content-sidebar-state.ts +23 -0
  123. package/corpus/templates/content/actions/get-document.ts +32 -7
  124. package/corpus/templates/content/actions/import-content-source.ts +33 -1
  125. package/corpus/templates/content/actions/list-content-spaces.ts +34 -2
  126. package/corpus/templates/content/actions/list-documents.ts +39 -7
  127. package/corpus/templates/content/actions/reorder-document-property.ts +9 -0
  128. package/corpus/templates/content/actions/set-document-property.ts +41 -23
  129. package/corpus/templates/content/actions/share-local-file-document.ts +15 -0
  130. package/corpus/templates/content/actions/submit-content-database-form.ts +7 -0
  131. package/corpus/templates/content/actions/sync-local-folder-source.ts +14 -0
  132. package/corpus/templates/content/actions/update-content-database-view.ts +1 -0
  133. package/corpus/templates/content/actions/update-content-sidebar-state.ts +27 -0
  134. package/corpus/templates/content/actions/update-document.ts +158 -66
  135. package/corpus/templates/content/app/components/EmptyState.tsx +4 -57
  136. package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +8 -1
  137. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +519 -178
  138. package/corpus/templates/content/app/components/editor/DocumentInfoPanel.tsx +39 -0
  139. package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +1 -1
  140. package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +266 -7
  141. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +430 -152
  142. package/corpus/templates/content/app/components/editor/database/sidebar.tsx +467 -66
  143. package/corpus/templates/content/app/components/editor/database/view-config.ts +9 -3
  144. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +720 -196
  145. package/corpus/templates/content/app/components/sidebar/DocumentTreeItem.tsx +173 -1
  146. package/corpus/templates/content/app/components/sidebar/document-sidebar-sections.ts +1 -1
  147. package/corpus/templates/content/app/components/sidebar/select-content-space.ts +91 -16
  148. package/corpus/templates/content/app/entry.client.tsx +5 -1
  149. package/corpus/templates/content/app/hooks/use-content-database.ts +84 -3
  150. package/corpus/templates/content/app/hooks/use-content-spaces.ts +60 -2
  151. package/corpus/templates/content/app/hooks/use-create-page.ts +30 -0
  152. package/corpus/templates/content/app/hooks/use-documents.ts +270 -19
  153. package/corpus/templates/content/app/i18n-data.ts +243 -20
  154. package/corpus/templates/content/app/lib/local-folder-picker-safety.ts +54 -0
  155. package/corpus/templates/content/app/lib/local-folder-picker-support.ts +18 -0
  156. package/corpus/templates/content/app/routes/_app.favorites.tsx +30 -0
  157. package/corpus/templates/content/app/routes/_app.local-files.tsx +18 -6
  158. package/corpus/templates/content/changelog/2026-07-17-workspace-files-now-stay-in-a-loading-state-until-automatic-.md +6 -0
  159. package/corpus/templates/content/changelog/2026-07-17-workspace-switching-now-opens-the-selected-files-database-pr.md +6 -0
  160. package/corpus/templates/content/changelog/2026-07-17-workspaces-now-expand-above-their-own-files-list-without-dup.md +6 -0
  161. package/corpus/templates/content/changelog/2026-07-18-create-named-workspaces-each-with-its-own-private-files-data.md +6 -0
  162. package/corpus/templates/content/changelog/2026-07-18-favorites-align-with-workspace-and-file-rows-in-the-sidebar.md +6 -0
  163. package/corpus/templates/content/changelog/2026-07-18-local-folder-selection-no-longer-invokes-the-unsafe-native-p.md +6 -0
  164. package/corpus/templates/content/changelog/2026-07-18-made-content-workspaces-independently-expandable-restored-or.md +6 -0
  165. package/corpus/templates/content/changelog/2026-07-18-page-details-now-live-in-a-shared-info-and-comments-rail-dat.md +6 -0
  166. package/corpus/templates/content/changelog/2026-07-18-workspace-database-views-now-control-sidebar-workspace-navig.md +6 -0
  167. package/corpus/templates/content/changelog/2026-07-18-workspace-navigation-now-aligns-favorites-with-workspace-pag.md +6 -0
  168. package/corpus/templates/content/changelog/2026-07-19-favorites-now-open-as-a-table-and-compact-breadcrumbs-make-w.md +6 -0
  169. package/corpus/templates/content/changelog/2026-07-19-files-databases-now-start-unfiltered-sidebar-rows-exactly-fo.md +6 -0
  170. package/corpus/templates/content/changelog/2026-07-19-sidebar-page-trees-now-open-only-when-expanded-remember-thei.md +6 -0
  171. package/corpus/templates/content/changelog/2026-07-19-workspace-file-databases-now-use-the-workspace-name-open-as-.md +6 -0
  172. package/corpus/templates/content/changelog/2026-07-19-workspace-navigation-now-stays-stable-on-hover-uses-folder-i.md +6 -0
  173. package/corpus/templates/content/changelog/2026-07-19-workspace-rows-now-use-folder-icons-and-deleting-a-user-crea.md +6 -0
  174. package/corpus/templates/content/changelog/2026-07-19-workspaces-can-be-created-without-leaving-the-workspaces-dat.md +6 -0
  175. package/corpus/templates/content/e2e/global-setup.ts +3 -2
  176. package/corpus/templates/content/parity/matrix.md +28 -28
  177. package/corpus/templates/content/parity/matrix.ts +8 -2
  178. package/corpus/templates/content/server/db/index.ts +1 -0
  179. package/corpus/templates/content/server/db/schema.ts +10 -0
  180. package/corpus/templates/content/server/lib/documents.ts +12 -7
  181. package/corpus/templates/content/server/plugins/db.ts +17 -0
  182. package/corpus/templates/content/shared/api.ts +9 -0
  183. package/corpus/templates/content/shared/database-form.ts +11 -2
  184. package/corpus/templates/content/vite.config.ts +1 -0
  185. package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  186. package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +9 -6
  187. package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  188. package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +9 -6
  189. package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  190. package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +9 -6
  191. package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  192. package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  193. package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +9 -6
  194. package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  195. package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +9 -6
  196. package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  197. package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +9 -6
  198. package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +15 -13
  199. package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  200. package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +9 -6
  201. package/corpus/toolkit/CHANGELOG.md +6 -0
  202. package/corpus/toolkit/agent-native.eject.json +411 -0
  203. package/corpus/toolkit/package.json +5 -2
  204. package/dist/cli/eject.d.ts +21 -0
  205. package/dist/cli/eject.d.ts.map +1 -0
  206. package/dist/cli/eject.js +1145 -0
  207. package/dist/cli/eject.js.map +1 -0
  208. package/dist/cli/index.js +15 -0
  209. package/dist/cli/index.js.map +1 -1
  210. package/dist/client/build-compatibility.d.ts +11 -0
  211. package/dist/client/build-compatibility.d.ts.map +1 -0
  212. package/dist/client/build-compatibility.js +56 -0
  213. package/dist/client/build-compatibility.js.map +1 -0
  214. package/dist/client/index.d.ts +1 -1
  215. package/dist/client/index.d.ts.map +1 -1
  216. package/dist/client/index.js +1 -1
  217. package/dist/client/index.js.map +1 -1
  218. package/dist/client/resources/McpConnectionSuggestion.d.ts +4 -3
  219. package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
  220. package/dist/client/resources/McpConnectionSuggestion.js +3 -3
  221. package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
  222. package/dist/client/resources/McpIntegrationDialog.d.ts +4 -3
  223. package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
  224. package/dist/client/resources/McpIntegrationDialog.js +2 -2
  225. package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
  226. package/dist/client/resources/ResourcesPanel.d.ts +4 -1
  227. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  228. package/dist/client/resources/ResourcesPanel.js +9 -7
  229. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  230. package/dist/client/resources/index.d.ts +3 -0
  231. package/dist/client/resources/index.d.ts.map +1 -1
  232. package/dist/client/resources/index.js +3 -0
  233. package/dist/client/resources/index.js.map +1 -1
  234. package/dist/client/resources/mcp-integration-catalog.d.ts +2 -1
  235. package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
  236. package/dist/client/resources/mcp-integration-catalog.js +6 -2
  237. package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
  238. package/dist/client/resources/runtime.d.ts +2 -0
  239. package/dist/client/resources/runtime.d.ts.map +1 -0
  240. package/dist/client/resources/runtime.js +2 -0
  241. package/dist/client/resources/runtime.js.map +1 -0
  242. package/dist/client/route-chunk-recovery/index.d.ts +1 -0
  243. package/dist/client/route-chunk-recovery/index.d.ts.map +1 -1
  244. package/dist/client/route-chunk-recovery/index.js +1 -0
  245. package/dist/client/route-chunk-recovery/index.js.map +1 -1
  246. package/dist/client/setup-connections/catalog.d.ts +2 -0
  247. package/dist/client/setup-connections/catalog.d.ts.map +1 -0
  248. package/dist/client/setup-connections/catalog.js +7 -0
  249. package/dist/client/setup-connections/catalog.js.map +1 -0
  250. package/dist/client/setup-connections/index.d.ts +1 -0
  251. package/dist/client/setup-connections/index.d.ts.map +1 -1
  252. package/dist/client/setup-connections/index.js +1 -0
  253. package/dist/client/setup-connections/index.js.map +1 -1
  254. package/dist/client/setup-connections/runtime.d.ts +2 -0
  255. package/dist/client/setup-connections/runtime.d.ts.map +1 -0
  256. package/dist/client/setup-connections/runtime.js +2 -0
  257. package/dist/client/setup-connections/runtime.js.map +1 -0
  258. package/dist/client/use-action.d.ts.map +1 -1
  259. package/dist/client/use-action.js +19 -1
  260. package/dist/client/use-action.js.map +1 -1
  261. package/dist/collab/awareness.d.ts +2 -2
  262. package/dist/collab/awareness.d.ts.map +1 -1
  263. package/dist/collab/struct-routes.d.ts +1 -1
  264. package/dist/connections/catalog.d.ts +5 -3
  265. package/dist/connections/catalog.d.ts.map +1 -1
  266. package/dist/connections/catalog.js +16 -8
  267. package/dist/connections/catalog.js.map +1 -1
  268. package/dist/connections/index.d.ts +1 -1
  269. package/dist/connections/index.d.ts.map +1 -1
  270. package/dist/connections/index.js +1 -1
  271. package/dist/connections/index.js.map +1 -1
  272. package/dist/connections/runtime.d.ts +2 -0
  273. package/dist/connections/runtime.d.ts.map +1 -0
  274. package/dist/connections/runtime.js +2 -0
  275. package/dist/connections/runtime.js.map +1 -0
  276. package/dist/deploy/build.js +2 -1
  277. package/dist/deploy/build.js.map +1 -1
  278. package/dist/eject/provider-api-definitions.d.ts +34 -0
  279. package/dist/eject/provider-api-definitions.d.ts.map +1 -0
  280. package/dist/eject/provider-api-definitions.js +88 -0
  281. package/dist/eject/provider-api-definitions.js.map +1 -0
  282. package/dist/eject/remote-mcp-presets.d.ts +17 -0
  283. package/dist/eject/remote-mcp-presets.d.ts.map +1 -0
  284. package/dist/eject/remote-mcp-presets.js +81 -0
  285. package/dist/eject/remote-mcp-presets.js.map +1 -0
  286. package/dist/eject/setup-readiness-ui.d.ts +7 -0
  287. package/dist/eject/setup-readiness-ui.d.ts.map +1 -0
  288. package/dist/eject/setup-readiness-ui.js +13 -0
  289. package/dist/eject/setup-readiness-ui.js.map +1 -0
  290. package/dist/eject/workspace-connections.d.ts +11 -0
  291. package/dist/eject/workspace-connections.d.ts.map +1 -0
  292. package/dist/eject/workspace-connections.js +47 -0
  293. package/dist/eject/workspace-connections.js.map +1 -0
  294. package/dist/file-upload/actions/upload-image.d.ts +1 -1
  295. package/dist/index.d.ts +1 -1
  296. package/dist/index.d.ts.map +1 -1
  297. package/dist/index.js +1 -1
  298. package/dist/index.js.map +1 -1
  299. package/dist/integrations/adapter-overrides.d.ts +3 -0
  300. package/dist/integrations/adapter-overrides.d.ts.map +1 -0
  301. package/dist/integrations/adapter-overrides.js +7 -0
  302. package/dist/integrations/adapter-overrides.js.map +1 -0
  303. package/dist/integrations/eject/messaging-adapters.d.ts +12 -0
  304. package/dist/integrations/eject/messaging-adapters.d.ts.map +1 -0
  305. package/dist/integrations/eject/messaging-adapters.js +49 -0
  306. package/dist/integrations/eject/messaging-adapters.js.map +1 -0
  307. package/dist/integrations/index.d.ts +3 -2
  308. package/dist/integrations/index.d.ts.map +1 -1
  309. package/dist/integrations/index.js +2 -1
  310. package/dist/integrations/index.js.map +1 -1
  311. package/dist/integrations/plugin.d.ts +32 -1
  312. package/dist/integrations/plugin.d.ts.map +1 -1
  313. package/dist/integrations/plugin.js +19 -12
  314. package/dist/integrations/plugin.js.map +1 -1
  315. package/dist/integrations/runtime.d.ts +2 -0
  316. package/dist/integrations/runtime.d.ts.map +1 -0
  317. package/dist/integrations/runtime.js +2 -0
  318. package/dist/integrations/runtime.js.map +1 -0
  319. package/dist/integrations/types.d.ts +3 -1
  320. package/dist/integrations/types.d.ts.map +1 -1
  321. package/dist/integrations/types.js.map +1 -1
  322. package/dist/notifications/routes.d.ts +2 -2
  323. package/dist/observability/routes.d.ts +5 -5
  324. package/dist/org/context.d.ts +4 -2
  325. package/dist/org/context.d.ts.map +1 -1
  326. package/dist/org/context.js +44 -22
  327. package/dist/org/context.js.map +1 -1
  328. package/dist/package-lifecycle/eject-manifest.d.ts +43 -0
  329. package/dist/package-lifecycle/eject-manifest.d.ts.map +1 -0
  330. package/dist/package-lifecycle/eject-manifest.js +219 -0
  331. package/dist/package-lifecycle/eject-manifest.js.map +1 -0
  332. package/dist/package-lifecycle/index.d.ts +1 -0
  333. package/dist/package-lifecycle/index.d.ts.map +1 -1
  334. package/dist/package-lifecycle/index.js +1 -0
  335. package/dist/package-lifecycle/index.js.map +1 -1
  336. package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
  337. package/dist/provider-api/actions/provider-api.d.ts +11 -11
  338. package/dist/provider-api/index.d.ts +6 -2
  339. package/dist/provider-api/index.d.ts.map +1 -1
  340. package/dist/provider-api/index.js +25 -12
  341. package/dist/provider-api/index.js.map +1 -1
  342. package/dist/provider-api/runtime.d.ts +2 -0
  343. package/dist/provider-api/runtime.d.ts.map +1 -0
  344. package/dist/provider-api/runtime.js +2 -0
  345. package/dist/provider-api/runtime.js.map +1 -0
  346. package/dist/resources/handlers.d.ts +1 -1
  347. package/dist/server/action-routes.d.ts.map +1 -1
  348. package/dist/server/action-routes.js +32 -2
  349. package/dist/server/action-routes.js.map +1 -1
  350. package/dist/server/auth-plugin.d.ts.map +1 -1
  351. package/dist/server/auth-plugin.js +9 -5
  352. package/dist/server/auth-plugin.js.map +1 -1
  353. package/dist/server/better-auth-instance.d.ts.map +1 -1
  354. package/dist/server/better-auth-instance.js +4 -1
  355. package/dist/server/better-auth-instance.js.map +1 -1
  356. package/dist/setup-connections/index.d.ts +1 -1
  357. package/dist/setup-connections/index.d.ts.map +1 -1
  358. package/dist/setup-connections/index.js +1 -1
  359. package/dist/setup-connections/index.js.map +1 -1
  360. package/dist/shared/mcp-embed-headers.d.ts +1 -1
  361. package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
  362. package/dist/shared/mcp-embed-headers.js +1 -1
  363. package/dist/shared/mcp-embed-headers.js.map +1 -1
  364. package/dist/shared/merge-by-id.d.ts +5 -0
  365. package/dist/shared/merge-by-id.d.ts.map +1 -0
  366. package/dist/shared/merge-by-id.js +7 -0
  367. package/dist/shared/merge-by-id.js.map +1 -0
  368. package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
  369. package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  370. package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
  371. package/dist/templates/chat/AGENTS.md +3 -2
  372. package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
  373. package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  374. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
  375. package/dist/templates/default/AGENTS.md +6 -5
  376. package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
  377. package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  378. package/dist/templates/headless/AGENTS.md +5 -4
  379. package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
  380. package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
  381. package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  382. package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
  383. package/dist/templates/workspace-core/AGENTS.md +4 -4
  384. package/dist/templates/workspace-root/AGENTS.md +4 -4
  385. package/dist/vite/client.d.ts +6 -0
  386. package/dist/vite/client.d.ts.map +1 -1
  387. package/dist/vite/client.js +30 -2
  388. package/dist/vite/client.js.map +1 -1
  389. package/docs/content/agent-native-toolkit.mdx +38 -0
  390. package/docs/content/package-lifecycle.mdx +54 -4
  391. package/package.json +15 -2
  392. package/src/a2a/agent-card.ts +83 -0
  393. package/src/a2a/artifact-response.ts +1648 -0
  394. package/src/a2a/auth-policy.ts +66 -0
  395. package/src/a2a/caller-auth.ts +102 -0
  396. package/src/a2a/client.ts +876 -0
  397. package/src/a2a/correlation.ts +50 -0
  398. package/src/a2a/handlers.ts +1285 -0
  399. package/src/a2a/index.ts +50 -0
  400. package/src/a2a/invoke.ts +348 -0
  401. package/src/a2a/response-text.ts +53 -0
  402. package/src/a2a/server.ts +586 -0
  403. package/src/a2a/task-store.ts +917 -0
  404. package/src/a2a/types.ts +221 -0
  405. package/src/a2a-claims.ts +52 -0
  406. package/src/action-change-marker.ts +74 -0
  407. package/src/action-ui.ts +38 -0
  408. package/src/action.ts +1406 -0
  409. package/src/adapters/cli/index.ts +6 -0
  410. package/src/adapters/cli/registry.ts +73 -0
  411. package/src/adapters/cli/shell-adapter.ts +92 -0
  412. package/src/adapters/cli/types.ts +27 -0
  413. package/src/agent/action-continuation-guidance.ts +38 -0
  414. package/src/agent/app-model-defaults.ts +201 -0
  415. package/src/agent/context-xray/actions/context-evict.ts +56 -0
  416. package/src/agent/context-xray/actions/context-manifest-get.ts +75 -0
  417. package/src/agent/context-xray/actions/context-pin.ts +56 -0
  418. package/src/agent/context-xray/actions/context-preview-get.ts +134 -0
  419. package/src/agent/context-xray/actions/context-report.ts +75 -0
  420. package/src/agent/context-xray/actions/context-restore.ts +51 -0
  421. package/src/agent/context-xray/actions/errors.ts +40 -0
  422. package/src/agent/context-xray/apply-directives.ts +137 -0
  423. package/src/agent/context-xray/directives-store.ts +178 -0
  424. package/src/agent/context-xray/identity.ts +37 -0
  425. package/src/agent/context-xray/manifest.ts +284 -0
  426. package/src/agent/context-xray/migrations.ts +32 -0
  427. package/src/agent/context-xray/plugin.ts +23 -0
  428. package/src/agent/context-xray/schema.ts +17 -0
  429. package/src/agent/context-xray/segments.ts +194 -0
  430. package/src/agent/context-xray/tokenize.ts +93 -0
  431. package/src/agent/default-model.ts +5 -0
  432. package/src/agent/durable-background.ts +547 -0
  433. package/src/agent/engine/ai-sdk-engine.ts +565 -0
  434. package/src/agent/engine/anthropic-engine.ts +320 -0
  435. package/src/agent/engine/builder-engine.ts +1110 -0
  436. package/src/agent/engine/builder-gateway-headers.ts +44 -0
  437. package/src/agent/engine/builtin.ts +122 -0
  438. package/src/agent/engine/context-directives-transform.ts +73 -0
  439. package/src/agent/engine/continuation-dispatch-retry.ts +168 -0
  440. package/src/agent/engine/credential-errors.ts +69 -0
  441. package/src/agent/engine/index.ts +54 -0
  442. package/src/agent/engine/openai-compatible-endpoint.ts +25 -0
  443. package/src/agent/engine/output-tokens.ts +181 -0
  444. package/src/agent/engine/provider-env-vars.ts +69 -0
  445. package/src/agent/engine/registry.ts +853 -0
  446. package/src/agent/engine/tool-call-journal-seed.ts +85 -0
  447. package/src/agent/engine/translate-ai-sdk.ts +407 -0
  448. package/src/agent/engine/translate-anthropic.ts +611 -0
  449. package/src/agent/engine/types.ts +310 -0
  450. package/src/agent/harness/acp-adapter.ts +893 -0
  451. package/src/agent/harness/acp-builtin.ts +70 -0
  452. package/src/agent/harness/ai-sdk-adapter.ts +509 -0
  453. package/src/agent/harness/background.ts +365 -0
  454. package/src/agent/harness/builtin.ts +50 -0
  455. package/src/agent/harness/index.ts +86 -0
  456. package/src/agent/harness/lifecycle.ts +498 -0
  457. package/src/agent/harness/registry.ts +97 -0
  458. package/src/agent/harness/runner.ts +182 -0
  459. package/src/agent/harness/store.ts +466 -0
  460. package/src/agent/harness/translate.ts +130 -0
  461. package/src/agent/harness/types.ts +129 -0
  462. package/src/agent/index.ts +32 -0
  463. package/src/agent/loop-settings.ts +186 -0
  464. package/src/agent/model-config.ts +363 -0
  465. package/src/agent/observational-memory/compactor.ts +78 -0
  466. package/src/agent/observational-memory/config.ts +78 -0
  467. package/src/agent/observational-memory/index.ts +79 -0
  468. package/src/agent/observational-memory/internal-run.ts +89 -0
  469. package/src/agent/observational-memory/message-text.ts +49 -0
  470. package/src/agent/observational-memory/migrations.ts +44 -0
  471. package/src/agent/observational-memory/observer.ts +128 -0
  472. package/src/agent/observational-memory/plugin.ts +35 -0
  473. package/src/agent/observational-memory/prompts.ts +53 -0
  474. package/src/agent/observational-memory/read.ts +131 -0
  475. package/src/agent/observational-memory/reflector.ts +119 -0
  476. package/src/agent/observational-memory/schema.ts +48 -0
  477. package/src/agent/observational-memory/store.ts +275 -0
  478. package/src/agent/observational-memory/types.ts +65 -0
  479. package/src/agent/processors.ts +209 -0
  480. package/src/agent/production-agent.ts +8254 -0
  481. package/src/agent/run-loop-with-resume.ts +394 -0
  482. package/src/agent/run-manager.ts +1825 -0
  483. package/src/agent/run-ownership.ts +75 -0
  484. package/src/agent/run-store.ts +2601 -0
  485. package/src/agent/runtime-context.ts +169 -0
  486. package/src/agent/thread-data-builder.ts +1584 -0
  487. package/src/agent/tool-call-journal.ts +368 -0
  488. package/src/agent/tool-error-redaction.ts +52 -0
  489. package/src/agent/tool-result-images.ts +178 -0
  490. package/src/agent/tool-search.ts +376 -0
  491. package/src/agent/types.ts +372 -0
  492. package/src/agent-native/index.ts +198 -0
  493. package/src/agent-web/config.ts +253 -0
  494. package/src/agent-web/generator.ts +382 -0
  495. package/src/agent-web/index.ts +36 -0
  496. package/src/appearance/actions/change-appearance.ts +35 -0
  497. package/src/application-state/emitter.ts +81 -0
  498. package/src/application-state/handlers.ts +121 -0
  499. package/src/application-state/index.ts +44 -0
  500. package/src/application-state/script-helpers.ts +155 -0
  501. package/src/application-state/store.ts +274 -0
  502. package/src/assets/branding/agent-native.icon/Assets/background.svg +3 -0
  503. package/src/assets/branding/agent-native.icon/Assets/foreground.svg +12 -0
  504. package/src/assets/branding/agent-native.icon/icon.json +49 -0
  505. package/src/assets/branding/favicon.png +0 -0
  506. package/src/assets/branding/favicon.svg +1 -0
  507. package/src/assets/branding/icon-on-dark.svg +10 -0
  508. package/src/assets/branding/icon-on-light.svg +10 -0
  509. package/src/assets/branding/mac-app-icon.svg +1 -0
  510. package/src/assets/branding/slack-bot/agent-native-1024.png +0 -0
  511. package/src/assets/branding/slack-bot/agent-native-512.png +0 -0
  512. package/src/assets/branding/tray-icon.svg +6 -0
  513. package/src/assets/branding/wordmark-on-dark.svg +21 -0
  514. package/src/assets/branding/wordmark-on-light.svg +21 -0
  515. package/src/assets/fonts/LICENSE_LIBERATION +96 -0
  516. package/src/assets/fonts/LICENSE_NOTO_NASKH_ARABIC +93 -0
  517. package/src/assets/fonts/LiberationSans-Bold.ttf +0 -0
  518. package/src/assets/fonts/LiberationSans-Regular.ttf +0 -0
  519. package/src/assets/fonts/NotoNaskhArabic-Variable.ttf +0 -0
  520. package/src/audit/actions/export-audit-events.ts +162 -0
  521. package/src/audit/actions/get-audit-event.ts +24 -0
  522. package/src/audit/actions/list-audit-events.ts +66 -0
  523. package/src/audit/cleanup-job.ts +100 -0
  524. package/src/audit/config.ts +90 -0
  525. package/src/audit/index.ts +43 -0
  526. package/src/audit/record.ts +180 -0
  527. package/src/audit/redact.ts +109 -0
  528. package/src/audit/store.ts +346 -0
  529. package/src/audit/types.ts +141 -0
  530. package/src/automation/index.ts +802 -0
  531. package/src/brand-kit/brand-signals.ts +124 -0
  532. package/src/brand-kit/fig/index.ts +64 -0
  533. package/src/brand-kit/index.ts +72 -0
  534. package/src/brand-kit/types.ts +113 -0
  535. package/src/browser-sessions/actions.ts +302 -0
  536. package/src/browser-sessions/routes.ts +234 -0
  537. package/src/browser-sessions/store.ts +679 -0
  538. package/src/browser-sessions/types.ts +84 -0
  539. package/src/changelog/parse.ts +328 -0
  540. package/src/chat-threads/emitter.ts +22 -0
  541. package/src/chat-threads/schema.ts +43 -0
  542. package/src/chat-threads/store.ts +1311 -0
  543. package/src/checkpoints/index.ts +15 -0
  544. package/src/checkpoints/service.ts +142 -0
  545. package/src/checkpoints/store.ts +153 -0
  546. package/src/cli/add.ts +425 -0
  547. package/src/cli/agent.ts +424 -0
  548. package/src/cli/agents.ts +122 -0
  549. package/src/cli/app-skill.ts +1455 -0
  550. package/src/cli/atomic-json-file.ts +324 -0
  551. package/src/cli/audit-agent-web.ts +324 -0
  552. package/src/cli/changelog.ts +199 -0
  553. package/src/cli/claude-code-participant.ts +515 -0
  554. package/src/cli/code-agent-commands.ts +270 -0
  555. package/src/cli/code-agent-connector.ts +1109 -0
  556. package/src/cli/code-agent-executor.ts +1970 -0
  557. package/src/cli/code-agent-output-smoother.ts +140 -0
  558. package/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
  559. package/src/cli/code-agent-runs.ts +548 -0
  560. package/src/cli/code.ts +1805 -0
  561. package/src/cli/codex-cli-participant.ts +496 -0
  562. package/src/cli/connect.ts +2714 -0
  563. package/src/cli/content-local.ts +442 -0
  564. package/src/cli/context-xray-local.ts +2193 -0
  565. package/src/cli/create-workspace.ts +30 -0
  566. package/src/cli/create.ts +2247 -0
  567. package/src/cli/deploy-build.ts +50 -0
  568. package/src/cli/design-connect.ts +3187 -0
  569. package/src/cli/doctor.ts +472 -0
  570. package/src/cli/eject.ts +1594 -0
  571. package/src/cli/eval.ts +134 -0
  572. package/src/cli/gateway-helpers.ts +70 -0
  573. package/src/cli/index.ts +1217 -0
  574. package/src/cli/info.ts +105 -0
  575. package/src/cli/invoke.ts +288 -0
  576. package/src/cli/mcp-config-writers.ts +857 -0
  577. package/src/cli/mcp.ts +594 -0
  578. package/src/cli/migrate.ts +1813 -0
  579. package/src/cli/migration-codemod.ts +646 -0
  580. package/src/cli/multi-frontier-runs.ts +1952 -0
  581. package/src/cli/package-lifecycle.ts +823 -0
  582. package/src/cli/plan-blocks.ts +143 -0
  583. package/src/cli/plan-local.ts +3189 -0
  584. package/src/cli/plan-publish-store.ts +138 -0
  585. package/src/cli/pr-visual-recap-workflow.ts +2 -0
  586. package/src/cli/recap.ts +5 -0
  587. package/src/cli/setup-agents.ts +120 -0
  588. package/src/cli/skills-content/assets-skill.ts +83 -0
  589. package/src/cli/skills-content/canvas.ts +153 -0
  590. package/src/cli/skills-content/connection.ts +52 -0
  591. package/src/cli/skills-content/content-skill.ts +120 -0
  592. package/src/cli/skills-content/design-exploration-skill.ts +118 -0
  593. package/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
  594. package/src/cli/skills-content/document-quality.ts +196 -0
  595. package/src/cli/skills-content/exemplar.ts +69 -0
  596. package/src/cli/skills-content/help.ts +77 -0
  597. package/src/cli/skills-content/index.ts +22 -0
  598. package/src/cli/skills-content/local-files.ts +100 -0
  599. package/src/cli/skills-content/plan-setup-auth.ts +80 -0
  600. package/src/cli/skills-content/visual-plan-skill.ts +493 -0
  601. package/src/cli/skills-content/visual-recap-skill.ts +553 -0
  602. package/src/cli/skills-content/visualize-repo-skill.ts +93 -0
  603. package/src/cli/skills-content/wireframe.ts +349 -0
  604. package/src/cli/skills.ts +4340 -0
  605. package/src/cli/sync-builder-starter-manifest.ts +631 -0
  606. package/src/cli/telemetry.ts +136 -0
  607. package/src/cli/templates-meta.ts +269 -0
  608. package/src/cli/upgrade.ts +956 -0
  609. package/src/cli/visualize-repo.ts +715 -0
  610. package/src/cli/workspace-dev.ts +1486 -0
  611. package/src/cli/workspacify.ts +258 -0
  612. package/src/client/AgentAskPopover.tsx +89 -0
  613. package/src/client/AgentChatHome.tsx +66 -0
  614. package/src/client/AgentNative.tsx +161 -0
  615. package/src/client/AgentNativeEmbedded.tsx +288 -0
  616. package/src/client/AgentNativeFrame.tsx +151 -0
  617. package/src/client/AgentPanel.tsx +3437 -0
  618. package/src/client/AgentTaskCard.tsx +273 -0
  619. package/src/client/AppearancePicker.tsx +79 -0
  620. package/src/client/AssistantChat.tsx +5793 -0
  621. package/src/client/ClientOnly.tsx +22 -0
  622. package/src/client/CommandMenu.tsx +726 -0
  623. package/src/client/ConnectBuilderCard.tsx +390 -0
  624. package/src/client/DefaultSpinner.tsx +47 -0
  625. package/src/client/ErrorBoundary.tsx +359 -0
  626. package/src/client/ErrorReportActions.tsx +69 -0
  627. package/src/client/FeedbackButton.tsx +553 -0
  628. package/src/client/HighlightedCodeBlock.tsx +173 -0
  629. package/src/client/IframeEmbed.tsx +151 -0
  630. package/src/client/KeepTabOpenNotice.tsx +181 -0
  631. package/src/client/MultiTabAssistantChat.tsx +2576 -0
  632. package/src/client/NewWorkspaceAppFlow.tsx +525 -0
  633. package/src/client/PoweredByBadge.tsx +284 -0
  634. package/src/client/RunStuckBanner.tsx +431 -0
  635. package/src/client/StarfieldBackground.tsx +466 -0
  636. package/src/client/Turnstile.tsx +125 -0
  637. package/src/client/active-run-state.ts +139 -0
  638. package/src/client/agent-chat/index.ts +279 -0
  639. package/src/client/agent-chat-adapter.ts +3692 -0
  640. package/src/client/agent-chat.ts +1233 -0
  641. package/src/client/agent-engine-key.ts +122 -0
  642. package/src/client/agent-page/AgentContextTab.tsx +487 -0
  643. package/src/client/agent-page/AgentEmptyState.tsx +44 -0
  644. package/src/client/agent-page/AgentJobsTab.tsx +441 -0
  645. package/src/client/agent-page/AgentTabFrame.tsx +39 -0
  646. package/src/client/agent-page/AgentTabsPage.tsx +1096 -0
  647. package/src/client/agent-page/types.ts +18 -0
  648. package/src/client/agent-page/use-jobs.ts +150 -0
  649. package/src/client/agent-sidebar-state.ts +166 -0
  650. package/src/client/analytics/index.ts +40 -0
  651. package/src/client/analytics-session.ts +70 -0
  652. package/src/client/analytics.ts +1757 -0
  653. package/src/client/api-path.ts +124 -0
  654. package/src/client/app-providers.tsx +230 -0
  655. package/src/client/appearance.ts +130 -0
  656. package/src/client/application-state.ts +154 -0
  657. package/src/client/assistant-ui-recovery.tsx +205 -0
  658. package/src/client/automation/index.ts +4 -0
  659. package/src/client/automation.ts +22 -0
  660. package/src/client/blocks/AiEditableField.tsx +30 -0
  661. package/src/client/blocks/BlockView.tsx +145 -0
  662. package/src/client/blocks/RegistryBlockDataProvider.tsx +121 -0
  663. package/src/client/blocks/SchemaBlockEditor.tsx +457 -0
  664. package/src/client/blocks/agent.ts +95 -0
  665. package/src/client/blocks/code-block-direction.ts +21 -0
  666. package/src/client/blocks/index.ts +308 -0
  667. package/src/client/blocks/library/AnnotatedCodeBlock.tsx +710 -0
  668. package/src/client/blocks/library/ApiEndpointBlock.tsx +1120 -0
  669. package/src/client/blocks/library/DataModelBlock.tsx +775 -0
  670. package/src/client/blocks/library/DiffBlock.tsx +1854 -0
  671. package/src/client/blocks/library/FileTreeBlock.tsx +868 -0
  672. package/src/client/blocks/library/HighlightedCode.tsx +260 -0
  673. package/src/client/blocks/library/JsonExplorerBlock.tsx +608 -0
  674. package/src/client/blocks/library/MermaidBlock.tsx +362 -0
  675. package/src/client/blocks/library/OpenApiSpecBlock.tsx +998 -0
  676. package/src/client/blocks/library/annotated-code.config.ts +101 -0
  677. package/src/client/blocks/library/annotation-rail.tsx +1020 -0
  678. package/src/client/blocks/library/api-endpoint.config.ts +207 -0
  679. package/src/client/blocks/library/block-copy.ts +399 -0
  680. package/src/client/blocks/library/callout.config.ts +57 -0
  681. package/src/client/blocks/library/callout.tsx +149 -0
  682. package/src/client/blocks/library/checklist.config.ts +56 -0
  683. package/src/client/blocks/library/checklist.tsx +208 -0
  684. package/src/client/blocks/library/code-filename-label.tsx +59 -0
  685. package/src/client/blocks/library/code-highlight.tsx +178 -0
  686. package/src/client/blocks/library/code-tabs.config.ts +70 -0
  687. package/src/client/blocks/library/code-tabs.tsx +606 -0
  688. package/src/client/blocks/library/code.config.ts +69 -0
  689. package/src/client/blocks/library/code.tsx +440 -0
  690. package/src/client/blocks/library/columns.config.ts +85 -0
  691. package/src/client/blocks/library/columns.tsx +334 -0
  692. package/src/client/blocks/library/data-model.config.ts +152 -0
  693. package/src/client/blocks/library/dev-doc-ui.tsx +191 -0
  694. package/src/client/blocks/library/diagram.config.ts +222 -0
  695. package/src/client/blocks/library/diagram.tsx +958 -0
  696. package/src/client/blocks/library/diff.config.ts +115 -0
  697. package/src/client/blocks/library/file-tree.config.ts +92 -0
  698. package/src/client/blocks/library/html.config.ts +79 -0
  699. package/src/client/blocks/library/html.tsx +258 -0
  700. package/src/client/blocks/library/json-explorer.config.ts +74 -0
  701. package/src/client/blocks/library/mermaid.config.ts +49 -0
  702. package/src/client/blocks/library/narrow-container.tsx +37 -0
  703. package/src/client/blocks/library/openapi-spec.config.ts +66 -0
  704. package/src/client/blocks/library/question-form.config.ts +127 -0
  705. package/src/client/blocks/library/question-form.tsx +944 -0
  706. package/src/client/blocks/library/sanitize-html.ts +343 -0
  707. package/src/client/blocks/library/server-specs.ts +338 -0
  708. package/src/client/blocks/library/specs.tsx +308 -0
  709. package/src/client/blocks/library/table.config.ts +61 -0
  710. package/src/client/blocks/library/table.tsx +449 -0
  711. package/src/client/blocks/library/tabs.config.ts +96 -0
  712. package/src/client/blocks/library/tabs.tsx +665 -0
  713. package/src/client/blocks/library/wireframe-icons.ts +210 -0
  714. package/src/client/blocks/library/wireframe-kit.tsx +1850 -0
  715. package/src/client/blocks/library/wireframe.config.ts +539 -0
  716. package/src/client/blocks/library/wireframe.tsx +535 -0
  717. package/src/client/blocks/mdx.ts +364 -0
  718. package/src/client/blocks/provider.tsx +51 -0
  719. package/src/client/blocks/registry.ts +83 -0
  720. package/src/client/blocks/schema-form/introspect.ts +201 -0
  721. package/src/client/blocks/server.ts +170 -0
  722. package/src/client/blocks/types.ts +415 -0
  723. package/src/client/browser-session-bridge.ts +548 -0
  724. package/src/client/browser-tab-id.ts +36 -0
  725. package/src/client/build-compatibility.ts +77 -0
  726. package/src/client/builder-frame.ts +194 -0
  727. package/src/client/builder-mark.tsx +21 -0
  728. package/src/client/changelog/Changelog.tsx +333 -0
  729. package/src/client/changelog/index.ts +1 -0
  730. package/src/client/chat/ChatHistoryList.tsx +7 -0
  731. package/src/client/chat/attachment-adapters.ts +426 -0
  732. package/src/client/chat/connectors.ts +1579 -0
  733. package/src/client/chat/index.ts +160 -0
  734. package/src/client/chat/markdown-renderer.tsx +693 -0
  735. package/src/client/chat/message-components.tsx +1326 -0
  736. package/src/client/chat/repo-helpers.ts +281 -0
  737. package/src/client/chat/run-recovery.tsx +994 -0
  738. package/src/client/chat/runtime.ts +1810 -0
  739. package/src/client/chat/tool-call-display.tsx +1270 -0
  740. package/src/client/chat/tool-render-registry.tsx +144 -0
  741. package/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
  742. package/src/client/chat/use-reconnect-reader-owner.ts +28 -0
  743. package/src/client/chat/widgets/DataChartRenderer.tsx +242 -0
  744. package/src/client/chat/widgets/DataChartWidget.tsx +51 -0
  745. package/src/client/chat/widgets/DataInsightsWidget.tsx +59 -0
  746. package/src/client/chat/widgets/DataTableWidget.tsx +240 -0
  747. package/src/client/chat/widgets/InlineExtensionWidget.tsx +60 -0
  748. package/src/client/chat/widgets/builtin-tool-renderers.tsx +213 -0
  749. package/src/client/chat/widgets/data-widget-types.ts +1 -0
  750. package/src/client/chat/widgets/inline-extension-result.ts +86 -0
  751. package/src/client/chat-model-groups.ts +171 -0
  752. package/src/client/chat-thread-url.ts +11 -0
  753. package/src/client/chat-view-transition.ts +213 -0
  754. package/src/client/client-action.ts +21 -0
  755. package/src/client/client-bootstrap.ts +7 -0
  756. package/src/client/client-surface.ts +41 -0
  757. package/src/client/clipboard.ts +89 -0
  758. package/src/client/code-agent-chat-adapter.ts +537 -0
  759. package/src/client/collab/index.ts +60 -0
  760. package/src/client/command-navigation/index.ts +15 -0
  761. package/src/client/comments-review/index.ts +1 -0
  762. package/src/client/components/AgentPresenceChip.tsx +4 -0
  763. package/src/client/components/ApiKeySettings.tsx +309 -0
  764. package/src/client/components/CodeAgentIndicator.tsx +59 -0
  765. package/src/client/components/CodeRequiredDialog.tsx +470 -0
  766. package/src/client/components/LiveCursorOverlay.tsx +5 -0
  767. package/src/client/components/MissingKeyCard.tsx +61 -0
  768. package/src/client/components/PresenceBar.tsx +4 -0
  769. package/src/client/components/RecentEditHighlights.tsx +4 -0
  770. package/src/client/components/RemoteSelectionRings.tsx +5 -0
  771. package/src/client/components/icons/AgentNativeIcon.tsx +46 -0
  772. package/src/client/components/ui/dialog.tsx +1 -0
  773. package/src/client/components/ui/dropdown-menu.tsx +1 -0
  774. package/src/client/components/ui/hover-card.tsx +1 -0
  775. package/src/client/components/ui/message-scroller.tsx +131 -0
  776. package/src/client/components/ui/popover.tsx +1 -0
  777. package/src/client/components/ui/sheet.tsx +1 -0
  778. package/src/client/components/ui/tooltip.tsx +1 -0
  779. package/src/client/composer/index.ts +11 -0
  780. package/src/client/composer/runtime-adapters.tsx +123 -0
  781. package/src/client/composer/use-mention-search.ts +7 -0
  782. package/src/client/composer/wired-components.tsx +53 -0
  783. package/src/client/context-xray/ContextMeter.tsx +124 -0
  784. package/src/client/context-xray/ContextSegmentRow.tsx +27 -0
  785. package/src/client/context-xray/ContextTreemap.tsx +24 -0
  786. package/src/client/context-xray/ContextXRayPanel.tsx +59 -0
  787. package/src/client/context-xray/SegmentProvenancePopover.tsx +18 -0
  788. package/src/client/context-xray/format.ts +27 -0
  789. package/src/client/conversation/AgentConversation.tsx +555 -0
  790. package/src/client/conversation/code-agent-transcript.ts +283 -0
  791. package/src/client/conversation/index.ts +22 -0
  792. package/src/client/conversation/types.ts +85 -0
  793. package/src/client/conversation/use-near-bottom-autoscroll.ts +278 -0
  794. package/src/client/create-query-client.ts +86 -0
  795. package/src/client/db-admin/DataGrid.tsx +551 -0
  796. package/src/client/db-admin/DbAdminPage.tsx +218 -0
  797. package/src/client/db-admin/DevDatabaseLink.tsx +16 -0
  798. package/src/client/db-admin/EditableCell.tsx +451 -0
  799. package/src/client/db-admin/FilterBar.tsx +203 -0
  800. package/src/client/db-admin/ResultsGrid.tsx +114 -0
  801. package/src/client/db-admin/RowSidePanel.tsx +337 -0
  802. package/src/client/db-admin/SqlEditor.tsx +840 -0
  803. package/src/client/db-admin/TableBrowser.tsx +212 -0
  804. package/src/client/db-admin/TableEditor.tsx +760 -0
  805. package/src/client/db-admin/cell-format.ts +246 -0
  806. package/src/client/db-admin/changeset.ts +296 -0
  807. package/src/client/db-admin/export-utils.ts +78 -0
  808. package/src/client/db-admin/index.ts +33 -0
  809. package/src/client/db-admin/sql-storage.ts +134 -0
  810. package/src/client/db-admin/storage.ts +68 -0
  811. package/src/client/db-admin/useAgentSync.ts +226 -0
  812. package/src/client/db-admin/useDbAdmin.ts +294 -0
  813. package/src/client/dev-overlay/DevOverlay.tsx +576 -0
  814. package/src/client/dev-overlay/builtins.ts +40 -0
  815. package/src/client/dev-overlay/index.ts +23 -0
  816. package/src/client/dev-overlay/registry.ts +67 -0
  817. package/src/client/dev-overlay/types.ts +64 -0
  818. package/src/client/dev-overlay/use-dev-option.ts +78 -0
  819. package/src/client/dev-overlay/use-dev-overlay-shortcut.ts +31 -0
  820. package/src/client/dynamic-suggestions.ts +455 -0
  821. package/src/client/embed-auth.ts +544 -0
  822. package/src/client/embed.ts +54 -0
  823. package/src/client/error-capture.ts +690 -0
  824. package/src/client/error-format.ts +211 -0
  825. package/src/client/error-reporting.ts +100 -0
  826. package/src/client/extensions/AgentNativeExtensionFrame.e2e-host.tsx +136 -0
  827. package/src/client/extensions/AgentNativeExtensionFrame.tsx +708 -0
  828. package/src/client/extensions/EmbeddedExtension.tsx +604 -0
  829. package/src/client/extensions/ExtensionEditor.tsx +450 -0
  830. package/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
  831. package/src/client/extensions/ExtensionSlot.tsx +345 -0
  832. package/src/client/extensions/ExtensionViewer.tsx +1502 -0
  833. package/src/client/extensions/ExtensionViewerPage.tsx +32 -0
  834. package/src/client/extensions/ExtensionsListPage.tsx +432 -0
  835. package/src/client/extensions/ExtensionsSidebarSection.tsx +1259 -0
  836. package/src/client/extensions/InlineExtensionFrame.tsx +660 -0
  837. package/src/client/extensions/agent-native-extension-runtime.ts +495 -0
  838. package/src/client/extensions/delete-extension.ts +76 -0
  839. package/src/client/extensions/extension-load-error.ts +26 -0
  840. package/src/client/extensions/extension-order.ts +49 -0
  841. package/src/client/extensions/extension-popularity.ts +61 -0
  842. package/src/client/extensions/iframe-bridge.ts +377 -0
  843. package/src/client/extensions/index.ts +84 -0
  844. package/src/client/extensions/portable-extension.ts +712 -0
  845. package/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
  846. package/src/client/feature-flags/helpers.ts +77 -0
  847. package/src/client/feature-flags/index.ts +13 -0
  848. package/src/client/feature-flags/types.ts +29 -0
  849. package/src/client/feature-flags/use-feature-flag.ts +26 -0
  850. package/src/client/feedback-context.ts +90 -0
  851. package/src/client/frame-protocol.ts +168 -0
  852. package/src/client/frame.ts +329 -0
  853. package/src/client/guided-questions.tsx +1152 -0
  854. package/src/client/history/VersionHistoryPanel.tsx +175 -0
  855. package/src/client/history/index.ts +21 -0
  856. package/src/client/history/use-history.ts +114 -0
  857. package/src/client/hooks/index.ts +46 -0
  858. package/src/client/host/index.ts +170 -0
  859. package/src/client/host-bridge.ts +1272 -0
  860. package/src/client/host-tools.ts +190 -0
  861. package/src/client/i18n.tsx +798 -0
  862. package/src/client/index.ts +370 -0
  863. package/src/client/integrations/IntegrationCard.tsx +186 -0
  864. package/src/client/integrations/IntegrationsPanel.tsx +633 -0
  865. package/src/client/integrations/api.ts +295 -0
  866. package/src/client/integrations/index.ts +29 -0
  867. package/src/client/integrations/useIntegrationStatus.ts +52 -0
  868. package/src/client/mcp-app-host.ts +720 -0
  869. package/src/client/mcp-apps/McpAppRenderer.tsx +760 -0
  870. package/src/client/navigation/index.ts +54 -0
  871. package/src/client/notifications/NotificationsBell.tsx +383 -0
  872. package/src/client/notifications/index.ts +1 -0
  873. package/src/client/observability/ObservabilityDashboard.tsx +890 -0
  874. package/src/client/observability/ThumbsFeedback.tsx +160 -0
  875. package/src/client/observability/index.ts +20 -0
  876. package/src/client/observability/useObservability.ts +266 -0
  877. package/src/client/onboarding/OnboardingBanner.tsx +73 -0
  878. package/src/client/onboarding/OnboardingPanel.tsx +1036 -0
  879. package/src/client/onboarding/SetupButton.tsx +64 -0
  880. package/src/client/onboarding/index.ts +25 -0
  881. package/src/client/onboarding/use-onboarding.ts +164 -0
  882. package/src/client/onboarding/use-preview-mode.ts +40 -0
  883. package/src/client/org/InvitationBanner.tsx +148 -0
  884. package/src/client/org/OrgSwitcher.tsx +754 -0
  885. package/src/client/org/RequireActiveOrg.tsx +337 -0
  886. package/src/client/org/TeamPage.tsx +1432 -0
  887. package/src/client/org/hooks.ts +359 -0
  888. package/src/client/org/index.ts +70 -0
  889. package/src/client/org/workspace-app-links.ts +367 -0
  890. package/src/client/org-team/index.ts +1 -0
  891. package/src/client/progress/RunsTray.tsx +680 -0
  892. package/src/client/progress/index.ts +1 -0
  893. package/src/client/require-session.tsx +142 -0
  894. package/src/client/resources/BuiltinCapabilityDetail.tsx +258 -0
  895. package/src/client/resources/McpConnectionSuggestion.tsx +276 -0
  896. package/src/client/resources/McpIntegrationDialog.tsx +808 -0
  897. package/src/client/resources/McpServerDetail.tsx +230 -0
  898. package/src/client/resources/ResourceEditor.tsx +872 -0
  899. package/src/client/resources/ResourceTree.tsx +860 -0
  900. package/src/client/resources/ResourcesPanel.tsx +1960 -0
  901. package/src/client/resources/index.ts +25 -0
  902. package/src/client/resources/mcp-integration-catalog.ts +771 -0
  903. package/src/client/resources/mcp-integration-logos.ts +108 -0
  904. package/src/client/resources/runtime.ts +1 -0
  905. package/src/client/resources/use-builtin-capabilities.ts +113 -0
  906. package/src/client/resources/use-mcp-servers.ts +217 -0
  907. package/src/client/resources/use-resources.ts +402 -0
  908. package/src/client/review/ReviewCommentComposer.tsx +123 -0
  909. package/src/client/review/ReviewStatusBadge.tsx +39 -0
  910. package/src/client/review/ReviewThreadPanel.tsx +625 -0
  911. package/src/client/review/index.ts +38 -0
  912. package/src/client/review/use-review.ts +186 -0
  913. package/src/client/route-chunk-recovery/index.ts +2 -0
  914. package/src/client/route-chunk-recovery.ts +331 -0
  915. package/src/client/route-state.ts +455 -0
  916. package/src/client/route-warmup.tsx +543 -0
  917. package/src/client/session-replay-iframe.e2e-host.tsx +100 -0
  918. package/src/client/session-replay.ts +3417 -0
  919. package/src/client/settings/AgentsSection.tsx +441 -0
  920. package/src/client/settings/AutomationsSection.tsx +516 -0
  921. package/src/client/settings/BackgroundAgentSection.tsx +189 -0
  922. package/src/client/settings/BrowserSection.tsx +110 -0
  923. package/src/client/settings/DemoModeSection.tsx +48 -0
  924. package/src/client/settings/SecretsSection.tsx +875 -0
  925. package/src/client/settings/SettingsPanel.tsx +3162 -0
  926. package/src/client/settings/SettingsSection.tsx +283 -0
  927. package/src/client/settings/SettingsTabsPage.tsx +592 -0
  928. package/src/client/settings/UsageSection.tsx +401 -0
  929. package/src/client/settings/VoiceTranscriptionSection.tsx +960 -0
  930. package/src/client/settings/agent-settings-search.ts +220 -0
  931. package/src/client/settings/index.ts +27 -0
  932. package/src/client/settings/useBuilderStatus.ts +1055 -0
  933. package/src/client/setup-connections/BuilderConnectCard.tsx +89 -0
  934. package/src/client/setup-connections/ProviderReadinessBadge.tsx +73 -0
  935. package/src/client/setup-connections/SetupConnectionsPage.tsx +94 -0
  936. package/src/client/setup-connections/catalog.ts +6 -0
  937. package/src/client/setup-connections/index.ts +47 -0
  938. package/src/client/setup-connections/runtime.ts +1 -0
  939. package/src/client/sharing/ShareButton.tsx +1748 -0
  940. package/src/client/sharing/ShareDialog.tsx +846 -0
  941. package/src/client/sharing/VisibilityBadge.tsx +4 -0
  942. package/src/client/sharing/index.ts +2 -0
  943. package/src/client/sse-event-processor.ts +2002 -0
  944. package/src/client/terminal/AgentTerminal.tsx +488 -0
  945. package/src/client/terminal/index.ts +7 -0
  946. package/src/client/theme.ts +27 -0
  947. package/src/client/tombstone/agent-presence-chip.ts +17 -0
  948. package/src/client/tombstone/editor.ts +265 -0
  949. package/src/client/tombstone/live-cursor-overlay.ts +21 -0
  950. package/src/client/tombstone/presence-bar.ts +17 -0
  951. package/src/client/tombstone/recent-edit-highlights.ts +17 -0
  952. package/src/client/tombstone/remote-selection-rings.ts +21 -0
  953. package/src/client/tombstone/rich-markdown-editor.ts +265 -0
  954. package/src/client/tombstone/ui-dialog.ts +49 -0
  955. package/src/client/tombstone/ui-dropdown-menu.ts +69 -0
  956. package/src/client/tombstone/ui-hover-card.ts +21 -0
  957. package/src/client/tombstone/ui-popover.ts +25 -0
  958. package/src/client/tombstone/ui-sheet.ts +49 -0
  959. package/src/client/tombstone/ui-tooltip.ts +29 -0
  960. package/src/client/tombstone/visual-style-controls.ts +61 -0
  961. package/src/client/tool-cells/BashCell.tsx +164 -0
  962. package/src/client/tool-cells/EditCell.tsx +303 -0
  963. package/src/client/tool-cells/FilesChangedSummary.tsx +208 -0
  964. package/src/client/tool-cells/WriteCell.tsx +145 -0
  965. package/src/client/tool-cells/index.ts +7 -0
  966. package/src/client/tool-display.ts +41 -0
  967. package/src/client/track.ts +57 -0
  968. package/src/client/transcription/BuilderTranscriptionCta.tsx +120 -0
  969. package/src/client/transcription/use-live-transcription.ts +292 -0
  970. package/src/client/ui/index.ts +55 -0
  971. package/src/client/uploads/index.ts +6 -0
  972. package/src/client/uploads/upload-editor-image.ts +79 -0
  973. package/src/client/uploads/use-upload-resource.ts +24 -0
  974. package/src/client/url-scrub.ts +51 -0
  975. package/src/client/use-action.ts +797 -0
  976. package/src/client/use-agent-chat-context.ts +63 -0
  977. package/src/client/use-agent-chat-home-handoff.ts +207 -0
  978. package/src/client/use-agent-chat.ts +53 -0
  979. package/src/client/use-agent-engine-configured.ts +211 -0
  980. package/src/client/use-avatar.ts +127 -0
  981. package/src/client/use-change-version.ts +150 -0
  982. package/src/client/use-chat-models.ts +252 -0
  983. package/src/client/use-chat-threads.ts +1262 -0
  984. package/src/client/use-db-sync.ts +1112 -0
  985. package/src/client/use-demo-mode-status.ts +30 -0
  986. package/src/client/use-dev-mode.ts +177 -0
  987. package/src/client/use-external-value.ts +40 -0
  988. package/src/client/use-pausing-interval.ts +65 -0
  989. package/src/client/use-pinch-zoom.ts +202 -0
  990. package/src/client/use-run-stuck-detection.ts +427 -0
  991. package/src/client/use-send-to-agent-chat.ts +85 -0
  992. package/src/client/use-session.ts +114 -0
  993. package/src/client/utils.ts +7 -0
  994. package/src/client/visual-style-controls.tsx +1 -0
  995. package/src/client/vite-dev-recovery-script.ts +226 -0
  996. package/src/client/voice-provider-status.ts +44 -0
  997. package/src/client/widgets/index.ts +41 -0
  998. package/src/code-agents/background-controller.ts +398 -0
  999. package/src/code-agents/background-run.ts +156 -0
  1000. package/src/code-agents/index.ts +95 -0
  1001. package/src/code-agents/prompt-attachments.ts +39 -0
  1002. package/src/code-agents/transcript-normalizer.ts +750 -0
  1003. package/src/code-agents/transcript-order.ts +73 -0
  1004. package/src/coding-tools/index.ts +742 -0
  1005. package/src/coding-tools/run-code.ts +1662 -0
  1006. package/src/coding-tools/sandbox/adapter.ts +82 -0
  1007. package/src/coding-tools/sandbox/background.ts +406 -0
  1008. package/src/coding-tools/sandbox/executions-store.ts +517 -0
  1009. package/src/coding-tools/sandbox/index.ts +132 -0
  1010. package/src/coding-tools/sandbox/local-child-process-adapter.ts +217 -0
  1011. package/src/collab/agent-identity.ts +5 -0
  1012. package/src/collab/agent-presence.ts +341 -0
  1013. package/src/collab/awareness-store.ts +196 -0
  1014. package/src/collab/awareness.ts +317 -0
  1015. package/src/collab/client-struct.ts +366 -0
  1016. package/src/collab/client.ts +1205 -0
  1017. package/src/collab/emitter.ts +31 -0
  1018. package/src/collab/follow-mode.ts +107 -0
  1019. package/src/collab/index.ts +151 -0
  1020. package/src/collab/json-to-yjs.ts +504 -0
  1021. package/src/collab/presence.ts +207 -0
  1022. package/src/collab/recent-edits.ts +215 -0
  1023. package/src/collab/routes.ts +191 -0
  1024. package/src/collab/storage.ts +228 -0
  1025. package/src/collab/struct-routes.ts +133 -0
  1026. package/src/collab/text-to-yjs.ts +79 -0
  1027. package/src/collab/undo.ts +432 -0
  1028. package/src/collab/xml-ops.ts +68 -0
  1029. package/src/collab/ydoc-manager.ts +544 -0
  1030. package/src/command-navigation/actions.ts +100 -0
  1031. package/src/command-navigation/index.ts +12 -0
  1032. package/src/comments-review/index.ts +1 -0
  1033. package/src/connections/catalog.ts +451 -0
  1034. package/src/connections/index.ts +48 -0
  1035. package/src/connections/reader.ts +911 -0
  1036. package/src/connections/runtime.ts +1 -0
  1037. package/src/credentials/index.ts +187 -0
  1038. package/src/data-programs/actions.ts +335 -0
  1039. package/src/data-programs/contract.ts +284 -0
  1040. package/src/data-programs/execute.ts +693 -0
  1041. package/src/data-programs/index.ts +72 -0
  1042. package/src/data-programs/schema.ts +148 -0
  1043. package/src/data-programs/store.ts +755 -0
  1044. package/src/data-widgets/index.ts +376 -0
  1045. package/src/db/client.ts +1627 -0
  1046. package/src/db/create-get-db.ts +579 -0
  1047. package/src/db/ddl-guard.ts +302 -0
  1048. package/src/db/drizzle-config.ts +190 -0
  1049. package/src/db/ensure-additive-columns.ts +430 -0
  1050. package/src/db/index.ts +57 -0
  1051. package/src/db/migrations.ts +691 -0
  1052. package/src/db/request-telemetry.ts +154 -0
  1053. package/src/db/runtime-diagnostics.ts +331 -0
  1054. package/src/db/schema.ts +121 -0
  1055. package/src/db/widen-columns.ts +75 -0
  1056. package/src/db-admin/agent-tools.ts +202 -0
  1057. package/src/db-admin/index.ts +26 -0
  1058. package/src/db-admin/operations.ts +803 -0
  1059. package/src/db-admin/routes.ts +174 -0
  1060. package/src/db-admin/types.ts +110 -0
  1061. package/src/demo/browser-state.ts +47 -0
  1062. package/src/demo/fetch-interceptor.ts +175 -0
  1063. package/src/demo/redact.ts +575 -0
  1064. package/src/deploy/build.ts +3938 -0
  1065. package/src/deploy/immutable-assets.ts +65 -0
  1066. package/src/deploy/route-discovery.ts +458 -0
  1067. package/src/deploy/workspace-core.ts +282 -0
  1068. package/src/deploy/workspace-deploy.ts +1488 -0
  1069. package/src/eject/provider-api-definitions.ts +193 -0
  1070. package/src/eject/remote-mcp-presets.ts +137 -0
  1071. package/src/eject/setup-readiness-ui.tsx +29 -0
  1072. package/src/eject/workspace-connections.ts +92 -0
  1073. package/src/embedding/agent.ts +159 -0
  1074. package/src/embedding/bridge.ts +297 -0
  1075. package/src/embedding/index.ts +43 -0
  1076. package/src/embedding/protocol.ts +185 -0
  1077. package/src/embedding/react.tsx +319 -0
  1078. package/src/embeddings/index.ts +233 -0
  1079. package/src/eval/agent-runner.ts +210 -0
  1080. package/src/eval/define-eval.ts +55 -0
  1081. package/src/eval/index.ts +49 -0
  1082. package/src/eval/report.ts +75 -0
  1083. package/src/eval/runner.ts +369 -0
  1084. package/src/eval/scorer.ts +244 -0
  1085. package/src/eval/types.ts +188 -0
  1086. package/src/event-bus/bus.ts +140 -0
  1087. package/src/event-bus/index.ts +3 -0
  1088. package/src/event-bus/registry.ts +79 -0
  1089. package/src/event-bus/types.ts +29 -0
  1090. package/src/extensions/actions.ts +1636 -0
  1091. package/src/extensions/change-marker.ts +54 -0
  1092. package/src/extensions/content-patch.ts +468 -0
  1093. package/src/extensions/fetch-tool.ts +461 -0
  1094. package/src/extensions/html-shell.ts +803 -0
  1095. package/src/extensions/local.ts +462 -0
  1096. package/src/extensions/path.ts +40 -0
  1097. package/src/extensions/proxy-security.ts +171 -0
  1098. package/src/extensions/routes.ts +1080 -0
  1099. package/src/extensions/schema.ts +269 -0
  1100. package/src/extensions/session-replay-iframe.ts +131 -0
  1101. package/src/extensions/slots/routes.ts +126 -0
  1102. package/src/extensions/slots/schema.ts +87 -0
  1103. package/src/extensions/slots/store.ts +450 -0
  1104. package/src/extensions/store.ts +1347 -0
  1105. package/src/extensions/theme.ts +114 -0
  1106. package/src/extensions/url-safety.ts +316 -0
  1107. package/src/extensions/web-content.ts +663 -0
  1108. package/src/extensions/web-search-tool.ts +437 -0
  1109. package/src/feature-flags/a2a-action-route.ts +56 -0
  1110. package/src/feature-flags/actions/get-feature-flags.ts +24 -0
  1111. package/src/feature-flags/actions/list-feature-flags.ts +69 -0
  1112. package/src/feature-flags/actions/set-feature-flag.ts +89 -0
  1113. package/src/feature-flags/index.ts +21 -0
  1114. package/src/feature-flags/permissions.ts +53 -0
  1115. package/src/feature-flags/plugin.ts +44 -0
  1116. package/src/feature-flags/registry.ts +96 -0
  1117. package/src/feature-flags/store.ts +176 -0
  1118. package/src/file-upload/actions/upload-image.ts +213 -0
  1119. package/src/file-upload/builder.ts +431 -0
  1120. package/src/file-upload/index.ts +24 -0
  1121. package/src/file-upload/pre-upload-attachments.ts +305 -0
  1122. package/src/file-upload/registry.ts +125 -0
  1123. package/src/file-upload/types.ts +89 -0
  1124. package/src/guards/db-tool-scoping.ts +129 -0
  1125. package/src/guards/index.ts +23 -0
  1126. package/src/guards/no-drizzle-push.ts +116 -0
  1127. package/src/guards/no-env-credentials.ts +229 -0
  1128. package/src/guards/no-env-mutation.ts +114 -0
  1129. package/src/guards/no-localhost-fallback.ts +124 -0
  1130. package/src/guards/no-unscoped-credentials.ts +227 -0
  1131. package/src/guards/no-unscoped-queries.ts +834 -0
  1132. package/src/guards/scan-utils.ts +105 -0
  1133. package/src/guards/types.ts +30 -0
  1134. package/src/history/actions/create-resource-version.ts +92 -0
  1135. package/src/history/actions/get-resource-version.ts +60 -0
  1136. package/src/history/actions/list-resource-history.ts +53 -0
  1137. package/src/history/actions/list-resource-versions.ts +43 -0
  1138. package/src/history/actions/restore-resource-version.ts +96 -0
  1139. package/src/history/index.ts +26 -0
  1140. package/src/history/registry.ts +111 -0
  1141. package/src/history/store.ts +379 -0
  1142. package/src/history/types.ts +69 -0
  1143. package/src/index.browser.ts +155 -0
  1144. package/src/index.ts +408 -0
  1145. package/src/ingestion/docx.ts +158 -0
  1146. package/src/ingestion/figma-node-to-html.ts +1860 -0
  1147. package/src/ingestion/figma.ts +548 -0
  1148. package/src/ingestion/index.ts +107 -0
  1149. package/src/ingestion/media.ts +264 -0
  1150. package/src/ingestion/notion.ts +121 -0
  1151. package/src/ingestion/office.ts +213 -0
  1152. package/src/ingestion/orchestration.ts +160 -0
  1153. package/src/ingestion/pptx.ts +331 -0
  1154. package/src/ingestion/selection.ts +81 -0
  1155. package/src/ingestion/website.ts +151 -0
  1156. package/src/integrations/a2a-continuation-marker.ts +2 -0
  1157. package/src/integrations/a2a-continuation-processor.ts +888 -0
  1158. package/src/integrations/a2a-continuations-store.ts +643 -0
  1159. package/src/integrations/adapter-overrides.ts +12 -0
  1160. package/src/integrations/adapters/discord.ts +364 -0
  1161. package/src/integrations/adapters/email.ts +1164 -0
  1162. package/src/integrations/adapters/google-docs.ts +371 -0
  1163. package/src/integrations/adapters/index.ts +29 -0
  1164. package/src/integrations/adapters/microsoft-teams.ts +413 -0
  1165. package/src/integrations/adapters/slack.ts +1914 -0
  1166. package/src/integrations/adapters/telegram.ts +386 -0
  1167. package/src/integrations/adapters/whatsapp.ts +358 -0
  1168. package/src/integrations/awaiting-input-store.ts +130 -0
  1169. package/src/integrations/catalog.ts +571 -0
  1170. package/src/integrations/computer-supervision-store.ts +423 -0
  1171. package/src/integrations/computer-supervision.ts +213 -0
  1172. package/src/integrations/config-store.ts +131 -0
  1173. package/src/integrations/controls-store.ts +187 -0
  1174. package/src/integrations/eject/messaging-adapters.ts +85 -0
  1175. package/src/integrations/google-docs-poller.ts +671 -0
  1176. package/src/integrations/identity-links-store.ts +210 -0
  1177. package/src/integrations/identity.ts +196 -0
  1178. package/src/integrations/index.ts +220 -0
  1179. package/src/integrations/installations-store.ts +677 -0
  1180. package/src/integrations/integration-memory.ts +187 -0
  1181. package/src/integrations/internal-token.ts +106 -0
  1182. package/src/integrations/pending-tasks-retry-job.ts +286 -0
  1183. package/src/integrations/pending-tasks-store.ts +468 -0
  1184. package/src/integrations/plugin.ts +3048 -0
  1185. package/src/integrations/remote-commands-store.ts +690 -0
  1186. package/src/integrations/remote-devices-store.ts +492 -0
  1187. package/src/integrations/remote-json-safety.ts +127 -0
  1188. package/src/integrations/remote-push-delivery-job.ts +48 -0
  1189. package/src/integrations/remote-push-delivery.ts +370 -0
  1190. package/src/integrations/remote-push-store.ts +664 -0
  1191. package/src/integrations/remote-retry-job.ts +55 -0
  1192. package/src/integrations/remote-run-events-store.ts +222 -0
  1193. package/src/integrations/remote-types.ts +186 -0
  1194. package/src/integrations/runtime.ts +1 -0
  1195. package/src/integrations/scope-store.ts +498 -0
  1196. package/src/integrations/slack-manifest.ts +78 -0
  1197. package/src/integrations/slack-oauth.ts +344 -0
  1198. package/src/integrations/task-queue-stats.ts +144 -0
  1199. package/src/integrations/thread-mapping-store.ts +134 -0
  1200. package/src/integrations/types.ts +485 -0
  1201. package/src/integrations/usage-budget-store.ts +906 -0
  1202. package/src/integrations/webhook-delivery.ts +55 -0
  1203. package/src/integrations/webhook-handler.ts +1939 -0
  1204. package/src/jobs/actions/list-recurring-jobs.ts +105 -0
  1205. package/src/jobs/actions/manage-recurring-job.ts +85 -0
  1206. package/src/jobs/cron.ts +126 -0
  1207. package/src/jobs/index.ts +9 -0
  1208. package/src/jobs/scheduler.ts +703 -0
  1209. package/src/jobs/tools.ts +367 -0
  1210. package/src/local-artifacts/index.ts +1372 -0
  1211. package/src/localization/actions/get-localization-preference.ts +24 -0
  1212. package/src/localization/actions/set-localization-preference.ts +32 -0
  1213. package/src/localization/default-messages.ts +1009 -0
  1214. package/src/localization/index.ts +2 -0
  1215. package/src/localization/server.ts +131 -0
  1216. package/src/localization/shared.ts +208 -0
  1217. package/src/mcp/actions/call-mcp-tool.ts +19 -0
  1218. package/src/mcp/actions/create-org-service-token.ts +87 -0
  1219. package/src/mcp/actions/list-mcp-tools.ts +18 -0
  1220. package/src/mcp/actions/list-org-service-tokens.ts +44 -0
  1221. package/src/mcp/actions/revoke-org-service-token.ts +30 -0
  1222. package/src/mcp/actions/service-token-access.ts +121 -0
  1223. package/src/mcp/ask-app-inline-tasks.ts +125 -0
  1224. package/src/mcp/build-server.ts +2356 -0
  1225. package/src/mcp/builtin-tools.ts +1506 -0
  1226. package/src/mcp/connect-route.ts +1460 -0
  1227. package/src/mcp/connect-store.ts +680 -0
  1228. package/src/mcp/embed-app.ts +2051 -0
  1229. package/src/mcp/embed-route.ts +84 -0
  1230. package/src/mcp/external-agent-policy.ts +18 -0
  1231. package/src/mcp/index.ts +47 -0
  1232. package/src/mcp/oauth-route.ts +1016 -0
  1233. package/src/mcp/oauth-store.ts +581 -0
  1234. package/src/mcp/oauth-token.ts +227 -0
  1235. package/src/mcp/org-directory.ts +343 -0
  1236. package/src/mcp/route-paths.ts +34 -0
  1237. package/src/mcp/screen-memory-stdio.ts +290 -0
  1238. package/src/mcp/server.ts +507 -0
  1239. package/src/mcp/stdio.ts +328 -0
  1240. package/src/mcp/workspace-resolve.ts +261 -0
  1241. package/src/mcp-client/app-api.ts +136 -0
  1242. package/src/mcp-client/app-result.ts +64 -0
  1243. package/src/mcp-client/builtin-capabilities.ts +146 -0
  1244. package/src/mcp-client/builtin-store.ts +93 -0
  1245. package/src/mcp-client/config.ts +281 -0
  1246. package/src/mcp-client/errors.ts +54 -0
  1247. package/src/mcp-client/hub-client.ts +172 -0
  1248. package/src/mcp-client/hub-routes.ts +198 -0
  1249. package/src/mcp-client/index.ts +504 -0
  1250. package/src/mcp-client/manager.ts +968 -0
  1251. package/src/mcp-client/oauth-client.ts +462 -0
  1252. package/src/mcp-client/oauth-routes.ts +307 -0
  1253. package/src/mcp-client/remote-store.ts +674 -0
  1254. package/src/mcp-client/remote-url.ts +97 -0
  1255. package/src/mcp-client/routes.ts +1093 -0
  1256. package/src/mcp-client/screen-memory-local.ts +461 -0
  1257. package/src/mcp-client/tool-policy.ts +182 -0
  1258. package/src/mcp-client/visibility.ts +56 -0
  1259. package/src/mcp-client/workspace-servers.ts +379 -0
  1260. package/src/navigation/index.ts +170 -0
  1261. package/src/notifications/actions.ts +151 -0
  1262. package/src/notifications/channels.ts +410 -0
  1263. package/src/notifications/index.ts +22 -0
  1264. package/src/notifications/registry.ts +216 -0
  1265. package/src/notifications/routes.ts +106 -0
  1266. package/src/notifications/store.ts +236 -0
  1267. package/src/notifications/types.ts +52 -0
  1268. package/src/oauth-tokens/google-refresh.ts +175 -0
  1269. package/src/oauth-tokens/index.ts +15 -0
  1270. package/src/oauth-tokens/store.ts +384 -0
  1271. package/src/observability/cleanup-job.ts +124 -0
  1272. package/src/observability/evals.ts +507 -0
  1273. package/src/observability/experiments.ts +359 -0
  1274. package/src/observability/feedback.ts +332 -0
  1275. package/src/observability/hosted-model-experiment.ts +118 -0
  1276. package/src/observability/index.ts +62 -0
  1277. package/src/observability/plugin.ts +31 -0
  1278. package/src/observability/routes.ts +431 -0
  1279. package/src/observability/sentiment.ts +261 -0
  1280. package/src/observability/store.ts +1347 -0
  1281. package/src/observability/traces.ts +789 -0
  1282. package/src/observability/tracing.ts +157 -0
  1283. package/src/observability/tracking-identity.ts +55 -0
  1284. package/src/observability/types.ts +211 -0
  1285. package/src/onboarding/default-steps.ts +428 -0
  1286. package/src/onboarding/index.ts +22 -0
  1287. package/src/onboarding/plugin.ts +262 -0
  1288. package/src/onboarding/registry.ts +47 -0
  1289. package/src/onboarding/types.ts +96 -0
  1290. package/src/org/accept-pending.ts +98 -0
  1291. package/src/org/auto-join-domain.ts +113 -0
  1292. package/src/org/context.ts +640 -0
  1293. package/src/org/free-email-providers.ts +124 -0
  1294. package/src/org/handlers.ts +1153 -0
  1295. package/src/org/index.ts +63 -0
  1296. package/src/org/migrations.ts +105 -0
  1297. package/src/org/permissions.ts +30 -0
  1298. package/src/org/plugin.ts +255 -0
  1299. package/src/org/schema.ts +28 -0
  1300. package/src/org/types.ts +57 -0
  1301. package/src/org-team/index.ts +1 -0
  1302. package/src/package-lifecycle/deprecated-imports.ts +179 -0
  1303. package/src/package-lifecycle/eject-manifest.ts +345 -0
  1304. package/src/package-lifecycle/index.ts +7 -0
  1305. package/src/package-lifecycle/manifest.ts +120 -0
  1306. package/src/package-lifecycle/migration-manifest.ts +159 -0
  1307. package/src/package-lifecycle/migration-message.ts +6 -0
  1308. package/src/package-lifecycle/tombstone.ts +58 -0
  1309. package/src/package-lifecycle/upgrade-error.ts +37 -0
  1310. package/src/private-blob/index.ts +18 -0
  1311. package/src/private-blob/registry.ts +242 -0
  1312. package/src/private-blob/types.ts +55 -0
  1313. package/src/progress/actions.ts +179 -0
  1314. package/src/progress/index.ts +16 -0
  1315. package/src/progress/registry.ts +127 -0
  1316. package/src/progress/routes.ts +89 -0
  1317. package/src/progress/store.ts +353 -0
  1318. package/src/progress/types.ts +59 -0
  1319. package/src/provider-api/actions/custom-provider-registration.ts +197 -0
  1320. package/src/provider-api/actions/delete-staged-dataset.ts +5 -0
  1321. package/src/provider-api/actions/github-repo-files.ts +266 -0
  1322. package/src/provider-api/actions/list-staged-datasets.ts +5 -0
  1323. package/src/provider-api/actions/provider-api-audit.ts +88 -0
  1324. package/src/provider-api/actions/provider-api.ts +460 -0
  1325. package/src/provider-api/actions/query-staged-dataset.ts +5 -0
  1326. package/src/provider-api/actions/staged-datasets.ts +359 -0
  1327. package/src/provider-api/corpus-jobs-store.ts +522 -0
  1328. package/src/provider-api/corpus-jobs.ts +1817 -0
  1329. package/src/provider-api/custom-registry.ts +456 -0
  1330. package/src/provider-api/github-repo.ts +675 -0
  1331. package/src/provider-api/gong.ts +108 -0
  1332. package/src/provider-api/index.ts +5444 -0
  1333. package/src/provider-api/quota-governor.ts +562 -0
  1334. package/src/provider-api/runtime.ts +1 -0
  1335. package/src/provider-api/staged-datasets-aggregate.ts +304 -0
  1336. package/src/provider-api/staged-datasets-store.ts +441 -0
  1337. package/src/provider-api/staging.ts +483 -0
  1338. package/src/resources/agents.ts +65 -0
  1339. package/src/resources/emitter.ts +54 -0
  1340. package/src/resources/handlers.ts +728 -0
  1341. package/src/resources/index.ts +4 -0
  1342. package/src/resources/metadata.ts +252 -0
  1343. package/src/resources/script-helpers.ts +160 -0
  1344. package/src/resources/store.ts +1618 -0
  1345. package/src/review/actions/consume-review-feedback.ts +48 -0
  1346. package/src/review/actions/create-review-comment.ts +108 -0
  1347. package/src/review/actions/delete-review-comment.ts +67 -0
  1348. package/src/review/actions/get-review-feedback.ts +49 -0
  1349. package/src/review/actions/list-review-comments.ts +87 -0
  1350. package/src/review/actions/reply-review-comment.ts +118 -0
  1351. package/src/review/actions/resolve-review-thread.ts +94 -0
  1352. package/src/review/actions/send-review-thread-to-agent.ts +62 -0
  1353. package/src/review/actions/set-review-status.ts +58 -0
  1354. package/src/review/identity.ts +101 -0
  1355. package/src/review/index.ts +45 -0
  1356. package/src/review/mentions.ts +44 -0
  1357. package/src/review/registry.ts +111 -0
  1358. package/src/review/store.ts +997 -0
  1359. package/src/review/types.ts +101 -0
  1360. package/src/router/index.ts +24 -0
  1361. package/src/scripts/agent-engines/list-agent-engines.ts +130 -0
  1362. package/src/scripts/agent-engines/manage-agent-engine.ts +197 -0
  1363. package/src/scripts/agent-engines/set-agent-engine.ts +84 -0
  1364. package/src/scripts/agent-engines/test-agent-engine.ts +174 -0
  1365. package/src/scripts/call-agent.ts +792 -0
  1366. package/src/scripts/chat/index.ts +8 -0
  1367. package/src/scripts/chat/open-chat.ts +56 -0
  1368. package/src/scripts/chat/search-chats.ts +121 -0
  1369. package/src/scripts/core-scripts.ts +22 -0
  1370. package/src/scripts/db/check-scoping.ts +212 -0
  1371. package/src/scripts/db/exec.ts +791 -0
  1372. package/src/scripts/db/index.ts +19 -0
  1373. package/src/scripts/db/migrate-encrypt-credentials.ts +223 -0
  1374. package/src/scripts/db/migrate-encrypt-oauth-tokens.ts +213 -0
  1375. package/src/scripts/db/migrate-user-api-keys.ts +257 -0
  1376. package/src/scripts/db/patch.ts +820 -0
  1377. package/src/scripts/db/query.ts +299 -0
  1378. package/src/scripts/db/reset-dev-owner.ts +285 -0
  1379. package/src/scripts/db/safety.ts +286 -0
  1380. package/src/scripts/db/schema.ts +364 -0
  1381. package/src/scripts/db/scoping.ts +341 -0
  1382. package/src/scripts/db/sqlite-client.ts +78 -0
  1383. package/src/scripts/db/tool-mode.ts +23 -0
  1384. package/src/scripts/db/tool-schemas.ts +31 -0
  1385. package/src/scripts/db/wipe-leaked-builder-keys.ts +201 -0
  1386. package/src/scripts/dev/index.ts +296 -0
  1387. package/src/scripts/dev/list-files.ts +119 -0
  1388. package/src/scripts/dev/read-file.ts +77 -0
  1389. package/src/scripts/dev/search-files.ts +151 -0
  1390. package/src/scripts/dev/shell.ts +111 -0
  1391. package/src/scripts/dev/write-file.ts +56 -0
  1392. package/src/scripts/dev-session.ts +96 -0
  1393. package/src/scripts/docs/index.ts +8 -0
  1394. package/src/scripts/docs/search.ts +274 -0
  1395. package/src/scripts/docs/source-search.ts +363 -0
  1396. package/src/scripts/index.ts +15 -0
  1397. package/src/scripts/manage-agent-loop-settings.ts +84 -0
  1398. package/src/scripts/parse-args.ts +46 -0
  1399. package/src/scripts/resources/delete-memory.ts +67 -0
  1400. package/src/scripts/resources/delete.ts +69 -0
  1401. package/src/scripts/resources/effective.ts +71 -0
  1402. package/src/scripts/resources/index.ts +18 -0
  1403. package/src/scripts/resources/list.ts +103 -0
  1404. package/src/scripts/resources/migrate-learnings.ts +40 -0
  1405. package/src/scripts/resources/read.ts +107 -0
  1406. package/src/scripts/resources/save-memory.ts +99 -0
  1407. package/src/scripts/resources/write.ts +158 -0
  1408. package/src/scripts/runner.ts +339 -0
  1409. package/src/scripts/utils.ts +130 -0
  1410. package/src/search/index.ts +413 -0
  1411. package/src/search-utils/index.ts +112 -0
  1412. package/src/secrets/crypto.ts +228 -0
  1413. package/src/secrets/index.ts +65 -0
  1414. package/src/secrets/onboarding.ts +101 -0
  1415. package/src/secrets/register-framework-secrets.ts +228 -0
  1416. package/src/secrets/register.ts +129 -0
  1417. package/src/secrets/routes.ts +697 -0
  1418. package/src/secrets/schema.ts +52 -0
  1419. package/src/secrets/storage.ts +561 -0
  1420. package/src/secrets/substitution.ts +305 -0
  1421. package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +150 -0
  1422. package/src/server/action-change.ts +66 -0
  1423. package/src/server/action-discovery.ts +774 -0
  1424. package/src/server/action-routes.ts +658 -0
  1425. package/src/server/agent-access.ts +72 -0
  1426. package/src/server/agent-chat/action-filters-a2a.ts +339 -0
  1427. package/src/server/agent-chat/browser-team-tools.ts +510 -0
  1428. package/src/server/agent-chat/context-tools.ts +599 -0
  1429. package/src/server/agent-chat/framework-prompts.ts +467 -0
  1430. package/src/server/agent-chat/lazy-fs.ts +11 -0
  1431. package/src/server/agent-chat/mcp-glue.ts +91 -0
  1432. package/src/server/agent-chat/plugin-options.ts +379 -0
  1433. package/src/server/agent-chat/process-run-failure.ts +62 -0
  1434. package/src/server/agent-chat/prompt-resources.ts +1004 -0
  1435. package/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
  1436. package/src/server/agent-chat/request-surface.ts +71 -0
  1437. package/src/server/agent-chat/run-code-tools.ts +67 -0
  1438. package/src/server/agent-chat/script-entries.ts +796 -0
  1439. package/src/server/agent-chat/shared-thread.ts +301 -0
  1440. package/src/server/agent-chat/skill-frontmatter.ts +41 -0
  1441. package/src/server/agent-chat-plugin.ts +5930 -0
  1442. package/src/server/agent-discovery.ts +706 -0
  1443. package/src/server/agent-engine-api-key-route.ts +236 -0
  1444. package/src/server/agent-run-context.ts +204 -0
  1445. package/src/server/agent-teams-run-queue.ts +344 -0
  1446. package/src/server/agent-teams.ts +2257 -0
  1447. package/src/server/agents-bundle.ts +464 -0
  1448. package/src/server/analytics.ts +105 -0
  1449. package/src/server/app-base-path.ts +79 -0
  1450. package/src/server/app-name.ts +53 -0
  1451. package/src/server/app-url.ts +184 -0
  1452. package/src/server/attachment-actions.ts +276 -0
  1453. package/src/server/attribution.ts +214 -0
  1454. package/src/server/auth-marketing.ts +260 -0
  1455. package/src/server/auth-plugin.ts +32 -0
  1456. package/src/server/auth.ts +3803 -0
  1457. package/src/server/better-auth-instance.ts +1201 -0
  1458. package/src/server/builder-browser.ts +1701 -0
  1459. package/src/server/builder-design-systems.ts +668 -0
  1460. package/src/server/builder-space.ts +176 -0
  1461. package/src/server/captcha.ts +63 -0
  1462. package/src/server/capture-error.ts +64 -0
  1463. package/src/server/cli-capture.ts +141 -0
  1464. package/src/server/collab-plugin.ts +391 -0
  1465. package/src/server/complete-text.ts +231 -0
  1466. package/src/server/cookie-namespace.ts +159 -0
  1467. package/src/server/core-routes-plugin.ts +4122 -0
  1468. package/src/server/cors-origins.ts +60 -0
  1469. package/src/server/create-server.ts +268 -0
  1470. package/src/server/credential-provider.ts +1202 -0
  1471. package/src/server/csrf.ts +229 -0
  1472. package/src/server/date-utils.ts +42 -0
  1473. package/src/server/deep-link.ts +119 -0
  1474. package/src/server/derived-secret.ts +32 -0
  1475. package/src/server/design-token-utils.ts +1032 -0
  1476. package/src/server/desktop-sso.ts +83 -0
  1477. package/src/server/edge.ts +69 -0
  1478. package/src/server/email-actions.ts +218 -0
  1479. package/src/server/email-template.ts +192 -0
  1480. package/src/server/email-templates.ts +148 -0
  1481. package/src/server/email.ts +219 -0
  1482. package/src/server/embed-route.ts +283 -0
  1483. package/src/server/embed-session.ts +805 -0
  1484. package/src/server/embedded.ts +252 -0
  1485. package/src/server/entry-server.tsx +154 -0
  1486. package/src/server/framework-request-handler.ts +848 -0
  1487. package/src/server/fusion-app.ts +447 -0
  1488. package/src/server/google-auth-mode.ts +34 -0
  1489. package/src/server/google-auth-plugin.ts +496 -0
  1490. package/src/server/google-oauth-credentials.ts +128 -0
  1491. package/src/server/google-oauth.ts +972 -0
  1492. package/src/server/google-realtime-session.ts +182 -0
  1493. package/src/server/h3-helpers.ts +174 -0
  1494. package/src/server/http-response-telemetry.ts +396 -0
  1495. package/src/server/identity-sso-store.ts +304 -0
  1496. package/src/server/identity-sso.ts +514 -0
  1497. package/src/server/index.ts +593 -0
  1498. package/src/server/missing-key.ts +36 -0
  1499. package/src/server/oauth-helpers.ts +44 -0
  1500. package/src/server/oauth-public-origin.ts +44 -0
  1501. package/src/server/oauth-return-url.ts +120 -0
  1502. package/src/server/og-fonts-data.ts +15 -0
  1503. package/src/server/og-fonts.ts +75 -0
  1504. package/src/server/onboarding-html.ts +4040 -0
  1505. package/src/server/open-route.ts +311 -0
  1506. package/src/server/org-admin.ts +28 -0
  1507. package/src/server/poll-events.ts +88 -0
  1508. package/src/server/poll.ts +1224 -0
  1509. package/src/server/prompts/framework-core-compact.ts +107 -0
  1510. package/src/server/prompts/framework-core.ts +143 -0
  1511. package/src/server/prompts/index.ts +16 -0
  1512. package/src/server/prompts/model-overlays.ts +54 -0
  1513. package/src/server/prompts/shared-rules.ts +104 -0
  1514. package/src/server/realtime-voice.ts +967 -0
  1515. package/src/server/recap-image-route.ts +242 -0
  1516. package/src/server/recap-image-store.ts +185 -0
  1517. package/src/server/request-context.ts +416 -0
  1518. package/src/server/request-origin.ts +67 -0
  1519. package/src/server/resources-plugin.ts +119 -0
  1520. package/src/server/schema-prompt.ts +429 -0
  1521. package/src/server/scoped-key-storage.ts +223 -0
  1522. package/src/server/security-headers.ts +170 -0
  1523. package/src/server/self-dispatch.ts +224 -0
  1524. package/src/server/sentry-config.ts +73 -0
  1525. package/src/server/sentry-plugin.ts +138 -0
  1526. package/src/server/sentry.ts +444 -0
  1527. package/src/server/short-lived-token.ts +170 -0
  1528. package/src/server/social-og-image.ts +454 -0
  1529. package/src/server/sse.ts +102 -0
  1530. package/src/server/ssr-handler.ts +466 -0
  1531. package/src/server/transcribe-voice.ts +1076 -0
  1532. package/src/server/voice-providers-status.ts +118 -0
  1533. package/src/server/workspace-oauth.ts +31 -0
  1534. package/src/server/workspace-provider-oauth.ts +970 -0
  1535. package/src/session-replay-iframe-protocol.ts +58 -0
  1536. package/src/settings/handlers.ts +44 -0
  1537. package/src/settings/index.ts +34 -0
  1538. package/src/settings/org-settings.ts +83 -0
  1539. package/src/settings/script-helpers.ts +24 -0
  1540. package/src/settings/store.ts +247 -0
  1541. package/src/settings/user-settings.ts +47 -0
  1542. package/src/setup-connections/index.ts +90 -0
  1543. package/src/setup-connections/onboarding.ts +47 -0
  1544. package/src/shared/agent-access.ts +112 -0
  1545. package/src/shared/agent-chat.ts +124 -0
  1546. package/src/shared/agent-env.ts +46 -0
  1547. package/src/shared/agent-readable-resource.ts +111 -0
  1548. package/src/shared/agent-sidebar-url.ts +39 -0
  1549. package/src/shared/cache-control.ts +25 -0
  1550. package/src/shared/cloudflare-globals.d.ts +34 -0
  1551. package/src/shared/context-xray.ts +172 -0
  1552. package/src/shared/embed-auth.ts +6 -0
  1553. package/src/shared/index.ts +83 -0
  1554. package/src/shared/llm-connection.ts +42 -0
  1555. package/src/shared/markdown-block-split.ts +129 -0
  1556. package/src/shared/mcp-connect-content.ts +130 -0
  1557. package/src/shared/mcp-embed-headers.ts +175 -0
  1558. package/src/shared/mcp-integration-config.ts +101 -0
  1559. package/src/shared/merge-by-id.ts +14 -0
  1560. package/src/shared/oauth-state.ts +39 -0
  1561. package/src/shared/reasoning-effort.ts +228 -0
  1562. package/src/shared/route-warmup-config.ts +128 -0
  1563. package/src/shared/runtime.ts +31 -0
  1564. package/src/shared/social-meta.ts +82 -0
  1565. package/src/shared/streaming-text-smoothing.ts +184 -0
  1566. package/src/shared/truncate.ts +13 -0
  1567. package/src/shared/workspace-app-audience.ts +177 -0
  1568. package/src/shared/workspace-app-id.ts +54 -0
  1569. package/src/sharing/access.ts +585 -0
  1570. package/src/sharing/actions/create-agent-resource-link.ts +91 -0
  1571. package/src/sharing/actions/extension-change.ts +22 -0
  1572. package/src/sharing/actions/list-resource-shares.ts +93 -0
  1573. package/src/sharing/actions/set-resource-visibility.ts +91 -0
  1574. package/src/sharing/actions/share-resource.ts +322 -0
  1575. package/src/sharing/actions/unshare-resource.ts +72 -0
  1576. package/src/sharing/index.ts +35 -0
  1577. package/src/sharing/registry.ts +201 -0
  1578. package/src/sharing/schema.ts +99 -0
  1579. package/src/styles/agent-conversation.css +766 -0
  1580. package/src/styles/agent-native.css +938 -0
  1581. package/src/styles/blocks.css +1717 -0
  1582. package/src/styles/chat-history-list.css +1 -0
  1583. package/src/styles/rich-markdown-editor.css +1 -0
  1584. package/src/tailwind.preset.ts +140 -0
  1585. package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1586. package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1587. package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
  1588. package/src/templates/chat/AGENTS.md +3 -2
  1589. package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1590. package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1591. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
  1592. package/src/templates/default/AGENTS.md +6 -5
  1593. package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1594. package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1595. package/src/templates/headless/AGENTS.md +5 -4
  1596. package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1597. package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
  1598. package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1599. package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
  1600. package/src/templates/workspace-core/AGENTS.md +4 -4
  1601. package/src/templates/workspace-root/AGENTS.md +4 -4
  1602. package/src/terminal/cli-registry.ts +57 -0
  1603. package/src/terminal/index.ts +22 -0
  1604. package/src/terminal/pty-server.ts +389 -0
  1605. package/src/terminal/terminal-plugin.ts +265 -0
  1606. package/src/testing.ts +23 -0
  1607. package/src/tracking/index.ts +10 -0
  1608. package/src/tracking/providers.ts +422 -0
  1609. package/src/tracking/registry.ts +102 -0
  1610. package/src/tracking/route.ts +108 -0
  1611. package/src/tracking/types.ts +16 -0
  1612. package/src/transcription/builder-transcription.ts +118 -0
  1613. package/src/triggers/actions/list-automations.ts +99 -0
  1614. package/src/triggers/actions/manage-automation.ts +78 -0
  1615. package/src/triggers/actions.ts +333 -0
  1616. package/src/triggers/condition-evaluator.ts +163 -0
  1617. package/src/triggers/dispatcher.ts +536 -0
  1618. package/src/triggers/index.ts +13 -0
  1619. package/src/triggers/routes.ts +322 -0
  1620. package/src/triggers/types.ts +42 -0
  1621. package/src/types/pglite.d.ts +26 -0
  1622. package/src/usage/store.ts +698 -0
  1623. package/src/vite/action-types-plugin.ts +481 -0
  1624. package/src/vite/agent-web-plugin.ts +78 -0
  1625. package/src/vite/agents-bundle-plugin.ts +185 -0
  1626. package/src/vite/client.ts +3056 -0
  1627. package/src/vite/index.ts +21 -0
  1628. package/src/voice/index.ts +18 -0
  1629. package/src/voice/voice-cleanup-prompt.ts +38 -0
  1630. package/src/voice/voice-context.ts +217 -0
  1631. package/src/voice/voice-replacements.ts +75 -0
  1632. package/src/workspace-connections/credentials.ts +603 -0
  1633. package/src/workspace-connections/index.ts +72 -0
  1634. package/src/workspace-connections/lifecycle.ts +43 -0
  1635. package/src/workspace-connections/store.ts +1943 -0
  1636. package/src/workspace-files/index.ts +18 -0
  1637. package/src/workspace-files/store.ts +339 -0
  1638. package/src/workspace-files/tool.ts +266 -0
@@ -0,0 +1,2247 @@
1
+ import { execFile, execFileSync } from "child_process";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ import { fileURLToPath, pathToFileURL } from "url";
6
+
7
+ import {
8
+ DISPATCH_WORKSPACE_ROOT_REDIRECTS,
9
+ getWorkspaceAppIdValidationError,
10
+ } from "../shared/workspace-app-id.js";
11
+ import { setupAgentSymlinks } from "./setup-agents.js";
12
+ import {
13
+ coreTemplates,
14
+ getTemplate,
15
+ allTemplateNames,
16
+ type TemplateMeta,
17
+ } from "./templates-meta.js";
18
+ import { workspacifyApp, parseWorkspaceScope } from "./workspacify.js";
19
+
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+
23
+ const REPO = "BuilderIO/agent-native";
24
+ const TEMPLATES_DIR = "templates";
25
+ const POSTGRES_DEPENDENCY_VERSION = "^3.4.9";
26
+ const STANDALONE_EXACT_DEPENDENCY_OVERRIDES: Record<string, string> = {
27
+ "@react-router/dev": "8.1.0",
28
+ "@react-router/fs-routes": "8.1.0",
29
+ "react-router": "8.1.0",
30
+ };
31
+ const REACT_ROUTER_BUILD_DEPENDENCIES = [
32
+ "@react-router/dev",
33
+ "@react-router/fs-routes",
34
+ "react-router",
35
+ "vite",
36
+ ] as const;
37
+ const MINIMUM_RELEASE_AGE_EXCLUDES = [
38
+ '"@typescript/*"',
39
+ '"@sentry/*"',
40
+ "fast-xml-parser",
41
+ "typescript",
42
+ "typescript-7",
43
+ ];
44
+ const FIRST_PARTY_TARBALL_SYMLINK_EXCLUDES = [
45
+ "*/CLAUDE.md",
46
+ "*/.claude/skills",
47
+ ];
48
+ const localPackageTarballs = new Map<string, string>();
49
+
50
+ /**
51
+ * Tagged error for input that fails CLI-level validation (repo names, app
52
+ * names, etc.). The Sentry `beforeSend` hook in cli/index.ts drops events
53
+ * whose top-level exception type is `ValidationError` so we don't pollute
54
+ * Sentry with expected user-input rejections.
55
+ */
56
+ export class ValidationError extends Error {
57
+ constructor(message: string) {
58
+ super(message);
59
+ this.name = "ValidationError";
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Move the primitive-first and chat on-ramps to the top of the list so they
65
+ * line up with clack's default highlight.
66
+ */
67
+ function onRampFirst(templates: TemplateMeta[]): TemplateMeta[] {
68
+ return moveTemplatesToFront(templates, ["headless", "chat"]);
69
+ }
70
+
71
+ function moveTemplatesToFront(
72
+ templates: TemplateMeta[],
73
+ preferredNames: string[],
74
+ ): TemplateMeta[] {
75
+ const preferred = preferredNames
76
+ .map((name) => templates.find((t) => t.name === name))
77
+ .filter((template): template is TemplateMeta => Boolean(template));
78
+ if (preferred.length === 0) return templates;
79
+ const preferredSet = new Set(preferred.map((t) => t.name));
80
+ return [...preferred, ...templates.filter((t) => !preferredSet.has(t.name))];
81
+ }
82
+
83
+ /** Primitive-first scaffold option appended to standalone pickers. */
84
+ const HEADLESS_OPTION = {
85
+ name: "headless",
86
+ label: "Headless",
87
+ hint: "Action-first app with one hello primitive and no UI shell",
88
+ };
89
+
90
+ export interface CreateAppOptions {
91
+ /** Pre-select these templates in the picker. Comma-separated string or array. */
92
+ template?: string;
93
+ /** Scaffold a single standalone app (old behavior). Skips workspace creation. */
94
+ standalone?: boolean;
95
+ /** Internal: skip pnpm install at the end (for tests). */
96
+ noInstall?: boolean;
97
+ /**
98
+ * Internal: always scaffold a workspace and skip the start-shape prompt.
99
+ * Used by the deprecated `create-workspace` alias, whose contract is an
100
+ * unconditional workspace scaffold.
101
+ */
102
+ forceWorkspace?: boolean;
103
+ }
104
+
105
+ /**
106
+ * Main entry for `agent-native create [name]`.
107
+ *
108
+ * Default behavior: scaffold a workspace at <name>/ with a multi-select
109
+ * template picker. Use --standalone for the single-app standalone flow.
110
+ *
111
+ * If run *inside* an existing workspace, falls through to the add-app
112
+ * flow that scaffolds one new app under apps/<name>/.
113
+ */
114
+ export async function createApp(
115
+ name?: string,
116
+ opts?: CreateAppOptions,
117
+ ): Promise<void> {
118
+ const clack = await import("@clack/prompts");
119
+
120
+ // Reject an invalid provided name before any interactive prompt so bad input
121
+ // fails fast instead of blocking on the start-shape picker below.
122
+ if (name !== undefined) {
123
+ assertValidProjectName(name, clack);
124
+ }
125
+
126
+ // If we're already inside a workspace, the meaning of `create <name>` is
127
+ // "add a new app to this workspace". Delegate to add-app.
128
+ const workspace = detectWorkspace(process.cwd());
129
+ if (workspace) {
130
+ await addAppToWorkspace(name, opts);
131
+ return;
132
+ }
133
+
134
+ // Standalone escape hatch — behaves like the old single-app flow.
135
+ if (opts?.standalone) {
136
+ await createStandaloneApp(name, opts, clack);
137
+ return;
138
+ }
139
+
140
+ // When exactly one template is specified explicitly, treat it as a
141
+ // standalone scaffold (script-friendly, matches historic behavior).
142
+ // Use `--template a,b` or pass no --template to opt into the workspace
143
+ // flow with the multi-select picker.
144
+ const parsed = parseTemplateList(opts?.template);
145
+ // Headless can't live in a workspace, so reject it when more than one
146
+ // template is requested or when workspace semantics are forced.
147
+ if (
148
+ parsed.includes("headless") &&
149
+ (parsed.length > 1 || opts?.forceWorkspace)
150
+ ) {
151
+ clack.cancel(
152
+ "The headless scaffold is standalone-only. Use `agent-native create my-app --headless`, or use the Chat template when adding a UI app to a workspace.",
153
+ );
154
+ process.exit(1);
155
+ }
156
+ // A single explicit template scaffolds a standalone app, unless the caller
157
+ // forces workspace semantics (the deprecated `create-workspace` alias), in
158
+ // which case the template is preselected in the workspace picker below.
159
+ if (parsed.length === 1 && !opts?.forceWorkspace) {
160
+ await createStandaloneApp(name, opts, clack);
161
+ return;
162
+ }
163
+
164
+ // No template specified: ask what shape to start from before diving into
165
+ // "which templates?". The on-ramp choice implies the project structure, so
166
+ // we don't ask a separate "workspace or standalone?" question — Chat and
167
+ // Headless scaffold a single standalone app (the lightest starts; headless
168
+ // cannot live in a workspace), while Template continues into the workspace
169
+ // multi-select.
170
+ if (parsed.length === 0) {
171
+ // The deprecated `create-workspace` alias forces workspace semantics, so
172
+ // it must skip the start-shape prompt and scaffold a workspace directly.
173
+ if (opts?.forceWorkspace) {
174
+ await createWorkspaceInteractive(name, opts, clack);
175
+ return;
176
+ }
177
+ const shape = await promptStartShape(clack);
178
+ if (shape === "headless" || shape === "chat") {
179
+ await createStandaloneApp(name, { ...opts, template: shape }, clack);
180
+ return;
181
+ }
182
+ // shape === "template" → full app(s) in a workspace.
183
+ await createWorkspaceInteractive(name, opts, clack);
184
+ return;
185
+ }
186
+
187
+ // Multiple explicit templates: create a workspace with them.
188
+ await createWorkspaceInteractive(name, opts, clack);
189
+ }
190
+
191
+ /**
192
+ * Top-level on-ramp shown by the bare `create <name>` command (no flags). The
193
+ * choice made here implies the project structure, so we deliberately avoid a
194
+ * separate "workspace or standalone?" question:
195
+ * - "template" → full app(s) in a workspace (the multi-select picker)
196
+ * - "chat" → a single standalone chat UI app
197
+ * - "headless" → a single standalone action-first app with no UI shell
198
+ * Chat and headless are standalone on purpose: a monorepo is unnecessary
199
+ * ceremony for the lightest on-ramps, and headless cannot be a workspace
200
+ * member. Either can grow into a workspace later via `add-app`.
201
+ */
202
+ async function promptStartShape(
203
+ clack: typeof import("@clack/prompts"),
204
+ ): Promise<"template" | "chat" | "headless"> {
205
+ const choice = await clack.select(startShapePromptOptions());
206
+ if (clack.isCancel(choice)) {
207
+ clack.cancel("Cancelled.");
208
+ process.exit(0);
209
+ }
210
+ return choice as "template" | "chat" | "headless";
211
+ }
212
+
213
+ function startShapePromptOptions() {
214
+ return {
215
+ message: "How do you want to start?",
216
+ initialValue: "chat",
217
+ options: [
218
+ {
219
+ value: "chat",
220
+ label: "Chat",
221
+ hint: "A single app with a minimal chat UI and the browser shell wired up",
222
+ },
223
+ {
224
+ value: "template",
225
+ label: "Full template(s)",
226
+ hint: "Clone complete apps (Mail, Calendar, Slides, ...) into a workspace",
227
+ },
228
+ {
229
+ value: "headless",
230
+ label: "Headless",
231
+ hint: "A single action-first app with one primitive and no UI shell",
232
+ },
233
+ ],
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Validate a project name supplied on the command line. Mirrors the rule in
239
+ * `promptNameIfMissing` so an invalid name is rejected before any interactive
240
+ * prompt runs (the sub-flows re-validate, which is a harmless no-op).
241
+ */
242
+ function assertValidProjectName(
243
+ name: string,
244
+ clack: typeof import("@clack/prompts"),
245
+ ): void {
246
+ if (!/^[a-z][a-z0-9-]*$/.test(name)) {
247
+ clack.cancel(
248
+ `Invalid name "${name}". Use lowercase letters, numbers, and hyphens (must start with a letter).`,
249
+ );
250
+ process.exit(1);
251
+ }
252
+ }
253
+
254
+ /* ─────────────────────────────────────────────────────────────────────────
255
+ * Workspace creation (new default)
256
+ * ───────────────────────────────────────────────────────────────────────── */
257
+
258
+ async function createWorkspaceInteractive(
259
+ name: string | undefined,
260
+ opts: CreateAppOptions | undefined,
261
+ clack: typeof import("@clack/prompts"),
262
+ ): Promise<void> {
263
+ clack.intro("Create a new agent-native workspace");
264
+
265
+ name = await promptNameIfMissing(name, clack, "workspace", "my-platform");
266
+ const preselected = parseTemplateList(opts?.template);
267
+
268
+ clack.note(
269
+ [
270
+ `You're creating a workspace named "${name}". A workspace is a monorepo`,
271
+ "container — it isn't an app itself. Inside it you pick one or more apps",
272
+ "(below), and each app gets its own route, agent, and UI. Apps in the",
273
+ "same workspace share auth, database, and the agent chat. Add more apps",
274
+ "later with `npx @agent-native/core@latest add-app`. Chat is the UI on-ramp",
275
+ "for a minimal chat-first app with the browser shell already wired.",
276
+ "Dispatch is always included as the workspace control plane —",
277
+ "it owns shared secrets, messaging, approvals, and cross-app routing.",
278
+ ].join("\n"),
279
+ "About workspaces",
280
+ );
281
+
282
+ // Dispatch is the workspace control plane (shared secrets, messaging,
283
+ // approvals, cross-app routing) and is always scaffolded — the picker
284
+ // only shows the optional apps. If the user explicitly passed
285
+ // `--template=...`, those entries get unioned with dispatch.
286
+ const optionalPicks =
287
+ preselected.length > 0
288
+ ? preselected.filter((t) => t !== "dispatch")
289
+ : await promptTemplatePicker(preselected, clack, {
290
+ defaultTemplates: ["chat"],
291
+ preferredFirst: ["chat"],
292
+ excludeNames: ["dispatch"],
293
+ });
294
+ const templates = ["dispatch", ...optionalPicks];
295
+
296
+ const targetDir = path.resolve(process.cwd(), name);
297
+ if (fs.existsSync(targetDir)) {
298
+ clack.cancel(`Directory "${name}" already exists.`);
299
+ process.exit(1);
300
+ }
301
+
302
+ const s = clack.spinner();
303
+ s.start(`Scaffolding workspace "${name}"...`);
304
+ const appNames = new Set<string>();
305
+ const scaffoldedApps: string[] = [];
306
+
307
+ try {
308
+ await scaffoldWorkspaceRoot(targetDir, name);
309
+ const workspaceCoreName = `@${name}/shared`;
310
+
311
+ for (let i = 0; i < templates.length; i++) {
312
+ const templateName = templates[i];
313
+ const appName = workspaceAppNameForTemplateSelection(templateName);
314
+ validateWorkspaceAppName(appName, clack, {
315
+ allowDispatch: appName === "dispatch" && templateName === "dispatch",
316
+ });
317
+ if (appNames.has(appName)) {
318
+ clack.cancel(
319
+ `Workspace app "${appName}" is selected more than once. Choose unique app templates or app names.`,
320
+ );
321
+ process.exit(1);
322
+ }
323
+ appNames.add(appName);
324
+ scaffoldedApps.push(appName);
325
+ // Distinguish download vs local copy in the spinner so a multi-second
326
+ // GitHub fetch doesn't look like a frozen "Scaffolding..." message.
327
+ // Mirrors the local-vs-remote decision inside scaffoldAppTemplate.
328
+ const willDownload =
329
+ templateName !== "headless" && templateName.startsWith("github:")
330
+ ? true
331
+ : !findLocalTemplate(normalizeTemplateName(templateName));
332
+ s.message(
333
+ willDownload
334
+ ? `Downloading ${titleCase(appName)} template (${i + 1}/${templates.length})...`
335
+ : `Scaffolding ${titleCase(appName)} (${i + 1}/${templates.length})...`,
336
+ );
337
+ const appDir = path.join(targetDir, "apps", appName);
338
+ await scaffoldAppTemplate(appDir, templateName);
339
+ s.message(
340
+ `Configuring ${titleCase(appName)} (${i + 1}/${templates.length})...`,
341
+ );
342
+ replacePlaceholders(appDir, appName, appTitleForScaffold(appName), name);
343
+ rewriteTrackingAppId(appDir, appName, templateName);
344
+ workspacifyApp({
345
+ appDir,
346
+ appName,
347
+ templateName,
348
+ workspaceRoot: targetDir,
349
+ workspaceCoreName,
350
+ coreDependencyVersion: getCoreDependencyVersion(),
351
+ dispatchDependencyVersion: getDispatchDependencyVersion(),
352
+ toolkitDependencyVersion: getToolkitDependencyVersion(),
353
+ });
354
+ fixPackageJsonName(appDir, appName, templateName);
355
+ fixWebManifestName(appDir, appName, templateName);
356
+ rewriteNetlifyToml(appDir, appName, "workspace");
357
+ renameGitignore(appDir);
358
+ // Each app owns its own .claude / .agents symlinks.
359
+ setupAgentSymlinks(appDir);
360
+ }
361
+
362
+ s.message("Adding shared packages...");
363
+ await scaffoldRequiredPackages(templates, targetDir);
364
+
365
+ s.stop(
366
+ `Workspace scaffolded with ${templates.length} app${templates.length === 1 ? "" : "s"}.`,
367
+ );
368
+ } catch (err: any) {
369
+ s.stop("Failed to scaffold workspace.");
370
+ // Remove the partially-scaffolded workspace so a retry of `agent-native
371
+ // create <name>` doesn't trip the "Directory already exists" guard.
372
+ cleanupOnFailure(targetDir);
373
+ clack.cancel(err?.message ?? String(err));
374
+ process.exit(1);
375
+ }
376
+
377
+ tryGitInit(targetDir);
378
+
379
+ // Show the user the tree we just built so the workspace/app distinction is
380
+ // visible, not just described. First-time users routinely expect their
381
+ // workspace name to be the app — seeing apps/<template>/ subdirectories
382
+ // makes the structure concrete.
383
+ const treeLines = [
384
+ ` ${name}/ ← your workspace`,
385
+ ...scaffoldedApps.map(
386
+ (appName, i) =>
387
+ ` ${i === scaffoldedApps.length - 1 ? "└─" : "├─"} apps/${appName}/`.padEnd(
388
+ 30,
389
+ ) + ` ← app`,
390
+ ),
391
+ ];
392
+ const dispatchNextStep = [
393
+ `Once running, open Dispatch — you'll see "Workspace: ${titleCase(name)}"`,
394
+ `at the top, with all your apps listed under it.`,
395
+ ];
396
+
397
+ const installSteps = hasPnpm()
398
+ ? [
399
+ ` pnpm install`,
400
+ ` pnpm dev # starts Dispatch on http://localhost:8092`,
401
+ ]
402
+ : [
403
+ ` # pnpm is required but wasn't found on your PATH. Install it first:`,
404
+ ` npm install -g pnpm`,
405
+ ``,
406
+ ` pnpm install`,
407
+ ` pnpm dev # starts Dispatch on http://localhost:8092`,
408
+ ];
409
+
410
+ clack.outro(
411
+ [
412
+ `Created workspace "${name}" with ${templates.length} app${templates.length === 1 ? "" : "s"}:`,
413
+ ``,
414
+ ...treeLines,
415
+ ``,
416
+ `Next steps:`,
417
+ ``,
418
+ ` cd ${name}`,
419
+ ...installSteps,
420
+ ``,
421
+ ...dispatchNextStep,
422
+ ``,
423
+ `Add another app later: npx @agent-native/core@latest add-app`,
424
+ `Deploy the whole workspace: pnpm exec agent-native deploy`,
425
+ ].join("\n"),
426
+ );
427
+ }
428
+
429
+ function workspaceAppNameForTemplateSelection(templateName: string): string {
430
+ const normalized = normalizeTemplateName(templateName);
431
+ if (!normalized.startsWith("github:")) return templateName;
432
+ const repo = normalized.slice("github:".length).trim();
433
+ const repoName = repo.split("/").filter(Boolean).pop() ?? "app";
434
+ let appName = repoName
435
+ .toLowerCase()
436
+ .replace(/[^a-z0-9-]+/g, "-")
437
+ .replace(/-+/g, "-")
438
+ .replace(/^-+|-+$/g, "");
439
+ if (!appName) appName = "app";
440
+ if (!/^[a-z]/.test(appName)) appName = `app-${appName}`;
441
+ return appName;
442
+ }
443
+
444
+ /**
445
+ * Detect whether pnpm is on PATH. End-user machines often have npm/yarn but
446
+ * not pnpm; the workspace scaffold uses pnpm workspaces, so we surface a
447
+ * specific install hint in the outro when it's missing rather than letting
448
+ * the user hit `zsh: command not found: pnpm`.
449
+ */
450
+ function hasPnpm(): boolean {
451
+ try {
452
+ execFileSync("pnpm", ["--version"], { stdio: "ignore" });
453
+ return true;
454
+ } catch {
455
+ return false;
456
+ }
457
+ }
458
+
459
+ async function scaffoldWorkspaceRoot(
460
+ targetDir: string,
461
+ name: string,
462
+ ): Promise<void> {
463
+ const packageRoot = path.resolve(__dirname, "../..");
464
+ const rootTemplate = path.join(packageRoot, "src/templates/workspace-root");
465
+ const coreTemplate = path.join(packageRoot, "src/templates/workspace-core");
466
+
467
+ copyDir(rootTemplate, targetDir);
468
+ replacePlaceholders(targetDir, name, titleCase(name));
469
+ rewriteCoreDependencyVersions(targetDir);
470
+ renameGitignore(targetDir);
471
+
472
+ // Inject the catalog from this repo's pnpm-workspace.yaml so templates'
473
+ // `catalog:` version references resolve in the scaffolded workspace.
474
+ const catalog = loadCatalog();
475
+ if (Object.keys(catalog).length > 0) {
476
+ const wsPath = path.join(targetDir, "pnpm-workspace.yaml");
477
+ const existing = fs.existsSync(wsPath)
478
+ ? fs.readFileSync(wsPath, "utf-8")
479
+ : "";
480
+ if (!existing.includes("catalog:")) {
481
+ const catalogYaml = Object.entries(catalog)
482
+ .map(([k, v]) => ` "${k}": "${v}"`)
483
+ .join("\n");
484
+ fs.writeFileSync(
485
+ wsPath,
486
+ existing.trimEnd() + "\ncatalog:\n" + catalogYaml + "\n",
487
+ );
488
+ }
489
+ }
490
+
491
+ applyLocalWorkspaceOverrides(targetDir);
492
+
493
+ const corePackageDir = path.join(targetDir, "packages", "shared");
494
+ fs.mkdirSync(path.join(targetDir, "packages"), { recursive: true });
495
+ copyDir(coreTemplate, corePackageDir);
496
+ replacePlaceholders(corePackageDir, name, titleCase(name));
497
+ rewriteCoreDependencyVersions(corePackageDir);
498
+ setupAgentSymlinks(corePackageDir);
499
+
500
+ // Ensure apps/ exists (even if empty).
501
+ fs.mkdirSync(path.join(targetDir, "apps"), { recursive: true });
502
+
503
+ // Root-level agent instructions apply before an agent descends into an app.
504
+ linkWorkspaceRootSkills(targetDir);
505
+ setupAgentSymlinks(targetDir);
506
+ }
507
+
508
+ function linkWorkspaceRootSkills(targetDir: string): void {
509
+ const sharedSkillsDir = path.join(
510
+ targetDir,
511
+ "packages",
512
+ "shared",
513
+ ".agents",
514
+ "skills",
515
+ );
516
+ if (!fs.existsSync(sharedSkillsDir)) return;
517
+
518
+ const agentsDir = path.join(targetDir, ".agents");
519
+ const linkPath = path.join(agentsDir, "skills");
520
+ const target = "../packages/shared/.agents/skills";
521
+
522
+ fs.mkdirSync(agentsDir, { recursive: true });
523
+
524
+ try {
525
+ const stat = fs.lstatSync(linkPath);
526
+ if (stat.isSymbolicLink()) {
527
+ if (fs.readlinkSync(linkPath) === target) return;
528
+ fs.unlinkSync(linkPath);
529
+ } else {
530
+ return;
531
+ }
532
+ } catch {
533
+ // Missing link; create below.
534
+ }
535
+
536
+ try {
537
+ fs.symlinkSync(
538
+ target,
539
+ linkPath,
540
+ process.platform === "win32" ? "junction" : "dir",
541
+ );
542
+ } catch {
543
+ try {
544
+ copyDir(sharedSkillsDir, linkPath);
545
+ } catch {
546
+ // Best-effort fallback for environments that disallow symlinks.
547
+ }
548
+ }
549
+ }
550
+
551
+ /* ─────────────────────────────────────────────────────────────────────────
552
+ * Adding an app into an existing workspace
553
+ * ───────────────────────────────────────────────────────────────────────── */
554
+
555
+ /**
556
+ * Entry for `agent-native add-app [name]`. Called from inside a workspace.
557
+ * Shows the multi-select picker (excluding already-installed apps) and
558
+ * scaffolds each selected template under apps/<name>/.
559
+ *
560
+ * When `name` is provided with `--template foo`, scaffolds exactly one app
561
+ * named <name> using template foo (non-interactive).
562
+ */
563
+ export async function addAppToWorkspace(
564
+ name?: string,
565
+ opts?: CreateAppOptions,
566
+ ): Promise<void> {
567
+ const clack = await import("@clack/prompts");
568
+ const workspace = detectWorkspace(process.cwd());
569
+ if (!workspace) {
570
+ clack.cancel(
571
+ "Not inside a workspace. Run `agent-native create` to make one first, or use `--standalone`.",
572
+ );
573
+ process.exit(1);
574
+ }
575
+
576
+ applyLocalWorkspaceOverrides(workspace.workspaceRoot);
577
+
578
+ clack.intro("Add an app to your workspace");
579
+
580
+ const installed = listInstalledApps(workspace.workspaceRoot);
581
+
582
+ // Non-interactive path: name + single --template
583
+ const preselected = parseTemplateList(opts?.template);
584
+ if (preselected.includes("headless")) {
585
+ clack.cancel(
586
+ "The headless scaffold is standalone-only. Use `agent-native create my-app --headless` outside a workspace, or use the Chat template when adding a UI app to a workspace.",
587
+ );
588
+ process.exit(1);
589
+ }
590
+ if (name && preselected.length === 1) {
591
+ const tpl = preselected[0];
592
+ await scaffoldOneAppIntoWorkspace(workspace, name, tpl, clack);
593
+ return;
594
+ }
595
+
596
+ const hasDispatch = installed.includes("dispatch");
597
+ const templates = await promptTemplatePicker(preselected, clack, {
598
+ excludeNames: installed,
599
+ message: "Which apps do you want to add?",
600
+ defaultTemplates: hasDispatch ? undefined : ["dispatch"],
601
+ preferredFirst: hasDispatch ? ["chat"] : ["dispatch", "chat"],
602
+ recommendedNames: hasDispatch ? [] : ["dispatch"],
603
+ });
604
+ if (templates.length === 0) {
605
+ clack.cancel("No apps selected. Cancelled.");
606
+ process.exit(0);
607
+ }
608
+
609
+ for (const t of templates) {
610
+ await scaffoldOneAppIntoWorkspace(workspace, t, t, clack);
611
+ }
612
+ }
613
+
614
+ async function scaffoldOneAppIntoWorkspace(
615
+ workspace: { workspaceRoot: string; workspaceCoreName: string },
616
+ appName: string,
617
+ templateName: string,
618
+ clack: typeof import("@clack/prompts"),
619
+ ): Promise<void> {
620
+ // Dispatch is the one reserved-route exception: the canonical workspace
621
+ // control-plane app intentionally owns /dispatch.
622
+ validateWorkspaceAppName(appName, clack, {
623
+ allowDispatch: appName === "dispatch" && templateName === "dispatch",
624
+ });
625
+ const appsDir = path.join(workspace.workspaceRoot, "apps");
626
+ fs.mkdirSync(appsDir, { recursive: true });
627
+ const appDir = path.join(appsDir, appName);
628
+
629
+ if (fs.existsSync(appDir)) {
630
+ clack.cancel(`Directory "apps/${appName}" already exists.`);
631
+ process.exit(1);
632
+ }
633
+
634
+ const s = clack.spinner();
635
+ s.start(
636
+ `Working... no action needed. Scaffolding apps/${appName} from ${templateName}.`,
637
+ );
638
+
639
+ try {
640
+ await scaffoldAppTemplate(appDir, templateName);
641
+ replacePlaceholders(
642
+ appDir,
643
+ appName,
644
+ appTitleForScaffold(appName),
645
+ path.basename(workspace.workspaceRoot),
646
+ );
647
+ rewriteTrackingAppId(appDir, appName, templateName);
648
+ workspacifyApp({
649
+ appDir,
650
+ appName,
651
+ templateName,
652
+ workspaceRoot: workspace.workspaceRoot,
653
+ workspaceCoreName: workspace.workspaceCoreName,
654
+ coreDependencyVersion: getCoreDependencyVersion(),
655
+ dispatchDependencyVersion: getDispatchDependencyVersion(),
656
+ toolkitDependencyVersion: getToolkitDependencyVersion(),
657
+ });
658
+ fixPackageJsonName(appDir, appName, templateName);
659
+ fixWebManifestName(appDir, appName, templateName);
660
+ rewriteNetlifyToml(appDir, appName, "workspace");
661
+ renameGitignore(appDir);
662
+ setupAgentSymlinks(appDir);
663
+ await scaffoldRequiredPackages([templateName], workspace.workspaceRoot);
664
+ s.stop(`Scaffolded apps/${appName}.`);
665
+ } catch (err: any) {
666
+ s.stop(`Failed to scaffold apps/${appName}.`);
667
+ cleanupOnFailure(appDir);
668
+ clack.cancel(err?.message ?? String(err));
669
+ process.exit(1);
670
+ }
671
+
672
+ clack.outro(
673
+ [
674
+ `Done!`,
675
+ ``,
676
+ ` pnpm install`,
677
+ ` pnpm dev`,
678
+ ``,
679
+ `The workspace gateway will detect apps/${appName} and serve it at /${appName}.`,
680
+ ].join("\n"),
681
+ );
682
+ }
683
+
684
+ /* ─────────────────────────────────────────────────────────────────────────
685
+ * Standalone creation (escape hatch)
686
+ * ───────────────────────────────────────────────────────────────────────── */
687
+
688
+ async function createStandaloneApp(
689
+ name: string | undefined,
690
+ opts: CreateAppOptions | undefined,
691
+ clack: typeof import("@clack/prompts"),
692
+ ): Promise<void> {
693
+ clack.intro("Create a new standalone agent-native app");
694
+
695
+ name = await promptNameIfMissing(name, clack, "app", "my-app");
696
+
697
+ const targetDir = path.resolve(process.cwd(), name);
698
+ if (fs.existsSync(targetDir)) {
699
+ clack.cancel(`Directory "${name}" already exists.`);
700
+ process.exit(1);
701
+ }
702
+
703
+ // Standalone is single-select — pick one template.
704
+ let template =
705
+ opts?.template && !opts.template.includes(",") ? opts.template : undefined;
706
+ if (!template) {
707
+ const picked = await clack.select({
708
+ message: "Which template would you like to use?",
709
+ options: [
710
+ {
711
+ value: HEADLESS_OPTION.name,
712
+ label: HEADLESS_OPTION.label,
713
+ hint: HEADLESS_OPTION.hint,
714
+ },
715
+ ...onRampFirst(coreTemplates())
716
+ .filter((t) => t.name !== HEADLESS_OPTION.name)
717
+ .map((t) => ({
718
+ value: t.name,
719
+ label: t.label,
720
+ hint: t.hint,
721
+ })),
722
+ ],
723
+ });
724
+ if (clack.isCancel(picked)) {
725
+ clack.cancel("Cancelled.");
726
+ process.exit(0);
727
+ }
728
+ template = picked as string;
729
+ }
730
+ template = normalizeTemplateName(template);
731
+
732
+ const s = clack.spinner();
733
+ s.start(
734
+ template === "headless"
735
+ ? "Scaffolding the headless agent app..."
736
+ : `Downloading the ${template} template from GitHub...`,
737
+ );
738
+ try {
739
+ await scaffoldAppTemplate(targetDir, template);
740
+ s.message(`Setting up ${name}…`);
741
+ postProcessStandalone(name, targetDir, template);
742
+ s.stop("App created!");
743
+ } catch (err: any) {
744
+ s.stop("Failed to create app.");
745
+ cleanupOnFailure(targetDir);
746
+ clack.cancel(err?.message ?? String(err));
747
+ process.exit(1);
748
+ }
749
+
750
+ tryGitInit(targetDir);
751
+
752
+ if (template === "headless") {
753
+ clack.outro(
754
+ [
755
+ "Done! Next steps:",
756
+ "",
757
+ ` cd ${name}`,
758
+ " pnpm install",
759
+ " pnpm action hello --name Builder",
760
+ ` pnpm agent "Call hello for Builder"`,
761
+ "",
762
+ "Add a UI later by starting from the Chat template; `agent-native add` is reserved for integration blueprints.",
763
+ ].join("\n"),
764
+ );
765
+ } else {
766
+ clack.outro(
767
+ `Done! Next steps:\n\n cd ${name}\n pnpm install\n pnpm dev`,
768
+ );
769
+ }
770
+ }
771
+
772
+ /**
773
+ * Remove a partially-scaffolded target directory after a scaffold failure so a
774
+ * retry doesn't hit the "Directory already exists" guard. Best-effort — the
775
+ * underlying failure is what we want surfaced, so we swallow rm errors and
776
+ * skip if the directory is somehow already gone.
777
+ */
778
+ function cleanupOnFailure(targetDir: string): void {
779
+ try {
780
+ if (fs.existsSync(targetDir)) {
781
+ fs.rmSync(targetDir, { recursive: true, force: true });
782
+ }
783
+ } catch {
784
+ // Ignore — original error is more useful than a cleanup failure.
785
+ }
786
+ }
787
+
788
+ /* ─────────────────────────────────────────────────────────────────────────
789
+ * Shared scaffolding helpers
790
+ * ───────────────────────────────────────────────────────────────────────── */
791
+
792
+ /**
793
+ * Scaffold a single app template into `targetDir`. Resolves:
794
+ * - "headless" / legacy "blank" → bundled action-first template
795
+ * - "github:user/repo" → download the whole repo
796
+ * - first-party template name → use a bundled copy or download its subdir
797
+ * from BuilderIO/agent-native
798
+ */
799
+ async function scaffoldAppTemplate(
800
+ targetDir: string,
801
+ template: string,
802
+ ): Promise<void> {
803
+ fs.mkdirSync(path.dirname(targetDir), { recursive: true });
804
+
805
+ // Normalize legacy / renamed aliases.
806
+ let resolved = normalizeTemplateName(template);
807
+
808
+ if (resolved === "headless") {
809
+ const packageRoot = path.resolve(__dirname, "../..");
810
+ const headlessDir = path.join(packageRoot, "src/templates/headless");
811
+ if (!fs.existsSync(headlessDir)) {
812
+ throw new Error(
813
+ `Headless template not found at ${headlessDir}. Is the package installed correctly?`,
814
+ );
815
+ }
816
+ copyDir(headlessDir, targetDir);
817
+ return;
818
+ }
819
+
820
+ if (resolved.startsWith("github:")) {
821
+ const repo = resolved.slice("github:".length);
822
+ await downloadGitHubRepo(repo, targetDir);
823
+ return;
824
+ }
825
+
826
+ if (!getTemplate(resolved)) {
827
+ throw new Error(
828
+ `Unknown template "${template}". Known: ${allTemplateNames().join(", ")} — or use github:user/repo for community templates.`,
829
+ );
830
+ }
831
+
832
+ // If running from the framework monorepo with a local templates/ dir, use
833
+ // that. Otherwise download from GitHub. This keeps `agent-native create`
834
+ // fast during framework development.
835
+ const sourceTemplate = templateSourceName(resolved);
836
+ const localTemplate = findLocalTemplate(sourceTemplate);
837
+ if (localTemplate) {
838
+ copyDir(localTemplate, targetDir);
839
+ } else {
840
+ await downloadGitHubSubdir(
841
+ REPO,
842
+ `${TEMPLATES_DIR}/${sourceTemplate}`,
843
+ targetDir,
844
+ );
845
+ }
846
+ }
847
+
848
+ function templateSourceName(name: string): string {
849
+ if (name === "starter") return "chat";
850
+ return name;
851
+ }
852
+
853
+ /**
854
+ * Prefer a nearby templates/<name> or src/templates/<name> directory. This
855
+ * covers the framework checkout, the dist/templates copy bundled into
856
+ * published CLI packages, and source templates included in package files;
857
+ * packages that do not bundle a template fall back to GitHub.
858
+ */
859
+ function findLocalTemplate(name: string): string | undefined {
860
+ return findLocalTemplateFrom(path.resolve(__dirname), name);
861
+ }
862
+
863
+ function findLocalTemplateFrom(
864
+ startDir: string,
865
+ name: string,
866
+ ): string | undefined {
867
+ let dir = path.resolve(startDir);
868
+ for (let i = 0; i < 10; i++) {
869
+ for (const templatesDir of ["templates", "src/templates"]) {
870
+ const candidate = path.join(dir, templatesDir, name);
871
+ if (fs.existsSync(path.join(candidate, "package.json"))) {
872
+ return candidate;
873
+ }
874
+ }
875
+ const parent = path.dirname(dir);
876
+ if (parent === dir) break;
877
+ dir = parent;
878
+ }
879
+ return undefined;
880
+ }
881
+
882
+ function normalizeTemplateName(template: string): string {
883
+ if (template === "blank") return "headless";
884
+ if (template === "image" || template === "images" || template === "asset") {
885
+ return "assets";
886
+ }
887
+ return template;
888
+ }
889
+
890
+ /**
891
+ * Find a local packages/<name> directory (for framework development).
892
+ * Returns undefined when running as a published npm package.
893
+ */
894
+ function findLocalPackage(name: string): string | undefined {
895
+ let dir = path.resolve(__dirname);
896
+ for (let i = 0; i < 10; i++) {
897
+ const candidate = path.join(dir, "packages", name);
898
+ if (fs.existsSync(path.join(candidate, "package.json"))) {
899
+ return candidate;
900
+ }
901
+ const parent = path.dirname(dir);
902
+ if (parent === dir) break;
903
+ dir = parent;
904
+ }
905
+ return undefined;
906
+ }
907
+
908
+ /**
909
+ * Pack a local framework package before linking it into a generated app.
910
+ * Raw file: dependencies retain workspace-only catalog references, while a
911
+ * packed artifact has the publish-ready manifest that consumers receive.
912
+ */
913
+ function localPackageTarball(packageDir: string): string {
914
+ const cached = localPackageTarballs.get(packageDir);
915
+ if (cached) return cached;
916
+
917
+ const packDir = fs.mkdtempSync(
918
+ path.join(os.tmpdir(), "agent-native-local-package-"),
919
+ );
920
+ const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
921
+ execFileSync(pnpm, ["pack", "--pack-destination", packDir], {
922
+ cwd: packageDir,
923
+ encoding: "utf-8",
924
+ env: { ...process.env, npm_config_ignore_scripts: "true" },
925
+ stdio: "pipe",
926
+ });
927
+
928
+ const tarballs = fs
929
+ .readdirSync(packDir)
930
+ .filter((entry) => entry.endsWith(".tgz"));
931
+ if (tarballs.length !== 1) {
932
+ throw new Error(
933
+ `Expected one packed local package artifact in ${packDir}, found ${tarballs.length}.`,
934
+ );
935
+ }
936
+
937
+ const tarball = pathToFileURL(path.join(packDir, tarballs[0]!)).href;
938
+ localPackageTarballs.set(packageDir, tarball);
939
+ return tarball;
940
+ }
941
+
942
+ /**
943
+ * Scaffold internal workspace packages required by the selected templates.
944
+ * Deduplicates so each package is only copied once even if multiple
945
+ * templates need it.
946
+ */
947
+ async function scaffoldRequiredPackages(
948
+ templateNames: string[],
949
+ workspaceRoot: string,
950
+ ): Promise<void> {
951
+ const needed = new Set<string>();
952
+ for (const t of templateNames) {
953
+ const meta = getTemplate(t);
954
+ if (meta?.requiredPackages) {
955
+ for (const p of meta.requiredPackages) needed.add(p);
956
+ }
957
+ }
958
+
959
+ for (const pkgName of needed) {
960
+ const targetDir = path.join(workspaceRoot, "packages", pkgName);
961
+ if (fs.existsSync(targetDir)) continue;
962
+
963
+ fs.mkdirSync(path.join(workspaceRoot, "packages"), { recursive: true });
964
+
965
+ const localPkg = findLocalPackage(pkgName);
966
+ if (localPkg) {
967
+ copyDir(localPkg, targetDir);
968
+ } else {
969
+ await downloadGitHubSubdir(REPO, `packages/${pkgName}`, targetDir);
970
+ }
971
+
972
+ // The copied package may have published framework packages as workspace:*
973
+ // deps. Convert them to published ranges because these package-backed
974
+ // modules are npm dependencies, not scaffolded workspace members.
975
+ const pkgJsonPath = path.join(targetDir, "package.json");
976
+ if (fs.existsSync(pkgJsonPath)) {
977
+ try {
978
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
979
+ for (const depType of [
980
+ "dependencies",
981
+ "devDependencies",
982
+ "peerDependencies",
983
+ ] as const) {
984
+ const deps = pkg[depType];
985
+ if (!deps) continue;
986
+ for (const [key, val] of Object.entries(deps)) {
987
+ if (
988
+ typeof val === "string" &&
989
+ val.startsWith("workspace:") &&
990
+ key === "@agent-native/core"
991
+ ) {
992
+ deps[key] = getCoreDependencyVersion();
993
+ }
994
+ if (
995
+ typeof val === "string" &&
996
+ val.startsWith("workspace:") &&
997
+ key === "@agent-native/toolkit"
998
+ ) {
999
+ deps[key] = getToolkitDependencyVersion();
1000
+ }
1001
+ }
1002
+ }
1003
+ fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + "\n");
1004
+ } catch {}
1005
+ }
1006
+ }
1007
+
1008
+ // Add a postinstall script to build workspace packages so their dist/
1009
+ // directories exist even when downloaded from GitHub (where dist/ is
1010
+ // gitignored).
1011
+ if (needed.size > 0) {
1012
+ const rootPkgPath = path.join(workspaceRoot, "package.json");
1013
+ if (fs.existsSync(rootPkgPath)) {
1014
+ try {
1015
+ const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
1016
+ rootPkg.scripts = rootPkg.scripts ?? {};
1017
+ const builds = [...needed]
1018
+ .map((n) => `pnpm --filter ./packages/${n} build`)
1019
+ .join(" && ");
1020
+ const existing = rootPkg.scripts.postinstall;
1021
+ if (existing) {
1022
+ if (!existing.includes(builds)) {
1023
+ rootPkg.scripts.postinstall = `${existing} && ${builds}`;
1024
+ }
1025
+ } else {
1026
+ rootPkg.scripts.postinstall = builds;
1027
+ }
1028
+ fs.writeFileSync(rootPkgPath, JSON.stringify(rootPkg, null, 2) + "\n");
1029
+ } catch {}
1030
+ }
1031
+ }
1032
+ }
1033
+
1034
+ /**
1035
+ * Post-process a standalone scaffold: replace placeholders, strip
1036
+ * workspace:* deps, set up agent symlinks, etc.
1037
+ */
1038
+ function postProcessStandalone(
1039
+ name: string,
1040
+ targetDir: string,
1041
+ templateName?: string,
1042
+ ): void {
1043
+ const appTitle = appTitleForScaffold(name);
1044
+ replacePlaceholders(targetDir, name, appTitle);
1045
+ rewriteTrackingAppId(targetDir, name, templateName);
1046
+ rewriteAgentChatAppId(targetDir, name, templateName);
1047
+ fixPackageJsonName(targetDir, name, templateName);
1048
+ fixWebManifestName(targetDir, name, templateName);
1049
+ rewriteNetlifyToml(targetDir, name, "standalone");
1050
+
1051
+ for (const base of ["learnings"]) {
1052
+ const defaultsFile = path.join(targetDir, `${base}.defaults.md`);
1053
+ const targetFile = path.join(targetDir, `${base}.md`);
1054
+ if (fs.existsSync(defaultsFile) && !fs.existsSync(targetFile)) {
1055
+ fs.copyFileSync(defaultsFile, targetFile);
1056
+ }
1057
+ }
1058
+
1059
+ renameGitignore(targetDir);
1060
+
1061
+ // No monorepo-only files to drop for standalone scaffolds.
1062
+ // DEVELOPING.md is intentionally kept: it documents local run commands,
1063
+ // DATABASE_URL defaults, and other local-run instructions that are equally
1064
+ // valid for standalone apps.
1065
+
1066
+ // Resolve workspace:* and catalog: deps for standalone projects.
1067
+ // catalog: references only resolve inside a pnpm workspace with a catalog
1068
+ // defined in pnpm-workspace.yaml — standalone scaffolds don't have one.
1069
+ const catalog = loadCatalog();
1070
+ const pkgPath = path.join(targetDir, "package.json");
1071
+ if (fs.existsSync(pkgPath)) {
1072
+ try {
1073
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1074
+ for (const depType of [
1075
+ "dependencies",
1076
+ "devDependencies",
1077
+ "peerDependencies",
1078
+ ] as const) {
1079
+ const deps = pkg[depType];
1080
+ if (!deps) continue;
1081
+ for (const [key, val] of Object.entries(deps)) {
1082
+ const exactOverride = STANDALONE_EXACT_DEPENDENCY_OVERRIDES[key];
1083
+ if (exactOverride) {
1084
+ deps[key] = exactOverride;
1085
+ } else if (key === "@agent-native/core") {
1086
+ deps[key] = getCoreDependencyVersion();
1087
+ } else if (key === "@agent-native/toolkit") {
1088
+ deps[key] = getToolkitDependencyVersion();
1089
+ } else if (typeof val === "string" && val.startsWith("workspace:")) {
1090
+ deps[key] = "latest";
1091
+ } else if (typeof val === "string" && val === "catalog:") {
1092
+ deps[key] = catalog[key] ?? "latest";
1093
+ }
1094
+ }
1095
+ }
1096
+ // Ensure pnpm.onlyBuiltDependencies is set so native packages
1097
+ // (better-sqlite3, esbuild, node-pty) compile their postinstall scripts
1098
+ // under pnpm 10+ without prompting for `pnpm approve-builds`.
1099
+ pkg.dependencies = pkg.dependencies ?? {};
1100
+ pkg.dependencies.postgres ??= POSTGRES_DEPENDENCY_VERSION;
1101
+ ensureReactRouterBuildDependencies(pkg);
1102
+
1103
+ const requiredBuilt = ["better-sqlite3", "esbuild", "node-pty"];
1104
+ if (!pkg.pnpm || typeof pkg.pnpm !== "object") {
1105
+ pkg.pnpm = {};
1106
+ }
1107
+ const existing = Array.isArray(pkg.pnpm.onlyBuiltDependencies)
1108
+ ? pkg.pnpm.onlyBuiltDependencies
1109
+ : [];
1110
+ pkg.pnpm.onlyBuiltDependencies = Array.from(
1111
+ new Set([...existing, ...requiredBuilt]),
1112
+ );
1113
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
1114
+ } catch {}
1115
+ }
1116
+
1117
+ // Write pnpm-workspace.yaml for pnpm v11 compatibility. pnpm v11 no longer
1118
+ // reads the pnpm field in package.json, so allowBuilds and overrides must
1119
+ // live here. Merge into any existing file (e.g. from the default template)
1120
+ // without creating duplicate section headers.
1121
+ const wsPath = path.join(targetDir, "pnpm-workspace.yaml");
1122
+ try {
1123
+ const existing = fs.existsSync(wsPath)
1124
+ ? fs.readFileSync(wsPath, "utf-8")
1125
+ : "";
1126
+ const sections: Record<string, Record<string, string>> = {
1127
+ allowBuilds: {
1128
+ "better-sqlite3": "true",
1129
+ esbuild: "true",
1130
+ "node-pty": "true",
1131
+ },
1132
+ };
1133
+ if (templateName !== "headless") {
1134
+ sections.overrides = {
1135
+ '"@assistant-ui/store"': '">=0.2.9 <0.2.14"',
1136
+ '"@assistant-ui/tap"': '"^0.5.14"',
1137
+ nf3: '"0.3.17"',
1138
+ };
1139
+ }
1140
+ const localToolkit = localToolkitOverride();
1141
+ if (localToolkit) {
1142
+ sections.overrides ??= {};
1143
+ sections.overrides['"@agent-native/toolkit"'] =
1144
+ JSON.stringify(localToolkit);
1145
+ }
1146
+ const localRecapCli = localRecapCliOverride();
1147
+ if (localRecapCli) {
1148
+ sections.overrides ??= {};
1149
+ sections.overrides['"@agent-native/recap-cli"'] =
1150
+ JSON.stringify(localRecapCli);
1151
+ }
1152
+ let updated = mergeWorkspaceYamlSections(existing, sections);
1153
+ updated = mergeWorkspaceYamlListItems(
1154
+ updated,
1155
+ "minimumReleaseAgeExclude",
1156
+ MINIMUM_RELEASE_AGE_EXCLUDES,
1157
+ );
1158
+ if (updated !== existing) {
1159
+ fs.writeFileSync(wsPath, updated);
1160
+ }
1161
+ } catch {}
1162
+
1163
+ fixStandaloneTsconfig(targetDir, templateName);
1164
+
1165
+ setupAgentSymlinks(targetDir);
1166
+ }
1167
+
1168
+ function ensureReactRouterBuildDependencies(pkg: Record<string, any>): void {
1169
+ const allDeps = {
1170
+ ...pkg.dependencies,
1171
+ ...pkg.devDependencies,
1172
+ ...pkg.peerDependencies,
1173
+ };
1174
+ if (
1175
+ !allDeps["@react-router/dev"] &&
1176
+ !allDeps["react-router"] &&
1177
+ !allDeps["@react-router/fs-routes"]
1178
+ ) {
1179
+ return;
1180
+ }
1181
+
1182
+ pkg.dependencies = pkg.dependencies ?? {};
1183
+ for (const key of REACT_ROUTER_BUILD_DEPENDENCIES) {
1184
+ const existing =
1185
+ pkg.dependencies[key] ??
1186
+ pkg.devDependencies?.[key] ??
1187
+ pkg.peerDependencies?.[key];
1188
+ if (!existing) continue;
1189
+ pkg.dependencies[key] =
1190
+ STANDALONE_EXACT_DEPENDENCY_OVERRIDES[key] ?? existing;
1191
+ delete pkg.devDependencies?.[key];
1192
+ delete pkg.peerDependencies?.[key];
1193
+ }
1194
+ }
1195
+
1196
+ function fixStandaloneTsconfig(targetDir: string, templateName?: string): void {
1197
+ const tsconfigPath = path.join(targetDir, "tsconfig.json");
1198
+ if (!fs.existsSync(tsconfigPath)) return;
1199
+ try {
1200
+ const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, "utf-8")) as {
1201
+ compilerOptions?: Record<string, unknown>;
1202
+ };
1203
+ tsconfig.compilerOptions ??= {};
1204
+ const hasUiApp =
1205
+ templateName !== "headless" && fs.existsSync(path.join(targetDir, "app"));
1206
+ const paths = {
1207
+ ...((tsconfig.compilerOptions.paths as Record<string, string[]>) ?? {}),
1208
+ };
1209
+ paths["*"] ??= ["./*"];
1210
+ if (hasUiApp) {
1211
+ paths["@/*"] ??= ["./app/*"];
1212
+ paths["@shared/*"] ??= ["./shared/*"];
1213
+ }
1214
+ // baseUrl is deprecated/errors in TS 6 (TS5101/TS5102) and removed in TS 7
1215
+ // (tsc, which CI runs). paths already resolve relative to this tsconfig,
1216
+ // and the "*": ["./*"] entry replaces baseUrl's bare-specifier resolution,
1217
+ // so never emit baseUrl into scaffolds.
1218
+ delete tsconfig.compilerOptions.baseUrl;
1219
+ tsconfig.compilerOptions.paths = paths;
1220
+ fs.writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\n`);
1221
+ } catch {}
1222
+ }
1223
+
1224
+ /* ─────────────────────────────────────────────────────────────────────────
1225
+ * Prompting helpers
1226
+ * ───────────────────────────────────────────────────────────────────────── */
1227
+
1228
+ async function promptNameIfMissing(
1229
+ name: string | undefined,
1230
+ clack: typeof import("@clack/prompts"),
1231
+ kind: "workspace" | "app",
1232
+ placeholder: string,
1233
+ ): Promise<string> {
1234
+ if (name) {
1235
+ if (!/^[a-z][a-z0-9-]*$/.test(name)) {
1236
+ clack.cancel(
1237
+ `Invalid ${kind} name "${name}". Use lowercase letters, numbers, and hyphens.`,
1238
+ );
1239
+ process.exit(1);
1240
+ }
1241
+ return name;
1242
+ }
1243
+ const result = await clack.text({
1244
+ message: `What is your ${kind} name?`,
1245
+ placeholder,
1246
+ validate(value) {
1247
+ if (!value)
1248
+ return `${kind[0].toUpperCase() + kind.slice(1)} name is required`;
1249
+ if (!/^[a-z][a-z0-9-]*$/.test(value)) {
1250
+ return "Use lowercase letters, numbers, and hyphens (must start with a letter)";
1251
+ }
1252
+ if (fs.existsSync(path.resolve(process.cwd(), value))) {
1253
+ return `Directory "${value}" already exists`;
1254
+ }
1255
+ },
1256
+ });
1257
+ if (clack.isCancel(result)) {
1258
+ clack.cancel("Cancelled.");
1259
+ process.exit(0);
1260
+ }
1261
+ return result as string;
1262
+ }
1263
+
1264
+ async function promptTemplatePicker(
1265
+ preselected: string[],
1266
+ clack: typeof import("@clack/prompts"),
1267
+ opts?: {
1268
+ defaultTemplates?: string[];
1269
+ excludeNames?: string[];
1270
+ message?: string;
1271
+ preferredFirst?: string[];
1272
+ recommendedNames?: string[];
1273
+ },
1274
+ ): Promise<string[]> {
1275
+ const excluded = new Set(opts?.excludeNames ?? []);
1276
+ const orderedTemplates = opts?.preferredFirst
1277
+ ? moveTemplatesToFront(coreTemplates(), opts.preferredFirst)
1278
+ : onRampFirst(coreTemplates());
1279
+ const recommendedNames = new Set(opts?.recommendedNames ?? []);
1280
+ const options = orderedTemplates
1281
+ .filter((t) => !excluded.has(t.name))
1282
+ .map((t) => ({
1283
+ value: t.name,
1284
+ label: recommendedNames.has(t.name)
1285
+ ? `${t.label} (recommended)`
1286
+ : t.label,
1287
+ hint:
1288
+ recommendedNames.has(t.name) && t.name === "dispatch"
1289
+ ? "Recommended workspace control plane: secrets, messaging, approvals, and A2A delegation"
1290
+ : t.hint,
1291
+ }));
1292
+
1293
+ // If there's nothing left to pick, the caller gets an empty selection —
1294
+ // they decide how to handle it.
1295
+ if (options.length === 0) return [];
1296
+
1297
+ // Default pre-selection: what the user passed via --template, falling
1298
+ // back to caller defaults, then to "chat" when available.
1299
+ const defaults =
1300
+ preselected.length > 0
1301
+ ? preselected.filter((p) => options.some((o) => o.value === p))
1302
+ : opts?.defaultTemplates
1303
+ ? opts.defaultTemplates.filter((p) =>
1304
+ options.some((o) => o.value === p),
1305
+ )
1306
+ : options.some((o) => o.value === "chat")
1307
+ ? ["chat"]
1308
+ : [];
1309
+
1310
+ const baseMessage = opts?.message ?? "Which apps would you like to include?";
1311
+ const result = await clack.multiselect({
1312
+ message: `${baseMessage}\n (↑/↓ move · space to toggle · enter to confirm)`,
1313
+ options,
1314
+ initialValues: defaults,
1315
+ required: false,
1316
+ });
1317
+ if (clack.isCancel(result)) {
1318
+ clack.cancel("Cancelled.");
1319
+ process.exit(0);
1320
+ }
1321
+ return result as string[];
1322
+ }
1323
+
1324
+ function parseTemplateList(input?: string): string[] {
1325
+ if (!input) return [];
1326
+ return input
1327
+ .split(",")
1328
+ .map((s) => normalizeTemplateName(s.trim()))
1329
+ .filter(Boolean);
1330
+ }
1331
+
1332
+ function listInstalledApps(workspaceRoot: string): string[] {
1333
+ const appsDir = path.join(workspaceRoot, "apps");
1334
+ if (!fs.existsSync(appsDir)) return [];
1335
+ return fs
1336
+ .readdirSync(appsDir, { withFileTypes: true })
1337
+ .filter((e) => e.isDirectory())
1338
+ .map((e) => e.name);
1339
+ }
1340
+
1341
+ /* ─────────────────────────────────────────────────────────────────────────
1342
+ * Workspace detection
1343
+ * ───────────────────────────────────────────────────────────────────────── */
1344
+
1345
+ /**
1346
+ * Walk up from startDir looking for a package.json with
1347
+ * `agent-native.workspaceCore` set. Returns the workspace root and core
1348
+ * package name, or null if not inside a workspace.
1349
+ */
1350
+ export function detectWorkspace(
1351
+ startDir: string,
1352
+ ): { workspaceRoot: string; workspaceCoreName: string } | null {
1353
+ let dir = path.resolve(startDir);
1354
+ for (let i = 0; i < 20; i++) {
1355
+ const pkgPath = path.join(dir, "package.json");
1356
+ if (fs.existsSync(pkgPath)) {
1357
+ try {
1358
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1359
+ const wsCore = pkg?.["agent-native"]?.workspaceCore;
1360
+ if (typeof wsCore === "string" && wsCore.length > 0) {
1361
+ return { workspaceRoot: dir, workspaceCoreName: wsCore };
1362
+ }
1363
+ } catch {}
1364
+ }
1365
+ const parent = path.dirname(dir);
1366
+ if (parent === dir) break;
1367
+ dir = parent;
1368
+ }
1369
+ return null;
1370
+ }
1371
+
1372
+ export { parseWorkspaceScope };
1373
+
1374
+ /** @internal — exported for E2E tests */
1375
+ export {
1376
+ scaffoldWorkspaceRoot as _scaffoldWorkspaceRoot,
1377
+ scaffoldAppTemplate as _scaffoldAppTemplate,
1378
+ scaffoldRequiredPackages as _scaffoldRequiredPackages,
1379
+ postProcessStandalone as _postProcessStandalone,
1380
+ loadCatalog as _loadCatalog,
1381
+ fixPackageJsonName as _fixPackageJsonName,
1382
+ renameGitignore as _renameGitignore,
1383
+ rewriteNetlifyToml as _rewriteNetlifyToml,
1384
+ getCoreDependencyVersion as _getCoreDependencyVersion,
1385
+ getDispatchDependencyVersion as _getDispatchDependencyVersion,
1386
+ getToolkitDependencyVersion as _getToolkitDependencyVersion,
1387
+ getGitHubTemplateRef as _getGitHubTemplateRef,
1388
+ getGitHubTemplateRefCandidates as _getGitHubTemplateRefCandidates,
1389
+ githubTarballUrl as _githubTarballUrl,
1390
+ findLocalTemplateFrom as _findLocalTemplateFrom,
1391
+ workspaceAppNameForTemplateSelection as _workspaceAppNameForTemplateSelection,
1392
+ startShapePromptOptions as _startShapePromptOptions,
1393
+ shouldSkipScaffoldEntry as _shouldSkipScaffoldEntry,
1394
+ tarExtractArgs as _tarExtractArgs,
1395
+ };
1396
+
1397
+ /* ─────────────────────────────────────────────────────────────────────────
1398
+ * Download / copy helpers
1399
+ * ───────────────────────────────────────────────────────────────────────── */
1400
+
1401
+ function validateRepoName(repo: string): void {
1402
+ if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(repo)) {
1403
+ throw new ValidationError(
1404
+ `Invalid repository name "${repo}". Expected format: user/repo`,
1405
+ );
1406
+ }
1407
+ }
1408
+
1409
+ function tarExtractArgs(
1410
+ tarPath: string,
1411
+ destDir: string,
1412
+ options: { skipAgentSymlinks?: boolean } = {},
1413
+ ): string[] {
1414
+ const excludes = options.skipAgentSymlinks
1415
+ ? FIRST_PARTY_TARBALL_SYMLINK_EXCLUDES.flatMap((pattern) => [
1416
+ "--exclude",
1417
+ pattern,
1418
+ ])
1419
+ : [];
1420
+ return ["xzf", tarPath, "--strip-components=1", ...excludes, "-C", destDir];
1421
+ }
1422
+
1423
+ function execFileBuffer(
1424
+ command: string,
1425
+ args: string[],
1426
+ options: { maxBuffer: number },
1427
+ ): Promise<Buffer> {
1428
+ return new Promise((resolve, reject) => {
1429
+ execFile(
1430
+ command,
1431
+ args,
1432
+ { ...options, encoding: "buffer" },
1433
+ (error, stdout, stderr) => {
1434
+ if (error) {
1435
+ const detail = stderr?.toString().trim();
1436
+ if (detail) error.message = `${error.message}: ${detail}`;
1437
+ reject(error);
1438
+ return;
1439
+ }
1440
+ resolve(Buffer.isBuffer(stdout) ? stdout : Buffer.from(stdout));
1441
+ },
1442
+ );
1443
+ });
1444
+ }
1445
+
1446
+ async function downloadAndExtract(
1447
+ url: string,
1448
+ destDir: string,
1449
+ options: { skipAgentSymlinks?: boolean } = {},
1450
+ ): Promise<void> {
1451
+ fs.mkdirSync(destDir, { recursive: true });
1452
+ // --fail-with-body so curl exits non-zero on HTTP 4xx/5xx instead of writing
1453
+ // the error body (HTML/JSON) to disk where tar then fails with the opaque
1454
+ // "Unrecognized archive format" message.
1455
+ // Keep this asynchronous: a synchronous curl blocks the event loop, which
1456
+ // makes the create command's spinner look frozen during the GitHub fetch.
1457
+ const tarball = await execFileBuffer(
1458
+ "curl",
1459
+ [
1460
+ "--fail-with-body",
1461
+ "--connect-timeout",
1462
+ "10",
1463
+ "--max-time",
1464
+ "120",
1465
+ "-sSL",
1466
+ url,
1467
+ ],
1468
+ { maxBuffer: 100 * 1024 * 1024 },
1469
+ );
1470
+ const tarPath = path.join(destDir, ".download.tar.gz");
1471
+ fs.writeFileSync(tarPath, tarball);
1472
+ try {
1473
+ execFileSync("tar", tarExtractArgs(tarPath, destDir, options), {
1474
+ stdio: "pipe",
1475
+ });
1476
+ } finally {
1477
+ fs.unlinkSync(tarPath);
1478
+ }
1479
+ }
1480
+
1481
+ async function downloadGitHubSubdir(
1482
+ repo: string,
1483
+ subdir: string,
1484
+ targetDir: string,
1485
+ ): Promise<void> {
1486
+ validateRepoName(repo);
1487
+ const refs = getGitHubTemplateRefCandidates();
1488
+ if (refs.length === 0) {
1489
+ throw new Error(
1490
+ "Cannot download first-party scaffold files without a versioned @agent-native/core package.",
1491
+ );
1492
+ }
1493
+ const errors: string[] = [];
1494
+ for (const ref of refs) {
1495
+ const tarUrl = githubTarballUrl(repo, ref, "tag");
1496
+ const tmpDir = path.join(
1497
+ targetDir,
1498
+ "..",
1499
+ `.agent-native-tmp-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
1500
+ );
1501
+ try {
1502
+ await downloadAndExtract(tarUrl, tmpDir, {
1503
+ skipAgentSymlinks: repo === REPO,
1504
+ });
1505
+ const srcDir = path.join(tmpDir, subdir);
1506
+ if (!fs.existsSync(srcDir)) {
1507
+ throw new Error(
1508
+ `Template directory "${subdir}" not found at ref "${ref}".`,
1509
+ );
1510
+ }
1511
+ copyDir(srcDir, targetDir);
1512
+ return;
1513
+ } catch (err) {
1514
+ errors.push(
1515
+ ` ${ref}: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`,
1516
+ );
1517
+ } finally {
1518
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1519
+ }
1520
+ }
1521
+ throw new Error(
1522
+ `Failed to download templates from ${repo}. Tried refs:\n${errors.join("\n")}`,
1523
+ );
1524
+ }
1525
+
1526
+ async function downloadGitHubRepo(
1527
+ repo: string,
1528
+ targetDir: string,
1529
+ ): Promise<void> {
1530
+ validateRepoName(repo);
1531
+ const tarUrl = githubTarballUrl(repo, "main", "branch");
1532
+ await downloadAndExtract(tarUrl, targetDir);
1533
+ }
1534
+
1535
+ function githubTarballUrl(
1536
+ repo: string,
1537
+ ref: string,
1538
+ kind: "branch" | "tag",
1539
+ ): string {
1540
+ return `https://codeload.github.com/${repo}/tar.gz/refs/${kind === "tag" ? "tags" : "heads"}/${encodeURIComponent(ref)}`;
1541
+ }
1542
+
1543
+ /* ─────────────────────────────────────────────────────────────────────────
1544
+ * Text / filesystem helpers
1545
+ * ───────────────────────────────────────────────────────────────────────── */
1546
+
1547
+ /**
1548
+ * Merge key-value entries into named sections of a pnpm-workspace.yaml string
1549
+ * without creating duplicate section headers. For each section:
1550
+ * - If the section already exists, new entries are injected after its header.
1551
+ * - If the section is absent, a new block is appended at the end.
1552
+ * Entries already present (by key) are skipped.
1553
+ */
1554
+ function mergeWorkspaceYamlSections(
1555
+ yaml: string,
1556
+ sections: Record<string, Record<string, string>>,
1557
+ ): string {
1558
+ let result = yaml;
1559
+ for (const [section, entries] of Object.entries(sections)) {
1560
+ for (const [key, value] of Object.entries(entries)) {
1561
+ if (result.includes(key)) continue;
1562
+ const sectionHeader = new RegExp(`^${section}:\\s*$`, "m");
1563
+ const match = sectionHeader.exec(result);
1564
+ if (match) {
1565
+ const insertAt = match.index + match[0].length;
1566
+ result =
1567
+ result.slice(0, insertAt) +
1568
+ `\n ${key}: ${value}` +
1569
+ result.slice(insertAt);
1570
+ } else {
1571
+ result =
1572
+ result.trimEnd() +
1573
+ (result ? "\n" : "") +
1574
+ `\n${section}:\n ${key}: ${value}\n`;
1575
+ }
1576
+ }
1577
+ }
1578
+ return result;
1579
+ }
1580
+
1581
+ function mergeWorkspaceYamlListItems(
1582
+ yaml: string,
1583
+ section: string,
1584
+ items: string[],
1585
+ ): string {
1586
+ let result = yaml;
1587
+ for (const item of items) {
1588
+ const rendered = ` - ${item}`;
1589
+ if (result.includes(rendered)) continue;
1590
+ const sectionHeader = new RegExp(`^${section}:\\s*$`, "m");
1591
+ const match = sectionHeader.exec(result);
1592
+ if (match) {
1593
+ const insertAt = match.index + match[0].length;
1594
+ result =
1595
+ result.slice(0, insertAt) + `\n${rendered}` + result.slice(insertAt);
1596
+ } else {
1597
+ result =
1598
+ result.trimEnd() +
1599
+ (result ? "\n" : "") +
1600
+ `\n${section}:\n${rendered}\n`;
1601
+ }
1602
+ }
1603
+ return result;
1604
+ }
1605
+
1606
+ /**
1607
+ * Load the pnpm workspace catalog.
1608
+ * First tries the build-time snapshot at dist/catalog.json (works when
1609
+ * running as a published npm package). Falls back to parsing the monorepo
1610
+ * pnpm-workspace.yaml (works during local framework development).
1611
+ */
1612
+ function loadCatalog(): Record<string, string> {
1613
+ try {
1614
+ // Build-time snapshot generated by finalize-build.mjs
1615
+ const snapshotPath = path.resolve(__dirname, "../catalog.json");
1616
+ if (fs.existsSync(snapshotPath)) {
1617
+ return JSON.parse(fs.readFileSync(snapshotPath, "utf-8"));
1618
+ }
1619
+
1620
+ // Fallback: parse pnpm-workspace.yaml from the monorepo root
1621
+ // From dist/cli/ or src/cli/: 4 levels up → packages/core → packages → repo root
1622
+ const repoRoot = path.resolve(__dirname, "../../../..");
1623
+ const wsPath = path.join(repoRoot, "pnpm-workspace.yaml");
1624
+ if (!fs.existsSync(wsPath)) return {};
1625
+ const content = fs.readFileSync(wsPath, "utf-8");
1626
+ const result: Record<string, string> = {};
1627
+ let inCatalog = false;
1628
+ for (const line of content.split("\n")) {
1629
+ if (/^catalog:\s*$/.test(line)) {
1630
+ inCatalog = true;
1631
+ continue;
1632
+ }
1633
+ if (inCatalog) {
1634
+ if (/^\S/.test(line)) break;
1635
+ const match = line.match(/^\s+"?([^":]+)"?\s*:\s*"?([^"]+)"?\s*$/);
1636
+ if (match) result[match[1]] = match[2];
1637
+ }
1638
+ }
1639
+ return result;
1640
+ } catch {
1641
+ return {};
1642
+ }
1643
+ }
1644
+
1645
+ function titleCase(name: string): string {
1646
+ return name
1647
+ .split("-")
1648
+ .map((w) => (w ? w[0].toUpperCase() + w.slice(1) : w))
1649
+ .join(" ");
1650
+ }
1651
+
1652
+ function appTitleForScaffold(appName: string): string {
1653
+ return titleCase(appName);
1654
+ }
1655
+
1656
+ function isChatOnRampTemplate(templateName: string | undefined): boolean {
1657
+ return templateName === "chat" || templateName === "starter";
1658
+ }
1659
+
1660
+ function trackingTemplateName(
1661
+ templateName: string | undefined,
1662
+ ): string | undefined {
1663
+ return templateName === "starter" ? "chat" : templateName;
1664
+ }
1665
+
1666
+ function defaultPackageDescriptionForScaffold(appName: string): string {
1667
+ const appTitle = appTitleForScaffold(appName);
1668
+ return `Workspace app for ${appTitle}.`;
1669
+ }
1670
+
1671
+ function shouldReplaceScaffoldDescription(value: unknown): boolean {
1672
+ if (typeof value !== "string" || !value.trim()) return true;
1673
+ return /\b(starter|new app|blank\b.*\bapp)\b/i.test(value);
1674
+ }
1675
+
1676
+ function fixPackageJsonName(
1677
+ appDir: string,
1678
+ name: string,
1679
+ templateName?: string,
1680
+ ): void {
1681
+ const pkgPath = path.join(appDir, "package.json");
1682
+ if (!fs.existsSync(pkgPath)) return;
1683
+ try {
1684
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1685
+ pkg.name = name;
1686
+ const appTitle = appTitleForScaffold(name);
1687
+ // When the user picked a custom name (e.g. `add-app todo --template=chat`)
1688
+ // the template's displayName would otherwise leak into the workspace apps
1689
+ // grid as the new app's label. Overwrite it so the app shows up as "Todo"
1690
+ // instead of the source template's branding.
1691
+ if (templateName && name !== templateName) {
1692
+ pkg.displayName = appTitle;
1693
+ }
1694
+ if (
1695
+ shouldReplaceScaffoldDescription(pkg.description) ||
1696
+ (isChatOnRampTemplate(templateName) && name !== templateName)
1697
+ ) {
1698
+ pkg.description = defaultPackageDescriptionForScaffold(name);
1699
+ }
1700
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
1701
+ } catch {}
1702
+ }
1703
+
1704
+ function fixWebManifestName(
1705
+ appDir: string,
1706
+ name: string,
1707
+ templateName?: string,
1708
+ ): void {
1709
+ if (!isChatOnRampTemplate(templateName) || name === templateName) return;
1710
+ const manifestPath = path.join(appDir, "public", "manifest.json");
1711
+ if (!fs.existsSync(manifestPath)) return;
1712
+ try {
1713
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
1714
+ const appTitle = titleCase(name);
1715
+ manifest.name = appTitle;
1716
+ manifest.short_name = appTitle;
1717
+ if (
1718
+ typeof manifest.description !== "string" ||
1719
+ /\b(blank app|starter|chat-first)\b/i.test(manifest.description)
1720
+ ) {
1721
+ manifest.description = defaultPackageDescriptionForScaffold(name);
1722
+ }
1723
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
1724
+ } catch {}
1725
+ }
1726
+
1727
+ function getCoreDependencyVersion(): string {
1728
+ if (process.env.AGENT_NATIVE_CREATE_USE_LOCAL_CORE === "1") {
1729
+ const localCore = findLocalPackage("core");
1730
+ if (localCore) return localPackageTarball(localCore);
1731
+ }
1732
+
1733
+ // Generated apps must install before the current package version is
1734
+ // published. The dist-tag resolves to the newest released core today and to
1735
+ // this package version once the release goes live. Local file deps are
1736
+ // intentionally opt-in so scaffolded repos remain portable by default.
1737
+ return "latest";
1738
+ }
1739
+
1740
+ function getDispatchDependencyVersion(): string {
1741
+ if (process.env.AGENT_NATIVE_CREATE_USE_LOCAL_CORE === "1") {
1742
+ const localDispatch = findLocalPackage("dispatch");
1743
+ if (localDispatch) return pathToFileURL(localDispatch).href;
1744
+ }
1745
+
1746
+ return "latest";
1747
+ }
1748
+
1749
+ function getToolkitDependencyVersion(): string {
1750
+ if (process.env.AGENT_NATIVE_CREATE_USE_LOCAL_CORE === "1") {
1751
+ const localToolkit = findLocalPackage("toolkit");
1752
+ if (localToolkit) return localPackageTarball(localToolkit);
1753
+ }
1754
+
1755
+ return "latest";
1756
+ }
1757
+
1758
+ function localToolkitOverride(): string | null {
1759
+ if (process.env.AGENT_NATIVE_CREATE_USE_LOCAL_CORE !== "1") return null;
1760
+ const localToolkit = findLocalPackage("toolkit");
1761
+ return localToolkit ? localPackageTarball(localToolkit) : null;
1762
+ }
1763
+
1764
+ function localRecapCliOverride(): string | null {
1765
+ if (process.env.AGENT_NATIVE_CREATE_USE_LOCAL_CORE !== "1") return null;
1766
+ const localRecapCli = findLocalPackage("recap-cli");
1767
+ return localRecapCli ? pathToFileURL(localRecapCli).href : null;
1768
+ }
1769
+
1770
+ function applyLocalWorkspaceOverrides(targetDir: string): void {
1771
+ const localToolkit = localToolkitOverride();
1772
+ const localRecapCli = localRecapCliOverride();
1773
+ if (!localToolkit && !localRecapCli) return;
1774
+
1775
+ const wsPath = path.join(targetDir, "pnpm-workspace.yaml");
1776
+ const existing = fs.existsSync(wsPath)
1777
+ ? fs.readFileSync(wsPath, "utf-8")
1778
+ : "";
1779
+ const updated = mergeWorkspaceYamlSections(existing, {
1780
+ overrides: {
1781
+ ...(localToolkit
1782
+ ? { '"@agent-native/toolkit"': JSON.stringify(localToolkit) }
1783
+ : {}),
1784
+ ...(localRecapCli
1785
+ ? { '"@agent-native/recap-cli"': JSON.stringify(localRecapCli) }
1786
+ : {}),
1787
+ },
1788
+ });
1789
+ if (updated !== existing) fs.writeFileSync(wsPath, updated);
1790
+ }
1791
+
1792
+ function getCorePackageVersion(): string | undefined {
1793
+ try {
1794
+ const packageRoot = path.resolve(__dirname, "../..");
1795
+ const pkg = JSON.parse(
1796
+ fs.readFileSync(path.join(packageRoot, "package.json"), "utf-8"),
1797
+ );
1798
+ return typeof pkg.version === "string" ? pkg.version : undefined;
1799
+ } catch {
1800
+ return undefined;
1801
+ }
1802
+ }
1803
+
1804
+ /**
1805
+ * Git refs to try, in priority order, when downloading templates from the
1806
+ * framework repo. The release tag scheme has shifted over time:
1807
+ *
1808
+ * - ≤ 0.7.83: single repo-wide tag `v<version>` (legacy).
1809
+ * - ≥ 0.8.0: changesets per-package tags
1810
+ * `@agent-native/core@<version>` (current).
1811
+ *
1812
+ * Published CLIs intentionally use only immutable version tags. Falling back
1813
+ * to mutable `main` can copy a template that imports exports not present in
1814
+ * the installed core package, leaving a generated app broken at SSR startup.
1815
+ * Local framework development uses the checkout's templates and packages
1816
+ * before this downloader runs, so it does not need a mutable fallback.
1817
+ */
1818
+ function getGitHubTemplateRefCandidates(): string[] {
1819
+ const version = getCorePackageVersion();
1820
+ const candidates: string[] = [];
1821
+ if (version && /^\d+\.\d+\.\d+(?:-.+)?$/.test(version)) {
1822
+ candidates.push(`@agent-native/core@${version}`);
1823
+ candidates.push(`v${version}`);
1824
+ }
1825
+ return candidates;
1826
+ }
1827
+
1828
+ /** @deprecated Kept for backward-compatible test imports. Returns the
1829
+ * highest-priority candidate; callers that need the full fallback list
1830
+ * should use `getGitHubTemplateRefCandidates()`. */
1831
+ function getGitHubTemplateRef(): string {
1832
+ return getGitHubTemplateRefCandidates()[0]!;
1833
+ }
1834
+
1835
+ function rewriteCoreDependencyVersions(projectDir: string): void {
1836
+ const pkgPath = path.join(projectDir, "package.json");
1837
+ if (!fs.existsSync(pkgPath)) return;
1838
+ try {
1839
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1840
+ for (const depType of [
1841
+ "dependencies",
1842
+ "devDependencies",
1843
+ "peerDependencies",
1844
+ ] as const) {
1845
+ const deps = pkg[depType];
1846
+ if (deps?.["@agent-native/core"]) {
1847
+ deps["@agent-native/core"] = getCoreDependencyVersion();
1848
+ }
1849
+ if (deps?.["@agent-native/toolkit"]) {
1850
+ deps["@agent-native/toolkit"] = getToolkitDependencyVersion();
1851
+ }
1852
+ }
1853
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
1854
+ } catch {}
1855
+ }
1856
+
1857
+ function validateWorkspaceAppName(
1858
+ appName: string,
1859
+ clack: typeof import("@clack/prompts"),
1860
+ opts?: { allowDispatch?: boolean },
1861
+ ): void {
1862
+ const error =
1863
+ opts?.allowDispatch && appName === "dispatch"
1864
+ ? null
1865
+ : getWorkspaceAppIdValidationError(appName);
1866
+ if (error) {
1867
+ clack.cancel(error);
1868
+ process.exit(1);
1869
+ }
1870
+ }
1871
+
1872
+ function upsertTomlBuildEnvironment(
1873
+ content: string,
1874
+ vars: Record<string, string>,
1875
+ ): string {
1876
+ const lines = content.split("\n");
1877
+ const sectionIndex = lines.findIndex(
1878
+ (line) => line.trim() === "[build.environment]",
1879
+ );
1880
+ if (sectionIndex === -1) {
1881
+ const envLines = ["", "[build.environment]"].concat(
1882
+ Object.entries(vars).map(([key, value]) => ` ${key} = "${value}"`),
1883
+ );
1884
+ return content.trimEnd() + "\n" + envLines.join("\n") + "\n";
1885
+ }
1886
+
1887
+ let nextSectionIndex = lines.findIndex(
1888
+ (line, index) => index > sectionIndex && /^\s*\[/.test(line),
1889
+ );
1890
+ if (nextSectionIndex === -1) nextSectionIndex = lines.length;
1891
+
1892
+ for (const [key, value] of Object.entries(vars)) {
1893
+ const existingIndex = lines.findIndex(
1894
+ (line, index) =>
1895
+ index > sectionIndex &&
1896
+ index < nextSectionIndex &&
1897
+ new RegExp(`^\\s*${key}\\s*=`).test(line),
1898
+ );
1899
+ const nextLine = ` ${key} = "${value}"`;
1900
+ if (existingIndex === -1) {
1901
+ lines.splice(nextSectionIndex, 0, nextLine);
1902
+ nextSectionIndex += 1;
1903
+ } else {
1904
+ lines[existingIndex] = nextLine;
1905
+ }
1906
+ }
1907
+
1908
+ return lines.join("\n");
1909
+ }
1910
+
1911
+ function ensureRedirect(
1912
+ content: string,
1913
+ from: string,
1914
+ to: string,
1915
+ status: number,
1916
+ ): string {
1917
+ const escapedFrom = from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1918
+ const redirectPattern = new RegExp(
1919
+ `\\n?\\[\\[redirects\\]\\]\\s+from\\s*=\\s*"${escapedFrom}"\\s+to\\s*=\\s*"[^"]*"\\s+status\\s*=\\s*\\d+(?:\\s+force\\s*=\\s*(?:true|false))?`,
1920
+ "m",
1921
+ );
1922
+ const block = [
1923
+ "",
1924
+ "[[redirects]]",
1925
+ ` from = "${from}"`,
1926
+ ` to = "${to}"`,
1927
+ ` status = ${status}`,
1928
+ ].join("\n");
1929
+ if (redirectPattern.test(content)) {
1930
+ return content.replace(redirectPattern, block);
1931
+ }
1932
+ return content.trimEnd() + "\n" + block + "\n";
1933
+ }
1934
+
1935
+ function removeRedirect(content: string, from: string): string {
1936
+ const escapedFrom = from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1937
+ const redirectPattern = new RegExp(
1938
+ `\\n?\\[\\[redirects\\]\\]\\s+from\\s*=\\s*"${escapedFrom}"\\s+to\\s*=\\s*"[^"]*"\\s+status\\s*=\\s*\\d+(?:\\s+force\\s*=\\s*(?:true|false))?`,
1939
+ "gm",
1940
+ );
1941
+ return content.replace(redirectPattern, "").replace(/\n{3,}/g, "\n\n");
1942
+ }
1943
+
1944
+ function addWorkspaceMountNetlifyConfig(
1945
+ content: string,
1946
+ appName: string,
1947
+ ): string {
1948
+ const basePath = `/${appName}`;
1949
+ let next = upsertTomlBuildEnvironment(content, {
1950
+ APP_BASE_PATH: basePath,
1951
+ VITE_APP_BASE_PATH: basePath,
1952
+ NITRO_PRESET: "netlify",
1953
+ NPM_CONFIG_PRODUCTION: "false",
1954
+ });
1955
+
1956
+ if (appName === "dispatch") {
1957
+ next = ensureRedirect(next, "/", "/dispatch/overview", 302);
1958
+ next = ensureRedirect(next, "/dispatch", "/dispatch/overview", 302);
1959
+ for (const [from, to] of DISPATCH_WORKSPACE_ROOT_REDIRECTS) {
1960
+ next = ensureRedirect(next, `/${from}`, `/dispatch/${to}`, 302);
1961
+ }
1962
+ next = removeRedirect(next, "/dispatch/*");
1963
+ }
1964
+
1965
+ return next;
1966
+ }
1967
+
1968
+ function rewriteNetlifyToml(
1969
+ appDir: string,
1970
+ appName: string,
1971
+ mode: "standalone" | "workspace",
1972
+ ): void {
1973
+ const netlifyPath = path.join(appDir, "netlify.toml");
1974
+ if (!fs.existsSync(netlifyPath)) return;
1975
+
1976
+ try {
1977
+ let content = fs.readFileSync(netlifyPath, "utf-8");
1978
+ const originalCommand = content.match(/^\s*command = "([^"]*)"$/m)?.[1];
1979
+ const usesUnpooledDatabase =
1980
+ originalCommand?.includes("NETLIFY_DATABASE_URL_UNPOOLED") ?? false;
1981
+ const buildCommand =
1982
+ mode === "workspace"
1983
+ ? `APP_BASE_PATH=/${appName} VITE_APP_BASE_PATH=/${appName} NITRO_PRESET=netlify pnpm --filter ${appName} build`
1984
+ : "NITRO_PRESET=netlify pnpm build";
1985
+ const databaseSetup =
1986
+ 'export DATABASE_URL=\\"${NETLIFY_DATABASE_URL:-$DATABASE_URL}\\"';
1987
+ const buildDatabasePrefix = usesUnpooledDatabase
1988
+ ? 'DATABASE_URL=\\"${NETLIFY_DATABASE_URL_UNPOOLED:-$DATABASE_URL}\\" '
1989
+ : "";
1990
+ const command = `${databaseSetup} && ${buildDatabasePrefix}${buildCommand}`;
1991
+ const publishPath = mode === "workspace" ? `apps/${appName}/dist` : "dist";
1992
+ const functionsPath =
1993
+ mode === "workspace"
1994
+ ? `apps/${appName}/.netlify/functions-internal`
1995
+ : ".netlify/functions-internal";
1996
+
1997
+ content = content
1998
+ .replace(/^(\s*)command = ".*"$/m, `$1command = "${command}"`)
1999
+ .replace(
2000
+ /publish = "templates\/[^"]+\/dist"/g,
2001
+ `publish = "${publishPath}"`,
2002
+ )
2003
+ .replace(
2004
+ /functions = "templates\/[^"]+\/\.netlify\/functions-internal"/g,
2005
+ `functions = "${functionsPath}"`,
2006
+ )
2007
+ // Strip the `ignore` script line: it references a monorepo script path
2008
+ // (scripts/netlify-ignore-build.mjs) that doesn't exist in scaffolds, so
2009
+ // skip-unchanged would never work and every deploy logs a not-found error.
2010
+ .replace(/^\s*ignore\s*=\s*"[^"]*"\s*\n/m, "");
2011
+
2012
+ if (mode === "workspace") {
2013
+ content = addWorkspaceMountNetlifyConfig(content, appName);
2014
+ }
2015
+
2016
+ fs.writeFileSync(netlifyPath, content);
2017
+ } catch {}
2018
+ }
2019
+
2020
+ function rewriteAgentChatAppId(
2021
+ appDir: string,
2022
+ appName: string,
2023
+ templateName?: string,
2024
+ ): void {
2025
+ const pluginPath = path.join(appDir, "server", "plugins", "agent-chat.ts");
2026
+ if (!fs.existsSync(pluginPath)) return;
2027
+
2028
+ try {
2029
+ const content = fs.readFileSync(pluginPath, "utf-8");
2030
+ const sourceAppIds = ["chat", "starter"];
2031
+ if (templateName && templateName !== appName) {
2032
+ sourceAppIds.push(templateName);
2033
+ }
2034
+ const pattern = new RegExp(
2035
+ `(appId:\\s*)(["'])(${sourceAppIds.map(escapeRegExp).join("|")})\\2`,
2036
+ );
2037
+ if (!pattern.test(content)) return;
2038
+
2039
+ const next = content.replace(
2040
+ pattern,
2041
+ (_match, prefix: string, quote: string) =>
2042
+ `${prefix}${quote}${appName}${quote}`,
2043
+ );
2044
+ if (next !== content) {
2045
+ fs.writeFileSync(pluginPath, next);
2046
+ }
2047
+ } catch {}
2048
+ }
2049
+
2050
+ function rewriteTrackingAppId(
2051
+ appDir: string,
2052
+ appName: string,
2053
+ templateName?: string,
2054
+ ): void {
2055
+ const rootPath = path.join(appDir, "app", "root.tsx");
2056
+ if (!fs.existsSync(rootPath)) return;
2057
+
2058
+ try {
2059
+ const content = fs.readFileSync(rootPath, "utf-8");
2060
+ const trackedTemplateName = trackingTemplateName(templateName);
2061
+ const sourceAppIds = ["agent-native-[^\"']+", "\\{\\{APP_NAME\\}\\}"];
2062
+ if (templateName && templateName !== appName) {
2063
+ sourceAppIds.push(escapeRegExp(templateName));
2064
+ }
2065
+ if (isChatOnRampTemplate(templateName)) {
2066
+ sourceAppIds.push("starter", "chat");
2067
+ }
2068
+ const pattern = new RegExp(
2069
+ `(^\\s*app:\\s*)(["'])(?:${sourceAppIds.join("|")})\\2(\\s*,?)`,
2070
+ "m",
2071
+ );
2072
+ if (!pattern.test(content)) return;
2073
+
2074
+ let next = content.replace(
2075
+ pattern,
2076
+ (_match, prefix: string, quote: string, suffix: string) =>
2077
+ `${prefix}${quote}${appName}${quote}${suffix}`,
2078
+ );
2079
+
2080
+ if (
2081
+ trackedTemplateName &&
2082
+ trackedTemplateName !== appName &&
2083
+ !hasTrackingTemplate(next)
2084
+ ) {
2085
+ next = next.replace(
2086
+ /(^\s*app:\s*["'][^"']+["'],?\s*$)/m,
2087
+ (line) =>
2088
+ `${line}\n template: ${JSON.stringify(trackedTemplateName)},`,
2089
+ );
2090
+ }
2091
+
2092
+ if (next !== content) {
2093
+ fs.writeFileSync(rootPath, next);
2094
+ }
2095
+ } catch {}
2096
+ }
2097
+
2098
+ function escapeRegExp(value: string): string {
2099
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2100
+ }
2101
+
2102
+ function hasTrackingTemplate(content: string): boolean {
2103
+ const match = content.match(/configureTracking\(\{[\s\S]*?\}\);/);
2104
+ return !!match && /^\s*template\s*:/m.test(match[0]);
2105
+ }
2106
+
2107
+ function tryGitInit(dir: string): boolean {
2108
+ try {
2109
+ execFileSync("git", ["init"], { cwd: dir, stdio: "pipe" });
2110
+ execFileSync("git", ["add", "-A"], { cwd: dir, stdio: "pipe" });
2111
+ execFileSync(
2112
+ "git",
2113
+ ["commit", "-m", "Initial commit from agent-native create"],
2114
+ {
2115
+ cwd: dir,
2116
+ stdio: "pipe",
2117
+ env: {
2118
+ ...process.env,
2119
+ GIT_AUTHOR_NAME: "agent-native",
2120
+ GIT_AUTHOR_EMAIL: "noreply@agent-native.com",
2121
+ GIT_COMMITTER_NAME: "agent-native",
2122
+ GIT_COMMITTER_EMAIL: "noreply@agent-native.com",
2123
+ },
2124
+ },
2125
+ );
2126
+ return true;
2127
+ } catch {
2128
+ return false;
2129
+ }
2130
+ }
2131
+
2132
+ function renameGitignore(dir: string): void {
2133
+ const src = path.join(dir, "_gitignore");
2134
+ const dst = path.join(dir, ".gitignore");
2135
+ if (fs.existsSync(src)) fs.renameSync(src, dst);
2136
+ }
2137
+
2138
+ function replacePlaceholders(
2139
+ dir: string,
2140
+ appName: string,
2141
+ appTitle: string,
2142
+ workspaceName?: string,
2143
+ ): void {
2144
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
2145
+ const p = path.join(dir, entry.name);
2146
+ if (entry.isSymbolicLink()) continue;
2147
+ if (entry.isDirectory()) {
2148
+ replacePlaceholders(p, appName, appTitle, workspaceName);
2149
+ continue;
2150
+ }
2151
+ let content: string;
2152
+ try {
2153
+ content = fs.readFileSync(p, "utf-8");
2154
+ } catch {
2155
+ continue;
2156
+ }
2157
+ const hasWs =
2158
+ workspaceName !== undefined && content.includes("{{WORKSPACE_NAME}}");
2159
+ if (
2160
+ !content.includes("{{APP_NAME}}") &&
2161
+ !content.includes("{{APP_TITLE}}") &&
2162
+ !hasWs
2163
+ ) {
2164
+ continue;
2165
+ }
2166
+ let next = content;
2167
+ if (workspaceName !== undefined) {
2168
+ next = next.replace(/\{\{WORKSPACE_NAME\}\}/g, workspaceName);
2169
+ }
2170
+ next = next
2171
+ .replace(/\{\{APP_NAME\}\}/g, appName)
2172
+ .replace(/\{\{APP_TITLE\}\}/g, appTitle);
2173
+ fs.writeFileSync(p, next);
2174
+ }
2175
+ }
2176
+
2177
+ function copyDir(src: string, dest: string, root?: string): void {
2178
+ const resolvedRoot = root ?? path.resolve(src);
2179
+ fs.mkdirSync(dest, { recursive: true });
2180
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
2181
+ const srcPath = path.join(src, entry.name);
2182
+ if (shouldSkipScaffoldEntry(entry.name, srcPath)) continue;
2183
+ const destPath = path.join(dest, entry.name);
2184
+ if (entry.isSymbolicLink()) {
2185
+ const target = fs.readlinkSync(srcPath);
2186
+ const resolvedTarget = path.resolve(path.dirname(srcPath), target);
2187
+ if (resolvedTarget.startsWith(resolvedRoot)) {
2188
+ fs.symlinkSync(target, destPath);
2189
+ } else {
2190
+ try {
2191
+ const stat = fs.statSync(srcPath);
2192
+ if (stat.isDirectory()) {
2193
+ copyDir(srcPath, destPath, resolvedRoot);
2194
+ } else {
2195
+ fs.copyFileSync(srcPath, destPath);
2196
+ }
2197
+ } catch {
2198
+ // Broken symlink — skip silently
2199
+ }
2200
+ }
2201
+ } else if (entry.isDirectory()) {
2202
+ copyDir(srcPath, destPath, resolvedRoot);
2203
+ } else {
2204
+ fs.copyFileSync(srcPath, destPath);
2205
+ }
2206
+ }
2207
+ }
2208
+
2209
+ function shouldSkipScaffoldEntry(name: string, srcPath?: string): boolean {
2210
+ const pathParts = srcPath?.split(path.sep);
2211
+ if (
2212
+ name === "plans" &&
2213
+ pathParts?.at(-2) === "plan" &&
2214
+ pathParts.at(-3) === "templates"
2215
+ ) {
2216
+ return true;
2217
+ }
2218
+ if (name === "preview.html" && srcPath?.split(path.sep).includes("plans")) {
2219
+ return true;
2220
+ }
2221
+ if (
2222
+ /^settings(?:\..*)?\.json$/.test(name) &&
2223
+ srcPath?.split(path.sep).includes(".claude")
2224
+ ) {
2225
+ return true;
2226
+ }
2227
+ if (
2228
+ name === "node_modules" ||
2229
+ name === ".agent-native" ||
2230
+ name === ".env" ||
2231
+ name === ".env.local" ||
2232
+ name === "pnpm-lock.yaml" ||
2233
+ name === ".netlify" ||
2234
+ name === ".vercel" ||
2235
+ name === ".generated" ||
2236
+ name === ".react-router" ||
2237
+ name === ".output" ||
2238
+ name === "build" ||
2239
+ name === "dist" ||
2240
+ name === "test-results" ||
2241
+ name === "playwright-report" ||
2242
+ name === ".DS_Store"
2243
+ ) {
2244
+ return true;
2245
+ }
2246
+ return name.endsWith(".tmp.json") || /\.db(?:-shm|-wal)?$/.test(name);
2247
+ }