@readmagic/workmate 0.0.27 → 0.0.29

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 (255) hide show
  1. package/dist/chunks/{AddWorkspaceDirectory-DqlPtsVK.js → AddWorkspaceDirectory-C0lrhffT.js} +1 -1
  2. package/dist/chunks/AgentsMdExternalIncludesDialog-DIahWLha.js +1 -0
  3. package/dist/chunks/{AgentsMdExternalIncludesDialog-rJS5l6yk.js → AgentsMdExternalIncludesDialog-Dmjjx4ql.js} +1 -1
  4. package/dist/chunks/App-COz7knHS.js +1 -0
  5. package/dist/chunks/{BackgroundTasksDialog-CBhSmdz_.js → BackgroundTasksDialog-5IkCQ8lN.js} +2 -2
  6. package/dist/chunks/{BypassPermissionsModeDialog-zz-lnmJt.js → BypassPermissionsModeDialog-g1FMGfQF.js} +1 -1
  7. package/dist/chunks/{CustomSelect-CYmc4vRh.js → CustomSelect-BsEd2To5.js} +1 -1
  8. package/dist/chunks/{DiffDialog-CTUIAcEE.js → DiffDialog-Cwf8CdxZ.js} +5 -5
  9. package/dist/chunks/Doctor-CcLoI7tF.js +1 -0
  10. package/dist/chunks/Doctor-GmT5aeAc.js +3 -0
  11. package/dist/chunks/ExitFlow-DPgUFqeC.js +2 -0
  12. package/dist/chunks/{InvalidConfigDialog-B-9Z58oD.js → InvalidConfigDialog-Di6HZYDV.js} +1 -1
  13. package/dist/chunks/{InvalidSettingsDialog-B4EWjbp7.js → InvalidSettingsDialog-BHL-MERJ.js} +1 -1
  14. package/dist/chunks/{KeybindingProviderSetup-Dzg77_Xn.js → KeybindingProviderSetup-eE3o0bfp.js} +1 -1
  15. package/dist/chunks/MCPConnectionManager-D-qpUJLV.js +1 -0
  16. package/dist/chunks/MCPToolListView-DtHRw4jQ.js +1 -0
  17. package/dist/chunks/{McpParsingWarnings-Dj_Fu5o-.js → McpParsingWarnings-ByyErvR3.js} +1 -1
  18. package/dist/chunks/MessageSelector-CFz30wBL.js +3 -0
  19. package/dist/chunks/Messages-CfY-Oj3M.js +10 -0
  20. package/dist/chunks/{Onboarding-BRSXxc2E.js → Onboarding-BfWLRx3n.js} +1 -1
  21. package/dist/chunks/{PromptInputFooterSuggestions-ChpyD9B7.js → PromptInputFooterSuggestions-BRyJj7XR.js} +1 -1
  22. package/dist/chunks/{PromptInputHelpMenu-CrTT8MKE.js → PromptInputHelpMenu-DLuRCXVS.js} +1 -1
  23. package/dist/chunks/{ProviderSetup-BEV95bnz.js → ProviderSetup-CKZGG2B9.js} +1 -1
  24. package/dist/chunks/QueryEngine-B27MOtBA.js +1 -0
  25. package/dist/chunks/{REPL-BDnZnm__.js → REPL-DMRD5wSN.js} +23 -23
  26. package/dist/chunks/REPL-gzolQvzu.js +1 -0
  27. package/dist/chunks/ResumeConversation-7eURPHmQ.js +1 -0
  28. package/dist/chunks/SearchExtraToolsTool-BINZTstr.js +1 -0
  29. package/dist/chunks/Settings-4TNYpfUs.js +2 -0
  30. package/dist/chunks/Spinner-BgjmQLjw.js +1 -0
  31. package/dist/chunks/{TextInput-ZKU-x_FD.js → TextInput-BVEWdRz9.js} +5 -5
  32. package/dist/chunks/{ThemePicker-B69oDgXN.js → ThemePicker-th2jdUjh.js} +1 -1
  33. package/dist/chunks/{TrustDialog-BSG8Ibh8.js → TrustDialog-YsYqHyRR.js} +1 -1
  34. package/dist/chunks/{ValidationErrorsList-BUYHEft4.js → ValidationErrorsList-CKeHoN2Z.js} +1 -1
  35. package/dist/chunks/{_baseEach-P0u1zIx6.js → _baseEach-Bz5fQbIq.js} +1 -1
  36. package/dist/chunks/{add-dir-C8RmmyQK.js → add-dir-BsO6l8Ue.js} +1 -1
  37. package/dist/chunks/{agentDisplay-np7CH47m.js → agentDisplay-ChkgiTIH.js} +1 -1
  38. package/dist/chunks/{agents-DedoH0Q4.js → agents-BV1nan6b.js} +6 -6
  39. package/dist/chunks/{agents-DRQlR5M1.js → agents-DqEB6iwV.js} +1 -1
  40. package/dist/chunks/allErrors-CkdguCDv.js +1 -0
  41. package/dist/chunks/{appleTerminalBackup-Bemd4RXh.js → appleTerminalBackup-CN8kS74J.js} +1 -1
  42. package/dist/chunks/{backgroundHousekeeping-BtEJ6TeC.js → backgroundHousekeeping-1VsWy8xd.js} +1 -1
  43. package/dist/chunks/backgroundHousekeeping-pMtrl4K2.js +1 -0
  44. package/dist/chunks/{banner-CuoceXzz.js → banner-BKOzHotb.js} +1 -1
  45. package/dist/chunks/{branch-ClhlS7f8.js → branch-CTIHtpwz.js} +2 -2
  46. package/dist/chunks/bridgeControl-C8xaGuwO.js +2 -0
  47. package/dist/chunks/{btw-B-FLxlx-.js → btw-BA39Zrhm.js} +1 -1
  48. package/dist/chunks/caches-DHZHqVhf.js +1 -0
  49. package/dist/chunks/caches-fqs-Y-kW.js +1 -0
  50. package/dist/chunks/channel-B5FkNSZ3.js +1 -0
  51. package/dist/chunks/channel-C5yKM1wf.js +1 -0
  52. package/dist/chunks/{clear-BnWv0i65.js → clear-BmlaYYrD.js} +1 -1
  53. package/dist/chunks/commands-EUcHifS4.js +1 -0
  54. package/dist/chunks/compact-D3uePeI7.js +2 -0
  55. package/dist/chunks/{config-BDn2YIjC.js → config-Bio2EjUK.js} +1 -1
  56. package/dist/chunks/config-C_AEhZrn.js +1 -0
  57. package/dist/chunks/config-GgGdlJ9h.js +1 -0
  58. package/dist/chunks/{context-BvDBAyJ9.js → context-CBEWyVpE.js} +1 -1
  59. package/dist/chunks/{context-noninteractive-CuHHniJn.js → context-noninteractive-B03nuxfN.js} +2 -2
  60. package/dist/chunks/context-noninteractive-BLCyyyGL.js +1 -0
  61. package/dist/chunks/conversation-BFL0rEIx.js +1 -0
  62. package/dist/chunks/conversation-D-ker4RO.js +1 -0
  63. package/dist/chunks/{conversationRecovery-NL05oJb1.js → conversationRecovery-Bt84CYO6.js} +1 -1
  64. package/dist/chunks/crossProjectResume-DwlYY6lV.js +40 -0
  65. package/dist/chunks/{diff--6gQCx_x.js → diff-CewYzu3Y.js} +1 -1
  66. package/dist/chunks/doctor-CrQ0UfG2.js +1 -0
  67. package/dist/chunks/{entry-DWYOrkFS.js → entry-DdVUdGWV.js} +3 -3
  68. package/dist/chunks/exit-QwCo2aJo.js +1 -0
  69. package/dist/chunks/{extraUsage-Dr0YXm1w.js → extraUsage-Cu0aV35i.js} +1 -1
  70. package/dist/chunks/extractMemories-DHlbRc5g.js +1 -0
  71. package/dist/chunks/{fast-C5-lNCQi.js → fast-BlhpCQ2f.js} +1 -1
  72. package/dist/chunks/fast-C3JeBy3A.js +1 -0
  73. package/dist/chunks/{fetchModelList-9w1E4Ue8.js → fetchModelList-DjFCMjVN.js} +1 -1
  74. package/dist/chunks/fetchModelList-L2XarfAj.js +1 -0
  75. package/dist/chunks/{fileSuggestions-BYD78vcF.js → fileSuggestions-BRwKV_KA.js} +2 -2
  76. package/dist/chunks/{gemini-BNBptTET.js → gemini-I-M5_sUA.js} +2 -2
  77. package/dist/chunks/{generateSessionName-CO2484aJ.js → generateSessionName-CJ0sh6HD.js} +1 -1
  78. package/dist/chunks/{goal-j0wdadwM.js → goal-DIrBBT5J.js} +3 -3
  79. package/dist/chunks/{grok-BpO1ZwK_.js → grok-ZLjJN6b9.js} +1 -1
  80. package/dist/chunks/{help-DwhA0qQ6.js → help-CDMjVOl6.js} +1 -1
  81. package/dist/chunks/{hooks-DG4_WdZ2.js → hooks-BNKCE023.js} +2 -2
  82. package/dist/chunks/hooks-ERYtmuNW.js +1 -0
  83. package/dist/chunks/{install-BbmCNCuM.js → install-xlfTw1j6.js} +1 -1
  84. package/dist/chunks/{instrumentation-DpPmDyNF.js → instrumentation-DSt0UvGn.js} +3 -3
  85. package/dist/chunks/{job-GcmX1ALd.js → job-BVElGsu0.js} +1 -1
  86. package/dist/chunks/{launchLocalMemory-CDgT5lst.js → launchLocalMemory-DUkJCKmd.js} +2 -2
  87. package/dist/chunks/{launchOnboarding-uQ_ux9sS.js → launchOnboarding-BvD-E_jC.js} +1 -1
  88. package/dist/chunks/loadAgentsDir-BImZsKrh.js +1 -0
  89. package/dist/chunks/{loadAgentsDir-uuZYOgKn.js → loadAgentsDir-BfLCckVj.js} +343 -343
  90. package/dist/chunks/loadPluginHooks-BPwWtBzO.js +1 -0
  91. package/dist/chunks/{localSearch-yVCDrVrf.js → localSearch-BHG8sp8p.js} +1 -1
  92. package/dist/chunks/localSearch-D3rvcRRC.js +1 -0
  93. package/dist/chunks/{logoUtils-B4wCDKs9.js → logoUtils-BsNLv-qi.js} +1 -1
  94. package/dist/chunks/{magicDocs-D53lV8b5.js → magicDocs-Bue9vxzY.js} +2 -2
  95. package/dist/chunks/{main-fy_XSXGj.js → main-U71X4Thd.js} +22 -22
  96. package/dist/chunks/managedEnv-DCGLDTP_.js +1 -0
  97. package/dist/chunks/{managedEnv-B8YWmM4A.js → managedEnv-EZ2IirNa.js} +1 -1
  98. package/dist/chunks/{mcp-CZUVaPb3.js → mcp-C4CxCMwJ.js} +3 -3
  99. package/dist/chunks/mcp-D9HFARDy.js +1 -0
  100. package/dist/chunks/mcp-De3QGKvT.js +2 -0
  101. package/dist/chunks/memory-DVRdJFfI.js +1 -0
  102. package/dist/chunks/{mode-Bteqe2QG.js → mode-Bd5w-RBX.js} +2 -2
  103. package/dist/chunks/{model-CHDU5yqH.js → model-BCIcUhrc.js} +1 -1
  104. package/dist/chunks/{model-CcHyMyBv.js → model-BIf2i1is.js} +1 -1
  105. package/dist/chunks/{modelOptions-CJV1R3Jt.js → modelOptions-COIU5U3w.js} +1 -1
  106. package/dist/chunks/{nativeInstaller-CIUYh1aD.js → nativeInstaller-CGSNzGNn.js} +1 -1
  107. package/dist/chunks/{notifications-GLnjirCl.js → notifications-B5gzCmPC.js} +1 -1
  108. package/dist/chunks/{onChangeAppState-CxGW2d-l.js → onChangeAppState-NWwSE-I4.js} +1 -1
  109. package/dist/chunks/{openai-BpGQT2Iv.js → openai-CyJ3m4dI.js} +2 -2
  110. package/dist/chunks/{overlayContext-7wgLio1O.js → overlayContext-DYrGDe63.js} +1 -1
  111. package/dist/chunks/{partition-djFY9gGI.js → partition-BavNaw1S.js} +1 -1
  112. package/dist/chunks/permissions-CLYcBXIu.js +3 -0
  113. package/dist/chunks/{pidLock-CFUBtZck.js → pidLock-Bao7SU6Z.js} +2 -2
  114. package/dist/chunks/{plan-DI0n7LIV.js → plan-Dwj_ZX8G.js} +1 -1
  115. package/dist/chunks/plugin-Cscvf8st.js +17 -0
  116. package/dist/chunks/{pluginAutoupdate-CNrHb4RJ.js → pluginAutoupdate-D5XyiZrP.js} +1 -1
  117. package/dist/chunks/pluginBlocklist-CpkjXXKQ.js +1 -0
  118. package/dist/chunks/pluginCliCommands-DmLsxs1M.js +1 -0
  119. package/dist/chunks/{pluginFlagging-CUvkKGOB.js → pluginFlagging-CRuX6sHR.js} +1 -1
  120. package/dist/chunks/pluginOperations-orq3bOCp.js +2 -0
  121. package/dist/chunks/{pluginStartupCheck-DftTiXct.js → pluginStartupCheck-DGDl1WOZ.js} +1 -1
  122. package/dist/chunks/pluginStartupCheck-GHO77nmg.js +1 -0
  123. package/dist/chunks/plugins-Cq5c-Qs1.js +4 -0
  124. package/dist/chunks/{print-DSHypGJa.js → print-zo7Z--Ll.js} +9 -9
  125. package/dist/chunks/processBashCommand-C7oVqf0B.js +1 -0
  126. package/dist/chunks/processSlashCommand-CPQB5_0w.js +5 -0
  127. package/dist/chunks/{projectOnboardingState-nTCycGCD.js → projectOnboardingState-D-_ijZnG.js} +1 -1
  128. package/dist/chunks/prompt-CAzFDybL.js +1 -0
  129. package/dist/chunks/prompt-Cm8SKZXY.js +1 -0
  130. package/dist/chunks/{prompt-BfXryFt-.js → prompt-DaYH88Oe.js} +1 -1
  131. package/dist/chunks/{protocolHandler-VigBkAQQ.js → protocolHandler-CJO3CRYW.js} +1 -1
  132. package/dist/chunks/{reconciler-B9XFdL4f.js → reconciler-B5Kr4do0.js} +1 -1
  133. package/dist/chunks/refresh-DurNMJeS.js +1 -0
  134. package/dist/chunks/{reject-CBxnwckZ.js → reject-CzjtO3fU.js} +1 -1
  135. package/dist/chunks/{reload-plugins-5eFWrQlL.js → reload-plugins-C38i_Eb3.js} +1 -1
  136. package/dist/chunks/rename-BV-3ZpFx.js +1 -0
  137. package/dist/chunks/{resume-U2D0ybfU.js → resume-CUzQIor4.js} +2 -2
  138. package/dist/chunks/{runtimeObserver-CWaYMJG8.js → runtimeObserver-BKoQ5IEO.js} +4 -4
  139. package/dist/chunks/{runtimeObserver-DOYlxx9H.js → runtimeObserver-Ess1Cn8Y.js} +1 -1
  140. package/dist/chunks/sandbox-adapter-ClRO21Ci.js +1 -0
  141. package/dist/chunks/{sandbox-toggle-BtiPyjT3.js → sandbox-toggle-Bp6Xpjh3.js} +1 -1
  142. package/dist/chunks/searchExtraTools-CV_fkuD6.js +1 -0
  143. package/dist/chunks/{select-BuTJbu_Q.js → select-Bm29ymsI.js} +1 -1
  144. package/dist/chunks/sessionFileAccessHooks-B5kAD4ol.js +1 -0
  145. package/dist/chunks/{sessionObserver-cfwD8pV8.js → sessionObserver-CBlzrJt1.js} +1 -1
  146. package/dist/chunks/sessionObserver-CayxkuxO.js +1 -0
  147. package/dist/chunks/sessionStorage-vLxCo1Mh.js +1 -0
  148. package/dist/chunks/{sessionTracing-DsdcOqvc.js → sessionTracing-TDsq54Uc.js} +1 -1
  149. package/dist/chunks/setup-BbyfyeQk.js +3 -0
  150. package/dist/chunks/{shadowedRuleDetection-DiZUDzxU.js → shadowedRuleDetection-BG3jtA9Y.js} +1 -1
  151. package/dist/chunks/{sideQuestion-CdgUarC2.js → sideQuestion-C8GNVo4R.js} +3 -3
  152. package/dist/chunks/{sinks-Cy3NqVbk.js → sinks-BafJR6Fw.js} +1 -1
  153. package/dist/chunks/sinks-CHtjg7sn.js +1 -0
  154. package/dist/chunks/skillChangeDetector-CY17weG4.js +1 -0
  155. package/dist/chunks/{skillGapStore-BJV8ZIB1.js → skillGapStore-Cl4J1WoZ.js} +2 -2
  156. package/dist/chunks/{skillLifecycle-iO_3s9Ff.js → skillLifecycle-DdfeUHBf.js} +2 -2
  157. package/dist/chunks/{skillSearchPanel-BL5gXTHU.js → skillSearchPanel-DtQYF9gN.js} +4 -4
  158. package/dist/chunks/{skills-BEp3_RyT.js → skills-Fd12LJal.js} +1 -1
  159. package/dist/chunks/status-CGEMRiPI.js +1 -0
  160. package/dist/chunks/statusNoticeHelpers-D0tonVy0.js +1 -0
  161. package/dist/chunks/{switcher-DSt2cVjA.js → switcher-BCq9Az_q.js} +1 -1
  162. package/dist/chunks/switcher-DQMr6Anx.js +1 -0
  163. package/dist/chunks/{tasks-DyBUXnQb.js → tasks-DQmkY_xD.js} +1 -1
  164. package/dist/chunks/{templateJobs-BBnReWWj.js → templateJobs-CEDUbFAY.js} +1 -1
  165. package/dist/chunks/{terminalSetup-CDpFfqqV.js → terminalSetup-CaGbEVjB.js} +1 -1
  166. package/dist/chunks/{terminalSetup-DedaY1P7.js → terminalSetup-xe_P98fY.js} +1 -1
  167. package/dist/chunks/{theme-BZOy9Iqh.js → theme-DQjJ4R0o.js} +1 -1
  168. package/dist/chunks/tipRegistry-BwxZ_G0j.js +2 -0
  169. package/dist/chunks/{toolEventObserver-ClwWmVbH.js → toolEventObserver-DdZ30on9.js} +1 -1
  170. package/dist/chunks/toolPool-CWIXwdX7.js +1 -0
  171. package/dist/chunks/{useExitOnCtrlCDWithKeybindings-ClN4NJnB.js → useExitOnCtrlCDWithKeybindings-ClrtNKJ6.js} +1 -1
  172. package/dist/chunks/useMainLoopModel-CULw8pB_.js +1 -0
  173. package/dist/chunks/{useManagePlugins-CxHz-gUP.js → useManagePlugins-CmsPSHor.js} +1 -1
  174. package/dist/chunks/useMergedTools-C8PxReh0.js +1 -0
  175. package/dist/chunks/{useSearchInput-BIQN_-Hm.js → useSearchInput-BZhTzjgN.js} +1 -1
  176. package/dist/chunks/useSettingsErrors-GWIxCYyd.js +1 -0
  177. package/dist/chunks/{util-BHr5l6Bx.js → util-Bih2g-pV.js} +1 -1
  178. package/dist/chunks/validatePlugin-BwcC_Wbr.js +1 -0
  179. package/dist/chunks/{vim-CYjMtnwH.js → vim-BlO9V5_5.js} +1 -1
  180. package/dist/chunks/worktree-BB9lFWBB.js +1 -0
  181. package/dist/chunks/wrapper-B-Q3Illb.js +1 -0
  182. package/dist/chunks/{wrapper-K8ZapJVu.js → wrapper-DVKxC5fR.js} +1 -1
  183. package/dist/cli.js +1 -1
  184. package/package.json +2 -1
  185. package/dist/chunks/AgentsMdExternalIncludesDialog-CgSethgo.js +0 -1
  186. package/dist/chunks/App-DzRQpRKr.js +0 -1
  187. package/dist/chunks/Doctor-CLOYkPRR.js +0 -3
  188. package/dist/chunks/Doctor-CiZNe_qx.js +0 -1
  189. package/dist/chunks/ExitFlow-CATwJC4c.js +0 -2
  190. package/dist/chunks/MCPConnectionManager-CBY8nqdU.js +0 -1
  191. package/dist/chunks/MCPToolListView-C7HT6rrl.js +0 -1
  192. package/dist/chunks/MessageSelector-Dw_ERK_Z.js +0 -3
  193. package/dist/chunks/Messages-RBfRELKn.js +0 -10
  194. package/dist/chunks/QueryEngine-BBBkZWu2.js +0 -1
  195. package/dist/chunks/REPL-BHk0vZDf.js +0 -1
  196. package/dist/chunks/ResumeConversation-BuSqBrm1.js +0 -1
  197. package/dist/chunks/SearchExtraToolsTool-CdWB9sO8.js +0 -1
  198. package/dist/chunks/Settings-DYKmPdbd.js +0 -2
  199. package/dist/chunks/Spinner-DOI8qqZi.js +0 -1
  200. package/dist/chunks/allErrors-DvcU0w0F.js +0 -1
  201. package/dist/chunks/backgroundHousekeeping-B56nFTzq.js +0 -1
  202. package/dist/chunks/caches-D7arwhaa.js +0 -1
  203. package/dist/chunks/caches-Dn8yrJmL.js +0 -1
  204. package/dist/chunks/commands-AcfFLgl5.js +0 -1
  205. package/dist/chunks/compact-Banc-SNk.js +0 -2
  206. package/dist/chunks/config-BhBcadjZ.js +0 -1
  207. package/dist/chunks/config-Bm5pVdCq.js +0 -1
  208. package/dist/chunks/context-noninteractive-BK2IDLSS.js +0 -1
  209. package/dist/chunks/conversation-B2dX3X4Z.js +0 -1
  210. package/dist/chunks/conversation-Cjaftrrw.js +0 -1
  211. package/dist/chunks/crossProjectResume-BzltC4NJ.js +0 -40
  212. package/dist/chunks/doctor-CQf8xPZH.js +0 -1
  213. package/dist/chunks/exit-uKtXb5U3.js +0 -1
  214. package/dist/chunks/extractMemories-8yvMGZ1J.js +0 -1
  215. package/dist/chunks/fast-aNkj6WvB.js +0 -1
  216. package/dist/chunks/fetchModelList-D2quBF6M.js +0 -1
  217. package/dist/chunks/hooks-B5Wq-KxE.js +0 -1
  218. package/dist/chunks/loadAgentsDir-BBbIAiay.js +0 -1
  219. package/dist/chunks/loadPluginHooks-QoVXsBjy.js +0 -1
  220. package/dist/chunks/localSearch-D6MhwvnR.js +0 -1
  221. package/dist/chunks/managedEnv-ulQBH73B.js +0 -1
  222. package/dist/chunks/mcp--LmEVBRg.js +0 -1
  223. package/dist/chunks/mcp-DCl-Tz-C.js +0 -2
  224. package/dist/chunks/memory-Bu5ku7y9.js +0 -1
  225. package/dist/chunks/permissions-DNedQyLg.js +0 -3
  226. package/dist/chunks/plugin-BQ8gRVYF.js +0 -17
  227. package/dist/chunks/pluginBlocklist-CKCsgWdY.js +0 -1
  228. package/dist/chunks/pluginCliCommands-CACeyIwz.js +0 -1
  229. package/dist/chunks/pluginOperations-Ca_T-HYn.js +0 -2
  230. package/dist/chunks/pluginStartupCheck-Du9yx2P8.js +0 -1
  231. package/dist/chunks/plugins-Divl-P-X.js +0 -4
  232. package/dist/chunks/processBashCommand-BLcFmbyG.js +0 -1
  233. package/dist/chunks/processSlashCommand-Caif46Gi.js +0 -5
  234. package/dist/chunks/prompt-BZmu5CeK.js +0 -1
  235. package/dist/chunks/prompt-Cogr_WZr.js +0 -1
  236. package/dist/chunks/refresh-CBHbWTGg.js +0 -1
  237. package/dist/chunks/rename-Cw7cMerG.js +0 -1
  238. package/dist/chunks/sandbox-adapter-Df7Wpt77.js +0 -1
  239. package/dist/chunks/searchExtraTools-CbJVb_Zk.js +0 -1
  240. package/dist/chunks/sessionFileAccessHooks-_mxyfQmn.js +0 -1
  241. package/dist/chunks/sessionObserver-BZVgzp3W.js +0 -1
  242. package/dist/chunks/sessionStorage-SC5RfnUP.js +0 -1
  243. package/dist/chunks/setup-DR-KEmxL.js +0 -3
  244. package/dist/chunks/sinks-D41OiGE4.js +0 -1
  245. package/dist/chunks/skillChangeDetector-CVFCJcG7.js +0 -1
  246. package/dist/chunks/status-6JMz8jmM.js +0 -1
  247. package/dist/chunks/statusNoticeHelpers-BoloSeXY.js +0 -1
  248. package/dist/chunks/switcher-95d4TrQH.js +0 -1
  249. package/dist/chunks/tipRegistry-Cl5sdLRX.js +0 -2
  250. package/dist/chunks/toolPool-DSTbgGmX.js +0 -1
  251. package/dist/chunks/useMainLoopModel-Bgxpmn2Q.js +0 -1
  252. package/dist/chunks/useMergedTools-BUuWew0-.js +0 -1
  253. package/dist/chunks/useSettingsErrors-BDJCLei_.js +0 -1
  254. package/dist/chunks/validatePlugin-fx1Y8vam.js +0 -1
  255. package/dist/chunks/worktree-CGu_58ue.js +0 -1
