@buaa_smat/hometrans 26.0.5 → 26.0.6-devecocli.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/code-reviewer.md +1 -1
- package/devecocli-plugin/common.ts +2307 -0
- package/devecocli-plugin/content-resolver.ts +363 -0
- package/devecocli-plugin/install.ts +72 -0
- package/devecocli-plugin/uninstall.ts +26 -0
- package/devecocli-plugin/update.ts +77 -0
- package/i18n/agents/code-reviewer.md +1 -1
- package/i18n/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/i18n/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
- package/i18n/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/i18n/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/skills/a2h-app-migrate/SKILL.md +32 -15
- package/i18n/skills/a2h-app-migrate/references/stage-map.md +4 -2
- package/i18n/skills/a2h-app-migrate/references/workflow.yaml +148 -89
- package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
- package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
- package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +9 -3
- package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
- package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
- package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
- package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
- package/i18n/skills/a2h-batch-ui-align/SKILL.md +14 -12
- package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
- package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
- package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
- package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
- package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
- package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
- package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
- package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
- package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +1 -1
- package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
- package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
- package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
- package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
- package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
- package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
- package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
- package/i18n/skills/a2h-module-semantic-docs/SKILL.md +3 -2
- package/i18n/skills/a2h-page-specgen/SKILL.md +36 -5
- package/i18n/skills/a2h-page-specgen/references/behavior-ledger.md +89 -21
- package/i18n/skills/a2h-page-specgen/references/gates.md +33 -7
- package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
- package/i18n/skills/a2h-page-specgen/references/spec-example.md +166 -32
- package/i18n/skills/a2h-page-specgen/references/spec-template.md +8 -5
- package/i18n/skills/a2h-page-specgen/scripts/behavior-audit.mjs +37 -1
- package/i18n/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
- package/i18n/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
- package/i18n/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +32 -0
- package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
- package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
- package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +19 -10
- package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +62 -3
- package/i18n/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
- package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +116 -6
- package/i18n/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
- package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +26 -14
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +104 -19
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +104 -19
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +216 -216
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +100 -15
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +104 -19
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +155 -3
- package/i18n/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +75 -3
- package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +124 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
- package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +106 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +12 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +11 -3
- package/i18n/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
- package/i18n/skills/a2h-resource-convert/SKILL.md +1 -1
- package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
- package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
- package/i18n/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
- package/i18n/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
- package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +15 -12
- package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
- package/i18n/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
- package/i18n/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
- package/i18n/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
- package/i18n/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
- package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +5 -3
- package/i18n/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
- package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
- package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
- package/i18n/skills/a2h-spec-generate/references/input-formats.md +1 -1
- package/i18n/skills/a2h-utg-explorer/SKILL.md +11 -5
- package/i18n/skills/a2h-utg-explorer/references/architecture.md +37 -19
- package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +48 -3
- package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
- package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
- package/i18n/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
- package/i18n/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
- package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
- package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +143 -14
- package/i18n/skills/a2h-utg-static/SKILL.md +3 -3
- package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
- package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
- package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
- package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
- package/index.js +1677 -0
- package/package.json +9 -8
- package/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/codebuddy/agents/build-fixer.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/model-worker.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +5 -0
- package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/deveco/agents/build-fixer.frontmatter.md +2 -0
- package/platforms/deveco/agents/code-reviewer.frontmatter.md +2 -0
- package/platforms/deveco/agents/model-render-worker.frontmatter.md +2 -0
- package/platforms/deveco/agents/model-worker.frontmatter.md +2 -0
- package/platforms/deveco/agents/specgen-worker.frontmatter.md +2 -0
- package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/opencode/agents/build-fixer.frontmatter.md +2 -0
- package/platforms/opencode/agents/code-reviewer.frontmatter.md +2 -0
- package/platforms/opencode/agents/model-render-worker.frontmatter.md +2 -0
- package/platforms/opencode/agents/model-worker.frontmatter.md +2 -0
- package/platforms/opencode/agents/specgen-worker.frontmatter.md +2 -0
- package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
- package/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/plugin.jsonc +12 -0
- package/skills/a2h-app-migrate/SKILL.md +31 -14
- package/skills/a2h-app-migrate/references/stage-map.md +4 -2
- package/skills/a2h-app-migrate/references/workflow.yaml +152 -89
- package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +1 -1
- package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +28 -11
- package/skills/a2h-app-migrate/scripts/dag_action_catalog.mjs +76 -0
- package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +60 -5
- package/skills/a2h-app-migrate/scripts/dag_runner.mjs +184 -4
- package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
- package/skills/a2h-app-migrate/scripts/ledger.mjs +2 -2
- package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -3
- package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
- package/skills/a2h-app-migrate/test/test_dag_blocked_guard.mjs +291 -0
- package/skills/a2h-app-migrate/test/test_dag_production.mjs +40 -0
- package/skills/a2h-app-migrate/test/test_dag_runner.mjs +4 -3
- package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
- package/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +36 -0
- package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +19 -6
- package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
- package/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
- package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
- package/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
- package/skills/a2h-batch-ui-align/SKILL.md +14 -12
- package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
- package/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
- package/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
- package/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
- package/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
- package/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
- package/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
- package/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
- package/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
- package/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
- package/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
- package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
- package/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
- package/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
- package/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
- package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
- package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +6 -1
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
- package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +270 -0
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +134 -16
- package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +39 -8
- package/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
- package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
- package/skills/a2h-batch-ui-align/scripts/module_placement.mjs +189 -0
- package/skills/a2h-batch-ui-align/scripts/overlay_effects.mjs +205 -0
- package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +28 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +28 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_chrome_defaults.test.mjs +328 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_click_handler.test.mjs +127 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_compose_semantics.test.mjs +150 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +117 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +413 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_runtime_api.test.mjs +159 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_sheet_builder.test.mjs +192 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +4 -2
- package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
- package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_compose.test.mjs +106 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +15 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_pass.test.mjs +150 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +125 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +56 -0
- package/skills/a2h-batch-ui-align/scripts/tests/measure_pack_icon_leaf.test.mjs +143 -0
- package/skills/a2h-batch-ui-align/scripts/tests/module_placement.test.mjs +248 -0
- package/skills/a2h-batch-ui-align/scripts/tests/overlay_effects.test.mjs +214 -0
- package/skills/a2h-fix-build-errors/references/known-patterns.md +5 -5
- package/skills/a2h-module-semantic-docs/SKILL.md +3 -2
- package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +10 -0
- package/skills/a2h-module-semantic-docs/scripts/design_baseline.mjs +158 -0
- package/skills/a2h-module-semantic-docs/test/test_design_baseline.mjs +128 -0
- package/skills/a2h-page-specgen/SKILL.md +36 -5
- package/skills/a2h-page-specgen/references/behavior-ledger.md +88 -21
- package/skills/a2h-page-specgen/references/evidence.md +2 -1
- package/skills/a2h-page-specgen/references/execution-model.md +13 -5
- package/skills/a2h-page-specgen/references/gates.md +33 -7
- package/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
- package/skills/a2h-page-specgen/references/spec-example.md +166 -32
- package/skills/a2h-page-specgen/references/spec-template.md +8 -5
- package/skills/a2h-page-specgen/scripts/behavior-audit.mjs +40 -2
- package/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
- package/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
- package/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +35 -2
- package/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
- package/skills/a2h-page-specgen/scripts/finalize.mjs +55 -2
- package/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
- package/skills/a2h-page-specgen/scripts/gate.mjs +20 -11
- package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +56 -3
- package/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
- package/skills/a2h-page-specgen/scripts/lib/hg.mjs +114 -5
- package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +20 -3
- package/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
- package/skills/a2h-page-specgen/scripts/prepare.mjs +25 -14
- package/skills/a2h-page-specgen/scripts/report.mjs +26 -5
- package/skills/a2h-page-specgen/scripts/submission.mjs +69 -2
- package/skills/a2h-page-specgen/scripts/submit.mjs +105 -4
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +224 -224
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +153 -3
- package/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
- package/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
- package/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
- package/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
- package/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
- package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
- package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +82 -3
- package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
- package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +11 -0
- package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
- package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +94 -1
- package/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
- package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +14 -0
- package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +49 -1
- package/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
- package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +12 -4
- package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
- package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
- package/skills/a2h-page-specgen/scripts/test/report.test.mjs +80 -1
- package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
- package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +23 -0
- package/skills/a2h-page-specgen/scripts/waker.mjs +8 -1
- package/skills/a2h-resource-convert/SKILL.md +1 -1
- package/skills/a2h-resource-convert/data/framework-strings/NOTICE +10 -0
- package/skills/a2h-resource-convert/data/framework-strings/manifest.json +90 -0
- package/skills/a2h-resource-convert/data/framework-strings/strings.json +382 -0
- package/skills/a2h-resource-convert/references/conversion-rules.md +7 -1
- package/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
- package/skills/a2h-resource-convert/references/step5-reference-resolution.md +16 -0
- package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
- package/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
- package/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
- package/skills/a2h-spec-design-pipeline/SKILL.md +14 -11
- package/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
- package/skills/a2h-spec-design-pipeline/references/execution-model.md +3 -0
- package/skills/a2h-spec-design-pipeline/references/final-report-template.md +6 -3
- package/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
- package/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/scripts.md +4 -3
- package/skills/a2h-spec-design-pipeline/references/shared-layer.md +24 -19
- package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
- package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +12 -5
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/README.md +27 -3
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-param-contract.json +46 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-permission-map.json +2511 -295
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-cn.md +27 -72
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-en.md +39 -83
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +132 -101
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +158 -115
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-cn.md +60 -93
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-en.md +73 -100
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-cn.md +52 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-en.md +59 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ApiPermissionDeclaredCheck.js +57 -8
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +475 -18
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/PlatformApiContractCheck.js +472 -4
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/RoutePageSideEffectImportCheck.js +570 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/arkui/RouteParamCarrierSubCheck.js +1053 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/sql/SqlIdentifierAnalysis.js +427 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +7 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/settle.ts +785 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_api_permission_declared.ts +286 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_arkui_runtime_pitfall.ts +166 -2
- package/skills/a2h-spec-design-pipeline/scripts/test_docs_refresh_contract.ts +40 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_platform_api_contract.ts +350 -7
- package/skills/a2h-spec-design-pipeline/scripts/test_route_page_side_effect_import.ts +185 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_route_param_carrier.ts +341 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_settle.ts +593 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +92 -1
- package/skills/a2h-spec-design-pipeline/scripts/test_sql_identifier_analysis.ts +137 -0
- package/skills/a2h-spec-generate/references/input-formats.md +1 -1
- package/skills/a2h-utg-explorer/SKILL.md +11 -5
- package/skills/a2h-utg-explorer/references/architecture.md +37 -19
- package/skills/a2h-utg-explorer/scripts/audit.mjs +6 -2
- package/skills/a2h-utg-explorer/scripts/close_phases.mjs +8 -5
- package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +95 -19
- package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +192 -4
- package/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
- package/skills/a2h-utg-explorer/scripts/panel_routes.mjs +1 -1
- package/skills/a2h-utg-explorer/scripts/plan.mjs +16 -1
- package/skills/a2h-utg-explorer/scripts/predicates.mjs +270 -0
- package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +2 -0
- package/skills/a2h-utg-explorer/scripts/recover.mjs +4 -3
- package/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
- package/skills/a2h-utg-explorer/scripts/rejudge.mjs +4 -3
- package/skills/a2h-utg-explorer/scripts/report.mjs +32 -2
- package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +103 -36
- package/skills/a2h-utg-explorer/scripts/run_device.mjs +3 -8
- package/skills/a2h-utg-explorer/scripts/schedule_states.mjs +189 -0
- package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +9 -0
- package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +11 -0
- package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +31 -2
- package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +1 -1
- package/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
- package/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
- package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +4 -1
- package/skills/a2h-utg-explorer/scripts/tests/hybrid_route.test.mjs +6 -28
- package/skills/a2h-utg-explorer/scripts/tests/in_route_surface.test.mjs +125 -0
- package/skills/a2h-utg-explorer/scripts/tests/list_probe_target_wait.test.mjs +86 -0
- package/skills/a2h-utg-explorer/scripts/tests/multi_host.test.mjs +167 -0
- package/skills/a2h-utg-explorer/scripts/tests/nested_list.test.mjs +58 -0
- package/skills/a2h-utg-explorer/scripts/tests/overlay_opener.test.mjs +100 -0
- package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +8 -1
- package/skills/a2h-utg-explorer/scripts/tests/pr169_review_fixes.test.mjs +1 -0
- package/skills/a2h-utg-explorer/scripts/tests/pr191_review_fixes.test.mjs +2 -31
- package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +1 -1
- package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +56 -7
- package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +117 -6
- package/skills/a2h-utg-explorer/scripts/tests/state_inventory.test.mjs +414 -0
- package/skills/a2h-utg-explorer/scripts/tests/tree_unreliable.test.mjs +197 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +196 -30
- package/skills/a2h-utg-explorer/scripts/utg_explorer/hosts.mjs +146 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
- package/skills/a2h-utg-explorer/scripts/utg_explorer/states.mjs +286 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +197 -19
- package/skills/a2h-utg-static/SKILL.md +3 -3
- package/skills/a2h-utg-static/references/extractors.md +7 -0
- package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
- package/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
- package/skills/a2h-utg-static/scripts/compose_overlay.mjs +642 -22
- package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
- package/skills/a2h-utg-static/scripts/tests/test_in_route_surface.mjs +123 -0
- package/skills/a2h-utg-static/scripts/tests/test_overlay_host_effects.mjs +239 -0
- package/skills/a2h-utg-static/scripts/tests/test_shared_host_depths.mjs +48 -0
- package/skills/a2h-utg-static/scripts/utg_html.mjs +2 -0
- package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
- package/README.md +0 -440
- package/dist/cli/config-store.js +0 -128
- package/dist/cli/config.js +0 -48
- package/dist/cli/editors.json +0 -114
- package/dist/cli/env-vars.js +0 -127
- package/dist/cli/index.js +0 -76
- package/dist/cli/init.js +0 -2618
- package/dist/cli/uninstall.js +0 -406
- package/dist/platform/compose.js +0 -228
- package/dist/platform/frontmatter.js +0 -151
- package/dist/platform/installer.js +0 -417
- package/dist/platform/language.js +0 -77
- package/dist/platform/registry.js +0 -337
- package/dist/platform/transform.js +0 -363
- package/dist/platform/types.js +0 -9
- package/dist/platform/validate.js +0 -152
- package/dist/utils/regex.js +0 -7
- package/env-requirements.json +0 -536
- package/i18n/skills/a2h-app-migrate/references/specs.example.json +0 -19
- package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
- package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
- package/resource/choose_editor.png +0 -0
- package/resource/convert_pipeline_process.svg +0 -114
- package/resource/project_architecture.svg +0 -120
- package/resource/set_environment.png +0 -0
- package/resource/set_multimodel.png +0 -0
- package/resource/set_sdk.png +0 -0
- package/resource/title_dark.png +0 -0
- package/skills/a2h-app-migrate/references/specs.example.json +0 -19
- package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
- package/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
|
@@ -0,0 +1,2307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared logic of the plugin lifecycle scripts (install / uninstall / update).
|
|
3
|
+
*
|
|
4
|
+
* These scripts are run directly by external tools as `node devecocli-plugin/<cmd>.ts [--agent <name>] [--dir <path>]`
|
|
5
|
+
* (Node >= 22.18 natively supports TypeScript type stripping), so they depend only on Node built-in modules
|
|
6
|
+
* and use only erasable TS syntax (no enum / namespace / parameter properties).
|
|
7
|
+
*
|
|
8
|
+
* Arguments:
|
|
9
|
+
* --agent <name> target agent; must be a name in the `agent` list of plugin.jsonc;
|
|
10
|
+
* the old names with spaces, claude code / deveco code, are still accepted
|
|
11
|
+
* and mapped automatically to claude-code / deveco by canonicalAgentName.
|
|
12
|
+
* May be repeated, or comma-separated. Each platform's skills / agents /
|
|
13
|
+
* commands directories are resolved independently per the platform descriptors below (codex honors the CODEX_HOME
|
|
14
|
+
* environment variable; pi's global skills and subagent profiles both live under ~/.pi
|
|
15
|
+
* (skills in ~/.pi/skills, profiles in ~/.pi/agent/agents);
|
|
16
|
+
* dsh has no file-based subagents and installs skills only).
|
|
17
|
+
* --dir <path> direct path of the agent, i.e. the parent of the target skills / agents / commands folders;
|
|
18
|
+
* must be an existing directory. --dir targets do not recognize platforms; everything is copied as is, without conversion.
|
|
19
|
+
* --project <path> project root, must be an existing directory; each agent is installed in the project-level layout
|
|
20
|
+
* <project>/<agent project dir>/{skills,agents,commands}
|
|
21
|
+
* (directory name defaults to .<agent>; special cases in toProjectPlatform's
|
|
22
|
+
* PROJECT_ROOT_NAME: trae-cn -> .trae, claude-code -> .claude;
|
|
23
|
+
* other platform special cases: pi ignores project-level profiles, etc.).
|
|
24
|
+
* Mutually exclusive with --dir; may be combined with --agent.
|
|
25
|
+
* --dry-run only print the actions that would be taken; write / delete no files (supported by install / update).
|
|
26
|
+
* --verbose print per-target install details (summary line / conversion notes / validation results);
|
|
27
|
+
* silent by default -- no output on success; only validation ERRORs are still printed to stderr.
|
|
28
|
+
* The environment variable HOMETRANS_PLUGIN_VERBOSE=1|true|yes is equivalent (the deveco-cli
|
|
29
|
+
* plugin contract path cannot pass flags and can only enable it via the environment; see isVerboseEnv).
|
|
30
|
+
* --lang <zh|en> install language; when absent it is resolved automatically (HOMETRANS_PLUGIN_LANG, then the host
|
|
31
|
+
* time zone: China -> zh, anywhere else -> en, then the host locale), never asked interactively.
|
|
32
|
+
* An English install resolves every file through `i18n/` (see content-resolver.ts): FILE-NAMES.md
|
|
33
|
+
* renames first, then a same-path English copy, then the Chinese original. A Chinese install is
|
|
34
|
+
* byte-identical to earlier releases.
|
|
35
|
+
*
|
|
36
|
+
* With both --agent and --project, the given agents are installed at project level; with both --agent and --dir
|
|
37
|
+
* each is handled separately; with neither, all agents in plugin.jsonc are handled (skipping those not installed on
|
|
38
|
+
* this machine; under --project "editor installed on this machine" is the criterion as well).
|
|
39
|
+
*
|
|
40
|
+
* Multi-platform adaptation (paths aligned with defaultEditors() in src/cli/config-store.ts):
|
|
41
|
+
* - skill frontmatter: allowed-tools is natively supported only by pi / codebuddy / claude-code
|
|
42
|
+
* (pi lowercases it and drops Agent/Task); argument-hint is kept only for claude-code,
|
|
43
|
+
* the OpenCode family (opencode / deveco) rewrites it as metadata opencode/slash to expose
|
|
44
|
+
* a slash command; other non-standard top-level fields (type / domain etc.) all move into the standard metadata field.
|
|
45
|
+
* - agent md: the OpenCode family passes it through as is (mode / permission are native); claude-code /
|
|
46
|
+
* codebuddy / trae / trae-cn map permission deny entries to a disallowedTools denylist;
|
|
47
|
+
* qoder / pi map to a tools allowlist; cursor maps edit deny to readonly; codex converts to
|
|
48
|
+
* TOML (sandbox_mode has no effect in custom agents and is no longer written; bash deny ->
|
|
49
|
+
* features.shell_tool = false); atomcode converts to the role format (permission + difficulty
|
|
50
|
+
* required, difficulty always hard); dsh has no file-based subagents and is skipped. Semantics that cannot be kept
|
|
51
|
+
* are explained one by one in the install log.
|
|
52
|
+
* - command md: frontmatter is routed by the per-platform field matrix
|
|
53
|
+
* -- description is kept on all platforms; argument-hint only on codebuddy / codex /
|
|
54
|
+
* claude-code; agent / subtask are native only to the OpenCode family (claude-code translates
|
|
55
|
+
* subtask: true to context: fork); the body template is untouched ($ARGUMENTS / $1-$3
|
|
56
|
+
* are the cross-platform intersection). Directories: trae / trae-cn's global commands
|
|
57
|
+
* directories ~/.trae/commands and ~/.trae-cn/commands and pi's
|
|
58
|
+
* prompt template directory ~/.pi/prompts are installed again; codex commands are converted to skills
|
|
59
|
+
* and installed into skills/ ($ARGUMENTS replaced with an argument description, openai.yaml disables implicit invocation);
|
|
60
|
+
* dsh likewise converts to skills (a native key combination makes them user-invoked only); cursor commands go globally to
|
|
61
|
+
* ~/.cursor/commands, at project level to .cursor/commands (description only);
|
|
62
|
+
* atomcode likewise converts to skills (each skill automatically becomes /<skill-name>, and the $ menu can
|
|
63
|
+
* pass arguments inline).
|
|
64
|
+
* - After install, files written to disk are read back and validated per platform rules; the description limit
|
|
65
|
+
* is checked only when the platform really has that limit (e.g. 1024 for OpenCode/Pi/DevEco); exceeding it only prints
|
|
66
|
+
* a WARN, does not block the install, and does not modify the bundled source files. WARN and PASS details are printed only with
|
|
67
|
+
* --verbose / HOMETRANS_PLUGIN_VERBOSE=1; ERRORs are always printed (stderr,
|
|
68
|
+
* and in standalone mode the run ends with exit code 1).
|
|
69
|
+
*/
|
|
70
|
+
import fs from 'node:fs/promises';
|
|
71
|
+
import { existsSync, statSync } from 'node:fs';
|
|
72
|
+
import os from 'node:os';
|
|
73
|
+
import path from 'node:path';
|
|
74
|
+
import { fileURLToPath } from 'node:url';
|
|
75
|
+
import {
|
|
76
|
+
createContentResolver,
|
|
77
|
+
createZhResolver,
|
|
78
|
+
DEFAULT_INSTALL_LANGUAGE,
|
|
79
|
+
parseInstallLanguage,
|
|
80
|
+
resolveInstallLanguage,
|
|
81
|
+
type ContentResolver,
|
|
82
|
+
type InstallLanguage,
|
|
83
|
+
} from './content-resolver.ts';
|
|
84
|
+
|
|
85
|
+
export { parseInstallLanguage, resolveInstallLanguage };
|
|
86
|
+
export type { ContentResolver, InstallLanguage };
|
|
87
|
+
|
|
88
|
+
/** Plugin directory (the directory of this file; in bundled form, the directory of the package-root index.js). */
|
|
89
|
+
export const PLUGIN_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
90
|
+
/**
|
|
91
|
+
* Package root (the directory containing plugin.jsonc).
|
|
92
|
+
* Two run forms:
|
|
93
|
+
* - bundled form (index.js at the @buaa_smat/hometrans package root): this module is bundled by esbuild
|
|
94
|
+
* into the package root, and the bundled content sits next to the module (see the plugin bundling step of scripts/build.js);
|
|
95
|
+
* - source form (node devecocli-plugin/<cmd>.ts): this file is under devecocli-plugin/,
|
|
96
|
+
* and the package root is the parent directory.
|
|
97
|
+
* The anchor is the package root's `plugin.jsonc` (or the install source `skills/`): in bundled form
|
|
98
|
+
* index.js sits next to plugin.jsonc / skills/; in source form this file is under devecocli-plugin/
|
|
99
|
+
* and the package root is the parent directory.
|
|
100
|
+
*/
|
|
101
|
+
const looksLikePackageRoot = (dir: string): boolean =>
|
|
102
|
+
existsSync(path.join(dir, 'plugin.jsonc')) || existsSync(path.join(dir, 'skills'));
|
|
103
|
+
|
|
104
|
+
export const PACKAGE_ROOT = looksLikePackageRoot(PLUGIN_DIR)
|
|
105
|
+
? PLUGIN_DIR
|
|
106
|
+
: path.resolve(PLUGIN_DIR, '..');
|
|
107
|
+
/**
|
|
108
|
+
* Root of the platform definitions (`platforms/<agent>/...`):
|
|
109
|
+
* - in source / bundled form it sits next to plugin.jsonc (this package must ship platforms/);
|
|
110
|
+
* - if the package has no platforms/, fall back to platforms/ next to this file's parent directory, so it
|
|
111
|
+
* can run directly in source form inside the repo.
|
|
112
|
+
*/
|
|
113
|
+
export const PLATFORMS_ROOT = existsSync(path.join(PACKAGE_ROOT, 'platforms'))
|
|
114
|
+
? path.join(PACKAGE_ROOT, 'platforms')
|
|
115
|
+
: path.resolve(PLUGIN_DIR, '..', 'platforms');
|
|
116
|
+
/**
|
|
117
|
+
* Install source root: skills / agents / commands at the repo root (the package root in bundled form)
|
|
118
|
+
* -- the root directory is the base; there is no `platforms/base/` mirror anymore.
|
|
119
|
+
* Platform differences are layered on via the frontmatter / unique patches in `platforms/<agent>/`.
|
|
120
|
+
*/
|
|
121
|
+
export const SKILLS_ROOT = path.join(PACKAGE_ROOT, 'skills');
|
|
122
|
+
export const AGENTS_ROOT = path.join(PACKAGE_ROOT, 'agents');
|
|
123
|
+
export const COMMANDS_ROOT = path.join(PACKAGE_ROOT, 'commands');
|
|
124
|
+
|
|
125
|
+
/** English overlay root (`<packageRoot>/i18n`); read only when the install language is `en`. */
|
|
126
|
+
export const I18N_ROOT = path.join(PACKAGE_ROOT, 'i18n');
|
|
127
|
+
|
|
128
|
+
/** Resolver for the Chinese originals: what every direct API caller gets when no language is passed. */
|
|
129
|
+
const DEFAULT_RESOLVER = createZhResolver(PACKAGE_ROOT, PLATFORMS_ROOT);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Build the content resolver for an install language. An English install validates the i18n overlay up front and
|
|
133
|
+
* fails as a PluginError before anything is written into a target.
|
|
134
|
+
*/
|
|
135
|
+
export async function createResolver(
|
|
136
|
+
lang: InstallLanguage = DEFAULT_INSTALL_LANGUAGE,
|
|
137
|
+
): Promise<ContentResolver> {
|
|
138
|
+
try {
|
|
139
|
+
return await createContentResolver(lang, {
|
|
140
|
+
packageRoot: PACKAGE_ROOT,
|
|
141
|
+
i18nRoot: I18N_ROOT,
|
|
142
|
+
platformsRoot: PLATFORMS_ROOT,
|
|
143
|
+
});
|
|
144
|
+
} catch (err) {
|
|
145
|
+
throw new PluginError((err as Error).message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface PluginManifest {
|
|
150
|
+
id: string;
|
|
151
|
+
version: string;
|
|
152
|
+
name: string;
|
|
153
|
+
description: string;
|
|
154
|
+
publisher: string;
|
|
155
|
+
repo: string;
|
|
156
|
+
agent: string[];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export class PluginError extends Error {}
|
|
160
|
+
|
|
161
|
+
/* ------------------------------------------------------------------ */
|
|
162
|
+
/* plugin.jsonc */
|
|
163
|
+
/* ------------------------------------------------------------------ */
|
|
164
|
+
|
|
165
|
+
/** Strip comments and trailing commas from JSONC (skipping string contents, so "https://" is not damaged). */
|
|
166
|
+
export function stripJsonc(text: string): string {
|
|
167
|
+
let out = '';
|
|
168
|
+
let i = 0;
|
|
169
|
+
while (i < text.length) {
|
|
170
|
+
const ch = text[i];
|
|
171
|
+
if (ch === '"') {
|
|
172
|
+
let j = i + 1;
|
|
173
|
+
while (j < text.length && text[j] !== '"') j += text[j] === '\\' ? 2 : 1;
|
|
174
|
+
out += text.slice(i, j + 1);
|
|
175
|
+
i = j + 1;
|
|
176
|
+
} else if (ch === '/' && text[i + 1] === '/') {
|
|
177
|
+
while (i < text.length && text[i] !== '\n') i++;
|
|
178
|
+
} else if (ch === '/' && text[i + 1] === '*') {
|
|
179
|
+
const end = text.indexOf('*/', i + 2);
|
|
180
|
+
i = end < 0 ? text.length : end + 2;
|
|
181
|
+
} else {
|
|
182
|
+
out += ch;
|
|
183
|
+
i++;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return out.replace(/,(\s*[}\]])/g, '$1');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export async function loadManifest(): Promise<PluginManifest> {
|
|
190
|
+
// plugin.jsonc is at the package root (PACKAGE_ROOT): bundled form = next to index.js; source form = parent directory
|
|
191
|
+
const raw = await fs.readFile(path.join(PACKAGE_ROOT, 'plugin.jsonc'), 'utf-8');
|
|
192
|
+
return JSON.parse(stripJsonc(raw)) as PluginManifest;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* ------------------------------------------------------------------ */
|
|
196
|
+
/* YAML frontmatter subset: parsing and serialization */
|
|
197
|
+
/* ------------------------------------------------------------------ */
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Supports only the YAML syntax the bundled files actually use: top-level `key: value` (bare or quoted value), one level of
|
|
201
|
+
* nested map (`key:` + indented `subkey: value`, e.g. an agent's permission), and block lists
|
|
202
|
+
* (`key:` + indented `- item`, e.g. allowed-tools). Booleans are produced only when converters build them.
|
|
203
|
+
*/
|
|
204
|
+
export type FmValue = string | boolean | string[] | Record<string, string>;
|
|
205
|
+
export type Frontmatter = Record<string, FmValue>;
|
|
206
|
+
|
|
207
|
+
export interface ParsedMarkdown {
|
|
208
|
+
fm: Frontmatter;
|
|
209
|
+
/** The raw text after the frontmatter end marker (including the blank lines after it); the whole text if no frontmatter was parsed. */
|
|
210
|
+
body: string;
|
|
211
|
+
hasFrontmatter: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Strip quotes and unescape; bare values are returned as is. */
|
|
215
|
+
function parseScalar(v: string): string {
|
|
216
|
+
if (v.length >= 2 && v.startsWith('"') && v.endsWith('"')) {
|
|
217
|
+
return v.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
|
218
|
+
}
|
|
219
|
+
if (v.length >= 2 && v.startsWith("'") && v.endsWith("'")) {
|
|
220
|
+
return v.slice(1, -1).replace(/''/g, "'");
|
|
221
|
+
}
|
|
222
|
+
return v;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function parseFrontmatter(raw: string): ParsedMarkdown {
|
|
226
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(raw);
|
|
227
|
+
if (!m) return { fm: {}, body: raw, hasFrontmatter: false };
|
|
228
|
+
const fm: Frontmatter = {};
|
|
229
|
+
let parent: string | null = null;
|
|
230
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
231
|
+
if (!line.trim() || line.trim().startsWith('#')) continue;
|
|
232
|
+
const indented = line[0] === ' ' || line[0] === '\t';
|
|
233
|
+
const trimmed = line.trim();
|
|
234
|
+
// Block list item: `- item`, belongs to the nearest top-level key
|
|
235
|
+
if (trimmed.startsWith('- ') && parent !== null) {
|
|
236
|
+
const item = parseScalar(trimmed.slice(2).trim());
|
|
237
|
+
const cur = fm[parent];
|
|
238
|
+
fm[parent] = Array.isArray(cur) ? [...cur, item] : [item];
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const idx = line.indexOf(':');
|
|
242
|
+
if (idx < 0) continue;
|
|
243
|
+
const key = line.slice(0, idx).trim();
|
|
244
|
+
const value = line.slice(idx + 1).trim();
|
|
245
|
+
if (!indented) {
|
|
246
|
+
parent = key;
|
|
247
|
+
if (value === '') {
|
|
248
|
+
// `key:` may be a nested map or a block list; reserve a placeholder and let the following indented lines decide
|
|
249
|
+
if (!(key in fm)) fm[key] = {};
|
|
250
|
+
} else {
|
|
251
|
+
fm[key] = parseScalar(value);
|
|
252
|
+
}
|
|
253
|
+
} else if (parent !== null && value !== '') {
|
|
254
|
+
// Child key of a one-level nested map (e.g. permission.edit)
|
|
255
|
+
const cur = fm[parent];
|
|
256
|
+
const map: Record<string, string> =
|
|
257
|
+
Array.isArray(cur) || typeof cur !== 'object' || cur === undefined ? {} : cur;
|
|
258
|
+
map[key] = parseScalar(value);
|
|
259
|
+
fm[parent] = map;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return { fm, body: raw.slice(m[0].length), hasFrontmatter: true };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Bare values are limited to a conservative safe character set; boolean-looking strings are quoted so they are not parsed as booleans. */
|
|
266
|
+
const BARE_SAFE = /^[A-Za-z0-9_][A-Za-z0-9_ ./+|=-]*$/;
|
|
267
|
+
const BOOL_LIKE = /^(true|false|yes|no|on|off|null|~)$/i;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Fields with boolean semantics in each platform's frontmatter (subtask / disable-model-invocation /
|
|
271
|
+
* disable / hidden etc.). Their true/false stays bare boolean output -- quoting them would make
|
|
272
|
+
* YAML parse them as strings, while the schemas of OpenCode and other platforms expect booleans.
|
|
273
|
+
*/
|
|
274
|
+
const NATIVE_BOOLEAN_KEYS = new Set([
|
|
275
|
+
'subtask',
|
|
276
|
+
'disable-model-invocation',
|
|
277
|
+
'user-invocable',
|
|
278
|
+
'disable',
|
|
279
|
+
'hidden',
|
|
280
|
+
'is_background',
|
|
281
|
+
'background',
|
|
282
|
+
'readonly',
|
|
283
|
+
]);
|
|
284
|
+
|
|
285
|
+
function formatScalar(key: string, v: string): string {
|
|
286
|
+
if (v === '') return '""';
|
|
287
|
+
if (NATIVE_BOOLEAN_KEYS.has(key) && /^(true|false)$/i.test(v)) return v.toLowerCase();
|
|
288
|
+
if (!BARE_SAFE.test(v) || BOOL_LIKE.test(v) || v !== v.trim()) {
|
|
289
|
+
return '"' + v.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
|
|
290
|
+
}
|
|
291
|
+
return v;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Serialize as a `---\n...\n---\n` block (exactly one trailing newline, so appending the body matches the original file structure). */
|
|
295
|
+
export function serializeFrontmatter(fm: Frontmatter): string {
|
|
296
|
+
const lines: string[] = ['---'];
|
|
297
|
+
for (const [key, value] of Object.entries(fm)) {
|
|
298
|
+
if (Array.isArray(value)) {
|
|
299
|
+
if (value.length === 0) {
|
|
300
|
+
lines.push(`${key}: []`);
|
|
301
|
+
} else {
|
|
302
|
+
lines.push(`${key}:`);
|
|
303
|
+
for (const item of value) lines.push(` - ${formatScalar(key, item)}`);
|
|
304
|
+
}
|
|
305
|
+
} else if (typeof value === 'boolean') {
|
|
306
|
+
lines.push(`${key}: ${value ? 'true' : 'false'}`);
|
|
307
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
308
|
+
const entries = Object.entries(value);
|
|
309
|
+
if (entries.length === 0) {
|
|
310
|
+
lines.push(`${key}: {}`);
|
|
311
|
+
} else {
|
|
312
|
+
lines.push(`${key}:`);
|
|
313
|
+
for (const [k, v] of entries) lines.push(` ${k}: ${formatScalar(k, v)}`);
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
lines.push(`${key}: ${formatScalar(key, value)}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
lines.push('---', '');
|
|
320
|
+
return lines.join('\n');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function asString(v: FmValue | undefined): string | undefined {
|
|
324
|
+
return typeof v === 'string' ? v : undefined;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function asRecord(v: FmValue | undefined): Record<string, string> {
|
|
328
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v) ? v : {};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Flatten to a string when moving a non-standard field into metadata. */
|
|
332
|
+
function fmValueToString(v: FmValue): string {
|
|
333
|
+
if (typeof v === 'string') return v;
|
|
334
|
+
if (typeof v === 'boolean') return v ? 'true' : 'false';
|
|
335
|
+
if (Array.isArray(v)) return v.join(', ');
|
|
336
|
+
return Object.entries(v)
|
|
337
|
+
.map(([k, val]) => `${k}=${val}`)
|
|
338
|
+
.join(', ');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* ------------------------------------------------------------------ */
|
|
342
|
+
/* Platform descriptors */
|
|
343
|
+
/* ------------------------------------------------------------------ */
|
|
344
|
+
|
|
345
|
+
/** Format of subagent definitions on the target platform. */
|
|
346
|
+
export type AgentFormat =
|
|
347
|
+
| 'passthrough' // OpenCode family (opencode / deveco): mode / permission natively supported
|
|
348
|
+
| 'claude' // Claude Code: permission deny -> disallowedTools
|
|
349
|
+
| 'codebuddy' // CodeBuddy: same denylist as the Claude family
|
|
350
|
+
| 'cursor' // Cursor: edit deny -> readonly (no tool-level denylist)
|
|
351
|
+
| 'qoder' // Qoder: permission -> tools allowlist
|
|
352
|
+
| 'trae' // Trae: permission deny -> disallowedTools (no Task tool)
|
|
353
|
+
| 'pi-profile' // Pi simple-subagents profile: permission -> lowercase tools
|
|
354
|
+
| 'codex-toml' // Codex: md -> TOML
|
|
355
|
+
| 'atomcode-role' // AtomCode: role format (permission + difficulty required)
|
|
356
|
+
| 'none'; // DSH: no file-based subagents, skipped
|
|
357
|
+
|
|
358
|
+
/** Locations used by old plugin versions; cleaned up during install and uninstall so old and new do not coexist. */
|
|
359
|
+
export interface LegacyDir {
|
|
360
|
+
skillsDir?: string;
|
|
361
|
+
agentsDir?: string;
|
|
362
|
+
commandsDir?: string;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface AgentPlatform {
|
|
366
|
+
/** Name in the `agent` list of plugin.jsonc. */
|
|
367
|
+
name: string;
|
|
368
|
+
/** Directory used to detect installation on this machine (marker). */
|
|
369
|
+
markerDir: string;
|
|
370
|
+
/** Global skills directory; null = the platform has no skills concept. */
|
|
371
|
+
skillsDir: string | null;
|
|
372
|
+
/** Subagent definition directory; null = the platform has no file-based subagents (install skipped). */
|
|
373
|
+
agentsDir: string | null;
|
|
374
|
+
/** Slash command directory; null = commands are not installed. */
|
|
375
|
+
commandsDir: string | null;
|
|
376
|
+
agentFormat: AgentFormat;
|
|
377
|
+
/** Keep allowed-tools in skill frontmatter (supported by pi / codebuddy / claude-code). */
|
|
378
|
+
skillKeepAllowedTools: boolean;
|
|
379
|
+
/** Keep argument-hint in skill frontmatter (natively supported only by claude-code). */
|
|
380
|
+
skillKeepArgumentHint: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Hard limit of the skill description (in characters). Set only for platforms that really have the limit;
|
|
383
|
+
* unset = no length warning (e.g. Trae / Cursor / CodeBuddy / Qoder / Codex /
|
|
384
|
+
* AtomCode). Currently known limits: OpenCode / Pi / DevEco = 1024.
|
|
385
|
+
*/
|
|
386
|
+
skillDescriptionLimit?: number;
|
|
387
|
+
/** Skills with argument-hint write metadata opencode/slash (the OpenCode family exposes slash commands). */
|
|
388
|
+
skillSlashMetadata: boolean;
|
|
389
|
+
/** Fields kept in command md frontmatter. */
|
|
390
|
+
commandKeepKeys: string[];
|
|
391
|
+
/** Skip note when there is no commands directory (including the platform's equivalent mechanism). */
|
|
392
|
+
commandsSkipNote?: string;
|
|
393
|
+
/** Skip note when there is no agents directory; defaults to "the platform has no file-based subagents". */
|
|
394
|
+
agentsSkipNote?: string;
|
|
395
|
+
/**
|
|
396
|
+
* Commands are installed into the skills directory as skills (Codex: custom prompts are deprecated, and officially
|
|
397
|
+
* skills are recommended to carry them). When true, commandsDir has no effect.
|
|
398
|
+
*/
|
|
399
|
+
commandsAsSkills?: boolean;
|
|
400
|
+
/** --dir target: platform not recognized; skills / agents are copied as is. */
|
|
401
|
+
verbatim: boolean;
|
|
402
|
+
legacyDirs: LegacyDir[];
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function home(...segments: string[]): string {
|
|
406
|
+
return path.join(os.homedir(), ...segments);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Install layout and conversion strategy per platform. Directory sources:
|
|
411
|
+
* - opencode / deveco: ~/.config/{opencode,deveco} (deveco-code is based on OpenCode;
|
|
412
|
+
* consistent with defaultEditors() in src/cli/config-store.ts); the commands'
|
|
413
|
+
* agent / subtask fields are native to both platforms
|
|
414
|
+
* - trae / trae-cn: ~/.trae (international build) and ~/.trae-cn (mainland-China build;
|
|
415
|
+
* officially %userprofile%/.trae-cn on Windows); global commands directories
|
|
416
|
+
* ~/.trae/commands and ~/.trae-cn/commands
|
|
417
|
+
* - pi: global skills in ~/.pi/skills (pi's own directory, not the shared fallback directory
|
|
418
|
+
* ~/.agents/skills used by ht init; see the pi platform entry for why); subagents are simple-subagents
|
|
419
|
+
* extension profiles in ~/.pi/agent/agents (project-level profiles are ignored); commands
|
|
420
|
+
* are installed as prompt templates into ~/.pi/prompts (template name = command name)
|
|
421
|
+
* - cursor: ~/.cursor; commands go to ~/.cursor/commands (project level .cursor/commands),
|
|
422
|
+
* aligned with defaultEditors() in src/cli/config-store.ts
|
|
423
|
+
* - codebuddy / qoder / claude-code: their own user directories; claude-code's
|
|
424
|
+
* commands/ is a legacy format but still works (rendered equivalently as a skill)
|
|
425
|
+
* - codex: $CODEX_HOME (~/.codex when unset); commands are not installed as prompts (custom
|
|
426
|
+
* prompts are deprecated) but converted to skills in skills/ (openai.yaml disables implicit invocation,
|
|
427
|
+
* the old prompts location is included in legacy cleanup); subagents are defined in TOML
|
|
428
|
+
* - atomcode: ~/.atomcode; agents use the role format (permission/difficulty required,
|
|
429
|
+
* name/description are not read); no separate commands directory, commands are converted to skills in
|
|
430
|
+
* skills/ (each skill automatically becomes a /<skill-name> command)
|
|
431
|
+
* - dsh: ~/.dsh (skills rank 400); no file-based subagents; commands have no file form either and are
|
|
432
|
+
* converted to skills in skills/ (the native keys disable-model-invocation +
|
|
433
|
+
* user-invocable keep the "user-invoked only" semantics)
|
|
434
|
+
*/
|
|
435
|
+
export function resolvePlatforms(): Map<string, AgentPlatform> {
|
|
436
|
+
const codexRoot = process.env.CODEX_HOME
|
|
437
|
+
? path.resolve(process.env.CODEX_HOME)
|
|
438
|
+
: home('.codex');
|
|
439
|
+
const platforms: AgentPlatform[] = [
|
|
440
|
+
{
|
|
441
|
+
name: 'opencode',
|
|
442
|
+
markerDir: home('.config', 'opencode'),
|
|
443
|
+
skillsDir: home('.config', 'opencode', 'skills'),
|
|
444
|
+
agentsDir: home('.config', 'opencode', 'agents'),
|
|
445
|
+
commandsDir: home('.config', 'opencode', 'commands'),
|
|
446
|
+
agentFormat: 'passthrough',
|
|
447
|
+
skillKeepAllowedTools: false,
|
|
448
|
+
skillKeepArgumentHint: false,
|
|
449
|
+
skillDescriptionLimit: 1024,
|
|
450
|
+
skillSlashMetadata: true,
|
|
451
|
+
commandKeepKeys: ['description', 'agent', 'subtask', 'model'],
|
|
452
|
+
verbatim: false,
|
|
453
|
+
legacyDirs: [],
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
name: 'trae',
|
|
457
|
+
markerDir: home('.trae'),
|
|
458
|
+
skillsDir: home('.trae', 'skills'),
|
|
459
|
+
agentsDir: home('.trae', 'agents'),
|
|
460
|
+
commandsDir: home('.trae', 'commands'),
|
|
461
|
+
agentFormat: 'trae',
|
|
462
|
+
skillKeepAllowedTools: false,
|
|
463
|
+
skillKeepArgumentHint: false,
|
|
464
|
+
skillSlashMetadata: false,
|
|
465
|
+
commandKeepKeys: ['name', 'description'],
|
|
466
|
+
verbatim: false,
|
|
467
|
+
legacyDirs: [],
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
// Trae CN is the mainland-China build of Trae: same tool set and file
|
|
471
|
+
// formats, but its own user-level root ~/.trae-cn (the international
|
|
472
|
+
// build uses ~/.trae).
|
|
473
|
+
name: 'trae-cn',
|
|
474
|
+
markerDir: home('.trae-cn'),
|
|
475
|
+
skillsDir: home('.trae-cn', 'skills'),
|
|
476
|
+
agentsDir: home('.trae-cn', 'agents'),
|
|
477
|
+
commandsDir: home('.trae-cn', 'commands'),
|
|
478
|
+
agentFormat: 'trae',
|
|
479
|
+
skillKeepAllowedTools: false,
|
|
480
|
+
skillKeepArgumentHint: false,
|
|
481
|
+
skillSlashMetadata: false,
|
|
482
|
+
commandKeepKeys: ['name', 'description'],
|
|
483
|
+
verbatim: false,
|
|
484
|
+
legacyDirs: [],
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
name: 'pi',
|
|
488
|
+
markerDir: home('.pi'),
|
|
489
|
+
// Global skills go to pi's own ~/.pi/skills, not the open-standard shared directory
|
|
490
|
+
// ~/.agents/skills -- the shared directory is ht init's fallback install location (see SHARED_AGENTS_FALLBACK in src/cli/
|
|
491
|
+
// config-store.ts) and is also read by opencode / newer codex
|
|
492
|
+
// etc.: installing there would pollute what other agents see, detection would mistake a same-named skill in the shared directory
|
|
493
|
+
// for pi being installed, and uninstall would wrongly delete content installed by other tools
|
|
494
|
+
skillsDir: home('.pi', 'skills'),
|
|
495
|
+
agentsDir: home('.pi', 'agent', 'agents'),
|
|
496
|
+
// Pi provides slash commands as prompt templates: md templates under ~/.pi/prompts
|
|
497
|
+
// become commands by template name
|
|
498
|
+
commandsDir: home('.pi', 'prompts'),
|
|
499
|
+
agentFormat: 'pi-profile',
|
|
500
|
+
skillKeepAllowedTools: true,
|
|
501
|
+
skillKeepArgumentHint: false,
|
|
502
|
+
skillDescriptionLimit: 1024,
|
|
503
|
+
skillSlashMetadata: false,
|
|
504
|
+
commandKeepKeys: ['description'],
|
|
505
|
+
verbatim: false,
|
|
506
|
+
// Some versions installed pi skills into the shared directory ~/.agents/skills; deliberately not included in legacy
|
|
507
|
+
// cleanup: that directory is shared by ht init / other agents, and deleting would hit same-named content installed by other tools
|
|
508
|
+
// (ht uninstall handles its own installs symmetrically)
|
|
509
|
+
legacyDirs: [
|
|
510
|
+
{
|
|
511
|
+
agentsDir: home('.pi', 'agents'),
|
|
512
|
+
commandsDir: home('.pi', 'commands'),
|
|
513
|
+
},
|
|
514
|
+
],
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: 'deveco',
|
|
518
|
+
markerDir: home('.config', 'deveco'),
|
|
519
|
+
skillsDir: home('.config', 'deveco', 'skills'),
|
|
520
|
+
agentsDir: home('.config', 'deveco', 'agents'),
|
|
521
|
+
commandsDir: home('.config', 'deveco', 'commands'),
|
|
522
|
+
agentFormat: 'passthrough',
|
|
523
|
+
skillKeepAllowedTools: false,
|
|
524
|
+
skillKeepArgumentHint: false,
|
|
525
|
+
skillDescriptionLimit: 1024,
|
|
526
|
+
skillSlashMetadata: true,
|
|
527
|
+
commandKeepKeys: ['description', 'agent', 'subtask', 'model'],
|
|
528
|
+
verbatim: false,
|
|
529
|
+
legacyDirs: [],
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: 'cursor',
|
|
533
|
+
markerDir: home('.cursor'),
|
|
534
|
+
skillsDir: home('.cursor', 'skills'),
|
|
535
|
+
agentsDir: home('.cursor', 'agents'),
|
|
536
|
+
commandsDir: home('.cursor', 'commands'),
|
|
537
|
+
agentFormat: 'cursor',
|
|
538
|
+
skillKeepAllowedTools: false,
|
|
539
|
+
skillKeepArgumentHint: false,
|
|
540
|
+
skillSlashMetadata: false,
|
|
541
|
+
commandKeepKeys: ['description'],
|
|
542
|
+
verbatim: false,
|
|
543
|
+
legacyDirs: [],
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
name: 'codebuddy',
|
|
547
|
+
markerDir: home('.codebuddy'),
|
|
548
|
+
skillsDir: home('.codebuddy', 'skills'),
|
|
549
|
+
agentsDir: home('.codebuddy', 'agents'),
|
|
550
|
+
commandsDir: home('.codebuddy', 'commands'),
|
|
551
|
+
agentFormat: 'codebuddy',
|
|
552
|
+
skillKeepAllowedTools: true,
|
|
553
|
+
skillKeepArgumentHint: false,
|
|
554
|
+
skillSlashMetadata: false,
|
|
555
|
+
commandKeepKeys: [
|
|
556
|
+
'description',
|
|
557
|
+
'argument-hint',
|
|
558
|
+
'model',
|
|
559
|
+
'allowed-tools',
|
|
560
|
+
'disable-model-invocation',
|
|
561
|
+
],
|
|
562
|
+
verbatim: false,
|
|
563
|
+
legacyDirs: [],
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: 'qoder',
|
|
567
|
+
markerDir: home('.qoder'),
|
|
568
|
+
skillsDir: home('.qoder', 'skills'),
|
|
569
|
+
agentsDir: home('.qoder', 'agents'),
|
|
570
|
+
commandsDir: home('.qoder', 'commands'),
|
|
571
|
+
agentFormat: 'qoder',
|
|
572
|
+
skillKeepAllowedTools: false,
|
|
573
|
+
skillKeepArgumentHint: false,
|
|
574
|
+
skillSlashMetadata: false,
|
|
575
|
+
commandKeepKeys: ['description'],
|
|
576
|
+
verbatim: false,
|
|
577
|
+
legacyDirs: [],
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
// Qoder CN is the mainland-China build of Qoder: same tool set and file
|
|
581
|
+
// formats, but its own user-level root ~/.qoder-cn (the international
|
|
582
|
+
// build uses ~/.qoder).
|
|
583
|
+
name: 'qoder-cn',
|
|
584
|
+
markerDir: home('.qoder-cn'),
|
|
585
|
+
skillsDir: home('.qoder-cn', 'skills'),
|
|
586
|
+
agentsDir: home('.qoder-cn', 'agents'),
|
|
587
|
+
commandsDir: home('.qoder-cn', 'commands'),
|
|
588
|
+
agentFormat: 'qoder',
|
|
589
|
+
skillKeepAllowedTools: false,
|
|
590
|
+
skillKeepArgumentHint: false,
|
|
591
|
+
skillSlashMetadata: false,
|
|
592
|
+
commandKeepKeys: ['description'],
|
|
593
|
+
verbatim: false,
|
|
594
|
+
legacyDirs: [],
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
name: 'claude-code',
|
|
598
|
+
markerDir: home('.claude'),
|
|
599
|
+
skillsDir: home('.claude', 'skills'),
|
|
600
|
+
agentsDir: home('.claude', 'agents'),
|
|
601
|
+
commandsDir: home('.claude', 'commands'),
|
|
602
|
+
agentFormat: 'claude',
|
|
603
|
+
skillKeepAllowedTools: true,
|
|
604
|
+
skillKeepArgumentHint: true,
|
|
605
|
+
skillSlashMetadata: false,
|
|
606
|
+
commandKeepKeys: [
|
|
607
|
+
'description',
|
|
608
|
+
'argument-hint',
|
|
609
|
+
'allowed-tools',
|
|
610
|
+
'model',
|
|
611
|
+
'disable-model-invocation',
|
|
612
|
+
'context',
|
|
613
|
+
],
|
|
614
|
+
verbatim: false,
|
|
615
|
+
legacyDirs: [],
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: 'codex',
|
|
619
|
+
markerDir: codexRoot,
|
|
620
|
+
skillsDir: path.join(codexRoot, 'skills'),
|
|
621
|
+
agentsDir: path.join(codexRoot, 'agents'),
|
|
622
|
+
// Commands are not installed as prompts (custom prompts are deprecated) but converted to skills in the skills/
|
|
623
|
+
// directory; the old prompts location is included in legacy cleanup
|
|
624
|
+
commandsDir: null,
|
|
625
|
+
agentFormat: 'codex-toml',
|
|
626
|
+
skillKeepAllowedTools: false,
|
|
627
|
+
skillKeepArgumentHint: false,
|
|
628
|
+
skillSlashMetadata: false,
|
|
629
|
+
commandKeepKeys: [],
|
|
630
|
+
commandsAsSkills: true,
|
|
631
|
+
verbatim: false,
|
|
632
|
+
legacyDirs: [{ commandsDir: path.join(codexRoot, 'prompts') }],
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
name: 'atomcode',
|
|
636
|
+
markerDir: home('.atomcode'),
|
|
637
|
+
skillsDir: home('.atomcode', 'skills'),
|
|
638
|
+
agentsDir: home('.atomcode', 'agents'),
|
|
639
|
+
commandsDir: null,
|
|
640
|
+
agentFormat: 'atomcode-role',
|
|
641
|
+
skillKeepAllowedTools: false,
|
|
642
|
+
skillKeepArgumentHint: false,
|
|
643
|
+
skillSlashMetadata: false,
|
|
644
|
+
commandKeepKeys: [],
|
|
645
|
+
// AtomCode has no separate commands directory: slash commands come from skills (each skill automatically
|
|
646
|
+
// becomes /<skill-name>, and the $ menu supports inline arguments via $<name> <args>) and its own
|
|
647
|
+
// /plugin packages (with a plugin-name: prefix, not via this install path); once commands are converted to skills in
|
|
648
|
+
// skills/, /hometrans appears as is
|
|
649
|
+
commandsAsSkills: true,
|
|
650
|
+
verbatim: false,
|
|
651
|
+
legacyDirs: [{ commandsDir: home('.atomcode', 'commands') }],
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
name: 'dsh',
|
|
655
|
+
markerDir: home('.dsh'),
|
|
656
|
+
skillsDir: home('.dsh', 'skills'),
|
|
657
|
+
agentsDir: null,
|
|
658
|
+
// DSH has no file-based commands (commands are registered via the plugin API): commands are converted to skills in
|
|
659
|
+
// skills/, and the native keys disable-model-invocation + user-invocable keep
|
|
660
|
+
// the "user-invoked only" command semantics
|
|
661
|
+
commandsDir: null,
|
|
662
|
+
agentFormat: 'none',
|
|
663
|
+
skillKeepAllowedTools: false,
|
|
664
|
+
skillKeepArgumentHint: false,
|
|
665
|
+
skillSlashMetadata: false,
|
|
666
|
+
commandKeepKeys: [],
|
|
667
|
+
commandsAsSkills: true,
|
|
668
|
+
verbatim: false,
|
|
669
|
+
legacyDirs: [
|
|
670
|
+
{
|
|
671
|
+
agentsDir: home('.dsh', 'agents'),
|
|
672
|
+
commandsDir: home('.dsh', 'commands'),
|
|
673
|
+
},
|
|
674
|
+
],
|
|
675
|
+
},
|
|
676
|
+
];
|
|
677
|
+
return new Map(platforms.map((p) => [p.name, p]));
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export interface AgentTarget {
|
|
681
|
+
/** Name used in output: the agent name, or the --dir path. */
|
|
682
|
+
name: string;
|
|
683
|
+
/** Explicitly given via --agent / --dir; targets not given explicitly skip agents not installed on this machine. */
|
|
684
|
+
explicit: boolean;
|
|
685
|
+
platform: AgentPlatform;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/* ------------------------------------------------------------------ */
|
|
689
|
+
/* Project-level platform directories */
|
|
690
|
+
/* ------------------------------------------------------------------ */
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Project-level layout differences: the default rule is `<projectRoot>/.<agent>/{skills,agents,commands}`
|
|
694
|
+
* (directories that are null globally stay null); the platforms below override individual directories or carry skip notes.
|
|
695
|
+
*/
|
|
696
|
+
const PROJECT_DIR_OVERRIDES: Record<
|
|
697
|
+
string,
|
|
698
|
+
Partial<{
|
|
699
|
+
skills: string | null;
|
|
700
|
+
agents: string | null;
|
|
701
|
+
commands: string | null;
|
|
702
|
+
agentsSkipNote: string;
|
|
703
|
+
commandsSkipNote: string;
|
|
704
|
+
}>
|
|
705
|
+
> = {
|
|
706
|
+
// pi: skills go to .pi/skills (deveco-cli project-level convention); project-level profiles are ignored by the platform
|
|
707
|
+
// and prompt templates are global only (~/.pi/prompts), so both are skipped with a note
|
|
708
|
+
pi: {
|
|
709
|
+
agents: null,
|
|
710
|
+
commands: null,
|
|
711
|
+
agentsSkipNote: 'pi ignores project-level subagent profiles',
|
|
712
|
+
commandsSkipNote: 'pi prompt templates are global-only (~/.pi/prompts)',
|
|
713
|
+
},
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Project-level root directory name: defaults to `.<agent>`. For some platforms the in-project directory name differs from the global one:
|
|
718
|
+
* trae-cn is ~/.trae-cn globally but .trae in a project; claude-code's directory name is
|
|
719
|
+
* .claude to begin with (not .claude-code).
|
|
720
|
+
*/
|
|
721
|
+
const PROJECT_ROOT_NAME: Record<string, string> = {
|
|
722
|
+
'trae-cn': '.trae',
|
|
723
|
+
'claude-code': '.claude',
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Map a global platform descriptor to project level (`<projectRoot>/<PROJECT_ROOT_NAME>/...`).
|
|
728
|
+
*
|
|
729
|
+
* - markerDir keeps the global detection directory: project-level targets still use "editor installed on this machine",
|
|
730
|
+
* since the agent directory inside the project is created by the install and cannot serve as an existence criterion.
|
|
731
|
+
* - legacyDirs is cleared: legacy location cleanup only targets wrong locations of old global installs and has nothing to do with projects.
|
|
732
|
+
* - skillsDir (the deveco-cli contract's ctx.skillsDir, optional) is preferred: the project root is its
|
|
733
|
+
* parent directory (e.g. <project>/.agents/skills -> <project>/.agents), with agents /
|
|
734
|
+
* commands under the same root; when not provided it is derived by the default rule. Takes effect only when the platform itself has a skills
|
|
735
|
+
* directory concept (platform.skillsDir !== null).
|
|
736
|
+
*/
|
|
737
|
+
export function toProjectPlatform(
|
|
738
|
+
platform: AgentPlatform,
|
|
739
|
+
projectRoot: string,
|
|
740
|
+
skillsDir?: string,
|
|
741
|
+
): AgentPlatform {
|
|
742
|
+
const override = PROJECT_DIR_OVERRIDES[platform.name] ?? {};
|
|
743
|
+
const cliSkillsDir =
|
|
744
|
+
typeof skillsDir === 'string' && platform.skillsDir !== null
|
|
745
|
+
? skillsDir
|
|
746
|
+
: undefined;
|
|
747
|
+
const root = cliSkillsDir
|
|
748
|
+
? path.dirname(cliSkillsDir)
|
|
749
|
+
: path.join(
|
|
750
|
+
projectRoot,
|
|
751
|
+
PROJECT_ROOT_NAME[platform.name] ?? '.' + platform.name,
|
|
752
|
+
);
|
|
753
|
+
const resolveDir = (
|
|
754
|
+
globalDir: string | null,
|
|
755
|
+
sub: 'skills' | 'agents' | 'commands',
|
|
756
|
+
overrideValue: string | null | undefined,
|
|
757
|
+
): string | null => {
|
|
758
|
+
if (overrideValue !== undefined) {
|
|
759
|
+
return overrideValue === null ? null : path.join(root, overrideValue);
|
|
760
|
+
}
|
|
761
|
+
return globalDir === null ? null : path.join(root, sub);
|
|
762
|
+
};
|
|
763
|
+
return {
|
|
764
|
+
...platform,
|
|
765
|
+
skillsDir:
|
|
766
|
+
cliSkillsDir ?? resolveDir(platform.skillsDir, 'skills', override.skills),
|
|
767
|
+
agentsDir: resolveDir(platform.agentsDir, 'agents', override.agents),
|
|
768
|
+
commandsDir: resolveDir(
|
|
769
|
+
platform.commandsDir,
|
|
770
|
+
'commands',
|
|
771
|
+
override.commands
|
|
772
|
+
),
|
|
773
|
+
agentsSkipNote: override.agentsSkipNote ?? platform.agentsSkipNote,
|
|
774
|
+
commandsSkipNote: override.commandsSkipNote ?? platform.commandsSkipNote,
|
|
775
|
+
legacyDirs: [],
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** Install target description for commands (commandsAsSkills platforms point at the skills directory). */
|
|
780
|
+
export function commandsDirLabel(platform: AgentPlatform): string | null {
|
|
781
|
+
if (platform.commandsDir) return platform.commandsDir;
|
|
782
|
+
if (platform.commandsAsSkills && platform.skillsDir) return `${platform.skillsDir} (as skills)`;
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Install a platform into an arbitrary given directory: skills / agents / commands go to
|
|
788
|
+
* `<targetRoot>/skills|agents|commands` respectively (directories the platform lacks stay null).
|
|
789
|
+
*
|
|
790
|
+
* Differences from `toProjectPlatform`:
|
|
791
|
+
* - no `.<agent>` prefix is appended; the target directory itself is the install root;
|
|
792
|
+
* - the platform's own formats are kept (Codex TOML, commandsAsSkills, AtomCode roles, etc.);
|
|
793
|
+
* - legacyDirs is cleared, so historical global installs outside the target directory are not deleted by mistake.
|
|
794
|
+
*/
|
|
795
|
+
export function toDirPlatform(platform: AgentPlatform, targetRoot: string): AgentPlatform {
|
|
796
|
+
const resolveDir = (
|
|
797
|
+
globalDir: string | null,
|
|
798
|
+
sub: 'skills' | 'agents' | 'commands',
|
|
799
|
+
): string | null => (globalDir === null ? null : path.join(targetRoot, sub));
|
|
800
|
+
return {
|
|
801
|
+
...platform,
|
|
802
|
+
markerDir: targetRoot,
|
|
803
|
+
skillsDir: resolveDir(platform.skillsDir, 'skills'),
|
|
804
|
+
agentsDir: resolveDir(platform.agentsDir, 'agents'),
|
|
805
|
+
commandsDir: resolveDir(platform.commandsDir, 'commands'),
|
|
806
|
+
legacyDirs: [],
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/* ------------------------------------------------------------------ */
|
|
811
|
+
/* skill conversion: per-field frontmatter routing */
|
|
812
|
+
/* ------------------------------------------------------------------ */
|
|
813
|
+
|
|
814
|
+
/** Agent Skills standard fields (allowed-tools is routed separately). */
|
|
815
|
+
const SKILL_STANDARD_KEYS = new Set(['name', 'description', 'license', 'compatibility', 'metadata']);
|
|
816
|
+
|
|
817
|
+
export interface SkillTransform {
|
|
818
|
+
content: string;
|
|
819
|
+
/** true = no rewrite needed; copy the original text directly. */
|
|
820
|
+
rawCopy: boolean;
|
|
821
|
+
notes: string[];
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function toolItems(v: FmValue): string[] {
|
|
825
|
+
if (Array.isArray(v)) return v.map((s) => s.trim()).filter(Boolean);
|
|
826
|
+
if (typeof v === 'string') return v.split(',').map((s) => s.trim()).filter(Boolean);
|
|
827
|
+
return [];
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/** Pi tool names are lowercase and subagents do not nest (no Agent/Task); strip argument qualifiers like Bash(...). */
|
|
831
|
+
function normalizePiTools(v: FmValue): string[] {
|
|
832
|
+
const out: string[] = [];
|
|
833
|
+
for (const t of toolItems(v)) {
|
|
834
|
+
const base = t.replace(/\(.*\)$/, '').toLowerCase();
|
|
835
|
+
if (!base || base === 'agent' || base === 'task') continue;
|
|
836
|
+
if (!out.includes(base)) out.push(base);
|
|
837
|
+
}
|
|
838
|
+
return out;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
export function transformSkillMd(platform: AgentPlatform, raw: string): SkillTransform {
|
|
842
|
+
if (platform.verbatim) return { content: raw, rawCopy: true, notes: [] };
|
|
843
|
+
const { fm, body, hasFrontmatter } = parseFrontmatter(raw);
|
|
844
|
+
if (!hasFrontmatter) return { content: raw, rawCopy: true, notes: [] };
|
|
845
|
+
const out: Frontmatter = {};
|
|
846
|
+
const metadata: Record<string, string> = { ...asRecord(fm.metadata) };
|
|
847
|
+
let dirty = false;
|
|
848
|
+
const notes: string[] = [];
|
|
849
|
+
|
|
850
|
+
for (const [key, value] of Object.entries(fm)) {
|
|
851
|
+
if (key === 'metadata') continue; // already merged into metadata, written back together at the end
|
|
852
|
+
if (SKILL_STANDARD_KEYS.has(key)) {
|
|
853
|
+
out[key] = value;
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
if (key === 'allowed-tools') {
|
|
857
|
+
if (platform.skillKeepAllowedTools) {
|
|
858
|
+
if (platform.name === 'pi') {
|
|
859
|
+
const normalized = normalizePiTools(value);
|
|
860
|
+
if (JSON.stringify(normalized) === JSON.stringify(toolItems(value))) {
|
|
861
|
+
out['allowed-tools'] = value;
|
|
862
|
+
} else {
|
|
863
|
+
out['allowed-tools'] = normalized;
|
|
864
|
+
dirty = true;
|
|
865
|
+
notes.push('allowed-tools normalized for pi (lowercase, Agent/Task dropped)');
|
|
866
|
+
}
|
|
867
|
+
} else {
|
|
868
|
+
out['allowed-tools'] = value;
|
|
869
|
+
}
|
|
870
|
+
} else {
|
|
871
|
+
dirty = true;
|
|
872
|
+
notes.push(`dropped allowed-tools (${platform.name} has no skill-level tool allowlist)`);
|
|
873
|
+
}
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (key === 'argument-hint') {
|
|
877
|
+
if (platform.skillKeepArgumentHint) {
|
|
878
|
+
out['argument-hint'] = value;
|
|
879
|
+
} else if (platform.skillSlashMetadata) {
|
|
880
|
+
// argument-hint means the user can invoke it explicitly with arguments; OpenCode exposes it as a slash command
|
|
881
|
+
metadata['opencode/slash'] = 'true';
|
|
882
|
+
dirty = true;
|
|
883
|
+
notes.push('argument-hint -> metadata opencode/slash (slash command exposure)');
|
|
884
|
+
} else {
|
|
885
|
+
dirty = true;
|
|
886
|
+
notes.push(`dropped argument-hint (no equivalent on ${platform.name})`);
|
|
887
|
+
}
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
// Other non-standard top-level fields: move into the standard metadata, keeping the data and meeting
|
|
891
|
+
// the platform requirement "no new top-level fields" (OpenCode / DevEco / Claude Code upload paths)
|
|
892
|
+
metadata[key] = fmValueToString(value);
|
|
893
|
+
dirty = true;
|
|
894
|
+
notes.push(`relocated top-level ${key} -> metadata.${key}`);
|
|
895
|
+
}
|
|
896
|
+
if (Object.keys(metadata).length > 0) {
|
|
897
|
+
out.metadata = metadata;
|
|
898
|
+
if (!('metadata' in fm)) dirty = true;
|
|
899
|
+
}
|
|
900
|
+
if (!dirty) return { content: raw, rawCopy: true, notes: [] };
|
|
901
|
+
return { content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/* ------------------------------------------------------------------ */
|
|
905
|
+
/* agent conversion: generated per platform format */
|
|
906
|
+
/* ------------------------------------------------------------------ */
|
|
907
|
+
|
|
908
|
+
export interface AgentTransform {
|
|
909
|
+
fileName: string;
|
|
910
|
+
content: string;
|
|
911
|
+
rawCopy: boolean;
|
|
912
|
+
notes: string[];
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** Source permission key -> Claude-family tool names (edit covers Edit+Write; task accepts both Agent/Task namings). */
|
|
916
|
+
const PERMISSION_TO_TOOLS: Record<string, string[]> = {
|
|
917
|
+
edit: ['Edit', 'Write'],
|
|
918
|
+
bash: ['Bash'],
|
|
919
|
+
task: ['Agent', 'Task'],
|
|
920
|
+
webfetch: ['WebFetch'],
|
|
921
|
+
websearch: ['WebSearch'],
|
|
922
|
+
read: ['Read'],
|
|
923
|
+
glob: ['Glob'],
|
|
924
|
+
grep: ['Grep'],
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
/** Single-line TOML basic string (escapes backslashes and double quotes). */
|
|
928
|
+
function tomlInline(s: string): string {
|
|
929
|
+
return '"' + s.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/** Multi-line TOML literal string; falls back to an escaped basic string when the content contains '''. */
|
|
933
|
+
function tomlMultiline(s: string): string {
|
|
934
|
+
const body = s.replace(/\r\n/g, '\n');
|
|
935
|
+
if (!body.includes("'''")) return `'''\n${body}\n'''`;
|
|
936
|
+
return (
|
|
937
|
+
'"' + body.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\r/g, '\\r').replace(/\n/g, '\\n') + '"'
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** Take the first sentence of description as AtomCode's when (the whole text when there is no period; truncated if too long). */
|
|
942
|
+
function firstSentence(text: string, max = 200): string {
|
|
943
|
+
const m = /^[\s\S]*?[.!?](\s|$)/.exec(text);
|
|
944
|
+
let s = (m ? m[0] : text).trim();
|
|
945
|
+
if (s.length > max) s = s.slice(0, max - 1).replace(/\s+\S*$/, '') + '…';
|
|
946
|
+
return s;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Note on dropping the mode field. mode: all = the dual "primary agent + subagent" identity, where the primary-agent half
|
|
951
|
+
* exists only in the OpenCode family; claude-code's session-level `claude --agent <name>` usage is a native
|
|
952
|
+
* equivalent, and other platforms have no matching mechanism (the subagent half is kept natively on every platform).
|
|
953
|
+
*/
|
|
954
|
+
function droppedModeNote(mode: string | undefined, platform: AgentPlatform): string | undefined {
|
|
955
|
+
if (mode === undefined) return undefined;
|
|
956
|
+
if (mode !== 'all') return `dropped mode: ${mode}`;
|
|
957
|
+
if (platform.agentFormat === 'claude') {
|
|
958
|
+
return "dropped mode: all - primary-style use natively available via 'claude --agent <name>'";
|
|
959
|
+
}
|
|
960
|
+
return `dropped mode: all - ${platform.name} has no primary-agent concept (subagent dispatch preserved)`;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Convert a bundled agent md (OpenCode-style frontmatter: name / description / mode /
|
|
965
|
+
* permission + body) into the target platform's format. Returns null when the platform has no file-based
|
|
966
|
+
* subagents (dsh); the caller skips it.
|
|
967
|
+
*/
|
|
968
|
+
export function transformAgentMd(
|
|
969
|
+
platform: AgentPlatform,
|
|
970
|
+
fileName: string,
|
|
971
|
+
raw: string,
|
|
972
|
+
): AgentTransform | null {
|
|
973
|
+
if (platform.agentFormat === 'none') return null;
|
|
974
|
+
if (platform.verbatim || platform.agentFormat === 'passthrough') {
|
|
975
|
+
// OpenCode family: mode / permission natively supported, passed through as is
|
|
976
|
+
return { fileName, content: raw, rawCopy: true, notes: [] };
|
|
977
|
+
}
|
|
978
|
+
const { fm, body } = parseFrontmatter(raw);
|
|
979
|
+
const name = asString(fm.name) || fileName.replace(/\.md$/, '');
|
|
980
|
+
const description = asString(fm.description) ?? '';
|
|
981
|
+
const permission = asRecord(fm.permission);
|
|
982
|
+
const denies = Object.keys(permission).filter((k) => permission[k] === 'deny');
|
|
983
|
+
const allows = Object.keys(permission).filter((k) => permission[k] === 'allow');
|
|
984
|
+
const bodyText = body.replace(/^\r?\n/, '').replace(/\s+$/, '');
|
|
985
|
+
const modeNote = droppedModeNote(asString(fm.mode), platform);
|
|
986
|
+
|
|
987
|
+
switch (platform.agentFormat) {
|
|
988
|
+
case 'claude':
|
|
989
|
+
case 'codebuddy': {
|
|
990
|
+
const out: Frontmatter = { name, description };
|
|
991
|
+
const notes: string[] = [];
|
|
992
|
+
const disallowed = [...new Set(denies.flatMap((k) => PERMISSION_TO_TOOLS[k] ?? []))];
|
|
993
|
+
if (disallowed.length > 0) {
|
|
994
|
+
out.disallowedTools = disallowed;
|
|
995
|
+
notes.push(`permission deny (${denies.join(', ')}) -> disallowedTools: ${disallowed.join(', ')}`);
|
|
996
|
+
}
|
|
997
|
+
if (modeNote) notes.push(modeNote);
|
|
998
|
+
return { fileName, content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
999
|
+
}
|
|
1000
|
+
case 'cursor': {
|
|
1001
|
+
const out: Frontmatter = { name, description };
|
|
1002
|
+
const notes: string[] = [];
|
|
1003
|
+
if (permission.edit === 'deny') {
|
|
1004
|
+
out.readonly = true;
|
|
1005
|
+
notes.push('permission edit deny -> readonly: true');
|
|
1006
|
+
}
|
|
1007
|
+
const rest = denies.filter((k) => k !== 'edit');
|
|
1008
|
+
if (rest.length > 0) {
|
|
1009
|
+
notes.push(`dropped permission deny (${rest.join(', ')}) - no Cursor equivalent`);
|
|
1010
|
+
}
|
|
1011
|
+
if (modeNote) notes.push(modeNote);
|
|
1012
|
+
return { fileName, content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
1013
|
+
}
|
|
1014
|
+
case 'qoder': {
|
|
1015
|
+
const out: Frontmatter = { name, description };
|
|
1016
|
+
const notes: string[] = [];
|
|
1017
|
+
if (Object.keys(permission).length > 0) {
|
|
1018
|
+
// Qoder has no denylist, only an allowlist: basic read tools + permission-allowed items
|
|
1019
|
+
// (the Qoder tool set has no Agent/Task)
|
|
1020
|
+
const tools = new Set<string>(['Read', 'Glob', 'Grep']);
|
|
1021
|
+
for (const k of allows) {
|
|
1022
|
+
for (const t of PERMISSION_TO_TOOLS[k] ?? []) {
|
|
1023
|
+
if (t !== 'Agent' && t !== 'Task') tools.add(t);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
out.tools = [...tools];
|
|
1027
|
+
notes.push(`permission -> tools whitelist: ${out.tools.join(', ')}`);
|
|
1028
|
+
}
|
|
1029
|
+
if (modeNote) notes.push(modeNote);
|
|
1030
|
+
return { fileName, content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
1031
|
+
}
|
|
1032
|
+
case 'trae': {
|
|
1033
|
+
const out: Frontmatter = { name, description };
|
|
1034
|
+
const notes: string[] = [];
|
|
1035
|
+
// The Trae tool set has no Agent/Task, so task deny has no counterpart
|
|
1036
|
+
const disallowed = [
|
|
1037
|
+
...new Set(denies.flatMap((k) => PERMISSION_TO_TOOLS[k] ?? [])),
|
|
1038
|
+
].filter((t) => t !== 'Agent' && t !== 'Task');
|
|
1039
|
+
if (disallowed.length > 0) {
|
|
1040
|
+
// Trae's tools field convention is a comma-separated string (stated in the tools docs);
|
|
1041
|
+
// the block list form makes frontmatter parsing fail and the whole file gets skipped
|
|
1042
|
+
out.disallowedTools = disallowed.join(', ');
|
|
1043
|
+
notes.push(`permission deny (${denies.join(', ')}) -> disallowedTools: ${out.disallowedTools}`);
|
|
1044
|
+
}
|
|
1045
|
+
if (denies.includes('task')) {
|
|
1046
|
+
notes.push('dropped permission task deny - Trae subagents have no Task tool');
|
|
1047
|
+
}
|
|
1048
|
+
if (modeNote) notes.push(modeNote);
|
|
1049
|
+
return { fileName, content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
1050
|
+
}
|
|
1051
|
+
case 'pi-profile': {
|
|
1052
|
+
const out: Frontmatter = { name, description };
|
|
1053
|
+
const notes: string[] = [];
|
|
1054
|
+
if (Object.keys(permission).length > 0) {
|
|
1055
|
+
// Pi profile tools are comma-separated lowercase tool names; Pi subagents themselves forbid nesting
|
|
1056
|
+
const tools = new Set<string>(['read', 'glob', 'grep']);
|
|
1057
|
+
if (allows.includes('edit')) {
|
|
1058
|
+
tools.add('edit');
|
|
1059
|
+
tools.add('write');
|
|
1060
|
+
}
|
|
1061
|
+
if (allows.includes('bash')) tools.add('bash');
|
|
1062
|
+
if (allows.includes('webfetch')) tools.add('webfetch');
|
|
1063
|
+
if (allows.includes('websearch')) tools.add('websearch');
|
|
1064
|
+
out.tools = [...tools].join(', ');
|
|
1065
|
+
notes.push(`permission -> tools: ${out.tools}`);
|
|
1066
|
+
}
|
|
1067
|
+
if (modeNote) notes.push(modeNote);
|
|
1068
|
+
return { fileName, content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
1069
|
+
}
|
|
1070
|
+
case 'codex-toml': {
|
|
1071
|
+
const notes: string[] = ['converted to Codex subagent TOML (body -> developer_instructions)'];
|
|
1072
|
+
const lines: string[] = [`name = ${tomlInline(name)}`];
|
|
1073
|
+
if (description) lines.push(`description = ${tomlInline(description)}`);
|
|
1074
|
+
// sandbox_mode is not written: Codex custom agents inherit the parent session's sandbox, so setting it in the custom file has no effect
|
|
1075
|
+
let instructions = bodyText;
|
|
1076
|
+
if (permission.edit === 'deny') {
|
|
1077
|
+
instructions +=
|
|
1078
|
+
'\n\nConstraint: never modify, create, or delete any file - this agent is read-only.';
|
|
1079
|
+
notes.push('permission edit deny -> read-only constraint appended (no per-agent write sandbox)');
|
|
1080
|
+
}
|
|
1081
|
+
lines.push(`developer_instructions = ${tomlMultiline(instructions)}`);
|
|
1082
|
+
if (permission.bash === 'deny') {
|
|
1083
|
+
// The [features] table must come after all top-level keys
|
|
1084
|
+
lines.push('', '[features]', 'shell_tool = false');
|
|
1085
|
+
notes.push('permission bash deny -> features.shell_tool = false');
|
|
1086
|
+
}
|
|
1087
|
+
if (modeNote) notes.push(modeNote);
|
|
1088
|
+
return {
|
|
1089
|
+
fileName: fileName.replace(/\.md$/, '.toml'),
|
|
1090
|
+
content: lines.join('\n') + '\n',
|
|
1091
|
+
rawCopy: false,
|
|
1092
|
+
notes,
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
case 'atomcode-role': {
|
|
1096
|
+
// AtomCode role format: name/description are not read, permission + difficulty are required;
|
|
1097
|
+
// difficulty is always hard (so complex tasks are not routed to a fast model)
|
|
1098
|
+
const permissionValue = permission.edit === 'deny' ? 'explore' : 'worker';
|
|
1099
|
+
const out: Frontmatter = {
|
|
1100
|
+
permission: permissionValue,
|
|
1101
|
+
difficulty: 'hard',
|
|
1102
|
+
when: firstSentence(description),
|
|
1103
|
+
name,
|
|
1104
|
+
description,
|
|
1105
|
+
};
|
|
1106
|
+
const notes: string[] = [
|
|
1107
|
+
`converted to AtomCode role format (permission: ${permissionValue}, difficulty: hard)`,
|
|
1108
|
+
'difficulty defaults to hard (no source equivalent)',
|
|
1109
|
+
];
|
|
1110
|
+
return { fileName, content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
1111
|
+
}
|
|
1112
|
+
default:
|
|
1113
|
+
return { fileName, content: raw, rawCopy: true, notes: [] };
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/* ------------------------------------------------------------------ */
|
|
1118
|
+
/* command conversion: per-field frontmatter routing */
|
|
1119
|
+
/* ------------------------------------------------------------------ */
|
|
1120
|
+
|
|
1121
|
+
export interface CommandTransform {
|
|
1122
|
+
content: string;
|
|
1123
|
+
/** true = no rewrite needed; copy the original text directly. */
|
|
1124
|
+
rawCopy: boolean;
|
|
1125
|
+
notes: string[];
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Route the frontmatter fields of a bundled command md per platform: keys outside commandKeepKeys
|
|
1130
|
+
* are dropped with a note; claude-code additionally translates subtask: true (forced subagent execution) to
|
|
1131
|
+
* context: fork. The body template is untouched ($ARGUMENTS / $1-$3 are the cross-platform placeholder intersection).
|
|
1132
|
+
*/
|
|
1133
|
+
export function transformCommandMd(platform: AgentPlatform, raw: string): CommandTransform {
|
|
1134
|
+
if (platform.verbatim || platform.commandsDir === null) {
|
|
1135
|
+
return { content: raw, rawCopy: true, notes: [] };
|
|
1136
|
+
}
|
|
1137
|
+
const { fm, body, hasFrontmatter } = parseFrontmatter(raw);
|
|
1138
|
+
if (!hasFrontmatter) return { content: raw, rawCopy: true, notes: [] };
|
|
1139
|
+
const keep = new Set(platform.commandKeepKeys);
|
|
1140
|
+
const out: Frontmatter = {};
|
|
1141
|
+
let dirty = false;
|
|
1142
|
+
const notes: string[] = [];
|
|
1143
|
+
for (const [key, value] of Object.entries(fm)) {
|
|
1144
|
+
if (keep.has(key)) {
|
|
1145
|
+
out[key] = value;
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (key === 'subtask' && platform.agentFormat === 'claude' && value === 'true') {
|
|
1149
|
+
// subtask: true (forced subagent execution in the OpenCode family) ~= Claude Code's context: fork
|
|
1150
|
+
out.context = 'fork';
|
|
1151
|
+
dirty = true;
|
|
1152
|
+
notes.push('subtask: true -> context: fork');
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
dirty = true;
|
|
1156
|
+
notes.push(`dropped ${key} (not supported in ${platform.name} commands)`);
|
|
1157
|
+
}
|
|
1158
|
+
if (!dirty) return { content: raw, rawCopy: true, notes: [] };
|
|
1159
|
+
// No supported field at all (e.g. a command without description): remove the whole frontmatter block and keep only
|
|
1160
|
+
// the body -- an empty `---\n---` block fails read-back validation, and the platform does not parse it anyway
|
|
1161
|
+
if (Object.keys(out).length === 0) {
|
|
1162
|
+
return { content: body, rawCopy: false, notes };
|
|
1163
|
+
}
|
|
1164
|
+
return { content: serializeFrontmatter(out) + body, rawCopy: false, notes };
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
export interface CommandSkillTransform {
|
|
1168
|
+
/** Converted skill name (command file name without .md, i.e. the directory name under skills/). */
|
|
1169
|
+
skillName: string;
|
|
1170
|
+
/** SKILL.md content. */
|
|
1171
|
+
content: string;
|
|
1172
|
+
/** Content of Codex's agents/openai.yaml; null = the platform needs no sidecar. */
|
|
1173
|
+
openaiYaml: string | null;
|
|
1174
|
+
notes: string[];
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* Convert a bundled command md into a skill (Codex custom prompts are deprecated, DSH /
|
|
1179
|
+
* AtomCode have no file-based commands; the official carrier is a skill everywhere). name +
|
|
1180
|
+
* description form the skill frontmatter; the body is kept unchanged, so the $ARGUMENTS placeholder is preserved
|
|
1181
|
+
* as-is; subtask / argument-hint have no skill counterpart and are dropped with
|
|
1182
|
+
* a note. The "explicitly user-triggered only" command semantics are kept with each platform's native mechanism:
|
|
1183
|
+
* - codex: policy.allow_implicit_invocation = false in agents/openai.yaml;
|
|
1184
|
+
* - dsh: the native frontmatter keys disable-model-invocation + user-invocable
|
|
1185
|
+
* (combined = user-invocable only).
|
|
1186
|
+
* - atomcode: no native mechanism to keep it (the model can invoke it automatically via use_skill); only noted in the log.
|
|
1187
|
+
*/
|
|
1188
|
+
export function commandToSkillMd(
|
|
1189
|
+
platform: AgentPlatform,
|
|
1190
|
+
fileName: string,
|
|
1191
|
+
raw: string,
|
|
1192
|
+
): CommandSkillTransform {
|
|
1193
|
+
const { fm, body } = parseFrontmatter(raw);
|
|
1194
|
+
const skillName = fileName.replace(/\.md$/, '');
|
|
1195
|
+
const notes: string[] = [];
|
|
1196
|
+
const out: Frontmatter = { name: skillName };
|
|
1197
|
+
const description = asString(fm.description);
|
|
1198
|
+
if (description) out.description = description;
|
|
1199
|
+
if ('subtask' in fm) notes.push('dropped subtask (no skill equivalent)');
|
|
1200
|
+
if ('argument-hint' in fm) notes.push('dropped argument-hint (no skill equivalent)');
|
|
1201
|
+
let openaiYaml: string | null = null;
|
|
1202
|
+
if (platform.name === 'codex') {
|
|
1203
|
+
notes.push('converted command to skill (Codex custom prompts deprecated)');
|
|
1204
|
+
notes.push('openai.yaml: allow_implicit_invocation=false (commands are user-triggered)');
|
|
1205
|
+
openaiYaml = 'policy:\n allow_implicit_invocation: false\n';
|
|
1206
|
+
} else if (platform.name === 'dsh') {
|
|
1207
|
+
notes.push('converted command to skill (DSH has no file-based commands)');
|
|
1208
|
+
out['disable-model-invocation'] = true;
|
|
1209
|
+
out['user-invocable'] = true;
|
|
1210
|
+
notes.push('disable-model-invocation + user-invocable -> user-only invocation (DSH native keys)');
|
|
1211
|
+
} else if (platform.name === 'atomcode') {
|
|
1212
|
+
notes.push(
|
|
1213
|
+
'converted command to skill (each skill appears as /<skill-name>; $<skill-name> <args> carries inline arguments)',
|
|
1214
|
+
);
|
|
1215
|
+
notes.push('user-only invocation not preservable (AtomCode model may auto-invoke via use_skill)');
|
|
1216
|
+
} else {
|
|
1217
|
+
notes.push('converted command to skill');
|
|
1218
|
+
}
|
|
1219
|
+
return {
|
|
1220
|
+
skillName,
|
|
1221
|
+
content: serializeFrontmatter(out) + body,
|
|
1222
|
+
openaiYaml,
|
|
1223
|
+
notes,
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/* ------------------------------------------------------------------ */
|
|
1228
|
+
/* Validator: read-back checks after install */
|
|
1229
|
+
/* ------------------------------------------------------------------ */
|
|
1230
|
+
|
|
1231
|
+
export interface ValidationIssue {
|
|
1232
|
+
level: 'error' | 'warn';
|
|
1233
|
+
message: string;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
const SKILL_NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
1237
|
+
|
|
1238
|
+
/** Common rules; `descriptionLimit` is passed only when the target platform really has that hard limit. */
|
|
1239
|
+
export function validateSkillMd(
|
|
1240
|
+
skillName: string,
|
|
1241
|
+
raw: string,
|
|
1242
|
+
descriptionLimit?: number,
|
|
1243
|
+
): ValidationIssue[] {
|
|
1244
|
+
const issues: ValidationIssue[] = [];
|
|
1245
|
+
const { fm, hasFrontmatter } = parseFrontmatter(raw);
|
|
1246
|
+
if (!hasFrontmatter) {
|
|
1247
|
+
issues.push({
|
|
1248
|
+
level: 'error',
|
|
1249
|
+
message: `${skillName}: SKILL.md has no frontmatter block starting with --- on line 1`,
|
|
1250
|
+
});
|
|
1251
|
+
return issues;
|
|
1252
|
+
}
|
|
1253
|
+
const name = asString(fm.name);
|
|
1254
|
+
if (!name) {
|
|
1255
|
+
issues.push({ level: 'error', message: `${skillName}: missing name` });
|
|
1256
|
+
} else {
|
|
1257
|
+
if (!SKILL_NAME_RE.test(name)) {
|
|
1258
|
+
issues.push({ level: 'error', message: `${skillName}: name "${name}" is not kebab-case` });
|
|
1259
|
+
}
|
|
1260
|
+
if (name.length > 64) {
|
|
1261
|
+
issues.push({ level: 'error', message: `${skillName}: name exceeds 64 chars` });
|
|
1262
|
+
}
|
|
1263
|
+
if (name !== skillName) {
|
|
1264
|
+
issues.push({ level: 'error', message: `${skillName}: name "${name}" != directory name` });
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
const description = asString(fm.description);
|
|
1268
|
+
if (!description) {
|
|
1269
|
+
issues.push({ level: 'error', message: `${skillName}: missing description` });
|
|
1270
|
+
} else if (descriptionLimit !== undefined && description.length > descriptionLimit) {
|
|
1271
|
+
issues.push({
|
|
1272
|
+
level: 'warn',
|
|
1273
|
+
message: `${skillName}: description ${description.length} chars > ${descriptionLimit} (platform hard limit); installed as-is, platform may refuse to load`,
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
return issues;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
export function validateAgentFile(
|
|
1280
|
+
platform: AgentPlatform,
|
|
1281
|
+
fileName: string,
|
|
1282
|
+
raw: string,
|
|
1283
|
+
): ValidationIssue[] {
|
|
1284
|
+
const issues: ValidationIssue[] = [];
|
|
1285
|
+
const base = fileName.replace(/\.(md|toml)$/, '');
|
|
1286
|
+
if (platform.agentFormat === 'codex-toml') {
|
|
1287
|
+
if (!/^name\s*=/m.test(raw)) issues.push({ level: 'error', message: `${base}.toml: missing name` });
|
|
1288
|
+
if (!/^description\s*=/m.test(raw)) {
|
|
1289
|
+
issues.push({ level: 'error', message: `${base}.toml: missing description` });
|
|
1290
|
+
}
|
|
1291
|
+
if (!/^developer_instructions\s*=/m.test(raw)) {
|
|
1292
|
+
issues.push({ level: 'error', message: `${base}.toml: missing developer_instructions` });
|
|
1293
|
+
}
|
|
1294
|
+
return issues;
|
|
1295
|
+
}
|
|
1296
|
+
const { fm, hasFrontmatter } = parseFrontmatter(raw);
|
|
1297
|
+
if (!hasFrontmatter) {
|
|
1298
|
+
issues.push({ level: 'error', message: `${base}: no frontmatter block starting with --- on line 1` });
|
|
1299
|
+
return issues;
|
|
1300
|
+
}
|
|
1301
|
+
if (platform.agentFormat === 'atomcode-role') {
|
|
1302
|
+
const permission = asString(fm.permission);
|
|
1303
|
+
if (permission !== 'explore' && permission !== 'worker') {
|
|
1304
|
+
issues.push({ level: 'error', message: `${base}: permission must be explore|worker` });
|
|
1305
|
+
}
|
|
1306
|
+
const difficulty = asString(fm.difficulty);
|
|
1307
|
+
if (difficulty !== 'simple' && difficulty !== 'hard') {
|
|
1308
|
+
issues.push({ level: 'error', message: `${base}: difficulty must be simple|hard` });
|
|
1309
|
+
}
|
|
1310
|
+
return issues;
|
|
1311
|
+
}
|
|
1312
|
+
const name = asString(fm.name);
|
|
1313
|
+
if (!name) {
|
|
1314
|
+
issues.push({ level: 'error', message: `${base}: missing name` });
|
|
1315
|
+
} else {
|
|
1316
|
+
if ((platform.name === 'trae' || platform.name === 'trae-cn') && name.length > 50) {
|
|
1317
|
+
issues.push({ level: 'error', message: `${base}: name ${name.length} chars > 50 (trae limit)` });
|
|
1318
|
+
}
|
|
1319
|
+
if (platform.name === 'claude-code') {
|
|
1320
|
+
if (name.length > 256) {
|
|
1321
|
+
issues.push({ level: 'error', message: `${base}: name exceeds 256 chars` });
|
|
1322
|
+
}
|
|
1323
|
+
if (name.includes(':')) {
|
|
1324
|
+
issues.push({ level: 'error', message: `${base}: name must not contain ':'` });
|
|
1325
|
+
}
|
|
1326
|
+
if (name.startsWith('-')) {
|
|
1327
|
+
issues.push({ level: 'error', message: `${base}: name must not start with '-'` });
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
if (!asString(fm.description)) {
|
|
1332
|
+
issues.push({ level: 'error', message: `${base}: missing description` });
|
|
1333
|
+
}
|
|
1334
|
+
return issues;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Cross-platform rules for command md: file names are lowercase kebab-case (trae / qoder / codex naming
|
|
1339
|
+
* constraints); frontmatter integrity;
|
|
1340
|
+
* a missing description only warns (completion list empty, qoder may not list it); codebuddy's
|
|
1341
|
+
* `` !`cmd` `` injection requires allowed-tools to include Bash.
|
|
1342
|
+
*/
|
|
1343
|
+
export function validateCommandMd(
|
|
1344
|
+
platform: AgentPlatform,
|
|
1345
|
+
fileName: string,
|
|
1346
|
+
raw: string,
|
|
1347
|
+
): ValidationIssue[] {
|
|
1348
|
+
const issues: ValidationIssue[] = [];
|
|
1349
|
+
const base = fileName.replace(/\.md$/, '');
|
|
1350
|
+
if (!SKILL_NAME_RE.test(base)) {
|
|
1351
|
+
issues.push({
|
|
1352
|
+
level: 'error',
|
|
1353
|
+
message: `${fileName}: command name "${base}" is not lowercase kebab-case (trae/qoder/codex naming constraint)`,
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
if (!raw.startsWith('---')) {
|
|
1357
|
+
issues.push({
|
|
1358
|
+
level: 'warn',
|
|
1359
|
+
message: `${fileName}: no frontmatter block - description missing from command list`,
|
|
1360
|
+
});
|
|
1361
|
+
return issues;
|
|
1362
|
+
}
|
|
1363
|
+
const { fm, body, hasFrontmatter } = parseFrontmatter(raw);
|
|
1364
|
+
if (!hasFrontmatter) {
|
|
1365
|
+
issues.push({
|
|
1366
|
+
level: 'error',
|
|
1367
|
+
message: `${fileName}: malformed frontmatter (--- must open and close the block)`,
|
|
1368
|
+
});
|
|
1369
|
+
return issues;
|
|
1370
|
+
}
|
|
1371
|
+
if (!asString(fm.description)) {
|
|
1372
|
+
issues.push({
|
|
1373
|
+
level: 'warn',
|
|
1374
|
+
message: `${fileName}: no description - autocomplete shows nothing (qoder may not list it)`,
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
if (body.trim() === '') {
|
|
1378
|
+
issues.push({
|
|
1379
|
+
level: 'warn',
|
|
1380
|
+
message: `${fileName}: empty body - qoder will not list this command`,
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
if (platform.agentFormat === 'codebuddy' && body.includes('!`')) {
|
|
1384
|
+
const allowed =
|
|
1385
|
+
typeof fm['allowed-tools'] === 'string'
|
|
1386
|
+
? fm['allowed-tools']
|
|
1387
|
+
: Array.isArray(fm['allowed-tools'])
|
|
1388
|
+
? fm['allowed-tools'].join(',')
|
|
1389
|
+
: '';
|
|
1390
|
+
if (!/\bBash\b/.test(allowed)) {
|
|
1391
|
+
issues.push({
|
|
1392
|
+
level: 'warn',
|
|
1393
|
+
message: `${fileName}: body uses !\`cmd\` injection but allowed-tools lacks Bash (codebuddy requires it)`,
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return issues;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/* ------------------------------------------------------------------ */
|
|
1401
|
+
/* File operations */
|
|
1402
|
+
/* ------------------------------------------------------------------ */
|
|
1403
|
+
|
|
1404
|
+
export async function exists(p: string): Promise<boolean> {
|
|
1405
|
+
try {
|
|
1406
|
+
await fs.access(p);
|
|
1407
|
+
return true;
|
|
1408
|
+
} catch {
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/** Bundled skill directory names (subdirectories containing SKILL.md). */
|
|
1414
|
+
export async function listBundledSkills(
|
|
1415
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1416
|
+
): Promise<string[]> {
|
|
1417
|
+
const names: string[] = [];
|
|
1418
|
+
for (const name of await resolver.listNames('skills', 'dir')) {
|
|
1419
|
+
if (await resolver.has(`skills/${name}/SKILL.md`)) names.push(name);
|
|
1420
|
+
}
|
|
1421
|
+
return names;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
/** Top-level entry names (files and directories) of the bundled agents/. */
|
|
1425
|
+
export async function listBundledAgents(
|
|
1426
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1427
|
+
): Promise<string[]> {
|
|
1428
|
+
return resolver.listNames('agents', 'entry');
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
/** Slash command file names (*.md) under the bundled commands/. */
|
|
1432
|
+
export async function listBundledCommands(
|
|
1433
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1434
|
+
): Promise<string[]> {
|
|
1435
|
+
return (await resolver.listNames('commands', 'file')).filter((name) => name.endsWith('.md'));
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* Copy a whole package-relative directory into `dest`, resolving every file through the language resolver first
|
|
1440
|
+
* (an English install therefore lands translated content, and translated file names, under their English names).
|
|
1441
|
+
*/
|
|
1442
|
+
async function copyResolvedDir(
|
|
1443
|
+
resolver: ContentResolver,
|
|
1444
|
+
relDir: string,
|
|
1445
|
+
dest: string,
|
|
1446
|
+
): Promise<void> {
|
|
1447
|
+
await fs.mkdir(dest, { recursive: true });
|
|
1448
|
+
for (const file of await resolver.walkDir(relDir)) {
|
|
1449
|
+
const rel = path.posix.relative(relDir, file.destRel);
|
|
1450
|
+
const out = path.join(dest, ...rel.split('/'));
|
|
1451
|
+
await fs.mkdir(path.dirname(out), { recursive: true });
|
|
1452
|
+
await fs.copyFile(file.src, out);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* File-level overrides (skills / directory-form agents): copy the files under platforms/<platform>/<kind>/<name>/
|
|
1458
|
+
* to dest -- same names overwrite (the platforms version wins over the bundled root version), and new files are brought along too.
|
|
1459
|
+
* File names in exclude are skipped: a skill's SKILL.frontmatter.md / SKILL.unique.md are assembly inputs and
|
|
1460
|
+
* SKILL.md is the assembly output (written last by installTo); none of the three take part in overriding.
|
|
1461
|
+
* dryRun only counts and writes nothing. Returns the number of files copied.
|
|
1462
|
+
*/
|
|
1463
|
+
async function copyOverlayFiles(
|
|
1464
|
+
resolver: ContentResolver,
|
|
1465
|
+
relDir: string,
|
|
1466
|
+
dest: string,
|
|
1467
|
+
exclude: ReadonlySet<string>,
|
|
1468
|
+
dryRun: boolean,
|
|
1469
|
+
): Promise<number> {
|
|
1470
|
+
let count = 0;
|
|
1471
|
+
for (const file of await resolver.walkDir(relDir)) {
|
|
1472
|
+
const rel = path.posix.relative(relDir, file.destRel);
|
|
1473
|
+
if (exclude.has(path.posix.basename(rel))) continue;
|
|
1474
|
+
count++;
|
|
1475
|
+
if (dryRun) continue;
|
|
1476
|
+
const out = path.join(dest, ...rel.split('/'));
|
|
1477
|
+
await fs.mkdir(path.dirname(out), { recursive: true });
|
|
1478
|
+
await fs.copyFile(file.src, out);
|
|
1479
|
+
}
|
|
1480
|
+
return count;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
/** The assembly trio skipped during skills file-level overrides (two inputs + one output). */
|
|
1484
|
+
const SKILL_OVERLAY_EXCLUDE = new Set(['SKILL.frontmatter.md', 'SKILL.unique.md', 'SKILL.md']);
|
|
1485
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* Same-named source files prefer platforms (file-form agents / commands): when platforms/<platform>/<kind>/<name>
|
|
1488
|
+
* exists it is used as the assembly source body (same name -> the platforms version wins), otherwise fall back to the bundled root.
|
|
1489
|
+
*/
|
|
1490
|
+
async function platformSourcePath(
|
|
1491
|
+
platformName: string,
|
|
1492
|
+
kind: 'agents' | 'commands',
|
|
1493
|
+
name: string,
|
|
1494
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1495
|
+
): Promise<{ src: string; overlay: boolean }> {
|
|
1496
|
+
const rel = `platforms/${platformName}/${kind}/${name}`;
|
|
1497
|
+
if (await resolver.has(rel)) return { src: await resolver.resolve(rel), overlay: true };
|
|
1498
|
+
return { src: await resolver.resolve(`${kind}/${name}`), overlay: false };
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
/** Agent file names to clean up on uninstall / detection: codex targets additionally clean the raw md copied by historical versions. */
|
|
1502
|
+
function agentFileCandidates(platform: AgentPlatform, mdName: string): string[] {
|
|
1503
|
+
return platform.agentFormat === 'codex-toml'
|
|
1504
|
+
? [mdName.replace(/\.md$/, '.toml'), mdName]
|
|
1505
|
+
: [mdName];
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/** Delete bundled content that old versions installed in wrong locations (does not affect the user's own files). */
|
|
1509
|
+
async function cleanLegacyDirs(
|
|
1510
|
+
platform: AgentPlatform,
|
|
1511
|
+
resolver: ContentResolver,
|
|
1512
|
+
): Promise<void> {
|
|
1513
|
+
if (platform.legacyDirs.length === 0) return;
|
|
1514
|
+
const skills = await listBundledSkills(resolver);
|
|
1515
|
+
const agents = await listBundledAgents(resolver);
|
|
1516
|
+
const commands = await listBundledCommands(resolver);
|
|
1517
|
+
for (const legacy of platform.legacyDirs) {
|
|
1518
|
+
if (legacy.skillsDir) {
|
|
1519
|
+
for (const s of skills) await fs.rm(path.join(legacy.skillsDir, s), { recursive: true, force: true });
|
|
1520
|
+
}
|
|
1521
|
+
if (legacy.agentsDir) {
|
|
1522
|
+
for (const a of agents) await fs.rm(path.join(legacy.agentsDir, a), { recursive: true, force: true });
|
|
1523
|
+
}
|
|
1524
|
+
if (legacy.commandsDir) {
|
|
1525
|
+
for (const c of commands) await fs.rm(path.join(legacy.commandsDir, c), { force: true });
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
export interface ActionResult {
|
|
1531
|
+
skills: number;
|
|
1532
|
+
agents: number;
|
|
1533
|
+
commands: number;
|
|
1534
|
+
/** Skipped install items and reasons (e.g. dsh has no file-based subagents). */
|
|
1535
|
+
skipped: string[];
|
|
1536
|
+
/** Aggregated conversion notes (notes of the same kind merged with a count). */
|
|
1537
|
+
notes: string[];
|
|
1538
|
+
/** Problems found by read-back validation after install. */
|
|
1539
|
+
issues: ValidationIssue[];
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
/* ------------------------------------------------------------------ */
|
|
1543
|
+
/* Platform body assembly: frontmatter from platforms/, body = unique + root doc */
|
|
1544
|
+
/* ------------------------------------------------------------------ */
|
|
1545
|
+
|
|
1546
|
+
export type DocKind = 'skill' | 'agent' | 'command';
|
|
1547
|
+
|
|
1548
|
+
interface PlatformPaths {
|
|
1549
|
+
headerMd: string;
|
|
1550
|
+
headerToml: string | null;
|
|
1551
|
+
unique: string;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
interface ComposedDoc {
|
|
1555
|
+
/** The platform-defined YAML frontmatter block (with --- separators); null = not defined by the platform. */
|
|
1556
|
+
header: string | null;
|
|
1557
|
+
/** The platform-defined Codex TOML header; null = not defined. */
|
|
1558
|
+
headerToml: string | null;
|
|
1559
|
+
/** Raw text of the platform's `.frontmatter.md`; used for compatibility with historical outputs that "wrote TOML in .md". */
|
|
1560
|
+
headerRaw: string | null;
|
|
1561
|
+
/** Raw unique patch text; null = no patch. */
|
|
1562
|
+
unique: string | null;
|
|
1563
|
+
/** Frontmatter block of the root document; null = the root document has no frontmatter. */
|
|
1564
|
+
rootHeader: string | null;
|
|
1565
|
+
/** Assembled body (unique + root document body), with leading/trailing whitespace normalized. */
|
|
1566
|
+
body: string;
|
|
1567
|
+
/** Fallback: root frontmatter + assembled body. */
|
|
1568
|
+
legacyRaw: string;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
function normalizeText(raw: string): string {
|
|
1572
|
+
const noBom = raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw;
|
|
1573
|
+
return noBom.replace(/\r\n/g, '\n');
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
/** Extract a `---\n...\n---` block (with separators, without the newline after the block); returns null if there is no block. */
|
|
1577
|
+
function extractYamlHeader(raw: string): string | null {
|
|
1578
|
+
const m = /^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(raw);
|
|
1579
|
+
return m ? m[0].replace(/\r\n/g, '\n').replace(/\n+$/, '') : null;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
function trimmedBody(raw: string): string {
|
|
1583
|
+
const { body, hasFrontmatter } = parseFrontmatter(raw);
|
|
1584
|
+
return (hasFrontmatter ? body : raw)
|
|
1585
|
+
.replace(/^(?:\r?\n)+/, '')
|
|
1586
|
+
.replace(/\s+$/, '');
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
/** Package-relative (POSIX) paths of a platform definition; resolved through the language resolver by composeDoc. */
|
|
1590
|
+
function platformPaths(platformName: string, kind: DocKind, name: string): PlatformPaths {
|
|
1591
|
+
const base = `platforms/${platformName}`;
|
|
1592
|
+
if (kind === 'skill') {
|
|
1593
|
+
const dir = `${base}/skills/${name}`;
|
|
1594
|
+
return {
|
|
1595
|
+
headerMd: `${dir}/SKILL.frontmatter.md`,
|
|
1596
|
+
headerToml: null,
|
|
1597
|
+
unique: `${dir}/SKILL.unique.md`,
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
const dir = `${base}/${kind === 'agent' ? 'agents' : 'commands'}`;
|
|
1601
|
+
const stem = name.replace(/\.md$/, '');
|
|
1602
|
+
return {
|
|
1603
|
+
headerMd: `${dir}/${stem}.frontmatter.md`,
|
|
1604
|
+
headerToml: kind === 'agent' ? `${dir}/${stem}.frontmatter.toml` : null,
|
|
1605
|
+
unique: `${dir}/${stem}.unique.md`,
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
async function readOptional(p: string): Promise<string | null> {
|
|
1610
|
+
try {
|
|
1611
|
+
return normalizeText(await fs.readFile(p, 'utf-8'));
|
|
1612
|
+
} catch {
|
|
1613
|
+
return null;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
function joinYamlBody(header: string, body: string): string {
|
|
1618
|
+
const h = header.replace(/\n+$/, '');
|
|
1619
|
+
return body ? `${h}\n\n${body}\n` : `${h}\n`;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* Read the platform's frontmatter / unique and assemble them with the root document body.
|
|
1624
|
+
* Frontmatter is no longer rewritten by code: use the platform definition if there is one, fall back to the old conversion only otherwise.
|
|
1625
|
+
*/
|
|
1626
|
+
async function composeDoc(
|
|
1627
|
+
platform: AgentPlatform,
|
|
1628
|
+
kind: DocKind,
|
|
1629
|
+
name: string,
|
|
1630
|
+
rootRaw: string,
|
|
1631
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1632
|
+
): Promise<ComposedDoc> {
|
|
1633
|
+
const rootText = normalizeText(rootRaw);
|
|
1634
|
+
const rootHeader = extractYamlHeader(rootText);
|
|
1635
|
+
const rootBody = trimmedBody(rootText);
|
|
1636
|
+
const paths = platformPaths(platform.name, kind, name);
|
|
1637
|
+
const [headerFile, tomlFile, uniqueFile] = await Promise.all([
|
|
1638
|
+
resolver.resolve(paths.headerMd).then(readOptional),
|
|
1639
|
+
paths.headerToml ? resolver.resolve(paths.headerToml).then(readOptional) : Promise.resolve(null),
|
|
1640
|
+
resolver.resolve(paths.unique).then(readOptional),
|
|
1641
|
+
]);
|
|
1642
|
+
const uniqueText = uniqueFile?.trimEnd() ?? null;
|
|
1643
|
+
const body = [uniqueText, rootBody].filter((s): s is string => !!s).join('\n\n');
|
|
1644
|
+
return {
|
|
1645
|
+
header: headerFile ? extractYamlHeader(headerFile) : null,
|
|
1646
|
+
headerToml: tomlFile ? tomlFile.replace(/\s+$/, '') : null,
|
|
1647
|
+
headerRaw: headerFile ? headerFile.replace(/\s+$/, '') : null,
|
|
1648
|
+
unique: uniqueText,
|
|
1649
|
+
rootHeader,
|
|
1650
|
+
body,
|
|
1651
|
+
legacyRaw: rootHeader ? joinYamlBody(rootHeader, body) : body ? `${body}\n` : '',
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
function sourceNotes(c: ComposedDoc): string[] {
|
|
1656
|
+
return [
|
|
1657
|
+
c.header || c.headerToml ? 'frontmatter: platforms definition' : 'frontmatter: root fallback',
|
|
1658
|
+
c.unique ? 'body: unique patch + root body' : 'body: root body',
|
|
1659
|
+
];
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
export interface ComposedTransform {
|
|
1663
|
+
content: string;
|
|
1664
|
+
rawCopy: boolean;
|
|
1665
|
+
notes: string[];
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/** Platform YAML header + assembled body; without a platform header the caller falls back to the old conversion. */
|
|
1669
|
+
function composeYamlDoc(c: ComposedDoc): ComposedTransform {
|
|
1670
|
+
return {
|
|
1671
|
+
content: joinYamlBody(c.header as string, c.body),
|
|
1672
|
+
rawCopy: false,
|
|
1673
|
+
notes: sourceNotes(c),
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/* ------------------------------------------------------------------ */
|
|
1678
|
+
/* Skill / Agent / Command content building */
|
|
1679
|
+
/* ------------------------------------------------------------------ */
|
|
1680
|
+
|
|
1681
|
+
export async function buildSkillContent(
|
|
1682
|
+
platform: AgentPlatform,
|
|
1683
|
+
skillName: string,
|
|
1684
|
+
rootRaw: string,
|
|
1685
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1686
|
+
): Promise<ComposedTransform> {
|
|
1687
|
+
if (platform.verbatim) return { content: rootRaw, rawCopy: true, notes: [] };
|
|
1688
|
+
const c = await composeDoc(platform, 'skill', skillName, rootRaw, resolver);
|
|
1689
|
+
if (c.header) return composeYamlDoc(c);
|
|
1690
|
+
const t = transformSkillMd(platform, c.legacyRaw);
|
|
1691
|
+
return {
|
|
1692
|
+
content: t.content,
|
|
1693
|
+
// The unique patch has been merged into the body (content != source file): even when the frontmatter needs no rewrite
|
|
1694
|
+
// it must not be marked rawCopy, or installTo would skip writing as "raw copy already correct" and the unique patch would be lost
|
|
1695
|
+
rawCopy: t.rawCopy && !c.unique,
|
|
1696
|
+
notes: [...sourceNotes(c), 'platform frontmatter absent: legacy transform applied', ...t.notes],
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
export interface AgentComposedTransform extends ComposedTransform {
|
|
1701
|
+
fileName: string;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
/** Codex: TOML header + body written into developer_instructions (left as is if already present). */
|
|
1705
|
+
function injectCodexInstructions(
|
|
1706
|
+
toml: string,
|
|
1707
|
+
body: string,
|
|
1708
|
+
): { content: string; notes: string[] } {
|
|
1709
|
+
const notes: string[] = [];
|
|
1710
|
+
let text = toml
|
|
1711
|
+
.split('\n')
|
|
1712
|
+
.filter(
|
|
1713
|
+
(line) =>
|
|
1714
|
+
!(/^\s*#/.test(line) && /developer_instructions\s*=/.test(line)),
|
|
1715
|
+
)
|
|
1716
|
+
.join('\n')
|
|
1717
|
+
.replace(/\s+$/, '');
|
|
1718
|
+
if (/^developer_instructions\s*=/m.test(text)) {
|
|
1719
|
+
notes.push('developer_instructions already defined in platform TOML: body not injected');
|
|
1720
|
+
return { content: text + '\n', notes };
|
|
1721
|
+
}
|
|
1722
|
+
const key = `developer_instructions = ${tomlMultiline(body)}`;
|
|
1723
|
+
const lines = text.split('\n');
|
|
1724
|
+
const firstTable = lines.findIndex((line) => /^\s*\[/.test(line));
|
|
1725
|
+
if (firstTable >= 0) {
|
|
1726
|
+
lines.splice(firstTable, 0, key, '');
|
|
1727
|
+
} else {
|
|
1728
|
+
lines.push('', key);
|
|
1729
|
+
}
|
|
1730
|
+
notes.push('developer_instructions injected from composed body');
|
|
1731
|
+
return { content: lines.join('\n').replace(/\n{3,}$/, '\n\n') + '\n', notes };
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
export async function buildAgentContent(
|
|
1735
|
+
platform: AgentPlatform,
|
|
1736
|
+
fileName: string,
|
|
1737
|
+
rootRaw: string,
|
|
1738
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1739
|
+
): Promise<AgentComposedTransform | null> {
|
|
1740
|
+
if (platform.agentFormat === 'none') return null;
|
|
1741
|
+
if (platform.verbatim) {
|
|
1742
|
+
return { fileName, content: rootRaw, rawCopy: true, notes: [] };
|
|
1743
|
+
}
|
|
1744
|
+
const c = await composeDoc(platform, 'agent', fileName, rootRaw, resolver);
|
|
1745
|
+
// codex: the authoritative TOML header is .frontmatter.toml; historical outputs wrote TOML in .frontmatter.md
|
|
1746
|
+
// (without --- fences); accepted here as a compatibility input, so the rule "platform preamble wins over base" does not regress.
|
|
1747
|
+
const tomlHeader =
|
|
1748
|
+
c.headerToml ?? (platform.agentFormat === 'codex-toml' && !c.header ? c.headerRaw : null);
|
|
1749
|
+
if (platform.agentFormat === 'codex-toml' && tomlHeader) {
|
|
1750
|
+
const out = injectCodexInstructions(tomlHeader, c.body);
|
|
1751
|
+
const notes = sourceNotes(c);
|
|
1752
|
+
if (!c.headerToml && !c.header) notes[0] = 'frontmatter: platforms definition (TOML in .frontmatter.md, legacy name)';
|
|
1753
|
+
return {
|
|
1754
|
+
fileName: fileName.replace(/\.md$/, '.toml'),
|
|
1755
|
+
content: out.content,
|
|
1756
|
+
rawCopy: false,
|
|
1757
|
+
notes: [...notes, ...out.notes],
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
if (c.header) {
|
|
1761
|
+
return { fileName, ...composeYamlDoc(c) };
|
|
1762
|
+
}
|
|
1763
|
+
const t = transformAgentMd(platform, fileName, c.legacyRaw);
|
|
1764
|
+
if (!t) return null;
|
|
1765
|
+
return {
|
|
1766
|
+
fileName: t.fileName,
|
|
1767
|
+
content: t.content,
|
|
1768
|
+
// Same as buildSkillContent: must not be marked rawCopy when the unique patch changed the content (keep the contract consistent)
|
|
1769
|
+
rawCopy: t.rawCopy && !c.unique,
|
|
1770
|
+
notes: [...sourceNotes(c), 'platform frontmatter absent: legacy transform applied', ...t.notes],
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
export async function buildCommandContent(
|
|
1775
|
+
platform: AgentPlatform,
|
|
1776
|
+
fileName: string,
|
|
1777
|
+
rootRaw: string,
|
|
1778
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1779
|
+
): Promise<ComposedTransform> {
|
|
1780
|
+
if (platform.verbatim) return { content: rootRaw, rawCopy: true, notes: [] };
|
|
1781
|
+
const c = await composeDoc(platform, 'command', fileName, rootRaw, resolver);
|
|
1782
|
+
if (c.header) return composeYamlDoc(c);
|
|
1783
|
+
const t = transformCommandMd(platform, c.legacyRaw);
|
|
1784
|
+
return {
|
|
1785
|
+
content: t.content,
|
|
1786
|
+
// Same as buildSkillContent: must not be marked rawCopy when the unique patch changed the content
|
|
1787
|
+
// (installTo's rawCopy branch copies the source file as is, which would drop the unique patch)
|
|
1788
|
+
rawCopy: t.rawCopy && !c.unique,
|
|
1789
|
+
notes: [...sourceNotes(c), ...t.notes],
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
export interface ComposedCommandSkill extends CommandSkillTransform {
|
|
1794
|
+
notes: string[];
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
export async function buildCommandSkill(
|
|
1798
|
+
platform: AgentPlatform,
|
|
1799
|
+
fileName: string,
|
|
1800
|
+
rootRaw: string,
|
|
1801
|
+
resolver: ContentResolver = DEFAULT_RESOLVER,
|
|
1802
|
+
): Promise<ComposedCommandSkill> {
|
|
1803
|
+
const c = await composeDoc(platform, 'command', fileName, rootRaw, resolver);
|
|
1804
|
+
const t = commandToSkillMd(platform, fileName, c.legacyRaw);
|
|
1805
|
+
return { ...t, notes: [...sourceNotes(c), ...t.notes] };
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
export interface InstallOptions {
|
|
1810
|
+
dryRun?: boolean;
|
|
1811
|
+
/** Language-aware content source; defaults to the Chinese originals. */
|
|
1812
|
+
resolver?: ContentResolver;
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* Install the bundled skills / agents / commands, adapted per platform, into the target agent directory
|
|
1817
|
+
* (same names overwrite; skills are deleted before copying to avoid old-version leftovers).
|
|
1818
|
+
*
|
|
1819
|
+
* File-level overrides (content under platforms/<agent>/... wins over the bundled root):
|
|
1820
|
+
* - skills: files under platforms/<agent>/skills/<name>/ are copied to the target, both overwriting same names and adding new ones
|
|
1821
|
+
* (SKILL.frontmatter.md / SKILL.unique.md are assembly inputs and SKILL.md is the assembly output; they take no part in overriding);
|
|
1822
|
+
* - agents / commands: the same-named source file platforms/<agent>/<kind>/<name> is used as the assembly source body.
|
|
1823
|
+
*/
|
|
1824
|
+
export async function installTo(
|
|
1825
|
+
target: AgentTarget,
|
|
1826
|
+
opts: InstallOptions = {},
|
|
1827
|
+
): Promise<ActionResult> {
|
|
1828
|
+
const platform = target.platform;
|
|
1829
|
+
const dryRun = opts.dryRun === true;
|
|
1830
|
+
const resolver = opts.resolver ?? DEFAULT_RESOLVER;
|
|
1831
|
+
const noteCounts = new Map<string, number>();
|
|
1832
|
+
const issues: ValidationIssue[] = [];
|
|
1833
|
+
const skipped: string[] = [];
|
|
1834
|
+
const addNote = (note: string): void => {
|
|
1835
|
+
noteCounts.set(note, (noteCounts.get(note) ?? 0) + 1);
|
|
1836
|
+
};
|
|
1837
|
+
|
|
1838
|
+
// The install source is skills|agents|commands at the package root / repo root (the root is the base). If they are missing,
|
|
1839
|
+
// the package excluded the install source when published -- fail right away instead of silently installing 0 skills.
|
|
1840
|
+
if (!existsSync(SKILLS_ROOT) || !existsSync(AGENTS_ROOT) || !existsSync(COMMANDS_ROOT)) {
|
|
1841
|
+
throw new Error(
|
|
1842
|
+
`incomplete plugin package: the install sources (skills/, agents/, commands/) are missing under ${PACKAGE_ROOT}. ` +
|
|
1843
|
+
'The publish config of this version excluded the root contents; upgrade the plugin or check files/exclusion in package.json.',
|
|
1844
|
+
);
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
// Clean up leftovers in old versions' wrong locations so they do not coexist with the current location
|
|
1848
|
+
if (!dryRun) await cleanLegacyDirs(platform, resolver);
|
|
1849
|
+
|
|
1850
|
+
let skills = 0;
|
|
1851
|
+
const bundledSkills = await listBundledSkills(resolver);
|
|
1852
|
+
if (platform.skillsDir && bundledSkills.length > 0 && !dryRun) {
|
|
1853
|
+
await fs.mkdir(platform.skillsDir, { recursive: true });
|
|
1854
|
+
}
|
|
1855
|
+
if (platform.skillsDir) {
|
|
1856
|
+
for (const name of bundledSkills) {
|
|
1857
|
+
const sourceRaw = await fs.readFile(await resolver.resolve(`skills/${name}/SKILL.md`), 'utf-8');
|
|
1858
|
+
const t = await buildSkillContent(platform, name, sourceRaw, resolver);
|
|
1859
|
+
const dest = path.join(platform.skillsDir, name);
|
|
1860
|
+
if (!dryRun) {
|
|
1861
|
+
await fs.rm(dest, { recursive: true, force: true });
|
|
1862
|
+
await copyResolvedDir(resolver, `skills/${name}`, dest);
|
|
1863
|
+
}
|
|
1864
|
+
// File-level override: files under platforms/<agent>/skills/<name>/ are laid over the target (same-named platforms version wins)
|
|
1865
|
+
const overlayCount = await copyOverlayFiles(
|
|
1866
|
+
resolver,
|
|
1867
|
+
`platforms/${platform.name}/skills/${name}`,
|
|
1868
|
+
dest,
|
|
1869
|
+
SKILL_OVERLAY_EXCLUDE,
|
|
1870
|
+
dryRun,
|
|
1871
|
+
);
|
|
1872
|
+
if (overlayCount > 0) {
|
|
1873
|
+
addNote(`file overlay: platforms/${platform.name}/skills/${name} (${overlayCount} files)`);
|
|
1874
|
+
}
|
|
1875
|
+
if (!dryRun && !t.rawCopy) await fs.writeFile(path.join(dest, 'SKILL.md'), t.content, 'utf-8');
|
|
1876
|
+
for (const n of t.notes) addNote(n);
|
|
1877
|
+
// Read back and validate the written content (in dry-run, validate the content to be written), proving the target platform can parse it
|
|
1878
|
+
const finalRaw = dryRun
|
|
1879
|
+
? t.rawCopy
|
|
1880
|
+
? sourceRaw
|
|
1881
|
+
: t.content
|
|
1882
|
+
: await fs.readFile(path.join(platform.skillsDir, name, 'SKILL.md'), 'utf-8');
|
|
1883
|
+
issues.push(...validateSkillMd(name, finalRaw, platform.skillDescriptionLimit));
|
|
1884
|
+
skills++;
|
|
1885
|
+
}
|
|
1886
|
+
} else if (bundledSkills.length > 0) {
|
|
1887
|
+
skipped.push(`${target.name}: skills skipped - platform has no skills directory`);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
let agents = 0;
|
|
1891
|
+
const bundledAgents = await listBundledAgents(resolver);
|
|
1892
|
+
if (platform.agentsDir && bundledAgents.length > 0 && !dryRun) {
|
|
1893
|
+
await fs.mkdir(platform.agentsDir, { recursive: true });
|
|
1894
|
+
}
|
|
1895
|
+
if (platform.agentsDir) {
|
|
1896
|
+
for (const name of bundledAgents) {
|
|
1897
|
+
const srcRel = `agents/${name}`;
|
|
1898
|
+
if ((await resolver.kind(srcRel)) === 'dir') {
|
|
1899
|
+
// Agent in subdirectory form (currently unused): copy as is + platforms file-level overrides
|
|
1900
|
+
const dest = path.join(platform.agentsDir, name);
|
|
1901
|
+
if (!dryRun) {
|
|
1902
|
+
await fs.rm(dest, { recursive: true, force: true });
|
|
1903
|
+
await copyResolvedDir(resolver, srcRel, dest);
|
|
1904
|
+
}
|
|
1905
|
+
const dirOverlay = await copyOverlayFiles(
|
|
1906
|
+
resolver,
|
|
1907
|
+
`platforms/${platform.name}/agents/${name}`,
|
|
1908
|
+
dest,
|
|
1909
|
+
new Set(),
|
|
1910
|
+
dryRun,
|
|
1911
|
+
);
|
|
1912
|
+
if (dirOverlay > 0) {
|
|
1913
|
+
addNote(`file overlay: platforms/${platform.name}/agents/${name} (${dirOverlay} files)`);
|
|
1914
|
+
}
|
|
1915
|
+
agents++;
|
|
1916
|
+
continue;
|
|
1917
|
+
}
|
|
1918
|
+
if (!name.endsWith('.md')) continue;
|
|
1919
|
+
// Same-named source file wins: when platforms/<agent>/agents/<name> exists it is the assembly source body
|
|
1920
|
+
const source = await platformSourcePath(platform.name, 'agents', name, resolver);
|
|
1921
|
+
if (source.overlay) addNote(`source overlay: platforms/${platform.name}/agents/${name}`);
|
|
1922
|
+
const raw = await fs.readFile(source.src, 'utf-8');
|
|
1923
|
+
const t = await buildAgentContent(platform, name, raw, resolver);
|
|
1924
|
+
if (!t) continue; // platforms of format 'none' never reach this branch (agentsDir is null)
|
|
1925
|
+
if (!dryRun) {
|
|
1926
|
+
await fs.writeFile(path.join(platform.agentsDir, t.fileName), t.content, 'utf-8');
|
|
1927
|
+
// Clean up the raw md copied directly by historical versions under codex targets
|
|
1928
|
+
if (t.fileName !== name) {
|
|
1929
|
+
await fs.rm(path.join(platform.agentsDir, name), { force: true });
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
for (const n of t.notes) addNote(n);
|
|
1933
|
+
const finalRaw = dryRun
|
|
1934
|
+
? t.content
|
|
1935
|
+
: await fs.readFile(path.join(platform.agentsDir, t.fileName), 'utf-8');
|
|
1936
|
+
issues.push(...validateAgentFile(platform, t.fileName, finalRaw));
|
|
1937
|
+
agents++;
|
|
1938
|
+
}
|
|
1939
|
+
} else if (bundledAgents.length > 0) {
|
|
1940
|
+
skipped.push(
|
|
1941
|
+
`${target.name}: agents skipped - ${platform.agentsSkipNote ?? 'platform has no file-based subagent'}`,
|
|
1942
|
+
);
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
let commands = 0;
|
|
1946
|
+
const bundledCommands = await listBundledCommands(resolver);
|
|
1947
|
+
if (platform.commandsAsSkills && platform.skillsDir) {
|
|
1948
|
+
// Commands are installed into the skills directory as skills (codex: custom prompts are deprecated;
|
|
1949
|
+
// dsh: no file-based commands); the "explicitly user-triggered only" semantics are kept with each platform's native mechanism
|
|
1950
|
+
if (bundledCommands.length > 0) {
|
|
1951
|
+
if (!dryRun) await fs.mkdir(platform.skillsDir, { recursive: true });
|
|
1952
|
+
addNote(`commands installed as skills into ${platform.skillsDir}`);
|
|
1953
|
+
}
|
|
1954
|
+
for (const name of bundledCommands) {
|
|
1955
|
+
const source = await platformSourcePath(platform.name, 'commands', name, resolver);
|
|
1956
|
+
if (source.overlay) addNote(`source overlay: platforms/${platform.name}/commands/${name}`);
|
|
1957
|
+
const sourceRaw = await fs.readFile(source.src, 'utf-8');
|
|
1958
|
+
const t = await buildCommandSkill(platform, name, sourceRaw, resolver);
|
|
1959
|
+
if (!dryRun) {
|
|
1960
|
+
const dest = path.join(platform.skillsDir, t.skillName);
|
|
1961
|
+
await fs.rm(dest, { recursive: true, force: true });
|
|
1962
|
+
await fs.mkdir(dest, { recursive: true });
|
|
1963
|
+
await fs.writeFile(path.join(dest, 'SKILL.md'), t.content, 'utf-8');
|
|
1964
|
+
if (t.openaiYaml !== null) {
|
|
1965
|
+
await fs.mkdir(path.join(dest, 'agents'), { recursive: true });
|
|
1966
|
+
await fs.writeFile(path.join(dest, 'agents', 'openai.yaml'), t.openaiYaml, 'utf-8');
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
for (const n of t.notes) addNote(n);
|
|
1970
|
+
const finalRaw = dryRun
|
|
1971
|
+
? t.content
|
|
1972
|
+
: await fs.readFile(path.join(platform.skillsDir, t.skillName, 'SKILL.md'), 'utf-8');
|
|
1973
|
+
issues.push(...validateSkillMd(t.skillName, finalRaw, platform.skillDescriptionLimit));
|
|
1974
|
+
commands++;
|
|
1975
|
+
}
|
|
1976
|
+
} else if (platform.commandsDir && bundledCommands.length > 0) {
|
|
1977
|
+
if (!dryRun) await fs.mkdir(platform.commandsDir, { recursive: true });
|
|
1978
|
+
for (const name of bundledCommands) {
|
|
1979
|
+
const source = await platformSourcePath(platform.name, 'commands', name, resolver);
|
|
1980
|
+
if (source.overlay) addNote(`source overlay: platforms/${platform.name}/commands/${name}`);
|
|
1981
|
+
const sourceRaw = await fs.readFile(source.src, 'utf-8');
|
|
1982
|
+
const t = await buildCommandContent(platform, name, sourceRaw, resolver);
|
|
1983
|
+
if (!dryRun) {
|
|
1984
|
+
const dest = path.join(platform.commandsDir, name);
|
|
1985
|
+
if (t.rawCopy) {
|
|
1986
|
+
await fs.copyFile(source.src, dest);
|
|
1987
|
+
} else {
|
|
1988
|
+
await fs.writeFile(dest, t.content, 'utf-8');
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
for (const n of t.notes) addNote(n);
|
|
1992
|
+
const finalRaw = dryRun
|
|
1993
|
+
? t.rawCopy
|
|
1994
|
+
? sourceRaw
|
|
1995
|
+
: t.content
|
|
1996
|
+
: await fs.readFile(path.join(platform.commandsDir, name), 'utf-8');
|
|
1997
|
+
issues.push(...validateCommandMd(platform, name, finalRaw));
|
|
1998
|
+
commands++;
|
|
1999
|
+
}
|
|
2000
|
+
} else if (bundledCommands.length > 0) {
|
|
2001
|
+
skipped.push(
|
|
2002
|
+
platform.commandsSkipNote
|
|
2003
|
+
? `${target.name}: commands skipped - ${platform.commandsSkipNote}`
|
|
2004
|
+
: `${target.name}: commands skipped - platform has no slash-command directory`,
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
const notes = [...noteCounts.entries()].map(([note, n]) => (n > 1 ? `${note} (${n} files)` : note));
|
|
2009
|
+
return { skills, agents, commands, skipped, notes, issues };
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
/** Delete skills / agents / commands with the same names as the bundled content from the target agent directory (including old-version leftover locations); other files are untouched. */
|
|
2013
|
+
export async function uninstallFrom(target: AgentTarget): Promise<ActionResult> {
|
|
2014
|
+
const platform = target.platform;
|
|
2015
|
+
const result: ActionResult = { skills: 0, agents: 0, commands: 0, skipped: [], notes: [], issues: [] };
|
|
2016
|
+
const skills = await listBundledSkills();
|
|
2017
|
+
const agents = await listBundledAgents();
|
|
2018
|
+
const commands = await listBundledCommands();
|
|
2019
|
+
|
|
2020
|
+
const skillDirs = [platform.skillsDir, ...platform.legacyDirs.map((l) => l.skillsDir)].filter(
|
|
2021
|
+
(d): d is string => !!d,
|
|
2022
|
+
);
|
|
2023
|
+
for (const name of skills) {
|
|
2024
|
+
let removed = false;
|
|
2025
|
+
for (const dir of skillDirs) {
|
|
2026
|
+
const p = path.join(dir, name);
|
|
2027
|
+
if (await exists(p)) {
|
|
2028
|
+
await fs.rm(p, { recursive: true, force: true });
|
|
2029
|
+
removed = true;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
if (removed) result.skills++;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
const agentDirs = [platform.agentsDir, ...platform.legacyDirs.map((l) => l.agentsDir)].filter(
|
|
2036
|
+
(d): d is string => !!d,
|
|
2037
|
+
);
|
|
2038
|
+
for (const name of agents) {
|
|
2039
|
+
let removed = false;
|
|
2040
|
+
for (const dir of agentDirs) {
|
|
2041
|
+
for (const candidate of agentFileCandidates(platform, name)) {
|
|
2042
|
+
const p = path.join(dir, candidate);
|
|
2043
|
+
if (await exists(p)) {
|
|
2044
|
+
await fs.rm(p, { recursive: true, force: true });
|
|
2045
|
+
removed = true;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
if (removed) result.agents++;
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
const commandDirs = [platform.commandsDir, ...platform.legacyDirs.map((l) => l.commandsDir)].filter(
|
|
2053
|
+
(d): d is string => !!d,
|
|
2054
|
+
);
|
|
2055
|
+
for (const name of commands) {
|
|
2056
|
+
let removed = false;
|
|
2057
|
+
for (const dir of commandDirs) {
|
|
2058
|
+
const p = path.join(dir, name);
|
|
2059
|
+
if (await exists(p)) {
|
|
2060
|
+
await fs.rm(p, { force: true });
|
|
2061
|
+
removed = true;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
// commandsAsSkills platforms: commands exist as <skillsDir>/<name>/ skill directories
|
|
2065
|
+
if (platform.commandsAsSkills && platform.skillsDir) {
|
|
2066
|
+
const p = path.join(platform.skillsDir, name.replace(/\.md$/, ''));
|
|
2067
|
+
if (await exists(p)) {
|
|
2068
|
+
await fs.rm(p, { recursive: true, force: true });
|
|
2069
|
+
removed = true;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
if (removed) result.commands++;
|
|
2073
|
+
}
|
|
2074
|
+
return result;
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
/** Whether the target agent directory already has any skill / agent / command of this plugin (including old-version leftover locations). */
|
|
2078
|
+
export async function isInstalledIn(target: AgentTarget): Promise<boolean> {
|
|
2079
|
+
const platform = target.platform;
|
|
2080
|
+
const skills = await listBundledSkills();
|
|
2081
|
+
const agents = await listBundledAgents();
|
|
2082
|
+
const commands = await listBundledCommands();
|
|
2083
|
+
for (const name of skills) {
|
|
2084
|
+
for (const dir of [platform.skillsDir, ...platform.legacyDirs.map((l) => l.skillsDir)]) {
|
|
2085
|
+
if (dir && (await exists(path.join(dir, name)))) return true;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
for (const name of agents) {
|
|
2089
|
+
for (const dir of [platform.agentsDir, ...platform.legacyDirs.map((l) => l.agentsDir)]) {
|
|
2090
|
+
if (!dir) continue;
|
|
2091
|
+
for (const candidate of agentFileCandidates(platform, name)) {
|
|
2092
|
+
if (await exists(path.join(dir, candidate))) return true;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
for (const name of commands) {
|
|
2097
|
+
for (const dir of [platform.commandsDir, ...platform.legacyDirs.map((l) => l.commandsDir)]) {
|
|
2098
|
+
if (dir && (await exists(path.join(dir, name)))) return true;
|
|
2099
|
+
}
|
|
2100
|
+
if (
|
|
2101
|
+
platform.commandsAsSkills &&
|
|
2102
|
+
platform.skillsDir &&
|
|
2103
|
+
(await exists(path.join(platform.skillsDir, name.replace(/\.md$/, ''))))
|
|
2104
|
+
) {
|
|
2105
|
+
return true;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
/* ------------------------------------------------------------------ */
|
|
2112
|
+
/* Argument parsing */
|
|
2113
|
+
/* ------------------------------------------------------------------ */
|
|
2114
|
+
|
|
2115
|
+
export interface CliOptions {
|
|
2116
|
+
targets: AgentTarget[];
|
|
2117
|
+
dryRun: boolean;
|
|
2118
|
+
/** --verbose or HOMETRANS_PLUGIN_VERBOSE=1: print per-target details (silent by default). */
|
|
2119
|
+
verbose: boolean;
|
|
2120
|
+
/** Project root resolved from --project (absolute path). */
|
|
2121
|
+
projectRoot?: string;
|
|
2122
|
+
/** --lang: install language; when absent, resolveInstallLanguage picks it from the environment / time zone. */
|
|
2123
|
+
lang?: InstallLanguage;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
/**
|
|
2127
|
+
* Old plugin.jsonc files / existing scripts use agent names with spaces; after the rename in this version they are still accepted as aliases
|
|
2128
|
+
* (mapped to the canonical names in the current platform table), so DevEco CLI or user scripts passing old names
|
|
2129
|
+
* do not error out. Unknown names are only lowercased and returned as is, for the caller to validate and report.
|
|
2130
|
+
*/
|
|
2131
|
+
const AGENT_NAME_ALIASES: Record<string, string> = {
|
|
2132
|
+
'claude code': 'claude-code',
|
|
2133
|
+
'deveco code': 'deveco',
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
export function canonicalAgentName(name: string): string {
|
|
2137
|
+
const n = name.trim().toLowerCase();
|
|
2138
|
+
return AGENT_NAME_ALIASES[n] ?? n;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* Verbose output switch (environment variable form). install / uninstall / update are silent by default:
|
|
2143
|
+
* no console output on success; only validation ERRORs remain visible. The deveco-cli plugin contract
|
|
2144
|
+
* path (index.ts hooks) is called by the host and cannot pass flags, so the environment variable is the only entry;
|
|
2145
|
+
* the standalone mode also accepts the --verbose flag besides this variable (parseArgs ORs the two).
|
|
2146
|
+
*/
|
|
2147
|
+
export function isVerboseEnv(): boolean {
|
|
2148
|
+
const v = process.env.HOMETRANS_PLUGIN_VERBOSE;
|
|
2149
|
+
return v !== undefined && /^(1|true|yes)$/i.test(v.trim());
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
export function parseArgs(
|
|
2153
|
+
argv: string[],
|
|
2154
|
+
manifest: PluginManifest,
|
|
2155
|
+
platforms: Map<string, AgentPlatform>,
|
|
2156
|
+
): CliOptions {
|
|
2157
|
+
const agentNames: string[] = [];
|
|
2158
|
+
let dir: string | undefined;
|
|
2159
|
+
let project: string | undefined;
|
|
2160
|
+
let dryRun = false;
|
|
2161
|
+
let verboseFlag = false;
|
|
2162
|
+
let lang: InstallLanguage | undefined;
|
|
2163
|
+
|
|
2164
|
+
for (let i = 0; i < argv.length; i++) {
|
|
2165
|
+
const arg = argv[i];
|
|
2166
|
+
let key = arg;
|
|
2167
|
+
let value: string | undefined;
|
|
2168
|
+
const eq = arg.indexOf('=');
|
|
2169
|
+
if (arg.startsWith('--') && eq > 0) {
|
|
2170
|
+
key = arg.slice(0, eq);
|
|
2171
|
+
value = arg.slice(eq + 1);
|
|
2172
|
+
}
|
|
2173
|
+
if (key === '--dry-run' && value === undefined) {
|
|
2174
|
+
dryRun = true;
|
|
2175
|
+
continue;
|
|
2176
|
+
}
|
|
2177
|
+
if (key === '--verbose' && value === undefined) {
|
|
2178
|
+
verboseFlag = true;
|
|
2179
|
+
continue;
|
|
2180
|
+
}
|
|
2181
|
+
if (key !== '--agent' && key !== '--dir' && key !== '--project' && key !== '--lang') {
|
|
2182
|
+
throw new PluginError(`unknown option ${arg}`);
|
|
2183
|
+
}
|
|
2184
|
+
if (value === undefined) {
|
|
2185
|
+
value = argv[++i];
|
|
2186
|
+
if (value === undefined || value.startsWith('--')) {
|
|
2187
|
+
throw new PluginError(`option ${key} requires a value`);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
if (key === '--agent') {
|
|
2191
|
+
for (const piece of value.split(',').map((s) => s.trim()).filter(Boolean)) {
|
|
2192
|
+
const canonical = canonicalAgentName(piece);
|
|
2193
|
+
if (canonical !== piece.toLowerCase()) {
|
|
2194
|
+
console.error(`note: agent name "${piece}" is deprecated, use "${canonical}"`);
|
|
2195
|
+
}
|
|
2196
|
+
agentNames.push(canonical);
|
|
2197
|
+
}
|
|
2198
|
+
} else if (key === '--lang') {
|
|
2199
|
+
const parsed = parseInstallLanguage(value);
|
|
2200
|
+
if (!parsed) throw new PluginError(`option --lang expects zh or en, got ${value}`);
|
|
2201
|
+
lang = parsed;
|
|
2202
|
+
} else if (key === '--dir') {
|
|
2203
|
+
dir = value;
|
|
2204
|
+
} else {
|
|
2205
|
+
project = value;
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
const allowed = manifest.agent.map((a) => a.toLowerCase());
|
|
2210
|
+
for (const name of agentNames) {
|
|
2211
|
+
if (!allowed.includes(name.toLowerCase())) {
|
|
2212
|
+
throw new PluginError(`agent name ${name} invalid`);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
if (dir !== undefined && project !== undefined) {
|
|
2216
|
+
throw new PluginError('--dir and --project cannot be used together');
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
let dirTarget: AgentTarget | undefined;
|
|
2220
|
+
if (dir !== undefined) {
|
|
2221
|
+
const resolved = path.resolve(dir.replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
2222
|
+
let isDir = false;
|
|
2223
|
+
try {
|
|
2224
|
+
isDir = statSync(resolved).isDirectory();
|
|
2225
|
+
} catch {
|
|
2226
|
+
isDir = false;
|
|
2227
|
+
}
|
|
2228
|
+
if (!isDir) throw new PluginError('dir path invalid');
|
|
2229
|
+
// --dir does not recognize platforms: skills / agents are copied as is, without any conversion
|
|
2230
|
+
dirTarget = {
|
|
2231
|
+
name: resolved,
|
|
2232
|
+
explicit: true,
|
|
2233
|
+
platform: {
|
|
2234
|
+
name: `dir(${resolved})`,
|
|
2235
|
+
markerDir: resolved,
|
|
2236
|
+
skillsDir: path.join(resolved, 'skills'),
|
|
2237
|
+
agentsDir: path.join(resolved, 'agents'),
|
|
2238
|
+
commandsDir: path.join(resolved, 'commands'),
|
|
2239
|
+
agentFormat: 'passthrough',
|
|
2240
|
+
skillKeepAllowedTools: true,
|
|
2241
|
+
skillKeepArgumentHint: true,
|
|
2242
|
+
skillSlashMetadata: false,
|
|
2243
|
+
commandKeepKeys: [],
|
|
2244
|
+
commandsAsSkills: false,
|
|
2245
|
+
verbatim: true,
|
|
2246
|
+
legacyDirs: [],
|
|
2247
|
+
},
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// The project root must be an existing directory (the in-project .<agent> is created by the install)
|
|
2252
|
+
let projectRoot: string | undefined;
|
|
2253
|
+
if (project !== undefined) {
|
|
2254
|
+
const resolved = path.resolve(project.replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
2255
|
+
let isDir = false;
|
|
2256
|
+
try {
|
|
2257
|
+
isDir = statSync(resolved).isDirectory();
|
|
2258
|
+
} catch {
|
|
2259
|
+
isDir = false;
|
|
2260
|
+
}
|
|
2261
|
+
if (!isDir) throw new PluginError('project path invalid');
|
|
2262
|
+
projectRoot = resolved;
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
const explicitAgent = agentNames.length > 0;
|
|
2266
|
+
// With only --dir, handle only that path; with neither (or only --project), handle all agents
|
|
2267
|
+
// (agentNames have already been normalized to lowercase canonical names by canonicalAgentName)
|
|
2268
|
+
const selected = explicitAgent
|
|
2269
|
+
? agentNames
|
|
2270
|
+
: dir === undefined
|
|
2271
|
+
? allowed
|
|
2272
|
+
: [];
|
|
2273
|
+
const targets: AgentTarget[] = [];
|
|
2274
|
+
for (const name of new Set(selected)) {
|
|
2275
|
+
const platform = platforms.get(name);
|
|
2276
|
+
if (!platform) throw new PluginError(`agent name ${name} invalid`);
|
|
2277
|
+
targets.push({
|
|
2278
|
+
name,
|
|
2279
|
+
explicit: explicitAgent,
|
|
2280
|
+
platform: projectRoot ? toProjectPlatform(platform, projectRoot) : platform,
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
// When --dir equals some --agent's directory, handle it only once
|
|
2284
|
+
if (dirTarget && !targets.some((t) => t.platform.markerDir === dirTarget!.platform.markerDir)) {
|
|
2285
|
+
targets.push(dirTarget);
|
|
2286
|
+
}
|
|
2287
|
+
return { targets, dryRun, verbose: verboseFlag || isVerboseEnv(), projectRoot, lang };
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
/* ------------------------------------------------------------------ */
|
|
2291
|
+
/* Entry wrapper */
|
|
2292
|
+
/* ------------------------------------------------------------------ */
|
|
2293
|
+
|
|
2294
|
+
/** Parse arguments and run the command; argument errors are printed to stderr and exit with code 1. */
|
|
2295
|
+
export async function runCommand(
|
|
2296
|
+
run: (opts: CliOptions, manifest: PluginManifest) => Promise<void>,
|
|
2297
|
+
): Promise<void> {
|
|
2298
|
+
try {
|
|
2299
|
+
const manifest = await loadManifest();
|
|
2300
|
+
const platforms = resolvePlatforms();
|
|
2301
|
+
const opts = parseArgs(process.argv.slice(2), manifest, platforms);
|
|
2302
|
+
await run(opts, manifest);
|
|
2303
|
+
} catch (err) {
|
|
2304
|
+
console.error(err instanceof PluginError ? err.message : (err as Error).stack ?? String(err));
|
|
2305
|
+
process.exitCode = 1;
|
|
2306
|
+
}
|
|
2307
|
+
}
|