@agent-native/core 0.15.12 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/README.md +37 -0
  2. package/dist/agent/app-model-defaults.d.ts +37 -0
  3. package/dist/agent/app-model-defaults.d.ts.map +1 -0
  4. package/dist/agent/app-model-defaults.js +136 -0
  5. package/dist/agent/app-model-defaults.js.map +1 -0
  6. package/dist/agent/engine/registry.d.ts +12 -7
  7. package/dist/agent/engine/registry.d.ts.map +1 -1
  8. package/dist/agent/engine/registry.js +28 -8
  9. package/dist/agent/engine/registry.js.map +1 -1
  10. package/dist/agent/production-agent.d.ts +2 -0
  11. package/dist/agent/production-agent.d.ts.map +1 -1
  12. package/dist/agent/production-agent.js +3 -1
  13. package/dist/agent/production-agent.js.map +1 -1
  14. package/dist/browser-sessions/actions.d.ts +7 -0
  15. package/dist/browser-sessions/actions.d.ts.map +1 -0
  16. package/dist/browser-sessions/actions.js +223 -0
  17. package/dist/browser-sessions/actions.js.map +1 -0
  18. package/dist/browser-sessions/routes.d.ts +7 -0
  19. package/dist/browser-sessions/routes.d.ts.map +1 -0
  20. package/dist/browser-sessions/routes.js +159 -0
  21. package/dist/browser-sessions/routes.js.map +1 -0
  22. package/dist/browser-sessions/store.d.ts +33 -0
  23. package/dist/browser-sessions/store.d.ts.map +1 -0
  24. package/dist/browser-sessions/store.js +506 -0
  25. package/dist/browser-sessions/store.js.map +1 -0
  26. package/dist/browser-sessions/types.d.ts +68 -0
  27. package/dist/browser-sessions/types.d.ts.map +1 -0
  28. package/dist/browser-sessions/types.js +2 -0
  29. package/dist/browser-sessions/types.js.map +1 -0
  30. package/dist/cli/code-agent-commands.d.ts +36 -0
  31. package/dist/cli/code-agent-commands.d.ts.map +1 -0
  32. package/dist/cli/code-agent-commands.js +192 -0
  33. package/dist/cli/code-agent-commands.js.map +1 -0
  34. package/dist/cli/code-agent-connector.d.ts +17 -0
  35. package/dist/cli/code-agent-connector.d.ts.map +1 -0
  36. package/dist/cli/code-agent-connector.js +724 -0
  37. package/dist/cli/code-agent-connector.js.map +1 -0
  38. package/dist/cli/code-agent-executor.d.ts +31 -0
  39. package/dist/cli/code-agent-executor.d.ts.map +1 -0
  40. package/dist/cli/code-agent-executor.js +921 -0
  41. package/dist/cli/code-agent-executor.js.map +1 -0
  42. package/dist/cli/code-agent-runs.d.ts +102 -0
  43. package/dist/cli/code-agent-runs.d.ts.map +1 -0
  44. package/dist/cli/code-agent-runs.js +277 -0
  45. package/dist/cli/code-agent-runs.js.map +1 -0
  46. package/dist/cli/code.d.ts +66 -0
  47. package/dist/cli/code.d.ts.map +1 -0
  48. package/dist/cli/code.js +1306 -0
  49. package/dist/cli/code.js.map +1 -0
  50. package/dist/cli/create.d.ts +2 -1
  51. package/dist/cli/create.d.ts.map +1 -1
  52. package/dist/cli/create.js +11 -1
  53. package/dist/cli/create.js.map +1 -1
  54. package/dist/cli/index.js +26 -1
  55. package/dist/cli/index.js.map +1 -1
  56. package/dist/cli/migrate.d.ts +27 -0
  57. package/dist/cli/migrate.d.ts.map +1 -1
  58. package/dist/cli/migrate.js +1328 -20
  59. package/dist/cli/migrate.js.map +1 -1
  60. package/dist/cli/templates-meta.d.ts.map +1 -1
  61. package/dist/cli/templates-meta.js +27 -3
  62. package/dist/cli/templates-meta.js.map +1 -1
  63. package/dist/cli/workspacify.d.ts +2 -0
  64. package/dist/cli/workspacify.d.ts.map +1 -1
  65. package/dist/cli/workspacify.js +2 -1
  66. package/dist/cli/workspacify.js.map +1 -1
  67. package/dist/client/AgentNative.d.ts +32 -0
  68. package/dist/client/AgentNative.d.ts.map +1 -0
  69. package/dist/client/AgentNative.js +79 -0
  70. package/dist/client/AgentNative.js.map +1 -0
  71. package/dist/client/AgentNativeEmbedded.d.ts +47 -0
  72. package/dist/client/AgentNativeEmbedded.d.ts.map +1 -0
  73. package/dist/client/AgentNativeEmbedded.js +148 -0
  74. package/dist/client/AgentNativeEmbedded.js.map +1 -0
  75. package/dist/client/AgentNativeFrame.d.ts +25 -0
  76. package/dist/client/AgentNativeFrame.d.ts.map +1 -0
  77. package/dist/client/AgentNativeFrame.js +68 -0
  78. package/dist/client/AgentNativeFrame.js.map +1 -0
  79. package/dist/client/AgentPanel.d.ts +19 -2
  80. package/dist/client/AgentPanel.d.ts.map +1 -1
  81. package/dist/client/AgentPanel.js +15 -4
  82. package/dist/client/AgentPanel.js.map +1 -1
  83. package/dist/client/AssistantChat.d.ts +1 -1
  84. package/dist/client/AssistantChat.d.ts.map +1 -1
  85. package/dist/client/AssistantChat.js +79 -48
  86. package/dist/client/AssistantChat.js.map +1 -1
  87. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  88. package/dist/client/MultiTabAssistantChat.js +2 -1
  89. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  90. package/dist/client/NewWorkspaceAppFlow.d.ts.map +1 -1
  91. package/dist/client/NewWorkspaceAppFlow.js +3 -2
  92. package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
  93. package/dist/client/browser-session-bridge.d.ts +44 -0
  94. package/dist/client/browser-session-bridge.d.ts.map +1 -0
  95. package/dist/client/browser-session-bridge.js +339 -0
  96. package/dist/client/browser-session-bridge.js.map +1 -0
  97. package/dist/client/client-action.d.ts +7 -0
  98. package/dist/client/client-action.d.ts.map +1 -0
  99. package/dist/client/client-action.js +4 -0
  100. package/dist/client/client-action.js.map +1 -0
  101. package/dist/client/components/ui/tooltip.d.ts.map +1 -1
  102. package/dist/client/components/ui/tooltip.js +1 -1
  103. package/dist/client/components/ui/tooltip.js.map +1 -1
  104. package/dist/client/composer/AgentComposerFrame.d.ts +17 -0
  105. package/dist/client/composer/AgentComposerFrame.d.ts.map +1 -0
  106. package/dist/client/composer/AgentComposerFrame.js +14 -0
  107. package/dist/client/composer/AgentComposerFrame.js.map +1 -0
  108. package/dist/client/composer/MentionPopover.d.ts.map +1 -1
  109. package/dist/client/composer/MentionPopover.js +2 -2
  110. package/dist/client/composer/MentionPopover.js.map +1 -1
  111. package/dist/client/composer/PromptComposer.d.ts +35 -2
  112. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  113. package/dist/client/composer/PromptComposer.js +31 -17
  114. package/dist/client/composer/PromptComposer.js.map +1 -1
  115. package/dist/client/composer/TiptapComposer.d.ts +20 -2
  116. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  117. package/dist/client/composer/TiptapComposer.js +112 -22
  118. package/dist/client/composer/TiptapComposer.js.map +1 -1
  119. package/dist/client/composer/index.d.ts +3 -2
  120. package/dist/client/composer/index.d.ts.map +1 -1
  121. package/dist/client/composer/index.js +1 -0
  122. package/dist/client/composer/index.js.map +1 -1
  123. package/dist/client/composer/types.d.ts +1 -0
  124. package/dist/client/composer/types.d.ts.map +1 -1
  125. package/dist/client/composer/types.js.map +1 -1
  126. package/dist/client/extensions/AgentNativeExtensionFrame.d.ts +58 -0
  127. package/dist/client/extensions/AgentNativeExtensionFrame.d.ts.map +1 -0
  128. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.d.ts +2 -0
  129. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.d.ts.map +1 -0
  130. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.js +110 -0
  131. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.js.map +1 -0
  132. package/dist/client/extensions/AgentNativeExtensionFrame.js +354 -0
  133. package/dist/client/extensions/AgentNativeExtensionFrame.js.map +1 -0
  134. package/dist/client/extensions/AgentNativeExtensionFrame.spec.d.ts +2 -0
  135. package/dist/client/extensions/AgentNativeExtensionFrame.spec.d.ts.map +1 -0
  136. package/dist/client/extensions/AgentNativeExtensionFrame.spec.js +68 -0
  137. package/dist/client/extensions/AgentNativeExtensionFrame.spec.js.map +1 -0
  138. package/dist/client/extensions/agent-native-extension-runtime.d.ts +69 -0
  139. package/dist/client/extensions/agent-native-extension-runtime.d.ts.map +1 -0
  140. package/dist/client/extensions/agent-native-extension-runtime.js +348 -0
  141. package/dist/client/extensions/agent-native-extension-runtime.js.map +1 -0
  142. package/dist/client/extensions/index.d.ts +2 -0
  143. package/dist/client/extensions/index.d.ts.map +1 -1
  144. package/dist/client/extensions/index.js +2 -0
  145. package/dist/client/extensions/index.js.map +1 -1
  146. package/dist/client/extensions/portable-extension.d.ts +86 -0
  147. package/dist/client/extensions/portable-extension.d.ts.map +1 -0
  148. package/dist/client/extensions/portable-extension.js +480 -0
  149. package/dist/client/extensions/portable-extension.js.map +1 -0
  150. package/dist/client/host-bridge.d.ts +266 -0
  151. package/dist/client/host-bridge.d.ts.map +1 -0
  152. package/dist/client/host-bridge.js +745 -0
  153. package/dist/client/host-bridge.js.map +1 -0
  154. package/dist/client/host-tools.d.ts +40 -0
  155. package/dist/client/host-tools.d.ts.map +1 -0
  156. package/dist/client/host-tools.js +94 -0
  157. package/dist/client/host-tools.js.map +1 -0
  158. package/dist/client/index.d.ts +13 -2
  159. package/dist/client/index.d.ts.map +1 -1
  160. package/dist/client/index.js +11 -2
  161. package/dist/client/index.js.map +1 -1
  162. package/dist/client/resources/BuiltinCapabilityDetail.d.ts +10 -0
  163. package/dist/client/resources/BuiltinCapabilityDetail.d.ts.map +1 -0
  164. package/dist/client/resources/BuiltinCapabilityDetail.js +51 -0
  165. package/dist/client/resources/BuiltinCapabilityDetail.js.map +1 -0
  166. package/dist/client/resources/ResourceEditor.d.ts +3 -1
  167. package/dist/client/resources/ResourceEditor.d.ts.map +1 -1
  168. package/dist/client/resources/ResourceEditor.js +40 -17
  169. package/dist/client/resources/ResourceEditor.js.map +1 -1
  170. package/dist/client/resources/ResourceTree.d.ts.map +1 -1
  171. package/dist/client/resources/ResourceTree.js +23 -2
  172. package/dist/client/resources/ResourceTree.js.map +1 -1
  173. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  174. package/dist/client/resources/ResourcesPanel.js +77 -17
  175. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  176. package/dist/client/resources/index.d.ts +1 -0
  177. package/dist/client/resources/index.d.ts.map +1 -1
  178. package/dist/client/resources/index.js +1 -0
  179. package/dist/client/resources/index.js.map +1 -1
  180. package/dist/client/resources/use-builtin-capabilities.d.ts +62 -0
  181. package/dist/client/resources/use-builtin-capabilities.d.ts.map +1 -0
  182. package/dist/client/resources/use-builtin-capabilities.js +54 -0
  183. package/dist/client/resources/use-builtin-capabilities.js.map +1 -0
  184. package/dist/client/resources/use-resources.d.ts +30 -2
  185. package/dist/client/resources/use-resources.d.ts.map +1 -1
  186. package/dist/client/resources/use-resources.js +42 -1
  187. package/dist/client/resources/use-resources.js.map +1 -1
  188. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  189. package/dist/client/settings/SettingsPanel.js +151 -2
  190. package/dist/client/settings/SettingsPanel.js.map +1 -1
  191. package/dist/client/use-chat-models.d.ts.map +1 -1
  192. package/dist/client/use-chat-models.js +20 -0
  193. package/dist/client/use-chat-models.js.map +1 -1
  194. package/dist/client/use-chat-threads.d.ts.map +1 -1
  195. package/dist/client/use-chat-threads.js +46 -2
  196. package/dist/client/use-chat-threads.js.map +1 -1
  197. package/dist/client/use-chat-threads.spec.js +77 -0
  198. package/dist/client/use-chat-threads.spec.js.map +1 -1
  199. package/dist/code-agents/index.d.ts +4 -0
  200. package/dist/code-agents/index.d.ts.map +1 -0
  201. package/dist/code-agents/index.js +4 -0
  202. package/dist/code-agents/index.js.map +1 -0
  203. package/dist/connections/catalog.d.ts +134 -0
  204. package/dist/connections/catalog.d.ts.map +1 -0
  205. package/dist/connections/catalog.js +180 -0
  206. package/dist/connections/catalog.js.map +1 -0
  207. package/dist/connections/index.d.ts +2 -0
  208. package/dist/connections/index.d.ts.map +1 -0
  209. package/dist/connections/index.js +2 -0
  210. package/dist/connections/index.js.map +1 -0
  211. package/dist/extensions/change-marker.d.ts +10 -0
  212. package/dist/extensions/change-marker.d.ts.map +1 -0
  213. package/dist/extensions/change-marker.js +42 -0
  214. package/dist/extensions/change-marker.js.map +1 -0
  215. package/dist/extensions/routes.d.ts.map +1 -1
  216. package/dist/extensions/routes.js +1 -7
  217. package/dist/extensions/routes.js.map +1 -1
  218. package/dist/extensions/schema.d.ts +1 -0
  219. package/dist/extensions/schema.d.ts.map +1 -1
  220. package/dist/extensions/schema.js +1 -0
  221. package/dist/extensions/schema.js.map +1 -1
  222. package/dist/extensions/slots/routes.js +1 -1
  223. package/dist/extensions/slots/routes.js.map +1 -1
  224. package/dist/extensions/store.d.ts +3 -0
  225. package/dist/extensions/store.d.ts.map +1 -1
  226. package/dist/extensions/store.js +112 -4
  227. package/dist/extensions/store.js.map +1 -1
  228. package/dist/index.d.ts +4 -1
  229. package/dist/index.d.ts.map +1 -1
  230. package/dist/index.js +6 -1
  231. package/dist/index.js.map +1 -1
  232. package/dist/integrations/adapters/telegram.d.ts.map +1 -1
  233. package/dist/integrations/adapters/telegram.js +1 -0
  234. package/dist/integrations/adapters/telegram.js.map +1 -1
  235. package/dist/integrations/index.d.ts +5 -1
  236. package/dist/integrations/index.d.ts.map +1 -1
  237. package/dist/integrations/index.js +4 -1
  238. package/dist/integrations/index.js.map +1 -1
  239. package/dist/integrations/plugin.d.ts +8 -0
  240. package/dist/integrations/plugin.d.ts.map +1 -1
  241. package/dist/integrations/plugin.js +760 -32
  242. package/dist/integrations/plugin.js.map +1 -1
  243. package/dist/integrations/remote-commands-store.d.ts +36 -0
  244. package/dist/integrations/remote-commands-store.d.ts.map +1 -0
  245. package/dist/integrations/remote-commands-store.js +273 -0
  246. package/dist/integrations/remote-commands-store.js.map +1 -0
  247. package/dist/integrations/remote-devices-store.d.ts +43 -0
  248. package/dist/integrations/remote-devices-store.d.ts.map +1 -0
  249. package/dist/integrations/remote-devices-store.js +315 -0
  250. package/dist/integrations/remote-devices-store.js.map +1 -0
  251. package/dist/integrations/remote-push-store.d.ts +37 -0
  252. package/dist/integrations/remote-push-store.d.ts.map +1 -0
  253. package/dist/integrations/remote-push-store.js +299 -0
  254. package/dist/integrations/remote-push-store.js.map +1 -0
  255. package/dist/integrations/remote-retry-job.d.ts +7 -0
  256. package/dist/integrations/remote-retry-job.d.ts.map +1 -0
  257. package/dist/integrations/remote-retry-job.js +45 -0
  258. package/dist/integrations/remote-retry-job.js.map +1 -0
  259. package/dist/integrations/remote-run-events-store.d.ts +18 -0
  260. package/dist/integrations/remote-run-events-store.d.ts.map +1 -0
  261. package/dist/integrations/remote-run-events-store.js +82 -0
  262. package/dist/integrations/remote-run-events-store.js.map +1 -0
  263. package/dist/integrations/remote-types.d.ts +101 -0
  264. package/dist/integrations/remote-types.d.ts.map +1 -0
  265. package/dist/integrations/remote-types.js +2 -0
  266. package/dist/integrations/remote-types.js.map +1 -0
  267. package/dist/integrations/webhook-handler.d.ts +2 -0
  268. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  269. package/dist/integrations/webhook-handler.js +4 -1
  270. package/dist/integrations/webhook-handler.js.map +1 -1
  271. package/dist/jobs/scheduler.d.ts +4 -2
  272. package/dist/jobs/scheduler.d.ts.map +1 -1
  273. package/dist/jobs/scheduler.js +9 -3
  274. package/dist/jobs/scheduler.js.map +1 -1
  275. package/dist/mcp-client/builtin-capabilities.d.ts +20 -0
  276. package/dist/mcp-client/builtin-capabilities.d.ts.map +1 -0
  277. package/dist/mcp-client/builtin-capabilities.js +75 -0
  278. package/dist/mcp-client/builtin-capabilities.js.map +1 -0
  279. package/dist/mcp-client/builtin-store.d.ts +10 -0
  280. package/dist/mcp-client/builtin-store.d.ts.map +1 -0
  281. package/dist/mcp-client/builtin-store.js +55 -0
  282. package/dist/mcp-client/builtin-store.js.map +1 -0
  283. package/dist/mcp-client/index.d.ts +3 -1
  284. package/dist/mcp-client/index.d.ts.map +1 -1
  285. package/dist/mcp-client/index.js +3 -1
  286. package/dist/mcp-client/index.js.map +1 -1
  287. package/dist/mcp-client/routes.d.ts +28 -0
  288. package/dist/mcp-client/routes.d.ts.map +1 -1
  289. package/dist/mcp-client/routes.js +195 -1
  290. package/dist/mcp-client/routes.js.map +1 -1
  291. package/dist/org/context.d.ts.map +1 -1
  292. package/dist/org/context.js +34 -0
  293. package/dist/org/context.js.map +1 -1
  294. package/dist/resources/handlers.d.ts +4 -0
  295. package/dist/resources/handlers.d.ts.map +1 -1
  296. package/dist/resources/handlers.js +46 -7
  297. package/dist/resources/handlers.js.map +1 -1
  298. package/dist/resources/script-helpers.d.ts +8 -1
  299. package/dist/resources/script-helpers.d.ts.map +1 -1
  300. package/dist/resources/script-helpers.js +18 -8
  301. package/dist/resources/script-helpers.js.map +1 -1
  302. package/dist/resources/store.d.ts +19 -0
  303. package/dist/resources/store.d.ts.map +1 -1
  304. package/dist/resources/store.js +86 -3
  305. package/dist/resources/store.js.map +1 -1
  306. package/dist/scripts/agent-engines/list-agent-engines.d.ts +1 -1
  307. package/dist/scripts/agent-engines/list-agent-engines.d.ts.map +1 -1
  308. package/dist/scripts/agent-engines/list-agent-engines.js +18 -7
  309. package/dist/scripts/agent-engines/list-agent-engines.js.map +1 -1
  310. package/dist/scripts/agent-engines/manage-agent-engine.d.ts.map +1 -1
  311. package/dist/scripts/agent-engines/manage-agent-engine.js +100 -7
  312. package/dist/scripts/agent-engines/manage-agent-engine.js.map +1 -1
  313. package/dist/scripts/resources/delete.d.ts.map +1 -1
  314. package/dist/scripts/resources/delete.js +4 -1
  315. package/dist/scripts/resources/delete.js.map +1 -1
  316. package/dist/scripts/resources/effective.d.ts +11 -0
  317. package/dist/scripts/resources/effective.d.ts.map +1 -0
  318. package/dist/scripts/resources/effective.js +54 -0
  319. package/dist/scripts/resources/effective.js.map +1 -0
  320. package/dist/scripts/resources/index.d.ts.map +1 -1
  321. package/dist/scripts/resources/index.js +1 -0
  322. package/dist/scripts/resources/index.js.map +1 -1
  323. package/dist/scripts/resources/list.d.ts +1 -1
  324. package/dist/scripts/resources/list.d.ts.map +1 -1
  325. package/dist/scripts/resources/list.js +17 -5
  326. package/dist/scripts/resources/list.js.map +1 -1
  327. package/dist/scripts/resources/read.d.ts +1 -1
  328. package/dist/scripts/resources/read.d.ts.map +1 -1
  329. package/dist/scripts/resources/read.js +20 -5
  330. package/dist/scripts/resources/read.js.map +1 -1
  331. package/dist/scripts/resources/write.d.ts.map +1 -1
  332. package/dist/scripts/resources/write.js +4 -1
  333. package/dist/scripts/resources/write.js.map +1 -1
  334. package/dist/scripts/runner.d.ts +11 -1
  335. package/dist/scripts/runner.d.ts.map +1 -1
  336. package/dist/scripts/runner.js +75 -27
  337. package/dist/scripts/runner.js.map +1 -1
  338. package/dist/server/action-discovery.d.ts.map +1 -1
  339. package/dist/server/action-discovery.js +5 -0
  340. package/dist/server/action-discovery.js.map +1 -1
  341. package/dist/server/agent-chat-plugin.d.ts +24 -0
  342. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  343. package/dist/server/agent-chat-plugin.js +608 -54
  344. package/dist/server/agent-chat-plugin.js.map +1 -1
  345. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  346. package/dist/server/core-routes-plugin.js +2 -0
  347. package/dist/server/core-routes-plugin.js.map +1 -1
  348. package/dist/server/embedded.d.ts +72 -0
  349. package/dist/server/embedded.d.ts.map +1 -0
  350. package/dist/server/embedded.js +119 -0
  351. package/dist/server/embedded.js.map +1 -0
  352. package/dist/server/index.d.ts +8 -1
  353. package/dist/server/index.d.ts.map +1 -1
  354. package/dist/server/index.js +7 -1
  355. package/dist/server/index.js.map +1 -1
  356. package/dist/server/poll.d.ts.map +1 -1
  357. package/dist/server/poll.js +184 -13
  358. package/dist/server/poll.js.map +1 -1
  359. package/dist/server/resources-plugin.d.ts.map +1 -1
  360. package/dist/server/resources-plugin.js +11 -2
  361. package/dist/server/resources-plugin.js.map +1 -1
  362. package/dist/sharing/actions/extension-change.d.ts +4 -0
  363. package/dist/sharing/actions/extension-change.d.ts.map +1 -0
  364. package/dist/sharing/actions/extension-change.js +13 -0
  365. package/dist/sharing/actions/extension-change.js.map +1 -0
  366. package/dist/sharing/actions/set-resource-visibility.d.ts.map +1 -1
  367. package/dist/sharing/actions/set-resource-visibility.js +3 -0
  368. package/dist/sharing/actions/set-resource-visibility.js.map +1 -1
  369. package/dist/sharing/actions/share-resource.d.ts.map +1 -1
  370. package/dist/sharing/actions/share-resource.js +4 -0
  371. package/dist/sharing/actions/share-resource.js.map +1 -1
  372. package/dist/sharing/actions/unshare-resource.d.ts.map +1 -1
  373. package/dist/sharing/actions/unshare-resource.js +3 -0
  374. package/dist/sharing/actions/unshare-resource.js.map +1 -1
  375. package/dist/templates/default/AGENTS.md +3 -3
  376. package/dist/templates/workspace-core/AGENTS.md +7 -0
  377. package/dist/templates/workspace-root/AGENTS.md +7 -0
  378. package/dist/templates/workspace-root/README.md +25 -0
  379. package/dist/triggers/dispatcher.d.ts +3 -1
  380. package/dist/triggers/dispatcher.d.ts.map +1 -1
  381. package/dist/triggers/dispatcher.js +9 -3
  382. package/dist/triggers/dispatcher.js.map +1 -1
  383. package/dist/workspace-connections/index.d.ts +2 -0
  384. package/dist/workspace-connections/index.d.ts.map +1 -0
  385. package/dist/workspace-connections/index.js +2 -0
  386. package/dist/workspace-connections/index.js.map +1 -0
  387. package/dist/workspace-connections/store.d.ts +229 -0
  388. package/dist/workspace-connections/store.d.ts.map +1 -0
  389. package/dist/workspace-connections/store.js +938 -0
  390. package/dist/workspace-connections/store.js.map +1 -0
  391. package/docs/content/agent-teams.md +6 -0
  392. package/docs/content/cloneable-saas.md +1 -0
  393. package/docs/content/code-agents-ui.md +261 -0
  394. package/docs/content/dispatch.md +40 -3
  395. package/docs/content/embedding-sdk.md +459 -0
  396. package/docs/content/faq.md +1 -0
  397. package/docs/content/getting-started.md +1 -0
  398. package/docs/content/mcp-clients.md +41 -3
  399. package/docs/content/migration-workbench.md +237 -54
  400. package/docs/content/multi-app-workspace.md +41 -0
  401. package/docs/content/multi-tenancy.md +1 -1
  402. package/docs/content/template-brain.md +418 -0
  403. package/docs/content/template-dispatch.md +30 -0
  404. package/docs/content/workspace-connections.md +509 -0
  405. package/docs/content/workspace-management.md +12 -12
  406. package/docs/content/workspace.md +180 -40
  407. package/package.json +7 -2
  408. package/src/templates/default/AGENTS.md +3 -3
  409. package/src/templates/workspace-core/AGENTS.md +7 -0
  410. package/src/templates/workspace-root/AGENTS.md +7 -0
  411. package/src/templates/workspace-root/README.md +25 -0
