@agenthippo-ai/agenthippo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (480) hide show
  1. package/LICENSE +21 -0
  2. package/bin/agenthippo.js +2 -0
  3. package/out/agentpack/github.js +547 -0
  4. package/out/agentpack/index.js +66 -0
  5. package/out/agentpack/install.js +297 -0
  6. package/out/agentpack/manager.js +441 -0
  7. package/out/agentpack/manifest.js +135 -0
  8. package/out/agentpack/paths.js +475 -0
  9. package/out/agentpack/publish.js +248 -0
  10. package/out/agentpack/stores.js +554 -0
  11. package/out/agentpack/types.js +5 -0
  12. package/out/analytics/dashboard/artifactManager.js +439 -0
  13. package/out/analytics/dashboard/fleetDisplayUtils.js +159 -0
  14. package/out/analytics/dashboard/fleetOrchestrator.js +142 -0
  15. package/out/analytics/dashboard/fleetRegistry.js +79 -0
  16. package/out/analytics/dashboard/fleetRowDefaults.js +87 -0
  17. package/out/analytics/dashboard/fleetScriptAdapter.js +146 -0
  18. package/out/analytics/dashboard/fleetStatusUtils.js +30 -0
  19. package/out/analytics/dashboard/fleetTitleUtils.js +68 -0
  20. package/out/analytics/dashboard/fleetTypes.js +29 -0
  21. package/out/analytics/dashboard/index.js +17 -0
  22. package/out/analytics/dashboard/indexingService.js +422 -0
  23. package/out/analytics/dashboard/localFleetAdapter.js +222 -0
  24. package/out/analytics/dashboard/performanceMonitor.js +76 -0
  25. package/out/analytics/dashboard/processManager.js +209 -0
  26. package/out/analytics/dashboard/provider.js +3885 -0
  27. package/out/analytics/dashboard/queryRunner.js +994 -0
  28. package/out/analytics/dashboard/refreshPolicy.js +16 -0
  29. package/out/analytics/dashboard/scheduledFleetFingerprint.js +22 -0
  30. package/out/analytics/dashboard/scheduledFleetStorage.js +241 -0
  31. package/out/analytics/dashboard/scheduledFleetUtils.js +22 -0
  32. package/out/analytics/dashboard/sessionEventFleetStats.js +118 -0
  33. package/out/analytics/dashboard/sessionJsonlFleet.js +204 -0
  34. package/out/analytics/dashboard/teamViewDiscovery.js +106 -0
  35. package/out/analytics/dashboard/viewsConfigMerge.js +221 -0
  36. package/out/analytics/dashboard/webview/analytics-panel.html +155 -0
  37. package/out/analytics/dashboard/webview/codicon.ttf +0 -0
  38. package/out/analytics/dashboard/webview/index.html +78 -0
  39. package/out/analytics/dashboard/webview/panel.js +2295 -0
  40. package/out/analytics/dashboard/webview/runtime-bridge.js +82 -0
  41. package/out/analytics/dashboard/webview/styles.css +1009 -0
  42. package/out/analytics/lifecycle.js +43 -0
  43. package/out/analytics/service.js +1279 -0
  44. package/out/analytics/sessionEvents.js +231 -0
  45. package/out/auth/bootstrapApply.js +72 -0
  46. package/out/auth/brokerClient.js +126 -0
  47. package/out/auth/callbackUri.js +59 -0
  48. package/out/auth/callbackUriParse.js +59 -0
  49. package/out/auth/githubStoreGate.js +70 -0
  50. package/out/auth/loopbackAuthServer.js +165 -0
  51. package/out/auth/pkce.js +9 -0
  52. package/out/auth/provider.js +239 -0
  53. package/out/auth/sessionStore.js +193 -0
  54. package/out/auth/signInFlow.js +182 -0
  55. package/out/auth/types.js +12 -0
  56. package/out/auth-broker/config.js +62 -0
  57. package/out/auth-broker/jwt.js +105 -0
  58. package/out/auth-broker/pkce.js +57 -0
  59. package/out/auth-broker/server.js +539 -0
  60. package/out/auth-broker/store.js +273 -0
  61. package/out/base-prompts/gateway/openclaw-starter.json5 +144 -0
  62. package/out/base-prompts/gateway/slack-socket-mode-minimal.manifest.json +44 -0
  63. package/out/base-prompts/mcp-servers/.mcp.json +13 -0
  64. package/out/base-prompts/mcp-servers/langfuse-analytics/README.md +142 -0
  65. package/out/base-prompts/mcp-servers/langfuse-analytics/mcp.json +13 -0
  66. package/out/base-prompts/mcp-servers/langfuse-analytics/package-lock.json +1192 -0
  67. package/out/base-prompts/mcp-servers/langfuse-analytics/package.json +23 -0
  68. package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/run-with-env.sh +12 -0
  69. package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/sdk-test.js +102 -0
  70. package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/simple-test.js +137 -0
  71. package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/test-client.js +118 -0
  72. package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/test-server.js +209 -0
  73. package/out/base-prompts/mcp-servers/langfuse-analytics/src/client.ts +431 -0
  74. package/out/base-prompts/mcp-servers/langfuse-analytics/src/index.ts +270 -0
  75. package/out/base-prompts/mcp-servers/langfuse-analytics/tsconfig.json +18 -0
  76. package/out/base-prompts/rules/AGENTS.md +204 -0
  77. package/out/base-prompts/skills/agent-browser/SKILL.md +102 -0
  78. package/out/base-prompts/skills/agent-builder/SKILL.md +73 -0
  79. package/out/base-prompts/skills/agent-builder/references/agent-pack.md +63 -0
  80. package/out/base-prompts/skills/agent-builder/references/crewai.md +66 -0
  81. package/out/base-prompts/skills/agent-builder/references/langchain.md +60 -0
  82. package/out/base-prompts/skills/agent-builder/references/raw-sdk.md +73 -0
  83. package/out/base-prompts/skills/agent-engine-creator/SKILL.md +586 -0
  84. package/out/base-prompts/skills/agent-engine-installer/SKILL.md +106 -0
  85. package/out/base-prompts/skills/agent-engine-installer/scripts/install-engine.mjs +259 -0
  86. package/out/base-prompts/skills/agent-engine-installer/scripts/install-engine.ps1 +189 -0
  87. package/out/base-prompts/skills/agenthippo-cli/SKILL.md +69 -0
  88. package/out/base-prompts/skills/agenthippo-cli/scripts/install.sh +63 -0
  89. package/out/base-prompts/skills/agentpack-creator/SKILL.md +375 -0
  90. package/out/base-prompts/skills/agentpack-creator/references/agent-templates.md +261 -0
  91. package/out/base-prompts/skills/agentpack-creator/references/agents-md-guide.md +195 -0
  92. package/out/base-prompts/skills/agentpack-creator/scripts/init_pack.py +391 -0
  93. package/out/base-prompts/skills/agentpack-creator/scripts/init_pack_test.py +294 -0
  94. package/out/base-prompts/skills/agentpack-testbench/SKILL.md +135 -0
  95. package/out/base-prompts/skills/algorithmic-art/LICENSE.txt +202 -0
  96. package/out/base-prompts/skills/algorithmic-art/SKILL.md +405 -0
  97. package/out/base-prompts/skills/algorithmic-art/templates/generator_template.js +223 -0
  98. package/out/base-prompts/skills/algorithmic-art/templates/viewer.html +599 -0
  99. package/out/base-prompts/skills/debug-agent/SKILL.md +83 -0
  100. package/out/base-prompts/skills/desktop-automation/SKILL.md +166 -0
  101. package/out/base-prompts/skills/desktop-automation/references/agenthippo-ui-recipes.md +441 -0
  102. package/out/base-prompts/skills/desktop-automation/scripts/windows-desktop-uia.psm1 +280 -0
  103. package/out/base-prompts/skills/docx/LICENSE.txt +30 -0
  104. package/out/base-prompts/skills/docx/SKILL.md +197 -0
  105. package/out/base-prompts/skills/docx/docx-js.md +350 -0
  106. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  107. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  108. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  109. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  110. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  111. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  112. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  113. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  114. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  115. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  116. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  117. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  118. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  119. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  120. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  121. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  122. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  123. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  124. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  125. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  126. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  127. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  128. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  129. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  130. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  131. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  132. package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  133. package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  134. package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  135. package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  136. package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  137. package/out/base-prompts/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
  138. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  139. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  140. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  141. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  142. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  143. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  144. package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  145. package/out/base-prompts/skills/docx/ooxml/scripts/pack.py +159 -0
  146. package/out/base-prompts/skills/docx/ooxml/scripts/unpack.py +29 -0
  147. package/out/base-prompts/skills/docx/ooxml/scripts/validate.py +69 -0
  148. package/out/base-prompts/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
  149. package/out/base-prompts/skills/docx/ooxml/scripts/validation/base.py +951 -0
  150. package/out/base-prompts/skills/docx/ooxml/scripts/validation/docx.py +274 -0
  151. package/out/base-prompts/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
  152. package/out/base-prompts/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
  153. package/out/base-prompts/skills/docx/ooxml.md +610 -0
  154. package/out/base-prompts/skills/docx/scripts/__init__.py +1 -0
  155. package/out/base-prompts/skills/docx/scripts/document.py +1276 -0
  156. package/out/base-prompts/skills/docx/scripts/templates/comments.xml +3 -0
  157. package/out/base-prompts/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  158. package/out/base-prompts/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  159. package/out/base-prompts/skills/docx/scripts/templates/commentsIds.xml +3 -0
  160. package/out/base-prompts/skills/docx/scripts/templates/people.xml +3 -0
  161. package/out/base-prompts/skills/docx/scripts/utilities.py +374 -0
  162. package/out/base-prompts/skills/gateway-outbound/SKILL.md +136 -0
  163. package/out/base-prompts/skills/mcp-builder/LICENSE.txt +202 -0
  164. package/out/base-prompts/skills/mcp-builder/SKILL.md +328 -0
  165. package/out/base-prompts/skills/mcp-builder/reference/evaluation.md +602 -0
  166. package/out/base-prompts/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
  167. package/out/base-prompts/skills/mcp-builder/reference/node_mcp_server.md +970 -0
  168. package/out/base-prompts/skills/mcp-builder/reference/python_mcp_server.md +719 -0
  169. package/out/base-prompts/skills/mcp-builder/scripts/connections.py +151 -0
  170. package/out/base-prompts/skills/mcp-builder/scripts/evaluation.py +373 -0
  171. package/out/base-prompts/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
  172. package/out/base-prompts/skills/mcp-builder/scripts/requirements.txt +2 -0
  173. package/out/base-prompts/skills/openclaw/SKILL.md +406 -0
  174. package/out/base-prompts/skills/openclaw/scripts/run-smoke.sh +61 -0
  175. package/out/base-prompts/skills/pdf/LICENSE.txt +30 -0
  176. package/out/base-prompts/skills/pdf/SKILL.md +294 -0
  177. package/out/base-prompts/skills/pdf/forms.md +205 -0
  178. package/out/base-prompts/skills/pdf/reference.md +612 -0
  179. package/out/base-prompts/skills/pdf/scripts/check_bounding_boxes.py +70 -0
  180. package/out/base-prompts/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
  181. package/out/base-prompts/skills/pdf/scripts/check_fillable_fields.py +12 -0
  182. package/out/base-prompts/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
  183. package/out/base-prompts/skills/pdf/scripts/create_validation_image.py +41 -0
  184. package/out/base-prompts/skills/pdf/scripts/extract_form_field_info.py +152 -0
  185. package/out/base-prompts/skills/pdf/scripts/fill_fillable_fields.py +114 -0
  186. package/out/base-prompts/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
  187. package/out/base-prompts/skills/pptx/LICENSE.txt +30 -0
  188. package/out/base-prompts/skills/pptx/SKILL.md +484 -0
  189. package/out/base-prompts/skills/pptx/html2pptx.md +625 -0
  190. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  191. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  192. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  193. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  194. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  195. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  196. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  197. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  198. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  199. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  200. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  201. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  202. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  203. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  204. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  205. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  206. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  207. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  208. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  209. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  210. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  211. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  212. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  213. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  214. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  215. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  216. package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  217. package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  218. package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  219. package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  220. package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  221. package/out/base-prompts/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
  222. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  223. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  224. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  225. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  226. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  227. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  228. package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  229. package/out/base-prompts/skills/pptx/ooxml/scripts/pack.py +159 -0
  230. package/out/base-prompts/skills/pptx/ooxml/scripts/unpack.py +29 -0
  231. package/out/base-prompts/skills/pptx/ooxml/scripts/validate.py +69 -0
  232. package/out/base-prompts/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
  233. package/out/base-prompts/skills/pptx/ooxml/scripts/validation/base.py +951 -0
  234. package/out/base-prompts/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
  235. package/out/base-prompts/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
  236. package/out/base-prompts/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
  237. package/out/base-prompts/skills/pptx/ooxml.md +427 -0
  238. package/out/base-prompts/skills/pptx/scripts/html2pptx.js +984 -0
  239. package/out/base-prompts/skills/pptx/scripts/inventory.py +1020 -0
  240. package/out/base-prompts/skills/pptx/scripts/rearrange.py +231 -0
  241. package/out/base-prompts/skills/pptx/scripts/replace.py +385 -0
  242. package/out/base-prompts/skills/pptx/scripts/thumbnail.py +450 -0
  243. package/out/base-prompts/skills/prompt-lab/SKILL.md +149 -0
  244. package/out/base-prompts/skills/prompt-lab/scripts/query-analytics.sh +2551 -0
  245. package/out/base-prompts/skills/skill-creator/LICENSE.txt +202 -0
  246. package/out/base-prompts/skills/skill-creator/SKILL.md +371 -0
  247. package/out/base-prompts/skills/skill-creator/references/output-patterns.md +82 -0
  248. package/out/base-prompts/skills/skill-creator/references/workflows.md +28 -0
  249. package/out/base-prompts/skills/skill-creator/scripts/init_skill.py +303 -0
  250. package/out/base-prompts/skills/skill-creator/scripts/package_skill.py +110 -0
  251. package/out/base-prompts/skills/skill-creator/scripts/quick_validate.py +95 -0
  252. package/out/base-prompts/skills/skill-installer/SKILL.md +251 -0
  253. package/out/base-prompts/skills/skill-installer/references/store-api.md +219 -0
  254. package/out/base-prompts/skills/spotlight-dashboard/SKILL.md +83 -0
  255. package/out/base-prompts/skills/spotlight-insights/SKILL.md +101 -0
  256. package/out/base-prompts/skills/spotlight-optimize/SKILL.md +93 -0
  257. package/out/base-prompts/skills/spotlight-optimize/scripts/query-analytics.sh +2551 -0
  258. package/out/base-prompts/skills/spotlight-query/SKILL.md +314 -0
  259. package/out/base-prompts/skills/spotlight-query/references/otel-schema.md +163 -0
  260. package/out/base-prompts/skills/spotlight-query/scripts/query-analytics.sh +2551 -0
  261. package/out/base-prompts/skills/spotlight-query/scripts/query-analytics.test.sh +744 -0
  262. package/out/base-prompts/skills/spotlight-query/scripts/test-fixtures/analytics/sessions/sess-test-1.jsonl +14 -0
  263. package/out/base-prompts/skills/spotlight-query/scripts/test-fixtures/analytics/traces/.duckdb-index.json +7 -0
  264. package/out/base-prompts/skills/spotlight-query/scripts/test-fixtures/analytics/traces/sample.jsonl +5 -0
  265. package/out/base-prompts/skills/spotlight-report/SKILL.md +86 -0
  266. package/out/base-prompts/skills/spotlight-visualize/SKILL.md +92 -0
  267. package/out/base-prompts/skills/spotlight-visualize/scripts/query-analytics.sh +2551 -0
  268. package/out/base-prompts/skills/xlsx/LICENSE.txt +30 -0
  269. package/out/base-prompts/skills/xlsx/SKILL.md +289 -0
  270. package/out/base-prompts/skills/xlsx/recalc.py +178 -0
  271. package/out/branding.js +23 -0
  272. package/out/cli/commands/anywhere.js +66 -0
  273. package/out/cli/commands/ask.js +243 -0
  274. package/out/cli/commands/auth-broker.js +24 -0
  275. package/out/cli/commands/auth.js +219 -0
  276. package/out/cli/commands/chat.js +354 -0
  277. package/out/cli/commands/deploy.js +223 -0
  278. package/out/cli/commands/gateway.js +160 -0
  279. package/out/cli/commands/pack.js +220 -0
  280. package/out/cli/commands/probe-custom-engine.js +82 -0
  281. package/out/cli/commands/serve.js +583 -0
  282. package/out/cli/commands/store.js +919 -0
  283. package/out/cli/credential-context.js +113 -0
  284. package/out/cli/deploy-init.js +2087 -0
  285. package/out/cli/deps.js +238 -0
  286. package/out/cli/index.js +390 -0
  287. package/out/cli/pack-loader.js +376 -0
  288. package/out/cli/run-custom-engine-runner.js +318 -0
  289. package/out/cli/runtime.js +409 -0
  290. package/out/cli/serve-hardening.js +325 -0
  291. package/out/cli/state-sync.js +135 -0
  292. package/out/cli/utils.js +220 -0
  293. package/out/cli/vscode-shim.js +86 -0
  294. package/out/engines/base.js +159 -0
  295. package/out/engines/claude.js +1215 -0
  296. package/out/engines/codex.js +759 -0
  297. package/out/engines/custom.js +632 -0
  298. package/out/engines/customEngineIpc.js +95 -0
  299. package/out/engines/customEngineRunnerEmbed.js +107 -0
  300. package/out/engines/customRegistry.js +274 -0
  301. package/out/engines/embeddedCustomEngineRunner.generated.js +9 -0
  302. package/out/engines/engineApiKey.js +138 -0
  303. package/out/engines/factory.js +45 -0
  304. package/out/engines/install.js +372 -0
  305. package/out/engines/persistentEngineWorker.js +320 -0
  306. package/out/engines/publish.js +341 -0
  307. package/out/engines/types.js +17 -0
  308. package/out/examples/run-headless-repl.js +291 -0
  309. package/out/examples/run-headless.js +187 -0
  310. package/out/extension.js +4472 -0
  311. package/out/gateway/bridge.js +805 -0
  312. package/out/gateway/cli-agent-id.js +36 -0
  313. package/out/gateway/client.js +303 -0
  314. package/out/gateway/client.test.js +395 -0
  315. package/out/gateway/gateway-scope-errors.js +14 -0
  316. package/out/gateway/gatewayBackup.js +76 -0
  317. package/out/gateway/gatewayRouteIndex.js +371 -0
  318. package/out/gateway/gatewaySessionStore.js +243 -0
  319. package/out/gateway/index.js +31 -0
  320. package/out/gateway/lifecycle.js +3056 -0
  321. package/out/gateway/openclaw-channel-routing.js +317 -0
  322. package/out/gateway/outboundHandles.js +373 -0
  323. package/out/gateway/outboundPaths.js +72 -0
  324. package/out/gateway/outboundSend.js +254 -0
  325. package/out/gateway/protocol.js +48 -0
  326. package/out/gateway/resetMappings.js +52 -0
  327. package/out/gateway/service.js +1244 -0
  328. package/out/gateway/sessionRouting.js +77 -0
  329. package/out/headless/index.js +505 -0
  330. package/out/headless/sync.js +473 -0
  331. package/out/mcp/publish.js +143 -0
  332. package/out/mcp.js +597 -0
  333. package/out/permissions.js +108 -0
  334. package/out/permissions.mapping.yaml +68 -0
  335. package/out/registry/index.js +332 -0
  336. package/out/remote/handleRemoteChat.js +122 -0
  337. package/out/remote/remotePackStatusBar.js +103 -0
  338. package/out/remote/serveClient.js +216 -0
  339. package/out/remoteSkills.js +191 -0
  340. package/out/runtime/index.js +32 -0
  341. package/out/runtime/interfaces/config-provider.js +32 -0
  342. package/out/runtime/interfaces/edit-tracker.js +22 -0
  343. package/out/runtime/interfaces/index.js +29 -0
  344. package/out/runtime/interfaces/logger.js +40 -0
  345. package/out/runtime/interfaces/permission-handler.js +66 -0
  346. package/out/runtime/interfaces/session-store.js +342 -0
  347. package/out/runtime/vscode/index.js +20 -0
  348. package/out/runtime/vscode/vscode-config-provider.js +77 -0
  349. package/out/runtime/vscode/vscode-edit-tracker.js +120 -0
  350. package/out/runtime/vscode/vscode-logger.js +30 -0
  351. package/out/runtime/vscode/vscode-permission-handler.js +72 -0
  352. package/out/runtime/vscode/vscode-session-store.js +22 -0
  353. package/out/scripts/agentide-litellm.ps1 +501 -0
  354. package/out/scripts/agentide-litellm.sh +700 -0
  355. package/out/scripts/agentide_litellm_hooks_v1.py +604 -0
  356. package/out/scripts/analytics/agent-fleet-widget.js +954 -0
  357. package/out/scripts/analytics/agentide-litellm-otel.config.yaml +160 -0
  358. package/out/scripts/analytics/default-seed-scripts.json +12 -0
  359. package/out/scripts/analytics/duckdbLocator.js +29 -0
  360. package/out/scripts/analytics/fleet-local-adapter.js +246 -0
  361. package/out/scripts/analytics/fleet-workflow.sh +263 -0
  362. package/out/scripts/analytics/generate-default-charts.py +685 -0
  363. package/out/scripts/analytics/hotspot-analysis-widget.js +909 -0
  364. package/out/scripts/analytics/index-traces.py +1394 -0
  365. package/out/scripts/analytics/install-analytics.sh +286 -0
  366. package/out/scripts/analytics/live-fleet-4-collector.cjs +315 -0
  367. package/out/scripts/analytics/live-fleet-4-daemon.mjs +134 -0
  368. package/out/scripts/analytics/live-fleet-4-widget.cjs +433 -0
  369. package/out/scripts/analytics/otel-collector.yaml +55 -0
  370. package/out/scripts/analytics/query-analytics.ps1 +396 -0
  371. package/out/scripts/analytics/query-analytics.sh +2551 -0
  372. package/out/scripts/analytics/session-comparison-widget.js +1468 -0
  373. package/out/scripts/analytics/session-timeline-widget.js +2137 -0
  374. package/out/scripts/analytics/setup-analytics.ps1 +432 -0
  375. package/out/scripts/analytics/setup-analytics.sh +854 -0
  376. package/out/scripts/analytics/start-analytics.ps1 +169 -0
  377. package/out/scripts/analytics/start-analytics.sh +323 -0
  378. package/out/scripts/analytics/token-cost-flamegraph-widget.js +954 -0
  379. package/out/scripts/analytics/token-cost-trend-widget.js +1062 -0
  380. package/out/scripts/analytics/workflows-collector.cjs +315 -0
  381. package/out/scripts/analytics/workflows-daemon.mjs +186 -0
  382. package/out/scripts/analytics/workflows-widget.cjs +433 -0
  383. package/out/scripts/analytics/wow-model-widget.js +191 -0
  384. package/out/scripts/gateway/Dockerfile.serve +45 -0
  385. package/out/scripts/gateway/docker-serve.sh +248 -0
  386. package/out/scripts/gateway/setup-gateway-server.ps1 +953 -0
  387. package/out/scripts/gateway/setup-gateway-server.sh +935 -0
  388. package/out/scripts/gateway/setup-gateway.ps1 +1813 -0
  389. package/out/scripts/gateway/setup-gateway.sh +1541 -0
  390. package/out/scripts/setup-cli.ps1 +86 -0
  391. package/out/scripts/setup-cli.sh +117 -0
  392. package/out/scripts/tools-manifest.json +83 -0
  393. package/out/scripts/vendor-tools.mjs +234 -0
  394. package/out/session.js +272 -0
  395. package/out/shared/agentEngines.js +170 -0
  396. package/out/shared/index.js +109 -0
  397. package/out/shared/models.js +235 -0
  398. package/out/shared/providers.js +202 -0
  399. package/out/skills/publish.js +178 -0
  400. package/out/spotlight/install.js +339 -0
  401. package/out/spotlight/publish.js +544 -0
  402. package/out/spotlight/yaml.js +31 -0
  403. package/out/store/github/setup.js +235 -0
  404. package/out/store/github/templates/build-index.ts +339 -0
  405. package/out/store/github/templates/build-index.yml +97 -0
  406. package/out/store/github/templates/package.json +11 -0
  407. package/out/store/index.js +755 -0
  408. package/out/store/oramaIndex.js +884 -0
  409. package/out/store/shared.js +241 -0
  410. package/out/sync.js +1827 -0
  411. package/out/terminalLogger.js +358 -0
  412. package/out/test/agentEnvFile.test.js +97 -0
  413. package/out/test/agentYaml.test.js +373 -0
  414. package/out/test/agentpack.test.js +639 -0
  415. package/out/test/analytics-lifecycle.test.js +174 -0
  416. package/out/test/analytics.test.js +524 -0
  417. package/out/test/auth-bootstrapApply.test.js +102 -0
  418. package/out/test/auth-broker.test.js +434 -0
  419. package/out/test/auth-callback.test.js +62 -0
  420. package/out/test/branding.test.js +229 -0
  421. package/out/test/cli-agent-id.test.js +55 -0
  422. package/out/test/credential-context.test.js +105 -0
  423. package/out/test/customEngineInstall.test.js +100 -0
  424. package/out/test/customRegistry.test.js +122 -0
  425. package/out/test/deploy-init.test.js +532 -0
  426. package/out/test/deps-auto-install.test.js +81 -0
  427. package/out/test/engine-integration.test.js +297 -0
  428. package/out/test/enginePaths.test.js +195 -0
  429. package/out/test/enginePublish.test.js +82 -0
  430. package/out/test/fleetDisplayUtils.test.js +96 -0
  431. package/out/test/gateway-client.test.js +381 -0
  432. package/out/test/gateway-lifecycle.test.js +608 -0
  433. package/out/test/gateway-outbound.test.js +531 -0
  434. package/out/test/gateway-reset-mappings.test.js +221 -0
  435. package/out/test/gateway-route-index.test.js +235 -0
  436. package/out/test/gateway-session-routing.test.js +47 -0
  437. package/out/test/gateway-session-store.test.js +216 -0
  438. package/out/test/github.test.js +232 -0
  439. package/out/test/headless-sync.test.js +279 -0
  440. package/out/test/helpers/manifest-fixtures.js +27 -0
  441. package/out/test/mcp-obo.test.js +82 -0
  442. package/out/test/mcp.test.js +307 -0
  443. package/out/test/openclaw-channel-routing.test.js +191 -0
  444. package/out/test/pathSafety.test.js +63 -0
  445. package/out/test/permissions.test.js +175 -0
  446. package/out/test/persistent-engine-worker.test.js +220 -0
  447. package/out/test/refreshPolicy.test.js +60 -0
  448. package/out/test/registry.test.js +351 -0
  449. package/out/test/runtime.test.js +349 -0
  450. package/out/test/scheduledFleetStorage.test.js +72 -0
  451. package/out/test/serve-hardening.test.js +192 -0
  452. package/out/test/serveClient.test.js +173 -0
  453. package/out/test/sessionJsonlFleet.test.js +78 -0
  454. package/out/test/shared.test.js +173 -0
  455. package/out/test/skills-mcp.test.js +299 -0
  456. package/out/test/spotlightPublish.test.js +299 -0
  457. package/out/test/spotlightYaml.test.js +58 -0
  458. package/out/test/state-sync-peer.test.js +74 -0
  459. package/out/test/store.test.js +331 -0
  460. package/out/test/stores.test.js +504 -0
  461. package/out/test/sync-switch.test.js +251 -0
  462. package/out/test/teamViewDiscovery.test.js +90 -0
  463. package/out/test/toolPath.test.js +120 -0
  464. package/out/test/utils.test.js +308 -0
  465. package/out/test/viewsConfigMerge.test.js +180 -0
  466. package/out/test/windows-command-line.test.js +75 -0
  467. package/out/utils/agentEnvFile.js +131 -0
  468. package/out/utils/binary.js +175 -0
  469. package/out/utils/index.js +37 -0
  470. package/out/utils/network.js +74 -0
  471. package/out/utils/pathSafety.js +60 -0
  472. package/out/utils/paths.js +116 -0
  473. package/out/utils/pid.js +180 -0
  474. package/out/utils/pythonRunner.js +258 -0
  475. package/out/utils/resolveNodeBinary.js +168 -0
  476. package/out/utils/toolPath.js +83 -0
  477. package/out/utils/windowsCommandLine.js +29 -0
  478. package/out/utils.js +915 -0
  479. package/out/workspaceFolders.js +59 -0
  480. package/package.json +41 -0