@@ -1,12 +1,12 @@
1
- import{n as e,o as t}from"./rolldown-runtime-DaDcL9Zw.js";import{i as n,o as r}from"./envUtils-QyzA_cFM.js";import{n as i,t as a}from"./figures-5ThXQEtq.js";import{C as o,D as s,I as c,P as l,T as u,Wt as d,ai as f,di as p,fi as m,t as h,y as g}from"./src-BX54x08P.js";import{t as _}from"./jsx-runtime-Bb4Xn-E0.js";import{$n as v,K as y,Qn as b,X as x,fn as ee,mn as S,nt as te,rn as C,rt as ne,tn as re}from"./settings-D4M13toi.js";import{hr as ie,mr as ae}from"./state-CXY-q5gr.js";import{$d as oe,$x as se,Ap as ce,Au as le,Bh as ue,Bv as de,By as fe,Cf as pe,Cp as me,Dc as he,Dl as ge,Dp as _e,Ec as ve,Ef as ye,El as be,Em as xe,F_ as Se,GS as Ce,Hh as we,I_ as Te,Ji as Ee,Mm as De,Mu as Oe,Nm as ke,Nu as Ae,Op as je,Pm as Me,Q as Ne,Rl as Pe,Rm as Fe,Sp as Ie,Tf as Le,Tl as Re,Tm as ze,X as Be,_m as Ve,_p as He,bp as Ue,c as We,dd as Ge,ef as Ke,et as qe,fw as Je,gm as Ye,gp as Xe,hd as w,jm as Ze,ju as Qe,l as $e,ld as et,md as T,mw as tt,nt,o as rt,pw as it,r as at,s as ot,t as st,tb as E,ty as ct,ua as lt,vp as ut,wf as dt,wl as ft,xp as pt,yp as mt,zh as ht,zl as gt,zm as _t,zv as vt,zy as yt}from"./loadAgentsDir-uuZYOgKn.js";import{n as bt,t as xt}from"./cwd-DrEEb4f5.js";import{H as St,I as Ct,N as wt,S as Tt,V as Et,Y as Dt,x as Ot}from"./debug-2pVES-2G.js";import{C as kt,T as At}from"./config-BDn2YIjC.js";import{o as jt,s as Mt}from"./log-L1kqxa_P.js";import{n as Nt}from"./analytics-COpjZpvd.js";import{S as Pt,_ as Ft}from"./startupProfiler-B9Qv2QGH.js";import{l as It,n as Lt,o as Rt}from"./stringUtils-Cs6E5f-B.js";import{_n as zt,vn as Bt}from"./prompt-BfXryFt-.js";import{n as Vt,t as Ht}from"./_baseSlice-D67_NpZ1.js";import{a as Ut,i as Wt,n as Gt,o as Kt,r as qt,t as Jt}from"./agentDisplay-np7CH47m.js";import{n as Yt,t as Xt}from"./useExitOnCtrlCDWithKeybindings-ClN4NJnB.js";import{n as Zt,t as Qt}from"./TextInput-ZKU-x_FD.js";import{n as $t,t as en}from"./select-BuTJbu_Q.js";import{r as tn,t as nn}from"./Spinner-DOI8qqZi.js";import{n as rn,t as an}from"./useMergedTools-BUuWew0-.js";import{n as on,r as sn,t as cn}from"./promptEditor-14TB3MYt.js";import{n as ln,t as un}from"./useMainLoopModel-Bgxpmn2Q.js";import{join as D}from"path";import{mkdir as dn,open as fn,unlink as pn}from"fs/promises";function mn(e,t,n){var r=e.length;return n=n===void 0?r:n,!t&&n>=r?e:Ht(e,t,n)}var hn=e((()=>{Vt()}));function gn(e){return _n.test(e)}var _n,vn=e((()=>{_n=RegExp(`[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]`)}));function yn(e){return e.split(``)}var bn=e((()=>{}));function xn(e){return e.match(Rn)||[]}var Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn=e((()=>{Sn=`\\ud800-\\udfff`,Cn=`\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff`,wn=`\\ufe0e\\ufe0f`,Tn=`[`+Sn+`]`,En=`[`+Cn+`]`,Dn=`\\ud83c[\\udffb-\\udfff]`,On=`(?:`+En+`|`+Dn+`)`,kn=`[^`+Sn+`]`,An=`(?:\\ud83c[\\udde6-\\uddff]){2}`,jn=`[\\ud800-\\udbff][\\udc00-\\udfff]`,Mn=`\\u200d`,Nn=On+`?`,Pn=`[`+wn+`]?`,Fn=`(?:`+Mn+`(?:`+[kn,An,jn].join(`|`)+`)`+Pn+Nn+`)*`,In=Pn+Nn+Fn,Ln=`(?:`+[kn+En+`?`,En,An,jn,Tn].join(`|`)+`)`,Rn=RegExp(Dn+`(?=`+Dn+`)|`+Ln+In,`g`)}));function Bn(e){return gn(e)?xn(e):yn(e)}var Vn=e((()=>{bn(),vn(),zn()}));function Hn(e){return function(t){t=ie(t);var n=gn(t)?Bn(t):void 0,r=n?n[0]:t.charAt(0),i=n?mn(n,1).join(``):t.slice(1);return r[e]()+i}}var Un=e((()=>{hn(),vn(),Vn(),ae()})),Wn,Gn=e((()=>{Un(),Wn=Hn(`toUpperCase`)}));function Kn(e){return Wn(ie(e).toLowerCase())}var qn=e((()=>{ae(),Gn()})),O,Jn=e((()=>{O={FOLDER_NAME:`.workmate`,AGENTS_DIR:`agents`}}));function Yn(e,t,n,r,i,a,o){return`---
1
+ import{n as e,o as t}from"./rolldown-runtime-DaDcL9Zw.js";import{i as n,o as r}from"./envUtils-QyzA_cFM.js";import{n as i,t as a}from"./figures-5ThXQEtq.js";import{C as o,D as s,I as c,P as l,T as u,Wt as d,ai as f,di as p,fi as m,t as h,y as g}from"./src-BX54x08P.js";import{t as _}from"./jsx-runtime-Bb4Xn-E0.js";import{$n as v,K as y,Qn as b,X as x,fn as ee,mn as S,nt as te,rn as C,rt as ne,tn as re}from"./settings-D4M13toi.js";import{hr as ie,mr as ae}from"./state-CXY-q5gr.js";import{Ap as oe,Bl as se,Bm as ce,Cp as le,Df as ue,Dl as de,Dm as fe,Ef as pe,El as me,Fm as he,Fu as ge,Hh as _e,Hv as ve,Hy as ye,Im as be,L_ as xe,Mp as Se,Mu as Ce,Nm as we,Nu as Te,Oc as Ee,Of as De,Ol as Oe,Om as ke,Pm as Ae,Pu as je,Q as Me,R_ as Ne,Sp as Pe,Tf as Fe,Tp as Ie,Vh as Le,Vl as Re,Vm as ze,Vv as Be,Vy as Ve,Wh as He,Xi as Ue,_d as w,bp as We,c as Ge,dd as Ke,et as qe,fa as Je,gd as T,gw as Ye,hw as Xe,it as Ze,kc as Qe,kl as $e,kp as et,l as tt,mw as nt,nf as rt,nt as it,o as at,pd as ot,qS as st,r as ct,rb as E,ry as lt,s as ut,t as dt,tS as ft,tf as pt,vm as mt,vp as ht,wp as gt,xp as _t,ym as vt,yp as yt}from"./loadAgentsDir-BfLCckVj.js";import{n as bt,t as xt}from"./cwd-DrEEb4f5.js";import{H as St,I as Ct,N as wt,S as Tt,V as Et,Y as Dt,x as Ot}from"./debug-2pVES-2G.js";import{C as kt,T as At}from"./config-Bio2EjUK.js";import{o as jt,s as Mt}from"./log-L1kqxa_P.js";import{n as Nt}from"./analytics-COpjZpvd.js";import{S as Pt,_ as Ft}from"./startupProfiler-B9Qv2QGH.js";import{l as It,n as Lt,o as Rt}from"./stringUtils-Cs6E5f-B.js";import{_n as zt,vn as Bt}from"./prompt-DaYH88Oe.js";import{n as Vt,t as Ht}from"./_baseSlice-D67_NpZ1.js";import{a as Ut,i as Wt,n as Gt,o as Kt,r as qt,t as Jt}from"./agentDisplay-ChkgiTIH.js";import{n as Yt,t as Xt}from"./useExitOnCtrlCDWithKeybindings-ClrtNKJ6.js";import{n as Zt,t as Qt}from"./TextInput-BVEWdRz9.js";import{n as $t,t as en}from"./select-Bm29ymsI.js";import{r as tn,t as nn}from"./Spinner-BgjmQLjw.js";import{n as rn,t as an}from"./useMergedTools-C8PxReh0.js";import{n as on,r as sn,t as cn}from"./promptEditor-14TB3MYt.js";import{n as ln,t as un}from"./useMainLoopModel-CULw8pB_.js";import{join as D}from"path";import{mkdir as dn,open as fn,unlink as pn}from"fs/promises";function mn(e,t,n){var r=e.length;return n=n===void 0?r:n,!t&&n>=r?e:Ht(e,t,n)}var hn=e((()=>{Vt()}));function gn(e){return _n.test(e)}var _n,vn=e((()=>{_n=RegExp(`[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]`)}));function yn(e){return e.split(``)}var bn=e((()=>{}));function xn(e){return e.match(Rn)||[]}var Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn=e((()=>{Sn=`\\ud800-\\udfff`,Cn=`\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff`,wn=`\\ufe0e\\ufe0f`,Tn=`[`+Sn+`]`,En=`[`+Cn+`]`,Dn=`\\ud83c[\\udffb-\\udfff]`,On=`(?:`+En+`|`+Dn+`)`,kn=`[^`+Sn+`]`,An=`(?:\\ud83c[\\udde6-\\uddff]){2}`,jn=`[\\ud800-\\udbff][\\udc00-\\udfff]`,Mn=`\\u200d`,Nn=On+`?`,Pn=`[`+wn+`]?`,Fn=`(?:`+Mn+`(?:`+[kn,An,jn].join(`|`)+`)`+Pn+Nn+`)*`,In=Pn+Nn+Fn,Ln=`(?:`+[kn+En+`?`,En,An,jn,Tn].join(`|`)+`)`,Rn=RegExp(Dn+`(?=`+Dn+`)|`+Ln+In,`g`)}));function Bn(e){return gn(e)?xn(e):yn(e)}var Vn=e((()=>{bn(),vn(),zn()}));function Hn(e){return function(t){t=ie(t);var n=gn(t)?Bn(t):void 0,r=n?n[0]:t.charAt(0),i=n?mn(n,1).join(``):t.slice(1);return r[e]()+i}}var Un=e((()=>{hn(),vn(),Vn(),ae()})),Wn,Gn=e((()=>{Un(),Wn=Hn(`toUpperCase`)}));function Kn(e){return Wn(ie(e).toLowerCase())}var qn=e((()=>{ae(),Gn()})),O,Jn=e((()=>{O={FOLDER_NAME:`.workmate`,AGENTS_DIR:`agents`}}));function Yn(e,t,n,r,i,a,o){return`---
2
2
  name: ${e}
3
3
  description: "${t.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\\\n`)}"${n===void 0||n.length===1&&n[0]===`*`?``:`\ntools: ${n.join(`, `)}`}${a?`\nmodel: ${a}`:``}${i?`\ncolor: ${i}`:``}${o?`\nmemory: ${o}`:``}
4
4
  ---
5
5
 
6
6
  ${r}
7
- `}function Xn(e){switch(e){case`flagSettings`:throw Error(`Cannot get directory path for ${e} agents`);case`userSettings`:return D(n(),O.AGENTS_DIR);case`projectSettings`:return D(xt(),O.FOLDER_NAME,O.AGENTS_DIR);case`policySettings`:return D(re(),O.FOLDER_NAME,O.AGENTS_DIR);case`localSettings`:return D(xt(),O.FOLDER_NAME,O.AGENTS_DIR)}}function Zn(e){switch(e){case`projectSettings`:return D(`.`,O.FOLDER_NAME,O.AGENTS_DIR);default:return Xn(e)}}function Qn(e){return D(Xn(e.source),`${e.agentType}.md`)}function $n(e){if(e.source===`built-in`)return`Built-in`;if(e.source===`plugin`)throw Error(`Cannot get file path for plugin agents`);return D(Xn(e.source),`${e.filename||e.agentType}.md`)}function er(e){return e.source===`built-in`?`Built-in`:D(Zn(e.source),`${e.agentType}.md`)}function tr(e){return ot(e)?`Built-in`:$e(e)?`Plugin: ${e.plugin||`Unknown`}`:e.source===`flagSettings`?`CLI argument`:D(Zn(e.source),`${e.filename||e.agentType}.md`)}async function nr(e){let t=Xn(e);return await dn(t,{recursive:!0}),t}async function rr(e,t,n,r,i,a=!0,o,s,c){if(e===`built-in`)throw Error(`Cannot save built-in agents`);await nr(e);let l=Qn({source:e,agentType:t}),u=Yn(t,n,r,i,o,s,c);try{await or(l,u,a?`wx`:`w`)}catch(e){throw wt(e)===`EEXIST`?Error(`Agent file already exists: ${l}`):e}}async function ir(e,t,n,r,i,a,o){if(e.source===`built-in`)throw Error(`Cannot update built-in agents`);await or($n(e),Yn(e.agentType,t,n,r,i,a,o))}async function ar(e){if(e.source===`built-in`)throw Error(`Cannot delete built-in agents`);let t=$n(e);try{await pn(t)}catch(e){if(wt(e)!==`ENOENT`)throw e}}async function or(e,t,n=`w`){let r=await fn(e,n);try{await r.writeFile(t,{encoding:`utf-8`}),await r.datasync()}finally{await r.close()}}var sr=e((()=>{C(),rt(),bt(),r(),Ct(),Jn()}));function cr({agent:e,tools:t,onBack:n}){let r=ut(e,t,!1),i=tr(e),o=pt(e.agentType);d(`confirm:no`,n,{context:`Confirmation`});let s=e=>{e.key===`return`&&(e.preventDefault(),n())};function u(){return r.hasWildcard?(0,k.jsx)(l,{children:`All tools`}):!e.tools||e.tools.length===0?(0,k.jsx)(l,{children:`None`}):(0,k.jsxs)(k.Fragment,{children:[r.validTools.length>0&&(0,k.jsx)(l,{children:r.validTools.join(`, `)}),r.invalidTools.length>0&&(0,k.jsxs)(l,{color:`warning`,children:[a.warning,` Unrecognized: `,r.invalidTools.join(`, `)]})]})}return(0,k.jsxs)(c,{flexDirection:`column`,gap:1,tabIndex:0,autoFocus:!0,onKeyDown:s,children:[(0,k.jsx)(l,{dimColor:!0,children:i}),(0,k.jsxs)(c,{flexDirection:`column`,children:[(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Description`}),` (tells Work Mate when to use this agent):`]}),(0,k.jsx)(c,{marginLeft:2,children:(0,k.jsx)(l,{children:e.whenToUse})})]}),(0,k.jsxs)(c,{children:[(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Tools`}),`:`,` `]}),u()]}),(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Model`}),`: `,_e(e.model)]}),e.permissionMode&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Permission mode`}),`: `,e.permissionMode]}),e.memory&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Memory`}),`: `,Je(e.memory)]}),e.hooks&&Object.keys(e.hooks).length>0&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Hooks`}),`: `,Object.keys(e.hooks).join(`, `)]}),e.skills&&e.skills.length>0&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Skills`}),`:`,` `,e.skills.length>10?`${e.skills.length} skills`:e.skills.join(`, `)]}),o&&(0,k.jsx)(c,{children:(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Color`}),`:`,` `,(0,k.jsxs)(l,{backgroundColor:o,color:`inverseText`,children:[` `,e.agentType,` `]})]})}),!ot(e)&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{children:(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`System prompt`}),`:`]})}),(0,k.jsx)(c,{marginLeft:2,marginRight:2,children:(0,k.jsx)(et,{children:e.getSystemPrompt()})})]})]})}var k,lr=e((()=>{i(),h(),E(),Ie(),it(),He(),rt(),ce(),Ge(),sr(),k=_()}));function ur({agentName:e,currentColor:t=`automatic`,onConfirm:n}){let[r,i]=(0,dr.useState)(Math.max(0,j.indexOf(t))),o=e=>{if(e.key===`up`)e.preventDefault(),i(e=>e>0?e-1:j.length-1);else if(e.key===`down`)e.preventDefault(),i(e=>e<j.length-1?e+1:0);else if(e.key===`return`){e.preventDefault();let t=j[r];n(t===`automatic`?void 0:t)}},s=j[r];return(0,A.jsxs)(c,{flexDirection:`column`,gap:1,tabIndex:0,autoFocus:!0,onKeyDown:o,children:[(0,A.jsx)(c,{flexDirection:`column`,children:j.map((e,t)=>{let n=t===r;return(0,A.jsxs)(c,{flexDirection:`row`,gap:1,children:[(0,A.jsx)(l,{color:n?`suggestion`:void 0,children:n?a.pointer:` `}),e===`automatic`?(0,A.jsx)(l,{bold:n,children:`Automatic color`}):(0,A.jsxs)(c,{gap:1,children:[(0,A.jsx)(l,{backgroundColor:Ue[e],color:`inverseText`,children:` `}),(0,A.jsx)(l,{bold:n,children:Lt(e)})]})]},e)})}),(0,A.jsxs)(c,{marginTop:1,children:[(0,A.jsx)(l,{children:`Preview: `}),s===void 0||s===`automatic`?(0,A.jsxs)(l,{inverse:!0,bold:!0,children:[` `,`@`,e,` `]}):(0,A.jsxs)(l,{backgroundColor:Ue[s],color:`inverseText`,bold:!0,children:[` `,`@`,e,` `]})]})]})}var dr,A,j,fr=e((()=>{i(),dr=t(f(),1),h(),Ie(),Rt(),A=_(),j=[`automatic`,...mt]}));function pr({initialModel:e,onComplete:t,onCancel:n}){let r=mr.useMemo(()=>{let t=je();return e&&!t.some(t=>t.value===e)?[{value:e,label:e,description:`Current model (custom ID)`},...t]:t},[e]);return(0,hr.jsxs)(c,{flexDirection:`column`,children:[(0,hr.jsx)(c,{marginBottom:1,children:(0,hr.jsx)(l,{dimColor:!0,children:`Model determines the agent's reasoning capabilities and speed.`})}),(0,hr.jsx)(en,{options:r,defaultValue:e??`sonnet`,onChange:t,onCancel:()=>n?n():t(void 0)})]})}var mr,hr,gr=e((()=>{mr=t(f(),1),h(),ce(),$t(),hr=_()}));function _r(){return{READ_ONLY:{name:`Read-only tools`,toolNames:new Set([Ze.name,ke.name,ft.name,yt.name,ze.name,Pe.name,be.name,Le.name,pe.name])},EDIT:{name:`Edit tools`,toolNames:new Set([Oe.name,Fe.name,le.name])},EXECUTION:{name:`Execution tools`,toolNames:new Set([Ye.name])},MCP:{name:`MCP tools`,toolNames:new Set,isMcp:!0},OTHER:{name:`Other tools`,toolNames:new Set}}}function vr(e){let t=new Map;return e.forEach(e=>{if(Ke(e)){let n=ne(e.name);if(n?.serverName){let r=t.get(n.serverName)||[];r.push(e),t.set(n.serverName,r)}}}),Array.from(t.entries()).map(([e,t])=>({serverName:e,tools:t})).sort((e,t)=>e.serverName.localeCompare(t.serverName))}function yr({tools:e,initialTools:t,onComplete:n,onCancel:r}){let i=(0,M.useMemo)(()=>Xe({tools:e,isBuiltIn:!1,isAsync:!1}),[e]),[s,u]=(0,M.useState)(!t||t.includes(`*`)?i.map(e=>e.name):t),[f,p]=(0,M.useState)(0),[m,h]=(0,M.useState)(!1),g=(0,M.useMemo)(()=>{let e=new Set(i.map(e=>e.name));return s.filter(t=>e.has(t))},[s,i]),_=new Set(g),v=g.length===i.length&&i.length>0,y=e=>{e&&u(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},x=(e,t)=>{u(n=>{if(t){let t=e.filter(e=>!n.includes(e));return[...n,...t]}else return n.filter(t=>!e.includes(t))})},ee=()=>{let e=i.map(e=>e.name);n(g.length===e.length&&e.every(e=>g.includes(e))?void 0:g)},S=(0,M.useMemo)(()=>{let e=_r(),t={readOnly:[],edit:[],execution:[],mcp:[],other:[]};return i.forEach(n=>{Ke(n)?t.mcp.push(n):e.READ_ONLY.toolNames.has(n.name)?t.readOnly.push(n):e.EDIT.toolNames.has(n.name)?t.edit.push(n):e.EXECUTION.toolNames.has(n.name)?t.execution.push(n):n.name!==`Agent`&&t.other.push(n)}),t},[i]),te=e=>{let t=b(e,e=>_.has(e.name))<e.length;return()=>{let n=e.map(e=>e.name);x(n,t)}},C=[];C.push({id:`continue`,label:`Continue`,action:ee,isContinue:!0}),C.push({id:`bucket-all`,label:`${v?a.checkboxOn:a.checkboxOff} All tools`,action:()=>{let e=i.map(e=>e.name);x(e,!v)}});let re=_r();[{id:`bucket-readonly`,name:re.READ_ONLY.name,tools:S.readOnly},{id:`bucket-edit`,name:re.EDIT.name,tools:S.edit},{id:`bucket-execution`,name:re.EXECUTION.name,tools:S.execution},{id:`bucket-mcp`,name:re.MCP.name,tools:S.mcp},{id:`bucket-other`,name:re.OTHER.name,tools:S.other}].forEach(({id:e,name:t,tools:n})=>{if(n.length===0)return;let r=b(n,e=>_.has(e.name))===n.length;C.push({id:e,label:`${r?a.checkboxOn:a.checkboxOff} ${t}`,action:te(n)})});let ie=C.length;C.push({id:`toggle-individual`,label:m?`Hide advanced options`:`Show advanced options`,action:()=>{h(!m),m&&f>ie&&p(ie)},isToggle:!0});let ae=(0,M.useMemo)(()=>vr(i),[i]);return m&&(ae.length>0&&(C.push({id:`mcp-servers-header`,label:`MCP Servers:`,action:()=>{},isHeader:!0}),ae.forEach(({serverName:e,tools:t})=>{let n=b(t,e=>_.has(e.name))===t.length;C.push({id:`mcp-server-${e}`,label:`${n?a.checkboxOn:a.checkboxOff} ${e} (${t.length} ${It(t.length,`tool`)})`,action:()=>{let e=t.map(e=>e.name);x(e,!n)}})}),C.push({id:`tools-header`,label:`Individual Tools:`,action:()=>{},isHeader:!0})),i.forEach(e=>{let t=e.name;if(e.name.startsWith(`mcp__`)){let n=ne(e.name);t=n?`${n.toolName} (${n.serverName})`:e.name}C.push({id:`tool-${e.name}`,label:`${_.has(e.name)?a.checkboxOn:a.checkboxOff} ${t}`,action:()=>y(e.name)})})),d(`confirm:no`,(0,M.useCallback)(()=>{r?r():n(t)},[r,n,t]),{context:`Confirmation`}),(0,N.jsxs)(c,{flexDirection:`column`,marginTop:1,tabIndex:0,autoFocus:!0,onKeyDown:e=>{if(e.key===`return`){e.preventDefault();let t=C[f];t&&!t.isHeader&&t.action()}else if(e.key===`up`){e.preventDefault();let t=f-1;for(;t>0&&C[t]?.isHeader;)t--;p(Math.max(0,t))}else if(e.key===`down`){e.preventDefault();let t=f+1;for(;t<C.length-1&&C[t]?.isHeader;)t++;p(Math.min(C.length-1,t))}},children:[(0,N.jsxs)(l,{color:f===0?`suggestion`:void 0,bold:f===0,children:[f===0?`${a.pointer} `:` `,`[ Continue ]`]}),(0,N.jsx)(o,{width:40}),C.slice(1).map((e,t)=>{let n=t+1===f,r=e.isToggle,i=e.isHeader;return(0,N.jsxs)(M.Fragment,{children:[r&&(0,N.jsx)(o,{width:40}),i&&t>0&&(0,N.jsx)(c,{marginTop:1}),(0,N.jsxs)(l,{color:i?void 0:n?`suggestion`:void 0,dimColor:i,bold:r&&n,children:[i?``:n?`${a.pointer} `:` `,r?`[ ${e.label} ]`:e.label]})]},e.id)}),(0,N.jsx)(c,{marginTop:1,flexDirection:`column`,children:(0,N.jsx)(l,{dimColor:!0,children:v?`All tools selected`:`${_.size} of ${i.length} tools selected`})})]})}var M,N,br=e((()=>{i(),M=t(f(),1),te(),oe(),He(),x(),Ve(),Re(),Ae(),fe(),_t(),De(),Me(),ye(),Qe(),dt(),ge(),gt(),xe(),h(),E(),v(),Rt(),N=_()}));function xr(e){return e===`all`?`Agents`:e===`built-in`?`Built-in agents`:e===`plugin`?`Plugin agents`:Kn(ee(e))}var Sr=e((()=>{qn(),S()}));function Cr({agent:e,tools:t,onSaved:n,onBack:r}){let i=we(),[o,s]=(0,P.useState)(`menu`),[u,f]=(0,P.useState)(0),[m,h]=(0,P.useState)(null),[g,_]=(0,P.useState)(e.color),v=(0,P.useCallback)(async()=>{let t=await cn($n(e));t.error?h(t.error):n(`Opened ${e.agentType} in editor. If you made edits, restart to load the latest version.`)},[e,n]),y=(0,P.useCallback)(async(t={})=>{let{tools:r,color:a,model:o}=t,s=a??g,c=r!==void 0,l=o!==void 0,u=s!==e.color;if(!c&&!l&&!u)return!1;try{return!We(e)&&!$e(e)?!1:(await ir(e,e.whenToUse,r??e.tools,e.getSystemPrompt(),s,o??e.model),u&&s&&me(e.agentType,s),i(t=>{let n=t.agentDefinitions.allAgents.map(t=>t.agentType===e.agentType?{...t,tools:r??t.tools,color:s,model:o??t.model}:t);return{...t,agentDefinitions:{...t.agentDefinitions,activeAgents:at(n),allAgents:n}}}),n(`Updated agent: ${p.bold(e.agentType)}`),!0)}catch(e){return h(e instanceof Error?e.message:`Failed to save agent`),!1}},[e,g,n,i]),b=(0,P.useMemo)(()=>[{label:`Open in editor`,action:v},{label:`Edit tools`,action:()=>s(`edit-tools`)},{label:`Edit model`,action:()=>s(`edit-model`)},{label:`Edit color`,action:()=>s(`edit-color`)}],[v]),x=(0,P.useCallback)(()=>{h(null),o===`menu`?r():s(`menu`)},[o,r]),ee=(0,P.useCallback)(e=>{if(e.key===`up`)e.preventDefault(),f(e=>Math.max(0,e-1));else if(e.key===`down`)e.preventDefault(),f(e=>Math.min(b.length-1,e+1));else if(e.key===`return`){e.preventDefault();let t=b[u];t&&t.action()}},[b,u]);d(`confirm:no`,x,{context:`Confirmation`});let S=()=>(0,F.jsxs)(c,{flexDirection:`column`,tabIndex:0,autoFocus:!0,onKeyDown:ee,children:[(0,F.jsxs)(l,{dimColor:!0,children:[`Source: `,xr(e.source)]}),(0,F.jsx)(c,{marginTop:1,flexDirection:`column`,children:b.map((e,t)=>(0,F.jsxs)(l,{color:t===u?`suggestion`:void 0,children:[t===u?`${a.pointer} `:` `,e.label]},e.label))}),m&&(0,F.jsx)(c,{marginTop:1,children:(0,F.jsx)(l,{color:`error`,children:m})})]});switch(o){case`menu`:return S();case`edit-tools`:return(0,F.jsx)(yr,{tools:t,initialTools:e.tools,onComplete:async e=>{s(`menu`),await y({tools:e})}});case`edit-color`:return(0,F.jsx)(ur,{agentName:e.agentType,currentColor:g||e.color||`automatic`,onConfirm:async e=>{_(e),s(`menu`),await y({color:e})}});case`edit-model`:return(0,F.jsx)(pr,{initialModel:e.model,onComplete:async e=>{s(`menu`),await y({model:e})}});default:return null}}var P,F,wr=e((()=>{m(),i(),P=t(f(),1),ht(),h(),E(),Ie(),rt(),sn(),sr(),fr(),gr(),br(),Sr(),F=_()}));function Tr({instructions:e=`Press ↑↓ to navigate · Enter to select · Esc to go back`}){let t=Yt();return(0,Er.jsx)(c,{marginLeft:2,children:(0,Er.jsx)(l,{dimColor:!0,children:t.pending?`Press ${t.keyName} again to exit`:e})})}var Er,Dr=e((()=>{Xt(),h(),Er=_()}));function Or({source:e,agents:t,onBack:n,onSelect:r,onCreateNew:i,changes:s}){let[u,d]=kr.useState(null),[f,p]=kr.useState(!0),m=kr.useMemo(()=>[...t].sort(Gt),[t]),h=e=>({isOverridden:!!e.overriddenBy,overriddenBy:e.overriddenBy||null}),_=()=>(0,I.jsxs)(c,{children:[(0,I.jsx)(l,{color:f?`suggestion`:void 0,children:f?`${a.pointer} `:` `}),(0,I.jsx)(l,{color:f?`suggestion`:void 0,children:`Create new agent`})]}),v=e=>{let t=e.source===`built-in`,n=!t&&!f&&u?.agentType===e.agentType&&u?.source===e.source,{isOverridden:r,overriddenBy:i}=h(e),o=t||r,s=!t&&n?`suggestion`:void 0,d=Ut(e);return(0,I.jsxs)(c,{children:[(0,I.jsx)(l,{dimColor:o&&!n,color:s,children:t?``:n?`${a.pointer} `:` `}),(0,I.jsx)(l,{dimColor:o&&!n,color:s,children:e.agentType}),d&&(0,I.jsxs)(l,{dimColor:!0,color:s,children:[` · `,d]}),e.memory&&(0,I.jsxs)(l,{dimColor:!0,color:s,children:[` · `,e.memory,` memory`]}),i&&(0,I.jsxs)(l,{dimColor:!n,color:n?`warning`:void 0,children:[` `,a.warning,` shadowed by `,qt(i)]})]},`${e.agentType}-${e.source}`)},y=kr.useMemo(()=>{let t=m.filter(e=>e.source!==`built-in`);return e===`all`?Jt.filter(e=>e.source!==`built-in`).flatMap(({source:e})=>t.filter(t=>t.source===e)):t},[m,e]);kr.useEffect(()=>{!u&&!f&&y.length>0&&(i?p(!0):d(y[0]||null))},[y,u,f,i]);let x=e=>{if(e.key===`return`){e.preventDefault(),f&&i?i():u&&r(u);return}if(e.key!==`up`&&e.key!==`down`)return;e.preventDefault();let t=!!i,n=y.length+ +!!t;if(n===0)return;let a=0;if(!f&&u){let e=y.findIndex(e=>e.agentType===u.agentType&&e.source===u.source);e>=0&&(a=t?e+1:e)}let o=e.key===`up`?a===0?n-1:a-1:a===n-1?0:a+1;if(t&&o===0)p(!0),d(null);else{let e=t?o-1:o,n=y[e];n&&(p(!1),d(n))}},ee=(e=`Built-in (always available):`)=>{let t=m.filter(e=>e.source===`built-in`);return(0,I.jsxs)(c,{flexDirection:`column`,marginBottom:1,paddingLeft:2,children:[(0,I.jsx)(l,{bold:!0,dimColor:!0,children:e}),t.map(v)]})},S=(e,t)=>{if(!t.length)return null;let n=t[0]?.baseDir;return(0,I.jsxs)(c,{flexDirection:`column`,marginBottom:1,children:[(0,I.jsxs)(c,{paddingLeft:2,children:[(0,I.jsx)(l,{bold:!0,dimColor:!0,children:e}),n&&(0,I.jsxs)(l,{dimColor:!0,children:[` (`,n,`)`]})]}),t.map(e=>v(e))]})},te=xr(e),C=m.filter(e=>e.source===`built-in`);return!m.length||e!==`built-in`&&!m.some(e=>e.source!==`built-in`)?(0,I.jsx)(g,{title:te,subtitle:`No agents found`,onCancel:n,hideInputGuide:!0,children:(0,I.jsxs)(c,{flexDirection:`column`,gap:1,tabIndex:0,autoFocus:!0,onKeyDown:x,children:[i&&(0,I.jsx)(c,{children:_()}),(0,I.jsx)(l,{dimColor:!0,children:`No agents found. Create specialized subagents that Work Mate can delegate to.`}),(0,I.jsx)(l,{dimColor:!0,children:`Each subagent has its own context window, custom system prompt, and specific tools.`}),(0,I.jsx)(l,{dimColor:!0,children:`Try creating: Code Reviewer, Code Simplifier, Security Reviewer, Tech Lead, or UX Reviewer.`}),e!==`built-in`&&m.some(e=>e.source===`built-in`)&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(o,{}),ee()]})]})}):(0,I.jsxs)(g,{title:te,subtitle:`${b(m,e=>!e.overriddenBy)} agents`,onCancel:n,hideInputGuide:!0,children:[s&&s.length>0&&(0,I.jsx)(c,{marginTop:1,children:(0,I.jsx)(l,{dimColor:!0,children:s[s.length-1]})}),(0,I.jsxs)(c,{flexDirection:`column`,tabIndex:0,autoFocus:!0,onKeyDown:x,children:[i&&(0,I.jsx)(c,{marginBottom:1,children:_()}),e===`all`?(0,I.jsxs)(I.Fragment,{children:[Jt.filter(e=>e.source!==`built-in`).map(({label:e,source:t})=>(0,I.jsx)(kr.Fragment,{children:S(e,m.filter(e=>e.source===t))},t)),C.length>0&&(0,I.jsxs)(c,{flexDirection:`column`,marginBottom:1,paddingLeft:2,children:[(0,I.jsxs)(l,{dimColor:!0,children:[(0,I.jsx)(l,{bold:!0,children:`Built-in agents`}),` (always available)`]}),C.map(v)]})]}):e===`built-in`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(l,{dimColor:!0,italic:!0,children:`Built-in agents are provided by default and cannot be modified.`}),(0,I.jsx)(c,{marginTop:1,flexDirection:`column`,children:m.map(e=>v(e))})]}):(0,I.jsxs)(I.Fragment,{children:[m.filter(e=>e.source!==`built-in`).map(e=>v(e)),m.some(e=>e.source===`built-in`)&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(o,{}),ee()]})]})]})]})}var kr,I,Ar=e((()=>{i(),kr=t(f(),1),h(),Wt(),v(),Sr(),I=_()}));function jr({steps:e,initialData:t={},onComplete:n,onCancel:r,children:i,title:a,showStepCounter:o=!0}){let[s,c]=(0,L.useState)(0),[l,u]=(0,L.useState)(t),[d,f]=(0,L.useState)(!1),[p,m]=(0,L.useState)([]);Yt(),(0,L.useEffect)(()=>{d&&(m([]),n(l))},[d,l,n]);let h=(0,L.useCallback)(()=>{s<e.length-1?(p.length>0&&m(e=>[...e,s]),c(e=>e+1)):f(!0)},[s,e.length,p]),g=(0,L.useCallback)(()=>{if(p.length>0){let e=p[p.length-1];e!==void 0&&(m(e=>e.slice(0,-1)),c(e))}else s>0?c(e=>e-1):r&&r()},[s,p,r]),_=(0,L.useCallback)(t=>{t>=0&&t<e.length&&(m(e=>[...e,s]),c(t))},[s,e.length]),v=(0,L.useCallback)(()=>{m([]),r&&r()},[r]),y=(0,L.useCallback)(e=>{u(t=>({...t,...e}))},[]),b=(0,L.useMemo)(()=>({currentStepIndex:s,totalSteps:e.length,wizardData:l,setWizardData:u,updateWizardData:y,goNext:h,goBack:g,goToStep:_,cancel:v,title:a,showStepCounter:o}),[s,e.length,l,y,h,g,_,v,a,o]),x=e[s];return!x||d?null:(0,Mr.jsx)(Nr.Provider,{value:b,children:i||(0,Mr.jsx)(x,{})})}var L,Mr,Nr,Pr=e((()=>{L=t(f(),1),Xt(),Mr=_(),Nr=(0,L.createContext)(null)}));function R(){let e=(0,Fr.useContext)(Nr);if(!e)throw Error(`useWizard must be used within a WizardProvider`);return e}var Fr,Ir=e((()=>{Fr=t(f(),1),Pr()}));function Lr({instructions:e=(0,z.jsxs)(u,{children:[(0,z.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,z.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,z.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]})}){let t=Yt();return(0,z.jsx)(c,{marginLeft:3,marginTop:1,children:(0,z.jsx)(l,{dimColor:!0,children:t.pending?`Press ${t.keyName} again to exit`:e})})}var z,Rr=e((()=>{Xt(),h(),w(),z=_()}));function B({title:e,color:t=`suggestion`,children:n,subtitle:r,footerText:i}){let{currentStepIndex:a,totalSteps:o,title:s,showStepCounter:c,goBack:l}=R();return(0,zr.jsxs)(zr.Fragment,{children:[(0,zr.jsx)(g,{title:`${e||s||`Wizard`}${c===!1?``:` (${a+1}/${o})`}`,subtitle:r,onCancel:l,color:t,hideInputGuide:!0,isCancelActive:!1,children:n}),(0,zr.jsx)(Lr,{instructions:i})]})}var zr,V=e((()=>{h(),Ir(),Rr(),zr=_()})),H=e((()=>{Ir(),V(),Rr(),Pr()}));function Br(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R();return d(`confirm:no`,t,{context:`Confirmation`}),(0,U.jsx)(B,{subtitle:`Choose background color`,footerText:(0,U.jsxs)(u,{children:[(0,U.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,U.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,U.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,U.jsx)(c,{children:(0,U.jsx)(ur,{agentName:r.agentType||`agent`,currentColor:`automatic`,onConfirm:t=>{n({selectedColor:t,finalAgent:{agentType:r.agentType,whenToUse:r.whenToUse,getSystemPrompt:()=>r.systemPrompt,tools:r.selectedTools,...r.selectedModel?{model:r.selectedModel}:{},...t?{color:t}:{},source:r.location}}),e()}})})})}var U,Vr=e((()=>{h(),E(),w(),H(),V(),fr(),U=_()}));function Hr(e){return e?/^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$/.test(e)?e.length<3?`Agent type must be at least 3 characters long`:e.length>50?`Agent type must be less than 50 characters`:null:`Agent type must start and end with alphanumeric characters and contain only letters, numbers, and hyphens`:`Agent type is required`}function Ur(e,t,n){let r=[],i=[];if(!e.agentType)r.push(`Agent type is required`);else{let t=Hr(e.agentType);t&&r.push(t);let i=n.find(t=>t.agentType===e.agentType&&t.source!==e.source);i&&r.push(`Agent type "${e.agentType}" already exists in ${xr(i.source)}`)}if(e.whenToUse?e.whenToUse.length<10?i.push(`Description should be more descriptive (at least 10 characters)`):e.whenToUse.length>5e3&&i.push(`Description is very long (over 5000 characters)`):r.push(`Description (description) is required`),e.tools!==void 0&&!Array.isArray(e.tools))r.push(`Tools must be an array`);else{e.tools===void 0?i.push(`Agent has access to all tools`):e.tools.length===0&&i.push(`No tools selected - agent will have very limited capabilities`);let n=ut(e,t,!1);n.invalidTools.length>0&&r.push(`Invalid tools: ${n.invalidTools.join(`, `)}`)}let a=e.getSystemPrompt();return a?a.length<20?r.push(`System prompt is too short (minimum 20 characters)`):a.length>1e4&&i.push(`System prompt is very long (over 10,000 characters)`):r.push(`System prompt is required`),{isValid:r.length===0,errors:r,warnings:i}}var Wr=e((()=>{He(),Sr()}));function Gr({tools:e,existingAgents:t,onSave:n,onSaveAndEdit:r,error:i}){let{goBack:a,wizardData:o}=R();d(`confirm:no`,a,{context:`Confirmation`});let f=e=>{e.key===`s`||e.key===`return`?(e.preventDefault(),n()):e.key===`e`&&(e.preventDefault(),r())},p=o.finalAgent,m=Ur(p,e,t),h=Pt(p.getSystemPrompt(),240),g=Pt(p.whenToUse,240),_=e=>e===void 0?`All tools`:e.length===0?`None`:e.length===1?e[0]||`None`:e.length===2?e.join(` and `):`${e.slice(0,-1).join(`, `)}, and ${e[e.length-1]}`,v=At()?(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Memory`}),`: `,Je(p.memory)]}):null;return(0,W.jsx)(B,{subtitle:`Confirm and save`,footerText:(0,W.jsxs)(u,{children:[(0,W.jsx)(s,{shortcut:`s/Enter`,action:`save`}),(0,W.jsx)(s,{shortcut:`e`,action:`edit in your editor`}),(0,W.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`cancel`})]}),children:(0,W.jsxs)(c,{flexDirection:`column`,tabIndex:0,autoFocus:!0,onKeyDown:f,children:[(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Name`}),`: `,p.agentType]}),(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Location`}),`:`,` `,er({source:o.location,agentType:p.agentType})]}),(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Tools`}),`: `,_(p.tools)]}),(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Model`}),`: `,_e(p.model)]}),v,(0,W.jsx)(c,{marginTop:1,children:(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Description`}),` (tells Work Mate when to use this agent):`]})}),(0,W.jsx)(c,{marginLeft:2,marginTop:1,children:(0,W.jsx)(l,{children:g})}),(0,W.jsx)(c,{marginTop:1,children:(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`System prompt`}),`:`]})}),(0,W.jsx)(c,{marginLeft:2,marginTop:1,children:(0,W.jsx)(l,{children:h})}),m.warnings.length>0&&(0,W.jsxs)(c,{marginTop:1,flexDirection:`column`,children:[(0,W.jsx)(l,{color:`warning`,children:`Warnings:`}),m.warnings.map((e,t)=>(0,W.jsxs)(l,{dimColor:!0,children:[` `,`• `,e]},t))]}),m.errors.length>0&&(0,W.jsxs)(c,{marginTop:1,flexDirection:`column`,children:[(0,W.jsx)(l,{color:`error`,children:`Errors:`}),m.errors.map((e,t)=>(0,W.jsxs)(l,{color:`error`,children:[` `,`• `,e]},t))]}),i&&(0,W.jsx)(c,{marginTop:1,children:(0,W.jsx)(l,{color:`error`,children:i})}),(0,W.jsx)(c,{marginTop:2,children:(0,W.jsxs)(l,{color:`success`,children:[`Press `,(0,W.jsx)(l,{bold:!0,children:`s`}),` or `,(0,W.jsx)(l,{bold:!0,children:`Enter`}),` to save, `,(0,W.jsx)(l,{bold:!0,children:`e`}),` to save and edit`]})})]})})}var W,Kr=e((()=>{h(),E(),kt(),it(),Ft(),ce(),w(),H(),V(),sr(),Wr(),W=_()}));function qr({tools:e,existingAgents:t,onComplete:n}){let{wizardData:r}=R(),[i,a]=(0,Jr.useState)(null),o=we(),s=(0,Jr.useCallback)(async e=>{if(r?.finalAgent)try{await rr(r.location,r.finalAgent.agentType,r.finalAgent.whenToUse,r.finalAgent.tools,r.finalAgent.getSystemPrompt(),!0,r.finalAgent.color,r.finalAgent.model,r.finalAgent.memory),o(e=>{if(!r.finalAgent)return e;let t=e.agentDefinitions.allAgents.concat(r.finalAgent);return{...e,agentDefinitions:{...e.agentDefinitions,activeAgents:at(t),allAgents:t}}}),st(),e&&await cn(Qn({source:r.location,agentType:r.finalAgent.agentType})),r.finalAgent.agentType,r.wasGenerated,r.location,r.finalAgent.tools?.length,r.finalAgent.model,r.finalAgent.color,r.finalAgent.memory,r.finalAgent.memory,{...e?{opened_in_editor:!0}:{}},n(e?`Created agent: ${p.bold(r.finalAgent.agentType)} and opened in editor. If you made edits, restart to load the latest version.`:`Created agent: ${p.bold(r.finalAgent.agentType)}`)}catch(e){a(e instanceof Error?e.message:`Failed to save agent`)}},[r,n,o]);return(0,Yr.jsx)(Gr,{tools:e,existingAgents:t,onSave:(0,Jr.useCallback)(()=>s(!1),[s]),onSaveAndEdit:(0,Jr.useCallback)(()=>s(!0),[s]),error:i})}var Jr,Yr,Xr=e((()=>{m(),Jr=t(f(),1),Nt(),ht(),rt(),sn(),H(),sr(),Kr(),Yr=_()}));function Zr(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R(),[i,a]=(0,Qr.useState)(r.whenToUse||``),[o,f]=(0,Qr.useState)(i.length),[p,m]=(0,Qr.useState)(null);return d(`confirm:no`,t,{context:`Settings`}),d(`chat:externalEditor`,(0,Qr.useCallback)(async()=>{let e=await on(i);e.content!==null&&(a(e.content),f(e.content.length))},[i]),{context:`Chat`}),(0,G.jsx)(B,{subtitle:`Description (tell Work Mate when to use this agent)`,footerText:(0,G.jsxs)(u,{children:[(0,G.jsx)(s,{shortcut:`Type`,action:`enter text`}),(0,G.jsx)(s,{shortcut:`Enter`,action:`continue`}),(0,G.jsx)(T,{action:`chat:externalEditor`,context:`Chat`,fallback:`ctrl+g`,description:`open in editor`}),(0,G.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,G.jsxs)(c,{flexDirection:`column`,children:[(0,G.jsx)(l,{children:`When should Work Mate use this agent?`}),(0,G.jsx)(c,{marginTop:1,children:(0,G.jsx)(Qt,{value:i,onChange:a,onSubmit:t=>{let r=t.trim();if(!r){m(`Description is required`);return}m(null),n({whenToUse:r}),e()},placeholder:`e.g., use this agent after you're done writing code...`,columns:80,cursorOffset:o,onChangeCursorOffset:f,focus:!0,showCursor:!0})}),p&&(0,G.jsx)(c,{marginTop:1,children:(0,G.jsx)(l,{color:`error`,children:p})})]})})}var Qr,G,$r=e((()=>{Qr=t(f(),1),h(),E(),sn(),w(),Zt(),H(),V(),G=_()}));async function ei(e,t,n,r){let i=se({content:`Create an agent configuration based on this request: "${e}".${n.length>0?`\n\nIMPORTANT: The following identifiers already exist and must NOT be used: ${n.join(`, `)}`:``}
8
- Return ONLY the JSON object, no other text.`}),a=await Se(),o=nt([i],a),s=At()?ti+ni:ti,c=await Ne({messages:lt(o),systemPrompt:Ce([s]),thinkingConfig:{type:`disabled`},tools:[],signal:r,options:{getToolPermissionContext:async()=>zt(),model:t,toolChoice:void 0,agents:[],isNonInteractiveSession:!1,hasAppendSystemPrompt:!1,querySource:`agent_creation`,mcpTools:[]}}),l=(Array.isArray(c.message.content)?c.message.content:[]).filter(e=>e.type===`text`).map(e=>e.text).join(`
9
- `),u;try{u=Tt(l.trim())}catch{let e=l.match(/\{[\s\S]*\}/);if(!e)throw Error(`No JSON object found in response`);u=Tt(e[0])}if(!u.identifier||!u.whenToUse||!u.systemPrompt)throw Error(`Invalid agent configuration generated`);return u.identifier,{identifier:u.identifier,whenToUse:u.whenToUse,systemPrompt:u.systemPrompt}}var ti,ni,ri=e((()=>{Te(),Be(),Bt(),x(),qe(),Ee(),kt(),Nt(),Ot(),ct(),ti=`You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.
7
+ `}function Xn(e){switch(e){case`flagSettings`:throw Error(`Cannot get directory path for ${e} agents`);case`userSettings`:return D(n(),O.AGENTS_DIR);case`projectSettings`:return D(xt(),O.FOLDER_NAME,O.AGENTS_DIR);case`policySettings`:return D(re(),O.FOLDER_NAME,O.AGENTS_DIR);case`localSettings`:return D(xt(),O.FOLDER_NAME,O.AGENTS_DIR)}}function Zn(e){switch(e){case`projectSettings`:return D(`.`,O.FOLDER_NAME,O.AGENTS_DIR);default:return Xn(e)}}function Qn(e){return D(Xn(e.source),`${e.agentType}.md`)}function $n(e){if(e.source===`built-in`)return`Built-in`;if(e.source===`plugin`)throw Error(`Cannot get file path for plugin agents`);return D(Xn(e.source),`${e.filename||e.agentType}.md`)}function er(e){return e.source===`built-in`?`Built-in`:D(Zn(e.source),`${e.agentType}.md`)}function tr(e){return ut(e)?`Built-in`:tt(e)?`Plugin: ${e.plugin||`Unknown`}`:e.source===`flagSettings`?`CLI argument`:D(Zn(e.source),`${e.filename||e.agentType}.md`)}async function nr(e){let t=Xn(e);return await dn(t,{recursive:!0}),t}async function rr(e,t,n,r,i,a=!0,o,s,c){if(e===`built-in`)throw Error(`Cannot save built-in agents`);await nr(e);let l=Qn({source:e,agentType:t}),u=Yn(t,n,r,i,o,s,c);try{await or(l,u,a?`wx`:`w`)}catch(e){throw wt(e)===`EEXIST`?Error(`Agent file already exists: ${l}`):e}}async function ir(e,t,n,r,i,a,o){if(e.source===`built-in`)throw Error(`Cannot update built-in agents`);await or($n(e),Yn(e.agentType,t,n,r,i,a,o))}async function ar(e){if(e.source===`built-in`)throw Error(`Cannot delete built-in agents`);let t=$n(e);try{await pn(t)}catch(e){if(wt(e)!==`ENOENT`)throw e}}async function or(e,t,n=`w`){let r=await fn(e,n);try{await r.writeFile(t,{encoding:`utf-8`}),await r.datasync()}finally{await r.close()}}var sr=e((()=>{C(),at(),bt(),r(),Ct(),Jn()}));function cr({agent:e,tools:t,onBack:n}){let r=We(e,t,!1),i=tr(e),o=le(e.agentType);d(`confirm:no`,n,{context:`Confirmation`});let s=e=>{e.key===`return`&&(e.preventDefault(),n())};function u(){return r.hasWildcard?(0,k.jsx)(l,{children:`All tools`}):!e.tools||e.tools.length===0?(0,k.jsx)(l,{children:`None`}):(0,k.jsxs)(k.Fragment,{children:[r.validTools.length>0&&(0,k.jsx)(l,{children:r.validTools.join(`, `)}),r.invalidTools.length>0&&(0,k.jsxs)(l,{color:`warning`,children:[a.warning,` Unrecognized: `,r.invalidTools.join(`, `)]})]})}return(0,k.jsxs)(c,{flexDirection:`column`,gap:1,tabIndex:0,autoFocus:!0,onKeyDown:s,children:[(0,k.jsx)(l,{dimColor:!0,children:i}),(0,k.jsxs)(c,{flexDirection:`column`,children:[(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Description`}),` (tells Work Mate when to use this agent):`]}),(0,k.jsx)(c,{marginLeft:2,children:(0,k.jsx)(l,{children:e.whenToUse})})]}),(0,k.jsxs)(c,{children:[(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Tools`}),`:`,` `]}),u()]}),(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Model`}),`: `,et(e.model)]}),e.permissionMode&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Permission mode`}),`: `,e.permissionMode]}),e.memory&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Memory`}),`: `,nt(e.memory)]}),e.hooks&&Object.keys(e.hooks).length>0&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Hooks`}),`: `,Object.keys(e.hooks).join(`, `)]}),e.skills&&e.skills.length>0&&(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Skills`}),`:`,` `,e.skills.length>10?`${e.skills.length} skills`:e.skills.join(`, `)]}),o&&(0,k.jsx)(c,{children:(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`Color`}),`:`,` `,(0,k.jsxs)(l,{backgroundColor:o,color:`inverseText`,children:[` `,e.agentType,` `]})]})}),!ut(e)&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{children:(0,k.jsxs)(l,{children:[(0,k.jsx)(l,{bold:!0,children:`System prompt`}),`:`]})}),(0,k.jsx)(c,{marginLeft:2,marginRight:2,children:(0,k.jsx)(Ke,{children:e.getSystemPrompt()})})]})]})}var k,lr=e((()=>{i(),h(),E(),gt(),Xe(),yt(),at(),Se(),ot(),sr(),k=_()}));function ur({agentName:e,currentColor:t=`automatic`,onConfirm:n}){let[r,i]=(0,dr.useState)(Math.max(0,j.indexOf(t))),o=e=>{if(e.key===`up`)e.preventDefault(),i(e=>e>0?e-1:j.length-1);else if(e.key===`down`)e.preventDefault(),i(e=>e<j.length-1?e+1:0);else if(e.key===`return`){e.preventDefault();let t=j[r];n(t===`automatic`?void 0:t)}},s=j[r];return(0,A.jsxs)(c,{flexDirection:`column`,gap:1,tabIndex:0,autoFocus:!0,onKeyDown:o,children:[(0,A.jsx)(c,{flexDirection:`column`,children:j.map((e,t)=>{let n=t===r;return(0,A.jsxs)(c,{flexDirection:`row`,gap:1,children:[(0,A.jsx)(l,{color:n?`suggestion`:void 0,children:n?a.pointer:` `}),e===`automatic`?(0,A.jsx)(l,{bold:n,children:`Automatic color`}):(0,A.jsxs)(c,{gap:1,children:[(0,A.jsx)(l,{backgroundColor:Pe[e],color:`inverseText`,children:` `}),(0,A.jsx)(l,{bold:n,children:Lt(e)})]})]},e)})}),(0,A.jsxs)(c,{marginTop:1,children:[(0,A.jsx)(l,{children:`Preview: `}),s===void 0||s===`automatic`?(0,A.jsxs)(l,{inverse:!0,bold:!0,children:[` `,`@`,e,` `]}):(0,A.jsxs)(l,{backgroundColor:Pe[s],color:`inverseText`,bold:!0,children:[` `,`@`,e,` `]})]})]})}var dr,A,j,fr=e((()=>{i(),dr=t(f(),1),h(),gt(),Rt(),A=_(),j=[`automatic`,..._t]}));function pr({initialModel:e,onComplete:t,onCancel:n}){let r=mr.useMemo(()=>{let t=oe();return e&&!t.some(t=>t.value===e)?[{value:e,label:e,description:`Current model (custom ID)`},...t]:t},[e]);return(0,hr.jsxs)(c,{flexDirection:`column`,children:[(0,hr.jsx)(c,{marginBottom:1,children:(0,hr.jsx)(l,{dimColor:!0,children:`Model determines the agent's reasoning capabilities and speed.`})}),(0,hr.jsx)(en,{options:r,defaultValue:e??`sonnet`,onChange:t,onCancel:()=>n?n():t(void 0)})]})}var mr,hr,gr=e((()=>{mr=t(f(),1),h(),Se(),$t(),hr=_()}));function _r(){return{READ_ONLY:{name:`Read-only tools`,toolNames:new Set([we.name,he.name,me.name,Ve.name,fe.name,se.name,Oe.name,ue.name,Fe.name])},EDIT:{name:`Edit tools`,toolNames:new Set([je.name,ce.name,Ce.name])},EXECUTION:{name:`Execution tools`,toolNames:new Set([mt.name])},MCP:{name:`MCP tools`,toolNames:new Set,isMcp:!0},OTHER:{name:`Other tools`,toolNames:new Set}}}function vr(e){let t=new Map;return e.forEach(e=>{if(rt(e)){let n=ne(e.name);if(n?.serverName){let r=t.get(n.serverName)||[];r.push(e),t.set(n.serverName,r)}}}),Array.from(t.entries()).map(([e,t])=>({serverName:e,tools:t})).sort((e,t)=>e.serverName.localeCompare(t.serverName))}function yr({tools:e,initialTools:t,onComplete:n,onCancel:r}){let i=(0,M.useMemo)(()=>ht({tools:e,isBuiltIn:!1,isAsync:!1}),[e]),[s,u]=(0,M.useState)(!t||t.includes(`*`)?i.map(e=>e.name):t),[f,p]=(0,M.useState)(0),[m,h]=(0,M.useState)(!1),g=(0,M.useMemo)(()=>{let e=new Set(i.map(e=>e.name));return s.filter(t=>e.has(t))},[s,i]),_=new Set(g),v=g.length===i.length&&i.length>0,y=e=>{e&&u(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},x=(e,t)=>{u(n=>{if(t){let t=e.filter(e=>!n.includes(e));return[...n,...t]}else return n.filter(t=>!e.includes(t))})},ee=()=>{let e=i.map(e=>e.name);n(g.length===e.length&&e.every(e=>g.includes(e))?void 0:g)},S=(0,M.useMemo)(()=>{let e=_r(),t={readOnly:[],edit:[],execution:[],mcp:[],other:[]};return i.forEach(n=>{rt(n)?t.mcp.push(n):e.READ_ONLY.toolNames.has(n.name)?t.readOnly.push(n):e.EDIT.toolNames.has(n.name)?t.edit.push(n):e.EXECUTION.toolNames.has(n.name)?t.execution.push(n):n.name!==`Agent`&&t.other.push(n)}),t},[i]),te=e=>{let t=b(e,e=>_.has(e.name))<e.length;return()=>{let n=e.map(e=>e.name);x(n,t)}},C=[];C.push({id:`continue`,label:`Continue`,action:ee,isContinue:!0}),C.push({id:`bucket-all`,label:`${v?a.checkboxOn:a.checkboxOff} All tools`,action:()=>{let e=i.map(e=>e.name);x(e,!v)}});let re=_r();[{id:`bucket-readonly`,name:re.READ_ONLY.name,tools:S.readOnly},{id:`bucket-edit`,name:re.EDIT.name,tools:S.edit},{id:`bucket-execution`,name:re.EXECUTION.name,tools:S.execution},{id:`bucket-mcp`,name:re.MCP.name,tools:S.mcp},{id:`bucket-other`,name:re.OTHER.name,tools:S.other}].forEach(({id:e,name:t,tools:n})=>{if(n.length===0)return;let r=b(n,e=>_.has(e.name))===n.length;C.push({id:e,label:`${r?a.checkboxOn:a.checkboxOff} ${t}`,action:te(n)})});let ie=C.length;C.push({id:`toggle-individual`,label:m?`Hide advanced options`:`Show advanced options`,action:()=>{h(!m),m&&f>ie&&p(ie)},isToggle:!0});let ae=(0,M.useMemo)(()=>vr(i),[i]);return m&&(ae.length>0&&(C.push({id:`mcp-servers-header`,label:`MCP Servers:`,action:()=>{},isHeader:!0}),ae.forEach(({serverName:e,tools:t})=>{let n=b(t,e=>_.has(e.name))===t.length;C.push({id:`mcp-server-${e}`,label:`${n?a.checkboxOn:a.checkboxOff} ${e} (${t.length} ${It(t.length,`tool`)})`,action:()=>{let e=t.map(e=>e.name);x(e,!n)}})}),C.push({id:`tools-header`,label:`Individual Tools:`,action:()=>{},isHeader:!0})),i.forEach(e=>{let t=e.name;if(e.name.startsWith(`mcp__`)){let n=ne(e.name);t=n?`${n.toolName} (${n.serverName})`:e.name}C.push({id:`tool-${e.name}`,label:`${_.has(e.name)?a.checkboxOn:a.checkboxOff} ${t}`,action:()=>y(e.name)})})),d(`confirm:no`,(0,M.useCallback)(()=>{r?r():n(t)},[r,n,t]),{context:`Confirmation`}),(0,N.jsxs)(c,{flexDirection:`column`,marginTop:1,tabIndex:0,autoFocus:!0,onKeyDown:e=>{if(e.key===`return`){e.preventDefault();let t=C[f];t&&!t.isHeader&&t.action()}else if(e.key===`up`){e.preventDefault();let t=f-1;for(;t>0&&C[t]?.isHeader;)t--;p(Math.max(0,t))}else if(e.key===`down`){e.preventDefault();let t=f+1;for(;t<C.length-1&&C[t]?.isHeader;)t++;p(Math.min(C.length-1,t))}},children:[(0,N.jsxs)(l,{color:f===0?`suggestion`:void 0,bold:f===0,children:[f===0?`${a.pointer} `:` `,`[ Continue ]`]}),(0,N.jsx)(o,{width:40}),C.slice(1).map((e,t)=>{let n=t+1===f,r=e.isToggle,i=e.isHeader;return(0,N.jsxs)(M.Fragment,{children:[r&&(0,N.jsx)(o,{width:40}),i&&t>0&&(0,N.jsx)(c,{marginTop:1}),(0,N.jsxs)(l,{color:i?void 0:n?`suggestion`:void 0,dimColor:i,bold:r&&n,children:[i?``:n?`${a.pointer} `:` `,r?`[ ${e.label} ]`:e.label]})]},e.id)}),(0,N.jsx)(c,{marginTop:1,flexDirection:`column`,children:(0,N.jsx)(l,{dimColor:!0,children:v?`All tools selected`:`${_.size} of ${i.length} tools selected`})})]})}var M,N,br=e((()=>{i(),M=t(f(),1),te(),pt(),yt(),x(),vt(),de(),ge(),ye(),ze(),Ae(),be(),De(),Te(),pe(),$e(),Re(),ke(),h(),E(),v(),Rt(),N=_()}));function xr(e){return e===`all`?`Agents`:e===`built-in`?`Built-in agents`:e===`plugin`?`Plugin agents`:Kn(ee(e))}var Sr=e((()=>{qn(),S()}));function Cr({agent:e,tools:t,onSaved:n,onBack:r}){let i=He(),[o,s]=(0,P.useState)(`menu`),[u,f]=(0,P.useState)(0),[m,h]=(0,P.useState)(null),[g,_]=(0,P.useState)(e.color),v=(0,P.useCallback)(async()=>{let t=await cn($n(e));t.error?h(t.error):n(`Opened ${e.agentType} in editor. If you made edits, restart to load the latest version.`)},[e,n]),y=(0,P.useCallback)(async(t={})=>{let{tools:r,color:a,model:o}=t,s=a??g,c=r!==void 0,l=o!==void 0,u=s!==e.color;if(!c&&!l&&!u)return!1;try{return!Ge(e)&&!tt(e)?!1:(await ir(e,e.whenToUse,r??e.tools,e.getSystemPrompt(),s,o??e.model),u&&s&&Ie(e.agentType,s),i(t=>{let n=t.agentDefinitions.allAgents.map(t=>t.agentType===e.agentType?{...t,tools:r??t.tools,color:s,model:o??t.model}:t);return{...t,agentDefinitions:{...t.agentDefinitions,activeAgents:ct(n),allAgents:n}}}),n(`Updated agent: ${p.bold(e.agentType)}`),!0)}catch(e){return h(e instanceof Error?e.message:`Failed to save agent`),!1}},[e,g,n,i]),b=(0,P.useMemo)(()=>[{label:`Open in editor`,action:v},{label:`Edit tools`,action:()=>s(`edit-tools`)},{label:`Edit model`,action:()=>s(`edit-model`)},{label:`Edit color`,action:()=>s(`edit-color`)}],[v]),x=(0,P.useCallback)(()=>{h(null),o===`menu`?r():s(`menu`)},[o,r]),ee=(0,P.useCallback)(e=>{if(e.key===`up`)e.preventDefault(),f(e=>Math.max(0,e-1));else if(e.key===`down`)e.preventDefault(),f(e=>Math.min(b.length-1,e+1));else if(e.key===`return`){e.preventDefault();let t=b[u];t&&t.action()}},[b,u]);d(`confirm:no`,x,{context:`Confirmation`});let S=()=>(0,F.jsxs)(c,{flexDirection:`column`,tabIndex:0,autoFocus:!0,onKeyDown:ee,children:[(0,F.jsxs)(l,{dimColor:!0,children:[`Source: `,xr(e.source)]}),(0,F.jsx)(c,{marginTop:1,flexDirection:`column`,children:b.map((e,t)=>(0,F.jsxs)(l,{color:t===u?`suggestion`:void 0,children:[t===u?`${a.pointer} `:` `,e.label]},e.label))}),m&&(0,F.jsx)(c,{marginTop:1,children:(0,F.jsx)(l,{color:`error`,children:m})})]});switch(o){case`menu`:return S();case`edit-tools`:return(0,F.jsx)(yr,{tools:t,initialTools:e.tools,onComplete:async e=>{s(`menu`),await y({tools:e})}});case`edit-color`:return(0,F.jsx)(ur,{agentName:e.agentType,currentColor:g||e.color||`automatic`,onConfirm:async e=>{_(e),s(`menu`),await y({color:e})}});case`edit-model`:return(0,F.jsx)(pr,{initialModel:e.model,onComplete:async e=>{s(`menu`),await y({model:e})}});default:return null}}var P,F,wr=e((()=>{m(),i(),P=t(f(),1),Le(),h(),E(),gt(),at(),sn(),sr(),fr(),gr(),br(),Sr(),F=_()}));function Tr({instructions:e=`Press ↑↓ to navigate · Enter to select · Esc to go back`}){let t=Yt();return(0,Er.jsx)(c,{marginLeft:2,children:(0,Er.jsx)(l,{dimColor:!0,children:t.pending?`Press ${t.keyName} again to exit`:e})})}var Er,Dr=e((()=>{Xt(),h(),Er=_()}));function Or({source:e,agents:t,onBack:n,onSelect:r,onCreateNew:i,changes:s}){let[u,d]=kr.useState(null),[f,p]=kr.useState(!0),m=kr.useMemo(()=>[...t].sort(Gt),[t]),h=e=>({isOverridden:!!e.overriddenBy,overriddenBy:e.overriddenBy||null}),_=()=>(0,I.jsxs)(c,{children:[(0,I.jsx)(l,{color:f?`suggestion`:void 0,children:f?`${a.pointer} `:` `}),(0,I.jsx)(l,{color:f?`suggestion`:void 0,children:`Create new agent`})]}),v=e=>{let t=e.source===`built-in`,n=!t&&!f&&u?.agentType===e.agentType&&u?.source===e.source,{isOverridden:r,overriddenBy:i}=h(e),o=t||r,s=!t&&n?`suggestion`:void 0,d=Ut(e);return(0,I.jsxs)(c,{children:[(0,I.jsx)(l,{dimColor:o&&!n,color:s,children:t?``:n?`${a.pointer} `:` `}),(0,I.jsx)(l,{dimColor:o&&!n,color:s,children:e.agentType}),d&&(0,I.jsxs)(l,{dimColor:!0,color:s,children:[` · `,d]}),e.memory&&(0,I.jsxs)(l,{dimColor:!0,color:s,children:[` · `,e.memory,` memory`]}),i&&(0,I.jsxs)(l,{dimColor:!n,color:n?`warning`:void 0,children:[` `,a.warning,` shadowed by `,qt(i)]})]},`${e.agentType}-${e.source}`)},y=kr.useMemo(()=>{let t=m.filter(e=>e.source!==`built-in`);return e===`all`?Jt.filter(e=>e.source!==`built-in`).flatMap(({source:e})=>t.filter(t=>t.source===e)):t},[m,e]);kr.useEffect(()=>{!u&&!f&&y.length>0&&(i?p(!0):d(y[0]||null))},[y,u,f,i]);let x=e=>{if(e.key===`return`){e.preventDefault(),f&&i?i():u&&r(u);return}if(e.key!==`up`&&e.key!==`down`)return;e.preventDefault();let t=!!i,n=y.length+ +!!t;if(n===0)return;let a=0;if(!f&&u){let e=y.findIndex(e=>e.agentType===u.agentType&&e.source===u.source);e>=0&&(a=t?e+1:e)}let o=e.key===`up`?a===0?n-1:a-1:a===n-1?0:a+1;if(t&&o===0)p(!0),d(null);else{let e=t?o-1:o,n=y[e];n&&(p(!1),d(n))}},ee=(e=`Built-in (always available):`)=>{let t=m.filter(e=>e.source===`built-in`);return(0,I.jsxs)(c,{flexDirection:`column`,marginBottom:1,paddingLeft:2,children:[(0,I.jsx)(l,{bold:!0,dimColor:!0,children:e}),t.map(v)]})},S=(e,t)=>{if(!t.length)return null;let n=t[0]?.baseDir;return(0,I.jsxs)(c,{flexDirection:`column`,marginBottom:1,children:[(0,I.jsxs)(c,{paddingLeft:2,children:[(0,I.jsx)(l,{bold:!0,dimColor:!0,children:e}),n&&(0,I.jsxs)(l,{dimColor:!0,children:[` (`,n,`)`]})]}),t.map(e=>v(e))]})},te=xr(e),C=m.filter(e=>e.source===`built-in`);return!m.length||e!==`built-in`&&!m.some(e=>e.source!==`built-in`)?(0,I.jsx)(g,{title:te,subtitle:`No agents found`,onCancel:n,hideInputGuide:!0,children:(0,I.jsxs)(c,{flexDirection:`column`,gap:1,tabIndex:0,autoFocus:!0,onKeyDown:x,children:[i&&(0,I.jsx)(c,{children:_()}),(0,I.jsx)(l,{dimColor:!0,children:`No agents found. Create specialized subagents that Work Mate can delegate to.`}),(0,I.jsx)(l,{dimColor:!0,children:`Each subagent has its own context window, custom system prompt, and specific tools.`}),(0,I.jsx)(l,{dimColor:!0,children:`Try creating: Code Reviewer, Code Simplifier, Security Reviewer, Tech Lead, or UX Reviewer.`}),e!==`built-in`&&m.some(e=>e.source===`built-in`)&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(o,{}),ee()]})]})}):(0,I.jsxs)(g,{title:te,subtitle:`${b(m,e=>!e.overriddenBy)} agents`,onCancel:n,hideInputGuide:!0,children:[s&&s.length>0&&(0,I.jsx)(c,{marginTop:1,children:(0,I.jsx)(l,{dimColor:!0,children:s[s.length-1]})}),(0,I.jsxs)(c,{flexDirection:`column`,tabIndex:0,autoFocus:!0,onKeyDown:x,children:[i&&(0,I.jsx)(c,{marginBottom:1,children:_()}),e===`all`?(0,I.jsxs)(I.Fragment,{children:[Jt.filter(e=>e.source!==`built-in`).map(({label:e,source:t})=>(0,I.jsx)(kr.Fragment,{children:S(e,m.filter(e=>e.source===t))},t)),C.length>0&&(0,I.jsxs)(c,{flexDirection:`column`,marginBottom:1,paddingLeft:2,children:[(0,I.jsxs)(l,{dimColor:!0,children:[(0,I.jsx)(l,{bold:!0,children:`Built-in agents`}),` (always available)`]}),C.map(v)]})]}):e===`built-in`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(l,{dimColor:!0,italic:!0,children:`Built-in agents are provided by default and cannot be modified.`}),(0,I.jsx)(c,{marginTop:1,flexDirection:`column`,children:m.map(e=>v(e))})]}):(0,I.jsxs)(I.Fragment,{children:[m.filter(e=>e.source!==`built-in`).map(e=>v(e)),m.some(e=>e.source===`built-in`)&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(o,{}),ee()]})]})]})]})}var kr,I,Ar=e((()=>{i(),kr=t(f(),1),h(),Wt(),v(),Sr(),I=_()}));function jr({steps:e,initialData:t={},onComplete:n,onCancel:r,children:i,title:a,showStepCounter:o=!0}){let[s,c]=(0,L.useState)(0),[l,u]=(0,L.useState)(t),[d,f]=(0,L.useState)(!1),[p,m]=(0,L.useState)([]);Yt(),(0,L.useEffect)(()=>{d&&(m([]),n(l))},[d,l,n]);let h=(0,L.useCallback)(()=>{s<e.length-1?(p.length>0&&m(e=>[...e,s]),c(e=>e+1)):f(!0)},[s,e.length,p]),g=(0,L.useCallback)(()=>{if(p.length>0){let e=p[p.length-1];e!==void 0&&(m(e=>e.slice(0,-1)),c(e))}else s>0?c(e=>e-1):r&&r()},[s,p,r]),_=(0,L.useCallback)(t=>{t>=0&&t<e.length&&(m(e=>[...e,s]),c(t))},[s,e.length]),v=(0,L.useCallback)(()=>{m([]),r&&r()},[r]),y=(0,L.useCallback)(e=>{u(t=>({...t,...e}))},[]),b=(0,L.useMemo)(()=>({currentStepIndex:s,totalSteps:e.length,wizardData:l,setWizardData:u,updateWizardData:y,goNext:h,goBack:g,goToStep:_,cancel:v,title:a,showStepCounter:o}),[s,e.length,l,y,h,g,_,v,a,o]),x=e[s];return!x||d?null:(0,Mr.jsx)(Nr.Provider,{value:b,children:i||(0,Mr.jsx)(x,{})})}var L,Mr,Nr,Pr=e((()=>{L=t(f(),1),Xt(),Mr=_(),Nr=(0,L.createContext)(null)}));function R(){let e=(0,Fr.useContext)(Nr);if(!e)throw Error(`useWizard must be used within a WizardProvider`);return e}var Fr,Ir=e((()=>{Fr=t(f(),1),Pr()}));function Lr({instructions:e=(0,z.jsxs)(u,{children:[(0,z.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,z.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,z.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]})}){let t=Yt();return(0,z.jsx)(c,{marginLeft:3,marginTop:1,children:(0,z.jsx)(l,{dimColor:!0,children:t.pending?`Press ${t.keyName} again to exit`:e})})}var z,Rr=e((()=>{Xt(),h(),w(),z=_()}));function B({title:e,color:t=`suggestion`,children:n,subtitle:r,footerText:i}){let{currentStepIndex:a,totalSteps:o,title:s,showStepCounter:c,goBack:l}=R();return(0,zr.jsxs)(zr.Fragment,{children:[(0,zr.jsx)(g,{title:`${e||s||`Wizard`}${c===!1?``:` (${a+1}/${o})`}`,subtitle:r,onCancel:l,color:t,hideInputGuide:!0,isCancelActive:!1,children:n}),(0,zr.jsx)(Lr,{instructions:i})]})}var zr,V=e((()=>{h(),Ir(),Rr(),zr=_()})),H=e((()=>{Ir(),V(),Rr(),Pr()}));function Br(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R();return d(`confirm:no`,t,{context:`Confirmation`}),(0,U.jsx)(B,{subtitle:`Choose background color`,footerText:(0,U.jsxs)(u,{children:[(0,U.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,U.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,U.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,U.jsx)(c,{children:(0,U.jsx)(ur,{agentName:r.agentType||`agent`,currentColor:`automatic`,onConfirm:t=>{n({selectedColor:t,finalAgent:{agentType:r.agentType,whenToUse:r.whenToUse,getSystemPrompt:()=>r.systemPrompt,tools:r.selectedTools,...r.selectedModel?{model:r.selectedModel}:{},...t?{color:t}:{},source:r.location}}),e()}})})})}var U,Vr=e((()=>{h(),E(),w(),H(),V(),fr(),U=_()}));function Hr(e){return e?/^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$/.test(e)?e.length<3?`Agent type must be at least 3 characters long`:e.length>50?`Agent type must be less than 50 characters`:null:`Agent type must start and end with alphanumeric characters and contain only letters, numbers, and hyphens`:`Agent type is required`}function Ur(e,t,n){let r=[],i=[];if(!e.agentType)r.push(`Agent type is required`);else{let t=Hr(e.agentType);t&&r.push(t);let i=n.find(t=>t.agentType===e.agentType&&t.source!==e.source);i&&r.push(`Agent type "${e.agentType}" already exists in ${xr(i.source)}`)}if(e.whenToUse?e.whenToUse.length<10?i.push(`Description should be more descriptive (at least 10 characters)`):e.whenToUse.length>5e3&&i.push(`Description is very long (over 5000 characters)`):r.push(`Description (description) is required`),e.tools!==void 0&&!Array.isArray(e.tools))r.push(`Tools must be an array`);else{e.tools===void 0?i.push(`Agent has access to all tools`):e.tools.length===0&&i.push(`No tools selected - agent will have very limited capabilities`);let n=We(e,t,!1);n.invalidTools.length>0&&r.push(`Invalid tools: ${n.invalidTools.join(`, `)}`)}let a=e.getSystemPrompt();return a?a.length<20?r.push(`System prompt is too short (minimum 20 characters)`):a.length>1e4&&i.push(`System prompt is very long (over 10,000 characters)`):r.push(`System prompt is required`),{isValid:r.length===0,errors:r,warnings:i}}var Wr=e((()=>{yt(),Sr()}));function Gr({tools:e,existingAgents:t,onSave:n,onSaveAndEdit:r,error:i}){let{goBack:a,wizardData:o}=R();d(`confirm:no`,a,{context:`Confirmation`});let f=e=>{e.key===`s`||e.key===`return`?(e.preventDefault(),n()):e.key===`e`&&(e.preventDefault(),r())},p=o.finalAgent,m=Ur(p,e,t),h=Pt(p.getSystemPrompt(),240),g=Pt(p.whenToUse,240),_=e=>e===void 0?`All tools`:e.length===0?`None`:e.length===1?e[0]||`None`:e.length===2?e.join(` and `):`${e.slice(0,-1).join(`, `)}, and ${e[e.length-1]}`,v=At()?(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Memory`}),`: `,nt(p.memory)]}):null;return(0,W.jsx)(B,{subtitle:`Confirm and save`,footerText:(0,W.jsxs)(u,{children:[(0,W.jsx)(s,{shortcut:`s/Enter`,action:`save`}),(0,W.jsx)(s,{shortcut:`e`,action:`edit in your editor`}),(0,W.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`cancel`})]}),children:(0,W.jsxs)(c,{flexDirection:`column`,tabIndex:0,autoFocus:!0,onKeyDown:f,children:[(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Name`}),`: `,p.agentType]}),(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Location`}),`:`,` `,er({source:o.location,agentType:p.agentType})]}),(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Tools`}),`: `,_(p.tools)]}),(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Model`}),`: `,et(p.model)]}),v,(0,W.jsx)(c,{marginTop:1,children:(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`Description`}),` (tells Work Mate when to use this agent):`]})}),(0,W.jsx)(c,{marginLeft:2,marginTop:1,children:(0,W.jsx)(l,{children:g})}),(0,W.jsx)(c,{marginTop:1,children:(0,W.jsxs)(l,{children:[(0,W.jsx)(l,{bold:!0,children:`System prompt`}),`:`]})}),(0,W.jsx)(c,{marginLeft:2,marginTop:1,children:(0,W.jsx)(l,{children:h})}),m.warnings.length>0&&(0,W.jsxs)(c,{marginTop:1,flexDirection:`column`,children:[(0,W.jsx)(l,{color:`warning`,children:`Warnings:`}),m.warnings.map((e,t)=>(0,W.jsxs)(l,{dimColor:!0,children:[` `,`• `,e]},t))]}),m.errors.length>0&&(0,W.jsxs)(c,{marginTop:1,flexDirection:`column`,children:[(0,W.jsx)(l,{color:`error`,children:`Errors:`}),m.errors.map((e,t)=>(0,W.jsxs)(l,{color:`error`,children:[` `,`• `,e]},t))]}),i&&(0,W.jsx)(c,{marginTop:1,children:(0,W.jsx)(l,{color:`error`,children:i})}),(0,W.jsx)(c,{marginTop:2,children:(0,W.jsxs)(l,{color:`success`,children:[`Press `,(0,W.jsx)(l,{bold:!0,children:`s`}),` or `,(0,W.jsx)(l,{bold:!0,children:`Enter`}),` to save, `,(0,W.jsx)(l,{bold:!0,children:`e`}),` to save and edit`]})})]})})}var W,Kr=e((()=>{h(),E(),kt(),Xe(),Ft(),Se(),w(),H(),V(),sr(),Wr(),W=_()}));function qr({tools:e,existingAgents:t,onComplete:n}){let{wizardData:r}=R(),[i,a]=(0,Jr.useState)(null),o=He(),s=(0,Jr.useCallback)(async e=>{if(r?.finalAgent)try{await rr(r.location,r.finalAgent.agentType,r.finalAgent.whenToUse,r.finalAgent.tools,r.finalAgent.getSystemPrompt(),!0,r.finalAgent.color,r.finalAgent.model,r.finalAgent.memory),o(e=>{if(!r.finalAgent)return e;let t=e.agentDefinitions.allAgents.concat(r.finalAgent);return{...e,agentDefinitions:{...e.agentDefinitions,activeAgents:ct(t),allAgents:t}}}),dt(),e&&await cn(Qn({source:r.location,agentType:r.finalAgent.agentType})),r.finalAgent.agentType,r.wasGenerated,r.location,r.finalAgent.tools?.length,r.finalAgent.model,r.finalAgent.color,r.finalAgent.memory,r.finalAgent.memory,{...e?{opened_in_editor:!0}:{}},n(e?`Created agent: ${p.bold(r.finalAgent.agentType)} and opened in editor. If you made edits, restart to load the latest version.`:`Created agent: ${p.bold(r.finalAgent.agentType)}`)}catch(e){a(e instanceof Error?e.message:`Failed to save agent`)}},[r,n,o]);return(0,Yr.jsx)(Gr,{tools:e,existingAgents:t,onSave:(0,Jr.useCallback)(()=>s(!1),[s]),onSaveAndEdit:(0,Jr.useCallback)(()=>s(!0),[s]),error:i})}var Jr,Yr,Xr=e((()=>{m(),Jr=t(f(),1),Nt(),Le(),at(),sn(),H(),sr(),Kr(),Yr=_()}));function Zr(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R(),[i,a]=(0,Qr.useState)(r.whenToUse||``),[o,f]=(0,Qr.useState)(i.length),[p,m]=(0,Qr.useState)(null);return d(`confirm:no`,t,{context:`Settings`}),d(`chat:externalEditor`,(0,Qr.useCallback)(async()=>{let e=await on(i);e.content!==null&&(a(e.content),f(e.content.length))},[i]),{context:`Chat`}),(0,G.jsx)(B,{subtitle:`Description (tell Work Mate when to use this agent)`,footerText:(0,G.jsxs)(u,{children:[(0,G.jsx)(s,{shortcut:`Type`,action:`enter text`}),(0,G.jsx)(s,{shortcut:`Enter`,action:`continue`}),(0,G.jsx)(T,{action:`chat:externalEditor`,context:`Chat`,fallback:`ctrl+g`,description:`open in editor`}),(0,G.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,G.jsxs)(c,{flexDirection:`column`,children:[(0,G.jsx)(l,{children:`When should Work Mate use this agent?`}),(0,G.jsx)(c,{marginTop:1,children:(0,G.jsx)(Qt,{value:i,onChange:a,onSubmit:t=>{let r=t.trim();if(!r){m(`Description is required`);return}m(null),n({whenToUse:r}),e()},placeholder:`e.g., use this agent after you're done writing code...`,columns:80,cursorOffset:o,onChangeCursorOffset:f,focus:!0,showCursor:!0})}),p&&(0,G.jsx)(c,{marginTop:1,children:(0,G.jsx)(l,{color:`error`,children:p})})]})})}var Qr,G,$r=e((()=>{Qr=t(f(),1),h(),E(),sn(),w(),Zt(),H(),V(),G=_()}));async function ei(e,t,n,r){let i=ft({content:`Create an agent configuration based on this request: "${e}".${n.length>0?`\n\nIMPORTANT: The following identifiers already exist and must NOT be used: ${n.join(`, `)}`:``}
8
+ Return ONLY the JSON object, no other text.`}),a=await xe(),o=Ze([i],a),s=At()?ti+ni:ti,c=await qe({messages:Je(o),systemPrompt:st([s]),thinkingConfig:{type:`disabled`},tools:[],signal:r,options:{getToolPermissionContext:async()=>zt(),model:t,toolChoice:void 0,agents:[],isNonInteractiveSession:!1,hasAppendSystemPrompt:!1,querySource:`agent_creation`,mcpTools:[]}}),l=(Array.isArray(c.message.content)?c.message.content:[]).filter(e=>e.type===`text`).map(e=>e.text).join(`
9
+ `),u;try{u=Tt(l.trim())}catch{let e=l.match(/\{[\s\S]*\}/);if(!e)throw Error(`No JSON object found in response`);u=Tt(e[0])}if(!u.identifier||!u.whenToUse||!u.systemPrompt)throw Error(`Invalid agent configuration generated`);return u.identifier,{identifier:u.identifier,whenToUse:u.whenToUse,systemPrompt:u.systemPrompt}}var ti,ni,ri=e((()=>{Ne(),Me(),Bt(),x(),it(),Ue(),kt(),Nt(),Ot(),lt(),ti=`You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.
10
10
 
11
11
  **Important Context**: You may have access to project-specific instructions from AGENTS.md files and other context that may include coding standards, project structure, and custom requirements. Consider this context when creating agents to ensure they align with the project's established patterns and practices.
12
12
 
@@ -97,5 +97,5 @@ Remember: The agents you create should be autonomous experts capable of handling
97
97
  - For a documentation writer: "Update your agent memory as you discover documentation patterns, API structures, and terminology conventions."
98
98
 
99
99
  The memory instructions should be specific to what the agent would naturally learn while performing its core tasks.
100
- `}));function ii(){let{updateWizardData:e,goBack:t,goToStep:n,wizardData:r}=R(),[i,a]=(0,K.useState)(r.generationPrompt||``),[o,s]=(0,K.useState)(!1),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(i.length),g=ln(),_=(0,K.useRef)(null);d(`confirm:no`,(0,K.useCallback)(()=>{_.current&&(_.current.abort(),_.current=null,s(!1),p(`Generation cancelled`))},[]),{context:`Settings`,isActive:o}),d(`chat:externalEditor`,(0,K.useCallback)(async()=>{let e=await on(i);e.content!==null&&(a(e.content),h(e.content.length))},[i]),{context:`Chat`,isActive:!o}),d(`confirm:no`,(0,K.useCallback)(()=>{e({generationPrompt:``,agentType:``,systemPrompt:``,whenToUse:``,generatedAgent:void 0,wasGenerated:!1}),a(``),p(null),t()},[e,t]),{context:`Settings`,isActive:!o});let v=async()=>{let t=i.trim();if(!t){p(`Please describe what the agent should do`);return}p(null),s(!0),e({generationPrompt:t,isGenerating:!0});let r=vt();_.current=r;try{let i=await ei(t,g,[],r.signal);e({agentType:i.identifier,whenToUse:i.whenToUse,systemPrompt:i.systemPrompt,generatedAgent:i,isGenerating:!1,wasGenerated:!0}),n(6)}catch(t){t instanceof Dt||t instanceof Error&&!t.message.includes(`No assistant message found`)&&p(t.message||`Failed to generate agent`),e({isGenerating:!1})}finally{s(!1),_.current=null}},y=`Describe what this agent should do and when it should be used (be comprehensive for best results)`;return o?(0,q.jsx)(B,{subtitle:y,footerText:(0,q.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`cancel`}),children:(0,q.jsxs)(c,{flexDirection:`row`,alignItems:`center`,children:[(0,q.jsx)(nn,{}),(0,q.jsx)(l,{color:`suggestion`,children:` Generating agent from description...`})]})}):(0,q.jsx)(B,{subtitle:y,footerText:(0,q.jsxs)(u,{children:[(0,q.jsx)(T,{action:`confirm:yes`,context:`Confirmation`,fallback:`Enter`,description:`submit`}),(0,q.jsx)(T,{action:`chat:externalEditor`,context:`Chat`,fallback:`ctrl+g`,description:`open in editor`}),(0,q.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,q.jsxs)(c,{flexDirection:`column`,children:[f&&(0,q.jsx)(c,{marginBottom:1,children:(0,q.jsx)(l,{color:`error`,children:f})}),(0,q.jsx)(Qt,{value:i,onChange:a,onSubmit:v,placeholder:`e.g., Help me write unit tests for my code...`,columns:80,cursorOffset:m,onChangeCursorOffset:h,focus:!0,showCursor:!0})]})})}var K,q,ai=e((()=>{St(),K=t(f(),1),un(),h(),E(),de(),sn(),w(),tn(),Zt(),H(),V(),ri(),q=_()}));function oi(){let{goNext:e,updateWizardData:t,cancel:n}=R();return(0,J.jsx)(B,{subtitle:`Choose location`,footerText:(0,J.jsxs)(u,{children:[(0,J.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,J.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,J.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`cancel`})]}),children:(0,J.jsx)(c,{children:(0,J.jsx)(en,{options:[{label:`Project (.workmate/agents/)`,value:`projectSettings`},{label:`Personal (~/.workmate/agents/)`,value:`userSettings`}],onChange:n=>{t({location:n}),e()},onCancel:()=>n()},`location-select`)})})}var J,si=e((()=>{h(),w(),$t(),H(),V(),J=_()}));function ci(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R();d(`confirm:no`,t,{context:`Confirmation`});let i=r.location===`userSettings`?[{label:`User scope (~/.workmate/agent-memory/) (Recommended)`,value:`user`},{label:`None (no persistent memory)`,value:`none`},{label:`Project scope (.workmate/agent-memory/)`,value:`project`},{label:`Local scope (.workmate/agent-memory-local/)`,value:`local`}]:[{label:`Project scope (.workmate/agent-memory/) (Recommended)`,value:`project`},{label:`None (no persistent memory)`,value:`none`},{label:`User scope (~/.workmate/agent-memory/)`,value:`user`},{label:`Local scope (.workmate/agent-memory-local/)`,value:`local`}];return(0,Y.jsx)(B,{subtitle:`Configure agent memory`,footerText:(0,Y.jsxs)(u,{children:[(0,Y.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,Y.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,Y.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,Y.jsx)(c,{children:(0,Y.jsx)(en,{options:i,onChange:t=>{let i=t===`none`?void 0:t,a=r.finalAgent?.agentType;n({selectedMemory:i,finalAgent:r.finalAgent?{...r.finalAgent,memory:i,getSystemPrompt:At()&&i&&a?()=>`${r.systemPrompt}\n\n${tt(a,i)}`:()=>r.systemPrompt}:void 0}),e()},onCancel:t},`memory-select`)})})}var Y,li=e((()=>{h(),E(),kt(),it(),w(),$t(),H(),V(),Y=_()}));function ui(){let{goNext:e,goBack:t,updateWizardData:n,goToStep:r}=R();return(0,X.jsx)(B,{subtitle:`Creation method`,footerText:(0,X.jsxs)(u,{children:[(0,X.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,X.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,X.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,X.jsx)(c,{children:(0,X.jsx)(en,{options:[{label:`Generate with Work Mate (recommended)`,value:`generate`},{label:`Manual configuration`,value:`manual`}],onChange:t=>{let i=t;n({method:i,wasGenerated:i===`generate`}),i===`generate`?e():r(3)},onCancel:()=>t()},`method-select`)})})}var X,di=e((()=>{h(),w(),$t(),H(),V(),X=_()}));function fi(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R();return(0,pi.jsx)(B,{subtitle:`Select model`,footerText:(0,pi.jsxs)(u,{children:[(0,pi.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,pi.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,pi.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,pi.jsx)(pr,{initialModel:r.selectedModel,onComplete:t=>{n({selectedModel:t}),e()},onCancel:t})})}var pi,mi=e((()=>{w(),h(),H(),V(),gr(),pi=_()}));function hi(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R(),[i,a]=(0,gi.useState)(r.systemPrompt||``),[o,f]=(0,gi.useState)(i.length),[p,m]=(0,gi.useState)(null);return d(`confirm:no`,t,{context:`Settings`}),d(`chat:externalEditor`,(0,gi.useCallback)(async()=>{let e=await on(i);e.content!==null&&(a(e.content),f(e.content.length))},[i]),{context:`Chat`}),(0,Z.jsx)(B,{subtitle:`System prompt`,footerText:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(s,{shortcut:`Type`,action:`enter text`}),(0,Z.jsx)(s,{shortcut:`Enter`,action:`continue`}),(0,Z.jsx)(T,{action:`chat:externalEditor`,context:`Chat`,fallback:`ctrl+g`,description:`open in editor`}),(0,Z.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,Z.jsxs)(c,{flexDirection:`column`,children:[(0,Z.jsx)(l,{children:`Enter the system prompt for your agent:`}),(0,Z.jsx)(l,{dimColor:!0,children:`Be comprehensive for best results`}),(0,Z.jsx)(c,{marginTop:1,children:(0,Z.jsx)(Qt,{value:i,onChange:a,onSubmit:()=>{let t=i.trim();if(!t){m(`System prompt is required`);return}m(null),n({systemPrompt:t}),e()},placeholder:`You are a helpful code reviewer who...`,columns:80,cursorOffset:o,onChangeCursorOffset:f,focus:!0,showCursor:!0})}),p&&(0,Z.jsx)(c,{marginTop:1,children:(0,Z.jsx)(l,{color:`error`,children:p})})]})})}var gi,Z,_i=e((()=>{gi=t(f(),1),h(),E(),sn(),w(),Zt(),H(),V(),Z=_()}));function vi({tools:e}){let{goNext:t,goBack:n,updateWizardData:r,wizardData:i}=R(),a=e=>{r({selectedTools:e}),t()},o=i.selectedTools;return(0,yi.jsx)(B,{subtitle:`Select tools`,footerText:(0,yi.jsxs)(u,{children:[(0,yi.jsx)(s,{shortcut:`Enter`,action:`toggle selection`}),(0,yi.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,yi.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,yi.jsx)(yr,{tools:e,initialTools:o,onComplete:a,onCancel:n})})}var yi,bi=e((()=>{h(),w(),H(),V(),br(),yi=_()}));function xi(e){let{goNext:t,goBack:n,updateWizardData:r,wizardData:i}=R(),[a,o]=(0,Si.useState)(i.agentType||``),[f,p]=(0,Si.useState)(null),[m,h]=(0,Si.useState)(a.length);return d(`confirm:no`,n,{context:`Settings`}),(0,Q.jsx)(B,{subtitle:`Agent type (identifier)`,footerText:(0,Q.jsxs)(u,{children:[(0,Q.jsx)(s,{shortcut:`Type`,action:`enter text`}),(0,Q.jsx)(s,{shortcut:`Enter`,action:`continue`}),(0,Q.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,Q.jsxs)(c,{flexDirection:`column`,children:[(0,Q.jsx)(l,{children:`Enter a unique identifier for your agent:`}),(0,Q.jsx)(c,{marginTop:1,children:(0,Q.jsx)(Qt,{value:a,onChange:o,onSubmit:e=>{let n=e.trim(),i=Hr(n);if(i){p(i);return}p(null),r({agentType:n}),t()},placeholder:`e.g., test-runner, tech-lead, etc`,columns:60,cursorOffset:m,onChangeCursorOffset:h,focus:!0,showCursor:!0})}),f&&(0,Q.jsx)(c,{marginTop:1,children:(0,Q.jsx)(l,{color:`error`,children:f})})]})})}var Si,Q,Ci=e((()=>{Si=t(f(),1),h(),E(),w(),Zt(),H(),V(),Wr(),Q=_()}));function wi({tools:e,existingAgents:t,onComplete:n,onCancel:r}){return(0,Ti.jsx)(jr,{steps:[oi,ui,ii,()=>(0,Ti.jsx)(xi,{existingAgents:t}),hi,Zr,()=>(0,Ti.jsx)(vi,{tools:e}),fi,Br,...At()?[ci]:[],()=>(0,Ti.jsx)(qr,{tools:e,existingAgents:t,onComplete:n})],initialData:{},onComplete:()=>{},onCancel:r,title:`Create new agent`,showStepCounter:!1})}var Ti,Ei=e((()=>{kt(),H(),Vr(),Xr(),$r(),ai(),si(),li(),di(),mi(),_i(),bi(),Ci(),Ti=_()}));function Di({tools:e,onExit:t}){let[n,r]=(0,Oi.useState)({mode:`list-agents`,source:`all`}),i=ue(e=>e.agentDefinitions),a=ue(e=>e.mcp.tools),o=ue(e=>e.toolPermissionContext),s=we(),{allAgents:u,activeAgents:d}=i,[f,m]=(0,Oi.useState)([]),h=rn(e,a,o);Yt();let _=(0,Oi.useMemo)(()=>({"built-in":u.filter(e=>e.source===`built-in`),userSettings:u.filter(e=>e.source===`userSettings`),projectSettings:u.filter(e=>e.source===`projectSettings`),policySettings:u.filter(e=>e.source===`policySettings`),localSettings:u.filter(e=>e.source===`localSettings`),flagSettings:u.filter(e=>e.source===`flagSettings`),plugin:u.filter(e=>e.source===`plugin`),all:u}),[u]),v=(0,Oi.useCallback)(e=>{m(t=>[...t,e]),r({mode:`list-agents`,source:`all`})},[]),y=(0,Oi.useCallback)(async e=>{try{await ar(e),s(t=>{let n=t.agentDefinitions.allAgents.filter(t=>!(t.agentType===e.agentType&&t.source===e.source));return{...t,agentDefinitions:{...t.agentDefinitions,allAgents:n,activeAgents:at(n)}}}),m(t=>[...t,`Deleted agent: ${p.bold(e.agentType)}`]),r({mode:`list-agents`,source:`all`})}catch(e){Mt(Et(e))}},[s]);switch(n.mode){case`list-agents`:{let e=Kt(n.source===`all`?[..._[`built-in`],..._.userSettings,..._.projectSettings,..._.localSettings,..._.policySettings,..._.flagSettings,..._.plugin]:_[n.source],d);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Or,{source:n.source,agents:e,onBack:()=>{t((f.length>0?`Agent changes:\n${f.join(`
101
- `)}`:void 0)??`Agents dialog dismissed`,{display:f.length===0?`system`:void 0})},onSelect:e=>r({mode:`agent-menu`,agent:e,previousMode:n}),onCreateNew:()=>r({mode:`create-agent`}),changes:f}),(0,$.jsx)(Tr,{})]})}case`create-agent`:return(0,$.jsx)(wi,{tools:h,existingAgents:d,onComplete:v,onCancel:()=>r({mode:`list-agents`,source:`all`})});case`agent-menu`:{let e=u.find(e=>e.agentType===n.agent.agentType&&e.source===n.agent.source)||n.agent,t=[{label:`View agent`,value:`view`},...e.source!==`built-in`&&e.source!==`plugin`&&e.source!==`flagSettings`?[{label:`Edit agent`,value:`edit`},{label:`Delete agent`,value:`delete`}]:[],{label:`Back`,value:`back`}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{title:n.agent.agentType,onCancel:()=>r(n.previousMode),hideInputGuide:!0,children:(0,$.jsxs)(c,{flexDirection:`column`,children:[(0,$.jsx)(en,{options:t,onChange:t=>{switch(t){case`view`:r({mode:`view-agent`,agent:e,previousMode:n.previousMode});break;case`edit`:r({mode:`edit-agent`,agent:e,previousMode:n});break;case`delete`:r({mode:`delete-confirm`,agent:e,previousMode:n});break;case`back`:r(n.previousMode);break}},onCancel:()=>r(n.previousMode)}),f.length>0&&(0,$.jsx)(c,{marginTop:1,children:(0,$.jsx)(l,{dimColor:!0,children:f[f.length-1]})})]})}),(0,$.jsx)(Tr,{})]})}case`view-agent`:{let e=u.find(e=>e.agentType===n.agent.agentType&&e.source===n.agent.source)||n.agent;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{title:e.agentType,onCancel:()=>r({mode:`agent-menu`,agent:e,previousMode:n.previousMode}),hideInputGuide:!0,children:(0,$.jsx)(cr,{agent:e,tools:h,allAgents:u,onBack:()=>r({mode:`agent-menu`,agent:e,previousMode:n.previousMode})})}),(0,$.jsx)(Tr,{instructions:`Press Enter or Esc to go back`})]})}case`delete-confirm`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(g,{title:`Delete agent`,onCancel:()=>{`previousMode`in n&&r(n.previousMode)},color:`error`,children:[(0,$.jsxs)(l,{children:[`Are you sure you want to delete the agent `,(0,$.jsx)(l,{bold:!0,children:n.agent.agentType}),`?`]}),(0,$.jsx)(c,{marginTop:1,children:(0,$.jsxs)(l,{dimColor:!0,children:[`Source: `,n.agent.source]})}),(0,$.jsx)(c,{marginTop:1,children:(0,$.jsx)(en,{options:[{label:`Yes, delete`,value:`yes`},{label:`No, cancel`,value:`no`}],onChange:e=>{e===`yes`?y(n.agent):`previousMode`in n&&r(n.previousMode)},onCancel:()=>{`previousMode`in n&&r(n.previousMode)}})})]}),(0,$.jsx)(Tr,{instructions:`Press ↑↓ to navigate, Enter to select, Esc to cancel`})]});case`edit-agent`:{let e=u.find(e=>e.agentType===n.agent.agentType&&e.source===n.agent.source)||n.agent;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{title:`Edit agent: ${e.agentType}`,onCancel:()=>r(n.previousMode),hideInputGuide:!0,children:(0,$.jsx)(Cr,{agent:e,tools:h,onSaved:e=>{v(e),r(n.previousMode)},onBack:()=>r(n.previousMode)})}),(0,$.jsx)(Tr,{})]})}default:return null}}var Oi,$,ki=e((()=>{m(),Oi=t(f(),1),Xt(),an(),h(),ht(),Wt(),rt(),Ct(),jt(),$t(),lr(),wr(),Dr(),Ar(),sr(),Ei(),$=_()}));async function Ai(e,t){let n=t.getAppState().toolPermissionContext;return(0,ji.jsx)(Di,{tools:ve(n),onExit:e})}var ji;e((()=>{ki(),he(),ji=_()}))();export{Ai as call};
100
+ `}));function ii(){let{updateWizardData:e,goBack:t,goToStep:n,wizardData:r}=R(),[i,a]=(0,K.useState)(r.generationPrompt||``),[o,s]=(0,K.useState)(!1),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(i.length),g=ln(),_=(0,K.useRef)(null);d(`confirm:no`,(0,K.useCallback)(()=>{_.current&&(_.current.abort(),_.current=null,s(!1),p(`Generation cancelled`))},[]),{context:`Settings`,isActive:o}),d(`chat:externalEditor`,(0,K.useCallback)(async()=>{let e=await on(i);e.content!==null&&(a(e.content),h(e.content.length))},[i]),{context:`Chat`,isActive:!o}),d(`confirm:no`,(0,K.useCallback)(()=>{e({generationPrompt:``,agentType:``,systemPrompt:``,whenToUse:``,generatedAgent:void 0,wasGenerated:!1}),a(``),p(null),t()},[e,t]),{context:`Settings`,isActive:!o});let v=async()=>{let t=i.trim();if(!t){p(`Please describe what the agent should do`);return}p(null),s(!0),e({generationPrompt:t,isGenerating:!0});let r=Be();_.current=r;try{let i=await ei(t,g,[],r.signal);e({agentType:i.identifier,whenToUse:i.whenToUse,systemPrompt:i.systemPrompt,generatedAgent:i,isGenerating:!1,wasGenerated:!0}),n(6)}catch(t){t instanceof Dt||t instanceof Error&&!t.message.includes(`No assistant message found`)&&p(t.message||`Failed to generate agent`),e({isGenerating:!1})}finally{s(!1),_.current=null}},y=`Describe what this agent should do and when it should be used (be comprehensive for best results)`;return o?(0,q.jsx)(B,{subtitle:y,footerText:(0,q.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`cancel`}),children:(0,q.jsxs)(c,{flexDirection:`row`,alignItems:`center`,children:[(0,q.jsx)(nn,{}),(0,q.jsx)(l,{color:`suggestion`,children:` Generating agent from description...`})]})}):(0,q.jsx)(B,{subtitle:y,footerText:(0,q.jsxs)(u,{children:[(0,q.jsx)(T,{action:`confirm:yes`,context:`Confirmation`,fallback:`Enter`,description:`submit`}),(0,q.jsx)(T,{action:`chat:externalEditor`,context:`Chat`,fallback:`ctrl+g`,description:`open in editor`}),(0,q.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,q.jsxs)(c,{flexDirection:`column`,children:[f&&(0,q.jsx)(c,{marginBottom:1,children:(0,q.jsx)(l,{color:`error`,children:f})}),(0,q.jsx)(Qt,{value:i,onChange:a,onSubmit:v,placeholder:`e.g., Help me write unit tests for my code...`,columns:80,cursorOffset:m,onChangeCursorOffset:h,focus:!0,showCursor:!0})]})})}var K,q,ai=e((()=>{St(),K=t(f(),1),un(),h(),E(),ve(),sn(),w(),tn(),Zt(),H(),V(),ri(),q=_()}));function oi(){let{goNext:e,updateWizardData:t,cancel:n}=R();return(0,J.jsx)(B,{subtitle:`Choose location`,footerText:(0,J.jsxs)(u,{children:[(0,J.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,J.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,J.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`cancel`})]}),children:(0,J.jsx)(c,{children:(0,J.jsx)(en,{options:[{label:`Project (.workmate/agents/)`,value:`projectSettings`},{label:`Personal (~/.workmate/agents/)`,value:`userSettings`}],onChange:n=>{t({location:n}),e()},onCancel:()=>n()},`location-select`)})})}var J,si=e((()=>{h(),w(),$t(),H(),V(),J=_()}));function ci(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R();d(`confirm:no`,t,{context:`Confirmation`});let i=r.location===`userSettings`?[{label:`User scope (~/.workmate/agent-memory/) (Recommended)`,value:`user`},{label:`None (no persistent memory)`,value:`none`},{label:`Project scope (.workmate/agent-memory/)`,value:`project`},{label:`Local scope (.workmate/agent-memory-local/)`,value:`local`}]:[{label:`Project scope (.workmate/agent-memory/) (Recommended)`,value:`project`},{label:`None (no persistent memory)`,value:`none`},{label:`User scope (~/.workmate/agent-memory/)`,value:`user`},{label:`Local scope (.workmate/agent-memory-local/)`,value:`local`}];return(0,Y.jsx)(B,{subtitle:`Configure agent memory`,footerText:(0,Y.jsxs)(u,{children:[(0,Y.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,Y.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,Y.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,Y.jsx)(c,{children:(0,Y.jsx)(en,{options:i,onChange:t=>{let i=t===`none`?void 0:t,a=r.finalAgent?.agentType;n({selectedMemory:i,finalAgent:r.finalAgent?{...r.finalAgent,memory:i,getSystemPrompt:At()&&i&&a?()=>`${r.systemPrompt}\n\n${Ye(a,i)}`:()=>r.systemPrompt}:void 0}),e()},onCancel:t},`memory-select`)})})}var Y,li=e((()=>{h(),E(),kt(),Xe(),w(),$t(),H(),V(),Y=_()}));function ui(){let{goNext:e,goBack:t,updateWizardData:n,goToStep:r}=R();return(0,X.jsx)(B,{subtitle:`Creation method`,footerText:(0,X.jsxs)(u,{children:[(0,X.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,X.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,X.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,X.jsx)(c,{children:(0,X.jsx)(en,{options:[{label:`Generate with Work Mate (recommended)`,value:`generate`},{label:`Manual configuration`,value:`manual`}],onChange:t=>{let i=t;n({method:i,wasGenerated:i===`generate`}),i===`generate`?e():r(3)},onCancel:()=>t()},`method-select`)})})}var X,di=e((()=>{h(),w(),$t(),H(),V(),X=_()}));function fi(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R();return(0,pi.jsx)(B,{subtitle:`Select model`,footerText:(0,pi.jsxs)(u,{children:[(0,pi.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,pi.jsx)(s,{shortcut:`Enter`,action:`select`}),(0,pi.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,pi.jsx)(pr,{initialModel:r.selectedModel,onComplete:t=>{n({selectedModel:t}),e()},onCancel:t})})}var pi,mi=e((()=>{w(),h(),H(),V(),gr(),pi=_()}));function hi(){let{goNext:e,goBack:t,updateWizardData:n,wizardData:r}=R(),[i,a]=(0,gi.useState)(r.systemPrompt||``),[o,f]=(0,gi.useState)(i.length),[p,m]=(0,gi.useState)(null);return d(`confirm:no`,t,{context:`Settings`}),d(`chat:externalEditor`,(0,gi.useCallback)(async()=>{let e=await on(i);e.content!==null&&(a(e.content),f(e.content.length))},[i]),{context:`Chat`}),(0,Z.jsx)(B,{subtitle:`System prompt`,footerText:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(s,{shortcut:`Type`,action:`enter text`}),(0,Z.jsx)(s,{shortcut:`Enter`,action:`continue`}),(0,Z.jsx)(T,{action:`chat:externalEditor`,context:`Chat`,fallback:`ctrl+g`,description:`open in editor`}),(0,Z.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,Z.jsxs)(c,{flexDirection:`column`,children:[(0,Z.jsx)(l,{children:`Enter the system prompt for your agent:`}),(0,Z.jsx)(l,{dimColor:!0,children:`Be comprehensive for best results`}),(0,Z.jsx)(c,{marginTop:1,children:(0,Z.jsx)(Qt,{value:i,onChange:a,onSubmit:()=>{let t=i.trim();if(!t){m(`System prompt is required`);return}m(null),n({systemPrompt:t}),e()},placeholder:`You are a helpful code reviewer who...`,columns:80,cursorOffset:o,onChangeCursorOffset:f,focus:!0,showCursor:!0})}),p&&(0,Z.jsx)(c,{marginTop:1,children:(0,Z.jsx)(l,{color:`error`,children:p})})]})})}var gi,Z,_i=e((()=>{gi=t(f(),1),h(),E(),sn(),w(),Zt(),H(),V(),Z=_()}));function vi({tools:e}){let{goNext:t,goBack:n,updateWizardData:r,wizardData:i}=R(),a=e=>{r({selectedTools:e}),t()},o=i.selectedTools;return(0,yi.jsx)(B,{subtitle:`Select tools`,footerText:(0,yi.jsxs)(u,{children:[(0,yi.jsx)(s,{shortcut:`Enter`,action:`toggle selection`}),(0,yi.jsx)(s,{shortcut:`↑↓`,action:`navigate`}),(0,yi.jsx)(T,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`go back`})]}),children:(0,yi.jsx)(yr,{tools:e,initialTools:o,onComplete:a,onCancel:n})})}var yi,bi=e((()=>{h(),w(),H(),V(),br(),yi=_()}));function xi(e){let{goNext:t,goBack:n,updateWizardData:r,wizardData:i}=R(),[a,o]=(0,Si.useState)(i.agentType||``),[f,p]=(0,Si.useState)(null),[m,h]=(0,Si.useState)(a.length);return d(`confirm:no`,n,{context:`Settings`}),(0,Q.jsx)(B,{subtitle:`Agent type (identifier)`,footerText:(0,Q.jsxs)(u,{children:[(0,Q.jsx)(s,{shortcut:`Type`,action:`enter text`}),(0,Q.jsx)(s,{shortcut:`Enter`,action:`continue`}),(0,Q.jsx)(T,{action:`confirm:no`,context:`Settings`,fallback:`Esc`,description:`go back`})]}),children:(0,Q.jsxs)(c,{flexDirection:`column`,children:[(0,Q.jsx)(l,{children:`Enter a unique identifier for your agent:`}),(0,Q.jsx)(c,{marginTop:1,children:(0,Q.jsx)(Qt,{value:a,onChange:o,onSubmit:e=>{let n=e.trim(),i=Hr(n);if(i){p(i);return}p(null),r({agentType:n}),t()},placeholder:`e.g., test-runner, tech-lead, etc`,columns:60,cursorOffset:m,onChangeCursorOffset:h,focus:!0,showCursor:!0})}),f&&(0,Q.jsx)(c,{marginTop:1,children:(0,Q.jsx)(l,{color:`error`,children:f})})]})})}var Si,Q,Ci=e((()=>{Si=t(f(),1),h(),E(),w(),Zt(),H(),V(),Wr(),Q=_()}));function wi({tools:e,existingAgents:t,onComplete:n,onCancel:r}){return(0,Ti.jsx)(jr,{steps:[oi,ui,ii,()=>(0,Ti.jsx)(xi,{existingAgents:t}),hi,Zr,()=>(0,Ti.jsx)(vi,{tools:e}),fi,Br,...At()?[ci]:[],()=>(0,Ti.jsx)(qr,{tools:e,existingAgents:t,onComplete:n})],initialData:{},onComplete:()=>{},onCancel:r,title:`Create new agent`,showStepCounter:!1})}var Ti,Ei=e((()=>{kt(),H(),Vr(),Xr(),$r(),ai(),si(),li(),di(),mi(),_i(),bi(),Ci(),Ti=_()}));function Di({tools:e,onExit:t}){let[n,r]=(0,Oi.useState)({mode:`list-agents`,source:`all`}),i=_e(e=>e.agentDefinitions),a=_e(e=>e.mcp.tools),o=_e(e=>e.toolPermissionContext),s=He(),{allAgents:u,activeAgents:d}=i,[f,m]=(0,Oi.useState)([]),h=rn(e,a,o);Yt();let _=(0,Oi.useMemo)(()=>({"built-in":u.filter(e=>e.source===`built-in`),userSettings:u.filter(e=>e.source===`userSettings`),projectSettings:u.filter(e=>e.source===`projectSettings`),policySettings:u.filter(e=>e.source===`policySettings`),localSettings:u.filter(e=>e.source===`localSettings`),flagSettings:u.filter(e=>e.source===`flagSettings`),plugin:u.filter(e=>e.source===`plugin`),all:u}),[u]),v=(0,Oi.useCallback)(e=>{m(t=>[...t,e]),r({mode:`list-agents`,source:`all`})},[]),y=(0,Oi.useCallback)(async e=>{try{await ar(e),s(t=>{let n=t.agentDefinitions.allAgents.filter(t=>!(t.agentType===e.agentType&&t.source===e.source));return{...t,agentDefinitions:{...t.agentDefinitions,allAgents:n,activeAgents:ct(n)}}}),m(t=>[...t,`Deleted agent: ${p.bold(e.agentType)}`]),r({mode:`list-agents`,source:`all`})}catch(e){Mt(Et(e))}},[s]);switch(n.mode){case`list-agents`:{let e=Kt(n.source===`all`?[..._[`built-in`],..._.userSettings,..._.projectSettings,..._.localSettings,..._.policySettings,..._.flagSettings,..._.plugin]:_[n.source],d);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Or,{source:n.source,agents:e,onBack:()=>{t((f.length>0?`Agent changes:\n${f.join(`
101
+ `)}`:void 0)??`Agents dialog dismissed`,{display:f.length===0?`system`:void 0})},onSelect:e=>r({mode:`agent-menu`,agent:e,previousMode:n}),onCreateNew:()=>r({mode:`create-agent`}),changes:f}),(0,$.jsx)(Tr,{})]})}case`create-agent`:return(0,$.jsx)(wi,{tools:h,existingAgents:d,onComplete:v,onCancel:()=>r({mode:`list-agents`,source:`all`})});case`agent-menu`:{let e=u.find(e=>e.agentType===n.agent.agentType&&e.source===n.agent.source)||n.agent,t=[{label:`View agent`,value:`view`},...e.source!==`built-in`&&e.source!==`plugin`&&e.source!==`flagSettings`?[{label:`Edit agent`,value:`edit`},{label:`Delete agent`,value:`delete`}]:[],{label:`Back`,value:`back`}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{title:n.agent.agentType,onCancel:()=>r(n.previousMode),hideInputGuide:!0,children:(0,$.jsxs)(c,{flexDirection:`column`,children:[(0,$.jsx)(en,{options:t,onChange:t=>{switch(t){case`view`:r({mode:`view-agent`,agent:e,previousMode:n.previousMode});break;case`edit`:r({mode:`edit-agent`,agent:e,previousMode:n});break;case`delete`:r({mode:`delete-confirm`,agent:e,previousMode:n});break;case`back`:r(n.previousMode);break}},onCancel:()=>r(n.previousMode)}),f.length>0&&(0,$.jsx)(c,{marginTop:1,children:(0,$.jsx)(l,{dimColor:!0,children:f[f.length-1]})})]})}),(0,$.jsx)(Tr,{})]})}case`view-agent`:{let e=u.find(e=>e.agentType===n.agent.agentType&&e.source===n.agent.source)||n.agent;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{title:e.agentType,onCancel:()=>r({mode:`agent-menu`,agent:e,previousMode:n.previousMode}),hideInputGuide:!0,children:(0,$.jsx)(cr,{agent:e,tools:h,allAgents:u,onBack:()=>r({mode:`agent-menu`,agent:e,previousMode:n.previousMode})})}),(0,$.jsx)(Tr,{instructions:`Press Enter or Esc to go back`})]})}case`delete-confirm`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(g,{title:`Delete agent`,onCancel:()=>{`previousMode`in n&&r(n.previousMode)},color:`error`,children:[(0,$.jsxs)(l,{children:[`Are you sure you want to delete the agent `,(0,$.jsx)(l,{bold:!0,children:n.agent.agentType}),`?`]}),(0,$.jsx)(c,{marginTop:1,children:(0,$.jsxs)(l,{dimColor:!0,children:[`Source: `,n.agent.source]})}),(0,$.jsx)(c,{marginTop:1,children:(0,$.jsx)(en,{options:[{label:`Yes, delete`,value:`yes`},{label:`No, cancel`,value:`no`}],onChange:e=>{e===`yes`?y(n.agent):`previousMode`in n&&r(n.previousMode)},onCancel:()=>{`previousMode`in n&&r(n.previousMode)}})})]}),(0,$.jsx)(Tr,{instructions:`Press ↑↓ to navigate, Enter to select, Esc to cancel`})]});case`edit-agent`:{let e=u.find(e=>e.agentType===n.agent.agentType&&e.source===n.agent.source)||n.agent;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{title:`Edit agent: ${e.agentType}`,onCancel:()=>r(n.previousMode),hideInputGuide:!0,children:(0,$.jsx)(Cr,{agent:e,tools:h,onSaved:e=>{v(e),r(n.previousMode)},onBack:()=>r(n.previousMode)})}),(0,$.jsx)(Tr,{})]})}default:return null}}var Oi,$,ki=e((()=>{m(),Oi=t(f(),1),Xt(),an(),h(),Le(),Wt(),at(),Ct(),jt(),$t(),lr(),wr(),Dr(),Ar(),sr(),Ei(),$=_()}));async function Ai(e,t){let n=t.getAppState().toolPermissionContext;return(0,ji.jsx)(Di,{tools:Ee(n),onExit:e})}var ji;e((()=>{ki(),Qe(),ji=_()}))();export{Ai as call};
@@ -1,2 +1,2 @@
1
- import{i as e,o as t,r as n}from"./loadAgentsDir-uuZYOgKn.js";import{n as r,t as i}from"./cwd-DrEEb4f5.js";import{a,i as o,n as s,o as c,r as l,t as u}from"./agentDisplay-np7CH47m.js";o(),t(),r();function d(e){let t=a(e),n=[e.agentType];return t&&n.push(t),e.memory&&n.push(`${e.memory} memory`),n.join(` · `)}async function f(){let{allAgents:t}=await e(i()),r=c(t,n(t)),a=[],o=0;for(let{label:e,source:t}of u){let n=r.filter(e=>e.source===t).sort(s);if(n.length!==0){a.push(`${e}:`);for(let e of n)if(e.overriddenBy){let t=l(e.overriddenBy);a.push(` (shadowed by ${t}) ${d(e)}`)}else a.push(` ${d(e)}`),o++;a.push(``)}}a.length===0?console.log(`No agents found.`):(console.log(`${o} active agents\n`),console.log(a.join(`
1
+ import{i as e,o as t,r as n}from"./loadAgentsDir-BfLCckVj.js";import{n as r,t as i}from"./cwd-DrEEb4f5.js";import{a,i as o,n as s,o as c,r as l,t as u}from"./agentDisplay-ChkgiTIH.js";o(),t(),r();function d(e){let t=a(e),n=[e.agentType];return t&&n.push(t),e.memory&&n.push(`${e.memory} memory`),n.join(` · `)}async function f(){let{allAgents:t}=await e(i()),r=c(t,n(t)),a=[],o=0;for(let{label:e,source:t}of u){let n=r.filter(e=>e.source===t).sort(s);if(n.length!==0){a.push(`${e}:`);for(let e of n)if(e.overriddenBy){let t=l(e.overriddenBy);a.push(` (shadowed by ${t}) ${d(e)}`)}else a.push(` ${d(e)}`),o++;a.push(``)}}a.length===0?console.log(`No agents found.`):(console.log(`${o} active agents\n`),console.log(a.join(`
2
2
  `).trimEnd()))}export{f as agentsHandler};
@@ -0,0 +1 @@
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{l as t,m as n}from"./settings-D4M13toi.js";import{ff as r,uf as i}from"./loadAgentsDir-BfLCckVj.js";function a(){let e=t(),n=[`user`,`project`,`local`].flatMap(e=>i(e).errors);return{settings:e.settings,errors:[...e.errors,...n]}}var o=e((()=>{r(),n()}));export{o as n,a as t};
@@ -1 +1 @@
1
- import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{d as t,h as n,o as r}from"./config-BDn2YIjC.js";import{o as i,s as a}from"./log-L1kqxa_P.js";import{i as o,t as s}from"./execFileNoThrow-DXSEj8ZO.js";import{homedir as c}from"os";import{join as l}from"path";import{stat as u}from"fs/promises";function d(e){n(t=>({...t,appleTerminalSetupInProgress:!0,appleTerminalBackupPath:e}))}function f(){n(e=>({...e,appleTerminalSetupInProgress:!1}))}function p(){let e=r();return{inProgress:e.appleTerminalSetupInProgress??!1,backupPath:e.appleTerminalBackupPath||null}}function m(){return l(c(),`Library`,`Preferences`,`com.apple.Terminal.plist`)}async function h(){let e=m(),t=`${e}.bak`;try{let{code:n}=await s(`defaults`,[`export`,`com.apple.Terminal`,e]);if(n!==0)return null;try{await u(e)}catch{return null}return await s(`defaults`,[`export`,`com.apple.Terminal`,t]),d(t),t}catch(e){return a(e),null}}async function g(){let{inProgress:e,backupPath:t}=p();if(!e)return{status:`no_backup`};if(!t)return f(),{status:`no_backup`};try{await u(t)}catch{return f(),{status:`no_backup`}}try{let{code:e}=await s(`defaults`,[`import`,`com.apple.Terminal`,t]);return e===0?(await s(`killall`,[`cfprefsd`]),f(),{status:`restored`}):{status:`failed`,backupPath:t}}catch(e){return a(Error(`Failed to restore Terminal.app settings with: ${e}`)),f(),{status:`failed`,backupPath:t}}}var _=e((()=>{t(),o(),i()}));export{f as a,_ as i,g as n,m as r,h as t};
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{d as t,h as n,o as r}from"./config-Bio2EjUK.js";import{o as i,s as a}from"./log-L1kqxa_P.js";import{i as o,t as s}from"./execFileNoThrow-DXSEj8ZO.js";import{homedir as c}from"os";import{join as l}from"path";import{stat as u}from"fs/promises";function d(e){n(t=>({...t,appleTerminalSetupInProgress:!0,appleTerminalBackupPath:e}))}function f(){n(e=>({...e,appleTerminalSetupInProgress:!1}))}function p(){let e=r();return{inProgress:e.appleTerminalSetupInProgress??!1,backupPath:e.appleTerminalBackupPath||null}}function m(){return l(c(),`Library`,`Preferences`,`com.apple.Terminal.plist`)}async function h(){let e=m(),t=`${e}.bak`;try{let{code:n}=await s(`defaults`,[`export`,`com.apple.Terminal`,e]);if(n!==0)return null;try{await u(e)}catch{return null}return await s(`defaults`,[`export`,`com.apple.Terminal`,t]),d(t),t}catch(e){return a(e),null}}async function g(){let{inProgress:e,backupPath:t}=p();if(!e)return{status:`no_backup`};if(!t)return f(),{status:`no_backup`};try{await u(t)}catch{return f(),{status:`no_backup`}}try{let{code:e}=await s(`defaults`,[`import`,`com.apple.Terminal`,t]);return e===0?(await s(`killall`,[`cfprefsd`]),f(),{status:`restored`}):{status:`failed`,backupPath:t}}catch(e){return a(Error(`Failed to restore Terminal.app settings with: ${e}`)),f(),{status:`failed`,backupPath:t}}}var _=e((()=>{t(),o(),i()}));export{f as a,_ as i,g as n,m as r,h as t};
@@ -1 +1 @@
1
- import{i as e,o as t}from"./envUtils-QyzA_cFM.js";import{_ as n,d as r,m as i}from"./settings-D4M13toi.js";import{P as a,Pt as o,z as s}from"./state-CXY-q5gr.js";import{Fu as c,Ru as l,St as u,db as d,ft as f,gr as p,ic as m,or as h,pb as g,rc as _}from"./loadAgentsDir-uuZYOgKn.js";import{c as v,f as y,i as b,u as x}from"./debug-2pVES-2G.js";import{_ as S,o as C,s as w,v as T}from"./log-L1kqxa_P.js";import{n as E}from"./analytics-COpjZpvd.js";import{r as D,t as O}from"./pasteStore-njJCBMKr.js";import{r as k}from"./magicDocs-D53lV8b5.js";import{i as A,t as j}from"./nativeInstaller-CIUYh1aD.js";import{n as M,t as N}from"./allErrors-DvcU0w0F.js";import{n as P,t as F}from"./pluginAutoupdate-CNrHb4RJ.js";import{join as I}from"path";o(),m(),k(),E(),T(),b(),t(),y(),l(),C(),D(),p(),M(),i(),g(),u();var L=30;function R(){let e=((r()||{}).cleanupPeriodDays??L)*24*60*60*1e3;return new Date(Date.now()-e)}function z(e,t){return{messages:e.messages+t.messages,errors:e.errors+t.errors}}function B(e){let t=e.split(`.`)[0].replace(/T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z/,`T$1:$2:$3.$4Z`);return new Date(t)}async function V(e,t,n){let r={messages:0,errors:0};try{let i=await x().readdir(e);for(let a of i)try{B(a.name)<t&&(await x().unlink(I(e,a.name)),n?r.messages++:r.errors++)}catch(e){w(e)}}catch(e){e instanceof Error&&`code`in e&&e.code!==`ENOENT`&&w(e)}return r}async function H(){let e=x(),t=R(),n=S.errors(),r=S.baseLogs(),i=await V(n,t,!1);try{let n;try{n=await e.readdir(r)}catch{return i}let a=n.filter(e=>e.isDirectory()&&e.name.startsWith(`mcp-logs-`)).map(e=>I(r,e.name));for(let n of a)i=z(i,await V(n,t,!0)),await W(n,e)}catch(e){e instanceof Error&&`code`in e&&e.code!==`ENOENT`&&w(e)}return i}async function U(e,t,n){return(await n.stat(e)).mtime<t?(await n.unlink(e),!0):!1}async function W(e,t){try{await t.rmdir(e)}catch{}}async function G(){let e=R(),t={messages:0,errors:0},n=h(),r=x(),i;try{i=await r.readdir(n)}catch{return t}for(let a of i){if(!a.isDirectory())continue;let i=I(n,a.name),o;try{o=await r.readdir(i)}catch{t.errors++;continue}for(let n of o)if(n.isFile()){if(!n.name.endsWith(`.jsonl`)&&!n.name.endsWith(`.cast`))continue;try{await U(I(i,n.name),e,r)&&t.messages++}catch{t.errors++}}else if(n.isDirectory()){let a=I(i,n.name),o=I(a,d),s;try{s=await r.readdir(o)}catch{await W(a,r);continue}for(let n of s)if(n.isFile())try{await U(I(o,n.name),e,r)&&t.messages++}catch{t.errors++}else if(n.isDirectory()){let i=I(o,n.name),a;try{a=await r.readdir(i)}catch{continue}for(let n of a)if(n.isFile())try{await U(I(i,n.name),e,r)&&t.messages++}catch{t.errors++}await W(i,r)}await W(o,r),await W(a,r)}await W(i,r)}return t}async function K(e,t,n=!0){let r=R(),i={messages:0,errors:0},a=x(),o;try{o=await a.readdir(e)}catch{return i}for(let n of o)if(!(!n.isFile()||!n.name.endsWith(t)))try{await U(I(e,n.name),r,a)&&i.messages++}catch{i.errors++}return n&&await W(e,a),i}function q(){return K(I(e(),`plans`),`.md`)}async function J(){let t=R(),n={messages:0,errors:0},r=x();try{let i=I(e(),`file-history`),a;try{a=await r.readdir(i)}catch{return n}let o=a.filter(e=>e.isDirectory()).map(e=>I(i,e.name));await Promise.all(o.map(async e=>{try{(await r.stat(e)).mtime<t&&(await r.rm(e,{recursive:!0,force:!0}),n.messages++)}catch{n.errors++}})),await W(i,r)}catch(e){w(e)}return n}async function Y(){let t=R(),n={messages:0,errors:0},r=x();try{let i=I(e(),`session-env`),a;try{a=await r.readdir(i)}catch{return n}let o=a.filter(e=>e.isDirectory()).map(e=>I(i,e.name));for(let e of o)try{(await r.stat(e)).mtime<t&&(await r.rm(e,{recursive:!0,force:!0}),n.messages++)}catch{n.errors++}await W(i,r)}catch(e){w(e)}return n}async function X(){let t=R(),n={messages:0,errors:0},r=x(),i=I(e(),`debug`),a;try{a=await r.readdir(i)}catch{return n}for(let e of a)if(!(!e.isFile()||!e.name.endsWith(`.txt`)||e.name===`latest`))try{await U(I(i,e.name),t,r)&&n.messages++}catch{n.errors++}return n}async function Z(){let{errors:e}=N();if(e.length>0&&n(`cleanupPeriodDays`)){v(`Skipping cleanup: settings have validation errors but cleanupPeriodDays was explicitly set. Fix settings errors to enable cleanup.`);return}await H(),await G(),await q(),await J(),await Y(),await X(),await c(),await O(R()),await f(R())}j(),P();var Q=600*1e3;function $(){import(`./extractMemories-8yvMGZ1J.js`).then(({initExtractMemories:e})=>{e()}).catch(()=>{}),_(),F();let e=!0;async function t(){if(a()&&s()>Date.now()-1e3*60){setTimeout(t,Q).unref();return}if(e&&(e=!1,await Z()),a()&&s()>Date.now()-1e3*60){setTimeout(t,Q).unref();return}await A()}setTimeout(t,Q).unref()}export{$ as t};
1
+ import{i as e,o as t}from"./envUtils-QyzA_cFM.js";import{_ as n,d as r,m as i}from"./settings-D4M13toi.js";import{P as a,Pt as o,z as s}from"./state-CXY-q5gr.js";import{Bu as c,Lu as l,ac as u,cr as d,hb as f,mt as p,oc as m,pb as h,vr as g,wt as _}from"./loadAgentsDir-BfLCckVj.js";import{c as v,f as y,i as b,u as x}from"./debug-2pVES-2G.js";import{_ as S,o as C,s as w,v as T}from"./log-L1kqxa_P.js";import{n as E}from"./analytics-COpjZpvd.js";import{r as D,t as O}from"./pasteStore-njJCBMKr.js";import{r as k}from"./magicDocs-Bue9vxzY.js";import{i as A,t as j}from"./nativeInstaller-CGSNzGNn.js";import{n as M,t as N}from"./allErrors-CkdguCDv.js";import{n as P,t as F}from"./pluginAutoupdate-D5XyiZrP.js";import{join as I}from"path";o(),m(),k(),E(),T(),b(),t(),y(),c(),C(),D(),g(),M(),i(),f(),_();var L=30;function R(){let e=((r()||{}).cleanupPeriodDays??L)*24*60*60*1e3;return new Date(Date.now()-e)}function z(e,t){return{messages:e.messages+t.messages,errors:e.errors+t.errors}}function B(e){let t=e.split(`.`)[0].replace(/T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z/,`T$1:$2:$3.$4Z`);return new Date(t)}async function V(e,t,n){let r={messages:0,errors:0};try{let i=await x().readdir(e);for(let a of i)try{B(a.name)<t&&(await x().unlink(I(e,a.name)),n?r.messages++:r.errors++)}catch(e){w(e)}}catch(e){e instanceof Error&&`code`in e&&e.code!==`ENOENT`&&w(e)}return r}async function H(){let e=x(),t=R(),n=S.errors(),r=S.baseLogs(),i=await V(n,t,!1);try{let n;try{n=await e.readdir(r)}catch{return i}let a=n.filter(e=>e.isDirectory()&&e.name.startsWith(`mcp-logs-`)).map(e=>I(r,e.name));for(let n of a)i=z(i,await V(n,t,!0)),await W(n,e)}catch(e){e instanceof Error&&`code`in e&&e.code!==`ENOENT`&&w(e)}return i}async function U(e,t,n){return(await n.stat(e)).mtime<t?(await n.unlink(e),!0):!1}async function W(e,t){try{await t.rmdir(e)}catch{}}async function G(){let e=R(),t={messages:0,errors:0},n=d(),r=x(),i;try{i=await r.readdir(n)}catch{return t}for(let a of i){if(!a.isDirectory())continue;let i=I(n,a.name),o;try{o=await r.readdir(i)}catch{t.errors++;continue}for(let n of o)if(n.isFile()){if(!n.name.endsWith(`.jsonl`)&&!n.name.endsWith(`.cast`))continue;try{await U(I(i,n.name),e,r)&&t.messages++}catch{t.errors++}}else if(n.isDirectory()){let a=I(i,n.name),o=I(a,h),s;try{s=await r.readdir(o)}catch{await W(a,r);continue}for(let n of s)if(n.isFile())try{await U(I(o,n.name),e,r)&&t.messages++}catch{t.errors++}else if(n.isDirectory()){let i=I(o,n.name),a;try{a=await r.readdir(i)}catch{continue}for(let n of a)if(n.isFile())try{await U(I(i,n.name),e,r)&&t.messages++}catch{t.errors++}await W(i,r)}await W(o,r),await W(a,r)}await W(i,r)}return t}async function K(e,t,n=!0){let r=R(),i={messages:0,errors:0},a=x(),o;try{o=await a.readdir(e)}catch{return i}for(let n of o)if(!(!n.isFile()||!n.name.endsWith(t)))try{await U(I(e,n.name),r,a)&&i.messages++}catch{i.errors++}return n&&await W(e,a),i}function q(){return K(I(e(),`plans`),`.md`)}async function J(){let t=R(),n={messages:0,errors:0},r=x();try{let i=I(e(),`file-history`),a;try{a=await r.readdir(i)}catch{return n}let o=a.filter(e=>e.isDirectory()).map(e=>I(i,e.name));await Promise.all(o.map(async e=>{try{(await r.stat(e)).mtime<t&&(await r.rm(e,{recursive:!0,force:!0}),n.messages++)}catch{n.errors++}})),await W(i,r)}catch(e){w(e)}return n}async function Y(){let t=R(),n={messages:0,errors:0},r=x();try{let i=I(e(),`session-env`),a;try{a=await r.readdir(i)}catch{return n}let o=a.filter(e=>e.isDirectory()).map(e=>I(i,e.name));for(let e of o)try{(await r.stat(e)).mtime<t&&(await r.rm(e,{recursive:!0,force:!0}),n.messages++)}catch{n.errors++}await W(i,r)}catch(e){w(e)}return n}async function X(){let t=R(),n={messages:0,errors:0},r=x(),i=I(e(),`debug`),a;try{a=await r.readdir(i)}catch{return n}for(let e of a)if(!(!e.isFile()||!e.name.endsWith(`.txt`)||e.name===`latest`))try{await U(I(i,e.name),t,r)&&n.messages++}catch{n.errors++}return n}async function Z(){let{errors:e}=N();if(e.length>0&&n(`cleanupPeriodDays`)){v(`Skipping cleanup: settings have validation errors but cleanupPeriodDays was explicitly set. Fix settings errors to enable cleanup.`);return}await H(),await G(),await q(),await J(),await Y(),await X(),await l(),await O(R()),await p(R())}j(),P();var Q=600*1e3;function $(){import(`./extractMemories-DHlbRc5g.js`).then(({initExtractMemories:e})=>{e()}).catch(()=>{}),u(),F();let e=!0;async function t(){if(a()&&s()>Date.now()-1e3*60){setTimeout(t,Q).unref();return}if(e&&(e=!1,await Z()),a()&&s()>Date.now()-1e3*60){setTimeout(t,Q).unref();return}await A()}setTimeout(t,Q).unref()}export{$ as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./backgroundHousekeeping-1VsWy8xd.js";export{e as startBackgroundHousekeeping};
@@ -1,2 +1,2 @@
1
- import{Hr as e,In as t,Vn as n,ii as r,qr as i,ti as a,zr as o}from"./settings-D4M13toi.js";import{Pt as s,q as c}from"./state-CXY-q5gr.js";import{c as l,i as u}from"./debug-2pVES-2G.js";import{d,h as f,o as p}from"./config-BDn2YIjC.js";import{_ as m,f as h,p as g}from"./startupProfiler-B9Qv2QGH.js";import{n as _,r as v}from"./detectRepository--luIRv5H.js";import{homedir as y}from"os";import{join as b,sep as x}from"path";import{realpath as S,stat as C}from"fs/promises";s(),d(),u(),v(),t(),r(),i();async function w(){try{let e=await _();if(!e){l(`Not in a GitHub repository, skipping path mapping update`);return}let t=c(),n=o(t)??t,r;try{r=(await S(n)).normalize(`NFC`)}catch{r=n}let i=e.toLowerCase(),a=p().githubRepoPaths?.[i]??[];if(a[0]===r){l(`Path ${r} already tracked for repo ${i}`);return}let s=a.filter(e=>e!==r),u=[r,...s];f(e=>({...e,githubRepoPaths:{...e.githubRepoPaths,[i]:u}})),l(`Added ${r} to tracked paths for repo ${i}`)}catch(e){l(`Error updating repo path mapping: ${e}`)}}function T(e){let t=p(),n=e.toLowerCase();return t.githubRepoPaths?.[n]??[]}async function E(e){let t=await Promise.all(e.map(n));return e.filter((e,n)=>t[n])}m(),r(),i();var D=10080*60*1e3,O=1e3;function k(e){let t=[`This session was opened by an external deep link in ${M(e.cwd)}`];if(e.repo){let n=e.lastFetch?g(e.lastFetch):`never`,r=!e.lastFetch||Date.now()-e.lastFetch.getTime()>D;t.push(`Resolved ${e.repo} from local clones · last fetched ${n}${r?` — AGENTS.md may be stale`:``}`)}return e.prefillLength&&t.push(e.prefillLength>O?`The prompt below (${h(e.prefillLength)} chars) was supplied by the link — scroll to review the entire prompt before pressing Enter.`:`The prompt below was supplied by the link — review carefully before pressing Enter.`),t.join(`
1
+ import{Hr as e,In as t,Vn as n,ii as r,qr as i,ti as a,zr as o}from"./settings-D4M13toi.js";import{Pt as s,q as c}from"./state-CXY-q5gr.js";import{c as l,i as u}from"./debug-2pVES-2G.js";import{d,h as f,o as p}from"./config-Bio2EjUK.js";import{_ as m,f as h,p as g}from"./startupProfiler-B9Qv2QGH.js";import{n as _,r as v}from"./detectRepository--luIRv5H.js";import{homedir as y}from"os";import{join as b,sep as x}from"path";import{realpath as S,stat as C}from"fs/promises";s(),d(),u(),v(),t(),r(),i();async function w(){try{let e=await _();if(!e){l(`Not in a GitHub repository, skipping path mapping update`);return}let t=c(),n=o(t)??t,r;try{r=(await S(n)).normalize(`NFC`)}catch{r=n}let i=e.toLowerCase(),a=p().githubRepoPaths?.[i]??[];if(a[0]===r){l(`Path ${r} already tracked for repo ${i}`);return}let s=a.filter(e=>e!==r),u=[r,...s];f(e=>({...e,githubRepoPaths:{...e.githubRepoPaths,[i]:u}})),l(`Added ${r} to tracked paths for repo ${i}`)}catch(e){l(`Error updating repo path mapping: ${e}`)}}function T(e){let t=p(),n=e.toLowerCase();return t.githubRepoPaths?.[n]??[]}async function E(e){let t=await Promise.all(e.map(n));return e.filter((e,n)=>t[n])}m(),r(),i();var D=10080*60*1e3,O=1e3;function k(e){let t=[`This session was opened by an external deep link in ${M(e.cwd)}`];if(e.repo){let n=e.lastFetch?g(e.lastFetch):`never`,r=!e.lastFetch||Date.now()-e.lastFetch.getTime()>D;t.push(`Resolved ${e.repo} from local clones · last fetched ${n}${r?` — AGENTS.md may be stale`:``}`)}return e.prefillLength&&t.push(e.prefillLength>O?`The prompt below (${h(e.prefillLength)} chars) was supplied by the link — scroll to review the entire prompt before pressing Enter.`:`The prompt below was supplied by the link — review carefully before pressing Enter.`),t.join(`
2
2
  `)}async function A(t){let n=await e(t);if(!n)return;let r=await a(n),[i,o]=await Promise.all([j(b(n,`FETCH_HEAD`)),r?j(b(r,`FETCH_HEAD`)):Promise.resolve(void 0)]);return i&&o?i>o?i:o:i??o}async function j(e){try{let{mtime:t}=await C(e);return t}catch{return}}function M(e){let t=y();return e===t?`~`:e.startsWith(t+x)?`~${e.slice(t.length)}`:e}export{w as a,T as i,A as n,E as r,k as t};
@@ -1,2 +1,2 @@
1
- import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{vn as t,yn as n}from"./settings-D4M13toi.js";import{Pt as r,at as i,q as a}from"./state-CXY-q5gr.js";import{Sr as o,ar as s,ei as c,fr as l,gr as u,oi as d,pr as f}from"./loadAgentsDir-uuZYOgKn.js";import{C as p,x as m}from"./debug-2pVES-2G.js";import{n as h}from"./analytics-COpjZpvd.js";import{i as g,o as _}from"./stringUtils-Cs6E5f-B.js";import{randomUUID as v}from"crypto";import{mkdir as y,readFile as b,writeFile as x}from"fs/promises";function S(e){let t=e?.message?.content;if(!t)return`Branched conversation`;let n=typeof t==`string`?t:t.find(e=>e.type===`text`)?.text;return n&&n.replace(/\s+/g,` `).trim().slice(0,100)||`Branched conversation`}async function C(e){let t=v(),r=i(),c=s(a()),u=f(t),d=l();await y(c,{recursive:!0,mode:448});let m;try{m=await b(d)}catch{throw Error(`No conversation to branch`)}if(m.length===0)throw Error(`No conversation to branch`);let h=n(m),g=h.filter(e=>o(e)&&!e.isSidechain),_=h.filter(e=>e.type===`content-replacement`&&e.sessionId===r).flatMap(e=>e.replacements);if(g.length===0)throw Error(`No messages to branch`);let S=null,C=[],w=[];for(let e of g){let n={...e,sessionId:t,parentUuid:S,isSidechain:!1,forkedFrom:{sessionId:r,messageUuid:e.uuid}},i={...e,sessionId:t};w.push(i),C.push(p(n)),e.type!==`progress`&&(S=e.uuid)}if(_.length>0){let e={type:`content-replacement`,sessionId:t,replacements:_};C.push(p(e))}return await x(u,`${C.join(`
2
- `)}\n`,{encoding:`utf8`,mode:384}),{sessionId:t,title:e,forkPath:u,serializedMessages:w,contentReplacementRecords:_}}async function w(e){let t=`${e} (Branch)`;if((await d(t,{exact:!0})).length===0)return t;let n=await d(`${e} (Branch`),r=new Set([1]),i=RegExp(`^${g(e)} \\(Branch(?: (\\d+))?\\)$`);for(let e of n){let t=e.customTitle?.match(i);t&&(t[1]?r.add(parseInt(t[1],10)):r.add(1))}let a=2;for(;r.has(a);)a++;return`${e} (Branch ${a})`}async function T(e,t,n){let r=n?.trim()||void 0,a=i();try{let{sessionId:n,title:i,forkPath:o,serializedMessages:s,contentReplacementRecords:l}=await C(r),u=new Date,d=S(s.find(e=>e.type===`user`)),f=await w(i??d);await c(n,f,o),s.length;let p={date:u.toISOString().split(`T`)[0],messages:s,fullPath:o,value:u.getTime(),created:u,modified:u,firstPrompt:d,messageCount:s.length,isSidechain:!1,sessionId:n,customTitle:f,contentReplacements:l},m=i?` "${i}"`:``,h=`Branched conversation${m}. You are now in the branch.${`\nTo resume the original: claude -r ${a}`}`;return t.resume?(await t.resume(n,p,`fork`),e(h,{display:`system`})):e(`Branched conversation${m}. Resume with: /resume ${n}`),null}catch(t){return e(`Failed to branch conversation: ${t instanceof Error?t.message:`Unknown error occurred`}`),null}}e((()=>{r(),h(),t(),u(),m(),_()}))();export{T as call,S as deriveFirstPrompt};
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{vn as t,yn as n}from"./settings-D4M13toi.js";import{Pt as r,at as i,q as a}from"./state-CXY-q5gr.js";import{ci as o,hr as s,mr as c,ni as l,sr as u,vr as d,wr as f}from"./loadAgentsDir-BfLCckVj.js";import{C as p,x as m}from"./debug-2pVES-2G.js";import{n as h}from"./analytics-COpjZpvd.js";import{i as g,o as _}from"./stringUtils-Cs6E5f-B.js";import{randomUUID as v}from"crypto";import{mkdir as y,readFile as b,writeFile as x}from"fs/promises";function S(e){let t=e?.message?.content;if(!t)return`Branched conversation`;let n=typeof t==`string`?t:t.find(e=>e.type===`text`)?.text;return n&&n.replace(/\s+/g,` `).trim().slice(0,100)||`Branched conversation`}async function C(e){let t=v(),r=i(),o=u(a()),l=s(t),d=c();await y(o,{recursive:!0,mode:448});let m;try{m=await b(d)}catch{throw Error(`No conversation to branch`)}if(m.length===0)throw Error(`No conversation to branch`);let h=n(m),g=h.filter(e=>f(e)&&!e.isSidechain),_=h.filter(e=>e.type===`content-replacement`&&e.sessionId===r).flatMap(e=>e.replacements);if(g.length===0)throw Error(`No messages to branch`);let S=null,C=[],w=[];for(let e of g){let n={...e,sessionId:t,parentUuid:S,isSidechain:!1,forkedFrom:{sessionId:r,messageUuid:e.uuid}},i={...e,sessionId:t};w.push(i),C.push(p(n)),e.type!==`progress`&&(S=e.uuid)}if(_.length>0){let e={type:`content-replacement`,sessionId:t,replacements:_};C.push(p(e))}return await x(l,`${C.join(`
2
+ `)}\n`,{encoding:`utf8`,mode:384}),{sessionId:t,title:e,forkPath:l,serializedMessages:w,contentReplacementRecords:_}}async function w(e){let t=`${e} (Branch)`;if((await o(t,{exact:!0})).length===0)return t;let n=await o(`${e} (Branch`),r=new Set([1]),i=RegExp(`^${g(e)} \\(Branch(?: (\\d+))?\\)$`);for(let e of n){let t=e.customTitle?.match(i);t&&(t[1]?r.add(parseInt(t[1],10)):r.add(1))}let a=2;for(;r.has(a);)a++;return`${e} (Branch ${a})`}async function T(e,t,n){let r=n?.trim()||void 0,a=i();try{let{sessionId:n,title:i,forkPath:o,serializedMessages:s,contentReplacementRecords:c}=await C(r),u=new Date,d=S(s.find(e=>e.type===`user`)),f=await w(i??d);await l(n,f,o),s.length;let p={date:u.toISOString().split(`T`)[0],messages:s,fullPath:o,value:u.getTime(),created:u,modified:u,firstPrompt:d,messageCount:s.length,isSidechain:!1,sessionId:n,customTitle:f,contentReplacements:c},m=i?` "${i}"`:``,h=`Branched conversation${m}. You are now in the branch.${`\nTo resume the original: claude -r ${a}`}`;return t.resume?(await t.resume(n,p,`fork`),e(h,{display:`system`})):e(`Branched conversation${m}. Resume with: /resume ${n}`),null}catch(t){return e(`Failed to branch conversation: ${t instanceof Error?t.message:`Unknown error occurred`}`),null}}e((()=>{r(),h(),t(),d(),m(),_()}))();export{T as call,S as deriveFirstPrompt};
@@ -0,0 +1,2 @@
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{i as t,o as n}from"./envUtils-QyzA_cFM.js";import{Gi as r,Ni as i,Vi as a,Wi as o,ea as s,ia as c,oa as l,ta as u}from"./settings-D4M13toi.js";import{c as d,i as f}from"./debug-2pVES-2G.js";import{o as p,s as m}from"./log-L1kqxa_P.js";import{join as h}from"node:path";import{spawn as g,spawnSync as _}from"node:child_process";import{chmodSync as v,existsSync as y,mkdirSync as b,readFileSync as x,renameSync as S,writeFileSync as C}from"node:fs";function w(){return h(t(),`channel`)}function T(){return h(w(),`dingtalk.json`)}function E(){return M.parse({})}function D(){let e=T();try{if(!y(e))return E();let t=x(e,`utf8`),n=JSON.parse(t);return M.parse(n)}catch(e){return m(e),E()}}function O(e){let t=T(),n=e(D());b(w(),{recursive:!0});let r=`${t}.${process.pid}.tmp`;C(r,`${JSON.stringify(n,null,2)}\n`,{mode:384}),S(r,t);try{v(t,384)}catch{}return n}function k(e){return e.channel?.enabled===!0&&e.channel?.activePlugin===`dingtalk`}function A(e){return e.permissionMode}var j,M,N=e((()=>{i(),n(),p(),j=u({workmateSessionId:l(),lastActiveAt:s(),senderId:l().optional()}),M=u({corpid:l().default(``),appKey:l().default(``),appSecret:l().default(``),robotName:l().default(`workmate`),cardTemplateId:l().default(``),permissionMode:a([`default`,`acceptEdits`,`bypassPermissions`,`plan`,`dontAsk`,`auto`]).default(`default`),sessionStrategy:a([`perConversation`,`perUser`,`shared`]).default(`perConversation`),confirmDangerous:r().default(!0),confirmTimeoutMs:s().default(300*1e3),admins:o(l()).default([]),sessions:c(l(),j).default({})})}));function P(){let e=R();if(e)return d(`[channel] bridge 已在运行,pid=${e}`,{level:`debug`}),{pid:e,started:!1};let t=process.argv[1],n=t&&/\.(cjs|js|mjs)$/.test(t)?[t,`channel`,`start`]:[`channel`,`start`],r=g(process.execPath,n,{detached:!0,stdio:`ignore`,cwd:process.cwd()});r.unref();let i=r.pid;return i?(d(`[channel] bridge 已启动,pid=${i}`,{level:`debug`}),{pid:i,started:!0}):{pid:0,started:!1}}function F(){let e=R();if(!e)return!1;try{return process.kill(e,`SIGTERM`),d(`[channel] 已发 SIGTERM 给 bridge pid=${e}`,{level:`debug`}),!0}catch(e){return m(e),!1}}function I(){return R()!==null}function L(){return R()}function R(){let e=_(`pgrep`,[`-f`,z],{encoding:`utf8`});if(e.status!==0||!e.stdout.trim())return null;let t=e.stdout.trim().split(`
2
+ `).map(Number).filter(e=>e&&e!==process.pid);return t.length?t[t.length-1]:null}var z,B=e((()=>{f(),p(),z=`channel start`}));export{F as a,N as c,P as i,k as l,B as n,D as o,I as r,A as s,L as t,O as u};
@@ -1 +1 @@
1
- import{n as e,o as t}from"./rolldown-runtime-DaDcL9Zw.js";import{I as n,P as r,ai as i,bn as a,ot as o,t as s,vn as c,xt as l}from"./src-BX54x08P.js";import{t as u}from"./jsx-runtime-Bb4Xn-E0.js";import{Gt as d}from"./settings-D4M13toi.js";import{Bv as f,F_ as p,GS as m,I_ as h,Ji as g,P_ as _,Rx as v,Us as y,Ws as b,dd as x,ld as S,ot as C,sb as w,st as T,ty as E,zv as D}from"./loadAgentsDir-uuZYOgKn.js";import{I as O,M as k}from"./debug-2pVES-2G.js";import{d as A,h as j}from"./config-BDn2YIjC.js";import{n as M,t as N}from"./SpinnerGlyph-BR_SiV9L.js";import{n as P,r as F}from"./sideQuestion-CdgUarC2.js";import{i as I,n as L}from"./modalContext-sU2lfR08.js";function R({question:e,context:t,onDone:i}){let[s,c]=(0,H.useState)(null),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(0),m=(0,H.useRef)(null),{rows:h}=I(o());a(()=>p(e=>e+1),s||u?null:80);function g(e){if(e.key===`escape`||e.key===`return`||e.key===` `||e.ctrl&&(e.key===`c`||e.key===`d`)){e.preventDefault(),i(void 0,{display:`skip`});return}(e.key===`up`||e.ctrl&&e.key===`p`)&&(e.preventDefault(),m.current?.scrollBy(-3)),(e.key===`down`||e.ctrl&&e.key===`n`)&&(e.preventDefault(),m.current?.scrollBy(K))}(0,H.useEffect)(()=>{let n=D();async function r(){try{let r=await F({question:e,cacheSafeParams:await B(t)});n.signal.aborted||(r.response?c(r.response):d(`No response received`))}catch(e){n.signal.aborted||d(k(e)||`Failed to get response`)}}return r(),()=>{n.abort()}},[e,t]);let _=Math.max(5,h-W-G);return(0,U.jsxs)(n,{flexDirection:`column`,paddingLeft:2,marginTop:1,tabIndex:0,autoFocus:!0,onKeyDown:g,children:[(0,U.jsxs)(n,{children:[(0,U.jsxs)(r,{color:`warning`,bold:!0,children:[`/btw`,` `]}),(0,U.jsx)(r,{dimColor:!0,children:e})]}),(0,U.jsx)(n,{marginTop:1,marginLeft:2,maxHeight:_,children:(0,U.jsx)(l,{ref:m,flexDirection:`column`,flexGrow:1,children:u?(0,U.jsx)(r,{color:`error`,children:u}):s?(0,U.jsx)(S,{children:s}):(0,U.jsxs)(n,{children:[(0,U.jsx)(N,{frame:f,messageColor:`warning`}),(0,U.jsx)(r,{color:`warning`,children:`Answering...`})]})})}),(s||u)&&(0,U.jsx)(n,{marginTop:1,children:(0,U.jsxs)(r,{dimColor:!0,children:[`↑`,`/`,`↓`,` to scroll · Space, Enter, or Escape to dismiss`]})})]})}function z(e){let t=e.at(-1);return t?.type===`assistant`&&t.message.stop_reason===null?e.slice(0,-1):e}async function B(e){let t=v(z(e.messages)),n=y();if(n)return{systemPrompt:n.systemPrompt,userContext:n.userContext,systemContext:n.systemContext,toolUseContext:e,forkContextMessages:t};let[r,i,a]=await Promise.all([C(e.options.tools,e.options.mainLoopModel,[],e.options.mcpClients),p(),_()]);return{systemPrompt:m(r),userContext:i,systemContext:a,toolUseContext:e,forkContextMessages:t}}async function V(e,t,n){let r=n?.trim();return r?(j(e=>({...e,btwUseCount:e.btwUseCount+1})),(0,U.jsx)(R,{question:r,context:t,onDone:e})):(e(`Usage: /btw <your question>`,{display:`system`}),null)}var H,U,W,G,K;e((()=>{H=t(i(),1),c(),x(),M(),d(),T(),L(),h(),w(),s(),f(),A(),O(),b(),g(),P(),E(),U=u(),W=5,G=6,K=3}))();export{V as call};
1
+ import{n as e,o as t}from"./rolldown-runtime-DaDcL9Zw.js";import{I as n,P as r,ai as i,bn as a,ot as o,t as s,vn as c,xt as l}from"./src-BX54x08P.js";import{t as u}from"./jsx-runtime-Bb4Xn-E0.js";import{Gt as d}from"./settings-D4M13toi.js";import{Bx as f,Gs as p,Hv as m,I_ as h,Ks as g,L_ as _,R_ as v,Vv as y,Xi as b,ct as x,dd as S,lb as C,lt as w,pd as T,qS as E,ry as D}from"./loadAgentsDir-BfLCckVj.js";import{I as O,M as k}from"./debug-2pVES-2G.js";import{d as A,h as j}from"./config-Bio2EjUK.js";import{n as M,t as N}from"./SpinnerGlyph-BR_SiV9L.js";import{n as P,r as F}from"./sideQuestion-C8GNVo4R.js";import{i as I,n as L}from"./modalContext-sU2lfR08.js";function R({question:e,context:t,onDone:i}){let[s,c]=(0,H.useState)(null),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(0),m=(0,H.useRef)(null),{rows:h}=I(o());a(()=>p(e=>e+1),s||u?null:80);function g(e){if(e.key===`escape`||e.key===`return`||e.key===` `||e.ctrl&&(e.key===`c`||e.key===`d`)){e.preventDefault(),i(void 0,{display:`skip`});return}(e.key===`up`||e.ctrl&&e.key===`p`)&&(e.preventDefault(),m.current?.scrollBy(-3)),(e.key===`down`||e.ctrl&&e.key===`n`)&&(e.preventDefault(),m.current?.scrollBy(K))}(0,H.useEffect)(()=>{let n=y();async function r(){try{let r=await F({question:e,cacheSafeParams:await B(t)});n.signal.aborted||(r.response?c(r.response):d(`No response received`))}catch(e){n.signal.aborted||d(k(e)||`Failed to get response`)}}return r(),()=>{n.abort()}},[e,t]);let _=Math.max(5,h-W-G);return(0,U.jsxs)(n,{flexDirection:`column`,paddingLeft:2,marginTop:1,tabIndex:0,autoFocus:!0,onKeyDown:g,children:[(0,U.jsxs)(n,{children:[(0,U.jsxs)(r,{color:`warning`,bold:!0,children:[`/btw`,` `]}),(0,U.jsx)(r,{dimColor:!0,children:e})]}),(0,U.jsx)(n,{marginTop:1,marginLeft:2,maxHeight:_,children:(0,U.jsx)(l,{ref:m,flexDirection:`column`,flexGrow:1,children:u?(0,U.jsx)(r,{color:`error`,children:u}):s?(0,U.jsx)(S,{children:s}):(0,U.jsxs)(n,{children:[(0,U.jsx)(N,{frame:f,messageColor:`warning`}),(0,U.jsx)(r,{color:`warning`,children:`Answering...`})]})})}),(s||u)&&(0,U.jsx)(n,{marginTop:1,children:(0,U.jsxs)(r,{dimColor:!0,children:[`↑`,`/`,`↓`,` to scroll · Space, Enter, or Escape to dismiss`]})})]})}function z(e){let t=e.at(-1);return t?.type===`assistant`&&t.message.stop_reason===null?e.slice(0,-1):e}async function B(e){let t=f(z(e.messages)),n=p();if(n)return{systemPrompt:n.systemPrompt,userContext:n.userContext,systemContext:n.systemContext,toolUseContext:e,forkContextMessages:t};let[r,i,a]=await Promise.all([x(e.options.tools,e.options.mainLoopModel,[],e.options.mcpClients),_(),h()]);return{systemPrompt:E(r),userContext:i,systemContext:a,toolUseContext:e,forkContextMessages:t}}async function V(e,t,n){let r=n?.trim();return r?(j(e=>({...e,btwUseCount:e.btwUseCount+1})),(0,U.jsx)(R,{question:r,context:t,onDone:e})):(e(`Usage: /btw <your question>`,{display:`system`}),null)}var H,U,W,G,K;e((()=>{H=t(i(),1),c(),T(),M(),d(),w(),L(),v(),C(),s(),m(),A(),O(),g(),b(),P(),D(),U=u(),W=5,G=6,K=3}))();export{V as call};
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./caches-fqs-Y-kW.js";e();export{t as clearSessionCaches};
@@ -0,0 +1 @@
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{ei as t,ii as n}from"./settings-D4M13toi.js";import{Pt as r,l as i,mn as a}from"./state-CXY-q5gr.js";import{B_ as o,Bu as s,F_ as c,Hi as l,I_ as u,Ki as d,L_ as f,My as p,Pi as m,Pp as h,R_ as g,Ru as _,Tb as v,Ti as y,V_ as b,Y as x,_p as S,dh as C,dm as w,fh as T,hp as E,is as D,jy as O,lm as k,q as A,rs as j,wb as M,z_ as N}from"./loadAgentsDir-BfLCckVj.js";import{a as P,n as F}from"./fileSuggestions-BRwKV_KA.js";import{r as I,t as L}from"./magicDocs-Bue9vxzY.js";import{r as R,t as z}from"./detectRepository--luIRv5H.js";function B(e=new Set){let n=e.size>0;f.cache.clear?.(),u.cache.clear?.(),c.cache.clear?.(),o.cache.clear?.(),F(),y(),n||S(),N(null),a(null),w(),D(),p(`session_start`),_(),z(),A(),i(e),t(),l(),T(),L(),M(),import(`./SearchExtraToolsTool-BINZTstr.js`).then(({clearSearchExtraToolsDescriptionCache:e})=>e()),import(`./loadAgentsDir-BImZsKrh.js`).then(({clearAgentDefinitionsCache:e})=>e()),import(`./prompt-CAzFDybL.js`).then(({clearPromptCache:e})=>e())}var V=e((()=>{r(),m(),b(),g(),P(),h(),E(),k(),C(),I(),d(),j(),x(),O(),R(),n(),s(),v()}));export{V as n,B as t};
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./defineProperty-C-QyHrDq.js";import{n,t as r}from"./axios-DaWTGg7G.js";import{n as i,r as a}from"./wrapper-DVKxC5fR.js";import{Pt as o,Vt as s}from"./settings-D4M13toi.js";import{U as c,W as l}from"./loadAgentsDir-BfLCckVj.js";import{c as u,i as d}from"./debug-2pVES-2G.js";import{d as f,o as p}from"./config-Bio2EjUK.js";import{o as m,s as h}from"./log-L1kqxa_P.js";import{c as g,l as _,n as v,o as y,r as b,s as x,t as S,u as C}from"./bridgeControl-C8xaGuwO.js";import{createInterface as w}from"node:readline";import{spawn as T}from"node:child_process";import{randomUUID as E}from"node:crypto";import{EventEmitter as D}from"node:events";import O from"events";m(),c(),g(),v(),d(),e();var k=`https://api.dingtalk.com`,A=`https://oapi.dingtalk.com`,j=`/gettoken`,M=`/v1.0/card/instances/createAndDeliver`,N=`/v1.0/card/streaming`,P=300*1e3,F=class{constructor(e){t(this,`opts`,void 0),t(this,`tokenCache`,null),this.opts=e}async getAccessToken(){if(this.tokenCache&&Date.now()<this.tokenCache.expiresAt-P)return this.tokenCache.token;let e=`${A}${j}?appkey=${encodeURIComponent(this.opts.appKey)}&appsecret=${encodeURIComponent(this.opts.appSecret)}`,t=await(await fetch(e)).json();if(t.errcode!==0||!t.access_token)throw Error(`gettoken 失败: errcode=${t.errcode} errmsg=${t.errmsg}`);return this.tokenCache={token:t.access_token,expiresAt:Date.now()+(t.expires_in??7200)*1e3},t.access_token}async createAndDeliverCard(e){let t=E(),n=e.conversationType===`2`,r=await this.getAccessToken(),i=n?`IM_GROUP`:`IM_ROBOT`,a=n?e.conversationId:e.senderStaffId,o={cardTemplateId:e.cardTemplateId,outTrackId:t,cardData:{cardParamMap:{content:e.initialMarkdown}},openSpaceId:`dtv1.card//${i}.${a}`};n?(o.imGroupOpenSpaceModel={supportForward:!0},o.imGroupOpenDeliverModel={robotCode:this.opts.robotCode}):(o.imRobotOpenSpaceModel={supportForward:!0},o.imRobotOpenDeliverModel={robotCode:this.opts.robotCode});let s=await fetch(`${k}${M}`,{method:`POST`,headers:{"Content-Type":`application/json`,"x-acs-dingtalk-access-token":r},body:JSON.stringify(o)});if(!s.ok){let e=await s.text();throw Error(`createAndDeliver 失败: ${s.status} ${e}`)}return u(`[channel] 卡片已创建 outTrackId=${t} ${n?`群聊`:`单聊`}`,{level:`debug`}),t}async streamingUpdate(e,t,n={}){let r=await this.getAccessToken(),i={outTrackId:e,guid:E(),key:`content`,content:t,isFull:!0,isFinalize:n.finalize??!1,isError:n.error??!1},a=await fetch(`${k}${N}`,{method:`PUT`,headers:{"Content-Type":`application/json`,"x-acs-dingtalk-access-token":r},body:JSON.stringify(i)});if(!a.ok){let e=await a.text();throw Error(`streaming 失败: ${a.status} ${e}`)}u(`[channel] streaming 推送 finalize=${n.finalize??!1} len=${t.length}`,{level:`debug`})}},I=`https://api.dingtalk.com/v1.0/gateway/connections/open`,L=`https://oapi.dingtalk.com/gettoken`,R=`/v1.0/im/bot/messages/get`;i(),r(),e();var z={autoReconnect:!0,keepAlive:!1,ua:``,subscriptions:[{type:`EVENT`,topic:`*`}]},B=class extends O{constructor(e){if(super(),t(this,`debug`,!1),t(this,`connected`,!1),t(this,`registered`,!1),t(this,`reconnecting`,!1),t(this,`userDisconnect`,!1),t(this,`reconnectBaseInterval`,1e3),t(this,`reconnectMaxInterval`,6e4),t(this,`reconnectAttempts`,0),t(this,`heartbeat_interval`,8e3),t(this,`heartbeatIntervallId`,void 0),t(this,`reconnectTimerId`,void 0),t(this,`isConnecting`,!1),t(this,`sslopts`,{rejectUnauthorized:!0}),t(this,`config`,void 0),t(this,`socket`,void 0),t(this,`dw_url`,void 0),t(this,`isAlive`,!1),t(this,`onEventReceived`,e=>({status:`SUCCESS`})),this.config={...z,...e},!this.config.clientId||!this.config.clientSecret)throw console.error(`clientId or clientSecret is null`),Error(`clientId or clientSecret is null`);this.config.debug!==void 0&&(this.debug=this.config.debug)}getConfig(){return{...this.config}}printDebug(e){if(this.debug){let t=`[`+new Date().toISOString()+`]`;console.info(t,e)}}registerAllEventListener(e){return this.onEventReceived=e,this}registerCallbackListener(e,t){if(!e||!t)throw console.error(`registerCallbackListener: eventId and callback must be defined`),Error(`registerCallbackListener: eventId and callback must be defined`);return this.config.subscriptions.find(t=>t.topic===e&&t.type===`CALLBACK`)||this.config.subscriptions.push({type:`CALLBACK`,topic:e}),this.on(e,t),this}async getAccessToken(){let e=await n.get(`${L}?appkey=${this.config.clientId}&appsecret=${this.config.clientSecret}`);if(e.status===200&&e.data.access_token)return this.config.access_token=e.data.access_token,e.data.access_token;throw Error(`getAccessToken: get access_token failed`)}async getEndpoint(){this.printDebug(`get connect endpoint by config`),this.printDebug(this.config);let e=await n({url:I,method:`POST`,responseType:`json`,data:{clientId:this.config.clientId,clientSecret:this.config.clientSecret,ua:this.config.ua,subscriptions:this.config.subscriptions},headers:{Accept:`application/json`}});if(this.printDebug(`res.data `+JSON.stringify(e.data)),e.data){this.config.endpoint=e.data;let{endpoint:t,ticket:n}=e.data;if(!t||!n)throw this.printDebug(`endpoint or ticket is null`),Error(`endpoint or ticket is null`);return this.dw_url=`${t}?ticket=${n}`,this}else throw Error(`build: get endpoint failed`)}cleanup(){this.heartbeatIntervallId!==void 0&&(clearInterval(this.heartbeatIntervallId),this.heartbeatIntervallId=void 0),this.socket&&(this.socket.removeAllListeners(),(this.socket.readyState===a.OPEN||this.socket.readyState===a.CONNECTING)&&this.socket.terminate(),this.socket=void 0)}scheduleReconnect(){if(!this.config.autoReconnect||this.userDisconnect||this.isConnecting)return;let e=Math.min(this.reconnectBaseInterval*2**this.reconnectAttempts+Math.random()*1e3,this.reconnectMaxInterval);this.reconnecting=!0,this.printDebug(`Reconnecting in `+(e/1e3).toFixed(1)+` seconds... (attempt `+(this.reconnectAttempts+1)+`)`),this.reconnectTimerId&&clearTimeout(this.reconnectTimerId),this.reconnectTimerId=setTimeout(()=>{this.reconnectTimerId=void 0,this.connect()},e)}_connect(){return new Promise((e,t)=>{this.printDebug(`Connecting to dingtalk websocket @ `+this.dw_url);try{this.socket=new a(this.dw_url,this.sslopts)}catch(e){this.printDebug(`WebSocket constructor error`),console.warn(`ERROR`,e),t(e);return}let n=!1;this.socket.on(`open`,()=>{this.connected=!0,this.reconnectAttempts=0,console.info(`[`+new Date().toISOString()+`] connect success`),this.config.keepAlive&&(this.isAlive=!0,this.heartbeatIntervallId=setInterval(()=>{var e;if(this.isAlive===!1)return console.error(`TERMINATE SOCKET: Ping Pong does not transfer heartbeat within heartbeat intervall`),this.socket?.terminate();this.isAlive=!1,(e=this.socket)==null||e.ping(``,!0)},this.heartbeat_interval)),n=!0,e()}),this.socket.on(`pong`,()=>{this.heartbeat()}),this.socket.on(`message`,e=>{this.onDownStream(e)}),this.socket.on(`close`,()=>{this.printDebug(`Socket closed`),this.connected=!1,this.registered=!1,this.heartbeatIntervallId!==void 0&&(clearInterval(this.heartbeatIntervallId),this.heartbeatIntervallId=void 0),n&&this.scheduleReconnect()}),this.socket.on(`error`,e=>{var r;this.printDebug(`SOCKET ERROR`),console.warn(`ERROR`,e),(r=this.socket)==null||r.terminate(),n||(n=!0,t(e))})})}async connect(){if(this.isConnecting){this.printDebug(`connect() already in progress, skipping`);return}this.userDisconnect=!1,this.isConnecting=!0;try{if(this.cleanup(),await this.getEndpoint(),this.userDisconnect)return;await this._connect()}catch(e){this.printDebug(`Connect failed: `+(e instanceof Error?e.message:String(e))),this.userDisconnect||(this.reconnectAttempts++,this.isConnecting=!1,this.scheduleReconnect());return}finally{this.isConnecting=!1}}disconnect(){console.info(`Disconnecting.`),this.userDisconnect=!0,this.reconnectTimerId&&(clearTimeout(this.reconnectTimerId),this.reconnectTimerId=void 0),this.reconnecting=!1,this.reconnectAttempts=0,this.cleanup(),this.connected=!1,this.registered=!1}heartbeat(){this.isAlive=!0,this.printDebug(`CLIENT-SIDE HEARTBEAT`)}onDownStream(e){this.printDebug(`Received message from dingtalk websocket server`);let t=JSON.parse(e);switch(this.printDebug(t),t.type){case`SYSTEM`:this.onSystem(t);break;case`EVENT`:this.onEvent(t);break;case`CALLBACK`:this.onCallback(t);break}}onSystem(e){var t;switch(e.headers.topic){case`CONNECTED`:this.printDebug(`CONNECTED`);break;case`REGISTERED`:this.registered=!0,this.reconnecting=!1;break;case`disconnect`:this.connected=!1,this.registered=!1;break;case`KEEPALIVE`:this.heartbeat();break;case`ping`:this.printDebug(`PING`),(t=this.socket)==null||t.send(JSON.stringify({code:200,headers:e.headers,message:`OK`,data:e.data}));break}}onEvent(e){var t;this.printDebug(`received event, message=`+JSON.stringify(e));let n=this.onEventReceived(e);(t=this.socket)==null||t.send(JSON.stringify({code:200,headers:{contentType:`application/json`,messageId:e.headers.messageId},message:`OK`,data:JSON.stringify(n)}))}onCallback(e){this.emit(e.headers.topic,e)}send(e,t){var n;if(!e)throw console.error(`send: messageId must be defined`),Error(`send: messageId must be defined`);let r={code:200,headers:{contentType:`application/json`,messageId:e},message:`OK`,data:JSON.stringify(t)};(n=this.socket)==null||n.send(JSON.stringify(r))}socketCallBackResponse(e,t){this.send(e,{response:t})}sendGraphAPIResponse(e,t){var n;if(!e)throw console.error(`send: messageId must be defined`),Error(`send: messageId must be defined`);let r={code:200,headers:{contentType:`application/json`,messageId:e},message:`OK`,data:JSON.stringify(t)};(n=this.socket)==null||n.send(JSON.stringify(r))}};i(),d(),e();var V=class{constructor(e){t(this,`opts`,void 0),t(this,`client`,void 0),t(this,`messageHandler`,void 0),this.opts=e,this.client=new B({clientId:e.appKey,clientSecret:e.appSecret,debug:!1,keepAlive:!0})}onMessage(e){this.messageHandler=e,this.client.registerCallbackListener(R,e=>{this.handleDownstream(e)})}handleDownstream(e){try{let t=JSON.parse(e.data);if(u(`[channel] downstream 到达: msgtype=${t.msgtype} sender=${t.senderNick} conv=${t.conversationId}`,{level:`debug`}),t.msgtype!==`text`||!t.text?.content){u(`[channel] 丢弃: msgtype=${t.msgtype} 非文本或空 content`,{level:`debug`});return}let n=t.text.content.trim(),r=this.stripMention(n);if(!r){u(`[channel] 丢弃: 纯 @ 无正文`,{level:`debug`});return}u(`[channel] 派发消息: text="${r.slice(0,50)}" sender=${t.senderNick}`,{level:`debug`}),this.messageHandler?.({conversationId:t.conversationId,senderStaffId:t.senderStaffId,senderNick:t.senderNick,conversationType:t.conversationType,text:r,msgId:t.msgId,sessionWebhook:t.sessionWebhook,sessionWebhookExpiredTime:t.sessionWebhookExpiredTime,isAdmin:t.isAdmin})}catch(e){h(e)}try{this.client.socketCallBackResponse(e.headers.messageId,{status:`SUCCESS`,message:`OK`})}catch{}}stripMention(e){if(!this.opts.robotName)return e;let t=this.opts.robotName.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(RegExp(`^@${t}\\s*`),``).trim()}async connect(){await this.client.connect(),u(`[channel] dingtalk stream 已连接`,{level:`debug`})}disconnect(){this.client.disconnect()}async sendText(e,t){if(e)try{await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({msgtype:`text`,text:{content:t}})})}catch(e){h(e)}}async sendMarkdown(e,t,n){if(e)try{await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({msgtype:`markdown`,markdown:{title:t,text:n}})})}catch(e){h(e)}}};d(),m(),o(),e();var H=1800*1e3;function U(e){let t=process.argv[1];return t&&/\.(cjs|js|mjs)$/.test(t)?{execPath:process.execPath,args:[t,...e]}:{execPath:process.execPath,args:e}}var W=class{constructor(e){t(this,`opts`,void 0),t(this,`proc`,null),t(this,`rl`,null),t(this,`emitter`,new D),t(this,`lastActiveAt`,Date.now()),t(this,`idleTimer`,null),t(this,`closed`,!1),this.opts=e}onEvent(e){this.emitter.on(`event`,e)}async start(){let e=[`--print`,`--input-format`,`stream-json`,`--output-format`,`stream-json`,`--verbose`,`--permission-mode`,s(this.opts.permissionMode)];this.opts.sessionId&&e.splice(1,0,`--resume`,this.opts.sessionId);let{execPath:t,args:n}=U(e);this.proc=T(t,n,{stdio:[`pipe`,`pipe`,`pipe`],env:{...process.env,WORKMATE_INCLUDE_PARTIAL_MESSAGES:`true`,WORKMATE_STREAMLINED_OUTPUT:`true`}}),this.proc.on(`exit`,e=>{this.closed=!0,this.emit({type:`exit`,code:e}),this.cleanup()}),this.proc.on(`error`,e=>{h(e),this.emit({type:`stderr`,data:String(e)})}),this.proc.stderr&&this.proc.stderr.on(`data`,e=>{let t=e.toString();u(`[channel] workmate stderr: ${t}`,{level:`debug`}),this.emit({type:`stderr`,data:t})}),this.proc.stdout&&(this.rl=w({input:this.proc.stdout,crlfDelay:1/0}),this.rl.on(`line`,e=>this.handleLine(e))),this.idleTimer=setInterval(()=>this.checkIdle(),6e4)}checkIdle(){this.closed||Date.now()-this.lastActiveAt>H&&(u(`[channel] workmate 子进程 idle 超时,回收`,{level:`debug`}),this.kill())}sendUserMessage(e){this.write({type:`user`,message:{role:`user`,content:e},parent_tool_use_id:null,priority:`now`}),this.lastActiveAt=Date.now()}respondPermission(e,t){this.write({type:`control_response`,response:{subtype:`success`,request_id:e,response:t}}),this.lastActiveAt=Date.now()}autoAllow(e){this.respondPermission(e,{behavior:`allow`})}interrupt(){this.write({type:`control_request`,request_id:E(),request:{subtype:`interrupt`}})}handleLine(e){let t=e.trim();if(!t)return;this.lastActiveAt=Date.now();let n;try{n=JSON.parse(t)}catch{return}switch(n.type){case`stream_event`:{let e=n.event;e?.type===`content_block_delta`&&e.delta?.type===`text_delta`&&typeof e.delta.text==`string`?this.emit({type:`text`,text:e.delta.text}):e?.type===`message_stop`&&this.emit({type:`message_end`});break}case`streamlined_text`:this.emit({type:`text`,text:String(n.text)}),this.emit({type:`message_end`});break;case`streamlined_tool_use_summary`:this.emit({type:`tool_summary`,summary:String(n.tool_summary)});break;case`control_request`:{let e=n.request;e?.subtype===`can_use_tool`&&this.emit({type:`permission_request`,requestId:String(n.request_id),toolName:String(e.tool_name??``),input:e.input??{},toolUseId:String(e.tool_use_id??``)});break}case`result`:this.emit({type:`turn_end`,subtype:n.subtype===`error`?`error`:`success`,resultText:typeof n.result==`string`?n.result:void 0,durationMs:typeof n.duration_ms==`number`?n.duration_ms:void 0,sessionId:typeof n.session_id==`string`?n.session_id:void 0});break;case`keep_alive`:break}}emit(e){this.emitter.emit(`event`,e)}write(e){!this.proc?.stdin?.writable||this.closed||this.proc.stdin.write(`${JSON.stringify(e)}\n`)}isAlive(){return!!this.proc&&!this.closed}kill(){if(!(this.closed||!this.proc)){try{this.proc.stdin?.end()}catch{}try{this.proc.kill(`SIGTERM`)}catch{}setTimeout(()=>{try{this.proc?.kill(`SIGKILL`)}catch{}},3e3)}}cleanup(){this.idleTimer&&(clearInterval(this.idleTimer),this.idleTimer=null),this.rl?.close(),this.rl=null,this.closed=!0}async stop(){this.kill(),this.proc&&await new Promise(e=>{if(this.closed)return e();this.proc.once(`exit`,()=>e()),setTimeout(e,5e3)}),this.cleanup()}};d(),m(),e();var G=400;function K(e,t){switch(t){case`perUser`:return`user:${e.senderStaffId}`;case`shared`:return`shared`;default:return`conv:${e.conversationId}`}}var q=class{constructor(e){t(this,`stream`,void 0),t(this,`sessions`,new Map),t(this,`config`,void 0),t(this,`running`,!1),t(this,`cardClient`,void 0),this.config=e??y(),this.stream=new V({appKey:this.config.appKey,appSecret:this.config.appSecret,robotName:this.config.robotName}),this.cardClient=this.config.cardTemplateId?new F({appKey:this.config.appKey,appSecret:this.config.appSecret,robotCode:this.config.appKey}):null}async start(){if(!this.config.appKey||!this.config.appSecret)throw Error(`钉钉 appKey/appSecret 未配置,请在 /channel 里填好`);this.stream.onMessage(e=>{this.handleMessage(e)}),await this.stream.connect(),this.running=!0;let e=()=>void this.stop();process.on(`SIGTERM`,e),process.on(`SIGINT`,e),u(`[channel] bridge 已启动,等待钉钉消息`,{level:`debug`})}async stop(){if(this.running){this.running=!1,this.stream.disconnect();for(let e of this.sessions.values())e.streamTimer&&clearTimeout(e.streamTimer),await e.driver.stop();this.sessions.clear(),u(`[channel] bridge 已停止`,{level:`debug`})}}async handleMessage(e){let t=K(e,this.config.sessionStrategy);u(`[channel] handleMessage: sender=${e.senderNick} conv=${e.conversationId} text="${e.text.slice(0,50)}"`,{level:`debug`});let n=this.sessions.get(t);if(n||(n=await this.createSession(t,e),this.sessions.set(t,n)),n.sessionWebhook=e.sessionWebhook,n.currentSenderStaffId=e.senderStaffId,n.pendingConfirm){let t=J(e.text);if(t!==null){let r=n.pendingConfirm;if(n.pendingConfirm=null,!this.canConfirm(e.senderStaffId,r.senderStaffId)){await this.stream.sendText(e.sessionWebhook,`⚠️ 只有任务发起人或管理员能确认`);return}t.behavior===`terminate`?(n.driver.respondPermission(r.requestId,{behavior:`deny`,message:`用户在钉钉终止任务`}),n.driver.interrupt(),await this.stream.sendText(e.sessionWebhook,`🛑 已终止整个任务`)):(n.driver.respondPermission(r.requestId,t),await this.stream.sendText(e.sessionWebhook,t.behavior===`allow`?`✅ 已同意,继续执行`:`❌ 已拒绝此工具,继续下一步`));return}n.pendingConfirm=null}n.textBuffer=``,n.turnInProgress=!0,n.cardOutTrackId=null,n.conversationType=e.conversationType,n.conversationId=e.conversationId,n.streamTimer&&(clearTimeout(n.streamTimer),n.streamTimer=null),n.driver.sendUserMessage(e.text),u(`[channel] 已发 driver.sendUserMessage`,{level:`debug`})}async createSession(e,t){let n=this.config.sessions[e]?.workmateSessionId??``;u(`[channel] ${n?`复用`:`新建`}会话: ${e} sid=${n||`(待 workmate 分配)`}`,{level:`debug`});let r=new W({sessionId:n||null,permissionMode:x(this.config)});return await r.start(),r.onEvent(t=>{this.handleDriverEvent(e,t)}),{driver:r,workmateSessionId:n,sessionWebhook:t.sessionWebhook,currentSenderStaffId:t.senderStaffId,conversationType:t.conversationType,conversationId:t.conversationId,textBuffer:``,turnInProgress:!1,pendingConfirm:null,cardOutTrackId:null,streamTimer:null}}async handleDriverEvent(e,t){let n=this.sessions.get(e);if(n)switch(t.type){case`text`:if(!n.cardOutTrackId&&this.cardClient&&n.turnInProgress)try{n.cardOutTrackId=await this.cardClient.createAndDeliverCard({conversationType:n.conversationType,conversationId:n.conversationId,senderStaffId:n.currentSenderStaffId,cardTemplateId:this.config.cardTemplateId,initialMarkdown:` `})}catch(e){h(e),u(`[channel] 卡片创建失败,回退整段 sendText`,{level:`debug`}),n.cardOutTrackId=null}n.textBuffer+=t.text,n.cardOutTrackId&&this.cardClient&&this.scheduleStreamPush(n);break;case`message_end`:if(n.streamTimer&&(clearTimeout(n.streamTimer),n.streamTimer=null),n.cardOutTrackId&&this.cardClient){let e=n.cardOutTrackId;n.cardOutTrackId=null;try{await this.cardClient.streamingUpdate(e,n.textBuffer,{finalize:!0})}catch(e){h(e),n.textBuffer.trim()&&await this.stream.sendText(n.sessionWebhook,n.textBuffer)}}else n.textBuffer.trim()&&await this.stream.sendText(n.sessionWebhook,n.textBuffer);n.textBuffer=``;break;case`tool_summary`:break;case`turn_end`:{n.turnInProgress=!1;let r=t.sessionId;if(r&&r!==n.workmateSessionId&&(n.workmateSessionId=r,C(t=>({...t,sessions:{...t.sessions,[e]:{workmateSessionId:r,lastActiveAt:Date.now(),senderId:n.currentSenderStaffId}}})),this.config=y()),n.streamTimer&&(clearTimeout(n.streamTimer),n.streamTimer=null),n.cardOutTrackId&&this.cardClient){let e=n.cardOutTrackId;n.cardOutTrackId=null;let r=n.textBuffer||t.resultText||``;n.textBuffer=``;try{await this.cardClient.streamingUpdate(e,r,{finalize:!0})}catch(e){h(e),r.trim()&&await this.stream.sendText(n.sessionWebhook,r)}}else if(n.textBuffer.trim()){let e=n.textBuffer;n.textBuffer=``,await this.stream.sendText(n.sessionWebhook,e)}else t.subtype===`success`&&t.resultText?.trim()&&await this.stream.sendText(n.sessionWebhook,t.resultText);u(`[channel] turn_end: subtype=${t.subtype} sid=${t.sessionId??`-`} resultText=${t.resultText?`"${t.resultText.slice(0,50)}"`:`(空)`}`,{level:`debug`});break}case`permission_request`:await this.handlePermissionRequest(n,t);break;case`stderr`:break;case`exit`:u(`[channel] workmate 子进程退出 code=${t.code},清会话 ${e}`,{level:`debug`}),n.streamTimer&&(clearTimeout(n.streamTimer),n.streamTimer=null),this.sessions.delete(e);break}}async handlePermissionRequest(e,t){if(l(t.toolName)){e.driver.autoAllow(t.requestId),u(`[channel] 只读工具 autoAllow: ${t.toolName}`,{level:`debug`});return}if(!this.config.confirmDangerous){e.driver.autoAllow(t.requestId);return}e.pendingConfirm={requestId:t.requestId,webhook:e.sessionWebhook,senderStaffId:e.currentSenderStaffId,toolName:t.toolName},u(`[channel] permission_request: tool=${t.toolName}`,{level:`debug`});let n=JSON.stringify(t.input,null,2).slice(0,500),r=Math.round(this.config.confirmTimeoutMs/6e4);await this.stream.sendMarkdown(e.sessionWebhook,`需要确认`,`### ⚠️ 需要确认:${t.toolName}\n\n**参数预览:**\n\`\`\`json\n${n}\n\`\`\`\n\n**选项:**\n- 回复「**同意**」→ 执行此工具\n- 回复「**拒绝**」→ 跳过此工具,继续下一步\n- 回复「**终止**」→ 终止整个任务\n\n⏰ ${r} 分钟无回复自动拒绝`),setTimeout(()=>{if(e.pendingConfirm?.requestId===t.requestId){e.pendingConfirm=null;try{e.driver.respondPermission(t.requestId,{behavior:`deny`,message:`确认超时`})}catch(e){h(e)}this.stream.sendText(e.sessionWebhook,`⏰ 确认超时,已拒绝执行`)}},this.config.confirmTimeoutMs)}scheduleStreamPush(e){e.streamTimer||(e.streamTimer=setTimeout(()=>{e.streamTimer=null,!(!e.cardOutTrackId||!this.cardClient)&&this.cardClient.streamingUpdate(e.cardOutTrackId,e.textBuffer).catch(e=>h(e))},G))}canConfirm(e,t){return!!(this.config.admins.includes(e)||t&&e===t||!t)}};function J(e){let t=e.trim().toLowerCase();return[`同意`,`yes`,`y`,`确认`,`ok`,`allow`,`同意了`].includes(t)?{behavior:`allow`}:[`拒绝`,`no`,`n`,`cancel`,`deny`,`不同意`,`拒绝执行`].includes(t)?{behavior:`deny`,message:`用户在钉钉拒绝`}:[`终止`,`stop`,`abort`,`中止`,`终止任务`,`终止整个任务`].includes(t)?{behavior:`terminate`}:null}g(),f(),m();async function Y(e){let t=e[0]??`start`;switch(t){case`start`:await X();break;case`status`:Z();break;case`stop`:console.log(`请在 workmate 交互会话里用 /channel 停止 bridge`);break;default:console.error(`未知子命令: ${t}。可用: start | status`),process.exit(1)}}async function X(){_(p())||(console.error(`channel 未启用。请在交互会话里运行 /channel,开启 channel 并选择 activePlugin=dingtalk`),process.exit(1));let e=new q;try{await e.start(),console.log(`[channel] bridge 已启动,Ctrl+C 退出`),await new Promise(()=>{})}catch(e){h(e),console.error(`bridge 启动失败: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}function Z(){let e=b(),t=S(),n=y(),r=_(p());console.log(`channel.enabled: ${r}`),console.log(`bridge.running: ${e}`),t&&console.log(`bridge.pid: ${t}`),console.log(`dingtalk.appKey: ${n.appKey?`已配置`:`未配置`}`),console.log(`dingtalk.robotName: ${n.robotName}`),console.log(`dingtalk.permissionMode: ${n.permissionMode}`),console.log(`dingtalk.sessionStrategy: ${n.sessionStrategy}`),console.log(`dingtalk.confirmDangerous: ${n.confirmDangerous}`),console.log(`sessions: ${Object.keys(n.sessions).length} 个`)}export{Y as channelMain};
@@ -0,0 +1 @@
1
+ import{n as e,o as t}from"./rolldown-runtime-DaDcL9Zw.js";import{I as n,P as r,ai as i,t as a}from"./src-BX54x08P.js";import{t as o}from"./jsx-runtime-Bb4Xn-E0.js";import{d as s,h as c,o as l}from"./config-Bio2EjUK.js";import{n as u,t as d}from"./select-Bm29ymsI.js";import{a as f,c as p,i as m,n as h,o as g,r as _,t as v,u as y}from"./bridgeControl-C8xaGuwO.js";function b({onClose:e}){let[t,i]=(0,x.useState)(0),[a,o]=(0,x.useState)(``),s=l(),u=g(),p=s.channel?.enabled===!0,h=s.channel?.activePlugin??null,b=_(),T=v();function E(){i(e=>e+1)}function D(e,t){c(n=>({...n,channel:{enabled:e,activePlugin:t}})),E()}function O(e,t,n){let r=t[(t.indexOf(e)+1)%t.length];n(r),E()}let k=[{label:(0,S.jsxs)(r,{children:[`Channel 开关:`,(0,S.jsx)(r,{bold:!0,children:p?`on`:`off`})]}),value:`toggle-enabled`},{label:(0,S.jsxs)(r,{children:[`激活渠道:`,(0,S.jsx)(r,{bold:!0,children:h??`(无)`})]}),value:`set-plugin`},{label:(0,S.jsxs)(r,{children:[`钉钉 corpid:`,(0,S.jsx)(r,{dimColor:!0,children:u.corpid||`(空) 编辑 dingtalk.json`})]}),value:`noop:corpid`},{label:(0,S.jsxs)(r,{children:[`钉钉 AppKey:`,(0,S.jsx)(r,{dimColor:!0,children:u.appKey?`已配置`:`(空) 编辑 dingtalk.json`})]}),value:`noop:appKey`},{label:(0,S.jsxs)(r,{children:[`钉钉 AppSecret:`,(0,S.jsx)(r,{dimColor:!0,children:u.appSecret?`已配置`:`(空) 编辑 dingtalk.json`})]}),value:`noop:appSecret`},{label:(0,S.jsxs)(r,{children:[`机器人名:`,(0,S.jsx)(r,{bold:!0,children:u.robotName})]}),value:`noop:robotName`},{label:(0,S.jsxs)(r,{children:[`AI 卡片模板:`,(0,S.jsx)(r,{dimColor:!0,children:u.cardTemplateId?`已配置`:`(空) 编辑 dingtalk.json`})]}),value:`noop:cardTemplateId`},{label:(0,S.jsxs)(r,{children:[`权限模式:`,(0,S.jsx)(r,{bold:!0,children:u.permissionMode})]}),value:`cycle-permissionMode`},{label:(0,S.jsxs)(r,{children:[`会话策略:`,(0,S.jsx)(r,{bold:!0,children:u.sessionStrategy}),(0,S.jsx)(r,{dimColor:!0,children:` (perConversation=每群一会话 / perUser=每人一会话 / shared=共用)`})]}),value:`cycle-sessionStrategy`},{label:(0,S.jsxs)(r,{children:[`危险操作钉钉确认:`,(0,S.jsx)(r,{bold:!0,children:u.confirmDangerous?`on`:`off`})]}),value:`toggle-confirmDangerous`},{label:(0,S.jsxs)(r,{bold:b,children:[b?`▶ bridge 运行中`:`▶ 启动 bridge`,T?` (pid=${T})`:``]}),value:`action:start`},{label:(0,S.jsx)(r,{bold:b,children:`■ 停止 bridge`}),value:`action:stop`}];function A(e){switch(o(``),e){case`toggle-enabled`:D(!p,h??`dingtalk`);break;case`set-plugin`:D(!0,`dingtalk`);break;case`cycle-permissionMode`:O(u.permissionMode,C,e=>y(t=>({...t,permissionMode:e})));break;case`cycle-sessionStrategy`:O(u.sessionStrategy,w,e=>y(t=>({...t,sessionStrategy:e})));break;case`toggle-confirmDangerous`:y(e=>({...e,confirmDangerous:!e.confirmDangerous})),E();break;case`action:start`:{let e=m();o(e.started?`bridge 已启动 (pid=${e.pid})`:`bridge 已在运行 (pid=${e.pid})`),E();break}case`action:stop`:{let e=f();o(e?`已发停止信号`:`bridge 未运行`),E();break}default:e.startsWith(`noop:`)&&o(`请编辑 ~/.workmate/channel/dingtalk.json 填入该字段`)}}return(0,S.jsxs)(n,{flexDirection:`column`,padding:1,children:[(0,S.jsxs)(n,{marginBottom:1,flexDirection:`column`,children:[(0,S.jsx)(r,{bold:!0,children:`远程对话渠道(钉钉)`}),(0,S.jsx)(r,{dimColor:!0,children:`↑↓ 导航 · Enter 切换/执行 · Esc 退出`}),(0,S.jsx)(r,{dimColor:!0,children:`corpid/AppKey/AppSecret 请直接编辑 ~/.workmate/channel/dingtalk.json`})]}),(0,S.jsx)(d,{options:k,onChange:A,onCancel:e,visibleOptionCount:k.length},t),a&&(0,S.jsx)(n,{marginTop:1,children:(0,S.jsx)(r,{bold:!0,children:a})})]})}var x,S,C,w,T=e((()=>{a(),x=t(i(),1),u(),s(),p(),h(),S=o(),C=[`default`,`acceptEdits`,`bypassPermissions`,`plan`,`dontAsk`,`auto`],w=[`perConversation`,`perUser`,`shared`]})),E,D;e((()=>{T(),E=o(),D=async e=>(0,E.jsx)(b,{onClose:()=>e()})}))();export{D as call};
@@ -1 +1 @@
1
- import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{n as t,t as n}from"./conversation-Cjaftrrw.js";var r;e((()=>{t(),r=async(e,t)=>(await n(t),{type:`text`,value:``})}))();export{r as call};
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{n as t,t as n}from"./conversation-BFL0rEIx.js";var r;e((()=>{t(),r=async(e,t)=>(await n(t),{type:`text`,value:``})}))();export{r as call};
@@ -0,0 +1 @@
1
+ import{Pi as e,Ti as t,ki as n}from"./loadAgentsDir-BfLCckVj.js";e();export{t as clearCommandsCache,n as getCommands};
@@ -0,0 +1,2 @@
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{di as t,fi as n}from"./src-BX54x08P.js";import{It as r,Pt as i}from"./state-CXY-q5gr.js";import{$g as a,Bx as o,H_ as s,I_ as c,K_ as l,L_ as u,N_ as d,P_ as f,Qg as p,R_ as m,U_ as h,Xg as g,Xi as _,Yg as v,am as y,cb as b,ct as x,dm as S,gn as C,gp as w,hp as T,id as E,im as D,lm as O,lt as k,q_ as A,rd as j,sb as M,sv as N,tv as P}from"./loadAgentsDir-BfLCckVj.js";import{F,I}from"./debug-2pVES-2G.js";import{o as L,s as R}from"./log-L1kqxa_P.js";function z(e,n){let r=j(`tip`),i=M(`app:toggleTranscript`,`Global`,`ctrl+o`),a=[...e.options.verbose?[]:[`(${i} to see full summary)`],...n?[n]:[],...r?[r]:[]];return t.dim(`Compacted ${a.join(`
2
+ `)}`)}async function B(e,t){let n=e.getAppState(),r=await x(e.options.tools,e.options.mainLoopModel,Array.from(n.toolPermissionContext.additionalWorkingDirectories.keys()),e.options.mcpClients),i=d({mainThreadAgentDefinition:void 0,toolUseContext:e,customSystemPrompt:e.options.customSystemPrompt,defaultSystemPrompt:r,appendSystemPrompt:e.options.appendSystemPrompt}),[a,o]=await Promise.all([u(),c()]);return{systemPrompt:i,userContext:a,systemContext:o,toolUseContext:e,forkContextMessages:t}}var V;e((()=>{n(),i(),k(),m(),b(),T(),a(),l(),s(),O(),D(),P(),I(),C(),L(),_(),E(),f(),V=async(e,t)=>{let{abortController:n}=t,{messages:i}=t;if(i=o(i),i.length===0)throw Error(`No messages to compact`);let a=e.trim();try{if(!a){let e=await y(i,t.agentId);if(e)return u.cache.clear?.(),S(),w(t.options.querySource??`compact`,t.agentId),r(),A(),{type:`compact`,compactionResult:e,displayText:z(t)}}let e=(await h(i,t)).messages,n=await p(e,t,await B(t,e),!1,a,!1);return N(void 0),A(),u.cache.clear?.(),S(),{type:`compact`,compactionResult:n,displayText:z(t,n.userDisplayMessage)}}catch(e){throw n.signal.aborted?Error(`Compaction canceled.`):F(e,`Not enough messages to compact. Send a few more messages first, then try again.`)?Error(g):F(e,`Compaction interrupted · This may be due to network issues — please try again.`)?Error(v):(R(e),Error(`Error during compaction: ${e}`))}}}))();export{V as call};
@@ -1,3 +1,3 @@
1
- import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{n as t,t as n}from"./isObject-C6qM3WEW.js";import{n as r,t as i}from"./memoize-BK3gG5ob.js";import{c as a,i as o,l as s,o as c}from"./envUtils-QyzA_cFM.js";import{Ai as l,Cn as u,Ei as d,In as ee,Kn as te,Rr as ne,Sn as re,Ti as ie,Xt as ae,Yt as f,bi as oe,bn as p,di as m,ki as se,kr as ce,m as le,mr as h,pr as ue,qr as de,rn as fe,s as g,t as pe,tn as me,ui as he,vn as ge,yi as _e}from"./settings-D4M13toi.js";import{Hr as ve,Jr as ye,Pt as be,Ur as xe,X as _,Xr as Se,Yr as Ce,Zr as we,_r as Te,ai as Ee,ar as De,cr as Oe,dr as ke,ei as Ae,fr as je,gr as Me,ii as Ne,ir as Pe,lr as Fe,pr as v,q as Ie,st as Le,ti as Re,ur as ze}from"./state-CXY-q5gr.js";import{n as Be,t as Ve}from"./cwd-DrEEb4f5.js";import{$ as He,C as y,I as Ue,N as b,O as x,S as We,c as S,et as Ge,f as Ke,i as qe,u as C,x as Je}from"./debug-2pVES-2G.js";import{d as Ye,o as Xe,s as Ze,u as Qe}from"./log-L1kqxa_P.js";import{n as $e}from"./analytics-COpjZpvd.js";import{i as et,n as tt}from"./lockfile-D_9vif6E.js";import{homedir as nt}from"os";import{basename as w,dirname as T,isAbsolute as rt,join as E,normalize as D,resolve as it,sep as at}from"path";import{unwatchFile as ot,watchFile as st}from"fs";import{randomBytes as ct}from"crypto";var O,lt=e((()=>{Ee(),oe(),Ce(),Se(),O=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)Ne(t,ye(e)),e=_e(e);return t}:we}));function ut(e){return Ae(e,d,O)}var dt=e((()=>{Re(),lt(),ie()}));function ft(){let e=process.env.WORKMATE_DISABLE_AUTO_MEMORY;if(s(e))return!1;if(a(e))return!0;if(s(process.env.WORKMATE_SIMPLE)||s(process.env.WORKMATE_REMOTE)&&!process.env.WORKMATE_REMOTE_MEMORY_DIR)return!1;let t=pe();return t.autoMemoryEnabled===void 0||t.autoMemoryEnabled}function pt(){return!1}function mt(){return process.env.WORKMATE_REMOTE_MEMORY_DIR?process.env.WORKMATE_REMOTE_MEMORY_DIR:o()}function ht(e,t){if(!e)return;let n=e;if(t&&(n.startsWith(`~/`)||n.startsWith(`~\\`))){let e=n.slice(2),t=D(e||`.`);if(t===`.`||t===`..`)return;n=E(nt(),e)}let r=D(n).replace(/[/\\]+$/,``);if(!(!rt(r)||r.length<3||/^[A-Za-z]:$/.test(r)||r.startsWith(`\\\\`)||r.startsWith(`//`)||r.includes(`\0`)))return(r+at).normalize(`NFC`)}function gt(){return ht(process.env.WORKMATE_COWORK_MEMORY_PATH_OVERRIDE,!1)}function _t(){return ht(g(`policySettings`)?.autoMemoryDirectory??g(`flagSettings`)?.autoMemoryDirectory??g(`localSettings`)?.autoMemoryDirectory??g(`userSettings`)?.autoMemoryDirectory,!0)}function vt(){return gt()!==void 0}function yt(){return ne(_())??_()}function bt(){return E(k(),Ct)}function xt(e){return D(e).startsWith(k())}var St,Ct,k,A=e((()=>{i(),be(),c(),de(),ue(),le(),St=`memory`,Ct=`MEMORY.md`,k=r(()=>(gt()??_t())||(E(E(mt(),`projects`),ce(yt()),St)+at).normalize(`NFC`),()=>_())}));function j(e,n,r,i){if(!t(e))return e;n=je(n,e);for(var a=-1,o=n.length,s=o-1,c=e;c!=null&&++a<o;){var l=ke(n[a]),u=r;if(l===`__proto__`||l===`constructor`||l===`prototype`)return e;if(a!=s){var d=c[l];u=i?i(d,l,c):void 0,u===void 0&&(u=t(d)?d:xe(n[a+1])?[]:{})}se(c,l,u),c=c[l]}return e}var M=e((()=>{l(),v(),ve(),n(),ze()}));function wt(e,t,n){for(var r=-1,i=t.length,a={};++r<i;){var o=t[r],s=Oe(e,o);n(s,o)&&j(a,je(o,e),s)}return a}var Tt=e((()=>{Fe(),M(),v()}));function N(e,t){if(e==null)return{};var n=Me(ut(e),function(e){return[e]});return t=Pe(t),wt(e,n,function(e,n){return t(e,n[0])})}var Et=e((()=>{Te(),De(),Tt(),dt()}));function P(){return{numStartups:0,installMethod:void 0,autoUpdates:void 0,theme:`dark`,preferredNotifChannel:`auto`,verbose:!1,editorMode:`normal`,autoCompactEnabled:!0,showTurnDuration:!0,hasSeenTasksHint:!1,hasUsedStash:!1,hasUsedBackgroundTask:!1,queuedCommandUpHintCount:0,diffTool:`auto`,env:{},tipsHistory:{},memoryUsageCount:0,promptQueueUseCount:0,btwUseCount:0,todoFeatureEnabled:!0,showExpandedTodos:!1,messageIdleNotifThresholdMs:6e4,fileCheckpointingEnabled:!0,terminalProgressBarEnabled:!0,cachedStatsigGates:{},cachedDynamicConfigs:{},respectGitignore:!0}}function Dt(){return G||(G=Ot())}function Ot(){if(Le())return!0;let e=z(),t=$();if(e.projects?.[t]?.hasTrustDialogAccepted)return!0;let n=h(Ve());for(;;){if(e.projects?.[n]?.hasTrustDialogAccepted)return!0;let t=h(it(n,`..`));if(t===n)break;n=t}return!1}function F(e){let t=K.config;return t?t.hasCompletedOnboarding===!0&&e.hasCompletedOnboarding!==!0:!1}function I(e){let t=null;try{Nt(f(),P,n=>{let r=e(n);return r===n?n:(t={...r,projects:At(n.projects)},t)})&&t&&R(t)}catch(n){S(`Failed to save config with lock: ${n}`,{level:`error`});let r=V(f(),P);if(F(r)){S(`saveGlobalConfig fallback: re-read config is missing auth that cache has; refusing to write. See GH #3117.`,{level:`error`});return}let i=e(r);if(i===r)return;t={...i,projects:At(r.projects)},Mt(f(),t,W),R(t)}}function kt(){let e=J+Y;e>0&&J/e,J=0,Y=0}function L(e){if(e.installMethod!==void 0)return e;let t=e,n=`unknown`,r=e.autoUpdates??!0;switch(t.autoUpdaterStatus){case`migrated`:n=`local`;break;case`installed`:n=`native`;break;case`disabled`:r=!1;break;case`enabled`:case`no_permissions`:case`not_configured`:n=`global`;break;case void 0:break}return{...e,installMethod:n,autoUpdates:r}}function At(e){if(!e)return e;let t={},n=!1;for(let[r,i]of Object.entries(e)){let e=i;if(e.history!==void 0){n=!0;let{history:i,...a}=e;t[r]=a}else t[r]=i}return n?t:e}function jt(){if(Z)return;Z=!0;let e=f();st(e,{interval:qt,persistent:!1},t=>{t.mtimeMs<=K.mtime||C().readFile(e,{encoding:`utf-8`}).then(e=>{if(t.mtimeMs<=K.mtime)return;let n=p(u(e));typeof n!=`object`||!n||(K={config:L({...P(),...n}),mtime:t.mtimeMs},q={mtime:t.mtimeMs,size:t.size})}).catch(()=>{})}),Ge(async()=>{ot(e),Z=!1})}function R(e){K={config:e,mtime:Date.now()},q=null}function z(){if(K.config)return J++,K.config;Y++;try{let e=null;try{e=C().statSync(f())}catch{}let t=L(V(f(),P));return K={config:t,mtime:e?.mtimeMs??Date.now()},q=e?{mtime:e.mtimeMs,size:e.size}:null,jt(),t}catch{return L(V(f(),P))}}function Mt(e,t,n){let r=T(e);C().mkdirSync(r),te(e,y(N(t,(e,t)=>y(e)!==y(n[t])),null,2),{encoding:`utf-8`,mode:384}),e===f()&&X++}function Nt(e,t,n){let r=t(),i=T(e),a=C();a.mkdirSync(i);let o;try{let i=`${e}.lock`,s=Date.now();if(o=et(e,{lockfilePath:i,onCompromised:e=>{S(`Config lock compromised: ${e}`,{level:`error`})}}),Date.now()-s>100&&S(`Lock acquisition took longer than expected - another Work Mate instance may be running`),q&&e===f())try{let t=a.statSync(e);(t.mtimeMs!==q.mtime||t.size!==q.size)&&(q.mtime,t.mtimeMs,q.size,t.size)}catch(e){if(b(e)!==`ENOENT`)throw e}let c=V(e,t);if(e===f()&&F(c))return S(`saveConfigWithLock: re-read config is missing auth that cache has; refusing to write to avoid wiping ~/.workmate.json. See GH #3117.`,{level:`error`}),!1;let l=n(c);if(l===c)return!1;let u=N(l,(e,t)=>y(e)!==y(r[t]));try{let t=w(e),n=B();try{a.mkdirSync(n)}catch(e){if(b(e)!==`EEXIST`)throw e}let r=a.readdirStringSync(n).filter(e=>e.startsWith(`${t}.backup.`)).sort().reverse(),i=r[0],o=i?Number(i.split(`.backup.`).pop()):0,s=Number.isNaN(o)||Date.now()-o>=6e4;if(s){let r=E(n,`${t}.backup.${Date.now()}`);a.copyFileSync(e,r)}let c=s?a.readdirStringSync(n).filter(e=>e.startsWith(`${t}.backup.`)).sort().reverse():r;for(let e of c.slice(5))try{a.unlinkSync(E(n,e))}catch{}}catch(e){b(e)!==`ENOENT`&&S(`Failed to backup config: ${e}`,{level:`error`})}return te(e,y(u,null,2),{encoding:`utf-8`,mode:384}),e===f()&&X++,!0}finally{o&&o()}}function Pt(){if(Q)return;let e=Date.now();m(`info`,`enable_configs_started`),Q=!0,V(f(),P,!0),m(`info`,`enable_configs_completed`,{duration_ms:Date.now()-e})}function B(){return E(o(),`backups`)}function Ft(e){let t=C(),n=w(e),r=B();try{let e=t.readdirStringSync(r).filter(e=>e.startsWith(`${n}.backup.`)).sort().at(-1);if(e)return E(r,e)}catch{}let i=T(e);try{let r=t.readdirStringSync(i).filter(e=>e.startsWith(`${n}.backup.`)).sort().at(-1);if(r)return E(i,r);let a=`${e}.backup`;try{return t.statSync(a),a}catch{}}catch{}return null}function V(e,t,n){if(!Q)throw Error(`Config accessed before allowed.`);let r=C();try{let n=r.readFileSync(e,{encoding:`utf-8`});try{let e=We(u(n));return{...t(),...e}}catch(n){throw new x(n instanceof Error?n.message:String(n),e,t())}}catch(i){if(b(i)===`ENOENT`){let n=Ft(e);return n&&process.stderr.write(`\nWork Mate configuration file not found at: ${e}\nA backup file exists at: ${n}\nYou can manually restore it by running: cp "${n}" "${e}"\n\n`),t()}if(i instanceof x&&n)throw i;if(i instanceof x){if(S(`Config file corrupted, resetting to defaults: ${i.message}`,{level:`error`}),!H){H=!0;try{Ze(i);try{r.statSync(`${e}.backup`)}catch{}}finally{H=!1}}process.stderr.write(`\nWork Mate configuration file at ${e} is corrupted: ${i.message}\n`);let t=w(e),n=B();try{r.mkdirSync(n)}catch(e){if(b(e)!==`EEXIST`)throw e}let a=r.readdirStringSync(n).filter(e=>e.startsWith(`${t}.corrupted.`)),o,s=!1,c=r.readFileSync(e,{encoding:`utf-8`});for(let e of a)try{if(c===r.readFileSync(E(n,e),{encoding:`utf-8`})){s=!0;break}}catch{}if(!s){o=E(n,`${t}.corrupted.${Date.now()}`);try{r.copyFileSync(e,o),S(`Corrupted config backed up to: ${o}`,{level:`error`})}catch{}}let l=Ft(e);o?process.stderr.write(`The corrupted file has been backed up to: ${o}\n`):s&&process.stderr.write(`The corrupted file has already been backed up.
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{n as t,t as n}from"./isObject-C6qM3WEW.js";import{n as r,t as i}from"./memoize-BK3gG5ob.js";import{c as a,i as o,l as s,o as c}from"./envUtils-QyzA_cFM.js";import{Ai as l,Cn as u,Ei as d,In as ee,Kn as te,Rr as ne,Sn as re,Ti as ie,Xt as ae,Yt as f,bi as oe,bn as p,di as m,ki as se,kr as ce,m as le,mr as h,pr as ue,qr as de,rn as fe,s as g,t as pe,tn as me,ui as he,vn as ge,yi as _e}from"./settings-D4M13toi.js";import{Hr as ve,Jr as ye,Pt as be,Ur as xe,X as _,Xr as Se,Yr as Ce,Zr as we,_r as Te,ai as Ee,ar as De,cr as Oe,dr as ke,ei as Ae,fr as je,gr as Me,ii as Ne,ir as Pe,lr as Fe,pr as v,q as Ie,st as Le,ti as Re,ur as ze}from"./state-CXY-q5gr.js";import{n as Be,t as Ve}from"./cwd-DrEEb4f5.js";import{$ as He,C as y,I as Ue,N as b,O as x,S as We,c as S,et as Ge,f as Ke,i as qe,u as C,x as Je}from"./debug-2pVES-2G.js";import{d as Ye,o as Xe,s as Ze,u as Qe}from"./log-L1kqxa_P.js";import{n as $e}from"./analytics-COpjZpvd.js";import{i as et,n as tt}from"./lockfile-D_9vif6E.js";import{homedir as nt}from"os";import{basename as w,dirname as T,isAbsolute as rt,join as E,normalize as D,resolve as it,sep as at}from"path";import{unwatchFile as ot,watchFile as st}from"fs";import{randomBytes as ct}from"crypto";var O,lt=e((()=>{Ee(),oe(),Ce(),Se(),O=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)Ne(t,ye(e)),e=_e(e);return t}:we}));function ut(e){return Ae(e,d,O)}var dt=e((()=>{Re(),lt(),ie()}));function ft(){let e=process.env.WORKMATE_DISABLE_AUTO_MEMORY;if(s(e))return!1;if(a(e))return!0;if(s(process.env.WORKMATE_SIMPLE)||s(process.env.WORKMATE_REMOTE)&&!process.env.WORKMATE_REMOTE_MEMORY_DIR)return!1;let t=pe();return t.autoMemoryEnabled===void 0||t.autoMemoryEnabled}function pt(){return!1}function mt(){return process.env.WORKMATE_REMOTE_MEMORY_DIR?process.env.WORKMATE_REMOTE_MEMORY_DIR:o()}function ht(e,t){if(!e)return;let n=e;if(t&&(n.startsWith(`~/`)||n.startsWith(`~\\`))){let e=n.slice(2),t=D(e||`.`);if(t===`.`||t===`..`)return;n=E(nt(),e)}let r=D(n).replace(/[/\\]+$/,``);if(!(!rt(r)||r.length<3||/^[A-Za-z]:$/.test(r)||r.startsWith(`\\\\`)||r.startsWith(`//`)||r.includes(`\0`)))return(r+at).normalize(`NFC`)}function gt(){return ht(process.env.WORKMATE_COWORK_MEMORY_PATH_OVERRIDE,!1)}function _t(){return ht(g(`policySettings`)?.autoMemoryDirectory??g(`flagSettings`)?.autoMemoryDirectory??g(`localSettings`)?.autoMemoryDirectory??g(`userSettings`)?.autoMemoryDirectory,!0)}function vt(){return gt()!==void 0}function yt(){return ne(_())??_()}function bt(){return E(k(),Ct)}function xt(e){return D(e).startsWith(k())}var St,Ct,k,A=e((()=>{i(),be(),c(),de(),ue(),le(),St=`memory`,Ct=`MEMORY.md`,k=r(()=>(gt()??_t())||(E(E(mt(),`projects`),ce(yt()),St)+at).normalize(`NFC`),()=>_())}));function j(e,n,r,i){if(!t(e))return e;n=je(n,e);for(var a=-1,o=n.length,s=o-1,c=e;c!=null&&++a<o;){var l=ke(n[a]),u=r;if(l===`__proto__`||l===`constructor`||l===`prototype`)return e;if(a!=s){var d=c[l];u=i?i(d,l,c):void 0,u===void 0&&(u=t(d)?d:xe(n[a+1])?[]:{})}se(c,l,u),c=c[l]}return e}var M=e((()=>{l(),v(),ve(),n(),ze()}));function wt(e,t,n){for(var r=-1,i=t.length,a={};++r<i;){var o=t[r],s=Oe(e,o);n(s,o)&&j(a,je(o,e),s)}return a}var Tt=e((()=>{Fe(),M(),v()}));function N(e,t){if(e==null)return{};var n=Me(ut(e),function(e){return[e]});return t=Pe(t),wt(e,n,function(e,n){return t(e,n[0])})}var Et=e((()=>{Te(),De(),Tt(),dt()}));function P(){return{numStartups:0,installMethod:void 0,autoUpdates:void 0,theme:`dark`,preferredNotifChannel:`auto`,verbose:!1,editorMode:`normal`,autoCompactEnabled:!0,showTurnDuration:!0,hasSeenTasksHint:!1,hasUsedStash:!1,hasUsedBackgroundTask:!1,queuedCommandUpHintCount:0,diffTool:`auto`,env:{},tipsHistory:{},memoryUsageCount:0,promptQueueUseCount:0,btwUseCount:0,todoFeatureEnabled:!0,showExpandedTodos:!1,messageIdleNotifThresholdMs:6e4,fileCheckpointingEnabled:!0,terminalProgressBarEnabled:!0,cachedStatsigGates:{},cachedDynamicConfigs:{},respectGitignore:!0,channel:{enabled:!1,activePlugin:null}}}function Dt(){return G||(G=Ot())}function Ot(){if(Le())return!0;let e=z(),t=$();if(e.projects?.[t]?.hasTrustDialogAccepted)return!0;let n=h(Ve());for(;;){if(e.projects?.[n]?.hasTrustDialogAccepted)return!0;let t=h(it(n,`..`));if(t===n)break;n=t}return!1}function F(e){let t=K.config;return t?t.hasCompletedOnboarding===!0&&e.hasCompletedOnboarding!==!0:!1}function I(e){let t=null;try{Nt(f(),P,n=>{let r=e(n);return r===n?n:(t={...r,projects:At(n.projects)},t)})&&t&&R(t)}catch(n){S(`Failed to save config with lock: ${n}`,{level:`error`});let r=V(f(),P);if(F(r)){S(`saveGlobalConfig fallback: re-read config is missing auth that cache has; refusing to write. See GH #3117.`,{level:`error`});return}let i=e(r);if(i===r)return;t={...i,projects:At(r.projects)},Mt(f(),t,W),R(t)}}function kt(){let e=J+Y;e>0&&J/e,J=0,Y=0}function L(e){if(e.installMethod!==void 0)return e;let t=e,n=`unknown`,r=e.autoUpdates??!0;switch(t.autoUpdaterStatus){case`migrated`:n=`local`;break;case`installed`:n=`native`;break;case`disabled`:r=!1;break;case`enabled`:case`no_permissions`:case`not_configured`:n=`global`;break;case void 0:break}return{...e,installMethod:n,autoUpdates:r}}function At(e){if(!e)return e;let t={},n=!1;for(let[r,i]of Object.entries(e)){let e=i;if(e.history!==void 0){n=!0;let{history:i,...a}=e;t[r]=a}else t[r]=i}return n?t:e}function jt(){if(Z)return;Z=!0;let e=f();st(e,{interval:qt,persistent:!1},t=>{t.mtimeMs<=K.mtime||C().readFile(e,{encoding:`utf-8`}).then(e=>{if(t.mtimeMs<=K.mtime)return;let n=p(u(e));typeof n!=`object`||!n||(K={config:L({...P(),...n}),mtime:t.mtimeMs},q={mtime:t.mtimeMs,size:t.size})}).catch(()=>{})}),Ge(async()=>{ot(e),Z=!1})}function R(e){K={config:e,mtime:Date.now()},q=null}function z(){if(K.config)return J++,K.config;Y++;try{let e=null;try{e=C().statSync(f())}catch{}let t=L(V(f(),P));return K={config:t,mtime:e?.mtimeMs??Date.now()},q=e?{mtime:e.mtimeMs,size:e.size}:null,jt(),t}catch{return L(V(f(),P))}}function Mt(e,t,n){let r=T(e);C().mkdirSync(r),te(e,y(N(t,(e,t)=>y(e)!==y(n[t])),null,2),{encoding:`utf-8`,mode:384}),e===f()&&X++}function Nt(e,t,n){let r=t(),i=T(e),a=C();a.mkdirSync(i);let o;try{let i=`${e}.lock`,s=Date.now();if(o=et(e,{lockfilePath:i,onCompromised:e=>{S(`Config lock compromised: ${e}`,{level:`error`})}}),Date.now()-s>100&&S(`Lock acquisition took longer than expected - another Work Mate instance may be running`),q&&e===f())try{let t=a.statSync(e);(t.mtimeMs!==q.mtime||t.size!==q.size)&&(q.mtime,t.mtimeMs,q.size,t.size)}catch(e){if(b(e)!==`ENOENT`)throw e}let c=V(e,t);if(e===f()&&F(c))return S(`saveConfigWithLock: re-read config is missing auth that cache has; refusing to write to avoid wiping ~/.workmate.json. See GH #3117.`,{level:`error`}),!1;let l=n(c);if(l===c)return!1;let u=N(l,(e,t)=>y(e)!==y(r[t]));try{let t=w(e),n=B();try{a.mkdirSync(n)}catch(e){if(b(e)!==`EEXIST`)throw e}let r=a.readdirStringSync(n).filter(e=>e.startsWith(`${t}.backup.`)).sort().reverse(),i=r[0],o=i?Number(i.split(`.backup.`).pop()):0,s=Number.isNaN(o)||Date.now()-o>=6e4;if(s){let r=E(n,`${t}.backup.${Date.now()}`);a.copyFileSync(e,r)}let c=s?a.readdirStringSync(n).filter(e=>e.startsWith(`${t}.backup.`)).sort().reverse():r;for(let e of c.slice(5))try{a.unlinkSync(E(n,e))}catch{}}catch(e){b(e)!==`ENOENT`&&S(`Failed to backup config: ${e}`,{level:`error`})}return te(e,y(u,null,2),{encoding:`utf-8`,mode:384}),e===f()&&X++,!0}finally{o&&o()}}function Pt(){if(Q)return;let e=Date.now();m(`info`,`enable_configs_started`),Q=!0,V(f(),P,!0),m(`info`,`enable_configs_completed`,{duration_ms:Date.now()-e})}function B(){return E(o(),`backups`)}function Ft(e){let t=C(),n=w(e),r=B();try{let e=t.readdirStringSync(r).filter(e=>e.startsWith(`${n}.backup.`)).sort().at(-1);if(e)return E(r,e)}catch{}let i=T(e);try{let r=t.readdirStringSync(i).filter(e=>e.startsWith(`${n}.backup.`)).sort().at(-1);if(r)return E(i,r);let a=`${e}.backup`;try{return t.statSync(a),a}catch{}}catch{}return null}function V(e,t,n){if(!Q)throw Error(`Config accessed before allowed.`);let r=C();try{let n=r.readFileSync(e,{encoding:`utf-8`});try{let e=We(u(n));return{...t(),...e}}catch(n){throw new x(n instanceof Error?n.message:String(n),e,t())}}catch(i){if(b(i)===`ENOENT`){let n=Ft(e);return n&&process.stderr.write(`\nWork Mate configuration file not found at: ${e}\nA backup file exists at: ${n}\nYou can manually restore it by running: cp "${n}" "${e}"\n\n`),t()}if(i instanceof x&&n)throw i;if(i instanceof x){if(S(`Config file corrupted, resetting to defaults: ${i.message}`,{level:`error`}),!H){H=!0;try{Ze(i);try{r.statSync(`${e}.backup`)}catch{}}finally{H=!1}}process.stderr.write(`\nWork Mate configuration file at ${e} is corrupted: ${i.message}\n`);let t=w(e),n=B();try{r.mkdirSync(n)}catch(e){if(b(e)!==`EEXIST`)throw e}let a=r.readdirStringSync(n).filter(e=>e.startsWith(`${t}.corrupted.`)),o,s=!1,c=r.readFileSync(e,{encoding:`utf-8`});for(let e of a)try{if(c===r.readFileSync(E(n,e),{encoding:`utf-8`})){s=!0;break}}catch{}if(!s){o=E(n,`${t}.corrupted.${Date.now()}`);try{r.copyFileSync(e,o),S(`Corrupted config backed up to: ${o}`,{level:`error`})}catch{}}let l=Ft(e);o?process.stderr.write(`The corrupted file has been backed up to: ${o}\n`):s&&process.stderr.write(`The corrupted file has already been backed up.
2
2
  `),l?process.stderr.write(`A backup file exists at: ${l}\nYou can manually restore it by running: cp "${l}" "${e}"\n\n`):process.stderr.write(`
3
3
  `)}return t()}}function It(){let e=$(),t=z();if(!t.projects)return U;let n=t.projects[e]??U;return typeof n.allowedTools==`string`&&(n.allowedTools=p(n.allowedTools)??[]),n}function Lt(e){let t=$(),n=null;try{Nt(f(),P,r=>{let i=r.projects?.[t]??U,a=e(i);return a===i?r:(n={...r,projects:{...r.projects,[t]:a}},n)})&&n&&R(n)}catch(r){S(`Failed to save config with lock: ${r}`,{level:`error`});let i=V(f(),P);if(F(i)){S(`saveCurrentProjectConfig fallback: re-read config is missing auth that cache has; refusing to write. See GH #3117.`,{level:`error`});return}let a=i.projects?.[t]??U,o=e(a);if(o===a)return;n={...i,projects:{...i.projects,[t]:o}},Mt(f(),n,W),R(n)}}function Rt(){return Vt()!==null}function zt(){return Rt()&&!s(process.env.FORCE_AUTOUPDATE_PLUGINS)}function Bt(e){switch(e.type){case`development`:return`development build`;case`env`:return`${e.envVar} set`;case`config`:return`config`}}function Vt(){if(!s(process.env.ENABLE_AUTOUPDATER))return{type:`config`};if(s(process.env.DISABLE_AUTOUPDATER))return{type:`env`,envVar:`DISABLE_AUTOUPDATER`};let e=Qe();if(e)return{type:`env`,envVar:e};let t=z();return t.autoUpdates===!1&&(t.installMethod!==`native`||t.autoUpdatesProtectedForNative!==!0)?{type:`config`}:null}function Ht(){let e=z();if(e.userID)return e.userID;let t=ct(32).toString(`hex`);return I(e=>({...e,userID:t})),t}function Ut(){if(!z().firstStartTime){let e=new Date().toISOString();I(t=>({...t,firstStartTime:t.firstStartTime??e}))}}function Wt(e){let t=Ie();switch(e){case`User`:return E(o(),`AGENTS.md`);case`Local`:return E(t,`AGENTS.local.md`);case`Project`:return E(t,`AGENTS.md`);case`Managed`:return E(me(),`AGENTS.md`);case`AutoMem`:return bt();default:return E(o(),`AGENTS.md`)}}function Gt(){return E(me(),`.workmate`,`rules`)}function Kt(){return E(o(),`rules`)}var H,U,W,G,K,q,J,Y,X,qt,Z,Q,$,Jt=e((()=>{i(),Et(),be(),A(),$e(),Be(),He(),qe(),he(),ae(),c(),Ue(),ee(),Ke(),de(),ge(),re(),tt(),Xe(),ue(),Ye(),fe(),Je(),H=!1,U={allowedTools:[],mcpContextUris:[],mcpServers:{},enabledMcpjsonServers:[],disabledMcpjsonServers:[],hasTrustDialogAccepted:!1,projectOnboardingSeenCount:0,hasAgentsMdExternalIncludesApproved:!1,hasAgentsMdExternalIncludesWarningShown:!1},W=P(),G=!1,{...W},{...U},K={config:null,mtime:0},q=null,J=0,Y=0,X=0,Ge(async()=>{kt()}),qt=1e3,Z=!1,Q=!1,$=r(()=>{let e=Ie();return h(ne(e)||it(e))})}));export{lt as A,A as C,ut as D,pt as E,dt as O,vt as S,ft as T,j as _,It as a,k as b,Wt as c,Jt as d,Rt as f,zt as g,I as h,Vt as i,O as k,Ht as l,Lt as m,Pt as n,z as o,Ut as p,Bt as r,Gt as s,Dt as t,Kt as u,M as v,xt as w,mt as x,bt as y};
@@ -0,0 +1 @@
1
+ import{d as e,n as t}from"./config-Bio2EjUK.js";e();export{t as enableConfigs};
@@ -0,0 +1 @@
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{t}from"./jsx-runtime-Bb4Xn-E0.js";import{n,t as r}from"./Settings-4TNYpfUs.js";var i,a;e((()=>{n(),i=t(),a=async(e,t)=>(0,i.jsx)(r,{onClose:e,context:t,defaultTab:`Config`})}))();export{a as call};
@@ -1 +1 @@
1
- import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{n as t,t as n}from"./figures-5ThXQEtq.js";import{I as r,P as i,s as a,t as o}from"./src-BX54x08P.js";import{t as s}from"./jsx-runtime-Bb4Xn-E0.js";import{In as c,Nn as l,mn as u,pn as d}from"./settings-D4M13toi.js";import{A_ as f,B_ as p,Ji as m,O_ as h,Rx as g,V_ as _}from"./loadAgentsDir-uuZYOgKn.js";import{_ as v,g as y}from"./startupProfiler-B9Qv2QGH.js";import{At as b,Ot as x,Yt as S,in as C,rn as w,tn as T}from"./prompt-BfXryFt-.js";import{n as E,t as D}from"./staticRender-Bt82RvGc.js";function O(e){let t=[];return k(e,t),A(e,t),M(e,t),ee(e,t),N(e,t),t.sort((e,t)=>e.severity===t.severity?(t.savingsTokens??0)-(e.savingsTokens??0):e.severity===`warning`?-1:1),t}function k(e,t){e.percentage>=L&&t.push({severity:`warning`,title:`Context is ${e.percentage}% full`,detail:e.isAutoCompactEnabled?`Autocompact will trigger soon, which discards older messages. Use /compact now to control what gets kept.`:`Autocompact is disabled. Use /compact to free space, or enable autocompact in /config.`})}function A(e,t){if(e.messageBreakdown)for(let n of e.messageBreakdown.toolCallsByType){let r=n.callTokens+n.resultTokens,i=r/e.rawMaxTokens*100;if(i<P||r<F)continue;let a=j(n.name,r,i);a&&t.push(a)}}function j(e,t,n){let r=y(t);switch(e){case w:return{severity:`warning`,title:`Bash results using ${r} tokens (${n.toFixed(0)}%)`,detail:`Pipe output through head, tail, or grep to reduce result size. Avoid cat on large files — use Read with offset/limit instead.`,savingsTokens:Math.floor(t*.5)};case S:return{severity:`info`,title:`Read results using ${r} tokens (${n.toFixed(0)}%)`,detail:`Use offset and limit parameters to read only the sections you need. Avoid re-reading entire files when you only need a few lines.`,savingsTokens:Math.floor(t*.3)};case x:return{severity:`info`,title:`Grep results using ${r} tokens (${n.toFixed(0)}%)`,detail:`Add more specific patterns or use the glob or type parameter to narrow file types. Consider Glob for file discovery instead of Grep.`,savingsTokens:Math.floor(t*.3)};default:return n>=20?{severity:`info`,title:`${e} using ${r} tokens (${n.toFixed(0)}%)`,detail:`This tool is consuming a significant portion of context.`,savingsTokens:Math.floor(t*.2)}:null}}function M(e,t){if(!e.messageBreakdown)return;let n=e.messageBreakdown.toolCallsByType.find(e=>e.name===S);if(!n)return;let r=n.callTokens+n.resultTokens,i=r/e.rawMaxTokens*100,a=n.resultTokens/e.rawMaxTokens*100;i>=P&&r>=F||a>=I&&n.resultTokens>=F&&t.push({severity:`info`,title:`File reads using ${y(n.resultTokens)} tokens (${a.toFixed(0)}%)`,detail:`If you are re-reading files, consider referencing earlier reads. Use offset/limit for large files.`,savingsTokens:Math.floor(n.resultTokens*.3)})}function ee(e,t){let n=e.memoryFiles.reduce((e,t)=>e+t.tokens,0),r=n/e.rawMaxTokens*100;if(r>=R&&n>=z){let i=[...e.memoryFiles].sort((e,t)=>t.tokens-e.tokens).slice(0,3).map(e=>`${l(e.path)} (${y(e.tokens)})`).join(`, `);t.push({severity:`info`,title:`Memory files using ${y(n)} tokens (${r.toFixed(0)}%)`,detail:`Largest: ${i}. Use /memory to review and prune stale entries.`,savingsTokens:Math.floor(n*.3)})}}function N(e,t){!e.isAutoCompactEnabled&&e.percentage>=50&&e.percentage<L&&t.push({severity:`info`,title:`Autocompact is disabled`,detail:`Without autocompact, you will hit context limits and lose the conversation. Enable it in /config or use /compact manually.`})}var P,F,I,L,R,z,B=e((()=>{C(),T(),b(),c(),v(),P=15,F=1e4,I=5,L=80,R=5,z=5e3}));function V({suggestions:e}){return e.length===0?null:(0,H.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,H.jsx)(i,{bold:!0,children:`Suggestions`}),e.map((e,t)=>(0,H.jsxs)(r,{flexDirection:`column`,marginTop:t===0?0:1,children:[(0,H.jsxs)(r,{children:[(0,H.jsx)(a,{status:e.severity,withSpace:!0}),(0,H.jsx)(i,{bold:!0,children:e.title}),e.savingsTokens?(0,H.jsxs)(i,{dimColor:!0,children:[` `,n.arrowRight,` save ~`,y(e.savingsTokens)]}):null]}),(0,H.jsx)(r,{marginLeft:2,children:(0,H.jsx)(i,{dimColor:!0,children:e.detail})})]},t))]})}var H,U=e((()=>{t(),o(),v(),H=s()}));function W(){return null}function G(e){let t=new Map;for(let n of e){let e=d(n.source),r=t.get(e)||[];r.push(n),t.set(e,r)}for(let[e,n]of t.entries())t.set(e,n.sort((e,t)=>t.tokens-e.tokens));let n=new Map;for(let e of Y){let r=t.get(e);r&&n.set(e,r)}return n}function K({data:e}){let{categories:t,totalTokens:n,rawMaxTokens:a,percentage:o,gridRows:s,model:c,memoryFiles:u,mcpTools:d,deferredBuiltinTools:f=[],agents:p,skills:m,cacheHitRate:h,cacheThreshold:g}=e,_=t.filter(e=>e.tokens>0&&e.name!==`Free space`&&e.name!==J&&!e.isDeferred),v=t.some(e=>e.isDeferred&&e.name.includes(`MCP`)),b=t.find(e=>e.name===J);return(0,q.jsxs)(r,{flexDirection:`column`,paddingLeft:1,children:[(0,q.jsx)(i,{bold:!0,children:`Context Usage`}),(0,q.jsxs)(r,{flexDirection:`row`,gap:2,children:[(0,q.jsx)(r,{flexDirection:`column`,flexShrink:0,children:s.map((e,t)=>(0,q.jsx)(r,{flexDirection:`row`,marginLeft:-1,children:e.map((e,t)=>e.categoryName===`Free space`?(0,q.jsx)(i,{dimColor:!0,children:`⛶ `},t):e.categoryName===J?(0,q.jsx)(i,{color:e.color,children:`⛝ `},t):(0,q.jsx)(i,{color:e.color,children:e.squareFullness>=.7?`⛁ `:`⛀ `},t))},t))}),(0,q.jsxs)(r,{flexDirection:`column`,gap:0,flexShrink:0,children:[(0,q.jsxs)(i,{dimColor:!0,children:[c,` · `,y(n),`/`,y(a),` tokens (`,o,`%)`]}),(0,q.jsx)(W,{}),h!==void 0&&g!==void 0&&(0,q.jsxs)(i,{color:h<g?`warning`:void 0,children:[`Cache hit rate: `,h.toFixed(0),`%`,h<g?` (below ${g}% threshold)`:``]}),(0,q.jsx)(i,{children:` `}),(0,q.jsx)(i,{dimColor:!0,italic:!0,children:`Estimated usage by category`}),_.map((e,t)=>{let n=y(e.tokens),o=e.isDeferred?`N/A`:`${(e.tokens/a*100).toFixed(1)}%`,s=e.name===J,c=e.name,l=e.isDeferred?` `:s?`⛝`:`⛁`;return(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{color:e.color,children:l}),(0,q.jsxs)(i,{children:[` `,c,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[n,` tokens (`,o,`)`]})]},t)}),(t.find(e=>e.name===`Free space`)?.tokens??0)>0&&(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{dimColor:!0,children:`⛶`}),(0,q.jsx)(i,{children:` Free space: `}),(0,q.jsxs)(i,{dimColor:!0,children:[y(t.find(e=>e.name===`Free space`)?.tokens||0),` (`,((t.find(e=>e.name===`Free space`)?.tokens||0)/a*100).toFixed(1),`%)`]})]}),b&&b.tokens>0&&(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{color:b.color,children:`⛝`}),(0,q.jsxs)(i,{dimColor:!0,children:[` `,b.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(b.tokens),` tokens (`,(b.tokens/a*100).toFixed(1),`%)`]})]})]})]}),(0,q.jsxs)(r,{flexDirection:`column`,marginLeft:-1,children:[d.length>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`MCP tools`}),(0,q.jsxs)(i,{dimColor:!0,children:[` · /mcp`,v?` (loaded on-demand)`:``]})]}),d.some(e=>e.isLoaded)&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:`Loaded`}),d.filter(e=>e.isLoaded).map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]}),v&&d.some(e=>!e.isLoaded)&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:`Available`}),d.filter(e=>!e.isLoaded).map((e,t)=>(0,q.jsx)(r,{children:(0,q.jsxs)(i,{dimColor:!0,children:[`└ `,e.name]})},t))]}),!v&&d.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]}),p.length>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`Custom agents`}),(0,q.jsx)(i,{dimColor:!0,children:` · /agents`})]}),Array.from(G(p).entries()).map(([e,t])=>(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:e}),t.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.agentType,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]},e))]}),u.length>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`Memory files`}),(0,q.jsx)(i,{dimColor:!0,children:` · /memory`})]}),u.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,l(e.path),`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]}),m&&m.tokens>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`Skills`}),(0,q.jsx)(i,{dimColor:!0,children:` · /skills`})]}),Array.from(G(m.skillFrontmatter).entries()).map(([e,t])=>(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:e}),t.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]},e))]})]}),(0,q.jsx)(V,{suggestions:O(e)})]})}var q,J,Y,X=e((()=>{o(),B(),c(),v(),u(),U(),q=s(),J=`Autocompact buffer`,Y=[`Project`,`User`,`Managed`,`Plugin`,`Built-in`]}));function Z(e){return g(e)}async function Q(e,t){let{messages:n,getAppState:r,options:{mainLoopModel:i,tools:a}}=t,o=Z(n),{messages:s}=await _(o),c=process.stdout.columns||80,l=r();return e(await E((0,$.jsx)(K,{data:await h(s,i,async()=>l.toolPermissionContext,a,l.agentDefinitions,c,t,void 0,o)}))),null}var $;e((()=>{X(),p(),f(),m(),D(),$=s()}))();export{Q as call};
1
+ import{n as e}from"./rolldown-runtime-DaDcL9Zw.js";import{n as t,t as n}from"./figures-5ThXQEtq.js";import{I as r,P as i,s as a,t as o}from"./src-BX54x08P.js";import{t as s}from"./jsx-runtime-Bb4Xn-E0.js";import{In as c,Nn as l,mn as u,pn as d}from"./settings-D4M13toi.js";import{A_ as f,Bx as p,H_ as m,M_ as h,U_ as g,Xi as _}from"./loadAgentsDir-BfLCckVj.js";import{_ as v,g as y}from"./startupProfiler-B9Qv2QGH.js";import{At as b,Ot as x,Yt as S,in as C,rn as w,tn as T}from"./prompt-DaYH88Oe.js";import{n as E,t as D}from"./staticRender-Bt82RvGc.js";function O(e){let t=[];return k(e,t),A(e,t),M(e,t),ee(e,t),N(e,t),t.sort((e,t)=>e.severity===t.severity?(t.savingsTokens??0)-(e.savingsTokens??0):e.severity===`warning`?-1:1),t}function k(e,t){e.percentage>=L&&t.push({severity:`warning`,title:`Context is ${e.percentage}% full`,detail:e.isAutoCompactEnabled?`Autocompact will trigger soon, which discards older messages. Use /compact now to control what gets kept.`:`Autocompact is disabled. Use /compact to free space, or enable autocompact in /config.`})}function A(e,t){if(e.messageBreakdown)for(let n of e.messageBreakdown.toolCallsByType){let r=n.callTokens+n.resultTokens,i=r/e.rawMaxTokens*100;if(i<P||r<F)continue;let a=j(n.name,r,i);a&&t.push(a)}}function j(e,t,n){let r=y(t);switch(e){case w:return{severity:`warning`,title:`Bash results using ${r} tokens (${n.toFixed(0)}%)`,detail:`Pipe output through head, tail, or grep to reduce result size. Avoid cat on large files — use Read with offset/limit instead.`,savingsTokens:Math.floor(t*.5)};case S:return{severity:`info`,title:`Read results using ${r} tokens (${n.toFixed(0)}%)`,detail:`Use offset and limit parameters to read only the sections you need. Avoid re-reading entire files when you only need a few lines.`,savingsTokens:Math.floor(t*.3)};case x:return{severity:`info`,title:`Grep results using ${r} tokens (${n.toFixed(0)}%)`,detail:`Add more specific patterns or use the glob or type parameter to narrow file types. Consider Glob for file discovery instead of Grep.`,savingsTokens:Math.floor(t*.3)};default:return n>=20?{severity:`info`,title:`${e} using ${r} tokens (${n.toFixed(0)}%)`,detail:`This tool is consuming a significant portion of context.`,savingsTokens:Math.floor(t*.2)}:null}}function M(e,t){if(!e.messageBreakdown)return;let n=e.messageBreakdown.toolCallsByType.find(e=>e.name===S);if(!n)return;let r=n.callTokens+n.resultTokens,i=r/e.rawMaxTokens*100,a=n.resultTokens/e.rawMaxTokens*100;i>=P&&r>=F||a>=I&&n.resultTokens>=F&&t.push({severity:`info`,title:`File reads using ${y(n.resultTokens)} tokens (${a.toFixed(0)}%)`,detail:`If you are re-reading files, consider referencing earlier reads. Use offset/limit for large files.`,savingsTokens:Math.floor(n.resultTokens*.3)})}function ee(e,t){let n=e.memoryFiles.reduce((e,t)=>e+t.tokens,0),r=n/e.rawMaxTokens*100;if(r>=R&&n>=z){let i=[...e.memoryFiles].sort((e,t)=>t.tokens-e.tokens).slice(0,3).map(e=>`${l(e.path)} (${y(e.tokens)})`).join(`, `);t.push({severity:`info`,title:`Memory files using ${y(n)} tokens (${r.toFixed(0)}%)`,detail:`Largest: ${i}. Use /memory to review and prune stale entries.`,savingsTokens:Math.floor(n*.3)})}}function N(e,t){!e.isAutoCompactEnabled&&e.percentage>=50&&e.percentage<L&&t.push({severity:`info`,title:`Autocompact is disabled`,detail:`Without autocompact, you will hit context limits and lose the conversation. Enable it in /config or use /compact manually.`})}var P,F,I,L,R,z,B=e((()=>{C(),T(),b(),c(),v(),P=15,F=1e4,I=5,L=80,R=5,z=5e3}));function V({suggestions:e}){return e.length===0?null:(0,H.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,H.jsx)(i,{bold:!0,children:`Suggestions`}),e.map((e,t)=>(0,H.jsxs)(r,{flexDirection:`column`,marginTop:t===0?0:1,children:[(0,H.jsxs)(r,{children:[(0,H.jsx)(a,{status:e.severity,withSpace:!0}),(0,H.jsx)(i,{bold:!0,children:e.title}),e.savingsTokens?(0,H.jsxs)(i,{dimColor:!0,children:[` `,n.arrowRight,` save ~`,y(e.savingsTokens)]}):null]}),(0,H.jsx)(r,{marginLeft:2,children:(0,H.jsx)(i,{dimColor:!0,children:e.detail})})]},t))]})}var H,U=e((()=>{t(),o(),v(),H=s()}));function W(){return null}function G(e){let t=new Map;for(let n of e){let e=d(n.source),r=t.get(e)||[];r.push(n),t.set(e,r)}for(let[e,n]of t.entries())t.set(e,n.sort((e,t)=>t.tokens-e.tokens));let n=new Map;for(let e of Y){let r=t.get(e);r&&n.set(e,r)}return n}function K({data:e}){let{categories:t,totalTokens:n,rawMaxTokens:a,percentage:o,gridRows:s,model:c,memoryFiles:u,mcpTools:d,deferredBuiltinTools:f=[],agents:p,skills:m,cacheHitRate:h,cacheThreshold:g}=e,_=t.filter(e=>e.tokens>0&&e.name!==`Free space`&&e.name!==J&&!e.isDeferred),v=t.some(e=>e.isDeferred&&e.name.includes(`MCP`)),b=t.find(e=>e.name===J);return(0,q.jsxs)(r,{flexDirection:`column`,paddingLeft:1,children:[(0,q.jsx)(i,{bold:!0,children:`Context Usage`}),(0,q.jsxs)(r,{flexDirection:`row`,gap:2,children:[(0,q.jsx)(r,{flexDirection:`column`,flexShrink:0,children:s.map((e,t)=>(0,q.jsx)(r,{flexDirection:`row`,marginLeft:-1,children:e.map((e,t)=>e.categoryName===`Free space`?(0,q.jsx)(i,{dimColor:!0,children:`⛶ `},t):e.categoryName===J?(0,q.jsx)(i,{color:e.color,children:`⛝ `},t):(0,q.jsx)(i,{color:e.color,children:e.squareFullness>=.7?`⛁ `:`⛀ `},t))},t))}),(0,q.jsxs)(r,{flexDirection:`column`,gap:0,flexShrink:0,children:[(0,q.jsxs)(i,{dimColor:!0,children:[c,` · `,y(n),`/`,y(a),` tokens (`,o,`%)`]}),(0,q.jsx)(W,{}),h!==void 0&&g!==void 0&&(0,q.jsxs)(i,{color:h<g?`warning`:void 0,children:[`Cache hit rate: `,h.toFixed(0),`%`,h<g?` (below ${g}% threshold)`:``]}),(0,q.jsx)(i,{children:` `}),(0,q.jsx)(i,{dimColor:!0,italic:!0,children:`Estimated usage by category`}),_.map((e,t)=>{let n=y(e.tokens),o=e.isDeferred?`N/A`:`${(e.tokens/a*100).toFixed(1)}%`,s=e.name===J,c=e.name,l=e.isDeferred?` `:s?`⛝`:`⛁`;return(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{color:e.color,children:l}),(0,q.jsxs)(i,{children:[` `,c,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[n,` tokens (`,o,`)`]})]},t)}),(t.find(e=>e.name===`Free space`)?.tokens??0)>0&&(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{dimColor:!0,children:`⛶`}),(0,q.jsx)(i,{children:` Free space: `}),(0,q.jsxs)(i,{dimColor:!0,children:[y(t.find(e=>e.name===`Free space`)?.tokens||0),` (`,((t.find(e=>e.name===`Free space`)?.tokens||0)/a*100).toFixed(1),`%)`]})]}),b&&b.tokens>0&&(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{color:b.color,children:`⛝`}),(0,q.jsxs)(i,{dimColor:!0,children:[` `,b.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(b.tokens),` tokens (`,(b.tokens/a*100).toFixed(1),`%)`]})]})]})]}),(0,q.jsxs)(r,{flexDirection:`column`,marginLeft:-1,children:[d.length>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`MCP tools`}),(0,q.jsxs)(i,{dimColor:!0,children:[` · /mcp`,v?` (loaded on-demand)`:``]})]}),d.some(e=>e.isLoaded)&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:`Loaded`}),d.filter(e=>e.isLoaded).map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]}),v&&d.some(e=>!e.isLoaded)&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:`Available`}),d.filter(e=>!e.isLoaded).map((e,t)=>(0,q.jsx)(r,{children:(0,q.jsxs)(i,{dimColor:!0,children:[`└ `,e.name]})},t))]}),!v&&d.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]}),p.length>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`Custom agents`}),(0,q.jsx)(i,{dimColor:!0,children:` · /agents`})]}),Array.from(G(p).entries()).map(([e,t])=>(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:e}),t.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.agentType,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]},e))]}),u.length>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`Memory files`}),(0,q.jsx)(i,{dimColor:!0,children:` · /memory`})]}),u.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,l(e.path),`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]}),m&&m.tokens>0&&(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsxs)(r,{children:[(0,q.jsx)(i,{bold:!0,children:`Skills`}),(0,q.jsx)(i,{dimColor:!0,children:` · /skills`})]}),Array.from(G(m.skillFrontmatter).entries()).map(([e,t])=>(0,q.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,q.jsx)(i,{dimColor:!0,children:e}),t.map((e,t)=>(0,q.jsxs)(r,{children:[(0,q.jsxs)(i,{children:[`└ `,e.name,`: `]}),(0,q.jsxs)(i,{dimColor:!0,children:[y(e.tokens),` tokens`]})]},t))]},e))]})]}),(0,q.jsx)(V,{suggestions:O(e)})]})}var q,J,Y,X=e((()=>{o(),B(),c(),v(),u(),U(),q=s(),J=`Autocompact buffer`,Y=[`Project`,`User`,`Managed`,`Plugin`,`Built-in`]}));function Z(e){return p(e)}async function Q(e,t){let{messages:n,getAppState:r,options:{mainLoopModel:i,tools:a}}=t,o=Z(n),{messages:s}=await g(o),c=process.stdout.columns||80,l=r();return e(await E((0,$.jsx)(K,{data:await f(s,i,async()=>l.toolPermissionContext,a,l.agentDefinitions,c,t,void 0,o)}))),null}var $;e((()=>{X(),m(),h(),_(),D(),$=s()}))();export{Q as call};