@@ -1,11 +1,39 @@
1
+ import crypto from "crypto";
1
2
  import fs from "fs";
2
3
  import path from "path";
4
+ import { fileURLToPath } from "url";
5
+ import { appendCodeAgentTranscriptEvent, codeAgentRunArtifactsDir, createCodeAgentRunRecord, getLastCodeAgentRunRecord, listCodeAgentRunRecords, writeCodeAgentRunRecord, } from "./code-agent-runs.js";
3
6
  import { createApp } from "./create.js";
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const DEFAULT_APP_NAME = "migration";
10
+ const DEFAULT_OUTPUT = "../migrated-app";
11
+ const DEFAULT_TARGET = "agent-native";
12
+ const DEFAULT_DOSSIER_DIR = "agent-native-migration-dossier";
13
+ const MIGRATION_DEV_PORT = 8101;
14
+ const MIGRATE_SUBCOMMANDS = new Set(["resume", "status", "stop", "ui"]);
15
+ const MIGRATION_SESSION_COMMAND = "agent-native code /migrate";
16
+ const MODEL_CREDENTIAL_ENV_NAMES = [
17
+ "ANTHROPIC_API_KEY",
18
+ "OPENAI_API_KEY",
19
+ "GOOGLE_GENERATIVE_AI_API_KEY",
20
+ "GROQ_API_KEY",
21
+ "MISTRAL_API_KEY",
22
+ "COHERE_API_KEY",
23
+ "BUILDER_PRIVATE_KEY",
24
+ ];
4
25
  export function parseMigrateArgs(argv) {
5
26
  const opts = {};
6
27
  for (let i = 0; i < argv.length; i++) {
7
28
  const arg = argv[i];
8
- if (arg === "--out" && argv[i + 1]) {
29
+ if (i === 0 && MIGRATE_SUBCOMMANDS.has(arg)) {
30
+ opts.subcommand = arg;
31
+ continue;
32
+ }
33
+ if (arg === "--help" || arg === "-h") {
34
+ opts.help = true;
35
+ }
36
+ else if (arg === "--out" && argv[i + 1]) {
9
37
  opts.output = argv[++i];
10
38
  }
11
39
  else if (arg.startsWith("--out=")) {
@@ -23,56 +51,1336 @@ export function parseMigrateArgs(argv) {
23
51
  else if (arg.startsWith("--target=")) {
24
52
  opts.target = arg.slice("--target=".length);
25
53
  }
54
+ else if (arg === "--source" && argv[i + 1]) {
55
+ setSourceOption(opts, argv[++i]);
56
+ }
57
+ else if (arg.startsWith("--source=")) {
58
+ setSourceOption(opts, arg.slice("--source=".length));
59
+ }
60
+ else if (arg === "--path" && argv[i + 1]) {
61
+ opts.sourcePath = argv[++i];
62
+ }
63
+ else if (arg.startsWith("--path=")) {
64
+ opts.sourcePath = arg.slice("--path=".length);
65
+ }
66
+ else if (arg === "--url" && argv[i + 1]) {
67
+ opts.sourceUrl = argv[++i];
68
+ }
69
+ else if (arg.startsWith("--url=")) {
70
+ opts.sourceUrl = arg.slice("--url=".length);
71
+ }
72
+ else if ((arg === "--description" || arg === "--describe") &&
73
+ argv[i + 1]) {
74
+ opts.sourceDescription = argv[++i];
75
+ }
76
+ else if (arg.startsWith("--description=")) {
77
+ opts.sourceDescription = arg.slice("--description=".length);
78
+ }
79
+ else if (arg.startsWith("--describe=")) {
80
+ opts.sourceDescription = arg.slice("--describe=".length);
81
+ }
82
+ else if (arg === "--emit") {
83
+ opts.emit = true;
84
+ if (argv[i + 1] && !argv[i + 1].startsWith("-")) {
85
+ opts.emitDir = argv[++i];
86
+ }
87
+ }
88
+ else if (arg.startsWith("--emit=")) {
89
+ opts.emit = true;
90
+ opts.emitDir = arg.slice("--emit=".length);
91
+ }
92
+ else if (arg === "--emit-dir" && argv[i + 1]) {
93
+ opts.emit = true;
94
+ opts.emitDir = argv[++i];
95
+ }
96
+ else if (arg.startsWith("--emit-dir=")) {
97
+ opts.emit = true;
98
+ opts.emitDir = arg.slice("--emit-dir=".length);
99
+ }
100
+ else if (arg === "--app-surface" || arg === "--workbench") {
101
+ opts.appSurface = true;
102
+ }
26
103
  else if (arg === "--plan-only") {
27
104
  opts.planOnly = true;
28
105
  }
29
- else if (!arg.startsWith("-") && !opts.source) {
30
- opts.source = arg;
106
+ else if (arg === "--last") {
107
+ opts.last = true;
108
+ }
109
+ else if (!arg.startsWith("-")) {
110
+ if (opts.subcommand &&
111
+ ["status", "stop", "ui"].includes(opts.subcommand) &&
112
+ !opts.workbench) {
113
+ opts.workbench = arg;
114
+ }
115
+ else if (!opts.source) {
116
+ opts.source = arg;
117
+ }
118
+ else if (!opts.workbench) {
119
+ opts.workbench = arg;
120
+ }
31
121
  }
32
122
  }
33
123
  return opts;
34
124
  }
35
125
  export async function runMigrate(argv) {
36
126
  const opts = parseMigrateArgs(argv);
37
- if (!opts.source) {
38
- console.error("Usage: agent-native migrate <source> [--out ../migrated-app] [--name migration]");
127
+ if (opts.help) {
128
+ console.log(migrateUsage());
129
+ return;
130
+ }
131
+ if (opts.subcommand === "status") {
132
+ printMigrationStatus(opts);
133
+ return;
134
+ }
135
+ if (opts.subcommand === "stop") {
136
+ printMigrationStop(opts);
137
+ return;
138
+ }
139
+ if (opts.subcommand === "ui") {
140
+ printMigrationUi(opts);
141
+ return;
142
+ }
143
+ if (opts.emit) {
144
+ try {
145
+ const result = await emitOwnAgentDossier(opts);
146
+ console.log(renderEmitResult(result));
147
+ }
148
+ catch (error) {
149
+ if (isExpectedMigrationCliError(error)) {
150
+ console.error(`\n${migrationCliErrorMessage(error)}\n`);
151
+ process.exit(1);
152
+ }
153
+ throw error;
154
+ }
155
+ return;
156
+ }
157
+ if (opts.subcommand === "resume" && !hasAnySource(opts)) {
158
+ printMigrationResume(opts);
159
+ return;
160
+ }
161
+ if (opts.appSurface) {
162
+ await scaffoldOrResumeWorkbench(opts);
163
+ return;
164
+ }
165
+ try {
166
+ await createMigrationCodeAgentSession(opts);
167
+ }
168
+ catch (error) {
169
+ if (isExpectedMigrationCliError(error)) {
170
+ console.error(`\n${migrationCliErrorMessage(error)}\n`);
171
+ process.exit(1);
172
+ }
173
+ throw error;
174
+ }
175
+ }
176
+ export async function emitOwnAgentDossier(opts, cwd = process.cwd()) {
177
+ const source = resolveSourceSpec(opts, cwd);
178
+ if (!source) {
179
+ throw new Error("Usage: agent-native migrate <source-path-or-url> --emit [dossier-dir]");
180
+ }
181
+ let dossierRoot = resolveDossierRoot(opts, source, cwd);
182
+ const explicitEmitDir = Boolean(opts.emitDir);
183
+ if (source.sourceRoot && isInsideOrSame(source.sourceRoot, dossierRoot)) {
184
+ if (explicitEmitDir) {
185
+ throw new Error(`Refusing to emit dossier inside sourceRoot (${source.sourceRoot}). Choose an --emit path outside the source project.`);
186
+ }
187
+ dossierRoot = defaultDossierRoot(source, cwd);
188
+ }
189
+ if (source.sourceRoot) {
190
+ assertOutsideSourceRoot(source.sourceRoot, dossierRoot, "dossier");
191
+ }
192
+ fs.mkdirSync(dossierRoot, { recursive: true });
193
+ const written = new Set();
194
+ const write = (relativePath, content) => {
195
+ const filePath = path.join(dossierRoot, relativePath);
196
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
197
+ fs.writeFileSync(filePath, content.endsWith("\n") ? content : `${content}\n`);
198
+ written.add(relativePath);
199
+ };
200
+ const templateDir = findMigrationTemplateDir();
201
+ const templateAgents = readTextIfExists(templateDir ? path.join(templateDir, "AGENTS.md") : undefined);
202
+ write("AGENTS.md", renderDossierAgentsMd(source, templateAgents));
203
+ for (const copied of copyMigrationSkills(templateDir, dossierRoot)) {
204
+ written.add(copied);
205
+ }
206
+ const helperResult = await writeAssessmentWithMigrateHelpers({
207
+ source,
208
+ dossierRoot,
209
+ target: opts.target ?? DEFAULT_TARGET,
210
+ write,
211
+ });
212
+ const usedMigrateHelpers = helperResult;
213
+ if (!helperResult) {
214
+ const fallback = buildFallbackAssessment(source);
215
+ write("01-assessment.md", fallback.assessment);
216
+ if (fallback.ir) {
217
+ write("ir.json", `${JSON.stringify(fallback.ir, null, 2)}\n`);
218
+ }
219
+ }
220
+ write("MIGRATION_PLAYBOOK.md", renderMigrationPlaybook(source));
221
+ write("source.json", `${JSON.stringify({
222
+ source,
223
+ target: opts.target ?? DEFAULT_TARGET,
224
+ createdAt: new Date().toISOString(),
225
+ usedMigrateHelpers,
226
+ }, null, 2)}\n`);
227
+ return {
228
+ dossierRoot,
229
+ files: [...written].sort(),
230
+ source,
231
+ usedMigrateHelpers,
232
+ };
233
+ }
234
+ export function isExpectedMigrationCliError(error) {
235
+ const message = migrationCliErrorMessage(error);
236
+ return (message.startsWith("Usage: agent-native migrate") ||
237
+ message.startsWith("Refusing to emit dossier inside sourceRoot") ||
238
+ message.startsWith("Refusing to write "));
239
+ }
240
+ function migrationCliErrorMessage(error) {
241
+ if (error instanceof Error)
242
+ return error.message;
243
+ return String(error);
244
+ }
245
+ async function scaffoldOrResumeWorkbench(opts) {
246
+ const cwd = process.cwd();
247
+ const source = resolveSourceSpec(opts, cwd);
248
+ if (!source) {
249
+ console.error(migrateUsage());
39
250
  process.exit(1);
40
251
  }
41
- const appName = opts.appName ?? "migration";
42
- const target = opts.target ?? "agent-native";
43
- const sourceRoot = path.resolve(process.cwd(), opts.source);
44
- const outputRoot = path.resolve(process.cwd(), opts.output ?? "../migrated-app");
45
- await createApp(appName, { template: "migration" });
46
- const appDir = resolveScaffoldedAppDir(process.cwd(), appName);
252
+ const appName = opts.appName ?? DEFAULT_APP_NAME;
253
+ const target = opts.target ?? DEFAULT_TARGET;
254
+ const outputRoot = path.resolve(cwd, opts.output ?? DEFAULT_OUTPUT);
255
+ const appDirBefore = resolveScaffoldedAppDir(cwd, appName);
256
+ const existing = fs.existsSync(appDirBefore);
257
+ if (!existing) {
258
+ await createApp(appName, { template: "migration" });
259
+ }
260
+ const appDir = resolveScaffoldedAppDir(cwd, appName);
47
261
  fs.mkdirSync(path.join(appDir, "data"), { recursive: true });
48
262
  fs.writeFileSync(path.join(appDir, "data", "migration-source.json"), `${JSON.stringify({
49
- name: `Migration from ${path.basename(sourceRoot)}`,
50
- sourceRoot,
263
+ schemaVersion: 2,
264
+ name: defaultRunName(source),
265
+ source: sourceSeedPayload(source),
266
+ sourceKind: source.kind,
267
+ sourceRoot: source.sourceRoot ?? "",
268
+ sourceUrl: source.kind === "url" ? source.value : undefined,
269
+ sourceDescription: source.description,
51
270
  outputRoot,
52
271
  target,
53
272
  planOnly: Boolean(opts.planOnly),
54
273
  createdAt: new Date().toISOString(),
55
274
  }, null, 2)}\n`);
275
+ console.log(renderWorkbenchReady({ appDir, existing, outputRoot, source }));
276
+ }
277
+ async function createMigrationCodeAgentSession(opts) {
278
+ const cwd = process.cwd();
279
+ const source = resolveSourceSpec(opts, cwd);
280
+ if (!source) {
281
+ console.error(migrateUsage());
282
+ process.exit(1);
283
+ }
284
+ const outputRoot = path.resolve(cwd, opts.output ?? DEFAULT_OUTPUT);
285
+ if (source.sourceRoot) {
286
+ assertOutsideSourceRoot(source.sourceRoot, outputRoot, "outputRoot");
287
+ }
288
+ const run = createCodeAgentRunRecord({
289
+ goalId: "migrate",
290
+ title: defaultRunName(source),
291
+ subtitle: formatSourceForDisplay(source),
292
+ status: "needs-approval",
293
+ phase: "intake",
294
+ needsApproval: true,
295
+ progress: {
296
+ label: "Intake",
297
+ completed: 0,
298
+ total: 1,
299
+ percent: 0,
300
+ },
301
+ cwd,
302
+ metadata: {
303
+ source,
304
+ sourceRoot: source.sourceRoot,
305
+ outputRoot,
306
+ target: opts.target ?? DEFAULT_TARGET,
307
+ },
308
+ });
309
+ appendCodeAgentTranscriptEvent({
310
+ runId: run.id,
311
+ kind: "user",
312
+ message: `Migrate ${formatSourceForDisplay(source)} to ${opts.target ?? DEFAULT_TARGET}.`,
313
+ metadata: {
314
+ source,
315
+ outputRoot,
316
+ target: opts.target ?? DEFAULT_TARGET,
317
+ },
318
+ });
319
+ appendCodeAgentTranscriptEvent({
320
+ runId: run.id,
321
+ kind: "status",
322
+ message: "Preparing migration dossier.",
323
+ metadata: { status: "needs-approval", phase: "intake" },
324
+ });
325
+ const artifactRoot = codeAgentRunArtifactsDir(run.id);
326
+ const dossierRoot = path.join(artifactRoot, "migration-dossier");
327
+ const dossier = await emitOwnAgentDossier({
328
+ ...opts,
329
+ emit: true,
330
+ emitDir: dossierRoot,
331
+ target: opts.target ?? DEFAULT_TARGET,
332
+ }, cwd);
333
+ const updated = {
334
+ ...run,
335
+ progress: {
336
+ label: "Dossier ready; waiting for approval",
337
+ completed: 1,
338
+ total: 2,
339
+ percent: 50,
340
+ },
341
+ artifactRoot,
342
+ details: [
343
+ { label: "Source", value: formatSourceForDisplay(source) },
344
+ { label: "Output", value: outputRoot },
345
+ { label: "Dossier", value: dossierRoot },
346
+ { label: "Resume", value: "agent-native code resume --last" },
347
+ { label: "Attach", value: "agent-native code attach --last" },
348
+ ],
349
+ metadata: {
350
+ ...(run.metadata ?? {}),
351
+ dossierRoot,
352
+ dossierFiles: dossier.files,
353
+ artifactFiles: dossier.files.map((file) => path.join(dossierRoot, file)),
354
+ usedMigrateHelpers: dossier.usedMigrateHelpers,
355
+ resumeCommand: "agent-native code resume --last",
356
+ attachCommand: "agent-native code attach --last",
357
+ statusCommand: "agent-native code status --last",
358
+ preferredCommand: MIGRATION_SESSION_COMMAND,
359
+ },
360
+ updatedAt: new Date().toISOString(),
361
+ };
362
+ writeCodeAgentRunRecord(updated);
363
+ appendCodeAgentTranscriptEvent({
364
+ runId: run.id,
365
+ kind: "artifact",
366
+ message: "Migration dossier created.",
367
+ metadata: {
368
+ path: dossierRoot,
369
+ files: dossier.files,
370
+ usedMigrateHelpers: dossier.usedMigrateHelpers,
371
+ },
372
+ });
373
+ appendCodeAgentTranscriptEvent({
374
+ runId: run.id,
375
+ kind: "note",
376
+ message: "Use the dossier with Codex, Claude Code, Cursor, or another coding agent; no migration agent process has been started by the CLI.",
377
+ metadata: { source: "migration-dossier" },
378
+ });
379
+ appendCodeAgentTranscriptEvent({
380
+ runId: run.id,
381
+ kind: "status",
382
+ message: "Migration dossier is ready. Resume the /migrate session from Agent-Native Code when you are ready to approve or continue.",
383
+ metadata: { status: "needs-approval", phase: "intake" },
384
+ });
385
+ console.log(renderCodeAgentMigrationSession(updated, dossier));
386
+ }
387
+ function printMigrationStatus(opts) {
388
+ const last = getLastCodeAgentRunRecord("migrate");
389
+ const runs = listCodeAgentRunRecords("migrate");
390
+ if (last || !opts.appSurface) {
391
+ console.log(renderCodeAgentMigrationStatus(runs));
392
+ return;
393
+ }
394
+ const appDir = resolveWorkbenchDir(opts);
395
+ const seedPath = path.join(appDir, "data", "migration-source.json");
396
+ const seed = readJsonIfExists(seedPath);
397
+ const artifactRuns = readArtifactRuns(appDir);
398
+ if (!fs.existsSync(appDir)) {
399
+ console.error(`No Migration Workbench found at ${appDir}.`);
400
+ console.error(`Create one with: npx @agent-native/core@latest code /migrate <source>`);
401
+ console.error(`The direct migrate command is a shortcut into that same Agent-Native Code slash command.`);
402
+ process.exit(1);
403
+ }
56
404
  console.log([
57
405
  "",
58
- "Migration Workbench is ready.",
406
+ "Migration Workbench status",
407
+ "",
408
+ ` App: ${appDir}`,
409
+ ` Seed: ${fs.existsSync(seedPath) ? seedPath : "not found"}`,
410
+ ` Source: ${formatSeedSource(seed)}`,
411
+ ` Output: ${seed?.outputRoot ?? "not set"}`,
412
+ ` Target: ${seed?.target ?? DEFAULT_TARGET}`,
413
+ ` Artifacts: ${artifactRuns.length} run${artifactRuns.length === 1 ? "" : "s"}`,
414
+ ...artifactRuns
415
+ .slice(0, 5)
416
+ .map((run) => ` - ${run.id} (${run.phase})`),
417
+ artifactRuns.length > 5 ? ` - ${artifactRuns.length - 5} more...` : "",
59
418
  "",
60
- ` Source: ${sourceRoot}`,
61
- ` Output: ${outputRoot}`,
62
- ` App: ${appDir}`,
419
+ ...credentialStatusLines(),
420
+ ]
421
+ .filter(Boolean)
422
+ .join("\n"));
423
+ }
424
+ function printMigrationStop(_opts) {
425
+ console.log([
63
426
  "",
64
- "Next:",
65
- ` cd ${path.relative(process.cwd(), appDir) || "."}`,
427
+ "Agent-Native Code /migrate stop",
428
+ "",
429
+ "The migrate CLI creates resumable session records and artifacts; it does not daemonize a background process yet.",
430
+ "Stop the terminal, Desktop run, or external coding agent that is actively working on the session.",
431
+ ].join("\n"));
432
+ }
433
+ function printMigrationUi(opts) {
434
+ const last = getLastCodeAgentRunRecord("migrate");
435
+ if (last && !opts.appSurface) {
436
+ console.log(renderCodeAgentMigrationUi(last));
437
+ return;
438
+ }
439
+ const appDir = resolveWorkbenchDir(opts);
440
+ console.log([
441
+ "",
442
+ "Migration Workbench UI",
443
+ "",
444
+ ` App: ${appDir}`,
445
+ ` URL: http://localhost:${MIGRATION_DEV_PORT}/`,
446
+ "",
447
+ "Start it with:",
448
+ ` cd ${shellQuote(path.relative(process.cwd(), appDir) || ".")}`,
66
449
  " pnpm install",
67
450
  " pnpm dev",
68
451
  "",
69
- "The Workbench will prefill the source and output paths. Create the run, assess, plan, approve, run a task, then verify.",
452
+ "Deep-link shape:",
453
+ ` http://localhost:${MIGRATION_DEV_PORT}/`,
454
+ " Pick a run in the Workbench, or ask the app agent to navigate by run ID.",
70
455
  ].join("\n"));
71
456
  }
457
+ function printMigrationResume(opts) {
458
+ const last = getLastCodeAgentRunRecord("migrate");
459
+ if (last && !opts.appSurface) {
460
+ console.log(renderCodeAgentMigrationResume(last));
461
+ return;
462
+ }
463
+ const appDir = resolveWorkbenchDir(opts);
464
+ const seedPath = path.join(appDir, "data", "migration-source.json");
465
+ const seed = readJsonIfExists(seedPath);
466
+ if (!fs.existsSync(appDir) || !seed) {
467
+ console.error("No resumable Migration Workbench seed found. Run `npx @agent-native/core@latest code /migrate <source>` first.");
468
+ process.exit(1);
469
+ }
470
+ console.log([
471
+ "",
472
+ "Migration Workbench resume",
473
+ "",
474
+ ` App: ${appDir}`,
475
+ ` Seed: ${seedPath}`,
476
+ "",
477
+ "Continue with:",
478
+ ` cd ${shellQuote(path.relative(process.cwd(), appDir) || ".")}`,
479
+ " pnpm dev",
480
+ "",
481
+ `Workbench URL: http://localhost:${MIGRATION_DEV_PORT}/`,
482
+ ].join("\n"));
483
+ }
484
+ function renderWorkbenchReady(args) {
485
+ const rel = path.relative(process.cwd(), args.appDir) || ".";
486
+ const sourceCommand = formatSourceForCommand(args.source);
487
+ return [
488
+ "",
489
+ args.existing
490
+ ? "Migration Workbench is ready (reused existing app)."
491
+ : "Migration Workbench is ready.",
492
+ "",
493
+ ` Source: ${formatSourceForDisplay(args.source)}`,
494
+ ` Output: ${args.outputRoot}`,
495
+ ` App: ${args.appDir}`,
496
+ "",
497
+ "Run it:",
498
+ ` cd ${shellQuote(rel)}`,
499
+ " pnpm install",
500
+ " pnpm dev",
501
+ "",
502
+ "npx-friendly commands:",
503
+ ` npx @agent-native/core@latest code /migrate ${sourceCommand} --out ${shellQuote(path.relative(process.cwd(), args.outputRoot) || ".")}`,
504
+ ` npx @agent-native/core@latest code /migrate ${sourceCommand} --emit ${shellQuote(defaultDossierDirForDisplay(args.source))}`,
505
+ "",
506
+ "Workbench URL:",
507
+ ` http://localhost:${MIGRATION_DEV_PORT}/`,
508
+ " If Vite chooses another port, use the URL printed by `pnpm dev`.",
509
+ "",
510
+ "Deep-link shape:",
511
+ ` http://localhost:${MIGRATION_DEV_PORT}/`,
512
+ " Select the run inside the Workbench, or ask the app agent to open a run by ID.",
513
+ "",
514
+ ...credentialStatusLines(),
515
+ "",
516
+ "The Workbench seed is written to data/migration-source.json. It stores paths and source metadata only, never secret values.",
517
+ ].join("\n");
518
+ }
519
+ function renderCodeAgentMigrationSession(run, dossier) {
520
+ return [
521
+ "",
522
+ "Agent-Native Code /migrate session created.",
523
+ "",
524
+ ` Run: ${run.id}`,
525
+ " Goal: /migrate",
526
+ ` Source: ${run.subtitle ?? "not set"}`,
527
+ ` Output: ${stringMetadata(run, "outputRoot") ?? "not set"}`,
528
+ ` Dossier: ${stringMetadata(run, "dossierRoot") ?? dossier.dossierRoot}`,
529
+ ` Engine: ${dossier.usedMigrateHelpers ? "@agent-native/migrate helpers" : "safe local fallback"}`,
530
+ "",
531
+ "Artifacts:",
532
+ ...dossier.files
533
+ .filter((file) => [
534
+ "AGENTS.md",
535
+ "MIGRATION_PLAYBOOK.md",
536
+ "01-assessment.md",
537
+ "ir.json",
538
+ "source.json",
539
+ ].includes(file))
540
+ .map((file) => ` - ${path.join(dossier.dossierRoot, file)}`),
541
+ "",
542
+ "Continue:",
543
+ " agent-native code attach --last",
544
+ " agent-native code resume --last",
545
+ " agent-native code logs --last",
546
+ " agent-native code status --last",
547
+ "",
548
+ "Desktop:",
549
+ " Open Agent-Native Code in the left sidebar. This run appears as a /migrate session.",
550
+ "",
551
+ "Use another agent:",
552
+ ` Point Codex, Claude Code, Cursor, or another coding agent at ${shellQuote(dossier.dossierRoot)} and ask it to follow AGENTS.md plus MIGRATION_PLAYBOOK.md.`,
553
+ "",
554
+ "Default surface:",
555
+ " Migration stays in Agent-Native Code. No hidden app/template was scaffolded.",
556
+ " Use --app-surface only when you explicitly want the legacy migration detail app.",
557
+ ].join("\n");
558
+ }
559
+ function renderCodeAgentMigrationStatus(runs) {
560
+ return [
561
+ "",
562
+ "Agent-Native Code /migrate status",
563
+ "",
564
+ runs.length === 0
565
+ ? " No /migrate sessions found. Start one with `agent-native code /migrate <source>`."
566
+ : ` ${runs.length} session${runs.length === 1 ? "" : "s"} found.`,
567
+ ...runs.slice(0, 8).map((run) => {
568
+ const output = stringMetadata(run, "outputRoot");
569
+ const dossier = stringMetadata(run, "dossierRoot");
570
+ const progress = run.progress?.label
571
+ ? ` Progress: ${run.progress.label} (${run.progress.completed}/${run.progress.total})`
572
+ : "";
573
+ return [
574
+ ` - ${run.id}`,
575
+ ` Status: ${run.status}${run.phase ? ` (${run.phase})` : ""}`,
576
+ progress,
577
+ ` Source: ${run.subtitle ?? "not set"}`,
578
+ output ? ` Output: ${output}` : "",
579
+ dossier ? ` Dossier: ${dossier}` : "",
580
+ ` Resume: agent-native code resume ${run.id}`,
581
+ ]
582
+ .filter(Boolean)
583
+ .join("\n");
584
+ }),
585
+ runs.length > 8 ? ` - ${runs.length - 8} more...` : "",
586
+ "",
587
+ "Shortcuts:",
588
+ " agent-native migrate status --last shows the same Agent-Native Code sessions.",
589
+ " Add --app-surface only to inspect the legacy hidden migration app.",
590
+ ]
591
+ .filter(Boolean)
592
+ .join("\n");
593
+ }
594
+ function renderCodeAgentMigrationResume(run) {
595
+ const dossier = stringMetadata(run, "dossierRoot");
596
+ return [
597
+ "",
598
+ "Agent-Native Code /migrate resume",
599
+ "",
600
+ ` Run: ${run.id}`,
601
+ ` Status: ${run.status}${run.phase ? ` (${run.phase})` : ""}`,
602
+ ` Source: ${run.subtitle ?? "not set"}`,
603
+ dossier ? ` Dossier: ${dossier}` : "",
604
+ "",
605
+ "Continue in the interactive shell:",
606
+ " agent-native code",
607
+ "",
608
+ "Resume this run directly:",
609
+ ` agent-native code resume ${run.id}`,
610
+ " agent-native code attach --last",
611
+ "",
612
+ dossier
613
+ ? `Or hand off to another agent by pointing it at ${shellQuote(dossier)}.`
614
+ : "No dossier path is recorded on this run.",
615
+ ]
616
+ .filter(Boolean)
617
+ .join("\n");
618
+ }
619
+ function renderCodeAgentMigrationUi(run) {
620
+ return [
621
+ "",
622
+ "Agent-Native Code /migrate UI",
623
+ "",
624
+ ` Run: ${run.id}`,
625
+ "",
626
+ "Open Agent-Native Desktop and choose Agent-Native Code from the left sidebar.",
627
+ "The migration detail app is no longer scaffolded by default; it is only an optional legacy surface.",
628
+ ].join("\n");
629
+ }
630
+ function renderEmitResult(result) {
631
+ return [
632
+ "",
633
+ "Migration agent dossier emitted.",
634
+ "",
635
+ ` Source: ${formatSourceForDisplay(result.source)}`,
636
+ ` Dossier: ${result.dossierRoot}`,
637
+ ` IR: ${result.files.includes("ir.json") ? "included" : "not available from this input"}`,
638
+ ` Engine: ${result.usedMigrateHelpers ? "@agent-native/migrate helpers" : "safe local fallback"}`,
639
+ "",
640
+ "Files:",
641
+ ...result.files.map((file) => ` - ${file}`),
642
+ "",
643
+ "Use with Agent-Native Code/Desktop:",
644
+ ` Point the agent at ${shellQuote(result.dossierRoot)} and ask it to follow AGENTS.md plus MIGRATION_PLAYBOOK.md.`,
645
+ "",
646
+ "Safety:",
647
+ " The dossier was written outside sourceRoot and contains no secret values.",
648
+ ].join("\n");
649
+ }
650
+ function migrateUsage() {
651
+ return [
652
+ "Usage:",
653
+ " agent-native code /migrate <source-path-or-url> [--out ../migrated-app] (preferred)",
654
+ " agent-native migrate <source-path-or-url> [--out ../migrated-app] (shortcut)",
655
+ " agent-native migrate <source> --emit [dossier-dir]",
656
+ ' agent-native migrate --describe "legacy app described in prose" --emit',
657
+ " agent-native migrate resume --last",
658
+ " agent-native migrate status --last",
659
+ " agent-native migrate ui --last",
660
+ " agent-native migrate stop --last",
661
+ "",
662
+ "Examples:",
663
+ " npx @agent-native/core@latest code /migrate ./my-next-app --out ../migrated-app",
664
+ " npx @agent-native/core@latest migrate ./my-next-app --out ../migrated-app",
665
+ ' npx @agent-native/core@latest code /migrate https://example.com --describe "marketing site" --emit ../migration-dossier',
666
+ ' npx @agent-native/core@latest code /migrate --describe "A Rails admin app with reporting dashboards" --emit',
667
+ "",
668
+ "Default:",
669
+ " Migration is an Agent-Native Code slash command. The hidden migration app is not scaffolded unless --app-surface is passed.",
670
+ "",
671
+ "Options:",
672
+ " --source, --path <path> Local source path",
673
+ " --url <url> Source URL",
674
+ " --description, --describe Source description for any-input migrations",
675
+ " --emit [dir] Emit an own-agent dossier without recording a session",
676
+ " --out <path> Generated output path for the migration session",
677
+ " --app-surface, --workbench Scaffold the legacy hidden migration detail app",
678
+ " --name <name> Legacy app-surface name (default: migration)",
679
+ " --target <name> Migration target (default: agent-native)",
680
+ " --plan-only Legacy app-surface plan-only seed",
681
+ ].join("\n");
682
+ }
683
+ function setSourceOption(opts, value) {
684
+ opts.source = value;
685
+ if (isProbablyUrl(value)) {
686
+ opts.sourceUrl = value;
687
+ }
688
+ else {
689
+ opts.sourcePath = value;
690
+ }
691
+ }
692
+ function hasAnySource(opts) {
693
+ return Boolean(opts.source || opts.sourcePath || opts.sourceUrl || opts.sourceDescription);
694
+ }
695
+ function resolveSourceSpec(opts, cwd = process.cwd()) {
696
+ if (opts.sourceUrl) {
697
+ return {
698
+ kind: "url",
699
+ value: opts.sourceUrl,
700
+ description: opts.sourceDescription,
701
+ };
702
+ }
703
+ if (opts.sourcePath) {
704
+ return {
705
+ kind: "path",
706
+ value: opts.sourcePath,
707
+ sourceRoot: path.resolve(cwd, opts.sourcePath),
708
+ description: opts.sourceDescription,
709
+ };
710
+ }
711
+ if (opts.source) {
712
+ if (isProbablyUrl(opts.source)) {
713
+ return {
714
+ kind: "url",
715
+ value: opts.source,
716
+ description: opts.sourceDescription,
717
+ };
718
+ }
719
+ return {
720
+ kind: "path",
721
+ value: opts.source,
722
+ sourceRoot: path.resolve(cwd, opts.source),
723
+ description: opts.sourceDescription,
724
+ };
725
+ }
726
+ if (opts.sourceDescription) {
727
+ return {
728
+ kind: "description",
729
+ value: opts.sourceDescription,
730
+ description: opts.sourceDescription,
731
+ };
732
+ }
733
+ return null;
734
+ }
735
+ function resolveDossierRoot(opts, source, cwd) {
736
+ if (opts.emitDir)
737
+ return path.resolve(cwd, opts.emitDir);
738
+ return defaultDossierRoot(source, cwd);
739
+ }
740
+ function defaultDossierRoot(source, cwd) {
741
+ if (source.sourceRoot) {
742
+ return path.resolve(path.dirname(source.sourceRoot), `${path.basename(source.sourceRoot)}-migration-dossier`);
743
+ }
744
+ return path.resolve(cwd, DEFAULT_DOSSIER_DIR);
745
+ }
746
+ function defaultDossierDirForDisplay(source) {
747
+ if (source.sourceRoot) {
748
+ return `../${path.basename(source.sourceRoot)}-migration-dossier`;
749
+ }
750
+ return DEFAULT_DOSSIER_DIR;
751
+ }
752
+ function assertOutsideSourceRoot(sourceRoot, targetPath, label) {
753
+ if (isInsideOrSame(sourceRoot, targetPath)) {
754
+ throw new Error(`Refusing to write ${label} inside sourceRoot (${sourceRoot}). Choose a path outside the source project.`);
755
+ }
756
+ }
757
+ function isInsideOrSame(root, candidate) {
758
+ const relative = path.relative(path.resolve(root), path.resolve(candidate));
759
+ return (relative === "" ||
760
+ (!relative.startsWith("..") && !path.isAbsolute(relative)));
761
+ }
762
+ async function writeAssessmentWithMigrateHelpers(args) {
763
+ try {
764
+ const migratePackage = "@agent-native/migrate";
765
+ const migrate = (await import(migratePackage));
766
+ const adapter = migrate.nextjsSourceAdapter;
767
+ if (args.source.sourceRoot &&
768
+ fs.existsSync(args.source.sourceRoot) &&
769
+ adapter?.introspect &&
770
+ migrate.createMigrationRun &&
771
+ migrate.discoverMigration &&
772
+ migrate.artifactPaths) {
773
+ if (adapter.detect) {
774
+ const detected = await adapter.detect(args.source.sourceRoot);
775
+ if (!detected)
776
+ return false;
777
+ }
778
+ const artifactRoot = path.join(args.dossierRoot, ".migrate-artifacts");
779
+ const outputRoot = path.join(args.dossierRoot, "generated-output");
780
+ assertOutsideSourceRoot(args.source.sourceRoot, artifactRoot, "artifacts");
781
+ assertOutsideSourceRoot(args.source.sourceRoot, outputRoot, "outputRoot");
782
+ const run = await migrate.createMigrationRun({
783
+ sourceRoot: args.source.sourceRoot,
784
+ outputRoot,
785
+ artifactRoot,
786
+ target: args.target,
787
+ id: "dossier",
788
+ });
789
+ const result = await migrate.discoverMigration(run, adapter);
790
+ const artifacts = migrate.artifactPaths(result.run);
791
+ args.write("01-assessment.md", fs.readFileSync(result.assessmentPath, "utf-8"));
792
+ if (fs.existsSync(artifacts.irPath)) {
793
+ args.write("ir.json", fs.readFileSync(artifacts.irPath, "utf-8"));
794
+ }
795
+ return true;
796
+ }
797
+ if (!args.source.sourceRoot && migrate.createSkeletonProjectIR) {
798
+ const ir = migrate.createSkeletonProjectIR({
799
+ sourceRoot: args.source.value,
800
+ inputKind: args.source.kind,
801
+ inputDescription: args.source.description ?? args.source.value,
802
+ });
803
+ args.write("01-assessment.md", renderLocalAssessment(args.source, ir));
804
+ args.write("ir.json", `${JSON.stringify(ir, null, 2)}\n`);
805
+ return true;
806
+ }
807
+ }
808
+ catch {
809
+ return false;
810
+ }
811
+ return false;
812
+ }
813
+ function buildFallbackAssessment(source) {
814
+ if (source.sourceRoot && fs.existsSync(source.sourceRoot)) {
815
+ const ir = createLocalProjectIr(source.sourceRoot);
816
+ return { assessment: renderLocalAssessment(source, ir), ir };
817
+ }
818
+ return { assessment: renderNonPathAssessment(source) };
819
+ }
820
+ function createLocalProjectIr(sourceRoot) {
821
+ const files = walkSourceFiles(sourceRoot);
822
+ const packageJson = readJsonIfExists(path.join(sourceRoot, "package.json"));
823
+ const deps = {
824
+ ...(packageJson?.dependencies ?? {}),
825
+ ...(packageJson?.devDependencies ?? {}),
826
+ };
827
+ const framework = deps.next ||
828
+ hasAnyFile(sourceRoot, [
829
+ "next.config.js",
830
+ "next.config.mjs",
831
+ "next.config.ts",
832
+ ])
833
+ ? "nextjs"
834
+ : deps.react
835
+ ? "react"
836
+ : "unknown";
837
+ const routes = files
838
+ .map((file) => routeFromFile(file))
839
+ .filter((route) => Boolean(route))
840
+ .sort((a, b) => a.path.localeCompare(b.path));
841
+ const codeFiles = files.filter((file) => /\.(ts|tsx|js|jsx)$/.test(file));
842
+ const behavior = {
843
+ apiEndpoints: [],
844
+ dataStores: [],
845
+ llmCalls: [],
846
+ clientState: [],
847
+ auth: [],
848
+ jobs: [],
849
+ };
850
+ for (const file of codeFiles) {
851
+ const text = readSmallText(path.join(sourceRoot, file));
852
+ if (!text)
853
+ continue;
854
+ if (file.startsWith("pages/api/") ||
855
+ /(^|\/)api\/.*\/route\.[tj]sx?$/.test(file)) {
856
+ behavior.apiEndpoints.push({
857
+ id: stableId(file),
858
+ path: apiPathFromFile(file),
859
+ method: inferHttpMethod(text),
860
+ filePath: file,
861
+ recommendedRecipe: "api-routes-to-actions",
862
+ });
863
+ }
864
+ if (/\b(useState|useReducer|localStorage|sessionStorage)\b/.test(text)) {
865
+ behavior.clientState.push({
866
+ id: stableId(`${file}:state`),
867
+ filePath: file,
868
+ reason: "Review for important UI state that should move into application_state.",
869
+ });
870
+ }
871
+ if (/\b(openai|anthropic|generateText|streamText|chat\.completions|messages\.create)\b/i.test(text)) {
872
+ behavior.llmCalls.push({
873
+ id: stableId(`${file}:llm`),
874
+ filePath: file,
875
+ provider: inferLlmProvider(text),
876
+ });
877
+ }
878
+ if (/\b(drizzle|prisma|postgres|supabase|mysql|sqlite|mongoose)\b/i.test(text)) {
879
+ behavior.dataStores.push({
880
+ id: stableId(`${file}:data`),
881
+ name: path.basename(file),
882
+ filePath: file,
883
+ kind: "database",
884
+ });
885
+ }
886
+ if (/\b(next-auth|better-auth|auth0|clerk|supabase\.auth)\b/i.test(text)) {
887
+ behavior.auth.push({
888
+ id: stableId(`${file}:auth`),
889
+ filePath: file,
890
+ provider: inferAuthProvider(text),
891
+ });
892
+ }
893
+ if (/\b(cron|schedule|queue|inngest|trigger\.dev|setInterval)\b/i.test(text)) {
894
+ behavior.jobs.push({
895
+ id: stableId(`${file}:job`),
896
+ filePath: file,
897
+ kind: "scheduled-or-queued",
898
+ });
899
+ }
900
+ }
901
+ return {
902
+ site: {
903
+ framework,
904
+ sourceRoot,
905
+ routes,
906
+ redirects: [],
907
+ metadata: {
908
+ routeCount: routes.length,
909
+ fileCount: files.length,
910
+ packageManager: detectPackageManager(sourceRoot),
911
+ },
912
+ },
913
+ components: {
914
+ components: files
915
+ .filter((file) => /(^|\/)(components|ui)\//.test(file) &&
916
+ /\.(ts|tsx|js|jsx)$/.test(file))
917
+ .sort()
918
+ .map((file) => ({
919
+ id: stableId(file),
920
+ name: componentName(file),
921
+ filePath: file,
922
+ usedByRoutes: [],
923
+ })),
924
+ designTokens: {},
925
+ },
926
+ content: {
927
+ models: [],
928
+ assets: files
929
+ .filter((file) => /\.(png|jpe?g|webp|gif|svg|avif|pdf|mp4|webm)$/i.test(file))
930
+ .sort()
931
+ .map((file) => ({
932
+ id: stableId(file),
933
+ path: file,
934
+ type: path.extname(file).slice(1).toLowerCase() || "unknown",
935
+ })),
936
+ },
937
+ behavior,
938
+ };
939
+ }
940
+ function renderLocalAssessment(source, ir) {
941
+ return `# Migration Assessment
942
+
943
+ Source type: \`${source.kind}\`
944
+ Source: \`${formatSourceForDisplay(source)}\`
945
+ ${source.description ? `Description: ${source.description}\n` : ""}
946
+ Target: \`${DEFAULT_TARGET}\`
947
+
948
+ ## Inventory
949
+
950
+ - Framework: ${ir.site.framework}
951
+ - Routes: ${ir.site.routes.length}
952
+ - Components: ${ir.components.components.length}
953
+ - API endpoints: ${ir.behavior.apiEndpoints.length}
954
+ - Data stores: ${ir.behavior.dataStores.length}
955
+ - LLM calls: ${ir.behavior.llmCalls.length}
956
+ - Client state hotspots: ${ir.behavior.clientState.length}
957
+ - Auth hotspots: ${ir.behavior.auth.length}
958
+ - Jobs: ${ir.behavior.jobs.length}
959
+ - Assets: ${ir.content.assets.length}
960
+
961
+ ## Routes
962
+
963
+ ${ir.site.routes.map((route) => `- \`${route.path}\` (${route.kind}) from \`${route.filePath}\``).join("\n") || "- No routes detected."}
964
+
965
+ ## Agent-Native Focus Areas
966
+
967
+ - Convert API routes and server mutations into actions unless they are uploads, webhooks, OAuth callbacks, or streams.
968
+ - Move app-owned state into SQL with Drizzle and expose reads/writes through actions.
969
+ - Delegate all AI work to the agent chat instead of calling model APIs directly from UI code.
970
+ - Expose important navigation and selection state through application_state.
971
+ - Keep public pages server-rendered and logged-in workflows inside the persistent app shell.
972
+ `;
973
+ }
974
+ function renderNonPathAssessment(source) {
975
+ return `# Migration Assessment
976
+
977
+ Source type: \`${source.kind}\`
978
+ Source: ${source.kind === "url" ? source.value : "provided description"}
979
+ ${source.description && source.kind !== "description" ? `Description: ${source.description}\n` : ""}
980
+ ${source.kind === "description" ? `Description: ${source.value}\n` : ""}
981
+ Target: \`${DEFAULT_TARGET}\`
982
+
983
+ ## Inventory
984
+
985
+ No local source path was provided, so this dossier does not include file-level IR. Use the URL or description as the intake brief, then let an Agent-Native Code or Desktop session inspect the real source before writing output.
986
+
987
+ ## Agent-Native Focus Areas
988
+
989
+ - Identify public pages, logged-in workflows, API endpoints, data ownership, auth, jobs, and direct LLM calls.
990
+ - Convert operations into actions and keep application data in SQL.
991
+ - Generate output outside the original source tree.
992
+ - Verify claims with deterministic checks or explicit human review notes.
993
+ `;
994
+ }
995
+ function renderDossierAgentsMd(source, templateAgents) {
996
+ return `# Migration Dossier Agent Instructions
997
+
998
+ You are migrating an existing application to agent-native.
999
+
1000
+ ## Source
1001
+
1002
+ - Type: ${source.kind}
1003
+ - Value: ${formatSourceForDisplay(source)}
1004
+ ${source.description ? `- Description: ${source.description}\n` : ""}
1005
+ ## Hard Rules
1006
+
1007
+ - Never write generated files inside the sourceRoot.
1008
+ - Treat source as read-only unless the user explicitly asks for source edits.
1009
+ - Put generated output in a separate directory.
1010
+ - Keep app-owned data in SQL, expose operations as actions, and route AI work through the agent chat.
1011
+ - Use 01-assessment.md and ir.json when present. If they are incomplete, update the assessment before implementation.
1012
+ - Record manual gaps and verification evidence. Do not present a migration as complete without checks.
1013
+
1014
+ ## Files In This Dossier
1015
+
1016
+ - \`MIGRATION_PLAYBOOK.md\` - ordered workflow for Agent-Native Code/Desktop.
1017
+ - \`01-assessment.md\` - initial source assessment.
1018
+ - \`ir.json\` - source inventory when available.
1019
+ - \`.agents/skills/migration*/SKILL.md\` - extra instruction packs when available from the migration goal surface.
1020
+
1021
+ ${templateAgents ? `## Migration Goal Surface Instructions\n\n${templateAgents.trim()}\n` : ""}
1022
+ `;
1023
+ }
1024
+ function renderMigrationPlaybook(source) {
1025
+ return `# Migration Playbook
1026
+
1027
+ ## 1. Intake Any Input
1028
+
1029
+ Start from the available input: a local source path, a URL, or a prose description. If this dossier has \`ir.json\`, use it as a first inventory. If not, inspect the real source before planning implementation.
1030
+
1031
+ Source: ${formatSourceForDisplay(source)}
1032
+
1033
+ ## 2. Build The Migration Map
1034
+
1035
+ Classify routes, public pages, logged-in app surfaces, API endpoints, data stores, auth, jobs, client state, assets, and direct LLM calls. Update \`01-assessment.md\` when you learn more.
1036
+
1037
+ ## 3. Apply Agent-Native Rules
1038
+
1039
+ - Actions are the single source of truth for operations.
1040
+ - Data lives in SQL through Drizzle.
1041
+ - AI work goes through the agent chat.
1042
+ - Important UI state is mirrored through \`application_state\`.
1043
+ - Public/SEO pages server-render; logged-in workflows use the persistent app shell.
1044
+ - Ownable resources use sharing and access helpers.
1045
+
1046
+ ## 4. Work In Samples
1047
+
1048
+ Migrate one representative route or workflow first. Verify it, tune the pattern, then sweep similar surfaces. Keep generated output outside the original source tree.
1049
+
1050
+ ## 5. Verify
1051
+
1052
+ Run typecheck/build plus route, action, and data checks that fit the migrated app. Capture unresolved gaps in a report before handing off.
1053
+
1054
+ ## 6. Use With Agent-Native Code Or Desktop
1055
+
1056
+ Point Codex, Claude Code, another code agent, or Agent-Native Desktop at this dossier directory. Ask it to follow \`AGENTS.md\`, then implement the plan in a separate output project.
1057
+ `;
1058
+ }
1059
+ function copyMigrationSkills(templateDir, dossierRoot) {
1060
+ if (!templateDir)
1061
+ return [];
1062
+ const skillsRoot = path.join(templateDir, ".agents", "skills");
1063
+ if (!fs.existsSync(skillsRoot))
1064
+ return [];
1065
+ const copied = [];
1066
+ for (const entry of fs.readdirSync(skillsRoot, { withFileTypes: true })) {
1067
+ if (!entry.isDirectory() || !entry.name.startsWith("migration"))
1068
+ continue;
1069
+ const src = path.join(skillsRoot, entry.name, "SKILL.md");
1070
+ if (!fs.existsSync(src))
1071
+ continue;
1072
+ const relative = path.join(".agents", "skills", entry.name, "SKILL.md");
1073
+ const dest = path.join(dossierRoot, relative);
1074
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
1075
+ fs.copyFileSync(src, dest);
1076
+ copied.push(relative);
1077
+ }
1078
+ return copied;
1079
+ }
1080
+ function findMigrationTemplateDir() {
1081
+ const starts = [__dirname, process.cwd()];
1082
+ for (const start of starts) {
1083
+ let dir = path.resolve(start);
1084
+ for (let i = 0; i < 12; i++) {
1085
+ for (const candidate of [
1086
+ path.join(dir, "templates", "migration"),
1087
+ path.join(dir, "src", "templates", "migration"),
1088
+ ]) {
1089
+ if (fs.existsSync(path.join(candidate, "AGENTS.md"))) {
1090
+ return candidate;
1091
+ }
1092
+ }
1093
+ const parent = path.dirname(dir);
1094
+ if (parent === dir)
1095
+ break;
1096
+ dir = parent;
1097
+ }
1098
+ }
1099
+ return undefined;
1100
+ }
1101
+ function resolveWorkbenchDir(opts) {
1102
+ if (opts.workbench)
1103
+ return path.resolve(process.cwd(), opts.workbench);
1104
+ return resolveScaffoldedAppDir(process.cwd(), opts.appName ?? DEFAULT_APP_NAME);
1105
+ }
72
1106
  function resolveScaffoldedAppDir(cwd, appName) {
73
1107
  const workspaceAppDir = path.join(cwd, "apps", appName);
74
1108
  if (fs.existsSync(workspaceAppDir))
75
1109
  return workspaceAppDir;
76
1110
  return path.join(cwd, appName);
77
1111
  }
1112
+ function sourceSeedPayload(source) {
1113
+ return {
1114
+ kind: source.kind,
1115
+ value: source.value,
1116
+ ...(source.sourceRoot ? { sourceRoot: source.sourceRoot } : {}),
1117
+ ...(source.description ? { description: source.description } : {}),
1118
+ };
1119
+ }
1120
+ function defaultRunName(source) {
1121
+ if (source.sourceRoot) {
1122
+ return `Migration from ${path.basename(source.sourceRoot)}`;
1123
+ }
1124
+ if (source.kind === "url") {
1125
+ return `Migration from ${source.value}`;
1126
+ }
1127
+ return "Migration from described source";
1128
+ }
1129
+ function stringMetadata(run, key) {
1130
+ const value = run.metadata?.[key];
1131
+ return typeof value === "string" ? value : undefined;
1132
+ }
1133
+ function formatSeedSource(seed) {
1134
+ if (!seed)
1135
+ return "not set";
1136
+ if (seed.sourceRoot)
1137
+ return seed.sourceRoot;
1138
+ if (seed.sourceUrl)
1139
+ return seed.sourceUrl;
1140
+ if (seed.sourceDescription)
1141
+ return seed.sourceDescription;
1142
+ return seed.sourceKind ?? "not set";
1143
+ }
1144
+ function readArtifactRuns(appDir) {
1145
+ const runsRoot = path.join(appDir, "data", "migration-runs");
1146
+ if (!fs.existsSync(runsRoot))
1147
+ return [];
1148
+ return fs
1149
+ .readdirSync(runsRoot, { withFileTypes: true })
1150
+ .filter((entry) => entry.isDirectory())
1151
+ .map((entry) => {
1152
+ const run = readJsonIfExists(path.join(runsRoot, entry.name, "run.json"));
1153
+ return {
1154
+ id: run?.id ?? entry.name,
1155
+ phase: run?.phase ?? "unknown",
1156
+ updatedAt: run?.updatedAt ?? "",
1157
+ };
1158
+ })
1159
+ .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
1160
+ }
1161
+ function credentialStatusLines() {
1162
+ const configured = MODEL_CREDENTIAL_ENV_NAMES.filter((key) => Boolean(process.env[key]));
1163
+ if (configured.length > 0) {
1164
+ return [
1165
+ `Headless credentials: detected ${configured.join(", ")} in this shell.`,
1166
+ "Secret values were not read or stored.",
1167
+ ];
1168
+ }
1169
+ return [
1170
+ `Headless credentials: none of ${MODEL_CREDENTIAL_ENV_NAMES.join(", ")} are set in this shell.`,
1171
+ "Set credentials in the Workbench app env or use Desktop/Agent-Native Code credentials; the migrate CLI will not store them.",
1172
+ ];
1173
+ }
1174
+ function walkSourceFiles(root) {
1175
+ const out = [];
1176
+ const ignored = new Set([
1177
+ ".git",
1178
+ ".next",
1179
+ ".turbo",
1180
+ "node_modules",
1181
+ "dist",
1182
+ "build",
1183
+ ".output",
1184
+ "coverage",
1185
+ ]);
1186
+ const visit = (dir) => {
1187
+ if (out.length > 5000)
1188
+ return;
1189
+ let entries;
1190
+ try {
1191
+ entries = fs.readdirSync(dir, { withFileTypes: true });
1192
+ }
1193
+ catch {
1194
+ return;
1195
+ }
1196
+ for (const entry of entries) {
1197
+ if (ignored.has(entry.name))
1198
+ continue;
1199
+ const absolute = path.join(dir, entry.name);
1200
+ if (entry.isDirectory()) {
1201
+ visit(absolute);
1202
+ }
1203
+ else if (entry.isFile()) {
1204
+ out.push(toPosix(path.relative(root, absolute)));
1205
+ }
1206
+ }
1207
+ };
1208
+ visit(root);
1209
+ return out.sort();
1210
+ }
1211
+ function routeFromFile(relativePath) {
1212
+ const normalized = toPosix(relativePath);
1213
+ const router = normalized.startsWith("app/") ? "next-app" : "next-pages";
1214
+ const isPageRoute = normalized.startsWith("pages/") &&
1215
+ /\.(ts|tsx|js|jsx|md|mdx)$/.test(normalized) &&
1216
+ !normalized.startsWith("pages/_app.") &&
1217
+ !normalized.startsWith("pages/_document.");
1218
+ const isAppRoute = normalized.startsWith("app/") &&
1219
+ /\/(page|route)\.(ts|tsx|js|jsx|md|mdx)$/.test(normalized);
1220
+ if (!isPageRoute && !isAppRoute)
1221
+ return null;
1222
+ const isApi = normalized.startsWith("pages/api/") ||
1223
+ /(^|\/)api\/.*\/route\.[tj]sx?$/.test(normalized) ||
1224
+ normalized.endsWith("/route.ts") ||
1225
+ normalized.endsWith("/route.tsx") ||
1226
+ normalized.endsWith("/route.js") ||
1227
+ normalized.endsWith("/route.jsx");
1228
+ let routePath = normalized;
1229
+ if (router === "next-app") {
1230
+ routePath = routePath
1231
+ .replace(/^app\//, "")
1232
+ .replace(/(^|\/)(page|route)\.(ts|tsx|js|jsx|md|mdx)$/, "");
1233
+ }
1234
+ else {
1235
+ routePath = routePath
1236
+ .replace(/^pages\//, "")
1237
+ .replace(/\.(ts|tsx|js|jsx|md|mdx)$/, "");
1238
+ }
1239
+ routePath = routePath
1240
+ .replace(/\/index$/, "")
1241
+ .replace(/^index$/, "")
1242
+ .replace(/^\(.*?\)\//, "")
1243
+ .replace(/\[(\.\.\.)?([^\]]+)\]/g, (_, dots, name) => dots ? `*${name}` : `:${name}`);
1244
+ const publicPath = routePath ? `/${routePath}` : "/";
1245
+ const pathValue = publicPath === "/api" && isApi ? "/api/*" : publicPath;
1246
+ const kind = isApi
1247
+ ? "api"
1248
+ : pathValue === "/"
1249
+ ? "landing"
1250
+ : pathValue.includes("docs")
1251
+ ? "docs"
1252
+ : pathValue.includes("pricing") || pathValue.includes("blog")
1253
+ ? "marketing"
1254
+ : "app";
1255
+ return {
1256
+ id: stableId(normalized),
1257
+ path: pathValue,
1258
+ filePath: normalized,
1259
+ router,
1260
+ kind,
1261
+ dynamic: pathValue.includes(":") || pathValue.includes("*"),
1262
+ public: kind !== "app" && kind !== "api",
1263
+ notes: isApi
1264
+ ? [
1265
+ "Convert to an action unless it uploads, streams, handles OAuth, or receives webhooks.",
1266
+ ]
1267
+ : [],
1268
+ };
1269
+ }
1270
+ function apiPathFromFile(file) {
1271
+ let value = file
1272
+ .replace(/^pages\/api\//, "/api/")
1273
+ .replace(/^app\//, "/")
1274
+ .replace(/\/route\.[tj]sx?$/, "")
1275
+ .replace(/\.[tj]sx?$/, "");
1276
+ value = value
1277
+ .replace(/\/index$/, "")
1278
+ .replace(/\[(\.\.\.)?([^\]]+)\]/g, (_, dots, name) => dots ? `*${name}` : `:${name}`);
1279
+ return value || "/api";
1280
+ }
1281
+ function inferHttpMethod(text) {
1282
+ const exported = text.match(/export\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)/);
1283
+ if (exported)
1284
+ return exported[1];
1285
+ const method = text.match(/method\s*[:=]\s*["'](GET|POST|PUT|PATCH|DELETE)["']/i);
1286
+ return method?.[1]?.toUpperCase() ?? "GET";
1287
+ }
1288
+ function inferLlmProvider(text) {
1289
+ if (/anthropic/i.test(text))
1290
+ return "anthropic";
1291
+ if (/openai/i.test(text))
1292
+ return "openai";
1293
+ return "unknown";
1294
+ }
1295
+ function inferAuthProvider(text) {
1296
+ if (/better-auth/i.test(text))
1297
+ return "better-auth";
1298
+ if (/next-auth/i.test(text))
1299
+ return "next-auth";
1300
+ if (/clerk/i.test(text))
1301
+ return "clerk";
1302
+ if (/auth0/i.test(text))
1303
+ return "auth0";
1304
+ if (/supabase\.auth/i.test(text))
1305
+ return "supabase";
1306
+ return "unknown";
1307
+ }
1308
+ function componentName(file) {
1309
+ const base = path.basename(file).replace(/\.(ts|tsx|js|jsx)$/, "");
1310
+ return base
1311
+ .split(/[-_]/g)
1312
+ .filter(Boolean)
1313
+ .map((part) => part[0]?.toUpperCase() + part.slice(1))
1314
+ .join("");
1315
+ }
1316
+ function detectPackageManager(sourceRoot) {
1317
+ if (fs.existsSync(path.join(sourceRoot, "pnpm-lock.yaml")))
1318
+ return "pnpm";
1319
+ if (fs.existsSync(path.join(sourceRoot, "yarn.lock")))
1320
+ return "yarn";
1321
+ if (fs.existsSync(path.join(sourceRoot, "package-lock.json")))
1322
+ return "npm";
1323
+ return "unknown";
1324
+ }
1325
+ function readSmallText(filePath) {
1326
+ try {
1327
+ const stat = fs.statSync(filePath);
1328
+ if (stat.size > 256_000)
1329
+ return null;
1330
+ return fs.readFileSync(filePath, "utf-8");
1331
+ }
1332
+ catch {
1333
+ return null;
1334
+ }
1335
+ }
1336
+ function readJsonIfExists(filePath) {
1337
+ try {
1338
+ return JSON.parse(fs.readFileSync(filePath, "utf-8"));
1339
+ }
1340
+ catch {
1341
+ return null;
1342
+ }
1343
+ }
1344
+ function readTextIfExists(filePath) {
1345
+ if (!filePath)
1346
+ return null;
1347
+ try {
1348
+ return fs.readFileSync(filePath, "utf-8");
1349
+ }
1350
+ catch {
1351
+ return null;
1352
+ }
1353
+ }
1354
+ function hasAnyFile(root, files) {
1355
+ return files.some((file) => fs.existsSync(path.join(root, file)));
1356
+ }
1357
+ function stableId(value) {
1358
+ return crypto.createHash("sha1").update(value).digest("hex").slice(0, 12);
1359
+ }
1360
+ function isProbablyUrl(value) {
1361
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
1362
+ }
1363
+ function formatSourceForDisplay(source) {
1364
+ if (source.sourceRoot)
1365
+ return source.sourceRoot;
1366
+ return source.value;
1367
+ }
1368
+ function formatSourceForCommand(source) {
1369
+ if (source.kind === "description") {
1370
+ return `--describe ${shellQuote(source.value)}`;
1371
+ }
1372
+ const base = shellQuote(source.value);
1373
+ if (source.description) {
1374
+ return `${base} --describe ${shellQuote(source.description)}`;
1375
+ }
1376
+ return base;
1377
+ }
1378
+ function shellQuote(value) {
1379
+ if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(value))
1380
+ return value;
1381
+ return JSON.stringify(value);
1382
+ }
1383
+ function toPosix(value) {
1384
+ return value.split(path.sep).join("/");
1385
+ }
78
1386
  //# sourceMappingURL=migrate.js.map