@@ -0,0 +1,1244 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) AgentHippo.ai. All rights reserved.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.GatewayService = exports.GatewaySessionBindingError = void 0;
40
+ /* eslint-disable local/code-no-unexternalized-strings */
41
+ /**
42
+ * Gateway Service - Manages connection to OpenClaw Gateway in VS Code
43
+ *
44
+ * Key concepts:
45
+ * - Stable agent IDs: ide-{workspace} or ide-{workspace}-{pack}
46
+ * - Session routing: disk-backed route index + per-session gateway-session.json
47
+ * - Publish: user connects an existing IDE session to the gateway
48
+ */
49
+ const os = __importStar(require("os"));
50
+ const path = __importStar(require("path"));
51
+ const vscode = __importStar(require("vscode"));
52
+ const scheduledFleetStorage_js_1 = require("../analytics/dashboard/scheduledFleetStorage.js");
53
+ const bridge_js_1 = require("./bridge.js");
54
+ const gateway_scope_errors_js_1 = require("./gateway-scope-errors.js");
55
+ const gatewayRouteIndex_js_1 = require("./gatewayRouteIndex.js");
56
+ const gatewaySessionStore_js_1 = require("./gatewaySessionStore.js");
57
+ const lifecycle_js_1 = require("./lifecycle.js");
58
+ const openclaw_channel_routing_js_1 = require("./openclaw-channel-routing.js");
59
+ const outboundHandles_js_1 = require("./outboundHandles.js");
60
+ const outboundPaths_js_1 = require("./outboundPaths.js");
61
+ const resetMappings_js_1 = require("./resetMappings.js");
62
+ /** Thrown when a gateway-bound chat cannot be opened without creating a new session (B+E fail-closed). */
63
+ class GatewaySessionBindingError extends Error {
64
+ userMessage;
65
+ constructor(sessionId, detail) {
66
+ const userMessage = `Agent Anywhere cannot open chat session ${sessionId}. ` +
67
+ `Use "Connect Chat to Gateway" on that chat to reconnect.`;
68
+ super(detail ? `${userMessage} ${detail}` : userMessage);
69
+ this.name = "GatewaySessionBindingError";
70
+ this.userMessage = userMessage;
71
+ }
72
+ }
73
+ exports.GatewaySessionBindingError = GatewaySessionBindingError;
74
+ // ============================================================================
75
+ // GatewayService
76
+ // ============================================================================
77
+ class GatewayService {
78
+ extensionContext;
79
+ bridge = null;
80
+ outputChannel;
81
+ config = {};
82
+ disposables = [];
83
+ healthCheckTimer = null;
84
+ static HEALTH_CHECK_INTERVAL = 30000;
85
+ static MAX_SESSIONS = 20;
86
+ /** Runtime cache: AgentHippo sessionId -> active VS Code chat binding. */
87
+ sessionCache = new Map();
88
+ // Gateway emitter correlation (unchanged from before)
89
+ static gatewayEmitters = new Map();
90
+ static getGatewayEmitter(token) {
91
+ const emitter = GatewayService.gatewayEmitters.get(token);
92
+ if (emitter) {
93
+ GatewayService.gatewayEmitters.delete(token);
94
+ }
95
+ return emitter;
96
+ }
97
+ constructor(extensionContext, outputChannel) {
98
+ this.extensionContext = extensionContext;
99
+ this.outputChannel = outputChannel;
100
+ this.registerCommands();
101
+ this.disposables.push(vscode.workspace.onDidChangeConfiguration((e) => {
102
+ if (e.affectsConfiguration("agentide.gateway")) {
103
+ this.loadConfig();
104
+ }
105
+ }));
106
+ this.loadConfig();
107
+ }
108
+ // ============================================================================
109
+ // Config
110
+ // ============================================================================
111
+ loadConfig() {
112
+ const config = vscode.workspace.getConfiguration("agentide.gateway");
113
+ this.config = {
114
+ url: config.get("url"),
115
+ token: config.get("token"),
116
+ autoConnect: config.get("autoConnect", false),
117
+ autoRegister: config.get("autoRegister", true),
118
+ workspaceName: config.get("workspaceName"),
119
+ agents: config.get("agents"),
120
+ };
121
+ if (this.config.autoConnect && this.config.url && !this.isConnected) {
122
+ void this.connect({ silent: true });
123
+ }
124
+ }
125
+ // ============================================================================
126
+ // Stable Agent IDs
127
+ // ============================================================================
128
+ /**
129
+ * Derive workspace name from VS Code workspace folder or setting.
130
+ * E.g., /Users/me/dev/frontend -> "frontend"
131
+ */
132
+ resolveWorkspaceName() {
133
+ const configured = this.config.workspaceName?.trim();
134
+ if (configured) {
135
+ return this.slugify(configured);
136
+ }
137
+ const folder = vscode.workspace.workspaceFolders?.[0];
138
+ if (folder) {
139
+ const folderName = folder.uri.path.split("/").pop() || "workspace";
140
+ return this.slugify(folderName);
141
+ }
142
+ return "workspace";
143
+ }
144
+ /**
145
+ * Build stable agent ID: ide-{workspace} or ide-{workspace}-{pack}
146
+ */
147
+ resolveAgentId(packName) {
148
+ const ws = this.resolveWorkspaceName();
149
+ if (!packName || packName === "default" || packName === "Default") {
150
+ return `ide-${ws}`;
151
+ }
152
+ return `ide-${ws}-${this.slugify(packName)}`;
153
+ }
154
+ slugify(str) {
155
+ return str
156
+ .toLowerCase()
157
+ .replace(/[^a-z0-9-]/g, "-")
158
+ .replace(/-+/g, "-")
159
+ .replace(/^-|-$/g, "")
160
+ .slice(0, 32) || "unnamed";
161
+ }
162
+ // ============================================================================
163
+ // Commands
164
+ // ============================================================================
165
+ registerCommands() {
166
+ this.disposables.push(vscode.commands.registerCommand("agentide.gateway.connect", () => this.connect()), vscode.commands.registerCommand("agentide.gateway.disconnect", () => this.disconnect()), vscode.commands.registerCommand("agentide.gateway.toggle", () => {
167
+ return this.isConnected ? this.disconnect() : this.connect();
168
+ }), vscode.commands.registerCommand("agentide.gateway.status", () => this.showStatus()), vscode.commands.registerCommand("agentide.gateway.connectSession", () => this.publishCurrentSession()), vscode.commands.registerCommand("agentide.gateway.listSessions", () => this.showSessionMap()), vscode.commands.registerCommand("agentide.gateway.resetMappings", () => this.resetMappings()));
169
+ }
170
+ // ============================================================================
171
+ // Reset mappings (forget learned inbound/outbound routing for an agent)
172
+ // ============================================================================
173
+ /**
174
+ * Forget an agent's learned routing so new Slack/Telegram messages start fresh chats. Backs up
175
+ * (never deletes) the route index, default chat, and per-chat outbound stores to `.bk` files.
176
+ * Channel bindings and chat history are kept. Works offline — pure local file operations.
177
+ */
178
+ async resetMappings() {
179
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
180
+ const agentId = await this.resolveResetMappingsAgentId();
181
+ if (!agentId) {
182
+ vscode.window.showWarningMessage("No agent found to reset. Open a chat or register an agent first.");
183
+ return;
184
+ }
185
+ // Cheap pre-check so we don't pop a modal when there is nothing to forget.
186
+ const index = await (0, gatewayRouteIndex_js_1.readGatewayRouteIndex)(workspaceRoot);
187
+ const prefix = `${agentId}::`;
188
+ const routeCount = Object.keys(index.byRoute).filter((k) => k.startsWith(prefix)).length;
189
+ const hasDefault = Boolean(await (0, gatewayRouteIndex_js_1.getDefaultPublishedSessionId)(workspaceRoot, agentId));
190
+ if (routeCount === 0 && !hasDefault) {
191
+ vscode.window.showInformationMessage(`${agentId}: no mappings to reset.`);
192
+ return;
193
+ }
194
+ const confirm = await vscode.window.showWarningMessage(`Reset mappings for "${agentId}"? New messages will start fresh chats. ` +
195
+ `Your channels, chats, and history are kept; old mappings are saved as .bk files.`, { modal: true }, "Reset");
196
+ if (confirm !== "Reset") {
197
+ return;
198
+ }
199
+ try {
200
+ const result = await (0, resetMappings_js_1.resetAgentMappings)(workspaceRoot, agentId);
201
+ // Drop in-memory routes for this agent so the Sessions list reflects reality at once.
202
+ for (const [id, entry] of this.sessionCache) {
203
+ if (entry.agentId === agentId) {
204
+ this.sessionCache.delete(id);
205
+ }
206
+ }
207
+ const parts = [`${result.routes} mapping${result.routes === 1 ? "" : "s"}`];
208
+ if (result.sessions > 0) {
209
+ parts.push(`${result.sessions} chat${result.sessions === 1 ? "" : "s"}`);
210
+ }
211
+ if (result.hadDefault) {
212
+ parts.push("default chat");
213
+ }
214
+ vscode.window.showInformationMessage(`Reset ${parts.join(", ")} for ${agentId}. Originals saved as .bk.`);
215
+ }
216
+ catch (err) {
217
+ this.log(`Reset mappings failed: ${err}`);
218
+ vscode.window.showErrorMessage(`Failed to reset mappings: ${err instanceof Error ? err.message : String(err)}`);
219
+ }
220
+ }
221
+ /**
222
+ * Resolve which agent "Reset mappings" should target: the current chat's agent when a chat is
223
+ * focused, otherwise a pick across registered agents (single registered agent is auto-selected).
224
+ */
225
+ async resolveResetMappingsAgentId() {
226
+ try {
227
+ const chatState = await this.queryChatState();
228
+ if (chatState?.sessionId) {
229
+ return this.resolveAgentId(chatState.activePackId || "default");
230
+ }
231
+ }
232
+ catch {
233
+ // Fall through to the registered-agent picker.
234
+ }
235
+ const agents = this.bridge?.registeredAgents ?? [];
236
+ if (agents.length === 1) {
237
+ return agents[0];
238
+ }
239
+ if (agents.length === 0) {
240
+ return undefined;
241
+ }
242
+ return vscode.window.showQuickPick(agents, {
243
+ title: "Reset mappings for which agent?",
244
+ placeHolder: "Select the agent whose learned routing to forget",
245
+ });
246
+ }
247
+ // ============================================================================
248
+ // Publish (Connect Existing Session to Gateway) - Phase 3
249
+ // ============================================================================
250
+ /**
251
+ * Publish the current VS Code chat session to the gateway.
252
+ * Shows a picker to choose who this session is for:
253
+ * - A specific known peer (e.g., @x via telegram)
254
+ * - Default fallback (web UI and unmatched inbound routes — not every channel/thread)
255
+ */
256
+ async publishCurrentSession(retryAttempt = 0) {
257
+ if (!this.isConnected) {
258
+ // Route through the lifecycle command so it owns the status-bar bookkeeping
259
+ // (setBridgeConnected + setStatus("running")). connectBridge() delegates back to
260
+ // this.connect() via _bridgeRef, so a direct call here would connect the bridge
261
+ // but leave the Agent Anywhere status bar stuck on "Disconnected".
262
+ await vscode.commands.executeCommand("agentide.anywhere.connect");
263
+ }
264
+ if (!this.bridge) {
265
+ vscode.window.showErrorMessage("Not connected to Gateway");
266
+ return;
267
+ }
268
+ try {
269
+ const chatState = await this.queryChatState();
270
+ if (!chatState?.sessionId || !chatState?.sessionResource) {
271
+ vscode.window.showErrorMessage("No active chat session found.");
272
+ return;
273
+ }
274
+ const packName = chatState.activePackId || "default";
275
+ const agentId = this.resolveAgentId(packName);
276
+ const sessionId = chatState.sessionId;
277
+ const sessionResource = vscode.Uri.parse(chatState.sessionResource);
278
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
279
+ await this.ensureAgentRegistered(agentId, packName);
280
+ const peerItems = [
281
+ {
282
+ label: "$(globe) Default for new routes",
283
+ description: "New Slack/Telegram threads use this chat; existing routes unchanged",
284
+ routeKey: undefined,
285
+ },
286
+ ];
287
+ const seenPeers = new Set();
288
+ for (const entry of this.sessionCache.values()) {
289
+ if (entry.agentId === agentId && entry.peerLabel && !seenPeers.has(entry.peerLabel)) {
290
+ seenPeers.add(entry.peerLabel);
291
+ peerItems.push({
292
+ label: `$(person) ${entry.peerLabel}`,
293
+ description: `Bind this chat to ${entry.peerLabel}`,
294
+ routeKey: entry.gatewaySessionKey,
295
+ });
296
+ }
297
+ }
298
+ let selectedRouteKey;
299
+ if (peerItems.length > 1) {
300
+ const picked = await vscode.window.showQuickPick(peerItems, {
301
+ title: "Connect Chat to Gateway",
302
+ placeHolder: "Who should this chat session serve?",
303
+ });
304
+ if (!picked) {
305
+ return;
306
+ }
307
+ selectedRouteKey = picked.routeKey;
308
+ }
309
+ let peerRoute;
310
+ let seedGatewaySessionKey;
311
+ let seedChannel;
312
+ if (selectedRouteKey) {
313
+ const dmMatch = selectedRouteKey.match(/:dm:(.+)$/i);
314
+ const channelMatch = selectedRouteKey.match(/:(channel|thread|group|chat):([^:]+)$/i);
315
+ peerRoute = dmMatch?.[1]
316
+ ? `dm:${dmMatch[1]}`
317
+ : channelMatch
318
+ ? `${channelMatch[1].toLowerCase()}:${channelMatch[2]}`
319
+ : selectedRouteKey;
320
+ seedGatewaySessionKey = selectedRouteKey;
321
+ const cached = [...this.sessionCache.values()].find((e) => e.gatewaySessionKey === selectedRouteKey);
322
+ seedChannel = cached?.channel;
323
+ }
324
+ const sessionTitleTrim = chatState.sessionTitle?.trim();
325
+ const bindLabel = !peerRoute && sessionTitleTrim && sessionTitleTrim.length > 0
326
+ ? (0, gatewaySessionStore_js_1.normalizeInboundBindLabel)(sessionTitleTrim)
327
+ : undefined;
328
+ const publishedMode = peerRoute ? "peer" : "default";
329
+ const existingRecord = await (0, gatewaySessionStore_js_1.readGatewaySessionRecord)(workspaceRoot, sessionId);
330
+ // Guard (a) — double-connect: this chat is already bound to a route/default.
331
+ // Confirm, then clear its prior mappings so we reconnect cleanly (per spec: "clear our
332
+ // connected session and reconnect this session anew").
333
+ if (existingRecord?.published) {
334
+ const prior = this.describePublishedTarget(existingRecord.published);
335
+ const choice = await vscode.window.showWarningMessage(`This chat is already connected to Agent Anywhere (${prior}). Clear that connection and reconnect this chat anew?`, "Clear & Reconnect");
336
+ if (choice !== "Clear & Reconnect") {
337
+ return;
338
+ }
339
+ const removedRoutes = await (0, gatewayRouteIndex_js_1.removeRouteSessionMappingsForSession)(workspaceRoot, agentId, sessionId);
340
+ await (0, gatewayRouteIndex_js_1.clearDefaultPublishedSessionId)(workspaceRoot, agentId, sessionId);
341
+ this.log(`Cleared prior gateway mapping for chat ${sessionId} (routes: ${removedRoutes.join(", ") || "none"})`);
342
+ }
343
+ // Guard (b) — clobber: the route/default we're about to claim is already served by a
344
+ // different chat. Confirm reassignment before stealing it, and remember the previous
345
+ // owner(s) so we can scrub their now-stale binding after the new mapping is written.
346
+ let reassignedDefaultOwner;
347
+ const reassignedRouteOwners = new Map();
348
+ if (publishedMode === "default") {
349
+ const currentDefault = await (0, gatewayRouteIndex_js_1.getDefaultPublishedSessionId)(workspaceRoot, agentId);
350
+ if (currentDefault && currentDefault !== sessionId) {
351
+ if (!(await this.confirmRouteReassignment(workspaceRoot, "Default for new inbound routes", currentDefault))) {
352
+ return;
353
+ }
354
+ reassignedDefaultOwner = currentDefault;
355
+ }
356
+ }
357
+ else {
358
+ const claimKeys = [...new Set([selectedRouteKey, peerRoute].filter((k) => !!k))];
359
+ for (const key of claimKeys) {
360
+ const owner = await (0, gatewayRouteIndex_js_1.getRouteSessionMapping)(workspaceRoot, agentId, key);
361
+ if (owner && owner !== sessionId) {
362
+ if (!(await this.confirmRouteReassignment(workspaceRoot, `Route "${key}"`, owner))) {
363
+ return;
364
+ }
365
+ const keys = reassignedRouteOwners.get(owner) ?? new Set();
366
+ keys.add(key);
367
+ reassignedRouteOwners.set(owner, keys);
368
+ }
369
+ }
370
+ }
371
+ const gatewaySessionKeys = (0, gatewaySessionStore_js_1.mergeGatewaySessionKeyList)(existingRecord?.gatewaySessionKeys ?? [], seedGatewaySessionKey);
372
+ await (0, gatewaySessionStore_js_1.writeGatewaySessionRecord)(workspaceRoot, {
373
+ version: 1,
374
+ sessionId,
375
+ agentId,
376
+ packName,
377
+ vscodeSessionResource: sessionResource.toString(),
378
+ chatMode: chatState.mode,
379
+ published: {
380
+ mode: publishedMode,
381
+ peerRoute,
382
+ bindLabel: bindLabel && bindLabel.length > 0 ? bindLabel : undefined,
383
+ at: new Date().toISOString(),
384
+ },
385
+ gatewaySessionKeys,
386
+ updatedAt: new Date().toISOString(),
387
+ });
388
+ if ((0, gatewaySessionStore_js_1.shouldUpdateAgentDefaultOnGatewayPublish)(publishedMode)) {
389
+ await (0, gatewayRouteIndex_js_1.setDefaultPublishedSessionId)(workspaceRoot, agentId, sessionId);
390
+ }
391
+ if (selectedRouteKey) {
392
+ await (0, gatewayRouteIndex_js_1.setRouteSessionMapping)(workspaceRoot, agentId, selectedRouteKey, sessionId);
393
+ }
394
+ if (peerRoute) {
395
+ await (0, gatewayRouteIndex_js_1.setRouteSessionMapping)(workspaceRoot, agentId, peerRoute, sessionId);
396
+ }
397
+ // New mappings are in place — scrub the reassigned binding from its previous owner so a
398
+ // stale leading sessionKey can't misroute that chat's outbound and its `published` no
399
+ // longer claims a route it lost. Delete the record only if fully orphaned (see § clobber).
400
+ if (reassignedDefaultOwner) {
401
+ const scrubbed = await (0, gatewaySessionStore_js_1.clearGatewaySessionPublishedDefault)(workspaceRoot, reassignedDefaultOwner);
402
+ await this.deleteOrphanedGatewayRecord(workspaceRoot, agentId, reassignedDefaultOwner, scrubbed);
403
+ }
404
+ for (const [owner, keys] of reassignedRouteOwners) {
405
+ const scrubbed = await (0, gatewaySessionStore_js_1.detachGatewaySessionRoutes)(workspaceRoot, owner, [...keys]);
406
+ await this.deleteOrphanedGatewayRecord(workspaceRoot, agentId, owner, scrubbed);
407
+ }
408
+ const entry = {
409
+ gatewaySessionKey: seedGatewaySessionKey ?? `__published__:${agentId}`,
410
+ agentId,
411
+ packName,
412
+ vscodeSessionResource: sessionResource,
413
+ chatSessionId: sessionId,
414
+ chatMode: chatState.mode,
415
+ lastActiveAt: Date.now(),
416
+ channel: seedChannel,
417
+ };
418
+ this.sessionCache.set(sessionId, entry);
419
+ const boundChannels = await this.bindPublishedGatewayChannels(agentId, seedChannel);
420
+ if (seedGatewaySessionKey) {
421
+ this.seedPublishedGatewayOutbound(packName, agentId, sessionId, seedGatewaySessionKey, seedChannel);
422
+ }
423
+ this.updateStatusBar("connected");
424
+ const displayName = bindLabel ?? (sessionTitleTrim && sessionTitleTrim.length > 0 ? sessionTitleTrim : undefined);
425
+ const chatDesc = displayName ? `Chat "${displayName}"` : "New chat";
426
+ const target = peerRoute
427
+ ? `route "${peerRoute}"`
428
+ : "default for new inbound routes";
429
+ this.log(`Published ${chatDesc} (${sessionId}) as ${agentId} for ${target}`);
430
+ const bindHint = bindLabel && bindLabel.length > 0
431
+ ? ` Use hippoclaw agent --session-id "${bindLabel}" to reach this chat.`
432
+ : "";
433
+ const channelHint = boundChannels.length > 0
434
+ ? ` Reachable from: ${boundChannels.join(", ")}.`
435
+ : "";
436
+ vscode.window.showInformationMessage(`${chatDesc} connected to Gateway for ${target}.${channelHint}${bindHint}`);
437
+ }
438
+ catch (err) {
439
+ const message = err instanceof Error ? err.message : String(err);
440
+ // The gateway may require a reconnect if the extension connected with stale auth/scopes.
441
+ const shouldRetry = retryAttempt < 1 &&
442
+ ((0, gateway_scope_errors_js_1.isGatewayScopeAuthError)(message) || message.toLowerCase().includes("connection closed"));
443
+ if (shouldRetry) {
444
+ this.log(`publishCurrentSession failed (${message}); reconnecting and retrying...`);
445
+ try {
446
+ await this.disconnect();
447
+ await this.connect();
448
+ return await this.publishCurrentSession(retryAttempt + 1);
449
+ }
450
+ catch {
451
+ // Fall through to error message
452
+ }
453
+ }
454
+ vscode.window.showErrorMessage(`Failed to publish session: ${message}`);
455
+ }
456
+ }
457
+ // ============================================================================
458
+ // Session Resolution - Phase 2
459
+ // ============================================================================
460
+ /**
461
+ * Build a human-readable label for a peer from their info.
462
+ */
463
+ /** Human-readable description of what a chat's existing publish points at (for the reconnect prompt). */
464
+ describePublishedTarget(published) {
465
+ if (published.mode === "peer" && published.peerRoute) {
466
+ return `route "${published.peerRoute}"`;
467
+ }
468
+ if (published.bindLabel) {
469
+ return `CLI label "${published.bindLabel}"`;
470
+ }
471
+ return "default for new inbound routes";
472
+ }
473
+ /**
474
+ * Confirm reassigning a route/default that another chat currently owns. Returns true to proceed.
475
+ * Dismissing the toast (no choice) cancels — we never silently clobber an existing binding.
476
+ */
477
+ async confirmRouteReassignment(workspaceRoot, targetDesc, ownerSessionId) {
478
+ const ownerRecord = await (0, gatewaySessionStore_js_1.readGatewaySessionRecord)(workspaceRoot, ownerSessionId);
479
+ const ownerLabel = ownerRecord?.published?.bindLabel?.trim() ||
480
+ ownerRecord?.published?.peerRoute?.trim() ||
481
+ ownerSessionId;
482
+ const choice = await vscode.window.showWarningMessage(`${targetDesc} is currently served by another chat ("${ownerLabel}"). Reassign it to this chat? The other chat will stop receiving those messages.`, "Reassign");
483
+ return choice === "Reassign";
484
+ }
485
+ /** Remove a scrubbed owner's binding record once it holds no routes/published and is not the agent default. */
486
+ async deleteOrphanedGatewayRecord(workspaceRoot, agentId, ownerSessionId, scrubbed) {
487
+ if (!scrubbed || !(0, gatewaySessionStore_js_1.isGatewaySessionRecordOrphaned)(scrubbed)) {
488
+ return;
489
+ }
490
+ const currentDefault = await (0, gatewayRouteIndex_js_1.getDefaultPublishedSessionId)(workspaceRoot, agentId);
491
+ if (currentDefault === ownerSessionId) {
492
+ return; // Still the agent default (published cleared but pointer remains) — keep the record.
493
+ }
494
+ await (0, gatewaySessionStore_js_1.deleteGatewaySessionRecord)(workspaceRoot, ownerSessionId);
495
+ this.log(`Removed orphaned gateway record for chat ${ownerSessionId}`);
496
+ }
497
+ buildPeerLabel(peerInfo) {
498
+ if (!peerInfo) {
499
+ return undefined;
500
+ }
501
+ const name = peerInfo.senderUsername || peerInfo.senderName || peerInfo.senderId;
502
+ if (!name) {
503
+ return undefined;
504
+ }
505
+ const channel = peerInfo.channel ? ` via ${peerInfo.channel}` : "";
506
+ return `${name}${channel}`;
507
+ }
508
+ async resolveOrCreateSession(agentId, sessionKey, packName, peerInfo, gatewayWireSessionId) {
509
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
510
+ const routeKey = sessionKey;
511
+ const resolution = await (0, gatewayRouteIndex_js_1.resolveInboundSessionId)({
512
+ workspaceRoot,
513
+ agentId,
514
+ routeKey,
515
+ gatewaySessionKey: sessionKey,
516
+ gatewayWireSessionId,
517
+ });
518
+ // The default published session is a one-shot catch for the first unmatched inbound. Claim it
519
+ // atomically so a burst of messages from *different* channels (e.g. a Slack backlog flushed on
520
+ // reconnect) can't all collapse onto it — only the first winner keeps the default chat and
521
+ // persists its route mapping; the rest fall through to their own per-channel chat below.
522
+ let sessionId = resolution.sessionId;
523
+ if (resolution.source === "defaultPublished") {
524
+ sessionId = await (0, gatewayRouteIndex_js_1.tryClaimDefaultPublishedSessionId)(workspaceRoot, agentId);
525
+ }
526
+ if (resolution.source === "new" || !sessionId) {
527
+ const peerLabel = this.buildPeerLabel(peerInfo);
528
+ this.log(`Creating new VS Code session for peer: ${peerLabel ?? sessionKey ?? "unknown"}, agent=${agentId}`);
529
+ return this.createNewGatewaySession(agentId, sessionKey, packName, peerInfo, resolution.persistRouteKey);
530
+ }
531
+ let entry = this.sessionCache.get(sessionId);
532
+ if (!entry) {
533
+ entry = await this.hydrateSessionEntryFromDisk(workspaceRoot, sessionId, agentId, packName);
534
+ }
535
+ if (!entry) {
536
+ this.log(`Session record missing for ${sessionId}; creating new chat and remapping route`);
537
+ const created = await this.createNewGatewaySession(agentId, sessionKey, packName, peerInfo, resolution.persistRouteKey);
538
+ if (resolution.persistRouteKey) {
539
+ await (0, gatewayRouteIndex_js_1.setRouteSessionMapping)(workspaceRoot, agentId, resolution.persistRouteKey, created.chatSessionId);
540
+ }
541
+ return created;
542
+ }
543
+ entry.lastActiveAt = Date.now();
544
+ entry.gatewaySessionKey = sessionKey ?? entry.gatewaySessionKey;
545
+ const peerLabel = this.buildPeerLabel(peerInfo);
546
+ if (peerLabel && !entry.peerLabel) {
547
+ entry.peerLabel = peerLabel;
548
+ }
549
+ if (peerInfo?.channel) {
550
+ entry.channel = peerInfo.channel;
551
+ }
552
+ await this.ensureChatSessionOpen(entry, workspaceRoot);
553
+ if (resolution.persistRouteKey) {
554
+ await (0, gatewayRouteIndex_js_1.setRouteSessionMapping)(workspaceRoot, agentId, resolution.persistRouteKey, sessionId);
555
+ await (0, gatewaySessionStore_js_1.appendGatewaySessionKey)(workspaceRoot, sessionId, resolution.persistRouteKey);
556
+ }
557
+ this.sessionCache.set(sessionId, entry);
558
+ this.evictStaleSessionCache();
559
+ return entry;
560
+ }
561
+ async hydrateSessionEntryFromDisk(workspaceRoot, sessionId, agentId, packName) {
562
+ const record = await (0, gatewaySessionStore_js_1.readGatewaySessionRecord)(workspaceRoot, sessionId);
563
+ if (!record) {
564
+ return undefined;
565
+ }
566
+ return {
567
+ gatewaySessionKey: record.gatewaySessionKeys[0] ?? `__published__:${agentId}`,
568
+ agentId: record.agentId,
569
+ packName: record.packName || packName,
570
+ vscodeSessionResource: vscode.Uri.parse(record.vscodeSessionResource),
571
+ chatSessionId: record.sessionId,
572
+ chatMode: record.chatMode,
573
+ lastActiveAt: Date.now(),
574
+ };
575
+ }
576
+ /**
577
+ * Open the gateway-bound VS Code chat (B: workbench restore only; E: fail closed, no newChat).
578
+ * Session folder id remains {@link GatewaySessionEntry.chatSessionId}.
579
+ */
580
+ async ensureChatSessionOpen(entry, workspaceRoot) {
581
+ const sessionId = entry.chatSessionId;
582
+ const candidates = [];
583
+ const stored = entry.vscodeSessionResource.toString();
584
+ if (stored) {
585
+ candidates.push(stored);
586
+ }
587
+ const canonical = (0, scheduledFleetStorage_js_1.buildChatSessionResourceFromSessionId)(sessionId);
588
+ if (canonical && !candidates.includes(canonical)) {
589
+ candidates.push(canonical);
590
+ }
591
+ const failures = [];
592
+ for (const sessionResource of candidates) {
593
+ const result = await vscode.commands.executeCommand("agentide.openChatSession", { sessionId, sessionResource });
594
+ if (result?.success) {
595
+ const openedResource = result.sessionResource;
596
+ if (openedResource && openedResource !== stored) {
597
+ entry.vscodeSessionResource = vscode.Uri.parse(openedResource);
598
+ await (0, gatewaySessionStore_js_1.updateGatewaySessionResource)(workspaceRoot, sessionId, openedResource, entry.chatMode);
599
+ }
600
+ return;
601
+ }
602
+ const reason = result && !result.success ? result.reason : "command_unavailable";
603
+ failures.push(`${sessionResource}: ${reason}`);
604
+ }
605
+ this.log(`Gateway could not open chat session ${sessionId} (${failures.join("; ")})`);
606
+ throw new GatewaySessionBindingError(sessionId);
607
+ }
608
+ async createNewGatewaySession(agentId, sessionKey, packName, peerInfo, persistRouteKey) {
609
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
610
+ await vscode.commands.executeCommand("workbench.action.chat.newChat");
611
+ await new Promise((resolve) => setTimeout(resolve, 500));
612
+ const chatState = await this.queryChatState();
613
+ if (!chatState?.sessionId || !chatState?.sessionResource) {
614
+ throw new Error("Failed to create new chat session");
615
+ }
616
+ const sessionId = chatState.sessionId;
617
+ const sessionResource = vscode.Uri.parse(chatState.sessionResource);
618
+ const gatewaySessionKey = sessionKey ?? `__created__:${agentId}:${sessionId}`;
619
+ await (0, gatewaySessionStore_js_1.writeGatewaySessionRecord)(workspaceRoot, {
620
+ version: 1,
621
+ sessionId,
622
+ agentId,
623
+ packName,
624
+ vscodeSessionResource: sessionResource.toString(),
625
+ chatMode: chatState.mode,
626
+ gatewaySessionKeys: gatewaySessionKey ? [gatewaySessionKey] : [],
627
+ updatedAt: new Date().toISOString(),
628
+ });
629
+ if (persistRouteKey) {
630
+ await (0, gatewayRouteIndex_js_1.setRouteSessionMapping)(workspaceRoot, agentId, persistRouteKey, sessionId);
631
+ }
632
+ const entry = {
633
+ gatewaySessionKey,
634
+ agentId,
635
+ packName,
636
+ vscodeSessionResource: sessionResource,
637
+ chatSessionId: sessionId,
638
+ chatMode: chatState.mode,
639
+ peerLabel: this.buildPeerLabel(peerInfo),
640
+ channel: peerInfo?.channel,
641
+ lastActiveAt: Date.now(),
642
+ };
643
+ this.sessionCache.set(sessionId, entry);
644
+ this.evictStaleSessionCache();
645
+ return entry;
646
+ }
647
+ evictStaleSessionCache() {
648
+ while (this.sessionCache.size > GatewayService.MAX_SESSIONS) {
649
+ let oldestId;
650
+ let oldestTime = Infinity;
651
+ for (const [id, entry] of this.sessionCache) {
652
+ if (entry.lastActiveAt < oldestTime) {
653
+ oldestTime = entry.lastActiveAt;
654
+ oldestId = id;
655
+ }
656
+ }
657
+ if (oldestId) {
658
+ this.log(`Evicting stale session cache: ${oldestId}`);
659
+ this.sessionCache.delete(oldestId);
660
+ }
661
+ else {
662
+ break;
663
+ }
664
+ }
665
+ }
666
+ // ============================================================================
667
+ // Chat UI Handler (session-aware)
668
+ // ============================================================================
669
+ resolveGatewayWorkspaceRoot() {
670
+ const folder = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
671
+ if (folder) {
672
+ return folder;
673
+ }
674
+ const dirName = vscode.workspace.getConfiguration("agentide").get("fallbackDirectory") || ".agent-hippo";
675
+ return path.join(os.homedir(), dirName);
676
+ }
677
+ async bindPublishedGatewayChannels(agentId, preferredChannel) {
678
+ if (!this.bridge?.isConnected) {
679
+ return [];
680
+ }
681
+ const request = this.bridge.request.bind(this.bridge);
682
+ const { rows, statusPayload } = await (0, openclaw_channel_routing_js_1.fetchMeetAgentChannelContext)(request);
683
+ const selectedChannels = (0, openclaw_channel_routing_js_1.resolvePublishedGatewayChannelIds)(rows, preferredChannel);
684
+ if (selectedChannels.length === 0) {
685
+ return [];
686
+ }
687
+ const patched = await (0, openclaw_channel_routing_js_1.applyAgentChannelBindingsViaConfigPatch)(request, {
688
+ agentId,
689
+ selectedChannelIds: selectedChannels,
690
+ statusPayload,
691
+ });
692
+ this.log(patched
693
+ ? `Bound ${agentId} to gateway channels: ${selectedChannels.join(", ")}`
694
+ : `${agentId} gateway channel bindings already current: ${selectedChannels.join(", ")}`);
695
+ // A real binding patch can bounce the affected channel; wait for the channels that were live
696
+ // before the patch to come back before we report success, otherwise an inbound message in the
697
+ // restart window is dropped or routed to the gateway's embedded agent (the "publish didn't
698
+ // take the first time, worked on the second click" symptom). Only wait on channels that were
699
+ // actually live pre-patch — a configured-but-offline channel (e.g. stalled Telegram polling)
700
+ // must not block publish. No patch ⇒ nothing restarted ⇒ skip the wait.
701
+ if (patched) {
702
+ const liveBefore = new Set(rows.filter((r) => r.connected).map((r) => r.id.trim().toLowerCase()));
703
+ const awaitable = selectedChannels.filter((id) => liveBefore.has(id.trim().toLowerCase()));
704
+ if (awaitable.length > 0) {
705
+ const settle = await (0, openclaw_channel_routing_js_1.waitForChannelsLive)(request, awaitable);
706
+ this.log(settle.ready
707
+ ? `Gateway channels live after bind: ${settle.live.join(", ")}`
708
+ : `Gateway channels not confirmed live after bind (timed out after ${settle.polls} poll(s)); pending: ${settle.pending.join(", ")}`);
709
+ }
710
+ }
711
+ return selectedChannels;
712
+ }
713
+ persistIdeGatewayOutbound(agentId, gatewayAgentId, sessionEntry, runContext) {
714
+ if (!runContext) {
715
+ return;
716
+ }
717
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
718
+ const chatSessionId = sessionEntry.chatSessionId ||
719
+ (0, scheduledFleetStorage_js_1.parseSessionIdFromChatResource)(sessionEntry.vscodeSessionResource.toString());
720
+ if (!chatSessionId) {
721
+ return;
722
+ }
723
+ const storePath = (0, outboundPaths_js_1.getGatewayOutboundFilePath)(workspaceRoot, chatSessionId);
724
+ void (0, outboundHandles_js_1.upsertGatewayOutboundHandle)(storePath, agentId, runContext.params, runContext.runId, {
725
+ gatewayAgentId,
726
+ })
727
+ .then((handle) => {
728
+ if (handle) {
729
+ this.log(`Gateway outbound routes: ${storePath}`);
730
+ }
731
+ })
732
+ .catch((err) => {
733
+ this.log(`Failed to persist outbound handle: ${err instanceof Error ? err.message : String(err)}`);
734
+ });
735
+ }
736
+ seedPublishedGatewayOutbound(agentId, gatewayAgentId, chatSessionId, gatewaySessionKey, channel) {
737
+ const sourceSessionDirId = (0, outboundPaths_js_1.resolveGatewaySessionDirId)({ gatewaySessionKey });
738
+ if (!sourceSessionDirId) {
739
+ return;
740
+ }
741
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
742
+ const sourceStorePath = (0, outboundPaths_js_1.getGatewayOutboundFilePath)(workspaceRoot, sourceSessionDirId);
743
+ const targetStorePath = (0, outboundPaths_js_1.getGatewayOutboundFilePath)(workspaceRoot, chatSessionId);
744
+ void (0, outboundHandles_js_1.mergeGatewayOutboundHandles)(sourceStorePath, targetStorePath, agentId)
745
+ .then(async (merged) => {
746
+ if (merged > 0) {
747
+ this.log(`Gateway outbound routes: ${targetStorePath} (seeded from ${sourceStorePath})`);
748
+ return;
749
+ }
750
+ const handle = await (0, outboundHandles_js_1.upsertGatewayOutboundHandle)(targetStorePath, agentId, {
751
+ message: "",
752
+ channel,
753
+ sessionKey: gatewaySessionKey,
754
+ idempotencyKey: `publish:${Date.now()}`,
755
+ }, undefined, {
756
+ gatewayAgentId,
757
+ });
758
+ if (handle) {
759
+ this.log(`Gateway outbound routes: ${targetStorePath}`);
760
+ }
761
+ })
762
+ .catch((err) => {
763
+ this.log(`Failed to seed outbound handle: ${err instanceof Error ? err.message : String(err)}`);
764
+ });
765
+ }
766
+ /**
767
+ * Create a session-aware Chat UI handler.
768
+ * Uses sessionKey + peerInfo to resolve the correct VS Code session.
769
+ */
770
+ createSessionAwareChatUIHandler(agentId, packName) {
771
+ return async (message, sessionKey, peerInfo, emitter, runContext) => {
772
+ const gatewayRequestToken = `gw-${Date.now()}-${Math.random().toString(36).slice(2)}`;
773
+ GatewayService.gatewayEmitters.set(gatewayRequestToken, emitter);
774
+ const markedMessage = `[gw:${gatewayRequestToken}]${message}`;
775
+ try {
776
+ const sessionEntry = await this.resolveOrCreateSession(agentId, sessionKey, packName, peerInfo, runContext?.params.sessionId);
777
+ const sessionResource = sessionEntry.vscodeSessionResource;
778
+ this.persistIdeGatewayOutbound(packName, agentId, sessionEntry, runContext);
779
+ const peerLabel = this.buildPeerLabel(peerInfo);
780
+ const sessionInfo = `session=${sessionResource.toString()}, peer=${peerLabel ?? "unknown"}, sessionKey=${sessionKey ?? "none"}`;
781
+ this.log(`Routing gateway message to Chat UI (${sessionInfo}): ${message.slice(0, 50)}...`);
782
+ const commandParams = {
783
+ query: markedMessage,
784
+ blockOnResponse: true,
785
+ sessionResource: sessionResource.toString(),
786
+ };
787
+ commandParams.mode = sessionEntry.chatMode?.trim() || "agent";
788
+ const result = await vscode.commands.executeCommand("workbench.action.chat.open", commandParams);
789
+ if (result?.errorDetails?.message) {
790
+ return `[Error: ${result.errorDetails.message}]`;
791
+ }
792
+ return result?.responseText || "[Chat response completed]";
793
+ }
794
+ catch (err) {
795
+ if (err instanceof GatewaySessionBindingError) {
796
+ this.log(`Gateway session binding lost: ${err.message}`);
797
+ void vscode.window.showWarningMessage(err.userMessage);
798
+ await emitter.error(err.userMessage);
799
+ return `[Error: ${err.userMessage}]`;
800
+ }
801
+ const errorMsg = err instanceof Error ? err.message : String(err);
802
+ this.log(`Chat UI handler error: ${errorMsg}`);
803
+ await emitter.error(errorMsg);
804
+ throw err;
805
+ }
806
+ finally {
807
+ GatewayService.gatewayEmitters.delete(gatewayRequestToken);
808
+ }
809
+ };
810
+ }
811
+ // ============================================================================
812
+ // Agent Registration
813
+ // ============================================================================
814
+ /**
815
+ * Ensure an agent is registered with the gateway.
816
+ * Idempotent: re-registering with the same ID is a no-op.
817
+ */
818
+ async ensureAgentRegistered(agentId, packName, scopeRetryDepth = 0) {
819
+ if (!this.bridge) {
820
+ return;
821
+ }
822
+ // Check if already registered
823
+ if (this.bridge.registeredAgents.includes(agentId)) {
824
+ return;
825
+ }
826
+ const chatUIHandler = this.createSessionAwareChatUIHandler(agentId, packName);
827
+ const agent = {
828
+ id: agentId,
829
+ agentId: packName,
830
+ name: `${packName} (${this.resolveWorkspaceName()})`,
831
+ workspace: this.resolveGatewayWorkspaceRoot(),
832
+ useChatUI: true,
833
+ chatUIHandler,
834
+ };
835
+ try {
836
+ await this.bridge.registerAgent(agent);
837
+ }
838
+ catch (err) {
839
+ const message = err instanceof Error ? err.message : String(err);
840
+ if (scopeRetryDepth >= 1 || !(0, gateway_scope_errors_js_1.isGatewayScopeAuthError)(message)) {
841
+ throw err;
842
+ }
843
+ // Scopes are fixed at WebSocket handshake time. A connection opened before the
844
+ // extension sent operator scopes will keep failing agents.register until we reconnect.
845
+ // Use bridge.reconnect() (not service.disconnect) so the session map stays intact.
846
+ this.log("Gateway denied RPC (missing operator scope); reconnecting with a fresh handshake...");
847
+ await this.bridge.reconnect();
848
+ await this.registerConfiguredAgents();
849
+ await this.ensureAgentRegistered(agentId, packName, scopeRetryDepth + 1);
850
+ return;
851
+ }
852
+ this.log(`Registered agent: ${agentId}`);
853
+ }
854
+ /**
855
+ * Register agents from settings on connect.
856
+ */
857
+ async registerConfiguredAgents() {
858
+ if (!this.bridge) {
859
+ return;
860
+ }
861
+ // Auto-register active pack
862
+ if (this.config.autoRegister) {
863
+ try {
864
+ const chatState = await this.queryChatState();
865
+ const packName = chatState?.activePackId || "default";
866
+ const agentId = this.resolveAgentId(packName);
867
+ await this.ensureAgentRegistered(agentId, packName);
868
+ }
869
+ catch (err) {
870
+ this.log(`Failed to auto-register active pack: ${err}`);
871
+ }
872
+ }
873
+ // Register explicitly configured packs
874
+ if (this.config.agents?.length) {
875
+ for (const agentConfig of this.config.agents) {
876
+ try {
877
+ const agentId = this.resolveAgentId(agentConfig.pack);
878
+ await this.ensureAgentRegistered(agentId, agentConfig.pack);
879
+ }
880
+ catch (err) {
881
+ this.log(`Failed to register pack ${agentConfig.pack}: ${err}`);
882
+ }
883
+ }
884
+ }
885
+ }
886
+ // ============================================================================
887
+ // Session New (from Gateway) - Phase 4
888
+ // ============================================================================
889
+ async handleSessionNewRequest(request) {
890
+ const { requestId, params } = request;
891
+ this.log(`Creating new session from Gateway (requestedBy=${params.requestedBy}, sessionKey=${params.sessionKey})`);
892
+ try {
893
+ await vscode.commands.executeCommand("workbench.action.chat.newChat");
894
+ await new Promise((resolve) => setTimeout(resolve, 500));
895
+ const chatState = await this.queryChatState();
896
+ if (!chatState?.sessionId || !chatState?.sessionResource) {
897
+ this.bridge?.respondSessionNew(requestId, {
898
+ success: false,
899
+ error: "Failed to create chat session",
900
+ });
901
+ return;
902
+ }
903
+ const sessionResource = vscode.Uri.parse(chatState.sessionResource);
904
+ const packName = chatState.activePackId || "default";
905
+ const agentId = this.resolveAgentId(packName);
906
+ // Ensure agent is registered
907
+ await this.ensureAgentRegistered(agentId, packName);
908
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
909
+ const sessionId = chatState.sessionId;
910
+ const newTitleTrim = chatState.sessionTitle?.trim();
911
+ const bindLabel = newTitleTrim && newTitleTrim.length > 0 ? (0, gatewaySessionStore_js_1.normalizeInboundBindLabel)(newTitleTrim) : undefined;
912
+ const existingRecord = await (0, gatewaySessionStore_js_1.readGatewaySessionRecord)(workspaceRoot, sessionId);
913
+ await (0, gatewaySessionStore_js_1.writeGatewaySessionRecord)(workspaceRoot, {
914
+ version: 1,
915
+ sessionId,
916
+ agentId,
917
+ packName,
918
+ vscodeSessionResource: sessionResource.toString(),
919
+ chatMode: chatState.mode,
920
+ published: bindLabel
921
+ ? {
922
+ mode: "default",
923
+ bindLabel,
924
+ at: new Date().toISOString(),
925
+ }
926
+ : undefined,
927
+ gatewaySessionKeys: (0, gatewaySessionStore_js_1.mergeGatewaySessionKeyList)(existingRecord?.gatewaySessionKeys ?? [], params.sessionKey),
928
+ updatedAt: new Date().toISOString(),
929
+ });
930
+ await (0, gatewayRouteIndex_js_1.setDefaultPublishedSessionId)(workspaceRoot, agentId, sessionId);
931
+ if (params.sessionKey) {
932
+ await (0, gatewayRouteIndex_js_1.setRouteSessionMapping)(workspaceRoot, agentId, params.sessionKey, sessionId);
933
+ }
934
+ for (const [id, entry] of this.sessionCache) {
935
+ if (entry.agentId === agentId) {
936
+ this.sessionCache.delete(id);
937
+ }
938
+ }
939
+ this.sessionCache.set(sessionId, {
940
+ gatewaySessionKey: params.sessionKey ?? `__published__:${agentId}`,
941
+ agentId,
942
+ packName,
943
+ vscodeSessionResource: sessionResource,
944
+ chatSessionId: sessionId,
945
+ chatMode: chatState.mode,
946
+ lastActiveAt: Date.now(),
947
+ });
948
+ if (params.sessionKey) {
949
+ this.log(`Route index updated: ${params.sessionKey} -> ${sessionId}`);
950
+ }
951
+ if (params.initialMessage) {
952
+ await vscode.commands.executeCommand("workbench.action.chat.open", {
953
+ mode: "agent",
954
+ query: params.initialMessage,
955
+ sessionResource: chatState.sessionResource,
956
+ });
957
+ }
958
+ vscode.window.showInformationMessage(`New chat session created from ${params.requestedBy ?? "Gateway"}`);
959
+ this.bridge?.respondSessionNew(requestId, {
960
+ success: true,
961
+ agentId,
962
+ });
963
+ }
964
+ catch (err) {
965
+ const errorMsg = err instanceof Error ? err.message : String(err);
966
+ this.log(`Failed to create new session: ${errorMsg}`);
967
+ this.bridge?.respondSessionNew(requestId, {
968
+ success: false,
969
+ error: errorMsg,
970
+ });
971
+ }
972
+ }
973
+ // ============================================================================
974
+ // Connection Lifecycle
975
+ // ============================================================================
976
+ async connect(opts) {
977
+ const silent = opts?.silent ?? false;
978
+ // Read merged settings here — onDidChangeConfiguration can lag behind await
979
+ // `getConfiguration().update()` from connectBridge / reset token, which would
980
+ // otherwise leave `this.config` stale and connect without a token.
981
+ const gwLive = vscode.workspace.getConfiguration("agentide.gateway");
982
+ const url = (gwLive.get("url") ?? "").trim() || (this.config.url ?? "").trim();
983
+ const tokenRaw = (gwLive.get("token") ?? "").trim() || (this.config.token ?? "").trim();
984
+ if (!url) {
985
+ if (!silent) {
986
+ vscode.window.showWarningMessage("Gateway URL not configured. Set agentide.gateway.url in settings.");
987
+ }
988
+ return;
989
+ }
990
+ if (this.isConnected) {
991
+ if (!silent) {
992
+ vscode.window.showInformationMessage("Already connected to Gateway");
993
+ }
994
+ return;
995
+ }
996
+ try {
997
+ this.updateStatusBar("connecting");
998
+ this.log("Connecting to Gateway...");
999
+ const options = {
1000
+ gatewayUrl: url,
1001
+ token: tokenRaw || undefined,
1002
+ version: this.extensionContext.extension.packageJSON.version,
1003
+ outputChannel: this.outputChannel,
1004
+ };
1005
+ this.bridge = new bridge_js_1.GatewayBridge(options);
1006
+ this.bridge.on("connected", () => {
1007
+ this.updateStatusBar("connected");
1008
+ this.log("Connected to Gateway");
1009
+ void this.registerConfiguredAgents();
1010
+ });
1011
+ this.bridge.on("disconnected", () => {
1012
+ const sessionCount = this.sessionCache.size;
1013
+ this.sessionCache.clear();
1014
+ this.updateStatusBar("disconnected");
1015
+ this.log(`Disconnected from Gateway. Cleared ${sessionCount} cached session(s).`);
1016
+ });
1017
+ this.bridge.on("error", (err) => {
1018
+ this.log(`Gateway error: ${err.message}`);
1019
+ });
1020
+ this.bridge.on("reconnecting", (attempt) => {
1021
+ this.updateStatusBar("reconnecting");
1022
+ this.log(`Reconnecting... (attempt ${attempt})`);
1023
+ });
1024
+ this.bridge.on("agent.message", (data) => {
1025
+ const rk = data.routeKey ?? data.sessionKey ?? "";
1026
+ this.log(`Message for ${data.agentId}${rk ? ` (${rk})` : ""}: ${data.message.slice(0, 100)}...`);
1027
+ });
1028
+ this.bridge.on("agent.registered", (_agentId, result) => {
1029
+ if (result?.needsBinding && this.onNeedsBinding) {
1030
+ this.onNeedsBinding(_agentId);
1031
+ }
1032
+ });
1033
+ this.bridge.on("session.new.request", (request) => {
1034
+ void this.handleSessionNewRequest(request);
1035
+ });
1036
+ this.bridge.on("agent.cancel", (params) => {
1037
+ this.log(`Cancelling chat generation (agent.cancel: sessionKey=${params?.sessionKey})`);
1038
+ const sessionKey = params?.sessionKey;
1039
+ const agentId = params?.agentId;
1040
+ if (sessionKey && agentId) {
1041
+ void this.openSessionForGatewayCancel(agentId, sessionKey);
1042
+ return;
1043
+ }
1044
+ void vscode.commands.executeCommand("workbench.action.chat.cancel");
1045
+ });
1046
+ await this.bridge.connect();
1047
+ this.startHealthCheck();
1048
+ }
1049
+ catch (err) {
1050
+ this.updateStatusBar("error");
1051
+ const message = err instanceof Error ? err.message : String(err);
1052
+ this.log(`Failed to connect: ${message}`);
1053
+ if (!silent) {
1054
+ vscode.window.showErrorMessage(`Failed to connect to Gateway: ${message}`);
1055
+ }
1056
+ }
1057
+ }
1058
+ async disconnect() {
1059
+ this.stopHealthCheck();
1060
+ if (!this.bridge) {
1061
+ return;
1062
+ }
1063
+ try {
1064
+ await this.bridge.disconnect();
1065
+ }
1066
+ finally {
1067
+ this.sessionCache.clear();
1068
+ this.bridge = null;
1069
+ this.updateStatusBar("disconnected");
1070
+ }
1071
+ }
1072
+ async openSessionForGatewayCancel(agentId, sessionKey) {
1073
+ const routeKey = (0, bridge_js_1.buildIdeSessionRouteKey)(sessionKey, undefined) ?? sessionKey;
1074
+ const cached = [...this.sessionCache.values()].find((e) => e.gatewaySessionKey === sessionKey);
1075
+ if (cached) {
1076
+ await vscode.commands.executeCommand("workbench.action.chat.open", {
1077
+ sessionResource: cached.vscodeSessionResource.toString(),
1078
+ });
1079
+ await vscode.commands.executeCommand("workbench.action.chat.cancel");
1080
+ return;
1081
+ }
1082
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
1083
+ const sessionId = await (0, gatewayRouteIndex_js_1.resolveInboundSessionId)({
1084
+ workspaceRoot,
1085
+ agentId,
1086
+ routeKey,
1087
+ gatewaySessionKey: sessionKey,
1088
+ }).then((r) => r.sessionId);
1089
+ if (sessionId) {
1090
+ const entry = await this.hydrateSessionEntryFromDisk(workspaceRoot, sessionId, agentId, "default");
1091
+ if (entry) {
1092
+ await vscode.commands.executeCommand("workbench.action.chat.open", {
1093
+ sessionResource: entry.vscodeSessionResource.toString(),
1094
+ });
1095
+ await vscode.commands.executeCommand("workbench.action.chat.cancel");
1096
+ return;
1097
+ }
1098
+ }
1099
+ await vscode.commands.executeCommand("workbench.action.chat.cancel");
1100
+ }
1101
+ // ============================================================================
1102
+ // Health Check
1103
+ // ============================================================================
1104
+ startHealthCheck() {
1105
+ this.stopHealthCheck();
1106
+ this.healthCheckTimer = setInterval(() => {
1107
+ void this.performHealthCheck();
1108
+ }, GatewayService.HEALTH_CHECK_INTERVAL);
1109
+ }
1110
+ stopHealthCheck() {
1111
+ if (this.healthCheckTimer) {
1112
+ clearInterval(this.healthCheckTimer);
1113
+ this.healthCheckTimer = null;
1114
+ }
1115
+ }
1116
+ async performHealthCheck() {
1117
+ if (!this.bridge?.isConnected) {
1118
+ return;
1119
+ }
1120
+ try {
1121
+ await this.bridge.request("agents.list", {});
1122
+ }
1123
+ catch {
1124
+ this.log("Health check failed, reconnecting...");
1125
+ try {
1126
+ await this.bridge.reconnect();
1127
+ }
1128
+ catch (err) {
1129
+ this.log(`Reconnect failed: ${err}`);
1130
+ }
1131
+ }
1132
+ }
1133
+ // ============================================================================
1134
+ // Status UI
1135
+ // ============================================================================
1136
+ showStatus() {
1137
+ const connected = this.isConnected;
1138
+ const agents = this.bridge?.registeredAgents ?? [];
1139
+ const sessionCount = this.sessionCache.size;
1140
+ let message = connected ? "Connected to Gateway" : "Disconnected from Gateway";
1141
+ if (connected && agents.length > 0) {
1142
+ message += `\nAgents: ${agents.join(", ")}`;
1143
+ }
1144
+ if (connected) {
1145
+ message += `\nSessions: ${sessionCount} active (disk-backed routing)`;
1146
+ }
1147
+ if (connected && this.bridge?.connId) {
1148
+ message += `\nConnection: ${this.bridge.connId}`;
1149
+ }
1150
+ vscode.window.showInformationMessage(message);
1151
+ }
1152
+ async showSessionMap() {
1153
+ if (!this.isConnected) {
1154
+ vscode.window.showInformationMessage("Not connected to Gateway");
1155
+ return;
1156
+ }
1157
+ const items = [];
1158
+ const workspaceRoot = this.resolveGatewayWorkspaceRoot();
1159
+ const seenDefaults = new Set();
1160
+ for (const agentId of this.bridge?.registeredAgents ?? []) {
1161
+ const defaultId = await (0, gatewayRouteIndex_js_1.getDefaultPublishedSessionId)(workspaceRoot, agentId);
1162
+ if (defaultId && !seenDefaults.has(defaultId)) {
1163
+ seenDefaults.add(defaultId);
1164
+ const record = await (0, gatewaySessionStore_js_1.readGatewaySessionRecord)(workspaceRoot, defaultId);
1165
+ items.push({
1166
+ label: `$(pin) ${agentId}`,
1167
+ description: "default published session",
1168
+ detail: record?.published?.bindLabel
1169
+ ? `CLI: ${record.published.bindLabel} | ${defaultId}`
1170
+ : defaultId,
1171
+ });
1172
+ }
1173
+ }
1174
+ for (const entry of this.sessionCache.values()) {
1175
+ const peerDisplay = entry.peerLabel ?? entry.gatewaySessionKey;
1176
+ items.push({
1177
+ label: `$(broadcast) ${peerDisplay}`,
1178
+ description: `${entry.agentId}${entry.channel ? ` (${entry.channel})` : ""}`,
1179
+ detail: `Pack: ${entry.packName} | ${entry.chatSessionId} | Active ${this.formatRelativeTime(entry.lastActiveAt)}`,
1180
+ });
1181
+ }
1182
+ if (items.length === 0) {
1183
+ vscode.window.showInformationMessage("No sessions mapped. Use 'Connect Chat to Gateway' to publish the current session.");
1184
+ return;
1185
+ }
1186
+ await vscode.window.showQuickPick(items, {
1187
+ title: `Gateway Sessions (${items.length})`,
1188
+ placeHolder: "Session mappings (published + active routes)",
1189
+ });
1190
+ }
1191
+ // ============================================================================
1192
+ // Helpers
1193
+ // ============================================================================
1194
+ async queryChatState() {
1195
+ return vscode.commands.executeCommand("agentide.getChatState");
1196
+ }
1197
+ formatRelativeTime(timestamp) {
1198
+ const seconds = Math.floor((Date.now() - timestamp) / 1000);
1199
+ if (seconds < 60) {
1200
+ return "just now";
1201
+ }
1202
+ const minutes = Math.floor(seconds / 60);
1203
+ if (minutes < 60) {
1204
+ return `${minutes}m ago`;
1205
+ }
1206
+ const hours = Math.floor(minutes / 60);
1207
+ if (hours < 24) {
1208
+ return `${hours}h ago`;
1209
+ }
1210
+ return `${Math.floor(hours / 24)}d ago`;
1211
+ }
1212
+ /**
1213
+ * Status bar is now owned by GatewayLifecycleManager.
1214
+ * This is a no-op kept for internal call-site compatibility.
1215
+ */
1216
+ updateStatusBar(_status) {
1217
+ // No-op: lifecycle manager owns the single status bar icon
1218
+ }
1219
+ log(message) {
1220
+ this.outputChannel.appendLine(`[${lifecycle_js_1.AGENT_ANYWHERE_LABEL}] ${message}`);
1221
+ }
1222
+ /** Callback invoked when a registered agent has no channel bindings. */
1223
+ onNeedsBinding;
1224
+ get isConnected() {
1225
+ return this.bridge?.isConnected ?? false;
1226
+ }
1227
+ /**
1228
+ * Send a gateway method request via the bridge's WebSocket client.
1229
+ * Exposed via GatewayBridgeRef so the lifecycle manager can call gateway methods.
1230
+ */
1231
+ async request(method, params) {
1232
+ if (!this.bridge?.isConnected) {
1233
+ throw new Error("Not connected to gateway");
1234
+ }
1235
+ return this.bridge.request(method, params);
1236
+ }
1237
+ dispose() {
1238
+ void this.disconnect();
1239
+ for (const d of this.disposables) {
1240
+ d.dispose();
1241
+ }
1242
+ }
1243
+ }
1244
+ exports.GatewayService = GatewayService;