@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.
- package/LICENSE +21 -0
- package/bin/agenthippo.js +2 -0
- package/out/agentpack/github.js +547 -0
- package/out/agentpack/index.js +66 -0
- package/out/agentpack/install.js +297 -0
- package/out/agentpack/manager.js +441 -0
- package/out/agentpack/manifest.js +135 -0
- package/out/agentpack/paths.js +475 -0
- package/out/agentpack/publish.js +248 -0
- package/out/agentpack/stores.js +554 -0
- package/out/agentpack/types.js +5 -0
- package/out/analytics/dashboard/artifactManager.js +439 -0
- package/out/analytics/dashboard/fleetDisplayUtils.js +159 -0
- package/out/analytics/dashboard/fleetOrchestrator.js +142 -0
- package/out/analytics/dashboard/fleetRegistry.js +79 -0
- package/out/analytics/dashboard/fleetRowDefaults.js +87 -0
- package/out/analytics/dashboard/fleetScriptAdapter.js +146 -0
- package/out/analytics/dashboard/fleetStatusUtils.js +30 -0
- package/out/analytics/dashboard/fleetTitleUtils.js +68 -0
- package/out/analytics/dashboard/fleetTypes.js +29 -0
- package/out/analytics/dashboard/index.js +17 -0
- package/out/analytics/dashboard/indexingService.js +422 -0
- package/out/analytics/dashboard/localFleetAdapter.js +222 -0
- package/out/analytics/dashboard/performanceMonitor.js +76 -0
- package/out/analytics/dashboard/processManager.js +209 -0
- package/out/analytics/dashboard/provider.js +3885 -0
- package/out/analytics/dashboard/queryRunner.js +994 -0
- package/out/analytics/dashboard/refreshPolicy.js +16 -0
- package/out/analytics/dashboard/scheduledFleetFingerprint.js +22 -0
- package/out/analytics/dashboard/scheduledFleetStorage.js +241 -0
- package/out/analytics/dashboard/scheduledFleetUtils.js +22 -0
- package/out/analytics/dashboard/sessionEventFleetStats.js +118 -0
- package/out/analytics/dashboard/sessionJsonlFleet.js +204 -0
- package/out/analytics/dashboard/teamViewDiscovery.js +106 -0
- package/out/analytics/dashboard/viewsConfigMerge.js +221 -0
- package/out/analytics/dashboard/webview/analytics-panel.html +155 -0
- package/out/analytics/dashboard/webview/codicon.ttf +0 -0
- package/out/analytics/dashboard/webview/index.html +78 -0
- package/out/analytics/dashboard/webview/panel.js +2295 -0
- package/out/analytics/dashboard/webview/runtime-bridge.js +82 -0
- package/out/analytics/dashboard/webview/styles.css +1009 -0
- package/out/analytics/lifecycle.js +43 -0
- package/out/analytics/service.js +1279 -0
- package/out/analytics/sessionEvents.js +231 -0
- package/out/auth/bootstrapApply.js +72 -0
- package/out/auth/brokerClient.js +126 -0
- package/out/auth/callbackUri.js +59 -0
- package/out/auth/callbackUriParse.js +59 -0
- package/out/auth/githubStoreGate.js +70 -0
- package/out/auth/loopbackAuthServer.js +165 -0
- package/out/auth/pkce.js +9 -0
- package/out/auth/provider.js +239 -0
- package/out/auth/sessionStore.js +193 -0
- package/out/auth/signInFlow.js +182 -0
- package/out/auth/types.js +12 -0
- package/out/auth-broker/config.js +62 -0
- package/out/auth-broker/jwt.js +105 -0
- package/out/auth-broker/pkce.js +57 -0
- package/out/auth-broker/server.js +539 -0
- package/out/auth-broker/store.js +273 -0
- package/out/base-prompts/gateway/openclaw-starter.json5 +144 -0
- package/out/base-prompts/gateway/slack-socket-mode-minimal.manifest.json +44 -0
- package/out/base-prompts/mcp-servers/.mcp.json +13 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/README.md +142 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/mcp.json +13 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/package-lock.json +1192 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/package.json +23 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/run-with-env.sh +12 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/sdk-test.js +102 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/simple-test.js +137 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/test-client.js +118 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/scripts/test-server.js +209 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/src/client.ts +431 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/src/index.ts +270 -0
- package/out/base-prompts/mcp-servers/langfuse-analytics/tsconfig.json +18 -0
- package/out/base-prompts/rules/AGENTS.md +204 -0
- package/out/base-prompts/skills/agent-browser/SKILL.md +102 -0
- package/out/base-prompts/skills/agent-builder/SKILL.md +73 -0
- package/out/base-prompts/skills/agent-builder/references/agent-pack.md +63 -0
- package/out/base-prompts/skills/agent-builder/references/crewai.md +66 -0
- package/out/base-prompts/skills/agent-builder/references/langchain.md +60 -0
- package/out/base-prompts/skills/agent-builder/references/raw-sdk.md +73 -0
- package/out/base-prompts/skills/agent-engine-creator/SKILL.md +586 -0
- package/out/base-prompts/skills/agent-engine-installer/SKILL.md +106 -0
- package/out/base-prompts/skills/agent-engine-installer/scripts/install-engine.mjs +259 -0
- package/out/base-prompts/skills/agent-engine-installer/scripts/install-engine.ps1 +189 -0
- package/out/base-prompts/skills/agenthippo-cli/SKILL.md +69 -0
- package/out/base-prompts/skills/agenthippo-cli/scripts/install.sh +63 -0
- package/out/base-prompts/skills/agentpack-creator/SKILL.md +375 -0
- package/out/base-prompts/skills/agentpack-creator/references/agent-templates.md +261 -0
- package/out/base-prompts/skills/agentpack-creator/references/agents-md-guide.md +195 -0
- package/out/base-prompts/skills/agentpack-creator/scripts/init_pack.py +391 -0
- package/out/base-prompts/skills/agentpack-creator/scripts/init_pack_test.py +294 -0
- package/out/base-prompts/skills/agentpack-testbench/SKILL.md +135 -0
- package/out/base-prompts/skills/algorithmic-art/LICENSE.txt +202 -0
- package/out/base-prompts/skills/algorithmic-art/SKILL.md +405 -0
- package/out/base-prompts/skills/algorithmic-art/templates/generator_template.js +223 -0
- package/out/base-prompts/skills/algorithmic-art/templates/viewer.html +599 -0
- package/out/base-prompts/skills/debug-agent/SKILL.md +83 -0
- package/out/base-prompts/skills/desktop-automation/SKILL.md +166 -0
- package/out/base-prompts/skills/desktop-automation/references/agenthippo-ui-recipes.md +441 -0
- package/out/base-prompts/skills/desktop-automation/scripts/windows-desktop-uia.psm1 +280 -0
- package/out/base-prompts/skills/docx/LICENSE.txt +30 -0
- package/out/base-prompts/skills/docx/SKILL.md +197 -0
- package/out/base-prompts/skills/docx/docx-js.md +350 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/out/base-prompts/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/pack.py +159 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/unpack.py +29 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/validate.py +69 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/validation/base.py +951 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/validation/docx.py +274 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
- package/out/base-prompts/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
- package/out/base-prompts/skills/docx/ooxml.md +610 -0
- package/out/base-prompts/skills/docx/scripts/__init__.py +1 -0
- package/out/base-prompts/skills/docx/scripts/document.py +1276 -0
- package/out/base-prompts/skills/docx/scripts/templates/comments.xml +3 -0
- package/out/base-prompts/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/out/base-prompts/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/out/base-prompts/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/out/base-prompts/skills/docx/scripts/templates/people.xml +3 -0
- package/out/base-prompts/skills/docx/scripts/utilities.py +374 -0
- package/out/base-prompts/skills/gateway-outbound/SKILL.md +136 -0
- package/out/base-prompts/skills/mcp-builder/LICENSE.txt +202 -0
- package/out/base-prompts/skills/mcp-builder/SKILL.md +328 -0
- package/out/base-prompts/skills/mcp-builder/reference/evaluation.md +602 -0
- package/out/base-prompts/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/out/base-prompts/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/out/base-prompts/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/out/base-prompts/skills/mcp-builder/scripts/connections.py +151 -0
- package/out/base-prompts/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/out/base-prompts/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/out/base-prompts/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/out/base-prompts/skills/openclaw/SKILL.md +406 -0
- package/out/base-prompts/skills/openclaw/scripts/run-smoke.sh +61 -0
- package/out/base-prompts/skills/pdf/LICENSE.txt +30 -0
- package/out/base-prompts/skills/pdf/SKILL.md +294 -0
- package/out/base-prompts/skills/pdf/forms.md +205 -0
- package/out/base-prompts/skills/pdf/reference.md +612 -0
- package/out/base-prompts/skills/pdf/scripts/check_bounding_boxes.py +70 -0
- package/out/base-prompts/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
- package/out/base-prompts/skills/pdf/scripts/check_fillable_fields.py +12 -0
- package/out/base-prompts/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
- package/out/base-prompts/skills/pdf/scripts/create_validation_image.py +41 -0
- package/out/base-prompts/skills/pdf/scripts/extract_form_field_info.py +152 -0
- package/out/base-prompts/skills/pdf/scripts/fill_fillable_fields.py +114 -0
- package/out/base-prompts/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
- package/out/base-prompts/skills/pptx/LICENSE.txt +30 -0
- package/out/base-prompts/skills/pptx/SKILL.md +484 -0
- package/out/base-prompts/skills/pptx/html2pptx.md +625 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/out/base-prompts/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/pack.py +159 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/unpack.py +29 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/validate.py +69 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/validation/base.py +951 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
- package/out/base-prompts/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
- package/out/base-prompts/skills/pptx/ooxml.md +427 -0
- package/out/base-prompts/skills/pptx/scripts/html2pptx.js +984 -0
- package/out/base-prompts/skills/pptx/scripts/inventory.py +1020 -0
- package/out/base-prompts/skills/pptx/scripts/rearrange.py +231 -0
- package/out/base-prompts/skills/pptx/scripts/replace.py +385 -0
- package/out/base-prompts/skills/pptx/scripts/thumbnail.py +450 -0
- package/out/base-prompts/skills/prompt-lab/SKILL.md +149 -0
- package/out/base-prompts/skills/prompt-lab/scripts/query-analytics.sh +2551 -0
- package/out/base-prompts/skills/skill-creator/LICENSE.txt +202 -0
- package/out/base-prompts/skills/skill-creator/SKILL.md +371 -0
- package/out/base-prompts/skills/skill-creator/references/output-patterns.md +82 -0
- package/out/base-prompts/skills/skill-creator/references/workflows.md +28 -0
- package/out/base-prompts/skills/skill-creator/scripts/init_skill.py +303 -0
- package/out/base-prompts/skills/skill-creator/scripts/package_skill.py +110 -0
- package/out/base-prompts/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/out/base-prompts/skills/skill-installer/SKILL.md +251 -0
- package/out/base-prompts/skills/skill-installer/references/store-api.md +219 -0
- package/out/base-prompts/skills/spotlight-dashboard/SKILL.md +83 -0
- package/out/base-prompts/skills/spotlight-insights/SKILL.md +101 -0
- package/out/base-prompts/skills/spotlight-optimize/SKILL.md +93 -0
- package/out/base-prompts/skills/spotlight-optimize/scripts/query-analytics.sh +2551 -0
- package/out/base-prompts/skills/spotlight-query/SKILL.md +314 -0
- package/out/base-prompts/skills/spotlight-query/references/otel-schema.md +163 -0
- package/out/base-prompts/skills/spotlight-query/scripts/query-analytics.sh +2551 -0
- package/out/base-prompts/skills/spotlight-query/scripts/query-analytics.test.sh +744 -0
- package/out/base-prompts/skills/spotlight-query/scripts/test-fixtures/analytics/sessions/sess-test-1.jsonl +14 -0
- package/out/base-prompts/skills/spotlight-query/scripts/test-fixtures/analytics/traces/.duckdb-index.json +7 -0
- package/out/base-prompts/skills/spotlight-query/scripts/test-fixtures/analytics/traces/sample.jsonl +5 -0
- package/out/base-prompts/skills/spotlight-report/SKILL.md +86 -0
- package/out/base-prompts/skills/spotlight-visualize/SKILL.md +92 -0
- package/out/base-prompts/skills/spotlight-visualize/scripts/query-analytics.sh +2551 -0
- package/out/base-prompts/skills/xlsx/LICENSE.txt +30 -0
- package/out/base-prompts/skills/xlsx/SKILL.md +289 -0
- package/out/base-prompts/skills/xlsx/recalc.py +178 -0
- package/out/branding.js +23 -0
- package/out/cli/commands/anywhere.js +66 -0
- package/out/cli/commands/ask.js +243 -0
- package/out/cli/commands/auth-broker.js +24 -0
- package/out/cli/commands/auth.js +219 -0
- package/out/cli/commands/chat.js +354 -0
- package/out/cli/commands/deploy.js +223 -0
- package/out/cli/commands/gateway.js +160 -0
- package/out/cli/commands/pack.js +220 -0
- package/out/cli/commands/probe-custom-engine.js +82 -0
- package/out/cli/commands/serve.js +583 -0
- package/out/cli/commands/store.js +919 -0
- package/out/cli/credential-context.js +113 -0
- package/out/cli/deploy-init.js +2087 -0
- package/out/cli/deps.js +238 -0
- package/out/cli/index.js +390 -0
- package/out/cli/pack-loader.js +376 -0
- package/out/cli/run-custom-engine-runner.js +318 -0
- package/out/cli/runtime.js +409 -0
- package/out/cli/serve-hardening.js +325 -0
- package/out/cli/state-sync.js +135 -0
- package/out/cli/utils.js +220 -0
- package/out/cli/vscode-shim.js +86 -0
- package/out/engines/base.js +159 -0
- package/out/engines/claude.js +1215 -0
- package/out/engines/codex.js +759 -0
- package/out/engines/custom.js +632 -0
- package/out/engines/customEngineIpc.js +95 -0
- package/out/engines/customEngineRunnerEmbed.js +107 -0
- package/out/engines/customRegistry.js +274 -0
- package/out/engines/embeddedCustomEngineRunner.generated.js +9 -0
- package/out/engines/engineApiKey.js +138 -0
- package/out/engines/factory.js +45 -0
- package/out/engines/install.js +372 -0
- package/out/engines/persistentEngineWorker.js +320 -0
- package/out/engines/publish.js +341 -0
- package/out/engines/types.js +17 -0
- package/out/examples/run-headless-repl.js +291 -0
- package/out/examples/run-headless.js +187 -0
- package/out/extension.js +4472 -0
- package/out/gateway/bridge.js +805 -0
- package/out/gateway/cli-agent-id.js +36 -0
- package/out/gateway/client.js +303 -0
- package/out/gateway/client.test.js +395 -0
- package/out/gateway/gateway-scope-errors.js +14 -0
- package/out/gateway/gatewayBackup.js +76 -0
- package/out/gateway/gatewayRouteIndex.js +371 -0
- package/out/gateway/gatewaySessionStore.js +243 -0
- package/out/gateway/index.js +31 -0
- package/out/gateway/lifecycle.js +3056 -0
- package/out/gateway/openclaw-channel-routing.js +317 -0
- package/out/gateway/outboundHandles.js +373 -0
- package/out/gateway/outboundPaths.js +72 -0
- package/out/gateway/outboundSend.js +254 -0
- package/out/gateway/protocol.js +48 -0
- package/out/gateway/resetMappings.js +52 -0
- package/out/gateway/service.js +1244 -0
- package/out/gateway/sessionRouting.js +77 -0
- package/out/headless/index.js +505 -0
- package/out/headless/sync.js +473 -0
- package/out/mcp/publish.js +143 -0
- package/out/mcp.js +597 -0
- package/out/permissions.js +108 -0
- package/out/permissions.mapping.yaml +68 -0
- package/out/registry/index.js +332 -0
- package/out/remote/handleRemoteChat.js +122 -0
- package/out/remote/remotePackStatusBar.js +103 -0
- package/out/remote/serveClient.js +216 -0
- package/out/remoteSkills.js +191 -0
- package/out/runtime/index.js +32 -0
- package/out/runtime/interfaces/config-provider.js +32 -0
- package/out/runtime/interfaces/edit-tracker.js +22 -0
- package/out/runtime/interfaces/index.js +29 -0
- package/out/runtime/interfaces/logger.js +40 -0
- package/out/runtime/interfaces/permission-handler.js +66 -0
- package/out/runtime/interfaces/session-store.js +342 -0
- package/out/runtime/vscode/index.js +20 -0
- package/out/runtime/vscode/vscode-config-provider.js +77 -0
- package/out/runtime/vscode/vscode-edit-tracker.js +120 -0
- package/out/runtime/vscode/vscode-logger.js +30 -0
- package/out/runtime/vscode/vscode-permission-handler.js +72 -0
- package/out/runtime/vscode/vscode-session-store.js +22 -0
- package/out/scripts/agentide-litellm.ps1 +501 -0
- package/out/scripts/agentide-litellm.sh +700 -0
- package/out/scripts/agentide_litellm_hooks_v1.py +604 -0
- package/out/scripts/analytics/agent-fleet-widget.js +954 -0
- package/out/scripts/analytics/agentide-litellm-otel.config.yaml +160 -0
- package/out/scripts/analytics/default-seed-scripts.json +12 -0
- package/out/scripts/analytics/duckdbLocator.js +29 -0
- package/out/scripts/analytics/fleet-local-adapter.js +246 -0
- package/out/scripts/analytics/fleet-workflow.sh +263 -0
- package/out/scripts/analytics/generate-default-charts.py +685 -0
- package/out/scripts/analytics/hotspot-analysis-widget.js +909 -0
- package/out/scripts/analytics/index-traces.py +1394 -0
- package/out/scripts/analytics/install-analytics.sh +286 -0
- package/out/scripts/analytics/live-fleet-4-collector.cjs +315 -0
- package/out/scripts/analytics/live-fleet-4-daemon.mjs +134 -0
- package/out/scripts/analytics/live-fleet-4-widget.cjs +433 -0
- package/out/scripts/analytics/otel-collector.yaml +55 -0
- package/out/scripts/analytics/query-analytics.ps1 +396 -0
- package/out/scripts/analytics/query-analytics.sh +2551 -0
- package/out/scripts/analytics/session-comparison-widget.js +1468 -0
- package/out/scripts/analytics/session-timeline-widget.js +2137 -0
- package/out/scripts/analytics/setup-analytics.ps1 +432 -0
- package/out/scripts/analytics/setup-analytics.sh +854 -0
- package/out/scripts/analytics/start-analytics.ps1 +169 -0
- package/out/scripts/analytics/start-analytics.sh +323 -0
- package/out/scripts/analytics/token-cost-flamegraph-widget.js +954 -0
- package/out/scripts/analytics/token-cost-trend-widget.js +1062 -0
- package/out/scripts/analytics/workflows-collector.cjs +315 -0
- package/out/scripts/analytics/workflows-daemon.mjs +186 -0
- package/out/scripts/analytics/workflows-widget.cjs +433 -0
- package/out/scripts/analytics/wow-model-widget.js +191 -0
- package/out/scripts/gateway/Dockerfile.serve +45 -0
- package/out/scripts/gateway/docker-serve.sh +248 -0
- package/out/scripts/gateway/setup-gateway-server.ps1 +953 -0
- package/out/scripts/gateway/setup-gateway-server.sh +935 -0
- package/out/scripts/gateway/setup-gateway.ps1 +1813 -0
- package/out/scripts/gateway/setup-gateway.sh +1541 -0
- package/out/scripts/setup-cli.ps1 +86 -0
- package/out/scripts/setup-cli.sh +117 -0
- package/out/scripts/tools-manifest.json +83 -0
- package/out/scripts/vendor-tools.mjs +234 -0
- package/out/session.js +272 -0
- package/out/shared/agentEngines.js +170 -0
- package/out/shared/index.js +109 -0
- package/out/shared/models.js +235 -0
- package/out/shared/providers.js +202 -0
- package/out/skills/publish.js +178 -0
- package/out/spotlight/install.js +339 -0
- package/out/spotlight/publish.js +544 -0
- package/out/spotlight/yaml.js +31 -0
- package/out/store/github/setup.js +235 -0
- package/out/store/github/templates/build-index.ts +339 -0
- package/out/store/github/templates/build-index.yml +97 -0
- package/out/store/github/templates/package.json +11 -0
- package/out/store/index.js +755 -0
- package/out/store/oramaIndex.js +884 -0
- package/out/store/shared.js +241 -0
- package/out/sync.js +1827 -0
- package/out/terminalLogger.js +358 -0
- package/out/test/agentEnvFile.test.js +97 -0
- package/out/test/agentYaml.test.js +373 -0
- package/out/test/agentpack.test.js +639 -0
- package/out/test/analytics-lifecycle.test.js +174 -0
- package/out/test/analytics.test.js +524 -0
- package/out/test/auth-bootstrapApply.test.js +102 -0
- package/out/test/auth-broker.test.js +434 -0
- package/out/test/auth-callback.test.js +62 -0
- package/out/test/branding.test.js +229 -0
- package/out/test/cli-agent-id.test.js +55 -0
- package/out/test/credential-context.test.js +105 -0
- package/out/test/customEngineInstall.test.js +100 -0
- package/out/test/customRegistry.test.js +122 -0
- package/out/test/deploy-init.test.js +532 -0
- package/out/test/deps-auto-install.test.js +81 -0
- package/out/test/engine-integration.test.js +297 -0
- package/out/test/enginePaths.test.js +195 -0
- package/out/test/enginePublish.test.js +82 -0
- package/out/test/fleetDisplayUtils.test.js +96 -0
- package/out/test/gateway-client.test.js +381 -0
- package/out/test/gateway-lifecycle.test.js +608 -0
- package/out/test/gateway-outbound.test.js +531 -0
- package/out/test/gateway-reset-mappings.test.js +221 -0
- package/out/test/gateway-route-index.test.js +235 -0
- package/out/test/gateway-session-routing.test.js +47 -0
- package/out/test/gateway-session-store.test.js +216 -0
- package/out/test/github.test.js +232 -0
- package/out/test/headless-sync.test.js +279 -0
- package/out/test/helpers/manifest-fixtures.js +27 -0
- package/out/test/mcp-obo.test.js +82 -0
- package/out/test/mcp.test.js +307 -0
- package/out/test/openclaw-channel-routing.test.js +191 -0
- package/out/test/pathSafety.test.js +63 -0
- package/out/test/permissions.test.js +175 -0
- package/out/test/persistent-engine-worker.test.js +220 -0
- package/out/test/refreshPolicy.test.js +60 -0
- package/out/test/registry.test.js +351 -0
- package/out/test/runtime.test.js +349 -0
- package/out/test/scheduledFleetStorage.test.js +72 -0
- package/out/test/serve-hardening.test.js +192 -0
- package/out/test/serveClient.test.js +173 -0
- package/out/test/sessionJsonlFleet.test.js +78 -0
- package/out/test/shared.test.js +173 -0
- package/out/test/skills-mcp.test.js +299 -0
- package/out/test/spotlightPublish.test.js +299 -0
- package/out/test/spotlightYaml.test.js +58 -0
- package/out/test/state-sync-peer.test.js +74 -0
- package/out/test/store.test.js +331 -0
- package/out/test/stores.test.js +504 -0
- package/out/test/sync-switch.test.js +251 -0
- package/out/test/teamViewDiscovery.test.js +90 -0
- package/out/test/toolPath.test.js +120 -0
- package/out/test/utils.test.js +308 -0
- package/out/test/viewsConfigMerge.test.js +180 -0
- package/out/test/windows-command-line.test.js +75 -0
- package/out/utils/agentEnvFile.js +131 -0
- package/out/utils/binary.js +175 -0
- package/out/utils/index.js +37 -0
- package/out/utils/network.js +74 -0
- package/out/utils/pathSafety.js +60 -0
- package/out/utils/paths.js +116 -0
- package/out/utils/pid.js +180 -0
- package/out/utils/pythonRunner.js +258 -0
- package/out/utils/resolveNodeBinary.js +168 -0
- package/out/utils/toolPath.js +83 -0
- package/out/utils/windowsCommandLine.js +29 -0
- package/out/utils.js +915 -0
- package/out/workspaceFolders.js +59 -0
- package/package.json +41 -0
package/out/extension.js
ADDED
|
@@ -0,0 +1,4472 @@
|
|
|
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.activate = activate;
|
|
40
|
+
exports.deactivate = deactivate;
|
|
41
|
+
/* eslint-disable local/code-no-unexternalized-strings */
|
|
42
|
+
const vscode = __importStar(require("vscode"));
|
|
43
|
+
const fs_1 = require("fs");
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const os = __importStar(require("os"));
|
|
46
|
+
const types_1 = require("./engines/types");
|
|
47
|
+
const factory_1 = require("./engines/factory");
|
|
48
|
+
const sync_1 = require("./sync");
|
|
49
|
+
const session_1 = require("./session");
|
|
50
|
+
const utils_1 = require("./utils");
|
|
51
|
+
const agentEnvFile_1 = require("./utils/agentEnvFile");
|
|
52
|
+
const index_1 = require("./utils/index");
|
|
53
|
+
const runtime_1 = require("./cli/runtime");
|
|
54
|
+
const mcp_1 = require("./mcp");
|
|
55
|
+
const terminalLogger_1 = require("./terminalLogger");
|
|
56
|
+
const workspaceFolders_1 = require("./workspaceFolders");
|
|
57
|
+
const branding_1 = require("./branding");
|
|
58
|
+
const binary_1 = require("./utils/binary");
|
|
59
|
+
const paths_1 = require("./agentpack/paths");
|
|
60
|
+
const permissions_1 = require("./permissions");
|
|
61
|
+
const vscode_edit_tracker_1 = require("./runtime/vscode/vscode-edit-tracker");
|
|
62
|
+
const vscode_logger_1 = require("./runtime/vscode/vscode-logger");
|
|
63
|
+
const vscode_config_provider_1 = require("./runtime/vscode/vscode-config-provider");
|
|
64
|
+
const permission_handler_1 = require("./runtime/interfaces/permission-handler");
|
|
65
|
+
const customRegistry_1 = require("./engines/customRegistry");
|
|
66
|
+
const handleRemoteChat_js_1 = require("./remote/handleRemoteChat.js");
|
|
67
|
+
const serveClient_js_1 = require("./remote/serveClient.js");
|
|
68
|
+
const remotePackStatusBar_js_1 = require("./remote/remotePackStatusBar.js");
|
|
69
|
+
const provider_js_1 = require("./auth/provider.js");
|
|
70
|
+
const signInFlow_js_1 = require("./auth/signInFlow.js");
|
|
71
|
+
const githubStoreGate_js_1 = require("./auth/githubStoreGate.js");
|
|
72
|
+
const sessionEvents_1 = require("./analytics/sessionEvents");
|
|
73
|
+
const base_1 = require("./engines/base");
|
|
74
|
+
/** globalState key for user-installed bundled tools dir (from "Install Bundled Tools" command). */
|
|
75
|
+
const BUNDLED_TOOLS_DIR_KEY = 'agentide.bundledToolsDir';
|
|
76
|
+
const AGENTIDE_SESSIONS_DIR_NAME = `${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/${paths_1.AGENT_CONSTANTS.SESSIONS_DIR}`;
|
|
77
|
+
const TERMINAL_LOG_FILE_NAME = "terminal.md";
|
|
78
|
+
const MAX_TERMINAL_LOG_BYTES = 2 * 1024 * 1024; // 2MB per session, then rotate
|
|
79
|
+
const ATTACHMENTS_DIR_NAME = "attachments";
|
|
80
|
+
let _state;
|
|
81
|
+
let _extensionContext;
|
|
82
|
+
const _activeRunsByStreamId = new Map();
|
|
83
|
+
const _pendingQuestionsById = new Map();
|
|
84
|
+
const STREAM_QUESTION_TIMEOUT_MS = 1000 * 60 * 10;
|
|
85
|
+
function resolvePendingQuestion(questionId, answer) {
|
|
86
|
+
const pending = _pendingQuestionsById.get(questionId);
|
|
87
|
+
if (!pending) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
clearTimeout(pending.timeout);
|
|
91
|
+
_pendingQuestionsById.delete(questionId);
|
|
92
|
+
pending.resolver(answer);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function rejectPendingQuestionsForStream(streamId, reason) {
|
|
96
|
+
for (const [questionId, pending] of _pendingQuestionsById) {
|
|
97
|
+
if (pending.streamId !== streamId) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
clearTimeout(pending.timeout);
|
|
101
|
+
_pendingQuestionsById.delete(questionId);
|
|
102
|
+
pending.rejecter(new Error(reason));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function askQuestionFromChatUI(streamId, question) {
|
|
106
|
+
return await new Promise((resolve, reject) => {
|
|
107
|
+
const timeout = setTimeout(() => {
|
|
108
|
+
_pendingQuestionsById.delete(question.questionId);
|
|
109
|
+
reject(new Error('Question timed out waiting for user response'));
|
|
110
|
+
}, STREAM_QUESTION_TIMEOUT_MS);
|
|
111
|
+
_pendingQuestionsById.set(question.questionId, {
|
|
112
|
+
streamId,
|
|
113
|
+
question,
|
|
114
|
+
resolver: resolve,
|
|
115
|
+
rejecter: reject,
|
|
116
|
+
timeout,
|
|
117
|
+
});
|
|
118
|
+
void Promise.resolve(vscode.commands.executeCommand('agentide.streamCallback', {
|
|
119
|
+
streamId,
|
|
120
|
+
type: 'question',
|
|
121
|
+
metadata: question,
|
|
122
|
+
})).catch((err) => {
|
|
123
|
+
clearTimeout(timeout);
|
|
124
|
+
_pendingQuestionsById.delete(question.questionId);
|
|
125
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function normalizeQuestionAnswer(answer) {
|
|
130
|
+
const candidate = (answer && typeof answer === 'object') ? answer : {};
|
|
131
|
+
const selected = Array.isArray(candidate.selected)
|
|
132
|
+
? candidate.selected.filter((item) => typeof item === 'string' && item.trim().length > 0)
|
|
133
|
+
: [];
|
|
134
|
+
const freeText = typeof candidate.freeText === 'string'
|
|
135
|
+
? candidate.freeText
|
|
136
|
+
: (candidate.freeText === null ? null : null);
|
|
137
|
+
return {
|
|
138
|
+
selected,
|
|
139
|
+
freeText,
|
|
140
|
+
declined: candidate.declined === true,
|
|
141
|
+
timedOut: candidate.timedOut === true,
|
|
142
|
+
cancelled: candidate.cancelled === true,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function questionPromptToHeader(prompt) {
|
|
146
|
+
const firstLine = prompt.split(/\r?\n/, 1)[0]?.trim() || 'Question';
|
|
147
|
+
if (firstLine.length <= 50) {
|
|
148
|
+
return firstLine;
|
|
149
|
+
}
|
|
150
|
+
return `${firstLine.slice(0, 47)}...`;
|
|
151
|
+
}
|
|
152
|
+
/** Map our stream question payload to the workbench askQuestions tool input. */
|
|
153
|
+
function streamPayloadToAskQuestionsInput(payload) {
|
|
154
|
+
const header = questionPromptToHeader(payload.prompt);
|
|
155
|
+
const question = {
|
|
156
|
+
header,
|
|
157
|
+
question: payload.prompt,
|
|
158
|
+
multiSelect: payload.multiSelect,
|
|
159
|
+
allowFreeformInput: payload.allowFreeText,
|
|
160
|
+
};
|
|
161
|
+
if (payload.options?.length) {
|
|
162
|
+
question.options = payload.options.map(o => ({
|
|
163
|
+
label: o.label,
|
|
164
|
+
description: o.description,
|
|
165
|
+
recommended: o.recommended,
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
return { questions: [question] };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Ask a question via the workbench's built-in askQuestions tool (same path as Copilot).
|
|
172
|
+
* Uses vscode.lm.invokeTool so the chat UI shows the question carousel and returns the user's answer.
|
|
173
|
+
*/
|
|
174
|
+
async function askQuestionViaWorkbenchTool(sessionResource, _requestId, payload, abortSignal) {
|
|
175
|
+
const tokenSource = new vscode.CancellationTokenSource();
|
|
176
|
+
abortSignal.addEventListener('abort', () => tokenSource.cancel(), { once: true });
|
|
177
|
+
try {
|
|
178
|
+
const input = streamPayloadToAskQuestionsInput(payload);
|
|
179
|
+
// Workbench expects IToolInvocationContext { sessionResource } for chat-attached tool UX
|
|
180
|
+
const result = await vscode.lm.invokeTool('vscode_askQuestions', {
|
|
181
|
+
input,
|
|
182
|
+
toolInvocationToken: { sessionResource: vscode.Uri.parse(sessionResource) },
|
|
183
|
+
}, tokenSource.token);
|
|
184
|
+
// Result content: [{ kind: 'text', value: jsonString }]. JSON is IAnswerResult { answers: Record<header, IQuestionAnswer> }.
|
|
185
|
+
const firstText = result?.content?.find((p) => typeof p.value === 'string');
|
|
186
|
+
const jsonStr = firstText?.value;
|
|
187
|
+
if (!jsonStr) {
|
|
188
|
+
return { selected: [], freeText: null, declined: true };
|
|
189
|
+
}
|
|
190
|
+
const parsed = JSON.parse(jsonStr);
|
|
191
|
+
const answers = parsed?.answers ?? {};
|
|
192
|
+
const firstKey = Object.keys(answers)[0];
|
|
193
|
+
const answer = firstKey ? answers[firstKey] : undefined;
|
|
194
|
+
if (!answer) {
|
|
195
|
+
return { selected: [], freeText: null, declined: true };
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
selected: answer.selected ?? [],
|
|
199
|
+
freeText: answer.freeText ?? null,
|
|
200
|
+
declined: answer.skipped === true,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
// User cancelled or tool failed
|
|
205
|
+
const cancelled = err instanceof Error && (err.name === 'Canceled' || err.message?.includes('cancel'));
|
|
206
|
+
return { selected: [], freeText: null, declined: true, cancelled };
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
tokenSource.dispose();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// -----------------------------------------------------------------------------
|
|
213
|
+
// Constants
|
|
214
|
+
// -----------------------------------------------------------------------------
|
|
215
|
+
const SESSION_CLEANUP_INTERVAL_MS = 1000 * 60 * 5; // 5 minutes
|
|
216
|
+
function log(outputChannel, message) {
|
|
217
|
+
outputChannel.appendLine((0, branding_1.brandify)(message));
|
|
218
|
+
}
|
|
219
|
+
function logConsole(message) {
|
|
220
|
+
console.log((0, branding_1.brandify)(message));
|
|
221
|
+
}
|
|
222
|
+
function showInfo(message) {
|
|
223
|
+
return vscode.window.showInformationMessage((0, branding_1.brandify)(message));
|
|
224
|
+
}
|
|
225
|
+
function showWarning(message) {
|
|
226
|
+
return vscode.window.showWarningMessage((0, branding_1.brandify)(message));
|
|
227
|
+
}
|
|
228
|
+
function showError(message) {
|
|
229
|
+
return vscode.window.showErrorMessage((0, branding_1.brandify)(message));
|
|
230
|
+
}
|
|
231
|
+
// -----------------------------------------------------------------------------
|
|
232
|
+
// Activation
|
|
233
|
+
// -----------------------------------------------------------------------------
|
|
234
|
+
async function activate(context) {
|
|
235
|
+
const outputChannel = vscode.window.createOutputChannel(branding_1.AGENTIDE_EXTENSION_NAME);
|
|
236
|
+
log(outputChannel, `${branding_1.AGENTIDE_BRAND_NAME} extension activating...`);
|
|
237
|
+
logConsole(`${branding_1.AGENTIDE_BRAND_NAME} extension activating...`);
|
|
238
|
+
try {
|
|
239
|
+
const envMerge = await (0, agentEnvFile_1.mergeAgentHomeEnvIntoProcessEnv)();
|
|
240
|
+
if (envMerge.applied.length > 0) {
|
|
241
|
+
log(outputChannel, `[AgentIDE] Loaded ${envMerge.applied.length} env var(s) from ${envMerge.envFilePath} (shell env wins on conflict)`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
246
|
+
log(outputChannel, `[AgentIDE] Warning: failed to load ~/.agent-hippo/.env: ${message}`);
|
|
247
|
+
}
|
|
248
|
+
_extensionContext = context;
|
|
249
|
+
// Expose extension scripts directory to agent shells
|
|
250
|
+
// This allows skills to reference setup scripts via $AGENTIDE_ANALYTICS_SCRIPTS_DIR
|
|
251
|
+
const analyticsScriptsDir = (0, utils_1.getAnalyticsScriptsDir)(context.extensionPath);
|
|
252
|
+
process.env.AGENTIDE_ANALYTICS_SCRIPTS_DIR = analyticsScriptsDir;
|
|
253
|
+
log(outputChannel, `[AgentIDE] Analytics scripts dir: ${analyticsScriptsDir}`);
|
|
254
|
+
// Initialize session persistence
|
|
255
|
+
(0, session_1.initSessionStore)(context);
|
|
256
|
+
// Setup cleanup interval - runs maintenance on all providers generically
|
|
257
|
+
const maintenanceLogger = new vscode_logger_1.VSCodeLogger(outputChannel, "[Maintenance]");
|
|
258
|
+
const cleanupInterval = setInterval(() => {
|
|
259
|
+
(0, session_1.runSessionMaintenance)();
|
|
260
|
+
if (_state) {
|
|
261
|
+
for (const engine of Object.values(_state.engines)) {
|
|
262
|
+
engine.onMaintenance(maintenanceLogger);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}, SESSION_CLEANUP_INTERVAL_MS);
|
|
266
|
+
context.subscriptions.push(new vscode.Disposable(() => clearInterval(cleanupInterval)));
|
|
267
|
+
// Prepare workspace-scoped engine directories from registry
|
|
268
|
+
const storageBase = context.storageUri ?? context.globalStorageUri;
|
|
269
|
+
const storageType = context.storageUri ? "per-workspace" : "global";
|
|
270
|
+
// Build config from AGENT_ENGINES
|
|
271
|
+
const config = {
|
|
272
|
+
storagePath: storageBase.fsPath,
|
|
273
|
+
};
|
|
274
|
+
for (const engine of Object.values(types_1.AGENT_ENGINES)) {
|
|
275
|
+
const dirPath = path.join(storageBase.fsPath, engine.id);
|
|
276
|
+
try {
|
|
277
|
+
await fs_1.promises.mkdir(dirPath, { recursive: true });
|
|
278
|
+
log(outputChannel, `[AgentIDE] ${engine.displayName} dir: ${dirPath} (${storageType})`);
|
|
279
|
+
// Dynamically set config directory based on engine's configEnvVar
|
|
280
|
+
if (engine.configEnvVar === "CODEX_HOME") {
|
|
281
|
+
config.codexHome = dirPath;
|
|
282
|
+
}
|
|
283
|
+
else if (engine.configEnvVar === "CLAUDE_CONFIG_DIR") {
|
|
284
|
+
config.claudeConfigDir = dirPath;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
log(outputChannel, `[AgentIDE] Warning: failed to create ${engine.id} dir: ${e instanceof Error ? e.message : String(e)}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Create sync service
|
|
292
|
+
const syncService = new sync_1.SyncService(() => getBundledBasePromptsDir());
|
|
293
|
+
// Create engines from factory
|
|
294
|
+
const engines = (0, factory_1.createEngines)({
|
|
295
|
+
config,
|
|
296
|
+
syncService,
|
|
297
|
+
getBundledBasePromptsDir: () => getBundledBasePromptsDir(),
|
|
298
|
+
});
|
|
299
|
+
// Store state
|
|
300
|
+
_state = {
|
|
301
|
+
outputChannel,
|
|
302
|
+
engines,
|
|
303
|
+
syncService,
|
|
304
|
+
config,
|
|
305
|
+
};
|
|
306
|
+
// Enable Agent Skills by default (VS Code promptSyntax setting renamed in main7)
|
|
307
|
+
try {
|
|
308
|
+
const chatConfig = vscode.workspace.getConfiguration("chat");
|
|
309
|
+
const inspect = chatConfig.inspect("useAgentSkills");
|
|
310
|
+
if (inspect &&
|
|
311
|
+
!inspect.globalValue &&
|
|
312
|
+
!inspect.workspaceValue &&
|
|
313
|
+
!inspect.workspaceFolderValue) {
|
|
314
|
+
await chatConfig.update("useAgentSkills", true, vscode.ConfigurationTarget.Global);
|
|
315
|
+
log(outputChannel, "[AgentIDE] Enabled Agent Skills by default");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch (e) {
|
|
319
|
+
log(outputChannel, `[AgentIDE] Warning: failed to enable Agent Skills setting: ${e instanceof Error ? e.message : String(e)}`);
|
|
320
|
+
}
|
|
321
|
+
// Register bundled MCP servers with VS Code
|
|
322
|
+
await registerBundledMcpServers(context, outputChannel);
|
|
323
|
+
(0, provider_js_1.registerAgentHippoAuth)(context);
|
|
324
|
+
void (0, provider_js_1.refreshBootstrapIfSignedIn)(context);
|
|
325
|
+
context.subscriptions.push((0, provider_js_1.startAgentHippoTokenRefreshTimer)(context));
|
|
326
|
+
// Register commands
|
|
327
|
+
registerCommands(context, _state);
|
|
328
|
+
const remotePackStatusBar = new remotePackStatusBar_js_1.RemotePackStatusBar(syncService, () => getWorkspaceRoot(outputChannel).workspaceRoot, outputChannel);
|
|
329
|
+
_state.remotePackStatusBar = remotePackStatusBar;
|
|
330
|
+
context.subscriptions.push(remotePackStatusBar);
|
|
331
|
+
void remotePackStatusBar.refresh();
|
|
332
|
+
// Initialize Agent Anywhere lifecycle manager (detect/install/start/stop gateway)
|
|
333
|
+
// This is the user-facing "Agent Anywhere" feature -- all opt-in, nothing auto-starts.
|
|
334
|
+
// The lifecycle manager owns the single status bar icon and handles connect/disconnect.
|
|
335
|
+
const { GatewayLifecycleManager } = await import('./gateway/lifecycle.js');
|
|
336
|
+
_state.gatewayLifecycle = new GatewayLifecycleManager(outputChannel, context);
|
|
337
|
+
context.subscriptions.push({ dispose: () => _state?.gatewayLifecycle?.dispose() });
|
|
338
|
+
// Initialize Gateway bridge service (WebSocket connection to gateway)
|
|
339
|
+
// Routes messages via VS Code Chat UI commands -- no direct engine access needed.
|
|
340
|
+
const { GatewayService: GatewayServiceClass } = await import('./gateway/service.js');
|
|
341
|
+
_state.gatewayService = new GatewayServiceClass(context, outputChannel);
|
|
342
|
+
context.subscriptions.push({ dispose: () => _state?.gatewayService?.dispose() });
|
|
343
|
+
// Wire lifecycle ↔ bridge: lifecycle manages connect/disconnect via the single icon
|
|
344
|
+
_state.gatewayLifecycle.setBridgeRef(_state.gatewayService);
|
|
345
|
+
// Meet Agent Anywhere is only opened from the command palette / Agent Anywhere menu — not after connect.
|
|
346
|
+
// Auto-connect bridge when gateway starts running (if autoConnect is enabled)
|
|
347
|
+
_state.gatewayLifecycle.onStatusChange(async (status) => {
|
|
348
|
+
if (status === 'running') {
|
|
349
|
+
const autoConnect = vscode.workspace.getConfiguration('agentide.anywhere').get('autoConnect', false);
|
|
350
|
+
if (autoConnect && _state?.gatewayLifecycle) {
|
|
351
|
+
void _state.gatewayLifecycle.connectBridge();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
// Initialize Analytics service (for LiteLLM Spotlight)
|
|
356
|
+
const { AnalyticsService: AnalyticsServiceClass } = await import('./analytics/service.js');
|
|
357
|
+
_state.analyticsService = new AnalyticsServiceClass(context, outputChannel);
|
|
358
|
+
context.subscriptions.push({ dispose: () => _state?.analyticsService?.dispose() });
|
|
359
|
+
// Initialize Spotlight Dashboard (WebView sidebar with charts + chat)
|
|
360
|
+
const { AnalyticsDashboardProvider, ArtifactManagerImpl, QueryRunnerImpl, ensureBundledFleetAdapters, } = await import('./analytics/dashboard/index.js');
|
|
361
|
+
const spotlightArtifactManager = new ArtifactManagerImpl(outputChannel);
|
|
362
|
+
const teamArtifactManager = new ArtifactManagerImpl(outputChannel);
|
|
363
|
+
const queryRunner = new QueryRunnerImpl(outputChannel);
|
|
364
|
+
ensureBundledFleetAdapters(queryRunner);
|
|
365
|
+
const analyticsService = _state.analyticsService;
|
|
366
|
+
_state.analyticsDashboard = new AnalyticsDashboardProvider(context, queryRunner, spotlightArtifactManager, outputChannel, () => analyticsService?.getIndexingService());
|
|
367
|
+
const teamDashboard = new AnalyticsDashboardProvider(context, queryRunner, teamArtifactManager, outputChannel, () => analyticsService?.getIndexingService(), 'team');
|
|
368
|
+
_state.analyticsTeamDashboard = teamDashboard;
|
|
369
|
+
context.subscriptions.push(vscode.window.registerWebviewViewProvider(AnalyticsDashboardProvider.viewType, _state.analyticsDashboard, { webviewOptions: { retainContextWhenHidden: true } }), vscode.window.registerWebviewViewProvider('agentide.teamView', teamDashboard, { webviewOptions: { retainContextWhenHidden: true } }), _state.analyticsDashboard, teamDashboard, { dispose: () => spotlightArtifactManager.dispose() }, { dispose: () => teamArtifactManager.dispose() }, { dispose: () => queryRunner.dispose() });
|
|
370
|
+
// Spotlight dashboard commands
|
|
371
|
+
context.subscriptions.push(vscode.commands.registerCommand('agentide.analytics.openDashboard', () => {
|
|
372
|
+
vscode.commands.executeCommand('agentide.analyticsView.focus');
|
|
373
|
+
}), vscode.commands.registerCommand('agentide.fleet.open', async () => {
|
|
374
|
+
const team = _state?.analyticsTeamDashboard;
|
|
375
|
+
if (team) {
|
|
376
|
+
await team.openWithView('fleet');
|
|
377
|
+
}
|
|
378
|
+
await vscode.commands.executeCommand('agentide.teamView.focus');
|
|
379
|
+
}), vscode.commands.registerCommand('agentide.analytics.clearArtifacts', async () => {
|
|
380
|
+
const result = await spotlightArtifactManager.cleanup(0);
|
|
381
|
+
await context.workspaceState.update('analytics.generatedDefaultDashboard', false);
|
|
382
|
+
vscode.window.showInformationMessage(`Cleared ${result.deletedCount} Spotlight artifacts (${(result.freedBytes / 1024).toFixed(1)} KB)`);
|
|
383
|
+
}), vscode.commands.registerCommand('agentide.analytics.regenerateDefaults', async () => {
|
|
384
|
+
if (_state?.analyticsDashboard) {
|
|
385
|
+
queryRunner.invalidateCache();
|
|
386
|
+
await _state.analyticsDashboard.runDefaultChartScript();
|
|
387
|
+
}
|
|
388
|
+
}), vscode.commands.registerCommand('agentide.persistChatVote', async (payload) => {
|
|
389
|
+
if (!payload?.sessionId || !payload?.requestId)
|
|
390
|
+
return;
|
|
391
|
+
await _sessionEventWriter.append(payload.sessionId, payload.requestId, 'vote', {
|
|
392
|
+
direction: payload.direction,
|
|
393
|
+
reason: payload.reason,
|
|
394
|
+
agentId: payload.agentId,
|
|
395
|
+
command: payload.command,
|
|
396
|
+
});
|
|
397
|
+
}));
|
|
398
|
+
// Activate terminal activity logger (logs all terminal commands to the agent terminals directory)
|
|
399
|
+
// Terminal logs are automatically truncated to max N lines (configurable)
|
|
400
|
+
// Session cleanup happens opportunistically when sessions are deleted
|
|
401
|
+
(0, terminalLogger_1.activateTerminalLogger)(context);
|
|
402
|
+
// Simplest retention behavior: best-effort cleanup on startup (non-blocking).
|
|
403
|
+
// Manual cleanup is also available via 'AgentIDE: Cleanup Old Session Logs'.
|
|
404
|
+
const sessionsCleanupTimeout = setTimeout(() => {
|
|
405
|
+
void (0, terminalLogger_1.cleanupOldSessionLogs)(outputChannel);
|
|
406
|
+
}, 5_000);
|
|
407
|
+
context.subscriptions.push(new vscode.Disposable(() => clearTimeout(sessionsCleanupTimeout)));
|
|
408
|
+
// Initialize store index in background (non-blocking)
|
|
409
|
+
// This preloads the Orama search index for faster store browsing
|
|
410
|
+
const storeIndexTimeout = setTimeout(async () => {
|
|
411
|
+
try {
|
|
412
|
+
const { initializeStoreIndex } = await import("./store/oramaIndex.js");
|
|
413
|
+
await initializeStoreIndex(outputChannel);
|
|
414
|
+
}
|
|
415
|
+
catch (e) {
|
|
416
|
+
log(outputChannel, `[AgentIDE] Store index init: ${e instanceof Error ? e.message : String(e)}`);
|
|
417
|
+
}
|
|
418
|
+
}, 3_000); // Delay slightly to prioritize other startup tasks
|
|
419
|
+
context.subscriptions.push(new vscode.Disposable(() => clearTimeout(storeIndexTimeout)));
|
|
420
|
+
// Setup workspace watchers and repair unregistered packs
|
|
421
|
+
if (vscode.workspace.workspaceFolders?.length) {
|
|
422
|
+
void refreshAgentideProject(_state).then(async () => {
|
|
423
|
+
syncService.ensureAgentideWatchers(outputChannel);
|
|
424
|
+
// Auto-repair: register any untracked packs found on disk
|
|
425
|
+
try {
|
|
426
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
427
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
428
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
429
|
+
const { registered } = await packManager.repairUnregisteredAgents();
|
|
430
|
+
if (registered.length > 0) {
|
|
431
|
+
log(outputChannel, `[AgentIDE] Auto-repaired ${registered.length} unregistered pack(s): ${registered.join(", ")}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
log(outputChannel, `[AgentIDE] Pack repair check failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
436
|
+
}
|
|
437
|
+
// Note: Pack restoration is now handled by the workbench (AgentPackService).
|
|
438
|
+
// The workbench persists the active pack ID in IStorageService and calls
|
|
439
|
+
// agentide.pack.setActive on startup to restore pack files.
|
|
440
|
+
// Mode/model preferences are stored in the chat widget's storage and
|
|
441
|
+
// restored by the chat widget itself.
|
|
442
|
+
void _state?.remotePackStatusBar?.refresh();
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(() => {
|
|
446
|
+
syncService.ensureAgentideWatchers(outputChannel);
|
|
447
|
+
if (_state) {
|
|
448
|
+
void refreshAgentideProject(_state);
|
|
449
|
+
void _state.remotePackStatusBar?.refresh();
|
|
450
|
+
}
|
|
451
|
+
}));
|
|
452
|
+
context.subscriptions.push(new vscode.Disposable(() => {
|
|
453
|
+
syncService.disposeAllWatchers();
|
|
454
|
+
}));
|
|
455
|
+
log(outputChannel, "[AgentIDE] Extension activation complete");
|
|
456
|
+
}
|
|
457
|
+
function deactivate() {
|
|
458
|
+
if (_state) {
|
|
459
|
+
for (const engine of Object.values(_state.engines)) {
|
|
460
|
+
try {
|
|
461
|
+
engine.dispose();
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
// ignore
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
_state = undefined;
|
|
469
|
+
}
|
|
470
|
+
function escapeRegExp(value) {
|
|
471
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
472
|
+
}
|
|
473
|
+
function quoteEnvValue(value) {
|
|
474
|
+
if (/^[A-Za-z0-9_./:@-]+$/.test(value)) {
|
|
475
|
+
return value;
|
|
476
|
+
}
|
|
477
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
478
|
+
}
|
|
479
|
+
function upsertEnvVar(content, variable, value) {
|
|
480
|
+
const lines = content.split(/\r?\n/);
|
|
481
|
+
const matcher = new RegExp(`^\\s*(?:export\\s+)?${escapeRegExp(variable)}\\s*=`);
|
|
482
|
+
let replaced = false;
|
|
483
|
+
for (let i = 0; i < lines.length; i++) {
|
|
484
|
+
const line = lines[i];
|
|
485
|
+
const trimmed = line.trim();
|
|
486
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
if (matcher.test(line)) {
|
|
490
|
+
lines[i] = `${variable}=${quoteEnvValue(value)}`;
|
|
491
|
+
replaced = true;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (!replaced) {
|
|
495
|
+
if (lines.length > 0 && lines[lines.length - 1].trim() !== "") {
|
|
496
|
+
lines.push("");
|
|
497
|
+
}
|
|
498
|
+
lines.push(`${variable}=${quoteEnvValue(value)}`);
|
|
499
|
+
}
|
|
500
|
+
return lines.join("\n").replace(/\s*$/, "\n");
|
|
501
|
+
}
|
|
502
|
+
function hasEnvVar(content, variable) {
|
|
503
|
+
const matcher = new RegExp(`^\\s*(?:export\\s+)?${escapeRegExp(variable)}\\s*=`);
|
|
504
|
+
return content.split(/\r?\n/).some(line => {
|
|
505
|
+
const trimmed = line.trim();
|
|
506
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
return matcher.test(line);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
// -----------------------------------------------------------------------------
|
|
513
|
+
// Command Registration
|
|
514
|
+
// -----------------------------------------------------------------------------
|
|
515
|
+
function registerCommands(context, state) {
|
|
516
|
+
const { outputChannel, syncService, config } = state;
|
|
517
|
+
// Set API keys (called from Workbench)
|
|
518
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.setParticipantApiKey", (args) => {
|
|
519
|
+
log(outputChannel, `[AgentIDE] Setting API key for ${args.provider}${args.baseUrl ? ` with baseUrl: ${args.baseUrl}` : ""}`);
|
|
520
|
+
if (args.provider === "litellm") {
|
|
521
|
+
config.litellmApiKey = args.apiKey;
|
|
522
|
+
config.litellmBaseUrl = args.baseUrl;
|
|
523
|
+
}
|
|
524
|
+
}));
|
|
525
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.binary.findOnPath", async (args) => {
|
|
526
|
+
const name = args?.name?.trim();
|
|
527
|
+
if (!name) {
|
|
528
|
+
throw new Error("Binary name is required");
|
|
529
|
+
}
|
|
530
|
+
return (0, binary_1.findBinaryCached)(name, (0, binary_1.getCommonBinaryPaths)(name));
|
|
531
|
+
}));
|
|
532
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.openaiCodex.loginOAuth", async () => {
|
|
533
|
+
log(outputChannel, "[AgentIDE] Starting native OpenAI Codex OAuth login");
|
|
534
|
+
const { loginOpenAICodex } = await import("@mariozechner/pi-ai");
|
|
535
|
+
const creds = await loginOpenAICodex({
|
|
536
|
+
onAuth: async ({ url }) => {
|
|
537
|
+
log(outputChannel, `[AgentIDE] OpenAI Codex OAuth URL: ${url}`);
|
|
538
|
+
try {
|
|
539
|
+
await vscode.env.openExternal(vscode.Uri.parse(url));
|
|
540
|
+
void showInfo("Complete ChatGPT sign-in in your browser. Return here if prompted for a redirect URL.");
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
log(outputChannel, `[AgentIDE] Failed to auto-open OAuth URL: ${String(error)}`);
|
|
544
|
+
void showWarning(`Open this URL in your browser: ${url}`);
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
onPrompt: async (prompt) => {
|
|
548
|
+
const input = await vscode.window.showInputBox({
|
|
549
|
+
title: "OpenAI Codex OAuth",
|
|
550
|
+
prompt: prompt.message,
|
|
551
|
+
placeHolder: prompt.placeholder,
|
|
552
|
+
ignoreFocusOut: true,
|
|
553
|
+
validateInput: value => value.trim().length > 0 ? undefined : "Required"
|
|
554
|
+
});
|
|
555
|
+
if (!input || input.trim().length === 0) {
|
|
556
|
+
throw new Error("OpenAI Codex OAuth cancelled");
|
|
557
|
+
}
|
|
558
|
+
return input.trim();
|
|
559
|
+
},
|
|
560
|
+
onProgress: (message) => {
|
|
561
|
+
log(outputChannel, `[AgentIDE] OpenAI Codex OAuth: ${message}`);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
const apiKey = creds?.access?.trim();
|
|
565
|
+
if (!apiKey) {
|
|
566
|
+
throw new Error("OpenAI Codex OAuth completed without an access token");
|
|
567
|
+
}
|
|
568
|
+
const oauthCredential = { type: "oauth", ...creds };
|
|
569
|
+
const result = {
|
|
570
|
+
apiKey,
|
|
571
|
+
oauthCredential,
|
|
572
|
+
expiresAt: typeof creds.expires === "number" ? creds.expires : undefined
|
|
573
|
+
};
|
|
574
|
+
log(outputChannel, "[AgentIDE] OpenAI Codex OAuth login complete");
|
|
575
|
+
return result;
|
|
576
|
+
}));
|
|
577
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.openaiCodex.getValidApiKey", async (args) => {
|
|
578
|
+
const oauthCredential = args?.oauthCredential;
|
|
579
|
+
if (!oauthCredential || typeof oauthCredential !== "object") {
|
|
580
|
+
throw new Error("Missing openai-codex OAuth credential payload.");
|
|
581
|
+
}
|
|
582
|
+
const { getOAuthApiKey } = await import("@mariozechner/pi-ai");
|
|
583
|
+
const normalized = ((oauthCredential.type === "oauth")
|
|
584
|
+
? oauthCredential
|
|
585
|
+
: { type: "oauth", ...oauthCredential });
|
|
586
|
+
const authMap = {
|
|
587
|
+
"openai-codex": normalized,
|
|
588
|
+
};
|
|
589
|
+
const resolved = await getOAuthApiKey("openai-codex", authMap);
|
|
590
|
+
if (!resolved?.apiKey) {
|
|
591
|
+
throw new Error("OpenAI Codex OAuth credential is invalid or expired. Please sign in again.");
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
apiKey: String(resolved.apiKey),
|
|
595
|
+
oauthCredential: { type: "oauth", ...resolved.newCredentials },
|
|
596
|
+
expiresAt: typeof resolved.newCredentials?.expires === "number"
|
|
597
|
+
? resolved.newCredentials.expires
|
|
598
|
+
: undefined
|
|
599
|
+
};
|
|
600
|
+
}));
|
|
601
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.litellm.setUpstreamApiKey", async (args) => {
|
|
602
|
+
const envVar = args?.envVar?.trim() ?? "";
|
|
603
|
+
const apiKey = args?.apiKey?.trim() ?? "";
|
|
604
|
+
if (!envVar || !/^[A-Z][A-Z0-9_]*$/.test(envVar)) {
|
|
605
|
+
throw new Error(`Invalid env var name: ${envVar}`);
|
|
606
|
+
}
|
|
607
|
+
if (!apiKey) {
|
|
608
|
+
throw new Error(`API key value cannot be empty for ${envVar}`);
|
|
609
|
+
}
|
|
610
|
+
const agentHomeDir = (0, index_1.getAgentideHome)();
|
|
611
|
+
const envFilePath = path.join(agentHomeDir, ".env");
|
|
612
|
+
await fs_1.promises.mkdir(agentHomeDir, { recursive: true, mode: 0o700 });
|
|
613
|
+
let existingContent = "";
|
|
614
|
+
try {
|
|
615
|
+
existingContent = await fs_1.promises.readFile(envFilePath, "utf8");
|
|
616
|
+
}
|
|
617
|
+
catch {
|
|
618
|
+
// File does not exist yet, we'll create it below.
|
|
619
|
+
}
|
|
620
|
+
const updatedContent = upsertEnvVar(existingContent, envVar, apiKey);
|
|
621
|
+
await fs_1.promises.writeFile(envFilePath, updatedContent, "utf8");
|
|
622
|
+
try {
|
|
623
|
+
await fs_1.promises.chmod(envFilePath, 0o600);
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
// Best-effort on platforms that may not support chmod.
|
|
627
|
+
}
|
|
628
|
+
log(outputChannel, `[AgentIDE] Updated LiteLLM upstream key in ${envFilePath} (${envVar})`);
|
|
629
|
+
return { envFilePath, envVar };
|
|
630
|
+
}));
|
|
631
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.litellm.getUpstreamApiKeyStatus", async (args) => {
|
|
632
|
+
const envVar = args?.envVar?.trim() ?? "";
|
|
633
|
+
if (!envVar || !/^[A-Z][A-Z0-9_]*$/.test(envVar)) {
|
|
634
|
+
throw new Error(`Invalid env var name: ${envVar}`);
|
|
635
|
+
}
|
|
636
|
+
const agentHomeDir = (0, index_1.getAgentideHome)();
|
|
637
|
+
const envFilePath = path.join(agentHomeDir, ".env");
|
|
638
|
+
let existingContent = "";
|
|
639
|
+
try {
|
|
640
|
+
existingContent = await fs_1.promises.readFile(envFilePath, "utf8");
|
|
641
|
+
}
|
|
642
|
+
catch {
|
|
643
|
+
// Missing file means key is not configured yet.
|
|
644
|
+
}
|
|
645
|
+
return {
|
|
646
|
+
envFilePath,
|
|
647
|
+
envVar,
|
|
648
|
+
exists: hasEnvVar(existingContent, envVar),
|
|
649
|
+
};
|
|
650
|
+
}));
|
|
651
|
+
// Clear managed resources
|
|
652
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.clearManagedResources", async () => {
|
|
653
|
+
const confirm = await vscode.window.showWarningMessage((0, branding_1.brandify)("Clear all AgentIDE managed resources?"), {
|
|
654
|
+
modal: true,
|
|
655
|
+
detail: `This will remove derived folders and generated files. User-managed files in \`${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/\` will NOT be deleted.`,
|
|
656
|
+
}, "Clear Resources", "Cancel");
|
|
657
|
+
if (confirm !== "Clear Resources") {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const { workspaceRoot, additionalDirectories, isHomeFallback } = getWorkspaceRoot(outputChannel);
|
|
661
|
+
if (isHomeFallback) {
|
|
662
|
+
// Ensure fallback exists before doing any filesystem work.
|
|
663
|
+
await ensureFallbackDirectoryExists(outputChannel);
|
|
664
|
+
}
|
|
665
|
+
const { cleared, skipped, errors } = await syncService.clearManagedResources(config.codexHome, config.claudeConfigDir, workspaceRoot, additionalDirectories, outputChannel);
|
|
666
|
+
const message = [
|
|
667
|
+
`Cleared: ${cleared.length} resources`,
|
|
668
|
+
skipped.length > 0 ? `Skipped: ${skipped.length} (user files)` : "",
|
|
669
|
+
errors.length > 0 ? `Errors: ${errors.length}` : "",
|
|
670
|
+
]
|
|
671
|
+
.filter(Boolean)
|
|
672
|
+
.join(" | ");
|
|
673
|
+
if (errors.length > 0) {
|
|
674
|
+
showError(`AgentIDE: ${message}`);
|
|
675
|
+
log(outputChannel, `[AgentIDE] Errors: ${errors.join(", ")}`);
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
showInfo(`AgentIDE: ${message}`);
|
|
679
|
+
}
|
|
680
|
+
log(outputChannel, `[AgentIDE] Clear complete: ${message}`);
|
|
681
|
+
}));
|
|
682
|
+
// Sync remote skills into the default agent skills directory (best-effort)
|
|
683
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.skills.syncRemote", async () => {
|
|
684
|
+
const { workspaceRoot, additionalDirectories, isHomeFallback } = getWorkspaceRoot(outputChannel);
|
|
685
|
+
if (isHomeFallback) {
|
|
686
|
+
await ensureFallbackDirectoryExists(outputChannel);
|
|
687
|
+
}
|
|
688
|
+
// Ensure project exists (creates agent root if missing)
|
|
689
|
+
await syncService.ensureAgentideProjectPrepared(workspaceRoot, additionalDirectories, outputChannel);
|
|
690
|
+
// Force a remote skills sync regardless of syncOnStartup
|
|
691
|
+
await syncService.syncRemoteSkillsIfEnabled(workspaceRoot, outputChannel, { force: true });
|
|
692
|
+
// Apply changes immediately (refresh manifest + derived dirs if needed)
|
|
693
|
+
await syncService.flushAgentideRootUpdate(workspaceRoot, outputChannel, {
|
|
694
|
+
allowDuringActiveTurn: true,
|
|
695
|
+
force: false,
|
|
696
|
+
});
|
|
697
|
+
void showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: Remote skills sync complete (see ${branding_1.AGENTIDE_BRAND_NAME} output for details).`);
|
|
698
|
+
}));
|
|
699
|
+
// Show managed resources
|
|
700
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.showManagedResources", async () => {
|
|
701
|
+
const { workspaceRoot, additionalDirectories, isHomeFallback } = getWorkspaceRoot(outputChannel);
|
|
702
|
+
if (isHomeFallback) {
|
|
703
|
+
// Ensure fallback exists before writing derived files.
|
|
704
|
+
await ensureFallbackDirectoryExists(outputChannel);
|
|
705
|
+
}
|
|
706
|
+
await syncService.writeManagedPathsManifest(config.codexHome, config.claudeConfigDir, workspaceRoot, additionalDirectories, outputChannel);
|
|
707
|
+
const manifestPath = path.join((0, paths_1.getAgentideDir)(workspaceRoot), "paths.md");
|
|
708
|
+
if (await (0, utils_1.pathExists)(manifestPath)) {
|
|
709
|
+
const doc = await vscode.workspace.openTextDocument(manifestPath);
|
|
710
|
+
await vscode.window.showTextDocument(doc);
|
|
711
|
+
}
|
|
712
|
+
}));
|
|
713
|
+
// Cleanup old session logs
|
|
714
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.cleanupSessionLogs", async () => {
|
|
715
|
+
const result = await (0, terminalLogger_1.cleanupOldSessionLogs)(outputChannel);
|
|
716
|
+
if (result.cleaned > 0) {
|
|
717
|
+
showInfo(`AgentIDE: Cleaned up ${result.cleaned} old session(s)`);
|
|
718
|
+
}
|
|
719
|
+
else if (result.errors.length > 0) {
|
|
720
|
+
showWarning(`AgentIDE: Cleanup completed with ${result.errors.length} error(s)`);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No old sessions to clean up`);
|
|
724
|
+
}
|
|
725
|
+
}));
|
|
726
|
+
// Delete specific session logs and opportunistically clean up old sessions
|
|
727
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.deleteSessionLogs", async (args) => {
|
|
728
|
+
const sessionId = args?.sessionId;
|
|
729
|
+
if (!sessionId) {
|
|
730
|
+
return { deleted: false, error: "sessionId is required" };
|
|
731
|
+
}
|
|
732
|
+
const result = await (0, terminalLogger_1.deleteSessionLogs)(sessionId);
|
|
733
|
+
if (result.deleted) {
|
|
734
|
+
log(outputChannel, `[AgentIDE] Deleted session logs: ${sessionId}`);
|
|
735
|
+
// Optional: run best-effort retention cleanup after deletion.
|
|
736
|
+
void (0, terminalLogger_1.cleanupOldSessionLogs)(outputChannel);
|
|
737
|
+
}
|
|
738
|
+
else if (result.error) {
|
|
739
|
+
log(outputChannel, `[AgentIDE] Failed to delete session logs: ${result.error}`);
|
|
740
|
+
}
|
|
741
|
+
return result;
|
|
742
|
+
}));
|
|
743
|
+
// -------------------------------------------------------------------------
|
|
744
|
+
// CLI Setup
|
|
745
|
+
// -------------------------------------------------------------------------
|
|
746
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.cli.status", async () => {
|
|
747
|
+
const configuredCliPath = vscode.workspace
|
|
748
|
+
.getConfiguration("agentide")
|
|
749
|
+
.get("cli.path", "");
|
|
750
|
+
const health = await (0, runtime_1.getCliHealth)({
|
|
751
|
+
configuredPath: configuredCliPath,
|
|
752
|
+
extensionPath: context.extensionPath,
|
|
753
|
+
});
|
|
754
|
+
const toolsHealth = (0, runtime_1.getBundledToolsHealth)({
|
|
755
|
+
extensionPath: context.extensionPath,
|
|
756
|
+
binaryDirHint: health.path ? path.dirname(health.path) : undefined,
|
|
757
|
+
});
|
|
758
|
+
const availableTools = toolsHealth.tools.filter(tool => tool.available).map(tool => tool.name);
|
|
759
|
+
if (health.installed) {
|
|
760
|
+
const sourceLabel = health.source === 'setting'
|
|
761
|
+
? 'configured path'
|
|
762
|
+
: health.source === 'bundled'
|
|
763
|
+
? 'bundled binary'
|
|
764
|
+
: 'system PATH';
|
|
765
|
+
const toolsSuffix = availableTools.length > 0
|
|
766
|
+
? `; tools: ${availableTools.join(', ')}`
|
|
767
|
+
: '; tools: none';
|
|
768
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: CLI available (${sourceLabel})${health.version ? ` ${health.version}` : ''}${toolsSuffix}`);
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
showWarning(`${branding_1.AGENTIDE_BRAND_NAME}: CLI not found. Run '${branding_1.AGENTIDE_BRAND_NAME}: Setup AgentHippo CLI'.`);
|
|
772
|
+
}
|
|
773
|
+
return health;
|
|
774
|
+
}));
|
|
775
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.cli.isInstalled", async () => {
|
|
776
|
+
const configuredCliPath = vscode.workspace
|
|
777
|
+
.getConfiguration("agentide")
|
|
778
|
+
.get("cli.path", "");
|
|
779
|
+
const health = await (0, runtime_1.getCliHealth)({
|
|
780
|
+
configuredPath: configuredCliPath,
|
|
781
|
+
extensionPath: context.extensionPath,
|
|
782
|
+
});
|
|
783
|
+
return health.installed;
|
|
784
|
+
}));
|
|
785
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.installBundledTools", async () => {
|
|
786
|
+
const toolsHealth = (0, runtime_1.getBundledToolsHealth)({ extensionPath: context.extensionPath });
|
|
787
|
+
if (!toolsHealth.platformKey) {
|
|
788
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: Unsupported platform ${process.platform}-${process.arch}. Cannot install bundled tools.`);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const storageUri = context.globalStorageUri;
|
|
792
|
+
if (!storageUri) {
|
|
793
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: No global storage path. Cannot install bundled tools.`);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
const outBaseDir = path.join(storageUri.fsPath, 'tools');
|
|
797
|
+
const scriptCandidates = [
|
|
798
|
+
path.join(context.extensionPath, 'out', 'scripts', 'vendor-tools.mjs'),
|
|
799
|
+
path.join(context.extensionPath, 'scripts', 'vendor-tools.mjs'),
|
|
800
|
+
];
|
|
801
|
+
const scriptPath = scriptCandidates.find((p) => {
|
|
802
|
+
try {
|
|
803
|
+
return require('fs').statSync(p).isFile();
|
|
804
|
+
}
|
|
805
|
+
catch {
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
if (!scriptPath) {
|
|
810
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: vendor-tools script not found. Run from extension source or rebuild.`);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
log(outputChannel, `[AgentIDE] Installing bundled tools (rg, sg, tree-sitter) into ${outBaseDir} ...`);
|
|
814
|
+
try {
|
|
815
|
+
const { spawn } = await import('child_process');
|
|
816
|
+
await new Promise((resolve, reject) => {
|
|
817
|
+
const child = spawn(process.execPath, [scriptPath, '--out-dir', outBaseDir, '--clean'], {
|
|
818
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
819
|
+
env: { ...process.env },
|
|
820
|
+
});
|
|
821
|
+
let stderr = '';
|
|
822
|
+
child.stdout?.on('data', (chunk) => log(outputChannel, chunk.toString()));
|
|
823
|
+
child.stderr?.on('data', (chunk) => { stderr += chunk.toString(); log(outputChannel, chunk.toString()); });
|
|
824
|
+
child.on('error', reject);
|
|
825
|
+
child.on('close', (code) => (code === 0 ? resolve() : reject(new Error(`Exit ${code}: ${stderr}`))));
|
|
826
|
+
});
|
|
827
|
+
const toolsDir = path.join(outBaseDir, toolsHealth.platformKey);
|
|
828
|
+
await context.globalState.update(BUNDLED_TOOLS_DIR_KEY, toolsDir);
|
|
829
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: Bundled tools installed to ${toolsDir}. They will be used by the agent.`);
|
|
830
|
+
}
|
|
831
|
+
catch (e) {
|
|
832
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
833
|
+
log(outputChannel, `[AgentIDE] Install bundled tools failed: ${msg}`);
|
|
834
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: Failed to install bundled tools. Check Output > Agent Hippo. ${msg}`);
|
|
835
|
+
}
|
|
836
|
+
}));
|
|
837
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.setupCli", async () => {
|
|
838
|
+
log(outputChannel, "[AgentIDE] Starting CLI setup...");
|
|
839
|
+
const cliConfig = vscode.workspace.getConfiguration("agentide.cli");
|
|
840
|
+
const configuredCliPath = cliConfig.get("path", "");
|
|
841
|
+
const installSource = cliConfig.get("installSource", "").trim();
|
|
842
|
+
if (installSource && /[;`|$&\n\r"']/.test(installSource)) {
|
|
843
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: Invalid CLI install source. Remove shell control characters from 'agentide.cli.installSource'.`);
|
|
844
|
+
return { success: false, error: "Invalid install source" };
|
|
845
|
+
}
|
|
846
|
+
const health = await (0, runtime_1.getCliHealth)({
|
|
847
|
+
configuredPath: configuredCliPath,
|
|
848
|
+
extensionPath: context.extensionPath,
|
|
849
|
+
forceRefresh: true,
|
|
850
|
+
});
|
|
851
|
+
if (health.installed && health.path) {
|
|
852
|
+
await vscode.workspace
|
|
853
|
+
.getConfiguration("agentide")
|
|
854
|
+
.update("cli.path", health.path, vscode.ConfigurationTarget.Global);
|
|
855
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: CLI is ready at ${health.path}`);
|
|
856
|
+
return { success: true, path: health.path };
|
|
857
|
+
}
|
|
858
|
+
const isWindows = process.platform === "win32";
|
|
859
|
+
const scriptName = isWindows ? "setup-cli.ps1" : "setup-cli.sh";
|
|
860
|
+
const candidates = [
|
|
861
|
+
path.join(context.extensionPath, "out", "scripts", scriptName),
|
|
862
|
+
path.join(context.extensionPath, "scripts", scriptName),
|
|
863
|
+
];
|
|
864
|
+
const scriptPath = candidates.find((p) => {
|
|
865
|
+
try {
|
|
866
|
+
require("fs").accessSync(p);
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
catch {
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
if (!scriptPath) {
|
|
874
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: CLI setup script not found. Build CLI via extensions/agentide/scripts/build-cli.sh and set agentide.cli.path.`);
|
|
875
|
+
return { success: false, error: "Script not found" };
|
|
876
|
+
}
|
|
877
|
+
const setupResult = await runCliSetup(scriptPath, outputChannel, installSource);
|
|
878
|
+
if (!setupResult.success) {
|
|
879
|
+
return setupResult;
|
|
880
|
+
}
|
|
881
|
+
const refreshed = await (0, runtime_1.getCliHealth)({
|
|
882
|
+
configuredPath: configuredCliPath,
|
|
883
|
+
extensionPath: context.extensionPath,
|
|
884
|
+
forceRefresh: true,
|
|
885
|
+
});
|
|
886
|
+
if (refreshed.installed && refreshed.path) {
|
|
887
|
+
await vscode.workspace
|
|
888
|
+
.getConfiguration("agentide")
|
|
889
|
+
.update("cli.path", refreshed.path, vscode.ConfigurationTarget.Global);
|
|
890
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: CLI configured at ${refreshed.path}`);
|
|
891
|
+
return { success: true, path: refreshed.path };
|
|
892
|
+
}
|
|
893
|
+
showWarning(`${branding_1.AGENTIDE_BRAND_NAME}: Setup launched. Re-run '${branding_1.AGENTIDE_BRAND_NAME}: CLI Status' after terminal setup completes.`);
|
|
894
|
+
return { success: true, pending: true };
|
|
895
|
+
}));
|
|
896
|
+
async function runCliSetup(scriptPath, outputChannel, installSource) {
|
|
897
|
+
const isWindows = process.platform === "win32";
|
|
898
|
+
const isUrlSource = /^https?:\/\//i.test(installSource);
|
|
899
|
+
const sourceArg = installSource
|
|
900
|
+
? isWindows
|
|
901
|
+
? `-Source \"${installSource}\"`
|
|
902
|
+
: `--source \"${installSource}\"`
|
|
903
|
+
: "";
|
|
904
|
+
const terminal = isWindows
|
|
905
|
+
? vscode.window.createTerminal({
|
|
906
|
+
name: "AgentHippo CLI Setup",
|
|
907
|
+
cwd: path.dirname(scriptPath),
|
|
908
|
+
shellPath: "powershell.exe",
|
|
909
|
+
shellArgs: [
|
|
910
|
+
"-NoProfile",
|
|
911
|
+
"-NoExit",
|
|
912
|
+
"-ExecutionPolicy",
|
|
913
|
+
"Bypass",
|
|
914
|
+
"-Command",
|
|
915
|
+
`& "${scriptPath}" ${sourceArg} -Yes; Write-Host ""; Write-Host "You can close this window."`,
|
|
916
|
+
],
|
|
917
|
+
})
|
|
918
|
+
: vscode.window.createTerminal({
|
|
919
|
+
name: "AgentHippo CLI Setup",
|
|
920
|
+
cwd: path.dirname(scriptPath),
|
|
921
|
+
shellPath: "/bin/bash",
|
|
922
|
+
shellArgs: [
|
|
923
|
+
"-c",
|
|
924
|
+
`"${scriptPath}" ${sourceArg} --yes; echo ''; echo 'Press any key to close...'; read -n 1`,
|
|
925
|
+
],
|
|
926
|
+
});
|
|
927
|
+
if (installSource) {
|
|
928
|
+
log(outputChannel, `[AgentIDE] CLI install source configured (${isUrlSource ? 'url' : 'package/path'}): ${installSource}`);
|
|
929
|
+
}
|
|
930
|
+
terminal.show();
|
|
931
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: CLI setup started. Check the terminal for progress.`);
|
|
932
|
+
log(outputChannel, "[AgentIDE] CLI setup terminal opened");
|
|
933
|
+
return { success: true };
|
|
934
|
+
}
|
|
935
|
+
// -------------------------------------------------------------------------
|
|
936
|
+
// Spotlight Setup
|
|
937
|
+
// -------------------------------------------------------------------------
|
|
938
|
+
// Install or repair Spotlight (OTEL Collector + DuckDB)
|
|
939
|
+
// Scripts are bundled with the extension for reliable access
|
|
940
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.setupAnalytics", async () => {
|
|
941
|
+
log(outputChannel, "[AgentIDE] Starting Spotlight install/repair...");
|
|
942
|
+
const isWindows = process.platform === "win32";
|
|
943
|
+
const scriptName = isWindows ? "setup-analytics.ps1" : "setup-analytics.sh";
|
|
944
|
+
const extensionPath = context.extensionPath;
|
|
945
|
+
// Try bundled location first, then dev location
|
|
946
|
+
const candidates = [
|
|
947
|
+
path.join(extensionPath, "out", "scripts", "analytics", scriptName),
|
|
948
|
+
path.join(extensionPath, "scripts", "analytics", scriptName),
|
|
949
|
+
];
|
|
950
|
+
const scriptPath = candidates.find((p) => {
|
|
951
|
+
try {
|
|
952
|
+
require("fs").accessSync(p);
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
catch {
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
if (!scriptPath) {
|
|
960
|
+
showError(`Spotlight install script not found. Please run 'scripts/analytics/${scriptName}' manually from the AgentIDE repository.`);
|
|
961
|
+
return { success: false, error: "Script not found" };
|
|
962
|
+
}
|
|
963
|
+
if (isWindows && _state?.analyticsService) {
|
|
964
|
+
return _state.analyticsService.setupWindowsSpotlight({ reinstall: false });
|
|
965
|
+
}
|
|
966
|
+
return runAnalyticsSetup(scriptPath, outputChannel);
|
|
967
|
+
}));
|
|
968
|
+
async function runAnalyticsSetup(scriptPath, outputChannel) {
|
|
969
|
+
const isWindows = process.platform === "win32";
|
|
970
|
+
const agentHomeDir = path.join(os.homedir(), branding_1.AGENTIDE_DIR_NAME);
|
|
971
|
+
const terminal = isWindows
|
|
972
|
+
? vscode.window.createTerminal({
|
|
973
|
+
name: "Spotlight Install",
|
|
974
|
+
cwd: path.dirname(scriptPath),
|
|
975
|
+
env: { AGENT_HOME_DIR: agentHomeDir },
|
|
976
|
+
shellPath: "powershell.exe",
|
|
977
|
+
shellArgs: ["-NoProfile", "-NoExit", "-ExecutionPolicy", "Bypass", "-Command",
|
|
978
|
+
`& "${scriptPath}" -Yes; Write-Host ""; Write-Host "You can close this window."`],
|
|
979
|
+
})
|
|
980
|
+
: vscode.window.createTerminal({
|
|
981
|
+
name: "Spotlight Install",
|
|
982
|
+
cwd: path.dirname(scriptPath),
|
|
983
|
+
env: { AGENT_HOME_DIR: agentHomeDir },
|
|
984
|
+
shellPath: "/bin/bash",
|
|
985
|
+
shellArgs: ["-c", `"${scriptPath}" --yes; echo ''; echo 'Press any key to close...'; read -n 1`],
|
|
986
|
+
});
|
|
987
|
+
terminal.show();
|
|
988
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: Spotlight install started. Check the terminal for progress.`);
|
|
989
|
+
log(outputChannel, "[AgentIDE] Spotlight install terminal opened");
|
|
990
|
+
return { success: true };
|
|
991
|
+
}
|
|
992
|
+
// -------------------------------------------------------------------------
|
|
993
|
+
// AgentPack Commands
|
|
994
|
+
// -------------------------------------------------------------------------
|
|
995
|
+
// Install agent pack from local folder
|
|
996
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.install", async () => {
|
|
997
|
+
const { workspaceRoot, isHomeFallback } = getWorkspaceRoot(outputChannel);
|
|
998
|
+
if (isHomeFallback) {
|
|
999
|
+
await ensureFallbackDirectoryExists(outputChannel);
|
|
1000
|
+
}
|
|
1001
|
+
const folders = await vscode.window.showOpenDialog({
|
|
1002
|
+
canSelectFolders: true,
|
|
1003
|
+
canSelectFiles: false,
|
|
1004
|
+
canSelectMany: false,
|
|
1005
|
+
openLabel: "Select Agent Pack Folder",
|
|
1006
|
+
title: "Install Agent Pack",
|
|
1007
|
+
});
|
|
1008
|
+
if (!folders || folders.length === 0) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
const sourcePath = folders[0].fsPath;
|
|
1012
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1013
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1014
|
+
try {
|
|
1015
|
+
const installed = await packManager.installFromLocal(sourcePath);
|
|
1016
|
+
showInfo(`AgentIDE: Installed pack "${installed.id}" v${installed.version}`);
|
|
1017
|
+
}
|
|
1018
|
+
catch (e) {
|
|
1019
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1020
|
+
log(outputChannel, `[AgentIDE] Pack install error: ${errorMsg}`);
|
|
1021
|
+
showError(`AgentIDE: Failed to install pack - ${errorMsg}`);
|
|
1022
|
+
}
|
|
1023
|
+
}));
|
|
1024
|
+
// List installed packs
|
|
1025
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.list", async () => {
|
|
1026
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1027
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1028
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1029
|
+
const packs = await packManager.listInstalled();
|
|
1030
|
+
if (packs.length === 0) {
|
|
1031
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agent packs installed`);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
const items = packs.map((p) => ({
|
|
1035
|
+
label: p.id,
|
|
1036
|
+
description: `v${p.version} (${p.preferredEngine})`,
|
|
1037
|
+
detail: `Status: ${p.status} | Installed: ${new Date(p.installedAt).toLocaleDateString()}`,
|
|
1038
|
+
}));
|
|
1039
|
+
const selected = await vscode.window.showQuickPick(items, {
|
|
1040
|
+
placeHolder: "Select a pack to view details",
|
|
1041
|
+
title: "Installed Agent Packs",
|
|
1042
|
+
});
|
|
1043
|
+
if (selected) {
|
|
1044
|
+
log(outputChannel, `[AgentIDE] Pack selected: ${selected.label}`);
|
|
1045
|
+
outputChannel.show();
|
|
1046
|
+
}
|
|
1047
|
+
}));
|
|
1048
|
+
// Get installed packs (data-only, no UI)
|
|
1049
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.getInstalled", async () => {
|
|
1050
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1051
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1052
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1053
|
+
try {
|
|
1054
|
+
return await packManager.listInstalled();
|
|
1055
|
+
}
|
|
1056
|
+
catch (e) {
|
|
1057
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1058
|
+
log(outputChannel, `[AgentIDE] Pack list error: ${errorMsg}`);
|
|
1059
|
+
return [];
|
|
1060
|
+
}
|
|
1061
|
+
}));
|
|
1062
|
+
// List discovered custom engines (data-only, no UI)
|
|
1063
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.customEngine.list", (args) => {
|
|
1064
|
+
const additionalEngineDir = getConfiguredAdditionalEngineDir();
|
|
1065
|
+
const explicitWorkspaceRoot = args?.workspaceRoot?.trim();
|
|
1066
|
+
const workspaceFolderRoots = (vscode.workspace.workspaceFolders ?? [])
|
|
1067
|
+
.map((folder) => folder.uri.fsPath)
|
|
1068
|
+
.filter((value) => !!value?.trim());
|
|
1069
|
+
const processCwd = process.cwd?.();
|
|
1070
|
+
const candidateRoots = Array.from(new Set([
|
|
1071
|
+
explicitWorkspaceRoot,
|
|
1072
|
+
...workspaceFolderRoots,
|
|
1073
|
+
processCwd,
|
|
1074
|
+
]
|
|
1075
|
+
.map((value) => value?.trim())
|
|
1076
|
+
.filter((value) => !!value)));
|
|
1077
|
+
const manifestsById = new Map();
|
|
1078
|
+
for (const root of candidateRoots) {
|
|
1079
|
+
try {
|
|
1080
|
+
const manifests = (0, customRegistry_1.discoverCustomEngineManifests)(root, additionalEngineDir);
|
|
1081
|
+
for (const manifest of manifests) {
|
|
1082
|
+
if (!manifestsById.has(manifest.id)) {
|
|
1083
|
+
manifestsById.set(manifest.id, {
|
|
1084
|
+
id: manifest.id,
|
|
1085
|
+
displayName: manifest.displayName || manifest.id,
|
|
1086
|
+
description: manifest.description,
|
|
1087
|
+
defaultModel: manifest.model?.defaultModel,
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
catch (e) {
|
|
1093
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1094
|
+
log(outputChannel, `[AgentIDE] Custom engine list warning for root ${root}: ${errorMsg}`);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (manifestsById.size === 0) {
|
|
1098
|
+
try {
|
|
1099
|
+
const manifests = (0, customRegistry_1.discoverCustomEngineManifests)(undefined, additionalEngineDir);
|
|
1100
|
+
for (const manifest of manifests) {
|
|
1101
|
+
manifestsById.set(manifest.id, {
|
|
1102
|
+
id: manifest.id,
|
|
1103
|
+
displayName: manifest.displayName || manifest.id,
|
|
1104
|
+
description: manifest.description,
|
|
1105
|
+
defaultModel: manifest.model?.defaultModel,
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
catch (e) {
|
|
1110
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1111
|
+
log(outputChannel, `[AgentIDE] Custom engine list error: ${errorMsg}`);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
log(outputChannel, `[AgentIDE] Custom engine list: ${manifestsById.size} discovered (${Array.from(manifestsById.keys()).join(", ") || "none"}) from roots: ${candidateRoots.join("; ") || "(home only)"}`);
|
|
1115
|
+
return Array.from(manifestsById.values());
|
|
1116
|
+
}));
|
|
1117
|
+
// Uninstall a custom engine from the default home install root
|
|
1118
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.engine.uninstall", async (args) => {
|
|
1119
|
+
const { listInstalledCustomEngines, uninstallCustomEngine, } = await import("./engines/install.js");
|
|
1120
|
+
let engineId = args?.id?.trim();
|
|
1121
|
+
let displayName = engineId;
|
|
1122
|
+
if (!engineId) {
|
|
1123
|
+
const installed = await listInstalledCustomEngines();
|
|
1124
|
+
if (installed.length === 0) {
|
|
1125
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No custom engines are installed`);
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
const selected = await vscode.window.showQuickPick(installed.map(engine => ({
|
|
1129
|
+
label: engine.displayName,
|
|
1130
|
+
description: engine.id,
|
|
1131
|
+
detail: engine.installDir,
|
|
1132
|
+
engine,
|
|
1133
|
+
})), {
|
|
1134
|
+
placeHolder: "Select a custom engine to uninstall",
|
|
1135
|
+
title: "Uninstall Custom Engine",
|
|
1136
|
+
});
|
|
1137
|
+
if (!selected) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
engineId = selected.engine.id;
|
|
1141
|
+
displayName = selected.engine.displayName;
|
|
1142
|
+
}
|
|
1143
|
+
if (!engineId) {
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
if (args?.skipConfirmation !== true) {
|
|
1147
|
+
const confirmed = await vscode.window.showWarningMessage(`Uninstall custom engine "${displayName || engineId}"?`, { modal: true }, "Uninstall", "Cancel");
|
|
1148
|
+
if (confirmed !== "Uninstall") {
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const result = await uninstallCustomEngine(engineId, { logger: outputChannel });
|
|
1153
|
+
if (!result.removed) {
|
|
1154
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: Custom engine "${result.id}" is not installed`);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
clearCustomEngineRuntimeCache(state, result.id);
|
|
1158
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
1159
|
+
invalidateLocalIndex();
|
|
1160
|
+
await refreshCustomEnginePicker(outputChannel);
|
|
1161
|
+
showInfo(`Uninstalled engine "${result.displayName || result.id}"`);
|
|
1162
|
+
}));
|
|
1163
|
+
// Publish custom engine to store (fork + PR)
|
|
1164
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.engine.publish", async () => {
|
|
1165
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1166
|
+
const { collectEngineFiles, discoverPublishableEngines, isValidPublishVersion, validateEngineForPublish, } = await import("./engines/publish.js");
|
|
1167
|
+
const { publishToStore, STORE_CONFIG, canPublishDirectlyToStore } = await import("./store/index.js");
|
|
1168
|
+
const engines = await discoverPublishableEngines(workspaceRoot);
|
|
1169
|
+
if (engines.length === 0) {
|
|
1170
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No custom engines found. Add engine.manifest.json under .agent-hippo/engines/<id>/`);
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const selected = await vscode.window.showQuickPick(engines.map(engine => ({
|
|
1174
|
+
label: engine.displayName,
|
|
1175
|
+
description: engine.id,
|
|
1176
|
+
detail: `${engine.sourceLabel}: ${engine.sourceDir}`,
|
|
1177
|
+
engine,
|
|
1178
|
+
})), {
|
|
1179
|
+
placeHolder: "Select a custom engine to publish",
|
|
1180
|
+
title: `Publish to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}`,
|
|
1181
|
+
});
|
|
1182
|
+
if (!selected) {
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
try {
|
|
1186
|
+
const validation = await validateEngineForPublish(selected.engine.sourceDir, selected.engine.id);
|
|
1187
|
+
if (!validation.valid) {
|
|
1188
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: Cannot publish - ${validation.errors.join(", ")}`);
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
if (validation.warnings.length > 0) {
|
|
1192
|
+
const proceed = await vscode.window.showWarningMessage(`Warnings: ${validation.warnings.join(", ")}`, "Publish Anyway", "Cancel");
|
|
1193
|
+
if (proceed !== "Publish Anyway") {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
const versionInput = await vscode.window.showInputBox({
|
|
1198
|
+
prompt: "Publish version (semver)",
|
|
1199
|
+
value: validation.metadata?.suggestedVersion || "1.0.0",
|
|
1200
|
+
placeHolder: "e.g., 1.0.0",
|
|
1201
|
+
validateInput: value => value && isValidPublishVersion(value.replace(/^v/, ""))
|
|
1202
|
+
? null
|
|
1203
|
+
: "Use semver format (e.g., 1.0.0)",
|
|
1204
|
+
});
|
|
1205
|
+
if (!versionInput) {
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
const version = versionInput.replace(/^v/, "");
|
|
1209
|
+
const changelog = await vscode.window.showInputBox({
|
|
1210
|
+
prompt: "What changed in this version? (optional)",
|
|
1211
|
+
placeHolder: "Initial release, bug fixes...",
|
|
1212
|
+
});
|
|
1213
|
+
const files = await collectEngineFiles(selected.engine.sourceDir);
|
|
1214
|
+
const publishDirect = await canPublishDirectlyToStore();
|
|
1215
|
+
const confirm = await vscode.window.showWarningMessage(publishDirect
|
|
1216
|
+
? `Publish "${selected.engine.id}" v${version} to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}?\n\nThis will open a pull request on the store repository.`
|
|
1217
|
+
: `Submit "${selected.engine.id}" v${version} to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}?\n\nThis will create a pull request from your fork.`, { modal: true }, "Submit PR");
|
|
1218
|
+
if (confirm !== "Submit PR") {
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
const result = await vscode.window.withProgress({
|
|
1222
|
+
location: vscode.ProgressLocation.Window,
|
|
1223
|
+
title: `Publishing engine ${selected.engine.id} v${version}`,
|
|
1224
|
+
cancellable: false,
|
|
1225
|
+
}, async (progress) => {
|
|
1226
|
+
progress.report({
|
|
1227
|
+
message: publishDirect
|
|
1228
|
+
? `Publishing to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}...`
|
|
1229
|
+
: "Preparing fork...",
|
|
1230
|
+
});
|
|
1231
|
+
const res = await publishToStore({
|
|
1232
|
+
type: "engine",
|
|
1233
|
+
slug: selected.engine.id,
|
|
1234
|
+
version,
|
|
1235
|
+
files,
|
|
1236
|
+
changelog,
|
|
1237
|
+
}, outputChannel);
|
|
1238
|
+
progress.report({ message: "Creating PR..." });
|
|
1239
|
+
return res;
|
|
1240
|
+
});
|
|
1241
|
+
const viewAction = await vscode.window.showInformationMessage(`Published engine "${selected.engine.id}" v${version}! PR created.`, "View PR");
|
|
1242
|
+
if (viewAction === "View PR") {
|
|
1243
|
+
vscode.env.openExternal(vscode.Uri.parse(result.prUrl));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
catch (e) {
|
|
1247
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1248
|
+
log(outputChannel, `[AgentIDE] Engine publish error: ${errorMsg}`);
|
|
1249
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: ${errorMsg}`);
|
|
1250
|
+
}
|
|
1251
|
+
}));
|
|
1252
|
+
// Uninstall agent pack
|
|
1253
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.uninstall", async () => {
|
|
1254
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1255
|
+
const { AgentPackManager, isDefaultAgent } = await import("./agentpack/index.js");
|
|
1256
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1257
|
+
const packs = await packManager.listInstalled();
|
|
1258
|
+
// Filter out the default agent - it cannot be uninstalled
|
|
1259
|
+
const uninstallablePacks = packs.filter((p) => !isDefaultAgent(p.id));
|
|
1260
|
+
if (uninstallablePacks.length === 0) {
|
|
1261
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agent packs available to uninstall`);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
const items = uninstallablePacks.map((p) => ({
|
|
1265
|
+
label: p.id,
|
|
1266
|
+
description: `v${p.version}${state.activePackId === p.id ? " (active)" : ""}`,
|
|
1267
|
+
}));
|
|
1268
|
+
const selected = await vscode.window.showQuickPick(items, {
|
|
1269
|
+
placeHolder: "Select a pack to uninstall",
|
|
1270
|
+
title: "Uninstall Agent Pack",
|
|
1271
|
+
});
|
|
1272
|
+
if (!selected) {
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
const packIdToUninstall = selected.label;
|
|
1276
|
+
const wasActive = state.activePackId === packIdToUninstall;
|
|
1277
|
+
const confirm = await vscode.window.showWarningMessage(`Uninstall agent pack "${packIdToUninstall}"?${wasActive ? " This will switch to the default agent." : ""}`, { modal: true }, "Uninstall", "Cancel");
|
|
1278
|
+
if (confirm !== "Uninstall") {
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
try {
|
|
1282
|
+
await packManager.uninstall(packIdToUninstall);
|
|
1283
|
+
// If uninstalling the active pack, switch to default agent
|
|
1284
|
+
if (wasActive) {
|
|
1285
|
+
const appliedPackId = await syncService.switchToPack(workspaceRoot, undefined, // Switch to default
|
|
1286
|
+
outputChannel, { importDerivedSkills: true });
|
|
1287
|
+
state.activePackId = appliedPackId;
|
|
1288
|
+
syncService.setActivePackId(workspaceRoot, appliedPackId);
|
|
1289
|
+
log(outputChannel, `[AgentIDE] Switched to default agent after uninstalling active pack`);
|
|
1290
|
+
// Notify workbench to update its pack state
|
|
1291
|
+
try {
|
|
1292
|
+
await vscode.commands.executeCommand("agentide.applyPackPreferences", {
|
|
1293
|
+
packId: "default",
|
|
1294
|
+
silent: true,
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
catch {
|
|
1298
|
+
// Workbench command may not be available
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
showInfo(`AgentIDE: Uninstalled pack "${packIdToUninstall}"${wasActive ? " - switched to default agent" : ""}`);
|
|
1302
|
+
}
|
|
1303
|
+
catch (e) {
|
|
1304
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1305
|
+
log(outputChannel, `[AgentIDE] Pack uninstall error: ${errorMsg}`);
|
|
1306
|
+
showError(`AgentIDE: Failed to uninstall pack - ${errorMsg}`);
|
|
1307
|
+
}
|
|
1308
|
+
}));
|
|
1309
|
+
// Set active pack (for next request) - syncs pack content to workspace .claude/.codex
|
|
1310
|
+
// NOTE: This is an INTERNAL command (not in package.json contributions).
|
|
1311
|
+
// It only handles file syncing. Mode/model switching is done via agentide.applyPackPreferences
|
|
1312
|
+
// on the workbench side. For interactive UI, use workbench.action.chat.openAgentPackPicker.
|
|
1313
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.setActive", async (args) => {
|
|
1314
|
+
if (!args?.packId) {
|
|
1315
|
+
throw new Error("packId is required. Use workbench.action.chat.openAgentPackPicker for interactive selection.");
|
|
1316
|
+
}
|
|
1317
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1318
|
+
// Switch pack and sync derived dirs
|
|
1319
|
+
const packId = args.packId === "default" ? undefined : args.packId;
|
|
1320
|
+
const appliedPackId = await syncService.switchToPack(workspaceRoot, packId, outputChannel, { importDerivedSkills: true });
|
|
1321
|
+
state.activePackId = appliedPackId;
|
|
1322
|
+
// Track active pack in SyncService for file-watcher awareness
|
|
1323
|
+
syncService.setActivePackId(workspaceRoot, appliedPackId);
|
|
1324
|
+
log(outputChannel, `[AgentIDE] Active pack switched to: ${appliedPackId ?? "default"}`);
|
|
1325
|
+
await state.remotePackStatusBar?.refresh({ notifyOnActivate: true });
|
|
1326
|
+
// Note: Pack ID is now persisted by the workbench (IAgentPackService)
|
|
1327
|
+
// The extension just handles file sync operations
|
|
1328
|
+
return { activePackId: state.activePackId ?? "default" };
|
|
1329
|
+
}));
|
|
1330
|
+
// Get active pack ID
|
|
1331
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.getActive", () => {
|
|
1332
|
+
return { activePackId: state.activePackId ?? "default" };
|
|
1333
|
+
}));
|
|
1334
|
+
// Remote pack URL for the active (or specified) pack — used by the workbench to bypass
|
|
1335
|
+
// local engine credential resolution when spec.remote.url is set.
|
|
1336
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.getRemoteServeUrl", async (args) => {
|
|
1337
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1338
|
+
const packId = args?.packId?.trim()
|
|
1339
|
+
|| syncService.getActivePackId(workspaceRoot)
|
|
1340
|
+
|| state.activePackId;
|
|
1341
|
+
if (!packId || packId === 'default') {
|
|
1342
|
+
return undefined;
|
|
1343
|
+
}
|
|
1344
|
+
const manifest = await syncService.getActiveAgentManifest(workspaceRoot, outputChannel, packId);
|
|
1345
|
+
const remoteUrl = (0, serveClient_js_1.getRemoteServeUrl)(manifest);
|
|
1346
|
+
if (!remoteUrl) {
|
|
1347
|
+
return undefined;
|
|
1348
|
+
}
|
|
1349
|
+
return {
|
|
1350
|
+
packId,
|
|
1351
|
+
remoteUrl,
|
|
1352
|
+
preferredEngine: manifest?.spec?.engine,
|
|
1353
|
+
};
|
|
1354
|
+
}));
|
|
1355
|
+
// Create a new agent pack scaffold
|
|
1356
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.create", async () => {
|
|
1357
|
+
const { workspaceRoot, isHomeFallback } = getWorkspaceRoot(outputChannel);
|
|
1358
|
+
if (isHomeFallback) {
|
|
1359
|
+
await ensureFallbackDirectoryExists(outputChannel);
|
|
1360
|
+
}
|
|
1361
|
+
// Get current chat state to capture current model (best effort)
|
|
1362
|
+
// We use modelId (e.g., 'claude-sonnet-4-20250514', 'litellm::gpt-nano') for reliable matching
|
|
1363
|
+
let currentModelId;
|
|
1364
|
+
try {
|
|
1365
|
+
const chatState = await vscode.commands.executeCommand("agentide.getChatState");
|
|
1366
|
+
currentModelId = chatState?.modelId;
|
|
1367
|
+
log(outputChannel, `[AgentIDE] Current chat state: mode=${chatState?.mode}, modelId=${currentModelId}, modelName=${chatState?.modelName}`);
|
|
1368
|
+
}
|
|
1369
|
+
catch {
|
|
1370
|
+
// Command may not be available yet
|
|
1371
|
+
}
|
|
1372
|
+
// Prompt for pack name with inline validation (including "already exists" check)
|
|
1373
|
+
const rawPackName = await vscode.window.showInputBox({
|
|
1374
|
+
prompt: "Enter the agent pack name",
|
|
1375
|
+
placeHolder: "e.g., code-reviewer, security-auditor, My Code Reviewer",
|
|
1376
|
+
validateInput: async (input) => {
|
|
1377
|
+
const normalized = (0, paths_1.normalizePackName)(input);
|
|
1378
|
+
// Check for invalid name first
|
|
1379
|
+
const nameError = (0, paths_1.getPackNameError)(normalized);
|
|
1380
|
+
if (nameError) {
|
|
1381
|
+
return nameError;
|
|
1382
|
+
}
|
|
1383
|
+
// Check if pack already exists
|
|
1384
|
+
const existingPackRoot = path.join((0, paths_1.getAgentideDir)(workspaceRoot), paths_1.AGENT_CONSTANTS.AGENTS_DIR, normalized);
|
|
1385
|
+
if (await (0, utils_1.pathExists)(existingPackRoot)) {
|
|
1386
|
+
return `A pack named "${normalized}" already exists. Choose a different name.`;
|
|
1387
|
+
}
|
|
1388
|
+
return undefined;
|
|
1389
|
+
},
|
|
1390
|
+
});
|
|
1391
|
+
if (!rawPackName) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
// Normalize the pack name (lowercase, hyphens, no special chars)
|
|
1395
|
+
const packName = (0, paths_1.normalizePackName)(rawPackName);
|
|
1396
|
+
log(outputChannel, `[AgentIDE] Pack name normalized: "${rawPackName}" -> "${packName}"`);
|
|
1397
|
+
const packRoot = path.join((0, paths_1.getAgentideDir)(workspaceRoot), paths_1.AGENT_CONSTANTS.AGENTS_DIR, packName);
|
|
1398
|
+
// Prompt for description
|
|
1399
|
+
const description = await vscode.window.showInputBox({
|
|
1400
|
+
prompt: "Enter a short description for the pack",
|
|
1401
|
+
placeHolder: "e.g., Advanced code review agent with security analysis",
|
|
1402
|
+
});
|
|
1403
|
+
// Prompt for preferred engine
|
|
1404
|
+
const engineChoice = await vscode.window.showQuickPick([
|
|
1405
|
+
{
|
|
1406
|
+
label: "Claude",
|
|
1407
|
+
description: "Anthropic Claude Agent SDK",
|
|
1408
|
+
engine: "claude",
|
|
1409
|
+
},
|
|
1410
|
+
{ label: "Codex", description: "OpenAI Codex SDK", engine: "codex" },
|
|
1411
|
+
], {
|
|
1412
|
+
placeHolder: "Select the preferred engine for this pack",
|
|
1413
|
+
title: "Preferred Engine",
|
|
1414
|
+
});
|
|
1415
|
+
if (!engineChoice) {
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
try {
|
|
1419
|
+
await fs_1.promises.mkdir(path.join(packRoot, "rules"), { recursive: true });
|
|
1420
|
+
await fs_1.promises.mkdir(path.join(packRoot, "skills"), { recursive: true });
|
|
1421
|
+
await fs_1.promises.mkdir(path.join(packRoot, "mcp"), { recursive: true });
|
|
1422
|
+
// Create agent.yaml manifest using centralized template
|
|
1423
|
+
// Use current model if available, otherwise let the template use the default
|
|
1424
|
+
const manifest = (0, paths_1.generateAgentYaml)(packName, {
|
|
1425
|
+
description: description || undefined,
|
|
1426
|
+
engine: engineChoice.engine,
|
|
1427
|
+
model: currentModelId,
|
|
1428
|
+
});
|
|
1429
|
+
await fs_1.promises.writeFile(path.join(packRoot, "agent.yaml"), manifest);
|
|
1430
|
+
// Create AGENTS.md using centralized template
|
|
1431
|
+
const agentsMd = (0, paths_1.generateAgentsMd)(packName, {
|
|
1432
|
+
description: description || undefined,
|
|
1433
|
+
});
|
|
1434
|
+
await fs_1.promises.writeFile(path.join(packRoot, "AGENTS.md"), agentsMd);
|
|
1435
|
+
// Note: We don't sync pack-internal derived dirs (.codex/.claude) here.
|
|
1436
|
+
// Those folders should only exist at workspace root level, not inside packs.
|
|
1437
|
+
// The pack's content will be synced to workspace root when it's activated.
|
|
1438
|
+
// Register the pack in the manifest
|
|
1439
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1440
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1441
|
+
await packManager.installFromLocal(packRoot);
|
|
1442
|
+
log(outputChannel, `[AgentIDE] Created agent pack scaffold: ${packName}`);
|
|
1443
|
+
showInfo(`AgentIDE: Created agent pack "${packName}" at ${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/${paths_1.AGENT_CONSTANTS.AGENTS_DIR}/${packName}/`);
|
|
1444
|
+
// Open the AGENTS.md file
|
|
1445
|
+
const agentsMdUri = vscode.Uri.file(path.join(packRoot, "AGENTS.md"));
|
|
1446
|
+
await vscode.window.showTextDocument(agentsMdUri);
|
|
1447
|
+
// Offer agent-assisted configuration
|
|
1448
|
+
const choice = await vscode.window.showInformationMessage(`Agent pack "${packName}" created. Would you like help generating a specialized configuration?`, "Yes, help me configure it", "No, I'll edit manually");
|
|
1449
|
+
if (choice === "Yes, help me configure it") {
|
|
1450
|
+
// Build a prompt that leverages the agentpack-creator skill
|
|
1451
|
+
const configureQuery = [
|
|
1452
|
+
`I just created a new agent pack called "${packName}"`,
|
|
1453
|
+
description ? ` that should: ${description}.` : ".",
|
|
1454
|
+
"\n\nPlease help me write a proper AGENTS.md file for this agent. ",
|
|
1455
|
+
"Ask me clarifying questions about:\n",
|
|
1456
|
+
"1. What specific tasks this agent should excel at\n",
|
|
1457
|
+
"2. What domain expertise it should have\n",
|
|
1458
|
+
"3. What constraints or limitations it should follow\n",
|
|
1459
|
+
"4. How it should format its outputs\n\n",
|
|
1460
|
+
`The AGENTS.md file is at: ${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/agents/${packName}/AGENTS.md`,
|
|
1461
|
+
].join("");
|
|
1462
|
+
// Open chat with the query - attach the AGENTS.md file for context
|
|
1463
|
+
await vscode.commands.executeCommand("workbench.action.chat.open", {
|
|
1464
|
+
query: configureQuery,
|
|
1465
|
+
isPartialQuery: false,
|
|
1466
|
+
mode: "agent",
|
|
1467
|
+
attachFiles: [agentsMdUri],
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
catch (e) {
|
|
1472
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1473
|
+
log(outputChannel, `[AgentIDE] Pack create error: ${errorMsg}`);
|
|
1474
|
+
showError(`AgentIDE: Failed to create pack - ${errorMsg}`);
|
|
1475
|
+
}
|
|
1476
|
+
}));
|
|
1477
|
+
// -------------------------------------------------------------------------
|
|
1478
|
+
// Agent Stores Commands (UAL + Hydration)
|
|
1479
|
+
// -------------------------------------------------------------------------
|
|
1480
|
+
// Share agent to User Library
|
|
1481
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.share", async () => {
|
|
1482
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1483
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1484
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1485
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
1486
|
+
// Filter out default agent - can't share it
|
|
1487
|
+
const shareable = packs.filter((p) => p.id !== "default");
|
|
1488
|
+
if (shareable.length === 0) {
|
|
1489
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agents to share (create an agent first)`);
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
const items = shareable.map((p) => ({
|
|
1493
|
+
label: p.id,
|
|
1494
|
+
description: `v${p.version}`,
|
|
1495
|
+
}));
|
|
1496
|
+
const selected = await vscode.window.showQuickPick(items, {
|
|
1497
|
+
placeHolder: "Select an agent to share to User Library",
|
|
1498
|
+
title: "Share Agent to User Library",
|
|
1499
|
+
});
|
|
1500
|
+
if (!selected) {
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
try {
|
|
1504
|
+
const version = await packManager.shareToUserLibrary(selected.label);
|
|
1505
|
+
showInfo(`AgentIDE: Shared "${selected.label}" v${version} to User Library`);
|
|
1506
|
+
}
|
|
1507
|
+
catch (e) {
|
|
1508
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1509
|
+
log(outputChannel, `[AgentIDE] Share error: ${errorMsg}`);
|
|
1510
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
1511
|
+
}
|
|
1512
|
+
}));
|
|
1513
|
+
// Share skill to User Library
|
|
1514
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.skill.share", async () => {
|
|
1515
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1516
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1517
|
+
const { getAgentSkillsDir, getUserSkillDir, } = await import("./agentpack/paths.js");
|
|
1518
|
+
const { copyDirRecursive, pathExists } = await import("./utils.js");
|
|
1519
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1520
|
+
// Get installed packs
|
|
1521
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
1522
|
+
if (packs.length === 0) {
|
|
1523
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agents found`);
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
// Let user pick a pack
|
|
1527
|
+
const packPick = await vscode.window.showQuickPick(packs.map((p) => ({ label: p.id, description: `v${p.version}` })), {
|
|
1528
|
+
placeHolder: "Select agent containing the skill",
|
|
1529
|
+
title: "Save Skill to User Library",
|
|
1530
|
+
});
|
|
1531
|
+
if (!packPick) {
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
// List skills in that pack
|
|
1535
|
+
const skillsDir = getAgentSkillsDir(workspaceRoot, packPick.label);
|
|
1536
|
+
const skillsDirExists = await pathExists(skillsDir);
|
|
1537
|
+
if (!skillsDirExists) {
|
|
1538
|
+
showInfo(`AgentIDE: No skills found in ${packPick.label}`);
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const skillEntries = await fs_1.promises.readdir(skillsDir, { withFileTypes: true });
|
|
1542
|
+
const skillDirs = skillEntries
|
|
1543
|
+
.filter((e) => e.isDirectory() && !e.name.startsWith("."))
|
|
1544
|
+
.map((e) => e.name);
|
|
1545
|
+
if (skillDirs.length === 0) {
|
|
1546
|
+
showInfo(`AgentIDE: No skills found in ${packPick.label}`);
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
const skillPick = await vscode.window.showQuickPick(skillDirs.map((s) => ({ label: s })), {
|
|
1550
|
+
placeHolder: "Select skill to save to User Library",
|
|
1551
|
+
title: "Save Skill to User Library",
|
|
1552
|
+
});
|
|
1553
|
+
if (!skillPick) {
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
const sourceDir = path.join(skillsDir, skillPick.label);
|
|
1557
|
+
const targetDir = getUserSkillDir(skillPick.label);
|
|
1558
|
+
// Check if skill already exists in library
|
|
1559
|
+
if (await pathExists(targetDir)) {
|
|
1560
|
+
const overwrite = await vscode.window.showWarningMessage(`Skill "${skillPick.label}" already exists in User Library. Overwrite?`, { modal: true }, "Overwrite", "Cancel");
|
|
1561
|
+
if (overwrite !== "Overwrite") {
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
await fs_1.promises.rm(targetDir, { recursive: true, force: true });
|
|
1565
|
+
}
|
|
1566
|
+
try {
|
|
1567
|
+
await copyDirRecursive(sourceDir, targetDir);
|
|
1568
|
+
// Register in local registry
|
|
1569
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
1570
|
+
const registry = getRegistry(outputChannel);
|
|
1571
|
+
await registry.registerSkill({
|
|
1572
|
+
slug: skillPick.label,
|
|
1573
|
+
displayName: skillPick.label,
|
|
1574
|
+
latestVersion: "local",
|
|
1575
|
+
tags: [],
|
|
1576
|
+
stats: { installs: 1 },
|
|
1577
|
+
});
|
|
1578
|
+
// Invalidate local index cache
|
|
1579
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
1580
|
+
invalidateLocalIndex();
|
|
1581
|
+
showInfo(`AgentIDE: Saved skill "${skillPick.label}" to User Library`);
|
|
1582
|
+
}
|
|
1583
|
+
catch (e) {
|
|
1584
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1585
|
+
log(outputChannel, `[AgentIDE] Share skill error: ${errorMsg}`);
|
|
1586
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
1587
|
+
}
|
|
1588
|
+
}));
|
|
1589
|
+
// Share MCP to User Library
|
|
1590
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.mcp.share", async () => {
|
|
1591
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1592
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1593
|
+
const { getAgentMcpDir, getUserMcpServerDir, } = await import("./agentpack/paths.js");
|
|
1594
|
+
const { copyDirRecursive, pathExists } = await import("./utils.js");
|
|
1595
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1596
|
+
// Get installed packs
|
|
1597
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
1598
|
+
if (packs.length === 0) {
|
|
1599
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agents found`);
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
// Let user pick a pack
|
|
1603
|
+
const packPick = await vscode.window.showQuickPick(packs.map((p) => ({ label: p.id, description: `v${p.version}` })), {
|
|
1604
|
+
placeHolder: "Select agent containing the MCP server",
|
|
1605
|
+
title: "Save MCP Server to User Library",
|
|
1606
|
+
});
|
|
1607
|
+
if (!packPick) {
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
// Read .mcp.json to get configured MCP servers
|
|
1611
|
+
const mcpDir = getAgentMcpDir(workspaceRoot, packPick.label);
|
|
1612
|
+
const mcpJsonPath = path.join(mcpDir, ".mcp.json");
|
|
1613
|
+
let mcpConfig = {
|
|
1614
|
+
mcpServers: {},
|
|
1615
|
+
};
|
|
1616
|
+
try {
|
|
1617
|
+
const content = await fs_1.promises.readFile(mcpJsonPath, "utf-8");
|
|
1618
|
+
mcpConfig = JSON.parse(content);
|
|
1619
|
+
}
|
|
1620
|
+
catch {
|
|
1621
|
+
showInfo(`AgentIDE: No MCP servers configured in ${packPick.label}`);
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
if (!mcpConfig.mcpServers ||
|
|
1625
|
+
Object.keys(mcpConfig.mcpServers).length === 0) {
|
|
1626
|
+
showInfo(`AgentIDE: No MCP servers configured in ${packPick.label}`);
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
const mcpNames = Object.keys(mcpConfig.mcpServers);
|
|
1630
|
+
const mcpPick = await vscode.window.showQuickPick(mcpNames.map((m) => ({ label: m })), {
|
|
1631
|
+
placeHolder: "Select MCP server to save to User Library",
|
|
1632
|
+
title: "Save MCP Server to User Library",
|
|
1633
|
+
});
|
|
1634
|
+
if (!mcpPick) {
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const targetDir = getUserMcpServerDir(mcpPick.label);
|
|
1638
|
+
// Check if MCP already exists in library
|
|
1639
|
+
if (await pathExists(targetDir)) {
|
|
1640
|
+
const overwrite = await vscode.window.showWarningMessage(`MCP "${mcpPick.label}" already exists in User Library. Overwrite?`, { modal: true }, "Overwrite", "Cancel");
|
|
1641
|
+
if (overwrite !== "Overwrite") {
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
await fs_1.promises.rm(targetDir, { recursive: true, force: true });
|
|
1645
|
+
}
|
|
1646
|
+
try {
|
|
1647
|
+
await fs_1.promises.mkdir(targetDir, { recursive: true });
|
|
1648
|
+
// Save the MCP config as mcp.json
|
|
1649
|
+
const mcpServerConfig = mcpConfig.mcpServers[mcpPick.label];
|
|
1650
|
+
await fs_1.promises.writeFile(path.join(targetDir, "mcp.json"), JSON.stringify({
|
|
1651
|
+
name: mcpPick.label,
|
|
1652
|
+
...mcpServerConfig,
|
|
1653
|
+
}, null, 2));
|
|
1654
|
+
// Copy any additional files from the MCP subdirectory if it exists
|
|
1655
|
+
const mcpSubDir = path.join(mcpDir, mcpPick.label);
|
|
1656
|
+
if (await pathExists(mcpSubDir)) {
|
|
1657
|
+
await copyDirRecursive(mcpSubDir, targetDir);
|
|
1658
|
+
}
|
|
1659
|
+
// Register in local registry
|
|
1660
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
1661
|
+
const registry = getRegistry(outputChannel);
|
|
1662
|
+
await registry.registerMcp({
|
|
1663
|
+
slug: mcpPick.label,
|
|
1664
|
+
displayName: mcpPick.label,
|
|
1665
|
+
transport: mcpServerConfig.transport || "stdio",
|
|
1666
|
+
latestVersion: "local",
|
|
1667
|
+
tags: [],
|
|
1668
|
+
stats: { installs: 1 },
|
|
1669
|
+
});
|
|
1670
|
+
// Invalidate local index cache
|
|
1671
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
1672
|
+
invalidateLocalIndex();
|
|
1673
|
+
showInfo(`AgentIDE: Saved MCP "${mcpPick.label}" to User Library`);
|
|
1674
|
+
}
|
|
1675
|
+
catch (e) {
|
|
1676
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1677
|
+
log(outputChannel, `[AgentIDE] Share MCP error: ${errorMsg}`);
|
|
1678
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
1679
|
+
}
|
|
1680
|
+
}));
|
|
1681
|
+
// Publish agent to store (fork → PR workflow)
|
|
1682
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.publish", async () => {
|
|
1683
|
+
await (0, githubStoreGate_js_1.ensureGitHubStoreAccess)(context);
|
|
1684
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1685
|
+
const { AgentPackManager, validateForPublish } = await import("./agentpack/index.js");
|
|
1686
|
+
const { publishToStore, STORE_CONFIG } = await import("./store/index.js");
|
|
1687
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1688
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
1689
|
+
const publishable = packs.filter((p) => p.id !== "default");
|
|
1690
|
+
if (publishable.length === 0) {
|
|
1691
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agents to publish (create an agent first)`);
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
// Select pack
|
|
1695
|
+
const selectedPack = await vscode.window.showQuickPick(publishable.map((p) => ({
|
|
1696
|
+
label: p.id,
|
|
1697
|
+
description: `v${p.version}`,
|
|
1698
|
+
})), {
|
|
1699
|
+
placeHolder: "Select an agent pack to publish",
|
|
1700
|
+
title: `Publish to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}`,
|
|
1701
|
+
});
|
|
1702
|
+
if (!selectedPack) {
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
// Validate before publishing
|
|
1706
|
+
const validation = await validateForPublish(workspaceRoot, selectedPack.label);
|
|
1707
|
+
if (!validation.valid) {
|
|
1708
|
+
showError(`AgentIDE: Cannot publish - ${validation.errors.join(", ")}`);
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
if (validation.warnings.length > 0) {
|
|
1712
|
+
const proceed = await vscode.window.showWarningMessage(`Warnings: ${validation.warnings.join(", ")}`, "Publish Anyway", "Cancel");
|
|
1713
|
+
if (proceed !== "Publish Anyway") {
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
// Changelog
|
|
1718
|
+
const changelog = await vscode.window.showInputBox({
|
|
1719
|
+
prompt: "What changed in this version? (optional)",
|
|
1720
|
+
placeHolder: "Added new features, fixed bugs...",
|
|
1721
|
+
});
|
|
1722
|
+
// Collect files
|
|
1723
|
+
const { getAgentRoot } = await import("./agentpack/paths.js");
|
|
1724
|
+
const agentRoot = getAgentRoot(workspaceRoot, selectedPack.label);
|
|
1725
|
+
const files = [];
|
|
1726
|
+
async function collectFiles(dir, prefix) {
|
|
1727
|
+
const entries = await fs_1.promises.readdir(dir);
|
|
1728
|
+
for (const entry of entries) {
|
|
1729
|
+
if (entry.startsWith(".")) {
|
|
1730
|
+
continue;
|
|
1731
|
+
}
|
|
1732
|
+
const fullPath = path.join(dir, entry);
|
|
1733
|
+
const relativePath = prefix ? `${prefix}/${entry}` : entry;
|
|
1734
|
+
const stat = await fs_1.promises.stat(fullPath);
|
|
1735
|
+
if (stat.isDirectory()) {
|
|
1736
|
+
await collectFiles(fullPath, relativePath);
|
|
1737
|
+
}
|
|
1738
|
+
else {
|
|
1739
|
+
const content = await fs_1.promises.readFile(fullPath, "utf-8");
|
|
1740
|
+
files.push({ path: relativePath, content });
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
await collectFiles(agentRoot, "");
|
|
1745
|
+
const pack = publishable.find((p) => p.id === selectedPack.label);
|
|
1746
|
+
// Confirm
|
|
1747
|
+
const confirm = await vscode.window.showWarningMessage(`Submit "${pack.id}" v${pack.version} to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}?\n\nThis will create a pull request.`, { modal: true }, "Submit PR");
|
|
1748
|
+
if (confirm !== "Submit PR") {
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
try {
|
|
1752
|
+
const result = await vscode.window.withProgress({
|
|
1753
|
+
location: vscode.ProgressLocation.Window,
|
|
1754
|
+
title: `Publishing ${pack.id} v${pack.version}`,
|
|
1755
|
+
cancellable: false,
|
|
1756
|
+
}, async (progress) => {
|
|
1757
|
+
progress.report({ message: "Preparing fork..." });
|
|
1758
|
+
const res = await publishToStore({
|
|
1759
|
+
type: "pack",
|
|
1760
|
+
slug: pack.id,
|
|
1761
|
+
version: pack.version,
|
|
1762
|
+
files,
|
|
1763
|
+
changelog,
|
|
1764
|
+
}, outputChannel);
|
|
1765
|
+
progress.report({ message: "Creating PR..." });
|
|
1766
|
+
return res;
|
|
1767
|
+
});
|
|
1768
|
+
const viewAction = await vscode.window.showInformationMessage(`Created PR #${result.prNumber} for ${pack.id} v${pack.version}`, "View PR");
|
|
1769
|
+
if (viewAction === "View PR") {
|
|
1770
|
+
vscode.env.openExternal(vscode.Uri.parse(result.prUrl));
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
catch (e) {
|
|
1774
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1775
|
+
log(outputChannel, `[AgentIDE] Publish error: ${errorMsg}`);
|
|
1776
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
1777
|
+
}
|
|
1778
|
+
}));
|
|
1779
|
+
// Install agent from GitHub
|
|
1780
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.installFromGitHub", async (sourceArg) => {
|
|
1781
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1782
|
+
const { installFromGitHub } = await import("./agentpack/index.js");
|
|
1783
|
+
// Get source from arg or prompt
|
|
1784
|
+
let source = sourceArg;
|
|
1785
|
+
if (!source) {
|
|
1786
|
+
source = await vscode.window.showInputBox({
|
|
1787
|
+
prompt: "Enter GitHub repository URL or owner/repo",
|
|
1788
|
+
placeHolder: "e.g., user/my-agent-pack or github://user/pack@v1.0.0",
|
|
1789
|
+
validateInput: (value) => {
|
|
1790
|
+
if (!value.trim()) {
|
|
1791
|
+
return "Please enter a repository";
|
|
1792
|
+
}
|
|
1793
|
+
if (!value.includes("/")) {
|
|
1794
|
+
return "Expected format: owner/repo or github://owner/repo@version";
|
|
1795
|
+
}
|
|
1796
|
+
return null;
|
|
1797
|
+
},
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
if (!source) {
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
try {
|
|
1804
|
+
const result = await vscode.window.withProgress({
|
|
1805
|
+
location: vscode.ProgressLocation.Window,
|
|
1806
|
+
title: "Installing from GitHub",
|
|
1807
|
+
cancellable: false,
|
|
1808
|
+
}, async (progress) => {
|
|
1809
|
+
progress.report({ message: "Downloading..." });
|
|
1810
|
+
return await installFromGitHub(workspaceRoot, {
|
|
1811
|
+
source,
|
|
1812
|
+
force: false,
|
|
1813
|
+
}, outputChannel);
|
|
1814
|
+
});
|
|
1815
|
+
// Refresh pack list
|
|
1816
|
+
await vscode.commands.executeCommand("agentide.packsChanged");
|
|
1817
|
+
await syncService.seedAgentDataIfNeeded(workspaceRoot, result.agentId, outputChannel);
|
|
1818
|
+
const activateAction = await vscode.window.showInformationMessage(`Installed ${result.agentId} ${result.version}!`, "Activate");
|
|
1819
|
+
if (activateAction === "Activate") {
|
|
1820
|
+
await vscode.commands.executeCommand("agentide.pack.switch", result.agentId);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
catch (e) {
|
|
1824
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1825
|
+
// Check if it's "already exists" error
|
|
1826
|
+
if (errorMsg.includes("already exists")) {
|
|
1827
|
+
const overwrite = await vscode.window.showWarningMessage(errorMsg, "Overwrite", "Cancel");
|
|
1828
|
+
if (overwrite === "Overwrite") {
|
|
1829
|
+
try {
|
|
1830
|
+
const result = await vscode.window.withProgress({
|
|
1831
|
+
location: vscode.ProgressLocation.Window,
|
|
1832
|
+
title: "Installing from GitHub",
|
|
1833
|
+
cancellable: false,
|
|
1834
|
+
}, async (progress) => {
|
|
1835
|
+
progress.report({ message: "Downloading..." });
|
|
1836
|
+
return await installFromGitHub(workspaceRoot, {
|
|
1837
|
+
source,
|
|
1838
|
+
force: true,
|
|
1839
|
+
}, outputChannel);
|
|
1840
|
+
});
|
|
1841
|
+
await vscode.commands.executeCommand("agentide.packsChanged");
|
|
1842
|
+
await syncService.seedAgentDataIfNeeded(workspaceRoot, result.agentId, outputChannel);
|
|
1843
|
+
showInfo(`AgentIDE: Installed ${result.agentId} ${result.version}`);
|
|
1844
|
+
}
|
|
1845
|
+
catch (e2) {
|
|
1846
|
+
const errorMsg2 = e2 instanceof Error ? e2.message : String(e2);
|
|
1847
|
+
showError(`AgentIDE: ${errorMsg2}`);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
else {
|
|
1852
|
+
log(outputChannel, `[AgentIDE] Install error: ${errorMsg}`);
|
|
1853
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}));
|
|
1857
|
+
// Browse User Library
|
|
1858
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.browseLibrary", async () => {
|
|
1859
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1860
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
1861
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
1862
|
+
const agents = await packManager.listUserLibrary();
|
|
1863
|
+
if (agents.length === 0) {
|
|
1864
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: User Library is empty. Share agents with "${branding_1.AGENTIDE_BRAND_NAME}: Share Agent to User Library"`);
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
const items = agents.map((a) => ({
|
|
1868
|
+
label: a.id,
|
|
1869
|
+
description: a.currentVersion
|
|
1870
|
+
? `v${a.currentVersion}`
|
|
1871
|
+
: `${a.versions.length} version(s)`,
|
|
1872
|
+
detail: a.description ||
|
|
1873
|
+
`Preferred engine: ${a.preferredEngine || "unknown"}`,
|
|
1874
|
+
agentId: a.id,
|
|
1875
|
+
currentVersion: a.currentVersion,
|
|
1876
|
+
}));
|
|
1877
|
+
const selected = await vscode.window.showQuickPick(items, {
|
|
1878
|
+
placeHolder: "Select an agent to install",
|
|
1879
|
+
title: "User Agent Library",
|
|
1880
|
+
});
|
|
1881
|
+
if (!selected) {
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
// Offer to install
|
|
1885
|
+
const action = await vscode.window.showQuickPick([
|
|
1886
|
+
{ label: "Install to Workspace", action: "install" },
|
|
1887
|
+
{ label: "Cancel", action: "cancel" },
|
|
1888
|
+
], {
|
|
1889
|
+
placeHolder: `What would you like to do with "${selected.agentId}"?`,
|
|
1890
|
+
});
|
|
1891
|
+
if (action?.action !== "install") {
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
try {
|
|
1895
|
+
const result = await packManager.installAgentToWorkspace(selected.agentId);
|
|
1896
|
+
if (result.installed) {
|
|
1897
|
+
const msg = result.hydrated
|
|
1898
|
+
? `Installed "${selected.agentId}" v${result.version} to workspace from User Library`
|
|
1899
|
+
: `"${selected.agentId}" is already installed in this workspace`;
|
|
1900
|
+
showInfo(`AgentIDE: ${msg}`);
|
|
1901
|
+
}
|
|
1902
|
+
else {
|
|
1903
|
+
showError(`AgentIDE: Failed to install "${selected.agentId}"`);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
catch (e) {
|
|
1907
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
1908
|
+
log(outputChannel, `[AgentIDE] Install error: ${errorMsg}`);
|
|
1909
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
1910
|
+
}
|
|
1911
|
+
}));
|
|
1912
|
+
// Publish skill to GitHub
|
|
1913
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.skill.publish", async () => {
|
|
1914
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
1915
|
+
// Find skills in current workspace
|
|
1916
|
+
const skillsDir = path.join(workspaceRoot, ".agent-hippo", "agents");
|
|
1917
|
+
const skills = [];
|
|
1918
|
+
if (await (0, utils_1.pathExists)(skillsDir)) {
|
|
1919
|
+
// Look for SKILL.md in agent packs
|
|
1920
|
+
const agents = await fs_1.promises.readdir(skillsDir);
|
|
1921
|
+
for (const agent of agents) {
|
|
1922
|
+
const agentSkillsDir = path.join(skillsDir, agent, "skills");
|
|
1923
|
+
if (await (0, utils_1.pathExists)(agentSkillsDir)) {
|
|
1924
|
+
const skillFolders = await fs_1.promises.readdir(agentSkillsDir);
|
|
1925
|
+
for (const skill of skillFolders) {
|
|
1926
|
+
const skillPath = path.join(agentSkillsDir, skill);
|
|
1927
|
+
const skillMd = path.join(skillPath, "SKILL.md");
|
|
1928
|
+
if (await (0, utils_1.pathExists)(skillMd)) {
|
|
1929
|
+
skills.push({ name: skill, path: skillPath });
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (skills.length === 0) {
|
|
1936
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No skills found. Create a skill with SKILL.md in your agent's skills/ folder.`);
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
// Select skill
|
|
1940
|
+
const selected = await vscode.window.showQuickPick(skills.map((s) => ({ label: s.name, path: s.path })), { placeHolder: "Select a skill to publish" });
|
|
1941
|
+
if (!selected) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
try {
|
|
1945
|
+
const { validateSkillForPublish, collectSkillFiles } = await import("./skills/publish.js");
|
|
1946
|
+
const { publishToStore } = await import("./store/index.js");
|
|
1947
|
+
const validation = await validateSkillForPublish(selected.path);
|
|
1948
|
+
if (!validation.valid) {
|
|
1949
|
+
showError(`AgentIDE: ${validation.errors.join(", ")}`);
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
// Get version (optional for skills)
|
|
1953
|
+
const version = validation.metadata?.version ||
|
|
1954
|
+
(await vscode.window.showInputBox({
|
|
1955
|
+
prompt: "Version (semver)",
|
|
1956
|
+
placeHolder: "e.g., 1.0.0",
|
|
1957
|
+
validateInput: (v) => /^\d+\.\d+\.\d+/.test(v)
|
|
1958
|
+
? null
|
|
1959
|
+
: "Use semver format (e.g., 1.0.0)",
|
|
1960
|
+
}));
|
|
1961
|
+
if (!version) {
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
// Collect files
|
|
1965
|
+
const files = await collectSkillFiles(selected.path);
|
|
1966
|
+
// Publish to store via fork + PR with progress
|
|
1967
|
+
const result = await vscode.window.withProgress({
|
|
1968
|
+
location: vscode.ProgressLocation.Window,
|
|
1969
|
+
title: `Publishing skill "${selected.label}"`,
|
|
1970
|
+
cancellable: false,
|
|
1971
|
+
}, async (progress) => {
|
|
1972
|
+
progress.report({ message: "Preparing fork..." });
|
|
1973
|
+
const res = await publishToStore({
|
|
1974
|
+
type: "skill",
|
|
1975
|
+
slug: selected.label,
|
|
1976
|
+
version,
|
|
1977
|
+
files,
|
|
1978
|
+
}, outputChannel);
|
|
1979
|
+
progress.report({ message: "Creating PR..." });
|
|
1980
|
+
return res;
|
|
1981
|
+
});
|
|
1982
|
+
// Register in local registry
|
|
1983
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
1984
|
+
const { STORE_CONFIG } = await import("./store/index.js");
|
|
1985
|
+
const registry = getRegistry(outputChannel);
|
|
1986
|
+
await registry.registerSkill({
|
|
1987
|
+
slug: selected.label,
|
|
1988
|
+
displayName: validation.metadata?.name || selected.label,
|
|
1989
|
+
description: validation.metadata?.description,
|
|
1990
|
+
github: { owner: STORE_CONFIG.owner, repo: STORE_CONFIG.repo },
|
|
1991
|
+
latestVersion: version,
|
|
1992
|
+
tags: validation.metadata?.tags || [],
|
|
1993
|
+
stats: { installs: 0 },
|
|
1994
|
+
});
|
|
1995
|
+
const viewAction = await vscode.window.showInformationMessage(`Published skill "${selected.label}" v${version}! PR created.`, "View PR");
|
|
1996
|
+
if (viewAction === "View PR") {
|
|
1997
|
+
vscode.env.openExternal(vscode.Uri.parse(result.prUrl));
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
catch (e) {
|
|
2001
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
2002
|
+
log(outputChannel, `[AgentIDE] Skill publish error: ${errorMsg}`);
|
|
2003
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
2004
|
+
}
|
|
2005
|
+
}));
|
|
2006
|
+
// Publish MCP server to store
|
|
2007
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.mcp.publish", async () => {
|
|
2008
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
2009
|
+
// Find MCP configs in current workspace
|
|
2010
|
+
const agentsDir = path.join(workspaceRoot, ".agentide", "agents");
|
|
2011
|
+
const mcpConfigs = [];
|
|
2012
|
+
if (await (0, utils_1.pathExists)(agentsDir)) {
|
|
2013
|
+
const agents = await fs_1.promises.readdir(agentsDir);
|
|
2014
|
+
for (const agent of agents) {
|
|
2015
|
+
const mcpDir = path.join(agentsDir, agent, "mcp");
|
|
2016
|
+
const mcpConfigPath = path.join(mcpDir, ".mcp.json");
|
|
2017
|
+
if (await (0, utils_1.pathExists)(mcpConfigPath)) {
|
|
2018
|
+
try {
|
|
2019
|
+
const content = await fs_1.promises.readFile(mcpConfigPath, "utf-8");
|
|
2020
|
+
const config = JSON.parse(content);
|
|
2021
|
+
// Each MCP config can have multiple servers
|
|
2022
|
+
if (config.mcpServers) {
|
|
2023
|
+
for (const serverName of Object.keys(config.mcpServers)) {
|
|
2024
|
+
mcpConfigs.push({
|
|
2025
|
+
name: serverName,
|
|
2026
|
+
agentId: agent,
|
|
2027
|
+
configPath: mcpConfigPath,
|
|
2028
|
+
mcpDir,
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
catch {
|
|
2034
|
+
// Skip invalid configs
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
if (mcpConfigs.length === 0) {
|
|
2040
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No MCP servers found. Add MCP servers to your agent's mcp/.mcp.json file.`);
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
// Select MCP server
|
|
2044
|
+
const selected = await vscode.window.showQuickPick(mcpConfigs.map((m) => ({
|
|
2045
|
+
label: m.name,
|
|
2046
|
+
description: `from ${m.agentId}`,
|
|
2047
|
+
detail: m.configPath,
|
|
2048
|
+
config: m,
|
|
2049
|
+
})), { placeHolder: "Select an MCP server to publish" });
|
|
2050
|
+
if (!selected) {
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
try {
|
|
2054
|
+
const { publishToStore, STORE_CONFIG } = await import("./store/index.js");
|
|
2055
|
+
const { collectMcpFiles, validateMcpConfig } = await import("./mcp/publish.js");
|
|
2056
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
2057
|
+
// Read the full config
|
|
2058
|
+
const configContent = await fs_1.promises.readFile(selected.config.configPath, "utf-8");
|
|
2059
|
+
const fullConfig = JSON.parse(configContent);
|
|
2060
|
+
const serverConfig = fullConfig.mcpServers[selected.config.name];
|
|
2061
|
+
// Validate
|
|
2062
|
+
const validation = validateMcpConfig({
|
|
2063
|
+
name: selected.config.name,
|
|
2064
|
+
version: serverConfig.version || "1.0.0",
|
|
2065
|
+
description: serverConfig.description,
|
|
2066
|
+
transport: serverConfig.transport || "stdio",
|
|
2067
|
+
command: serverConfig.command,
|
|
2068
|
+
args: serverConfig.args,
|
|
2069
|
+
env: serverConfig.env,
|
|
2070
|
+
url: serverConfig.url,
|
|
2071
|
+
npmPackage: serverConfig.npmPackage,
|
|
2072
|
+
});
|
|
2073
|
+
if (!validation.valid) {
|
|
2074
|
+
showError(`AgentIDE: ${validation.errors.join(", ")}`);
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
// Get version (if not in config)
|
|
2078
|
+
const version = serverConfig.version ||
|
|
2079
|
+
(await vscode.window.showInputBox({
|
|
2080
|
+
prompt: "Version (semver)",
|
|
2081
|
+
placeHolder: "e.g., 1.0.0",
|
|
2082
|
+
value: "1.0.0",
|
|
2083
|
+
validateInput: (v) => /^\d+\.\d+\.\d+/.test(v)
|
|
2084
|
+
? null
|
|
2085
|
+
: "Use semver format (e.g., 1.0.0)",
|
|
2086
|
+
}));
|
|
2087
|
+
if (!version) {
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
// Get description if missing
|
|
2091
|
+
let description = serverConfig.description;
|
|
2092
|
+
if (!description) {
|
|
2093
|
+
description = await vscode.window.showInputBox({
|
|
2094
|
+
prompt: "Description (required)",
|
|
2095
|
+
placeHolder: "What does this MCP server do?",
|
|
2096
|
+
});
|
|
2097
|
+
if (!description) {
|
|
2098
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: Description is required`);
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
// Collect files from MCP directory
|
|
2103
|
+
const files = await collectMcpFiles(selected.config.mcpDir);
|
|
2104
|
+
// Add/update mcp.json manifest
|
|
2105
|
+
const manifest = {
|
|
2106
|
+
name: selected.config.name,
|
|
2107
|
+
version,
|
|
2108
|
+
description,
|
|
2109
|
+
transport: serverConfig.transport || "stdio",
|
|
2110
|
+
command: serverConfig.command,
|
|
2111
|
+
args: serverConfig.args,
|
|
2112
|
+
env: serverConfig.env,
|
|
2113
|
+
url: serverConfig.url,
|
|
2114
|
+
npmPackage: serverConfig.npmPackage,
|
|
2115
|
+
};
|
|
2116
|
+
// Remove undefined fields
|
|
2117
|
+
const cleanManifest = JSON.parse(JSON.stringify(manifest));
|
|
2118
|
+
files.push({
|
|
2119
|
+
path: "mcp.json",
|
|
2120
|
+
content: JSON.stringify(cleanManifest, null, 2),
|
|
2121
|
+
});
|
|
2122
|
+
// Publish to store via fork + PR with progress
|
|
2123
|
+
const result = await vscode.window.withProgress({
|
|
2124
|
+
location: vscode.ProgressLocation.Window,
|
|
2125
|
+
title: `Publishing MCP "${selected.config.name}"`,
|
|
2126
|
+
cancellable: false,
|
|
2127
|
+
}, async (progress) => {
|
|
2128
|
+
progress.report({ message: "Preparing fork..." });
|
|
2129
|
+
const res = await publishToStore({
|
|
2130
|
+
type: "mcp",
|
|
2131
|
+
slug: selected.config.name,
|
|
2132
|
+
version,
|
|
2133
|
+
files,
|
|
2134
|
+
}, outputChannel);
|
|
2135
|
+
progress.report({ message: "Creating PR..." });
|
|
2136
|
+
return res;
|
|
2137
|
+
});
|
|
2138
|
+
// Register in local registry
|
|
2139
|
+
const registry = getRegistry(outputChannel);
|
|
2140
|
+
await registry.registerMcp({
|
|
2141
|
+
slug: selected.config.name,
|
|
2142
|
+
displayName: selected.config.name,
|
|
2143
|
+
description,
|
|
2144
|
+
transport: (serverConfig.transport || "stdio"),
|
|
2145
|
+
github: { owner: STORE_CONFIG.owner, repo: STORE_CONFIG.repo },
|
|
2146
|
+
latestVersion: version,
|
|
2147
|
+
tags: [],
|
|
2148
|
+
stats: { installs: 0 },
|
|
2149
|
+
});
|
|
2150
|
+
const viewAction = await vscode.window.showInformationMessage(`Published MCP "${selected.config.name}" v${version}! PR created.`, "View PR");
|
|
2151
|
+
if (viewAction === "View PR") {
|
|
2152
|
+
vscode.env.openExternal(vscode.Uri.parse(result.prUrl));
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
catch (e) {
|
|
2156
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
2157
|
+
log(outputChannel, `[AgentIDE] MCP publish error: ${errorMsg}`);
|
|
2158
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
2159
|
+
}
|
|
2160
|
+
}));
|
|
2161
|
+
// Publish Spotlight view to store
|
|
2162
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.spotlight.publish", async (viewIdArg, publishOptions) => {
|
|
2163
|
+
const bundleMode = publishOptions?.bundle === "scripts-only" ? "scripts-only" : "full";
|
|
2164
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
2165
|
+
const { collectViewFiles, discoverPublishableViews, validateViewForPublish, } = await import("./spotlight/publish.js");
|
|
2166
|
+
const { publishToStore, STORE_CONFIG, canPublishDirectlyToStore } = await import("./store/index.js");
|
|
2167
|
+
const { isValidPublishVersion } = await import("./engines/publish.js");
|
|
2168
|
+
const views = await discoverPublishableViews(workspaceRoot);
|
|
2169
|
+
if (views.length === 0) {
|
|
2170
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No publishable Spotlight views found. Create a view under .agent-hippo/analytics and register it in panel/views.yaml.`);
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
2173
|
+
const requestedViewId = typeof viewIdArg === "string" ? viewIdArg.trim() : "";
|
|
2174
|
+
let selectedView = requestedViewId
|
|
2175
|
+
? views.find((view) => view.id === requestedViewId)
|
|
2176
|
+
: undefined;
|
|
2177
|
+
if (requestedViewId && !selectedView) {
|
|
2178
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: View "${requestedViewId}" is not publishable. Add widget scripts under .agent-hippo/analytics/views/${requestedViewId}/scripts and register the view in panel/views.yaml.`);
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
if (!selectedView) {
|
|
2182
|
+
const selected = await vscode.window.showQuickPick(views.map((view) => ({
|
|
2183
|
+
label: view.name,
|
|
2184
|
+
description: view.id,
|
|
2185
|
+
detail: `${view.sourceLabel} • ${view.scope} • ${view.scripts.length} script(s)`,
|
|
2186
|
+
view,
|
|
2187
|
+
})), {
|
|
2188
|
+
placeHolder: "Select a Spotlight view to publish",
|
|
2189
|
+
title: `Publish to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}`,
|
|
2190
|
+
});
|
|
2191
|
+
if (!selected) {
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
selectedView = selected.view;
|
|
2195
|
+
}
|
|
2196
|
+
try {
|
|
2197
|
+
const validation = await validateViewForPublish(selectedView, {
|
|
2198
|
+
expectedId: selectedView.id,
|
|
2199
|
+
mode: bundleMode,
|
|
2200
|
+
});
|
|
2201
|
+
if (!validation.valid) {
|
|
2202
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: Cannot publish - ${validation.errors.join(", ")}`);
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
if (validation.warnings.length > 0) {
|
|
2206
|
+
const proceed = await vscode.window.showWarningMessage(`Warnings: ${validation.warnings.join(", ")}`, "Publish Anyway", "Cancel");
|
|
2207
|
+
if (proceed !== "Publish Anyway") {
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
const versionInput = await vscode.window.showInputBox({
|
|
2212
|
+
prompt: "Publish version (semver)",
|
|
2213
|
+
value: validation.metadata?.publishVersion || "1.0.0",
|
|
2214
|
+
placeHolder: "e.g., 1.0.0",
|
|
2215
|
+
validateInput: (value) => value && isValidPublishVersion(value.replace(/^v/, ""))
|
|
2216
|
+
? null
|
|
2217
|
+
: "Use semver format (e.g., 1.0.0)",
|
|
2218
|
+
});
|
|
2219
|
+
if (!versionInput || !validation.metadata) {
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
const version = versionInput.replace(/^v/, "");
|
|
2223
|
+
const changelog = await vscode.window.showInputBox({
|
|
2224
|
+
prompt: "What changed in this version? (optional)",
|
|
2225
|
+
placeHolder: "Initial release, new widgets...",
|
|
2226
|
+
});
|
|
2227
|
+
const files = await collectViewFiles(selectedView, version, validation.metadata, bundleMode);
|
|
2228
|
+
const bundleLabel = bundleMode === "full"
|
|
2229
|
+
? "full bundle (scripts + assets + charts/exports)"
|
|
2230
|
+
: "scripts only";
|
|
2231
|
+
const publishDirect = await canPublishDirectlyToStore();
|
|
2232
|
+
const confirm = await vscode.window.showWarningMessage(publishDirect
|
|
2233
|
+
? `Publish Spotlight view "${selectedView.id}" v${version} (${bundleLabel}) to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}?\n\nThis will open a pull request on the store repository.`
|
|
2234
|
+
: `Submit Spotlight view "${selectedView.id}" v${version} (${bundleLabel}) to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}?\n\nThis will create a pull request from your fork.`, { modal: true }, "Submit PR");
|
|
2235
|
+
if (confirm !== "Submit PR") {
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
const result = await vscode.window.withProgress({
|
|
2239
|
+
location: vscode.ProgressLocation.Window,
|
|
2240
|
+
title: `Publishing Spotlight view ${selectedView.id} v${version}`,
|
|
2241
|
+
cancellable: false,
|
|
2242
|
+
}, async (progress) => {
|
|
2243
|
+
progress.report({
|
|
2244
|
+
message: publishDirect
|
|
2245
|
+
? `Publishing to ${STORE_CONFIG.owner}/${STORE_CONFIG.repo}...`
|
|
2246
|
+
: "Preparing fork...",
|
|
2247
|
+
});
|
|
2248
|
+
return await publishToStore({
|
|
2249
|
+
type: "view",
|
|
2250
|
+
slug: selectedView.id,
|
|
2251
|
+
version,
|
|
2252
|
+
files,
|
|
2253
|
+
changelog,
|
|
2254
|
+
}, outputChannel);
|
|
2255
|
+
});
|
|
2256
|
+
const viewAction = await vscode.window.showInformationMessage(`Published Spotlight view "${selectedView.name}" v${version}! PR created.`, "View PR");
|
|
2257
|
+
if (viewAction === "View PR") {
|
|
2258
|
+
vscode.env.openExternal(vscode.Uri.parse(result.prUrl));
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
catch (e) {
|
|
2262
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
2263
|
+
log(outputChannel, `[AgentIDE] Spotlight publish error: ${errorMsg}`);
|
|
2264
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: ${errorMsg}`);
|
|
2265
|
+
}
|
|
2266
|
+
}));
|
|
2267
|
+
// Install from store (routes based on artifact type)
|
|
2268
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.store.install", async (urlArg) => {
|
|
2269
|
+
await (0, githubStoreGate_js_1.ensureGitHubStoreAccess)(context);
|
|
2270
|
+
const { parseStoreUrl } = await import("./store/index.js");
|
|
2271
|
+
// Get URL from arg or prompt
|
|
2272
|
+
let url = urlArg;
|
|
2273
|
+
if (!url) {
|
|
2274
|
+
url = await vscode.window.showInputBox({
|
|
2275
|
+
prompt: "Enter store URL or GitHub link",
|
|
2276
|
+
placeHolder: "e.g., engine/gemini or https://github.com/.../engines/gemini",
|
|
2277
|
+
validateInput: (value) => {
|
|
2278
|
+
if (!value.trim()) {
|
|
2279
|
+
return "Please enter a URL";
|
|
2280
|
+
}
|
|
2281
|
+
// Allow GitHub URLs or path-based URLs
|
|
2282
|
+
if (!value.includes("/")) {
|
|
2283
|
+
return "Expected: type/slug, or GitHub URL";
|
|
2284
|
+
}
|
|
2285
|
+
return null;
|
|
2286
|
+
},
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
if (!url) {
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
try {
|
|
2293
|
+
const artifact = parseStoreUrl(url);
|
|
2294
|
+
// Route to appropriate install command based on type
|
|
2295
|
+
switch (artifact.type) {
|
|
2296
|
+
case "pack":
|
|
2297
|
+
await vscode.commands.executeCommand("agentide.pack.storeInstall", artifact);
|
|
2298
|
+
break;
|
|
2299
|
+
case "skill":
|
|
2300
|
+
await vscode.commands.executeCommand("agentide.skill.install", artifact);
|
|
2301
|
+
break;
|
|
2302
|
+
case "mcp":
|
|
2303
|
+
await vscode.commands.executeCommand("agentide.mcp.install", artifact);
|
|
2304
|
+
break;
|
|
2305
|
+
case "engine":
|
|
2306
|
+
await vscode.commands.executeCommand("agentide.engine.install", artifact);
|
|
2307
|
+
break;
|
|
2308
|
+
case "view":
|
|
2309
|
+
await vscode.commands.executeCommand("agentide.view.install", artifact);
|
|
2310
|
+
break;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
catch (e) {
|
|
2314
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
2315
|
+
log(outputChannel, `[AgentIDE] Store install error: ${errorMsg}`);
|
|
2316
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
2317
|
+
}
|
|
2318
|
+
}));
|
|
2319
|
+
// Browse store - unified install command
|
|
2320
|
+
// If URL provided: direct install (detects type automatically)
|
|
2321
|
+
// If no URL: interactive picker with Orama-powered search
|
|
2322
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.store.find", async (arg) => {
|
|
2323
|
+
await (0, githubStoreGate_js_1.ensureGitHubStoreAccess)(context);
|
|
2324
|
+
const { isStoreUrl, parseStoreUrl, parseGitHubUrl, detectArtifactType, } = await import("./store/index.js");
|
|
2325
|
+
const { searchMerged, listMergedArtifacts } = await import("./store/oramaIndex.js");
|
|
2326
|
+
let urlArg;
|
|
2327
|
+
let initialTypeFilter = "all";
|
|
2328
|
+
if (typeof arg === "string") {
|
|
2329
|
+
urlArg = arg;
|
|
2330
|
+
}
|
|
2331
|
+
else if (arg && typeof arg === "object" && arg.typeFilter) {
|
|
2332
|
+
initialTypeFilter = arg.typeFilter;
|
|
2333
|
+
}
|
|
2334
|
+
// If URL provided, do direct install
|
|
2335
|
+
if (urlArg) {
|
|
2336
|
+
try {
|
|
2337
|
+
let type;
|
|
2338
|
+
let slug;
|
|
2339
|
+
let version;
|
|
2340
|
+
if (isStoreUrl(urlArg)) {
|
|
2341
|
+
// Store URL - parse type from path prefix
|
|
2342
|
+
const parsed = parseStoreUrl(urlArg);
|
|
2343
|
+
type = parsed.type;
|
|
2344
|
+
slug = parsed.slug;
|
|
2345
|
+
version = parsed.version;
|
|
2346
|
+
}
|
|
2347
|
+
else {
|
|
2348
|
+
// Generic GitHub URL - detect type from marker files
|
|
2349
|
+
const ghParsed = parseGitHubUrl(urlArg);
|
|
2350
|
+
type = await vscode.window.withProgress({
|
|
2351
|
+
location: vscode.ProgressLocation.Notification,
|
|
2352
|
+
title: "Detecting artifact type...",
|
|
2353
|
+
cancellable: false,
|
|
2354
|
+
}, async () => {
|
|
2355
|
+
return await detectArtifactType(ghParsed.owner, ghParsed.repo, ghParsed.ref, ghParsed.path, outputChannel);
|
|
2356
|
+
});
|
|
2357
|
+
// Extract just the last part of the path as the slug name
|
|
2358
|
+
const pathParts = (ghParsed.path || ghParsed.repo).split("/");
|
|
2359
|
+
slug = pathParts[pathParts.length - 1] || ghParsed.repo;
|
|
2360
|
+
version = ghParsed.ref;
|
|
2361
|
+
}
|
|
2362
|
+
// Route to appropriate install command
|
|
2363
|
+
switch (type) {
|
|
2364
|
+
case "pack":
|
|
2365
|
+
await vscode.commands.executeCommand("agentide.pack.storeInstall", {
|
|
2366
|
+
type: "pack",
|
|
2367
|
+
slug,
|
|
2368
|
+
version,
|
|
2369
|
+
sourceUrl: urlArg, // Pass original URL for non-store installs
|
|
2370
|
+
});
|
|
2371
|
+
break;
|
|
2372
|
+
case "skill":
|
|
2373
|
+
await vscode.commands.executeCommand("agentide.skill.install", {
|
|
2374
|
+
type: "skill",
|
|
2375
|
+
slug,
|
|
2376
|
+
version,
|
|
2377
|
+
sourceUrl: urlArg,
|
|
2378
|
+
});
|
|
2379
|
+
break;
|
|
2380
|
+
case "mcp":
|
|
2381
|
+
await vscode.commands.executeCommand("agentide.mcp.install", {
|
|
2382
|
+
type: "mcp",
|
|
2383
|
+
slug,
|
|
2384
|
+
version,
|
|
2385
|
+
sourceUrl: urlArg,
|
|
2386
|
+
});
|
|
2387
|
+
break;
|
|
2388
|
+
case "engine":
|
|
2389
|
+
await vscode.commands.executeCommand("agentide.engine.install", {
|
|
2390
|
+
type: "engine",
|
|
2391
|
+
slug,
|
|
2392
|
+
version,
|
|
2393
|
+
sourceUrl: urlArg,
|
|
2394
|
+
});
|
|
2395
|
+
break;
|
|
2396
|
+
case "view":
|
|
2397
|
+
await vscode.commands.executeCommand("agentide.view.install", {
|
|
2398
|
+
type: "view",
|
|
2399
|
+
slug,
|
|
2400
|
+
version,
|
|
2401
|
+
sourceUrl: urlArg,
|
|
2402
|
+
});
|
|
2403
|
+
break;
|
|
2404
|
+
}
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
catch (e) {
|
|
2408
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
2409
|
+
log(outputChannel, `[AgentIDE] Install error: ${errorMsg}`);
|
|
2410
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
// No URL - show interactive picker
|
|
2415
|
+
// Import shared icons (consistent with CLI)
|
|
2416
|
+
const { STORE_ICONS } = await import("./store/shared.js");
|
|
2417
|
+
const typeIcons = {
|
|
2418
|
+
pack: STORE_ICONS.pack,
|
|
2419
|
+
skill: STORE_ICONS.skill,
|
|
2420
|
+
mcp: STORE_ICONS.mcp,
|
|
2421
|
+
engine: STORE_ICONS.engine,
|
|
2422
|
+
view: STORE_ICONS.view,
|
|
2423
|
+
};
|
|
2424
|
+
const typeFilters = ["all", "pack", "skill", "mcp", "engine", "view"];
|
|
2425
|
+
// Create interactive QuickPick
|
|
2426
|
+
const quickPick = vscode.window.createQuickPick();
|
|
2427
|
+
quickPick.title =
|
|
2428
|
+
initialTypeFilter === "view"
|
|
2429
|
+
? "Install Spotlight View"
|
|
2430
|
+
: "Install Packs, Skills, MCP Tools, Engines, Spotlight Views";
|
|
2431
|
+
quickPick.placeholder = "Search or paste a GitHub URL to install...";
|
|
2432
|
+
quickPick.matchOnDescription = true;
|
|
2433
|
+
quickPick.matchOnDetail = true;
|
|
2434
|
+
quickPick.busy = true;
|
|
2435
|
+
let allItems = [];
|
|
2436
|
+
let currentFilter = initialTypeFilter;
|
|
2437
|
+
let searchDebounceTimer;
|
|
2438
|
+
// Source icons for Local/Remote display (from shared)
|
|
2439
|
+
const sourceIcons = {
|
|
2440
|
+
local: STORE_ICONS.local,
|
|
2441
|
+
remote: STORE_ICONS.remote,
|
|
2442
|
+
};
|
|
2443
|
+
const updateItems = (items) => {
|
|
2444
|
+
const itemsToShow = items ?? allItems;
|
|
2445
|
+
const filtered = currentFilter === "all"
|
|
2446
|
+
? itemsToShow
|
|
2447
|
+
: itemsToShow.filter((item) => item.type === currentFilter);
|
|
2448
|
+
// Filter header buttons
|
|
2449
|
+
const filterButtons = typeFilters.map((f) => ({
|
|
2450
|
+
label: f === "all"
|
|
2451
|
+
? "$(list-flat) All"
|
|
2452
|
+
: `${typeIcons[f]} ${f.charAt(0).toUpperCase() + f.slice(1)}s`,
|
|
2453
|
+
description: f === currentFilter ? "$(check)" : "",
|
|
2454
|
+
alwaysShow: true,
|
|
2455
|
+
itemType: "filter",
|
|
2456
|
+
filter: f,
|
|
2457
|
+
}));
|
|
2458
|
+
// Artifact items - show source icon (Local/Remote) and installed badge
|
|
2459
|
+
const artifactItems = filtered.map((item) => {
|
|
2460
|
+
const sourceIcon = item.source === "local" ? sourceIcons.local : sourceIcons.remote;
|
|
2461
|
+
const installedBadge = item.installed ? "$(check)" : "";
|
|
2462
|
+
// Build description: source + type + installed badge
|
|
2463
|
+
const descParts = [
|
|
2464
|
+
item.source === "local" ? "Local" : "Remote",
|
|
2465
|
+
item.type,
|
|
2466
|
+
];
|
|
2467
|
+
if (installedBadge) {
|
|
2468
|
+
descParts.push(installedBadge);
|
|
2469
|
+
}
|
|
2470
|
+
// Build detail: description + installed packs info
|
|
2471
|
+
let detail = item.description || item.path;
|
|
2472
|
+
if (item.installedTo && item.installedTo.length > 0) {
|
|
2473
|
+
detail += ` • Installed to: ${item.installedTo.join(", ")}`;
|
|
2474
|
+
}
|
|
2475
|
+
return {
|
|
2476
|
+
label: `${sourceIcon} ${typeIcons[item.type]} ${item.slug}`,
|
|
2477
|
+
description: descParts.join(" • "),
|
|
2478
|
+
detail,
|
|
2479
|
+
itemType: "artifact",
|
|
2480
|
+
artifact: item,
|
|
2481
|
+
};
|
|
2482
|
+
});
|
|
2483
|
+
quickPick.items = [
|
|
2484
|
+
...filterButtons,
|
|
2485
|
+
{
|
|
2486
|
+
label: "",
|
|
2487
|
+
kind: vscode.QuickPickItemKind.Separator,
|
|
2488
|
+
itemType: "filter",
|
|
2489
|
+
},
|
|
2490
|
+
...artifactItems,
|
|
2491
|
+
];
|
|
2492
|
+
};
|
|
2493
|
+
// Live search handler using Orama
|
|
2494
|
+
const handleSearch = async (query) => {
|
|
2495
|
+
if (searchDebounceTimer) {
|
|
2496
|
+
clearTimeout(searchDebounceTimer);
|
|
2497
|
+
}
|
|
2498
|
+
const trimmedQuery = query.trim();
|
|
2499
|
+
// If empty query or looks like URL, show all items
|
|
2500
|
+
if (!trimmedQuery ||
|
|
2501
|
+
trimmedQuery.startsWith("http") ||
|
|
2502
|
+
trimmedQuery.startsWith("store://") ||
|
|
2503
|
+
trimmedQuery.startsWith("github.com")) {
|
|
2504
|
+
updateItems(allItems);
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
// Debounce search
|
|
2508
|
+
searchDebounceTimer = setTimeout(async () => {
|
|
2509
|
+
try {
|
|
2510
|
+
const typeFilter = currentFilter === "all"
|
|
2511
|
+
? undefined
|
|
2512
|
+
: currentFilter;
|
|
2513
|
+
const results = await searchMerged(trimmedQuery, { type: typeFilter, limit: 50 }, outputChannel);
|
|
2514
|
+
const searchItems = results.map((r) => ({
|
|
2515
|
+
type: r.type,
|
|
2516
|
+
slug: r.slug,
|
|
2517
|
+
path: `${r.type}s/${r.slug}`,
|
|
2518
|
+
description: r.description,
|
|
2519
|
+
installed: r.installed,
|
|
2520
|
+
installedVersion: r.installedVersion,
|
|
2521
|
+
source: r.source,
|
|
2522
|
+
installedTo: r.installedTo,
|
|
2523
|
+
}));
|
|
2524
|
+
updateItems(searchItems);
|
|
2525
|
+
}
|
|
2526
|
+
catch (e) {
|
|
2527
|
+
// Fall back to showing all items on search error
|
|
2528
|
+
log(outputChannel, `[AgentIDE] Search error: ${e instanceof Error ? e.message : String(e)}`);
|
|
2529
|
+
updateItems(allItems);
|
|
2530
|
+
}
|
|
2531
|
+
}, 150); // 150ms debounce
|
|
2532
|
+
};
|
|
2533
|
+
// Listen for input changes for live search
|
|
2534
|
+
quickPick.onDidChangeValue(handleSearch);
|
|
2535
|
+
// Load items from store using merged Orama index (local + remote)
|
|
2536
|
+
try {
|
|
2537
|
+
const storeItems = await listMergedArtifacts(undefined, outputChannel);
|
|
2538
|
+
// Map to expected format - includes installed status, source, and installedTo
|
|
2539
|
+
allItems = storeItems.map((item) => ({
|
|
2540
|
+
type: item.type,
|
|
2541
|
+
slug: item.slug,
|
|
2542
|
+
path: `${item.type}s/${item.slug}`,
|
|
2543
|
+
description: item.description,
|
|
2544
|
+
installed: item.installed,
|
|
2545
|
+
installedVersion: item.installedVersion,
|
|
2546
|
+
source: item.source,
|
|
2547
|
+
installedTo: item.installedTo,
|
|
2548
|
+
}));
|
|
2549
|
+
quickPick.busy = false;
|
|
2550
|
+
updateItems();
|
|
2551
|
+
if (allItems.length === 0) {
|
|
2552
|
+
quickPick.placeholder =
|
|
2553
|
+
"Store is empty or index not synced yet. Try again later!";
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
catch (e) {
|
|
2557
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
2558
|
+
log(outputChannel, `[AgentIDE] Store browse error: ${errorMsg}`);
|
|
2559
|
+
quickPick.hide();
|
|
2560
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
// Helper to check if input looks like a URL
|
|
2564
|
+
const looksLikeUrl = (input) => {
|
|
2565
|
+
const trimmed = input.trim();
|
|
2566
|
+
return (trimmed.startsWith("https://") ||
|
|
2567
|
+
trimmed.startsWith("http://") ||
|
|
2568
|
+
trimmed.startsWith("github.com/") ||
|
|
2569
|
+
trimmed.startsWith("store://"));
|
|
2570
|
+
};
|
|
2571
|
+
// Handle selection or URL input
|
|
2572
|
+
quickPick.onDidAccept(async () => {
|
|
2573
|
+
const selected = quickPick.selectedItems[0];
|
|
2574
|
+
const inputValue = quickPick.value.trim();
|
|
2575
|
+
// Check if input looks like a URL FIRST - prioritize URL over selection
|
|
2576
|
+
if (inputValue && looksLikeUrl(inputValue)) {
|
|
2577
|
+
quickPick.hide();
|
|
2578
|
+
log(outputChannel, `[AgentIDE] Browse Store: detected URL input: ${inputValue}`);
|
|
2579
|
+
// Re-run the command with the URL
|
|
2580
|
+
await vscode.commands.executeCommand("agentide.store.find", inputValue);
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
if (!selected) {
|
|
2584
|
+
return;
|
|
2585
|
+
}
|
|
2586
|
+
// Handle filter selection
|
|
2587
|
+
if (selected.itemType === "filter" && selected.filter) {
|
|
2588
|
+
currentFilter = selected.filter;
|
|
2589
|
+
updateItems();
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
// Handle artifact selection
|
|
2593
|
+
if (selected.itemType === "artifact" && selected.artifact) {
|
|
2594
|
+
quickPick.hide();
|
|
2595
|
+
const { artifact } = selected;
|
|
2596
|
+
switch (artifact.type) {
|
|
2597
|
+
case "pack":
|
|
2598
|
+
await vscode.commands.executeCommand("agentide.pack.storeInstall", {
|
|
2599
|
+
type: "pack",
|
|
2600
|
+
slug: artifact.slug,
|
|
2601
|
+
});
|
|
2602
|
+
break;
|
|
2603
|
+
case "skill":
|
|
2604
|
+
await vscode.commands.executeCommand("agentide.skill.install", {
|
|
2605
|
+
type: "skill",
|
|
2606
|
+
slug: artifact.slug,
|
|
2607
|
+
});
|
|
2608
|
+
break;
|
|
2609
|
+
case "mcp":
|
|
2610
|
+
await vscode.commands.executeCommand("agentide.mcp.install", {
|
|
2611
|
+
type: "mcp",
|
|
2612
|
+
slug: artifact.slug,
|
|
2613
|
+
});
|
|
2614
|
+
break;
|
|
2615
|
+
case "engine":
|
|
2616
|
+
await vscode.commands.executeCommand("agentide.engine.install", {
|
|
2617
|
+
type: "engine",
|
|
2618
|
+
slug: artifact.slug,
|
|
2619
|
+
});
|
|
2620
|
+
break;
|
|
2621
|
+
case "view":
|
|
2622
|
+
await vscode.commands.executeCommand("agentide.view.install", {
|
|
2623
|
+
type: "view",
|
|
2624
|
+
slug: artifact.slug,
|
|
2625
|
+
});
|
|
2626
|
+
break;
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
});
|
|
2630
|
+
quickPick.onDidHide(() => quickPick.dispose());
|
|
2631
|
+
quickPick.show();
|
|
2632
|
+
}));
|
|
2633
|
+
// Store search API - for agent skill scripts to search without UI
|
|
2634
|
+
// Returns merged results from both local library and remote store
|
|
2635
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.store.search", async (query, options) => {
|
|
2636
|
+
const { searchMerged } = await import("./store/oramaIndex.js");
|
|
2637
|
+
return searchMerged(query, options, outputChannel);
|
|
2638
|
+
}));
|
|
2639
|
+
// Store sync API - force refresh the store index
|
|
2640
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.store.sync", async () => {
|
|
2641
|
+
const { forceRefresh, getIndexMeta } = await import("./store/oramaIndex.js");
|
|
2642
|
+
await vscode.window.withProgress({
|
|
2643
|
+
location: vscode.ProgressLocation.Notification,
|
|
2644
|
+
title: "Syncing store index...",
|
|
2645
|
+
cancellable: false,
|
|
2646
|
+
}, async () => {
|
|
2647
|
+
await forceRefresh(outputChannel);
|
|
2648
|
+
});
|
|
2649
|
+
const meta = await getIndexMeta();
|
|
2650
|
+
if (meta) {
|
|
2651
|
+
void showInfo(`Store index synced: ${meta.artifactCount} artifacts (updated ${new Date(meta.generatedAt).toLocaleDateString()})`);
|
|
2652
|
+
}
|
|
2653
|
+
}));
|
|
2654
|
+
// Store setup - automate store index in a GitHub repo
|
|
2655
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.store.setup", async () => {
|
|
2656
|
+
const { setupStoreAutomation } = await import("./store/github/setup.js");
|
|
2657
|
+
// Get repo URL from user
|
|
2658
|
+
const repoUrl = await vscode.window.showInputBox({
|
|
2659
|
+
prompt: "Enter GitHub repository URL for your store",
|
|
2660
|
+
placeHolder: "https://github.com/owner/repo or owner/repo",
|
|
2661
|
+
validateInput: (value) => {
|
|
2662
|
+
if (!value) {
|
|
2663
|
+
return "Repository URL is required";
|
|
2664
|
+
}
|
|
2665
|
+
const match = value.match(/(?:github\.com\/)?([^/]+)\/([^/]+)/);
|
|
2666
|
+
if (!match) {
|
|
2667
|
+
return "Invalid format. Use: owner/repo or https://github.com/owner/repo";
|
|
2668
|
+
}
|
|
2669
|
+
return null;
|
|
2670
|
+
},
|
|
2671
|
+
});
|
|
2672
|
+
if (!repoUrl) {
|
|
2673
|
+
return;
|
|
2674
|
+
}
|
|
2675
|
+
const match = repoUrl.match(/(?:github\.com\/)?([^/]+)\/([^/]+)/);
|
|
2676
|
+
if (!match) {
|
|
2677
|
+
void showError("Invalid repository URL");
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
const [, owner, repo] = match;
|
|
2681
|
+
const cleanRepo = repo.replace(/\.git$/, "");
|
|
2682
|
+
const result = await vscode.window.withProgress({
|
|
2683
|
+
location: vscode.ProgressLocation.Notification,
|
|
2684
|
+
title: `Setting up store automation for ${owner}/${cleanRepo}...`,
|
|
2685
|
+
cancellable: false,
|
|
2686
|
+
}, async () => {
|
|
2687
|
+
return await setupStoreAutomation(owner, cleanRepo, outputChannel);
|
|
2688
|
+
});
|
|
2689
|
+
if (result.success && result.pullRequestUrl) {
|
|
2690
|
+
// Update store configuration to use this repo for publish/find
|
|
2691
|
+
const storeConfig = vscode.workspace.getConfiguration("agentide");
|
|
2692
|
+
const newStoreRepo = `${owner}/${cleanRepo}`;
|
|
2693
|
+
const currentStoreRepo = storeConfig.get("storeRepo", "");
|
|
2694
|
+
const currentIndexUrl = storeConfig.get("store.indexUrl", "");
|
|
2695
|
+
const newIndexUrl = `https://${owner}.github.io/${cleanRepo}`;
|
|
2696
|
+
let currentDefaultIndexUrl = "";
|
|
2697
|
+
if (currentStoreRepo) {
|
|
2698
|
+
const matchStore = currentStoreRepo.match(/^(?:https?:\/\/github\.com\/)?([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
2699
|
+
if (matchStore) {
|
|
2700
|
+
currentDefaultIndexUrl = `https://${matchStore[1]}.github.io/${matchStore[2]}`;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
await storeConfig.update("storeRepo", newStoreRepo, vscode.ConfigurationTarget.Global);
|
|
2704
|
+
if (!currentIndexUrl ||
|
|
2705
|
+
(currentDefaultIndexUrl && currentIndexUrl === currentDefaultIndexUrl)) {
|
|
2706
|
+
await storeConfig.update("store.indexUrl", newIndexUrl, vscode.ConfigurationTarget.Global);
|
|
2707
|
+
}
|
|
2708
|
+
const action = await vscode.window.showInformationMessage(
|
|
2709
|
+
// allow-any-unicode-next-line
|
|
2710
|
+
`🦛 ${result.message}`, "Open Pull Request", "Copy URL");
|
|
2711
|
+
if (action === "Open Pull Request") {
|
|
2712
|
+
await vscode.env.openExternal(vscode.Uri.parse(result.pullRequestUrl));
|
|
2713
|
+
}
|
|
2714
|
+
else if (action === "Copy URL") {
|
|
2715
|
+
await vscode.env.clipboard.writeText(result.pullRequestUrl);
|
|
2716
|
+
void showInfo("Pull request URL copied to clipboard");
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
else if (!result.success) {
|
|
2720
|
+
void showError(`Setup failed: ${result.message}`);
|
|
2721
|
+
}
|
|
2722
|
+
}));
|
|
2723
|
+
// Install pack from store (internal command)
|
|
2724
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.storeInstall", async (artifactArg) => {
|
|
2725
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
2726
|
+
const { downloadFromStore, listStoreVersions } = await import("./store/index.js");
|
|
2727
|
+
const { getAgentRoot } = await import("./agentpack/paths.js");
|
|
2728
|
+
const artifact = artifactArg || {
|
|
2729
|
+
type: "pack",
|
|
2730
|
+
slug: "",
|
|
2731
|
+
version: undefined,
|
|
2732
|
+
};
|
|
2733
|
+
// If no version specified, show version picker or use main
|
|
2734
|
+
if (!artifact.version) {
|
|
2735
|
+
const versions = await listStoreVersions("pack", artifact.slug);
|
|
2736
|
+
if (versions.length === 0) {
|
|
2737
|
+
// No tags - will download from main branch
|
|
2738
|
+
artifact.version = "main";
|
|
2739
|
+
}
|
|
2740
|
+
else {
|
|
2741
|
+
const selected = await vscode.window.showQuickPick(versions.map((v) => ({
|
|
2742
|
+
label: v.version,
|
|
2743
|
+
description: v.isPrerelease ? "(pre-release)" : "",
|
|
2744
|
+
})), { placeHolder: "Select version to install" });
|
|
2745
|
+
if (!selected) {
|
|
2746
|
+
return;
|
|
2747
|
+
}
|
|
2748
|
+
artifact.version = selected.label;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
const targetDir = getAgentRoot(workspaceRoot, artifact.slug);
|
|
2752
|
+
const targetExists = await fs_1.promises
|
|
2753
|
+
.access(targetDir)
|
|
2754
|
+
.then(() => true)
|
|
2755
|
+
.catch(() => false);
|
|
2756
|
+
if (targetExists) {
|
|
2757
|
+
const overwrite = await vscode.window.showWarningMessage(`Pack "${artifact.slug}" already exists. Overwrite?`, { modal: true }, "Overwrite", "Cancel");
|
|
2758
|
+
if (overwrite !== "Overwrite") {
|
|
2759
|
+
return;
|
|
2760
|
+
}
|
|
2761
|
+
await fs_1.promises.rm(targetDir, { recursive: true, force: true });
|
|
2762
|
+
}
|
|
2763
|
+
await vscode.window.withProgress({
|
|
2764
|
+
location: vscode.ProgressLocation.Window,
|
|
2765
|
+
title: `Installing pack "${artifact.slug}"`,
|
|
2766
|
+
cancellable: false,
|
|
2767
|
+
}, async (progress) => {
|
|
2768
|
+
progress.report({ message: "Downloading from store..." });
|
|
2769
|
+
const files = await downloadFromStore({
|
|
2770
|
+
type: "pack",
|
|
2771
|
+
slug: artifact.slug,
|
|
2772
|
+
version: artifact.version,
|
|
2773
|
+
}, outputChannel);
|
|
2774
|
+
progress.report({ message: "Extracting files..." });
|
|
2775
|
+
await fs_1.promises.mkdir(targetDir, { recursive: true });
|
|
2776
|
+
for (const file of files) {
|
|
2777
|
+
const filePath = path.join(targetDir, file.path);
|
|
2778
|
+
await fs_1.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
2779
|
+
await fs_1.promises.writeFile(filePath, file.content);
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
await vscode.commands.executeCommand("agentide.packsChanged");
|
|
2783
|
+
// Register the installed pack in local registry
|
|
2784
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
2785
|
+
const registry = getRegistry(outputChannel);
|
|
2786
|
+
await registry.registerPack({
|
|
2787
|
+
slug: artifact.slug,
|
|
2788
|
+
displayName: artifact.slug,
|
|
2789
|
+
latestVersion: artifact.version || "main",
|
|
2790
|
+
tags: [],
|
|
2791
|
+
stats: { installs: 1, stars: 0 },
|
|
2792
|
+
});
|
|
2793
|
+
// Invalidate local index cache so merged search sees the new item
|
|
2794
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
2795
|
+
invalidateLocalIndex();
|
|
2796
|
+
const activateAction = await vscode.window.showInformationMessage(`Installed pack "${artifact.slug}" v${artifact.version}`, "Activate");
|
|
2797
|
+
if (activateAction === "Activate") {
|
|
2798
|
+
await vscode.commands.executeCommand("agentide.pack.switch", artifact.slug);
|
|
2799
|
+
}
|
|
2800
|
+
}));
|
|
2801
|
+
// Install skill from store or external GitHub
|
|
2802
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.skill.install", async (artifactArg) => {
|
|
2803
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
2804
|
+
const { downloadFromStore, downloadFromExternalGitHub, listStoreVersions, isStoreUrl, parseGitHubUrl, } = await import("./store/index.js");
|
|
2805
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
2806
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
2807
|
+
// Get artifact info
|
|
2808
|
+
let artifact = artifactArg;
|
|
2809
|
+
if (!artifact) {
|
|
2810
|
+
const url = await vscode.window.showInputBox({
|
|
2811
|
+
prompt: "Enter skill store URL or GitHub URL",
|
|
2812
|
+
placeHolder: "e.g., skills/typescript-testing@v1.0.0 or https://github.com/user/repo",
|
|
2813
|
+
});
|
|
2814
|
+
if (!url) {
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
const { parseStoreUrl } = await import("./store/index.js");
|
|
2818
|
+
artifact = parseStoreUrl(url);
|
|
2819
|
+
}
|
|
2820
|
+
// Determine if this is a store URL or external GitHub
|
|
2821
|
+
const isExternal = artifact.sourceUrl && !isStoreUrl(artifact.sourceUrl);
|
|
2822
|
+
// If no version specified and not external, show version picker
|
|
2823
|
+
if (!artifact.version && !isExternal) {
|
|
2824
|
+
const versions = await listStoreVersions("skill", artifact.slug);
|
|
2825
|
+
if (versions.length === 0) {
|
|
2826
|
+
artifact.version = "main";
|
|
2827
|
+
}
|
|
2828
|
+
else {
|
|
2829
|
+
const selected = await vscode.window.showQuickPick(versions.map((v) => ({
|
|
2830
|
+
label: v.version,
|
|
2831
|
+
description: v.isPrerelease ? "(pre-release)" : "",
|
|
2832
|
+
})), { placeHolder: "Select version to install" });
|
|
2833
|
+
if (!selected) {
|
|
2834
|
+
return;
|
|
2835
|
+
}
|
|
2836
|
+
artifact.version = selected.label;
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
// Select which agent to install the skill to
|
|
2840
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
2841
|
+
if (packs.length === 0) {
|
|
2842
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: No agents found. Create an agent first.`);
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2845
|
+
const targetPack = await vscode.window.showQuickPick(packs.map((p) => ({ label: p.id, description: `v${p.version}` })), { placeHolder: "Select agent to install skill to" });
|
|
2846
|
+
if (!targetPack) {
|
|
2847
|
+
return;
|
|
2848
|
+
}
|
|
2849
|
+
const { getAgentRoot } = await import("./agentpack/paths.js");
|
|
2850
|
+
const agentRoot = getAgentRoot(workspaceRoot, targetPack.label);
|
|
2851
|
+
const skillsDir = path.join(agentRoot, "skills", artifact.slug);
|
|
2852
|
+
const targetExists = await fs_1.promises
|
|
2853
|
+
.access(skillsDir)
|
|
2854
|
+
.then(() => true)
|
|
2855
|
+
.catch(() => false);
|
|
2856
|
+
if (targetExists) {
|
|
2857
|
+
const overwrite = await vscode.window.showWarningMessage(`Skill "${artifact.slug}" already exists in ${targetPack.label}. Overwrite?`, { modal: true }, "Overwrite", "Cancel");
|
|
2858
|
+
if (overwrite !== "Overwrite") {
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
await fs_1.promises.rm(skillsDir, { recursive: true, force: true });
|
|
2862
|
+
}
|
|
2863
|
+
await vscode.window.withProgress({
|
|
2864
|
+
location: vscode.ProgressLocation.Window,
|
|
2865
|
+
title: `Installing skill "${artifact.slug}"`,
|
|
2866
|
+
cancellable: false,
|
|
2867
|
+
}, async (progress) => {
|
|
2868
|
+
let files;
|
|
2869
|
+
if (isExternal && artifact.sourceUrl) {
|
|
2870
|
+
// Download from external GitHub
|
|
2871
|
+
progress.report({ message: "Downloading from GitHub..." });
|
|
2872
|
+
const parsed = parseGitHubUrl(artifact.sourceUrl);
|
|
2873
|
+
files = await downloadFromExternalGitHub({
|
|
2874
|
+
owner: parsed.owner,
|
|
2875
|
+
repo: parsed.repo,
|
|
2876
|
+
ref: parsed.ref || "main",
|
|
2877
|
+
path: parsed.path,
|
|
2878
|
+
}, outputChannel);
|
|
2879
|
+
}
|
|
2880
|
+
else {
|
|
2881
|
+
// Download from store
|
|
2882
|
+
progress.report({ message: "Downloading from store..." });
|
|
2883
|
+
files = await downloadFromStore({
|
|
2884
|
+
type: "skill",
|
|
2885
|
+
slug: artifact.slug,
|
|
2886
|
+
version: artifact.version,
|
|
2887
|
+
}, outputChannel);
|
|
2888
|
+
}
|
|
2889
|
+
progress.report({ message: "Extracting files..." });
|
|
2890
|
+
await fs_1.promises.mkdir(skillsDir, { recursive: true });
|
|
2891
|
+
for (const file of files) {
|
|
2892
|
+
const filePath = path.join(skillsDir, file.path);
|
|
2893
|
+
await fs_1.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
2894
|
+
await fs_1.promises.writeFile(filePath, file.content);
|
|
2895
|
+
}
|
|
2896
|
+
});
|
|
2897
|
+
// Register the installed skill in local registry
|
|
2898
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
2899
|
+
const registry = getRegistry(outputChannel);
|
|
2900
|
+
await registry.registerSkill({
|
|
2901
|
+
slug: artifact.slug,
|
|
2902
|
+
displayName: artifact.slug,
|
|
2903
|
+
latestVersion: artifact.version || "main",
|
|
2904
|
+
tags: [],
|
|
2905
|
+
stats: { installs: 1 },
|
|
2906
|
+
agentPackId: targetPack.label,
|
|
2907
|
+
});
|
|
2908
|
+
// Invalidate local index cache so merged search sees the new item
|
|
2909
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
2910
|
+
invalidateLocalIndex();
|
|
2911
|
+
showInfo(`Installed skill "${artifact.slug}" to ${targetPack.label}`);
|
|
2912
|
+
}));
|
|
2913
|
+
// Install MCP from store
|
|
2914
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.mcp.install", async (artifactArg) => {
|
|
2915
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
2916
|
+
const { downloadFromStore, listStoreVersions } = await import("./store/index.js");
|
|
2917
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
2918
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
2919
|
+
// Get artifact info
|
|
2920
|
+
let artifact = artifactArg;
|
|
2921
|
+
if (!artifact) {
|
|
2922
|
+
const url = await vscode.window.showInputBox({
|
|
2923
|
+
prompt: "Enter MCP store URL",
|
|
2924
|
+
placeHolder: "e.g., mcp/github@v1.0.0",
|
|
2925
|
+
});
|
|
2926
|
+
if (!url) {
|
|
2927
|
+
return;
|
|
2928
|
+
}
|
|
2929
|
+
const { parseStoreUrl } = await import("./store/index.js");
|
|
2930
|
+
artifact = parseStoreUrl(url);
|
|
2931
|
+
}
|
|
2932
|
+
// If no version specified, show version picker or use main
|
|
2933
|
+
if (!artifact.version) {
|
|
2934
|
+
const versions = await listStoreVersions("mcp", artifact.slug);
|
|
2935
|
+
if (versions.length === 0) {
|
|
2936
|
+
// No tags - will download from main branch
|
|
2937
|
+
artifact.version = "main";
|
|
2938
|
+
}
|
|
2939
|
+
else {
|
|
2940
|
+
const selected = await vscode.window.showQuickPick(versions.map((v) => ({
|
|
2941
|
+
label: v.version,
|
|
2942
|
+
description: v.isPrerelease ? "(pre-release)" : "",
|
|
2943
|
+
})), { placeHolder: "Select version to install" });
|
|
2944
|
+
if (!selected) {
|
|
2945
|
+
return;
|
|
2946
|
+
}
|
|
2947
|
+
artifact.version = selected.label;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
// Select which agent to install the MCP to
|
|
2951
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
2952
|
+
if (packs.length === 0) {
|
|
2953
|
+
showError(`${branding_1.AGENTIDE_BRAND_NAME}: No agents found. Create an agent first.`);
|
|
2954
|
+
return;
|
|
2955
|
+
}
|
|
2956
|
+
const targetPack = await vscode.window.showQuickPick(packs.map((p) => ({ label: p.id, description: `v${p.version}` })), { placeHolder: "Select agent to add MCP server to" });
|
|
2957
|
+
if (!targetPack) {
|
|
2958
|
+
return;
|
|
2959
|
+
}
|
|
2960
|
+
await vscode.window.withProgress({
|
|
2961
|
+
location: vscode.ProgressLocation.Window,
|
|
2962
|
+
title: `Installing MCP "${artifact.slug}"`,
|
|
2963
|
+
cancellable: false,
|
|
2964
|
+
}, async (progress) => {
|
|
2965
|
+
progress.report({ message: "Downloading from store..." });
|
|
2966
|
+
const files = await downloadFromStore({
|
|
2967
|
+
type: "mcp",
|
|
2968
|
+
slug: artifact.slug,
|
|
2969
|
+
version: artifact.version,
|
|
2970
|
+
}, outputChannel);
|
|
2971
|
+
progress.report({ message: "Merging MCP config..." });
|
|
2972
|
+
// Find mcp.json in downloaded files
|
|
2973
|
+
const mcpJsonFile = files.find((f) => f.path === "mcp.json" || f.path.endsWith("/mcp.json"));
|
|
2974
|
+
if (!mcpJsonFile) {
|
|
2975
|
+
throw new Error("Downloaded MCP package missing mcp.json");
|
|
2976
|
+
}
|
|
2977
|
+
const mcpConfig = JSON.parse(mcpJsonFile.content.toString());
|
|
2978
|
+
// Read existing .mcp.json or create new one
|
|
2979
|
+
const { getAgentRoot } = await import("./agentpack/paths.js");
|
|
2980
|
+
const agentRoot = getAgentRoot(workspaceRoot, targetPack.label);
|
|
2981
|
+
const mcpDir = path.join(agentRoot, "mcp");
|
|
2982
|
+
const mcpJsonPath = path.join(mcpDir, ".mcp.json");
|
|
2983
|
+
await fs_1.promises.mkdir(mcpDir, { recursive: true });
|
|
2984
|
+
let existingConfig = {
|
|
2985
|
+
mcpServers: {},
|
|
2986
|
+
};
|
|
2987
|
+
try {
|
|
2988
|
+
const content = await fs_1.promises.readFile(mcpJsonPath, "utf-8");
|
|
2989
|
+
existingConfig = JSON.parse(content);
|
|
2990
|
+
if (!existingConfig.mcpServers) {
|
|
2991
|
+
existingConfig.mcpServers = {};
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
catch {
|
|
2995
|
+
// File doesn't exist, use default
|
|
2996
|
+
}
|
|
2997
|
+
// Add/update the MCP server
|
|
2998
|
+
existingConfig.mcpServers[artifact.slug] = {
|
|
2999
|
+
transport: mcpConfig.transport || "stdio",
|
|
3000
|
+
command: mcpConfig.command,
|
|
3001
|
+
args: mcpConfig.args,
|
|
3002
|
+
env: mcpConfig.env,
|
|
3003
|
+
url: mcpConfig.url,
|
|
3004
|
+
npmPackage: mcpConfig.npmPackage,
|
|
3005
|
+
// Store metadata
|
|
3006
|
+
_version: artifact.version,
|
|
3007
|
+
_description: mcpConfig.description,
|
|
3008
|
+
};
|
|
3009
|
+
// Write back
|
|
3010
|
+
await fs_1.promises.writeFile(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
|
|
3011
|
+
// Also save any additional source files
|
|
3012
|
+
for (const file of files) {
|
|
3013
|
+
if (file.path !== "mcp.json" &&
|
|
3014
|
+
!file.path.endsWith("/mcp.json")) {
|
|
3015
|
+
const filePath = path.join(mcpDir, artifact.slug, file.path);
|
|
3016
|
+
await fs_1.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
3017
|
+
await fs_1.promises.writeFile(filePath, file.content);
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
});
|
|
3021
|
+
// Register the installed MCP in local registry
|
|
3022
|
+
const { getRegistry } = await import("./registry/index.js");
|
|
3023
|
+
const registry = getRegistry(outputChannel);
|
|
3024
|
+
await registry.registerMcp({
|
|
3025
|
+
slug: artifact.slug,
|
|
3026
|
+
displayName: artifact.slug,
|
|
3027
|
+
transport: "stdio",
|
|
3028
|
+
latestVersion: artifact.version || "main",
|
|
3029
|
+
tags: [],
|
|
3030
|
+
stats: { installs: 1 },
|
|
3031
|
+
agentPackId: targetPack.label,
|
|
3032
|
+
});
|
|
3033
|
+
// Invalidate local index cache so merged search sees the new item
|
|
3034
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
3035
|
+
invalidateLocalIndex();
|
|
3036
|
+
showInfo(`Installed MCP "${artifact.slug}" v${artifact.version} to ${targetPack.label}`);
|
|
3037
|
+
}));
|
|
3038
|
+
// Install custom engine from store or external GitHub
|
|
3039
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.engine.install", async (artifactArg) => {
|
|
3040
|
+
const { downloadFromStore, downloadFromExternalGitHub, listStoreVersions, isStoreUrl, parseGitHubUrl, parseStoreUrl, } = await import("./store/index.js");
|
|
3041
|
+
const { installCustomEngineFromFiles } = await import("./engines/install.js");
|
|
3042
|
+
let artifact = artifactArg;
|
|
3043
|
+
if (!artifact) {
|
|
3044
|
+
const url = await vscode.window.showInputBox({
|
|
3045
|
+
prompt: "Enter custom engine store URL or GitHub URL",
|
|
3046
|
+
placeHolder: "e.g., engine/gemini or https://github.com/user/repo/tree/main/gemini",
|
|
3047
|
+
});
|
|
3048
|
+
if (!url) {
|
|
3049
|
+
return;
|
|
3050
|
+
}
|
|
3051
|
+
if (isStoreUrl(url)) {
|
|
3052
|
+
artifact = parseStoreUrl(url);
|
|
3053
|
+
}
|
|
3054
|
+
else {
|
|
3055
|
+
const parsed = parseGitHubUrl(url);
|
|
3056
|
+
const pathParts = (parsed.path || parsed.repo).split("/");
|
|
3057
|
+
artifact = {
|
|
3058
|
+
type: "engine",
|
|
3059
|
+
slug: pathParts[pathParts.length - 1] || parsed.repo,
|
|
3060
|
+
version: parsed.ref,
|
|
3061
|
+
sourceUrl: url,
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
const isExternal = artifact.sourceUrl && !isStoreUrl(artifact.sourceUrl);
|
|
3066
|
+
if (!artifact.version && !isExternal) {
|
|
3067
|
+
const versions = await listStoreVersions("engine", artifact.slug);
|
|
3068
|
+
if (versions.length === 0) {
|
|
3069
|
+
artifact.version = "main";
|
|
3070
|
+
}
|
|
3071
|
+
else {
|
|
3072
|
+
const selected = await vscode.window.showQuickPick(versions.map((v) => ({
|
|
3073
|
+
label: v.version,
|
|
3074
|
+
description: v.isPrerelease ? "(pre-release)" : "",
|
|
3075
|
+
})), { placeHolder: "Select version to install" });
|
|
3076
|
+
if (!selected) {
|
|
3077
|
+
return;
|
|
3078
|
+
}
|
|
3079
|
+
artifact.version = selected.label;
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
const installOnce = async (overwrite) => {
|
|
3083
|
+
return await vscode.window.withProgress({
|
|
3084
|
+
location: vscode.ProgressLocation.Window,
|
|
3085
|
+
title: `Installing engine "${artifact.slug}"`,
|
|
3086
|
+
cancellable: false,
|
|
3087
|
+
}, async (progress) => {
|
|
3088
|
+
let files;
|
|
3089
|
+
if (isExternal && artifact.sourceUrl) {
|
|
3090
|
+
progress.report({ message: "Downloading from GitHub..." });
|
|
3091
|
+
const parsed = parseGitHubUrl(artifact.sourceUrl);
|
|
3092
|
+
files = await downloadFromExternalGitHub({
|
|
3093
|
+
owner: parsed.owner,
|
|
3094
|
+
repo: parsed.repo,
|
|
3095
|
+
ref: parsed.ref || "main",
|
|
3096
|
+
path: parsed.path,
|
|
3097
|
+
}, outputChannel);
|
|
3098
|
+
}
|
|
3099
|
+
else {
|
|
3100
|
+
progress.report({ message: "Downloading from store..." });
|
|
3101
|
+
files = await downloadFromStore({
|
|
3102
|
+
type: "engine",
|
|
3103
|
+
slug: artifact.slug,
|
|
3104
|
+
version: artifact.version,
|
|
3105
|
+
}, outputChannel);
|
|
3106
|
+
}
|
|
3107
|
+
progress.report({ message: "Validating and installing..." });
|
|
3108
|
+
return await installCustomEngineFromFiles(files, {
|
|
3109
|
+
slug: artifact.slug,
|
|
3110
|
+
version: artifact.version,
|
|
3111
|
+
sourceUrl: artifact.sourceUrl,
|
|
3112
|
+
overwrite,
|
|
3113
|
+
logger: outputChannel,
|
|
3114
|
+
});
|
|
3115
|
+
});
|
|
3116
|
+
};
|
|
3117
|
+
let result;
|
|
3118
|
+
try {
|
|
3119
|
+
result = await installOnce(false);
|
|
3120
|
+
}
|
|
3121
|
+
catch (error) {
|
|
3122
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
3123
|
+
if (!errorMsg.includes("already exists")) {
|
|
3124
|
+
log(outputChannel, `[AgentIDE] Engine install error: ${errorMsg}`);
|
|
3125
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
3126
|
+
return;
|
|
3127
|
+
}
|
|
3128
|
+
const overwrite = await vscode.window.showWarningMessage(errorMsg, { modal: true }, "Overwrite", "Cancel");
|
|
3129
|
+
if (overwrite !== "Overwrite") {
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
3132
|
+
try {
|
|
3133
|
+
result = await installOnce(true);
|
|
3134
|
+
}
|
|
3135
|
+
catch (retryError) {
|
|
3136
|
+
const retryMsg = retryError instanceof Error ? retryError.message : String(retryError);
|
|
3137
|
+
log(outputChannel, `[AgentIDE] Engine install error: ${retryMsg}`);
|
|
3138
|
+
showError(`AgentIDE: ${retryMsg}`);
|
|
3139
|
+
return;
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
3143
|
+
invalidateLocalIndex();
|
|
3144
|
+
if (!result) {
|
|
3145
|
+
return;
|
|
3146
|
+
}
|
|
3147
|
+
clearCustomEngineRuntimeCache(state, result.id);
|
|
3148
|
+
await refreshCustomEnginePicker(outputChannel);
|
|
3149
|
+
const action = await vscode.window.showInformationMessage(`Installed engine "${result.displayName}"`, "List Engines");
|
|
3150
|
+
if (action === "List Engines") {
|
|
3151
|
+
await vscode.commands.executeCommand("agentide.customEngine.list");
|
|
3152
|
+
}
|
|
3153
|
+
}));
|
|
3154
|
+
// Install Spotlight view from store or external GitHub
|
|
3155
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.view.install", async (artifactArg) => {
|
|
3156
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
3157
|
+
const { downloadFromStore, downloadFromExternalGitHub, listStoreVersions, isStoreUrl, parseGitHubUrl, parseStoreUrl, } = await import("./store/index.js");
|
|
3158
|
+
const { installSpotlightViewFromFiles } = await import("./spotlight/install.js");
|
|
3159
|
+
let artifact = artifactArg;
|
|
3160
|
+
if (!artifact) {
|
|
3161
|
+
const url = await vscode.window.showInputBox({
|
|
3162
|
+
prompt: "Enter Spotlight view store URL or GitHub URL",
|
|
3163
|
+
placeHolder: "e.g., view/cost-ops or https://github.com/user/repo/tree/main/spotlight/cost-ops",
|
|
3164
|
+
});
|
|
3165
|
+
if (!url) {
|
|
3166
|
+
return;
|
|
3167
|
+
}
|
|
3168
|
+
if (isStoreUrl(url)) {
|
|
3169
|
+
artifact = parseStoreUrl(url);
|
|
3170
|
+
}
|
|
3171
|
+
else {
|
|
3172
|
+
const parsed = parseGitHubUrl(url);
|
|
3173
|
+
const pathParts = (parsed.path || parsed.repo).split("/");
|
|
3174
|
+
artifact = {
|
|
3175
|
+
type: "view",
|
|
3176
|
+
slug: pathParts[pathParts.length - 1] || parsed.repo,
|
|
3177
|
+
version: parsed.ref,
|
|
3178
|
+
sourceUrl: url,
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
const isExternal = artifact.sourceUrl && !isStoreUrl(artifact.sourceUrl);
|
|
3183
|
+
if (!artifact.version && !isExternal) {
|
|
3184
|
+
const versions = await listStoreVersions("view", artifact.slug);
|
|
3185
|
+
if (versions.length === 0) {
|
|
3186
|
+
artifact.version = "main";
|
|
3187
|
+
}
|
|
3188
|
+
else {
|
|
3189
|
+
const selected = await vscode.window.showQuickPick(versions.map((v) => ({
|
|
3190
|
+
label: v.version,
|
|
3191
|
+
description: v.isPrerelease ? "(pre-release)" : "",
|
|
3192
|
+
})), { placeHolder: "Select version to install" });
|
|
3193
|
+
if (!selected) {
|
|
3194
|
+
return;
|
|
3195
|
+
}
|
|
3196
|
+
artifact.version = selected.label;
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
const installOnce = async (overwrite, activate) => {
|
|
3200
|
+
return await vscode.window.withProgress({
|
|
3201
|
+
location: vscode.ProgressLocation.Window,
|
|
3202
|
+
title: `Installing Spotlight view "${artifact.slug}"`,
|
|
3203
|
+
cancellable: false,
|
|
3204
|
+
}, async (progress) => {
|
|
3205
|
+
let files;
|
|
3206
|
+
if (isExternal && artifact.sourceUrl) {
|
|
3207
|
+
progress.report({ message: "Downloading from GitHub..." });
|
|
3208
|
+
const parsed = parseGitHubUrl(artifact.sourceUrl);
|
|
3209
|
+
const externalFiles = await downloadFromExternalGitHub({
|
|
3210
|
+
owner: parsed.owner,
|
|
3211
|
+
repo: parsed.repo,
|
|
3212
|
+
ref: parsed.ref || "main",
|
|
3213
|
+
path: parsed.path,
|
|
3214
|
+
}, outputChannel);
|
|
3215
|
+
files = externalFiles.map((file) => ({
|
|
3216
|
+
path: file.path,
|
|
3217
|
+
content: file.content,
|
|
3218
|
+
}));
|
|
3219
|
+
}
|
|
3220
|
+
else {
|
|
3221
|
+
progress.report({ message: "Downloading from store..." });
|
|
3222
|
+
const storeFiles = await downloadFromStore({
|
|
3223
|
+
type: "view",
|
|
3224
|
+
slug: artifact.slug,
|
|
3225
|
+
version: artifact.version,
|
|
3226
|
+
}, outputChannel);
|
|
3227
|
+
files = storeFiles;
|
|
3228
|
+
}
|
|
3229
|
+
progress.report({ message: "Installing view..." });
|
|
3230
|
+
return await installSpotlightViewFromFiles(files, {
|
|
3231
|
+
slug: artifact.slug,
|
|
3232
|
+
version: artifact.version,
|
|
3233
|
+
overwrite,
|
|
3234
|
+
activate,
|
|
3235
|
+
workspaceRoot,
|
|
3236
|
+
logger: outputChannel,
|
|
3237
|
+
});
|
|
3238
|
+
});
|
|
3239
|
+
};
|
|
3240
|
+
let result;
|
|
3241
|
+
try {
|
|
3242
|
+
result = await installOnce(false, false);
|
|
3243
|
+
}
|
|
3244
|
+
catch (error) {
|
|
3245
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
3246
|
+
if (!errorMsg.includes("already exists")) {
|
|
3247
|
+
log(outputChannel, `[AgentIDE] Spotlight view install error: ${errorMsg}`);
|
|
3248
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
const overwrite = await vscode.window.showWarningMessage(errorMsg, { modal: true }, "Overwrite", "Cancel");
|
|
3252
|
+
if (overwrite !== "Overwrite") {
|
|
3253
|
+
return;
|
|
3254
|
+
}
|
|
3255
|
+
try {
|
|
3256
|
+
result = await installOnce(true, false);
|
|
3257
|
+
}
|
|
3258
|
+
catch (retryError) {
|
|
3259
|
+
const retryMsg = retryError instanceof Error ? retryError.message : String(retryError);
|
|
3260
|
+
log(outputChannel, `[AgentIDE] Spotlight view install error: ${retryMsg}`);
|
|
3261
|
+
showError(`AgentIDE: ${retryMsg}`);
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
const { invalidateLocalIndex } = await import("./store/oramaIndex.js");
|
|
3266
|
+
invalidateLocalIndex();
|
|
3267
|
+
if (!result) {
|
|
3268
|
+
return;
|
|
3269
|
+
}
|
|
3270
|
+
const dashboard = _state?.analyticsDashboard;
|
|
3271
|
+
if (dashboard) {
|
|
3272
|
+
await dashboard.refreshViewsFromDisk();
|
|
3273
|
+
}
|
|
3274
|
+
const action = await vscode.window.showInformationMessage(`Installed Spotlight view "${result.id}" v${result.version || artifact.version || "main"}`, "Open Spotlight", "Activate View");
|
|
3275
|
+
if (action === "Open Spotlight") {
|
|
3276
|
+
await vscode.commands.executeCommand("agentide.analytics.openDashboard");
|
|
3277
|
+
}
|
|
3278
|
+
else if (action === "Activate View") {
|
|
3279
|
+
const { setActiveSpotlightView } = await import("./spotlight/install.js");
|
|
3280
|
+
await setActiveSpotlightView(result.viewsConfigPath, result.id);
|
|
3281
|
+
const dashboardAfterActivate = _state?.analyticsDashboard;
|
|
3282
|
+
if (dashboardAfterActivate) {
|
|
3283
|
+
await dashboardAfterActivate.refreshViewsFromDisk();
|
|
3284
|
+
}
|
|
3285
|
+
await vscode.commands.executeCommand("agentide.analytics.openDashboard");
|
|
3286
|
+
}
|
|
3287
|
+
}));
|
|
3288
|
+
// Update agent from User Library
|
|
3289
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.update", async () => {
|
|
3290
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
3291
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
3292
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
3293
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
3294
|
+
const updatable = [];
|
|
3295
|
+
for (const pack of packs) {
|
|
3296
|
+
if (pack.id === "default") {
|
|
3297
|
+
continue;
|
|
3298
|
+
}
|
|
3299
|
+
const newVersion = await packManager.checkAgentUpdate(pack.id);
|
|
3300
|
+
if (newVersion) {
|
|
3301
|
+
updatable.push({ id: pack.id, version: pack.version, newVersion });
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
if (updatable.length === 0) {
|
|
3305
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: All agents are up to date`);
|
|
3306
|
+
return;
|
|
3307
|
+
}
|
|
3308
|
+
const items = updatable.map((u) => ({
|
|
3309
|
+
label: u.id,
|
|
3310
|
+
description: `v${u.version} → v${u.newVersion}`,
|
|
3311
|
+
}));
|
|
3312
|
+
const selected = await vscode.window.showQuickPick(items, {
|
|
3313
|
+
placeHolder: "Select an agent to update",
|
|
3314
|
+
title: "Update Agent from User Library",
|
|
3315
|
+
});
|
|
3316
|
+
if (!selected) {
|
|
3317
|
+
return;
|
|
3318
|
+
}
|
|
3319
|
+
const confirm = await vscode.window.showWarningMessage(`Update "${selected.label}" from User Library? Current version will be backed up.`, { modal: true }, "Update", "Cancel");
|
|
3320
|
+
if (confirm !== "Update") {
|
|
3321
|
+
return;
|
|
3322
|
+
}
|
|
3323
|
+
try {
|
|
3324
|
+
const version = await packManager.updateFromLibrary(selected.label);
|
|
3325
|
+
showInfo(`AgentIDE: Updated "${selected.label}" to v${version}`);
|
|
3326
|
+
}
|
|
3327
|
+
catch (e) {
|
|
3328
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
3329
|
+
log(outputChannel, `[AgentIDE] Update error: ${errorMsg}`);
|
|
3330
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
3331
|
+
}
|
|
3332
|
+
}));
|
|
3333
|
+
// Duplicate agent
|
|
3334
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.duplicate", async () => {
|
|
3335
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
3336
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
3337
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
3338
|
+
const packs = await packManager.listInstalledWithCleanup();
|
|
3339
|
+
if (packs.length === 0) {
|
|
3340
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No agents to duplicate`);
|
|
3341
|
+
return;
|
|
3342
|
+
}
|
|
3343
|
+
const items = packs.map((p) => ({
|
|
3344
|
+
label: p.id,
|
|
3345
|
+
description: `v${p.version}`,
|
|
3346
|
+
}));
|
|
3347
|
+
const selected = await vscode.window.showQuickPick(items, {
|
|
3348
|
+
placeHolder: "Select an agent to duplicate",
|
|
3349
|
+
title: "Duplicate Agent",
|
|
3350
|
+
});
|
|
3351
|
+
if (!selected) {
|
|
3352
|
+
return;
|
|
3353
|
+
}
|
|
3354
|
+
try {
|
|
3355
|
+
const newAgentId = await packManager.duplicate(selected.label);
|
|
3356
|
+
showInfo(`AgentIDE: Created "${newAgentId}" as copy of "${selected.label}"`);
|
|
3357
|
+
// Open the new agent's AGENTS.md
|
|
3358
|
+
const agentsPath = path.join((0, paths_1.getAgentideDir)(workspaceRoot), paths_1.AGENT_CONSTANTS.AGENTS_DIR, newAgentId, paths_1.AGENT_CONSTANTS.AGENTS_MD);
|
|
3359
|
+
if (await (0, utils_1.pathExists)(agentsPath)) {
|
|
3360
|
+
const doc = await vscode.workspace.openTextDocument(agentsPath);
|
|
3361
|
+
await vscode.window.showTextDocument(doc);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
catch (e) {
|
|
3365
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
3366
|
+
log(outputChannel, `[AgentIDE] Duplicate error: ${errorMsg}`);
|
|
3367
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
3368
|
+
}
|
|
3369
|
+
}));
|
|
3370
|
+
// Refresh/discover packs - finds and registers any new packs on disk
|
|
3371
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.refresh", async () => {
|
|
3372
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
3373
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
3374
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
3375
|
+
try {
|
|
3376
|
+
const { registered } = await packManager.repairUnregisteredAgents();
|
|
3377
|
+
if (registered.length > 0) {
|
|
3378
|
+
showInfo(`AgentIDE: Discovered ${registered.length} new pack(s): ${registered.join(", ")}`);
|
|
3379
|
+
}
|
|
3380
|
+
else {
|
|
3381
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: No new packs found`);
|
|
3382
|
+
}
|
|
3383
|
+
return { registered };
|
|
3384
|
+
}
|
|
3385
|
+
catch (e) {
|
|
3386
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
3387
|
+
log(outputChannel, `[AgentIDE] Pack refresh error: ${errorMsg}`);
|
|
3388
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
3389
|
+
return { registered: [] };
|
|
3390
|
+
}
|
|
3391
|
+
}));
|
|
3392
|
+
// Reset default agent
|
|
3393
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.pack.resetDefault", async () => {
|
|
3394
|
+
const confirm = await vscode.window.showWarningMessage("Reset the default agent? This will restore it from bundled templates. Current default agent will be backed up.", { modal: true }, "Reset", "Cancel");
|
|
3395
|
+
if (confirm !== "Reset") {
|
|
3396
|
+
return;
|
|
3397
|
+
}
|
|
3398
|
+
const { workspaceRoot } = getWorkspaceRoot(outputChannel);
|
|
3399
|
+
const { AgentPackManager } = await import("./agentpack/index.js");
|
|
3400
|
+
const packManager = new AgentPackManager(syncService, () => workspaceRoot, () => config.storagePath, outputChannel);
|
|
3401
|
+
try {
|
|
3402
|
+
await packManager.resetDefault(getBundledBasePromptsDir());
|
|
3403
|
+
showInfo(`${branding_1.AGENTIDE_BRAND_NAME}: Default agent reset from bundled templates`);
|
|
3404
|
+
// Force sync
|
|
3405
|
+
await syncService.flushAgentideRootUpdate(workspaceRoot, outputChannel, { force: true, allowDuringActiveTurn: true });
|
|
3406
|
+
}
|
|
3407
|
+
catch (e) {
|
|
3408
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
3409
|
+
log(outputChannel, `[AgentIDE] Reset error: ${errorMsg}`);
|
|
3410
|
+
showError(`AgentIDE: ${errorMsg}`);
|
|
3411
|
+
}
|
|
3412
|
+
}));
|
|
3413
|
+
// Main chat command
|
|
3414
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.chat", async (args) => {
|
|
3415
|
+
return handleChatCommand(state, args);
|
|
3416
|
+
}));
|
|
3417
|
+
// Cancel an in-flight streamed chat run
|
|
3418
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.chat.cancel", async (args) => {
|
|
3419
|
+
const streamId = args?.streamId;
|
|
3420
|
+
if (!streamId) {
|
|
3421
|
+
return { cancelled: false, error: "streamId is required" };
|
|
3422
|
+
}
|
|
3423
|
+
const run = _activeRunsByStreamId.get(streamId);
|
|
3424
|
+
if (!run) {
|
|
3425
|
+
log(outputChannel, `[AgentIDE] Cancel ignored: no active run for streamId=${streamId}`);
|
|
3426
|
+
rejectPendingQuestionsForStream(streamId, 'Run cancelled');
|
|
3427
|
+
return { cancelled: false };
|
|
3428
|
+
}
|
|
3429
|
+
log(outputChannel, `[AgentIDE] Cancel requested: streamId=${streamId}, engine=${run.engine}, ageMs=${Date.now() - run.startedAt}`);
|
|
3430
|
+
try {
|
|
3431
|
+
run.abortController.abort();
|
|
3432
|
+
}
|
|
3433
|
+
catch {
|
|
3434
|
+
// ignore
|
|
3435
|
+
}
|
|
3436
|
+
rejectPendingQuestionsForStream(streamId, 'Run cancelled');
|
|
3437
|
+
return { cancelled: true };
|
|
3438
|
+
}));
|
|
3439
|
+
context.subscriptions.push(vscode.commands.registerCommand("agentide.chat.answerQuestion", async (args) => {
|
|
3440
|
+
const streamId = args?.streamId;
|
|
3441
|
+
const questionId = args?.questionId;
|
|
3442
|
+
if (!streamId || !questionId) {
|
|
3443
|
+
return { ok: false, error: 'streamId and questionId are required' };
|
|
3444
|
+
}
|
|
3445
|
+
const pending = _pendingQuestionsById.get(questionId);
|
|
3446
|
+
if (!pending || pending.streamId !== streamId) {
|
|
3447
|
+
return { ok: false, error: 'Question not found or already resolved' };
|
|
3448
|
+
}
|
|
3449
|
+
const normalized = normalizeQuestionAnswer(args?.answer);
|
|
3450
|
+
resolvePendingQuestion(questionId, normalized);
|
|
3451
|
+
return { ok: true };
|
|
3452
|
+
}));
|
|
3453
|
+
}
|
|
3454
|
+
// -----------------------------------------------------------------------------
|
|
3455
|
+
// User Permission Mapping
|
|
3456
|
+
// -----------------------------------------------------------------------------
|
|
3457
|
+
/**
|
|
3458
|
+
* Get user permissions from VS Code settings (unified model).
|
|
3459
|
+
*/
|
|
3460
|
+
function getUserPermissions() {
|
|
3461
|
+
const cfg = vscode.workspace.getConfiguration("agentide");
|
|
3462
|
+
return {
|
|
3463
|
+
fileAccess: cfg.get("permissions.fileAccess", "full"),
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
function getConfiguredAdditionalEngineDir() {
|
|
3467
|
+
return vscode.workspace
|
|
3468
|
+
.getConfiguration("agentide")
|
|
3469
|
+
.get("additionalEngineDir");
|
|
3470
|
+
}
|
|
3471
|
+
function clearCustomEngineRuntimeCache(state, engineId) {
|
|
3472
|
+
const customEngine = state.engines.custom;
|
|
3473
|
+
try {
|
|
3474
|
+
customEngine?.clearInstances?.(engineId);
|
|
3475
|
+
}
|
|
3476
|
+
catch (error) {
|
|
3477
|
+
log(state.outputChannel, `[AgentIDE] Custom engine cache clear warning: ${error instanceof Error ? error.message : String(error)}`);
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
async function refreshCustomEnginePicker(outputChannel) {
|
|
3481
|
+
try {
|
|
3482
|
+
await vscode.commands.executeCommand("agentide.engine.refresh");
|
|
3483
|
+
}
|
|
3484
|
+
catch (error) {
|
|
3485
|
+
log(outputChannel, `[AgentIDE] Custom engine picker refresh warning: ${error instanceof Error ? error.message : String(error)}`);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
// -----------------------------------------------------------------------------
|
|
3489
|
+
// Chat Command Handler
|
|
3490
|
+
// -----------------------------------------------------------------------------
|
|
3491
|
+
// Shared session event writer for IDE Layer 2 analytics (singleton to avoid repeated mkdir)
|
|
3492
|
+
const _sessionEventWriter = new sessionEvents_1.SessionEventWriter();
|
|
3493
|
+
async function handleChatCommand(state, args) {
|
|
3494
|
+
const { outputChannel, engines, syncService, config } = state;
|
|
3495
|
+
const { engine: engineId, streamId } = args;
|
|
3496
|
+
let { message } = args;
|
|
3497
|
+
const incomingOptions = args.options ?? {};
|
|
3498
|
+
// Check for gateway request marker: [gw:token]message
|
|
3499
|
+
// If present, extract the token and look up the gateway emitter for composite streaming
|
|
3500
|
+
let gatewayEmitter;
|
|
3501
|
+
const gatewayMarkerMatch = message.match(/^\[gw:(gw-[^\]]+)\]/);
|
|
3502
|
+
if (gatewayMarkerMatch) {
|
|
3503
|
+
const gatewayToken = gatewayMarkerMatch[1];
|
|
3504
|
+
// Strip the marker from the message
|
|
3505
|
+
message = message.slice(gatewayMarkerMatch[0].length);
|
|
3506
|
+
log(outputChannel, `[AgentIDE] Gateway request detected, token=${gatewayToken.slice(0, 20)}...`);
|
|
3507
|
+
// Look up the gateway emitter
|
|
3508
|
+
const { GatewayService } = await import("./gateway/service.js");
|
|
3509
|
+
gatewayEmitter = GatewayService.getGatewayEmitter(gatewayToken);
|
|
3510
|
+
if (gatewayEmitter) {
|
|
3511
|
+
log(outputChannel, `[AgentIDE] Gateway emitter found, will stream to both Chat UI and Gateway`);
|
|
3512
|
+
}
|
|
3513
|
+
else {
|
|
3514
|
+
log(outputChannel, `[AgentIDE] Gateway emitter NOT found for token ${gatewayToken.slice(0, 20)}...`);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
// Resolve workspace root
|
|
3518
|
+
const { workspaceRoot, additionalDirectories, isHomeFallback } = getWorkspaceRoot(outputChannel, incomingOptions.workspaceRoot, incomingOptions.additionalDirectories);
|
|
3519
|
+
if (streamId && isHomeFallback) {
|
|
3520
|
+
await warnHomeFallbackOnce(outputChannel, streamId);
|
|
3521
|
+
}
|
|
3522
|
+
const remoteManifest = await syncService.getActiveAgentManifest(workspaceRoot, outputChannel, syncService.getActivePackId(workspaceRoot) ?? state.activePackId);
|
|
3523
|
+
const remoteUrl = remoteManifest?.spec?.remote?.url?.trim();
|
|
3524
|
+
if (remoteUrl) {
|
|
3525
|
+
return (0, handleRemoteChat_js_1.handleRemoteServeChat)({
|
|
3526
|
+
outputChannel,
|
|
3527
|
+
syncService,
|
|
3528
|
+
sessionEventWriter: _sessionEventWriter,
|
|
3529
|
+
activeRunsByStreamId: _activeRunsByStreamId,
|
|
3530
|
+
rejectPendingQuestionsForStream,
|
|
3531
|
+
askQuestionViaWorkbenchTool,
|
|
3532
|
+
askQuestionFromChatUI,
|
|
3533
|
+
getServeAuth: async () => {
|
|
3534
|
+
if (!_extensionContext) {
|
|
3535
|
+
return undefined;
|
|
3536
|
+
}
|
|
3537
|
+
const session = await (0, provider_js_1.getAgentHippoAccessToken)(_extensionContext);
|
|
3538
|
+
if (!session) {
|
|
3539
|
+
return undefined;
|
|
3540
|
+
}
|
|
3541
|
+
return {
|
|
3542
|
+
accessToken: session.accessToken,
|
|
3543
|
+
userEmail: session.email,
|
|
3544
|
+
};
|
|
3545
|
+
},
|
|
3546
|
+
ensureSignedIn: async () => {
|
|
3547
|
+
if (!_extensionContext) {
|
|
3548
|
+
return undefined;
|
|
3549
|
+
}
|
|
3550
|
+
const session = await (0, signInFlow_js_1.ensureAgentHippoSignedIn)(_extensionContext);
|
|
3551
|
+
if (!session) {
|
|
3552
|
+
return undefined;
|
|
3553
|
+
}
|
|
3554
|
+
return {
|
|
3555
|
+
accessToken: session.accessToken,
|
|
3556
|
+
userEmail: session.email,
|
|
3557
|
+
};
|
|
3558
|
+
},
|
|
3559
|
+
log,
|
|
3560
|
+
}, {
|
|
3561
|
+
engine: engineId,
|
|
3562
|
+
message,
|
|
3563
|
+
options: args.options,
|
|
3564
|
+
streamId,
|
|
3565
|
+
sessionResource: args.sessionResource,
|
|
3566
|
+
requestId: args.requestId,
|
|
3567
|
+
remoteUrl,
|
|
3568
|
+
remoteManifest,
|
|
3569
|
+
workspaceRoot,
|
|
3570
|
+
incomingOptions,
|
|
3571
|
+
gatewayEmitter,
|
|
3572
|
+
});
|
|
3573
|
+
}
|
|
3574
|
+
// Build resolved options (include activePackId from state)
|
|
3575
|
+
let options = {
|
|
3576
|
+
...incomingOptions,
|
|
3577
|
+
workspaceRoot,
|
|
3578
|
+
additionalDirectories,
|
|
3579
|
+
agentPackId: state.activePackId, // Pass active pack to engine
|
|
3580
|
+
// agentPackVersion is set below after manifest is loaded
|
|
3581
|
+
};
|
|
3582
|
+
if (!streamId) {
|
|
3583
|
+
return {
|
|
3584
|
+
error: "streamId is required - non-streaming mode is no longer supported",
|
|
3585
|
+
};
|
|
3586
|
+
}
|
|
3587
|
+
// Resolve engine. Custom engine IDs are routed through the dynamic custom loader.
|
|
3588
|
+
let runtimeEngineId = engineId;
|
|
3589
|
+
let engine = engines[runtimeEngineId];
|
|
3590
|
+
if (!engine &&
|
|
3591
|
+
runtimeEngineId !== "codex" &&
|
|
3592
|
+
runtimeEngineId !== "claude" &&
|
|
3593
|
+
engines.custom) {
|
|
3594
|
+
options = {
|
|
3595
|
+
...options,
|
|
3596
|
+
engineId: options.engineId ?? runtimeEngineId,
|
|
3597
|
+
};
|
|
3598
|
+
runtimeEngineId = "custom";
|
|
3599
|
+
engine = engines.custom;
|
|
3600
|
+
log(outputChannel, `[AgentIDE] Routing requested engine "${engineId}" through custom runtime loader`);
|
|
3601
|
+
}
|
|
3602
|
+
if (!engine) {
|
|
3603
|
+
const errorMsg = `Unknown engine: ${engineId}`;
|
|
3604
|
+
log(outputChannel, `[AgentIDE] Error: ${errorMsg}`);
|
|
3605
|
+
return { error: errorMsg };
|
|
3606
|
+
}
|
|
3607
|
+
log(outputChannel, `[AgentIDE] Chat request for engine=${engineId} (runtime=${runtimeEngineId}), streamId: ${streamId}, useLiteLLM: ${options.useLiteLLM || false}`);
|
|
3608
|
+
// Create per-run abort controller so Workbench can cancel this stream
|
|
3609
|
+
const abortController = new AbortController();
|
|
3610
|
+
_activeRunsByStreamId.set(streamId, {
|
|
3611
|
+
streamId,
|
|
3612
|
+
engine: runtimeEngineId,
|
|
3613
|
+
startedAt: Date.now(),
|
|
3614
|
+
abortController,
|
|
3615
|
+
});
|
|
3616
|
+
// Create emitter - if gateway emitter is present, create a composite that streams to both
|
|
3617
|
+
const ipcEmitter = (0, utils_1.createIPCStreamEmitter)(streamId);
|
|
3618
|
+
const chatSessionResource = args.sessionResource;
|
|
3619
|
+
const chatRequestId = args.requestId;
|
|
3620
|
+
const questionEmitter = {
|
|
3621
|
+
...ipcEmitter,
|
|
3622
|
+
async question(payload) {
|
|
3623
|
+
// Use workbench askQuestions tool when we have session context (same path as Copilot)
|
|
3624
|
+
if (chatSessionResource) {
|
|
3625
|
+
return await askQuestionViaWorkbenchTool(chatSessionResource, chatRequestId, payload, abortController.signal);
|
|
3626
|
+
}
|
|
3627
|
+
return await askQuestionFromChatUI(streamId, payload);
|
|
3628
|
+
},
|
|
3629
|
+
};
|
|
3630
|
+
const emitter = gatewayEmitter ? {
|
|
3631
|
+
...questionEmitter,
|
|
3632
|
+
// Composite emitter: streams to both Chat UI (via IPC) and Gateway (via websocket)
|
|
3633
|
+
async thinking(delta) {
|
|
3634
|
+
await ipcEmitter.thinking(delta);
|
|
3635
|
+
// Send to Gateway with raw tags for CLI formatting
|
|
3636
|
+
await gatewayEmitter.thinking(`<thinking>${delta}</thinking>`);
|
|
3637
|
+
},
|
|
3638
|
+
async text(delta) {
|
|
3639
|
+
await ipcEmitter.text(delta);
|
|
3640
|
+
await gatewayEmitter.text(delta);
|
|
3641
|
+
},
|
|
3642
|
+
async toolStart(toolName, input, toolCallId, metadata) {
|
|
3643
|
+
await ipcEmitter.toolStart(toolName, input, toolCallId, metadata);
|
|
3644
|
+
await gatewayEmitter.toolStart(toolName, input, toolCallId, metadata);
|
|
3645
|
+
},
|
|
3646
|
+
async toolEnd(toolName, toolCallId, result, isError, metadata) {
|
|
3647
|
+
await ipcEmitter.toolEnd(toolName, toolCallId, result, isError, metadata);
|
|
3648
|
+
await gatewayEmitter.toolEnd(toolName, toolCallId, result, isError, metadata);
|
|
3649
|
+
},
|
|
3650
|
+
async progress(msg) {
|
|
3651
|
+
await ipcEmitter.progress(msg);
|
|
3652
|
+
await gatewayEmitter.progress(msg);
|
|
3653
|
+
},
|
|
3654
|
+
async question(payload) {
|
|
3655
|
+
const answer = await questionEmitter.question(payload);
|
|
3656
|
+
await gatewayEmitter.progress(`Question answered: ${questionPromptToHeader(payload.prompt)}`);
|
|
3657
|
+
return answer;
|
|
3658
|
+
},
|
|
3659
|
+
async error(msg) {
|
|
3660
|
+
await ipcEmitter.error(msg);
|
|
3661
|
+
await gatewayEmitter.error(msg);
|
|
3662
|
+
},
|
|
3663
|
+
async done() {
|
|
3664
|
+
await ipcEmitter.done();
|
|
3665
|
+
await gatewayEmitter.done();
|
|
3666
|
+
},
|
|
3667
|
+
} : questionEmitter;
|
|
3668
|
+
const terminalLog = getTerminalLogInfo(options);
|
|
3669
|
+
await appendTerminalAttachmentsToLog(args.context, streamId, outputChannel, terminalLog?.uri);
|
|
3670
|
+
// Persist image attachments (so agents can read a real file path instead of guessing)
|
|
3671
|
+
await persistImageAttachments(args.context, options, outputChannel);
|
|
3672
|
+
// Persist file/folder attachments (so agents can read them even if they were outside the workspace)
|
|
3673
|
+
await persistFileAndDirectoryAttachments(args.context, options, outputChannel);
|
|
3674
|
+
const contextSuffix = formatSdkContextSuffix(args.context, terminalLog?.relativePath);
|
|
3675
|
+
const enrichedMessage = contextSuffix
|
|
3676
|
+
? `${message}\n\n${contextSuffix}`
|
|
3677
|
+
: message;
|
|
3678
|
+
// Create Layer 2 session event observability (before try so it's accessible in catch)
|
|
3679
|
+
const requestId = (0, base_1.generateRequestId)();
|
|
3680
|
+
const sessionId = options.sessionId ?? `ide-${Date.now()}`;
|
|
3681
|
+
const observableEmitter = (0, sessionEvents_1.wrapEmitterWithObservability)(emitter, _sessionEventWriter, sessionId, requestId);
|
|
3682
|
+
try {
|
|
3683
|
+
// Prepare project sync
|
|
3684
|
+
syncService.incrementActiveAgentTurns();
|
|
3685
|
+
await syncService.ensureAgentideProjectPrepared(workspaceRoot, additionalDirectories, outputChannel);
|
|
3686
|
+
// Always write paths.md for the effective workspaceRoot so users can discover what AgentIDE manages.
|
|
3687
|
+
await syncService.writeManagedPathsManifest(config.codexHome, config.claudeConfigDir, workspaceRoot, additionalDirectories, outputChannel);
|
|
3688
|
+
// Load manifest and resolve permissions
|
|
3689
|
+
const manifest = await syncService.getActiveAgentManifest(workspaceRoot, outputChannel);
|
|
3690
|
+
const manifestPerms = (0, permissions_1.parseManifestPermissions)(manifest);
|
|
3691
|
+
const userPerms = getUserPermissions();
|
|
3692
|
+
const effectivePerms = (0, permissions_1.enforcePermissions)(manifestPerms, userPerms);
|
|
3693
|
+
log(outputChannel, `[AgentIDE] Permissions: manifest(files=${manifestPerms.fileAccess}) + user(files=${userPerms.fileAccess}) = effective(files=${effectivePerms.fileAccess})`);
|
|
3694
|
+
// Add permissions + agent version + requestId to options
|
|
3695
|
+
const optionsWithPerms = {
|
|
3696
|
+
...options,
|
|
3697
|
+
sessionId,
|
|
3698
|
+
permissions: effectivePerms,
|
|
3699
|
+
agentPackVersion: manifest?.metadata?.version,
|
|
3700
|
+
requestId, // Same requestId used by ObservableStreamEmitter for Layer 1/2 correlation
|
|
3701
|
+
};
|
|
3702
|
+
// Create runtime context with VS Code implementations.
|
|
3703
|
+
// V1 permissions are non-interactive; always auto-approve tool requests.
|
|
3704
|
+
const logger = new vscode_logger_1.VSCodeLogger(outputChannel);
|
|
3705
|
+
const permissionHandler = new permission_handler_1.AutoApprovePermissionHandler();
|
|
3706
|
+
const configuredCliPath = vscode.workspace
|
|
3707
|
+
.getConfiguration("agentide")
|
|
3708
|
+
.get("cli.path", "");
|
|
3709
|
+
const cliHealth = await (0, runtime_1.getCliHealth)({
|
|
3710
|
+
configuredPath: configuredCliPath,
|
|
3711
|
+
extensionPath: _extensionContext?.extensionPath,
|
|
3712
|
+
});
|
|
3713
|
+
const userInstalledToolsDir = _extensionContext?.globalState?.get(BUNDLED_TOOLS_DIR_KEY);
|
|
3714
|
+
const cliEnvPatch = (0, runtime_1.buildCliEnvPatch)({
|
|
3715
|
+
cliPath: cliHealth.path,
|
|
3716
|
+
workspaceRoot,
|
|
3717
|
+
agentId: optionsWithPerms.agentPackId ?? 'default',
|
|
3718
|
+
chatSessionId: optionsWithPerms.sessionId?.trim() || optionsWithPerms.contextSessionId?.trim(),
|
|
3719
|
+
baseEnv: process.env,
|
|
3720
|
+
extensionPath: _extensionContext?.extensionPath,
|
|
3721
|
+
userInstalledToolsDir: userInstalledToolsDir ?? undefined,
|
|
3722
|
+
});
|
|
3723
|
+
if (cliEnvPatch.AGENTHIPPO_TOOLS_DIR) {
|
|
3724
|
+
log(outputChannel, `[AgentIDE] Bundled tools dir available for runtime: ${cliEnvPatch.AGENTHIPPO_TOOLS_DIR}`);
|
|
3725
|
+
}
|
|
3726
|
+
const runtimeContext = {
|
|
3727
|
+
logger,
|
|
3728
|
+
editTracker: new vscode_edit_tracker_1.VSCodeEditTracker(new vscode_logger_1.VSCodeLogger(outputChannel, "[EditTracker]")),
|
|
3729
|
+
configProvider: new vscode_config_provider_1.VSCodeConfigProvider(),
|
|
3730
|
+
permissionHandler,
|
|
3731
|
+
cliEnvPatch,
|
|
3732
|
+
};
|
|
3733
|
+
if (cliHealth.installed && cliHealth.path) {
|
|
3734
|
+
log(outputChannel, `[AgentIDE] CLI available for agent runtime: ${cliHealth.path}`);
|
|
3735
|
+
}
|
|
3736
|
+
else {
|
|
3737
|
+
log(outputChannel, `[AgentIDE] CLI not detected for runtime (skills may rely on '${branding_1.AGENTIDE_CLI_NAME}' on PATH)`);
|
|
3738
|
+
}
|
|
3739
|
+
log(outputChannel, `[AgentIDE] Analytics: session=${sessionId}, request=${requestId}, agent=${optionsWithPerms.agentPackId ?? 'default'}, version=${optionsWithPerms.agentPackVersion ?? 'workspace'}`);
|
|
3740
|
+
// Emit turn_start event
|
|
3741
|
+
await observableEmitter.emitTurnStart();
|
|
3742
|
+
// Stream response
|
|
3743
|
+
await engine.stream(enrichedMessage, optionsWithPerms, observableEmitter, runtimeContext, abortController.signal);
|
|
3744
|
+
// Emit turn_end event
|
|
3745
|
+
await observableEmitter.emitTurnEnd(true);
|
|
3746
|
+
return { streaming: true };
|
|
3747
|
+
}
|
|
3748
|
+
catch (err) {
|
|
3749
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
3750
|
+
log(outputChannel, `[AgentIDE] Error: ${errorMsg}`);
|
|
3751
|
+
// Use observableEmitter (not raw emitter) so error is captured in Layer 2 session events
|
|
3752
|
+
await observableEmitter.error(errorMsg);
|
|
3753
|
+
await observableEmitter.emitTurnEnd(false);
|
|
3754
|
+
return { error: errorMsg };
|
|
3755
|
+
}
|
|
3756
|
+
finally {
|
|
3757
|
+
rejectPendingQuestionsForStream(streamId, 'Run finished');
|
|
3758
|
+
_activeRunsByStreamId.delete(streamId);
|
|
3759
|
+
syncService.decrementActiveAgentTurns();
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
function resolveWorkspaceRootUri(workspaceRoot) {
|
|
3763
|
+
const folders = vscode.workspace.workspaceFolders ?? [];
|
|
3764
|
+
const match = folders.find((f) => f.uri.fsPath === workspaceRoot);
|
|
3765
|
+
if (match) {
|
|
3766
|
+
return match.uri;
|
|
3767
|
+
}
|
|
3768
|
+
const primary = folders[0];
|
|
3769
|
+
if (primary && workspaceRoot.startsWith("/")) {
|
|
3770
|
+
// Preserve remote scheme/authority when possible.
|
|
3771
|
+
return vscode.Uri.from({
|
|
3772
|
+
scheme: primary.uri.scheme,
|
|
3773
|
+
authority: primary.uri.authority,
|
|
3774
|
+
path: workspaceRoot,
|
|
3775
|
+
});
|
|
3776
|
+
}
|
|
3777
|
+
return vscode.Uri.file(workspaceRoot);
|
|
3778
|
+
}
|
|
3779
|
+
function dirnameUri(uri) {
|
|
3780
|
+
const idx = uri.path.lastIndexOf("/");
|
|
3781
|
+
return idx >= 0 ? uri.with({ path: uri.path.slice(0, idx) }) : uri;
|
|
3782
|
+
}
|
|
3783
|
+
function getTerminalLogInfo(options) {
|
|
3784
|
+
const contextSessionId = options.contextSessionId?.trim() || options.sessionId?.trim();
|
|
3785
|
+
if (!contextSessionId) {
|
|
3786
|
+
return undefined;
|
|
3787
|
+
}
|
|
3788
|
+
const workspaceRootUri = resolveWorkspaceRootUri(options.workspaceRoot);
|
|
3789
|
+
const uri = vscode.Uri.joinPath(workspaceRootUri, paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME, paths_1.AGENT_CONSTANTS.SESSIONS_DIR, contextSessionId, TERMINAL_LOG_FILE_NAME);
|
|
3790
|
+
return {
|
|
3791
|
+
uri,
|
|
3792
|
+
relativePath: `${AGENTIDE_SESSIONS_DIR_NAME}/${contextSessionId}/${TERMINAL_LOG_FILE_NAME}`,
|
|
3793
|
+
};
|
|
3794
|
+
}
|
|
3795
|
+
function getSessionAttachmentsDirInfo(options) {
|
|
3796
|
+
const contextSessionId = options.contextSessionId?.trim() || options.sessionId?.trim();
|
|
3797
|
+
if (!contextSessionId) {
|
|
3798
|
+
return undefined;
|
|
3799
|
+
}
|
|
3800
|
+
const workspaceRootUri = resolveWorkspaceRootUri(options.workspaceRoot);
|
|
3801
|
+
const dirUri = vscode.Uri.joinPath(workspaceRootUri, paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME, paths_1.AGENT_CONSTANTS.SESSIONS_DIR, contextSessionId, ATTACHMENTS_DIR_NAME);
|
|
3802
|
+
return {
|
|
3803
|
+
dirUri,
|
|
3804
|
+
relativeDirPath: `${AGENTIDE_SESSIONS_DIR_NAME}/${contextSessionId}/${ATTACHMENTS_DIR_NAME}`,
|
|
3805
|
+
};
|
|
3806
|
+
}
|
|
3807
|
+
function slugifyFileStem(name) {
|
|
3808
|
+
const stem = name
|
|
3809
|
+
.toLowerCase()
|
|
3810
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
3811
|
+
.replace(/^-+|-+$/g, "")
|
|
3812
|
+
.slice(0, 60);
|
|
3813
|
+
return stem || "attachment";
|
|
3814
|
+
}
|
|
3815
|
+
function imageExtensionFromMimeType(mimeType) {
|
|
3816
|
+
switch ((mimeType ?? "").toLowerCase()) {
|
|
3817
|
+
case "image/png":
|
|
3818
|
+
return "png";
|
|
3819
|
+
case "image/jpeg":
|
|
3820
|
+
case "image/jpg":
|
|
3821
|
+
return "jpg";
|
|
3822
|
+
case "image/gif":
|
|
3823
|
+
return "gif";
|
|
3824
|
+
case "image/webp":
|
|
3825
|
+
return "webp";
|
|
3826
|
+
default:
|
|
3827
|
+
return "png";
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
async function persistImageAttachments(ctx, options, outputChannel) {
|
|
3831
|
+
const variables = ctx?.variables ?? [];
|
|
3832
|
+
if (!ctx || variables.length === 0) {
|
|
3833
|
+
return;
|
|
3834
|
+
}
|
|
3835
|
+
const images = variables.filter((v) => v.kind === "image" &&
|
|
3836
|
+
typeof v.dataBase64 === "string" &&
|
|
3837
|
+
v.dataBase64.length > 0);
|
|
3838
|
+
if (images.length === 0) {
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
const info = getSessionAttachmentsDirInfo(options);
|
|
3842
|
+
if (!info) {
|
|
3843
|
+
// No stable session folder -> cannot persist; leave bytes for now.
|
|
3844
|
+
log(outputChannel, "[AgentIDE] Note: image attachment present but no contextSessionId; skipping persistence");
|
|
3845
|
+
return;
|
|
3846
|
+
}
|
|
3847
|
+
try {
|
|
3848
|
+
await (0, terminalLogger_1.ensureDirectory)(info.dirUri);
|
|
3849
|
+
}
|
|
3850
|
+
catch (e) {
|
|
3851
|
+
log(outputChannel, `[AgentIDE] Warning: failed to create session attachments dir: ${e instanceof Error ? e.message : String(e)}`);
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
let index = 0;
|
|
3855
|
+
for (const img of images) {
|
|
3856
|
+
index++;
|
|
3857
|
+
const stem = slugifyFileStem(img.name || `image-${index}`);
|
|
3858
|
+
const ext = imageExtensionFromMimeType(img.mimeType);
|
|
3859
|
+
const fileName = images.length > 1 ? `${stem}-${index}.${ext}` : `${stem}.${ext}`;
|
|
3860
|
+
const fileUri = vscode.Uri.joinPath(info.dirUri, fileName);
|
|
3861
|
+
try {
|
|
3862
|
+
const bytes = Buffer.from(img.dataBase64, "base64");
|
|
3863
|
+
await vscode.workspace.fs.writeFile(fileUri, bytes);
|
|
3864
|
+
// Update the variable entry to point at a real workspace path the agent can read.
|
|
3865
|
+
img.uri = `${info.relativeDirPath}/${fileName}`;
|
|
3866
|
+
// Drop bytes from the payload to keep prompt + memory small downstream.
|
|
3867
|
+
delete img.dataBase64;
|
|
3868
|
+
}
|
|
3869
|
+
catch (e) {
|
|
3870
|
+
log(outputChannel, `[AgentIDE] Warning: failed to persist image attachment "${img.name}": ${e instanceof Error ? e.message : String(e)}`);
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
async function persistFileAndDirectoryAttachments(ctx, options, outputChannel) {
|
|
3875
|
+
const variables = ctx?.variables ?? [];
|
|
3876
|
+
if (!ctx || variables.length === 0) {
|
|
3877
|
+
return;
|
|
3878
|
+
}
|
|
3879
|
+
const candidates = variables.filter((v) => (v.kind === "file" || v.kind === "directory") &&
|
|
3880
|
+
typeof v.uri === "string" &&
|
|
3881
|
+
v.uri.trim().length > 0);
|
|
3882
|
+
if (candidates.length === 0) {
|
|
3883
|
+
return;
|
|
3884
|
+
}
|
|
3885
|
+
const info = getSessionAttachmentsDirInfo(options);
|
|
3886
|
+
if (!info) {
|
|
3887
|
+
log(outputChannel, "[AgentIDE] Note: file/folder attachment present but no contextSessionId; skipping persistence");
|
|
3888
|
+
return;
|
|
3889
|
+
}
|
|
3890
|
+
try {
|
|
3891
|
+
await (0, terminalLogger_1.ensureDirectory)(info.dirUri);
|
|
3892
|
+
}
|
|
3893
|
+
catch (e) {
|
|
3894
|
+
log(outputChannel, `[AgentIDE] Warning: failed to create session attachments dir: ${e instanceof Error ? e.message : String(e)}`);
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
const manifestUri = vscode.Uri.joinPath(info.dirUri, "manifest.json");
|
|
3898
|
+
const readManifest = async () => {
|
|
3899
|
+
try {
|
|
3900
|
+
const raw = await vscode.workspace.fs.readFile(manifestUri);
|
|
3901
|
+
const parsed = JSON.parse(Buffer.from(raw).toString("utf8"));
|
|
3902
|
+
if (parsed &&
|
|
3903
|
+
parsed.version === 1 &&
|
|
3904
|
+
typeof parsed.files === "object" &&
|
|
3905
|
+
typeof parsed.directories === "object") {
|
|
3906
|
+
return parsed;
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
catch {
|
|
3910
|
+
// ignore
|
|
3911
|
+
}
|
|
3912
|
+
return { version: 1, files: {}, directories: {} };
|
|
3913
|
+
};
|
|
3914
|
+
const writeManifest = async (manifest) => {
|
|
3915
|
+
try {
|
|
3916
|
+
const bytes = Buffer.from(JSON.stringify(manifest, null, 2), "utf8");
|
|
3917
|
+
await vscode.workspace.fs.writeFile(manifestUri, bytes);
|
|
3918
|
+
}
|
|
3919
|
+
catch {
|
|
3920
|
+
// ignore (best-effort)
|
|
3921
|
+
}
|
|
3922
|
+
};
|
|
3923
|
+
const manifest = await readManifest();
|
|
3924
|
+
let manifestDirty = false;
|
|
3925
|
+
const MAX_FILES = 500;
|
|
3926
|
+
const MAX_TOTAL_BYTES = 25 * 1024 * 1024; // 25MB total per request (best-effort)
|
|
3927
|
+
const MAX_SINGLE_FILE_BYTES = 10 * 1024 * 1024; // 10MB per file (best-effort)
|
|
3928
|
+
let totalFiles = 0;
|
|
3929
|
+
let totalBytes = 0;
|
|
3930
|
+
const isUnder = (parent, candidate) => {
|
|
3931
|
+
try {
|
|
3932
|
+
const parentNorm = path.resolve(parent);
|
|
3933
|
+
const candidateNorm = path.resolve(candidate);
|
|
3934
|
+
const rel = path.relative(parentNorm, candidateNorm);
|
|
3935
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
3936
|
+
}
|
|
3937
|
+
catch {
|
|
3938
|
+
return false;
|
|
3939
|
+
}
|
|
3940
|
+
};
|
|
3941
|
+
const workspaceRoot = options.workspaceRoot;
|
|
3942
|
+
const sessionRootSegment = path.normalize(`${path.sep}${AGENTIDE_SESSIONS_DIR_NAME.split("/").join(path.sep)}${path.sep}`);
|
|
3943
|
+
const exists = async (uri) => {
|
|
3944
|
+
try {
|
|
3945
|
+
await vscode.workspace.fs.stat(uri);
|
|
3946
|
+
return true;
|
|
3947
|
+
}
|
|
3948
|
+
catch {
|
|
3949
|
+
return false;
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
const uniqueNameInDir = async (dir, name) => {
|
|
3953
|
+
let candidateName = name;
|
|
3954
|
+
let attempt = 1;
|
|
3955
|
+
while (await exists(vscode.Uri.joinPath(dir, candidateName))) {
|
|
3956
|
+
attempt++;
|
|
3957
|
+
const ext = path.extname(name);
|
|
3958
|
+
const base = ext ? name.slice(0, -ext.length) : name;
|
|
3959
|
+
candidateName = `${base}-${attempt}${ext}`;
|
|
3960
|
+
}
|
|
3961
|
+
return candidateName;
|
|
3962
|
+
};
|
|
3963
|
+
const copyFile = async (srcPath, destDir) => {
|
|
3964
|
+
const srcUri = vscode.Uri.file(srcPath);
|
|
3965
|
+
try {
|
|
3966
|
+
const stat = await vscode.workspace.fs.stat(srcUri);
|
|
3967
|
+
if (stat.type !== vscode.FileType.File) {
|
|
3968
|
+
return undefined;
|
|
3969
|
+
}
|
|
3970
|
+
const key = `${srcPath}::${stat.size}::${stat.mtime}`;
|
|
3971
|
+
const existing = manifest.files[key];
|
|
3972
|
+
if (existing) {
|
|
3973
|
+
const existingUri = vscode.Uri.joinPath(destDir, existing.destName);
|
|
3974
|
+
if (await exists(existingUri)) {
|
|
3975
|
+
return existing.destName;
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
const baseName = path.basename(srcPath);
|
|
3979
|
+
const destName = await uniqueNameInDir(destDir, baseName || "attachment");
|
|
3980
|
+
const destUri = vscode.Uri.joinPath(destDir, destName);
|
|
3981
|
+
if (stat.size > MAX_SINGLE_FILE_BYTES) {
|
|
3982
|
+
log(outputChannel, `[AgentIDE] Note: skipping large file attachment (${stat.size} bytes): ${srcPath}`);
|
|
3983
|
+
return undefined;
|
|
3984
|
+
}
|
|
3985
|
+
if (totalFiles + 1 > MAX_FILES ||
|
|
3986
|
+
totalBytes + stat.size > MAX_TOTAL_BYTES) {
|
|
3987
|
+
log(outputChannel, "[AgentIDE] Note: skipping additional file attachments due to size limits");
|
|
3988
|
+
return undefined;
|
|
3989
|
+
}
|
|
3990
|
+
const bytes = await vscode.workspace.fs.readFile(srcUri);
|
|
3991
|
+
await vscode.workspace.fs.writeFile(destUri, bytes);
|
|
3992
|
+
totalFiles += 1;
|
|
3993
|
+
totalBytes += stat.size;
|
|
3994
|
+
manifest.files[key] = {
|
|
3995
|
+
destName,
|
|
3996
|
+
sourcePath: srcPath,
|
|
3997
|
+
size: stat.size,
|
|
3998
|
+
mtime: stat.mtime,
|
|
3999
|
+
};
|
|
4000
|
+
manifestDirty = true;
|
|
4001
|
+
return destName;
|
|
4002
|
+
}
|
|
4003
|
+
catch (e) {
|
|
4004
|
+
log(outputChannel, `[AgentIDE] Warning: failed to persist file attachment "${srcPath}": ${e instanceof Error ? e.message : String(e)}`);
|
|
4005
|
+
return undefined;
|
|
4006
|
+
}
|
|
4007
|
+
};
|
|
4008
|
+
const copyDirRecursive = async (srcUri, destUri) => {
|
|
4009
|
+
const entries = await vscode.workspace.fs.readDirectory(srcUri);
|
|
4010
|
+
for (const [name, type] of entries) {
|
|
4011
|
+
if (totalFiles >= MAX_FILES || totalBytes >= MAX_TOTAL_BYTES) {
|
|
4012
|
+
return;
|
|
4013
|
+
}
|
|
4014
|
+
const childSrc = vscode.Uri.joinPath(srcUri, name);
|
|
4015
|
+
const childDest = vscode.Uri.joinPath(destUri, name);
|
|
4016
|
+
if (type === vscode.FileType.Directory) {
|
|
4017
|
+
await (0, terminalLogger_1.ensureDirectory)(childDest);
|
|
4018
|
+
await copyDirRecursive(childSrc, childDest);
|
|
4019
|
+
}
|
|
4020
|
+
else if (type === vscode.FileType.File) {
|
|
4021
|
+
try {
|
|
4022
|
+
const stat = await vscode.workspace.fs.stat(childSrc);
|
|
4023
|
+
if (stat.size > MAX_SINGLE_FILE_BYTES) {
|
|
4024
|
+
continue;
|
|
4025
|
+
}
|
|
4026
|
+
if (totalFiles + 1 > MAX_FILES ||
|
|
4027
|
+
totalBytes + stat.size > MAX_TOTAL_BYTES) {
|
|
4028
|
+
return;
|
|
4029
|
+
}
|
|
4030
|
+
const bytes = await vscode.workspace.fs.readFile(childSrc);
|
|
4031
|
+
await vscode.workspace.fs.writeFile(childDest, bytes);
|
|
4032
|
+
totalFiles += 1;
|
|
4033
|
+
totalBytes += stat.size;
|
|
4034
|
+
}
|
|
4035
|
+
catch {
|
|
4036
|
+
// ignore
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
};
|
|
4041
|
+
for (const v of candidates) {
|
|
4042
|
+
const sourcePath = v.uri.trim();
|
|
4043
|
+
// Only persist absolute, local paths outside the workspace root.
|
|
4044
|
+
if (!path.isAbsolute(sourcePath)) {
|
|
4045
|
+
continue;
|
|
4046
|
+
}
|
|
4047
|
+
if (workspaceRoot && isUnder(workspaceRoot, sourcePath)) {
|
|
4048
|
+
continue;
|
|
4049
|
+
}
|
|
4050
|
+
if (path.normalize(sourcePath).includes(sessionRootSegment)) {
|
|
4051
|
+
continue;
|
|
4052
|
+
}
|
|
4053
|
+
try {
|
|
4054
|
+
const srcUri = vscode.Uri.file(sourcePath);
|
|
4055
|
+
const stat = await vscode.workspace.fs.stat(srcUri);
|
|
4056
|
+
if (stat.type === vscode.FileType.Directory && v.kind === "directory") {
|
|
4057
|
+
const key = `${sourcePath}::${stat.mtime}`;
|
|
4058
|
+
const existing = manifest.directories[key];
|
|
4059
|
+
if (existing) {
|
|
4060
|
+
const existingUri = vscode.Uri.joinPath(info.dirUri, existing.destName);
|
|
4061
|
+
if (await exists(existingUri)) {
|
|
4062
|
+
v.uri = `${info.relativeDirPath}/${existing.destName}`;
|
|
4063
|
+
continue;
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
const baseName = path.basename(sourcePath) || "folder";
|
|
4067
|
+
const destName = await uniqueNameInDir(info.dirUri, baseName);
|
|
4068
|
+
const destDirUri = vscode.Uri.joinPath(info.dirUri, destName);
|
|
4069
|
+
await (0, terminalLogger_1.ensureDirectory)(destDirUri);
|
|
4070
|
+
await copyDirRecursive(srcUri, destDirUri);
|
|
4071
|
+
manifest.directories[key] = { destName, sourcePath, mtime: stat.mtime };
|
|
4072
|
+
manifestDirty = true;
|
|
4073
|
+
v.uri = `${info.relativeDirPath}/${destName}`;
|
|
4074
|
+
}
|
|
4075
|
+
else if (stat.type === vscode.FileType.File && v.kind === "file") {
|
|
4076
|
+
const destName = await copyFile(sourcePath, info.dirUri);
|
|
4077
|
+
if (destName) {
|
|
4078
|
+
v.uri = `${info.relativeDirPath}/${destName}`;
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
catch {
|
|
4083
|
+
// ignore (best-effort)
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
if (manifestDirty) {
|
|
4087
|
+
await writeManifest(manifest);
|
|
4088
|
+
}
|
|
4089
|
+
}
|
|
4090
|
+
async function appendTerminalAttachmentsToLog(ctx, streamId, outputChannel, terminalLogUri) {
|
|
4091
|
+
if (!terminalLogUri) {
|
|
4092
|
+
return;
|
|
4093
|
+
}
|
|
4094
|
+
const variables = ctx?.variables ?? [];
|
|
4095
|
+
// Terminal command attachments (from @terminalCommand or terminal command history)
|
|
4096
|
+
const terminalCmdVars = variables.filter((v) => v.kind === "terminalCommand" &&
|
|
4097
|
+
typeof v.output === "string" &&
|
|
4098
|
+
v.output.trim().length > 0);
|
|
4099
|
+
// Terminal selection attachments (generated by terminal chat tools with a stable id prefix).
|
|
4100
|
+
const terminalSelectionVars = variables.filter((v) => v.kind === "generic" &&
|
|
4101
|
+
typeof v.text === "string" &&
|
|
4102
|
+
v.text.trim().length > 0 &&
|
|
4103
|
+
(v.isTerminalSelection ||
|
|
4104
|
+
(typeof v.id === "string" && v.id.startsWith("terminal-selection-"))));
|
|
4105
|
+
if (terminalCmdVars.length === 0 && terminalSelectionVars.length === 0) {
|
|
4106
|
+
return;
|
|
4107
|
+
}
|
|
4108
|
+
try {
|
|
4109
|
+
await (0, terminalLogger_1.ensureDirectory)(dirnameUri(terminalLogUri));
|
|
4110
|
+
const nowIso = new Date().toISOString();
|
|
4111
|
+
const lines = [];
|
|
4112
|
+
lines.push(`<!-- TERMINAL_ATTACHMENTS STREAM:${streamId} TIME:${nowIso} -->`);
|
|
4113
|
+
lines.push("");
|
|
4114
|
+
// Write terminal command outputs
|
|
4115
|
+
for (const t of terminalCmdVars) {
|
|
4116
|
+
const cmd = (t.command ?? t.name ?? "").toString().trim();
|
|
4117
|
+
lines.push("## Terminal Command");
|
|
4118
|
+
if (cmd) {
|
|
4119
|
+
lines.push(`- Command: ${cmd}`);
|
|
4120
|
+
}
|
|
4121
|
+
if (typeof t.exitCode === "number") {
|
|
4122
|
+
lines.push(`- Exit code: ${t.exitCode}`);
|
|
4123
|
+
}
|
|
4124
|
+
if (t.uri) {
|
|
4125
|
+
lines.push(`- Resource: ${t.uri}`);
|
|
4126
|
+
}
|
|
4127
|
+
lines.push("");
|
|
4128
|
+
lines.push("```text");
|
|
4129
|
+
lines.push(t.output ?? "");
|
|
4130
|
+
lines.push("```");
|
|
4131
|
+
lines.push("");
|
|
4132
|
+
}
|
|
4133
|
+
// Write terminal selection content
|
|
4134
|
+
for (const t of terminalSelectionVars) {
|
|
4135
|
+
const title = t.name || "Terminal Selection";
|
|
4136
|
+
lines.push(`## ${title}`);
|
|
4137
|
+
lines.push("");
|
|
4138
|
+
lines.push("```text");
|
|
4139
|
+
lines.push(t.text ?? "");
|
|
4140
|
+
lines.push("```");
|
|
4141
|
+
lines.push("");
|
|
4142
|
+
}
|
|
4143
|
+
lines.push(`<!-- TERMINAL_ATTACHMENTS_END STREAM:${streamId} -->`);
|
|
4144
|
+
lines.push("");
|
|
4145
|
+
await (0, terminalLogger_1.appendTextFileWithRotation)(terminalLogUri, lines.join("\n"), MAX_TERMINAL_LOG_BYTES);
|
|
4146
|
+
}
|
|
4147
|
+
catch (e) {
|
|
4148
|
+
log(outputChannel, `[AgentIDE] Warning: failed to persist terminal attachments for grep: ${e instanceof Error ? e.message : String(e)}`);
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
function formatSdkContextSuffix(ctx, terminalLogRelPath) {
|
|
4152
|
+
if (!ctx) {
|
|
4153
|
+
return "";
|
|
4154
|
+
}
|
|
4155
|
+
const parts = [];
|
|
4156
|
+
if (ctx.selection?.text && ctx.selection.text.trim()) {
|
|
4157
|
+
const headerBits = [];
|
|
4158
|
+
if (ctx.selection.uri) {
|
|
4159
|
+
headerBits.push(`**File:** \`${ctx.selection.uri}\``);
|
|
4160
|
+
}
|
|
4161
|
+
if (ctx.selection.range) {
|
|
4162
|
+
const r = ctx.selection.range;
|
|
4163
|
+
headerBits.push(`**Range:** ${r.startLineNumber}:${r.startColumn}-${r.endLineNumber}:${r.endColumn}`);
|
|
4164
|
+
}
|
|
4165
|
+
parts.push("## Currently Selected Code");
|
|
4166
|
+
if (headerBits.length) {
|
|
4167
|
+
parts.push(headerBits.join(" \n"));
|
|
4168
|
+
parts.push("");
|
|
4169
|
+
}
|
|
4170
|
+
const lang = (ctx.selection.languageId ?? "").trim();
|
|
4171
|
+
parts.push(`\`\`\`${lang}`);
|
|
4172
|
+
parts.push(ctx.selection.text);
|
|
4173
|
+
parts.push("```");
|
|
4174
|
+
}
|
|
4175
|
+
const variables = ctx.variables ?? [];
|
|
4176
|
+
if (variables.length) {
|
|
4177
|
+
parts.push("## Attached Context");
|
|
4178
|
+
for (const v of variables) {
|
|
4179
|
+
switch (v.kind) {
|
|
4180
|
+
case "terminalCommand": {
|
|
4181
|
+
const cmd = v.command?.trim() || v.name;
|
|
4182
|
+
parts.push(`### Terminal`);
|
|
4183
|
+
parts.push(`**Command:** \`${cmd}\``);
|
|
4184
|
+
if (v.uri) {
|
|
4185
|
+
parts.push(`**Resource:** \`${v.uri}\``);
|
|
4186
|
+
}
|
|
4187
|
+
if (typeof v.exitCode === "number") {
|
|
4188
|
+
parts.push(`**Exit code:** ${v.exitCode}`);
|
|
4189
|
+
}
|
|
4190
|
+
// Keep prompt small: persist output to a session log file and tell the agent where to grep.
|
|
4191
|
+
if (terminalLogRelPath) {
|
|
4192
|
+
parts.push(`**Output:** saved to \`${terminalLogRelPath}\` (use \`rg\`/ \`grep\`)`);
|
|
4193
|
+
}
|
|
4194
|
+
else if (v.output && v.output.trim()) {
|
|
4195
|
+
// Fallback when no session id is available: inline a small tail so the agent still sees errors.
|
|
4196
|
+
const tail = v.output.length > 2000
|
|
4197
|
+
? `…(truncated)\n${v.output.slice(-2000)}`
|
|
4198
|
+
: v.output;
|
|
4199
|
+
parts.push("");
|
|
4200
|
+
parts.push("```text");
|
|
4201
|
+
parts.push(tail);
|
|
4202
|
+
parts.push("```");
|
|
4203
|
+
}
|
|
4204
|
+
parts.push("");
|
|
4205
|
+
break;
|
|
4206
|
+
}
|
|
4207
|
+
case "paste": {
|
|
4208
|
+
const lang = (v.language ?? "").trim();
|
|
4209
|
+
const title = v.name || "Paste";
|
|
4210
|
+
parts.push(`### ${title}`);
|
|
4211
|
+
if (v.code && v.code.trim()) {
|
|
4212
|
+
parts.push(`\`\`\`${lang}`);
|
|
4213
|
+
parts.push(v.code);
|
|
4214
|
+
parts.push("```");
|
|
4215
|
+
}
|
|
4216
|
+
parts.push("");
|
|
4217
|
+
break;
|
|
4218
|
+
}
|
|
4219
|
+
case "file":
|
|
4220
|
+
case "directory":
|
|
4221
|
+
case "promptFile": {
|
|
4222
|
+
const target = v.uri ?? v.name;
|
|
4223
|
+
parts.push(`- **${v.kind}**: \`${target}\``);
|
|
4224
|
+
break;
|
|
4225
|
+
}
|
|
4226
|
+
case "image":
|
|
4227
|
+
case "notebookOutput": {
|
|
4228
|
+
const target = v.uri ?? v.name;
|
|
4229
|
+
const extra = v.mimeType ? ` (${v.mimeType})` : "";
|
|
4230
|
+
parts.push(`- **${v.kind}**: \`${target}\`${extra}`);
|
|
4231
|
+
break;
|
|
4232
|
+
}
|
|
4233
|
+
case "implicit": {
|
|
4234
|
+
if (v.isSelection) {
|
|
4235
|
+
const target = v.uri ?? v.name;
|
|
4236
|
+
parts.push(`- **selection reference**: \`${target}\``);
|
|
4237
|
+
}
|
|
4238
|
+
else if (v.uri) {
|
|
4239
|
+
parts.push(`- **reference**: \`${v.uri}\``);
|
|
4240
|
+
}
|
|
4241
|
+
break;
|
|
4242
|
+
}
|
|
4243
|
+
case "generic": {
|
|
4244
|
+
// Generic attachments like Terminal Selection
|
|
4245
|
+
const title = v.name || "Context";
|
|
4246
|
+
const isTerminalSelection = !!v.isTerminalSelection ||
|
|
4247
|
+
(typeof v.id === "string" &&
|
|
4248
|
+
v.id.startsWith("terminal-selection-"));
|
|
4249
|
+
parts.push(`### ${title}`);
|
|
4250
|
+
if (isTerminalSelection && v.text && v.text.trim()) {
|
|
4251
|
+
// Terminal selection content is stored in terminal.md for grep-ability
|
|
4252
|
+
if (terminalLogRelPath) {
|
|
4253
|
+
parts.push(`**Content:** saved to \`${terminalLogRelPath}\` (use \`rg\`/\`grep\`)`);
|
|
4254
|
+
}
|
|
4255
|
+
else {
|
|
4256
|
+
// Fallback: inline small tail if no session
|
|
4257
|
+
const tail = v.text.length > 2000
|
|
4258
|
+
? `…(truncated)\n${v.text.slice(-2000)}`
|
|
4259
|
+
: v.text;
|
|
4260
|
+
parts.push("```text");
|
|
4261
|
+
parts.push(tail);
|
|
4262
|
+
parts.push("```");
|
|
4263
|
+
}
|
|
4264
|
+
// Parse terminal name from "Terminal Selection (zsh)" format and point to the activity log
|
|
4265
|
+
const terminalNameMatch = v.name?.match(/Terminal Selection \((.+)\)/);
|
|
4266
|
+
if (terminalNameMatch) {
|
|
4267
|
+
const terminalName = terminalNameMatch[1];
|
|
4268
|
+
const terminalSlug = (0, terminalLogger_1.terminalNameToSlug)(terminalName);
|
|
4269
|
+
parts.push(`**Full terminal history:** \`${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/terminals/${terminalSlug}.md\``);
|
|
4270
|
+
}
|
|
4271
|
+
else {
|
|
4272
|
+
// Point to the terminals directory for all terminal logs
|
|
4273
|
+
parts.push(`**All terminal logs:** \`${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/terminals/\``);
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
else if (v.text && v.text.trim()) {
|
|
4277
|
+
// Non-terminal generic content: inline it
|
|
4278
|
+
parts.push("```text");
|
|
4279
|
+
parts.push(v.text);
|
|
4280
|
+
parts.push("```");
|
|
4281
|
+
}
|
|
4282
|
+
else if (v.uri) {
|
|
4283
|
+
parts.push(`**Resource:** \`${v.uri}\``);
|
|
4284
|
+
}
|
|
4285
|
+
parts.push("");
|
|
4286
|
+
break;
|
|
4287
|
+
}
|
|
4288
|
+
default: {
|
|
4289
|
+
const target = v.uri ?? v.name;
|
|
4290
|
+
parts.push(`- **${v.kind}**: ${target}`);
|
|
4291
|
+
break;
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
const out = parts.join("\n").trim();
|
|
4297
|
+
return out ? out + "\n" : "";
|
|
4298
|
+
}
|
|
4299
|
+
// -----------------------------------------------------------------------------
|
|
4300
|
+
// Helpers
|
|
4301
|
+
// -----------------------------------------------------------------------------
|
|
4302
|
+
function getBundledBasePromptsDir() {
|
|
4303
|
+
if (!_extensionContext) {
|
|
4304
|
+
return undefined;
|
|
4305
|
+
}
|
|
4306
|
+
return path.join(_extensionContext.extensionPath, "base-prompts");
|
|
4307
|
+
}
|
|
4308
|
+
/**
|
|
4309
|
+
* Register bundled MCP servers with VS Code's MCP infrastructure.
|
|
4310
|
+
* This allows the VS Code native chat (DirectLLM) to discover and use MCP servers.
|
|
4311
|
+
*/
|
|
4312
|
+
async function registerBundledMcpServers(context, outputChannel) {
|
|
4313
|
+
const basePromptsDir = getBundledBasePromptsDir();
|
|
4314
|
+
if (!basePromptsDir) {
|
|
4315
|
+
log(outputChannel, "[AgentIDE] Cannot register MCP servers: base-prompts dir not found");
|
|
4316
|
+
return;
|
|
4317
|
+
}
|
|
4318
|
+
try {
|
|
4319
|
+
const servers = await (0, mcp_1.loadBundledMcpServers)(basePromptsDir);
|
|
4320
|
+
if (servers.length === 0) {
|
|
4321
|
+
log(outputChannel, "[AgentIDE] No bundled MCP servers found");
|
|
4322
|
+
return;
|
|
4323
|
+
}
|
|
4324
|
+
// Register MCP server definition provider with VS Code
|
|
4325
|
+
// The ID must match what's declared in package.json contributes.mcpServerDefinitionProviders
|
|
4326
|
+
const disposable = vscode.lm.registerMcpServerDefinitionProvider("bundled-mcp-servers", {
|
|
4327
|
+
provideMcpServerDefinitions: async () => {
|
|
4328
|
+
return servers.map((server) => new vscode.McpStdioServerDefinition(server.label, server.command, server.args, server.env ?? {}));
|
|
4329
|
+
},
|
|
4330
|
+
});
|
|
4331
|
+
context.subscriptions.push(disposable);
|
|
4332
|
+
log(outputChannel, `[AgentIDE] Registered ${servers.length} bundled MCP server(s) with VS Code: ${servers.map((s) => s.name).join(", ")}`);
|
|
4333
|
+
}
|
|
4334
|
+
catch (e) {
|
|
4335
|
+
log(outputChannel, `[AgentIDE] Warning: failed to register MCP servers: ${e instanceof Error ? e.message : String(e)}`);
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
async function refreshAgentideProject(state) {
|
|
4339
|
+
const { outputChannel, syncService, config } = state;
|
|
4340
|
+
const { workspaceRoot, additionalDirectories, isHomeFallback } = getWorkspaceRoot(outputChannel);
|
|
4341
|
+
if (isHomeFallback) {
|
|
4342
|
+
// Don't sync/watch when no workspace is open; fallback is only for running ad-hoc agent tools.
|
|
4343
|
+
return;
|
|
4344
|
+
}
|
|
4345
|
+
try {
|
|
4346
|
+
await syncService.ensureAgentideProjectPrepared(workspaceRoot, additionalDirectories, outputChannel);
|
|
4347
|
+
await syncService.writeManagedPathsManifest(config.codexHome, config.claudeConfigDir, workspaceRoot, additionalDirectories, outputChannel);
|
|
4348
|
+
log(outputChannel, "[AgentIDE] Project sync complete");
|
|
4349
|
+
}
|
|
4350
|
+
catch (e) {
|
|
4351
|
+
log(outputChannel, `[AgentIDE] Warning: failed to refresh project sync: ${e instanceof Error ? e.message : String(e)}`);
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
/**
|
|
4355
|
+
* Get the configured fallback directory path.
|
|
4356
|
+
* Reads from `agentide.fallbackDirectory` setting (directory name relative to home).
|
|
4357
|
+
*/
|
|
4358
|
+
function getFallbackDirectoryPath() {
|
|
4359
|
+
const config = vscode.workspace.getConfiguration("agentide");
|
|
4360
|
+
const dirName = config.get("fallbackDirectory") || ".agent-hippo";
|
|
4361
|
+
return path.join(os.homedir(), dirName);
|
|
4362
|
+
}
|
|
4363
|
+
function getWorkspaceRoot(outputChannel, explicitWorkspaceRoot, explicitAdditionalDirs) {
|
|
4364
|
+
const folders = vscode.workspace.workspaceFolders;
|
|
4365
|
+
const allFolderPaths = (0, workspaceFolders_1.getWorkspaceFolderFsPaths)();
|
|
4366
|
+
const candidate = explicitWorkspaceRoot?.trim();
|
|
4367
|
+
if (candidate) {
|
|
4368
|
+
const additionalDirectories = explicitAdditionalDirs ?? allFolderPaths.filter((p) => p !== candidate);
|
|
4369
|
+
if (folders && folders.length > 1) {
|
|
4370
|
+
log(outputChannel, `[AgentIDE] Multi-root workspace (${folders.length} folders). Primary: ${candidate}, Additional: ${additionalDirectories.length}`);
|
|
4371
|
+
}
|
|
4372
|
+
else {
|
|
4373
|
+
log(outputChannel, `[AgentIDE] Using explicit workspaceRoot=${candidate}`);
|
|
4374
|
+
}
|
|
4375
|
+
return {
|
|
4376
|
+
workspaceRoot: candidate,
|
|
4377
|
+
additionalDirectories,
|
|
4378
|
+
isHomeFallback: false,
|
|
4379
|
+
};
|
|
4380
|
+
}
|
|
4381
|
+
if (folders && folders.length > 0) {
|
|
4382
|
+
const primaryFolder = folders[0].uri.fsPath;
|
|
4383
|
+
const additionalDirectories = allFolderPaths.slice(1);
|
|
4384
|
+
if (folders.length > 1) {
|
|
4385
|
+
log(outputChannel, `[AgentIDE] Multi-root workspace (${folders.length} folders). Primary: ${primaryFolder}, Additional: ${additionalDirectories.length}`);
|
|
4386
|
+
}
|
|
4387
|
+
else {
|
|
4388
|
+
log(outputChannel, `[AgentIDE] Using workspace folder: ${primaryFolder}`);
|
|
4389
|
+
}
|
|
4390
|
+
return {
|
|
4391
|
+
workspaceRoot: primaryFolder,
|
|
4392
|
+
additionalDirectories,
|
|
4393
|
+
isHomeFallback: false,
|
|
4394
|
+
};
|
|
4395
|
+
}
|
|
4396
|
+
// Use fallback workspace (configurable via agentide.fallbackDirectory, default: ~/myagentide)
|
|
4397
|
+
const fallbackDir = getFallbackDirectoryPath();
|
|
4398
|
+
log(outputChannel, `[AgentIDE] No workspace open, using fallback directory: ${fallbackDir}`);
|
|
4399
|
+
return {
|
|
4400
|
+
workspaceRoot: fallbackDir,
|
|
4401
|
+
additionalDirectories: [],
|
|
4402
|
+
isHomeFallback: true,
|
|
4403
|
+
};
|
|
4404
|
+
}
|
|
4405
|
+
/**
|
|
4406
|
+
* Ensure the fallback directory exists with git initialized.
|
|
4407
|
+
* Called before using the fallback as a workspace root.
|
|
4408
|
+
*/
|
|
4409
|
+
async function ensureFallbackDirectoryExists(outputChannel) {
|
|
4410
|
+
const fallbackDir = getFallbackDirectoryPath();
|
|
4411
|
+
try {
|
|
4412
|
+
// Check if directory exists
|
|
4413
|
+
const exists = await (0, utils_1.pathExists)(fallbackDir);
|
|
4414
|
+
if (!exists) {
|
|
4415
|
+
// Create the directory
|
|
4416
|
+
await fs_1.promises.mkdir(fallbackDir, { recursive: true });
|
|
4417
|
+
log(outputChannel, `[AgentIDE] Created fallback directory: ${fallbackDir}`);
|
|
4418
|
+
// Initialize git repository
|
|
4419
|
+
try {
|
|
4420
|
+
const { execFile } = await import("child_process");
|
|
4421
|
+
const { promisify } = await import("util");
|
|
4422
|
+
const execFileAsync = promisify(execFile);
|
|
4423
|
+
await execFileAsync("git", ["init"], { cwd: fallbackDir });
|
|
4424
|
+
log(outputChannel, `[AgentIDE] Initialized git in fallback directory`);
|
|
4425
|
+
// Create a .gitignore to keep things clean
|
|
4426
|
+
const gitignorePath = path.join(fallbackDir, ".gitignore");
|
|
4427
|
+
const gitignoreContent = `# ${branding_1.AGENTIDE_BRAND_NAME} fallback workspace
|
|
4428
|
+
${paths_1.AGENT_CONSTANTS.AGENTIDE_DIR_NAME}/${paths_1.AGENT_CONSTANTS.SESSIONS_DIR}/
|
|
4429
|
+
*.log
|
|
4430
|
+
`;
|
|
4431
|
+
await fs_1.promises.writeFile(gitignorePath, gitignoreContent, "utf8");
|
|
4432
|
+
// Create a README
|
|
4433
|
+
const readmePath = path.join(fallbackDir, "README.md");
|
|
4434
|
+
const readmeContent = `# My ${branding_1.AGENTIDE_BRAND_NAME} Workspace
|
|
4435
|
+
|
|
4436
|
+
This is the default ${branding_1.AGENTIDE_BRAND_NAME} workspace, created automatically when no folder is open.
|
|
4437
|
+
|
|
4438
|
+
**Recommendation:** Open a specific project folder for better context and safety.
|
|
4439
|
+
|
|
4440
|
+
Files created here:
|
|
4441
|
+
- Agent-generated files when no workspace is open
|
|
4442
|
+
- Temporary experiments
|
|
4443
|
+
`;
|
|
4444
|
+
await fs_1.promises.writeFile(readmePath, readmeContent, "utf8");
|
|
4445
|
+
}
|
|
4446
|
+
catch (gitError) {
|
|
4447
|
+
// Git init failed - that's okay, directory still exists
|
|
4448
|
+
log(outputChannel, `[AgentIDE] Note: Could not initialize git in fallback directory: ${gitError instanceof Error ? gitError.message : String(gitError)}`);
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
catch (error) {
|
|
4453
|
+
log(outputChannel, `[AgentIDE] Warning: Failed to ensure fallback directory: ${error instanceof Error ? error.message : String(error)}`);
|
|
4454
|
+
}
|
|
4455
|
+
return fallbackDir;
|
|
4456
|
+
}
|
|
4457
|
+
let _hasWarnedHomeFallbackInThisSession = false;
|
|
4458
|
+
async function warnHomeFallbackOnce(outputChannel, streamId) {
|
|
4459
|
+
if (_hasWarnedHomeFallbackInThisSession) {
|
|
4460
|
+
return;
|
|
4461
|
+
}
|
|
4462
|
+
_hasWarnedHomeFallbackInThisSession = true;
|
|
4463
|
+
// Ensure fallback directory exists with git init
|
|
4464
|
+
const fallbackDir = await ensureFallbackDirectoryExists(outputChannel);
|
|
4465
|
+
const msg = `No folder is open. Running agent tools in: ${fallbackDir}`;
|
|
4466
|
+
log(outputChannel, `[AgentIDE] ${msg}`);
|
|
4467
|
+
void vscode.commands.executeCommand("agentide.streamCallback", {
|
|
4468
|
+
streamId,
|
|
4469
|
+
type: "progress",
|
|
4470
|
+
data: msg,
|
|
4471
|
+
});
|
|
4472
|
+
}
|