@thinkingai/ae-cli 6.1.29 → 6.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/README.md +11 -5
  2. package/README.zh.md +11 -5
  3. package/bin/ai-monitor.js +2 -0
  4. package/dist/ai-monitor-MKMHSSNI.js +32 -0
  5. package/dist/ai-monitor.js +135 -0
  6. package/dist/{auth-OBQ5KVQM.js → auth-CZHHPZOQ.js} +12 -11
  7. package/dist/{automation-NAR5DDGL.js → automation-FLCPFMN4.js} +5 -5
  8. package/dist/{capability-LFSVNI5B.js → capability-64KVJFIA.js} +28 -32
  9. package/dist/{chunk-IN7KKL6K.js → chunk-2F64AZYH.js} +1 -1
  10. package/dist/{chunk-QZLRHGVH.js → chunk-3ULDJJTZ.js} +1 -1
  11. package/dist/{chunk-JNVVJ273.js → chunk-4PSTYEG5.js} +5 -10
  12. package/dist/{chunk-3SDHJOCR.js → chunk-4XKTRCRK.js} +16 -16
  13. package/dist/{chunk-RJHGDWSC.js → chunk-5M5LBRR3.js} +2 -2
  14. package/dist/chunk-6M7ZEDT2.js +182 -0
  15. package/dist/{chunk-KPQY44JQ.js → chunk-AWW2T2WL.js} +3 -0
  16. package/dist/chunk-BNBCMCYN.js +563 -0
  17. package/dist/chunk-CF6JTT2U.js +64 -0
  18. package/dist/{chunk-2UW3Y463.js → chunk-DWBYNGSR.js} +565 -315
  19. package/dist/{chunk-N6XBLRB7.js → chunk-F2VFZUGG.js} +2 -2
  20. package/dist/{chunk-CVCTFLSO.js → chunk-FCAA7I2D.js} +3 -3
  21. package/dist/{chunk-H3K5UGYC.js → chunk-HTZ2MLYA.js} +48 -22
  22. package/dist/{chunk-QZUVLFNR.js → chunk-HVMCPKOZ.js} +1 -1
  23. package/dist/chunk-IDDWEZ7F.js +1285 -0
  24. package/dist/{chunk-7JAVT5TK.js → chunk-KTJXD27G.js} +2 -2
  25. package/dist/{chunk-6HAUVWOQ.js → chunk-NLEXY2TM.js} +48 -13
  26. package/dist/{chunk-YVG6QD3V.js → chunk-P7QDCWJ6.js} +98 -7
  27. package/dist/{chunk-PWXDWMCW.js → chunk-T7WF4HYW.js} +84 -32
  28. package/dist/{chunk-VCZE3IWO.js → chunk-TMQGS4TO.js} +15 -10
  29. package/dist/{compat-check-CII6B74E.js → compat-check-ZJNCMNQV.js} +3 -3
  30. package/dist/{config-YZ6O2UQ2.js → config-FSH2NMNZ.js} +26 -13
  31. package/dist/{context-F6FCGTF3.js → context-YAQG6YQC.js} +3 -3
  32. package/dist/{data-integration-6UAZO4GG.js → data-integration-QE37EQ3A.js} +1 -1
  33. package/dist/{evaluation-4LO2O4AF.js → evaluation-2JSF4V47.js} +13 -158
  34. package/dist/index.js +84 -586
  35. package/dist/{memory-HHPX3NF2.js → memory-VEZZVAAP.js} +5 -5
  36. package/dist/{metadata-TIFY24LW.js → metadata-3IWHX3V4.js} +8 -8
  37. package/dist/{model-7UHGWYVR.js → model-T7H7Q6BG.js} +3 -3
  38. package/dist/{personal-semantic-preference-WKJEGPTM.js → personal-semantic-preference-YITU23SA.js} +7 -7
  39. package/dist/{project-semantic-EIQVZNHW.js → project-semantic-MHEXJF3C.js} +16 -14
  40. package/dist/{sync-RV3OPCTI.js → sync-AQHVCSPI.js} +5 -5
  41. package/dist/{te-agent-5ENVZJUH.js → te-agent-RXI7WOH4.js} +6 -6
  42. package/dist/{te-analysis-USIK6ZZG.js → te-analysis-CZY74HVF.js} +381 -192
  43. package/dist/{te-community-WE2UU4XV.js → te-community-DKCYUBCM.js} +7 -7
  44. package/dist/{te-dataops-XNMO7MBF.js → te-dataops-QEH6VE56.js} +5 -5
  45. package/dist/{te-engage-6C3HCFQR.js → te-engage-WK7WKDKF.js} +7 -7
  46. package/dist/{te-experiment-LVTRI3QK.js → te-experiment-LH3RPIOE.js} +275 -30
  47. package/dist/{te-kb-TUPGMVBY.js → te-kb-UPORIOVN.js} +17 -8
  48. package/dist/{te-system-YM657FKO.js → te-system-AL4B4XZL.js} +3 -3
  49. package/dist/{te-team-G4VEJJNL.js → te-team-LLVTO2G4.js} +6 -6
  50. package/dist/{things-22KQWC23.js → things-XLMLBYQR.js} +6 -6
  51. package/dist/{update-XX4ILU7X.js → update-7J5UQHSK.js} +4 -4
  52. package/dist/{workspace-LYDAP647.js → workspace-FF2HXJGR.js} +5 -5
  53. package/package.json +9 -7
  54. package/skills/ae-ai-monitor/SKILL.md +179 -0
  55. package/skills/ae-ai-monitor/references/read-commands.md +866 -0
  56. package/skills/ae-analysis/SKILL.md +10 -4
  57. package/skills/ae-analysis/references/adhoc_export.md +3 -1
  58. package/skills/ae-analysis/references/ai_models/path.md +5 -6
  59. package/skills/ae-analysis/references/ai_models.md +1 -0
  60. package/skills/ae-analysis/references/analysis_gateway_assets.md +2 -0
  61. package/skills/ae-analysis/references/asset_search.md +1 -1
  62. package/skills/ae-analysis/references/bad_case_begin.md +12 -0
  63. package/skills/ae-analysis/references/bad_case_get.md +12 -0
  64. package/skills/ae-analysis/references/bad_case_history.md +12 -0
  65. package/skills/ae-analysis/references/bad_case_list.md +12 -0
  66. package/skills/ae-analysis/references/bad_case_review.md +51 -0
  67. package/skills/ae-analysis/references/bad_case_run.md +12 -0
  68. package/skills/ae-analysis/references/bad_case_submit.md +12 -0
  69. package/skills/ae-analysis/references/bad_case_submit_to_page.md +12 -0
  70. package/skills/ae-analysis/references/bad_case_sync_evaluation.md +11 -0
  71. package/skills/ae-analysis/references/bi_panel_list.md +1 -1
  72. package/skills/ae-analysis/references/bi_panel_share.md +3 -1
  73. package/skills/ae-analysis/references/catalog_list.md +2 -0
  74. package/skills/ae-analysis/references/command_index.md +38 -29
  75. package/skills/ae-analysis/references/dashboard_daily_report_update.md +2 -0
  76. package/skills/ae-analysis/references/dashboard_handover.md +3 -1
  77. package/skills/ae-analysis/references/dashboard_list.md +3 -3
  78. package/skills/ae-analysis/references/dashboard_report_data_export.md +1 -1
  79. package/skills/ae-analysis/references/dashboard_share.md +3 -1
  80. package/skills/ae-analysis/references/dashboard_update.md +3 -2
  81. package/skills/ae-analysis/references/filter_value_list.md +2 -0
  82. package/skills/ae-analysis/references/folder_share.md +8 -2
  83. package/skills/ae-analysis/references/governance_recommendation_run_update.md +3 -1
  84. package/skills/ae-analysis/references/project_data_power_upsert.md +3 -1
  85. package/skills/ae-analysis/references/project_mark_time_create.md +2 -0
  86. package/skills/ae-analysis/references/project_mark_time_update.md +2 -0
  87. package/skills/ae-analysis/references/project_member_add.md +3 -1
  88. package/skills/ae-analysis/references/project_member_batch_update.md +3 -1
  89. package/skills/ae-analysis/references/project_member_handover_run.md +3 -1
  90. package/skills/ae-analysis/references/project_member_update.md +3 -1
  91. package/skills/ae-analysis/references/project_owner_update.md +3 -1
  92. package/skills/ae-analysis/references/project_role_upsert.md +5 -3
  93. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +16 -1
  94. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +14 -1
  95. package/skills/ae-analysis/references/project_space_share.md +8 -2
  96. package/skills/ae-analysis/references/property_get.md +2 -0
  97. package/skills/ae-analysis/references/public_link_list.md +3 -1
  98. package/skills/ae-analysis/references/query_cancel.md +4 -1
  99. package/skills/ae-analysis/references/report_data_run.md +1 -1
  100. package/skills/ae-analysis/references/report_list.md +3 -3
  101. package/skills/ae-analysis/references/scenario_append.md +2 -2
  102. package/skills/ae-analysis/references/scenario_collect.md +15 -4
  103. package/skills/ae-analysis/references/scenario_list.md +2 -1
  104. package/skills/ae-analysis/references/system_oauth2_update.md +3 -1
  105. package/skills/ae-analysis/references/system_third_party_login_upsert.md +4 -2
  106. package/skills/ae-analysis/references/user_tag_create.md +4 -1
  107. package/skills/ae-analysis/references/user_tag_get.md +2 -0
  108. package/skills/ae-analysis/references/user_tag_models.md +8 -2
  109. package/skills/ae-analysis/references/user_tag_update.md +5 -2
  110. package/skills/ae-analysis/references/virtual_property_create.md +12 -1
  111. package/skills/ae-analysis/references/virtual_property_sql_rule_update.md +10 -0
  112. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +55 -13
  113. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +2 -2
  114. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-rules.md +2 -2
  115. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +7 -1
  116. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/wait-compile-run.mjs +79 -0
  117. package/skills/ae-automation/SKILL.md +4 -2
  118. package/skills/ae-capability/SKILL.md +9 -5
  119. package/skills/ae-community/SKILL.md +1 -0
  120. package/skills/ae-dataops/SKILL.md +1 -0
  121. package/skills/ae-engage/SKILL.md +1 -0
  122. package/skills/ae-evaluation/SKILL.md +17 -2
  123. package/skills/ae-experiment/SKILL.md +38 -11
  124. package/skills/ae-experiment/references/experiment_approval.md +171 -0
  125. package/skills/ae-experiment/references/manage_experiment.md +11 -2
  126. package/skills/ae-experiment/references/save_experiment.md +28 -8
  127. package/skills/ae-experiment/references/save_submit_experiment.md +18 -3
  128. package/skills/ae-experiment/references/save_submit_external_experiment.md +57 -3
  129. package/skills/ae-generate-tracking-plan/SKILL.md +5 -0
  130. package/skills/ae-kb/SKILL.md +9 -5
  131. package/skills/ae-kb/references/analysis-workflow.md +11 -2
  132. package/skills/ae-kb/references/query-workflow.md +9 -6
  133. package/skills/ae-kb/references/versions.md +1 -1
  134. package/skills/ae-kb-discovery/SKILL.md +15 -6
  135. package/skills/ae-metadata/SKILL.md +1 -0
  136. package/skills/ae-migrate-tracking-code/SKILL.md +2 -1
  137. package/skills/ae-team/SKILL.md +1 -1
  138. package/skills/ae-tracking-matrix/SKILL.md +170 -0
  139. package/skills/ae-tracking-matrix/assets//345/237/213/347/202/271/346/250/241/347/211/210.xlsx +0 -0
  140. package/skills/ae-tracking-matrix/i18n.yaml +12 -0
  141. package/skills/ae-tracking-matrix/references/ae-capabilities.md +93 -0
  142. package/skills/ae-tracking-matrix/references/business-semantic-checks.md +30 -0
  143. package/skills/ae-tracking-matrix/references/categories/acquaintance_social_tracking_plan_template.md +256 -0
  144. package/skills/ae-tracking-matrix/references/categories/blockchain_game_tracking_plan_template.md +213 -0
  145. package/skills/ae-tracking-matrix/references/categories/card_game_tracking_plan_template.md +407 -0
  146. package/skills/ae-tracking-matrix/references/categories/casual_game_tracking_plan_template.md +218 -0
  147. package/skills/ae-tracking-matrix/references/categories/casual_music.md +112 -0
  148. package/skills/ae-tracking-matrix/references/categories/chess_cards_tracking_plan_template.md +301 -0
  149. package/skills/ae-tracking-matrix/references/categories/ecommerce_tracking_plan_template.md +356 -0
  150. package/skills/ae-tracking-matrix/references/categories/fishing.md +775 -0
  151. package/skills/ae-tracking-matrix/references/categories/game_basic_module_tracking_plan.md +89 -0
  152. package/skills/ae-tracking-matrix/references/categories/idle_card.md +27 -0
  153. package/skills/ae-tracking-matrix/references/categories/idle_game_tracking_plan_template.md +415 -0
  154. package/skills/ae-tracking-matrix/references/categories/interactive_video.md +133 -0
  155. package/skills/ae-tracking-matrix/references/categories/merge.md +639 -0
  156. package/skills/ae-tracking-matrix/references/categories/mmo_mobile_tracking_plan_template.md +406 -0
  157. package/skills/ae-tracking-matrix/references/categories/mmo_web.md +230 -0
  158. package/skills/ae-tracking-matrix/references/categories/music.md +137 -0
  159. package/skills/ae-tracking-matrix/references/categories/online_education_tracking_plan_template.md +414 -0
  160. package/skills/ae-tracking-matrix/references/categories/qipai_mj.md +199 -0
  161. package/skills/ae-tracking-matrix/references/categories/reading_tracking_plan_template.md +158 -0
  162. package/skills/ae-tracking-matrix/references/categories/roguelike_tracking_plan_template.md +546 -0
  163. package/skills/ae-tracking-matrix/references/categories/rpg.md +195 -0
  164. package/skills/ae-tracking-matrix/references/categories/short_drama_tracking_plan_template.md +115 -0
  165. package/skills/ae-tracking-matrix/references/categories/simulation_business_tracking_plan_template.md +151 -0
  166. package/skills/ae-tracking-matrix/references/categories/slg_tracking_plan_template.md +260 -0
  167. package/skills/ae-tracking-matrix/references/categories/slots_tracking_plan_template.md +232 -0
  168. package/skills/ae-tracking-matrix/references/categories/stranger_social_tracking_plan_template.md +359 -0
  169. package/skills/ae-tracking-matrix/references/categories/tower_defense.md +365 -0
  170. package/skills/ae-tracking-matrix/references/categories/video_editor_tracking_plan_template.md +211 -0
  171. package/skills/ae-tracking-matrix/references/categories/wechat_minigame.md +132 -0
  172. package/skills/ae-tracking-matrix/references/category-registry.md +77 -0
  173. package/skills/ae-tracking-matrix/references/data-verification/diagnosis_kb.md +230 -0
  174. package/skills/ae-tracking-matrix/references/data-verification/sql_checks.md +406 -0
  175. package/skills/ae-tracking-matrix/references/data-verification/tracking_plan_comparison.md +128 -0
  176. package/skills/ae-tracking-matrix/references/eval-cases.md +74 -0
  177. package/skills/ae-tracking-matrix/references/naming-dict.md +238 -0
  178. package/skills/ae-tracking-matrix/references/optimization-checklist.md +85 -0
  179. package/skills/ae-tracking-matrix/references/plan-generation/export-schema.md +142 -0
  180. package/skills/ae-tracking-matrix/references/plan-generation/module-baseline.md +47 -0
  181. package/skills/ae-tracking-matrix/references/plan-generation/reference.md +794 -0
  182. package/skills/ae-tracking-matrix/references/plan-generation/template-catalog.md +94 -0
  183. package/skills/ae-tracking-matrix/references/scene-routing.md +80 -0
  184. package/skills/ae-tracking-matrix/references/sdk/client-sdk/android.md +3787 -0
  185. package/skills/ae-tracking-matrix/references/sdk/client-sdk/c.md +827 -0
  186. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-lua.md +655 -0
  187. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-x.md +953 -0
  188. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocoscreator.md +1128 -0
  189. package/skills/ae-tracking-matrix/references/sdk/client-sdk/corona.md +714 -0
  190. package/skills/ae-tracking-matrix/references/sdk/client-sdk/egret.md +1268 -0
  191. package/skills/ae-tracking-matrix/references/sdk/client-sdk/flutter.md +776 -0
  192. package/skills/ae-tracking-matrix/references/sdk/client-sdk/h5-and-app-sdk-integration.md +182 -0
  193. package/skills/ae-tracking-matrix/references/sdk/client-sdk/ios.md +2755 -0
  194. package/skills/ae-tracking-matrix/references/sdk/client-sdk/javascript.md +1182 -0
  195. package/skills/ae-tracking-matrix/references/sdk/client-sdk/layaair.md +1300 -0
  196. package/skills/ae-tracking-matrix/references/sdk/client-sdk/macos.md +1369 -0
  197. package/skills/ae-tracking-matrix/references/sdk/client-sdk/mini-program-mini-game.md +1692 -0
  198. package/skills/ae-tracking-matrix/references/sdk/client-sdk/openharmony.md +902 -0
  199. package/skills/ae-tracking-matrix/references/sdk/client-sdk/react-native.md +763 -0
  200. package/skills/ae-tracking-matrix/references/sdk/client-sdk/uni-app.md +1107 -0
  201. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unity.md +1532 -0
  202. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unreal.md +845 -0
  203. package/skills/ae-tracking-matrix/references/sdk/faq/android_sdk_faq.md +228 -0
  204. package/skills/ae-tracking-matrix/references/sdk/faq/ios_sdk_faq.md +149 -0
  205. package/skills/ae-tracking-matrix/references/sdk/faq/java_sdk_faq.md +407 -0
  206. package/skills/ae-tracking-matrix/references/sdk/faq/javascript_sdk_faq.md +163 -0
  207. package/skills/ae-tracking-matrix/references/sdk/faq/minigame_sdk_faq.md +149 -0
  208. package/skills/ae-tracking-matrix/references/sdk/faq/miniprogram_sdk_faq.md +153 -0
  209. package/skills/ae-tracking-matrix/references/sdk/faq/python_sdk_faq.md +232 -0
  210. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_log_guide.md +314 -0
  211. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_usage_notes.md +117 -0
  212. package/skills/ae-tracking-matrix/references/sdk/faq/unity_sdk_faq.md +148 -0
  213. package/skills/ae-tracking-matrix/references/sdk/integration-tools/filebeat-logstash-guide.md +645 -0
  214. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_guide.md +307 -0
  215. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_parser_plugin.md +347 -0
  216. package/skills/ae-tracking-matrix/references/sdk/integration-tools/restful_api_notes.md +72 -0
  217. package/skills/ae-tracking-matrix/references/sdk/integration-tools/ta-datax-writer-guide.md +264 -0
  218. package/skills/ae-tracking-matrix/references/sdk/server-sdk/c.md +566 -0
  219. package/skills/ae-tracking-matrix/references/sdk/server-sdk/erlang.md +409 -0
  220. package/skills/ae-tracking-matrix/references/sdk/server-sdk/golang.md +446 -0
  221. package/skills/ae-tracking-matrix/references/sdk/server-sdk/java.md +557 -0
  222. package/skills/ae-tracking-matrix/references/sdk/server-sdk/lua.md +457 -0
  223. package/skills/ae-tracking-matrix/references/sdk/server-sdk/nodejs.md +490 -0
  224. package/skills/ae-tracking-matrix/references/sdk/server-sdk/php.md +523 -0
  225. package/skills/ae-tracking-matrix/references/sdk/server-sdk/python.md +484 -0
  226. package/skills/ae-tracking-matrix/references/sdk/server-sdk/ruby.md +442 -0
  227. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/data-rules.md +391 -0
  228. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/first-event-validation.md +91 -0
  229. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/preset-properties-system-fields.md +635 -0
  230. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/updatable-events.md +113 -0
  231. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/user-identification-rules.md +466 -0
  232. package/skills/ae-tracking-matrix/references/standard-base/README.md +22 -0
  233. package/skills/ae-tracking-matrix/references/standard-base/basic_event_data.md +174 -0
  234. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties.md +20 -0
  235. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties_setup.md +7 -0
  236. package/skills/ae-tracking-matrix/references/standard-base/data_type_design_principles.md +14 -0
  237. package/skills/ae-tracking-matrix/references/standard-base/gameplay_event_data.md +370 -0
  238. package/skills/ae-tracking-matrix/references/standard-base/id_system_faq.md +47 -0
  239. package/skills/ae-tracking-matrix/references/standard-base/integration_must_know.md +37 -0
  240. package/skills/ae-tracking-matrix/references/standard-base/multi_platform_integration_notes.md +27 -0
  241. package/skills/ae-tracking-matrix/references/standard-base/multi_user_id_system_recommendations.md +23 -0
  242. package/skills/ae-tracking-matrix/references/standard-base/tracking_notes.md +14 -0
  243. package/skills/ae-tracking-matrix/references/standard-base/user_data.md +46 -0
  244. package/skills/ae-tracking-matrix/references/standard-base/user_id_system.md +13 -0
  245. package/skills/ae-tracking-matrix/references/system-fields.md +297 -0
  246. package/skills/ae-tracking-matrix/references/te-field-translations.md +1791 -0
  247. package/skills/ae-tracking-matrix/references/workflows/data-verification.md +232 -0
  248. package/skills/ae-tracking-matrix/references/workflows/feasibility-analysis.md +829 -0
  249. package/skills/ae-tracking-matrix/references/workflows/integration-qna.md +355 -0
  250. package/skills/ae-tracking-matrix/references/workflows/plan-generation.md +283 -0
  251. package/skills/ae-tracking-matrix/references/workflows/plan-lint.md +168 -0
  252. package/skills/ae-tracking-matrix/references/workflows/plan-review-optimize.md +205 -0
  253. package/skills/ae-tracking-matrix/references/workflows/prd-to-suggestions.md +75 -0
  254. package/skills/ae-tracking-matrix/references/workflows/troubleshooting.md +36 -0
  255. package/skills/ae-tracking-matrix/references/workflows/validated-upload.md +107 -0
  256. package/skills/ae-tracking-matrix/scripts/build_template_catalog.py +114 -0
  257. package/skills/ae-tracking-matrix/scripts/export_tracking_plan.py +53 -0
  258. package/skills/ae-tracking-matrix/scripts/finalize_plan.py +166 -0
  259. package/skills/ae-tracking-matrix/scripts/lint_tracking_plan.py +674 -0
  260. package/skills/ae-tracking-matrix/scripts/plan_contract.py +200 -0
  261. package/skills/ae-tracking-matrix/scripts/plan_types.py +60 -0
  262. package/skills/ae-tracking-matrix/scripts/prepare_delivery.py +169 -0
  263. package/skills/ae-tracking-matrix/scripts/sync_plan.py +296 -0
  264. package/skills/ae-tracking-matrix/scripts/upload_plan.py +340 -0
  265. package/dist/chunk-AMBFK2K3.js +0 -28
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  peekCliToken
4
- } from "./chunk-H3K5UGYC.js";
4
+ } from "./chunk-HTZ2MLYA.js";
5
5
  import {
6
6
  getActiveHost,
7
7
  getConfigDir,
8
8
  isAeSandboxRuntime,
9
9
  readSandboxCliTokenEntry
10
- } from "./chunk-JNVVJ273.js";
10
+ } from "./chunk-4PSTYEG5.js";
11
11
  import {
12
12
  PermissionError,
13
13
  externalCliTokenRequestOptions,
@@ -16,9 +16,9 @@ import {
16
16
  } from "./chunk-Z3Q2AEIN.js";
17
17
 
18
18
  // src/core/compat-check.ts
19
- import fs10 from "fs";
20
- import path10 from "path";
21
- import { createHash as createHash2 } from "crypto";
19
+ import fs11 from "fs";
20
+ import path11 from "path";
21
+ import { createHash as createHash3 } from "crypto";
22
22
  import { Agent } from "undici";
23
23
 
24
24
  // src/core/update-check.ts
@@ -307,13 +307,13 @@ function formatCompatNotice(verdict) {
307
307
  }
308
308
 
309
309
  // src/core/version-sync.ts
310
- import fs8 from "fs";
311
- import path8 from "path";
310
+ import fs9 from "fs";
311
+ import path9 from "path";
312
312
 
313
313
  // src/core/installation.ts
314
- import fs7 from "fs";
315
- import path7 from "path";
316
- import crypto2 from "crypto";
314
+ import fs8 from "fs";
315
+ import path8 from "path";
316
+ import crypto3 from "crypto";
317
317
 
318
318
  // src/core/package-info.ts
319
319
  import fs2 from "fs";
@@ -366,17 +366,30 @@ function readFiles(root, prefix = "", files = /* @__PURE__ */ new Map()) {
366
366
  }
367
367
  return files;
368
368
  }
369
- function readBundledSkills(directory) {
370
- const skills = fs3.readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => {
369
+ function readBundledSkills(directory, select) {
370
+ const entries = fs3.readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith("."));
371
+ const names = /* @__PURE__ */ new Set();
372
+ const skills = entries.flatMap((entry) => {
371
373
  try {
374
+ let selectedName;
375
+ if (select) {
376
+ const header = path3.join(directory, entry.name, "SKILL.md");
377
+ if (!fs3.lstatSync(header).isFile()) throw new Error("Bundled Skill metadata must be a regular file.");
378
+ selectedName = skillName(fs3.readFileSync(header, "utf8"));
379
+ if (names.has(selectedName)) throw new Error("Duplicate bundled Skill name.");
380
+ names.add(selectedName);
381
+ if (!select(selectedName)) return [];
382
+ }
372
383
  const files = readFiles(path3.join(directory, entry.name));
373
- return { name: skillName(files.get("SKILL.md").toString("utf8")), files };
384
+ const name = skillName(files.get("SKILL.md").toString("utf8"));
385
+ if (selectedName !== void 0 && selectedName !== name) throw new Error("Bundled Skill metadata changed.");
386
+ return [{ name, files }];
374
387
  } catch {
375
388
  const name = /^[a-z0-9-]+$/.test(entry.name) ? entry.name : "(invalid name)";
376
389
  throw new Error(`Invalid bundled Skill ${name}: missing files or YAML/frontmatter error.`);
377
390
  }
378
391
  });
379
- if (!skills.length || new Set(skills.map((skill) => skill.name)).size !== skills.length) {
392
+ if (!entries.length || !select && new Set(skills.map((skill) => skill.name)).size !== skills.length) {
380
393
  throw new Error("Bundled Skills are empty or contain duplicate names.");
381
394
  }
382
395
  return skills;
@@ -404,9 +417,9 @@ function verifyGlobalSkills(skills, directory) {
404
417
  }
405
418
 
406
419
  // src/core/business-config.ts
407
- import crypto from "crypto";
408
- import fs4 from "fs";
409
- import path4 from "path";
420
+ import crypto2 from "crypto";
421
+ import fs7 from "fs";
422
+ import path7 from "path";
410
423
 
411
424
  // src/core/skill-businesses.json
412
425
  var skill_businesses_default = {
@@ -421,7 +434,8 @@ var skill_businesses_default = {
421
434
  "ae-generate-tracking-code",
422
435
  "ae-generate-tracking-plan",
423
436
  "ae-metadata",
424
- "ae-migrate-tracking-code"
437
+ "ae-migrate-tracking-code",
438
+ "ae-tracking-matrix"
425
439
  ],
426
440
  dataops: [
427
441
  "ae-dataops"
@@ -439,6 +453,7 @@ var skill_businesses_default = {
439
453
  ],
440
454
  agent: [
441
455
  "ae-agent",
456
+ "ae-ai-monitor",
442
457
  "ae-automation",
443
458
  "ae-current-context",
444
459
  "ae-evaluation",
@@ -483,7 +498,9 @@ var COMMAND_BUSINESSES = {
483
498
  evaluation: "agent",
484
499
  sync: "agent",
485
500
  model: "agent",
486
- context: "agent"
501
+ context: "agent",
502
+ "ai-monitor": "agent",
503
+ ai_monitor: "agent"
487
504
  };
488
505
  var AGENT_SYSTEM_COMMANDS = /* @__PURE__ */ new Set([
489
506
  "channel",
@@ -586,153 +603,65 @@ function canManageGlobalSkills() {
586
603
  return !readExternalCliToken() && !isSandboxExecutionContext();
587
604
  }
588
605
 
589
- // src/core/business-config.ts
590
- var BUSINESS_CONFIG_TTL_MS = 10 * 60 * 1e3;
591
- var UNAVAILABLE_TTL_MS = 5 * 60 * 1e3;
592
- function cachePath() {
593
- return path4.join(getConfigDir(), "business-config.json");
594
- }
595
- function cacheKey(host, token) {
596
- return `${normalizeUrl(host)}#${crypto.createHash("sha256").update(token).digest("hex")}`;
597
- }
598
- function readStore() {
599
- try {
600
- const value = JSON.parse(fs4.readFileSync(cachePath(), "utf8"));
601
- if (value?.entries && typeof value.entries === "object" && !Array.isArray(value.entries)) return value;
602
- } catch {
603
- }
604
- return { entries: {} };
605
- }
606
- function remember(host, token, entry) {
607
- const store = readStore();
608
- store.entries[cacheKey(host, token)] = entry;
609
- const target = cachePath();
610
- const temporary = `${target}.${process.pid}.${crypto.randomBytes(6).toString("hex")}.tmp`;
611
- try {
612
- fs4.mkdirSync(path4.dirname(target), { recursive: true });
613
- fs4.writeFileSync(temporary, JSON.stringify(store), { encoding: "utf8", mode: 384 });
614
- fs4.renameSync(temporary, target);
615
- fs4.chmodSync(target, 384);
616
- } catch {
617
- try {
618
- fs4.rmSync(temporary, { force: true });
619
- } catch {
620
- }
621
- }
622
- }
623
- function rememberBusinessConfig(host, token, businesses, now = Date.now()) {
624
- remember(host, token, { businesses: normalizeBusinesses(businesses), fetchedAt: now });
625
- }
626
- function peekBusinessConfig(host, token, now = Date.now()) {
627
- const entry = readStore().entries[cacheKey(host, token)];
628
- if (entry?.unavailableAt !== void 0 && now >= entry.unavailableAt && now - entry.unavailableAt < UNAVAILABLE_TTL_MS) return {};
629
- if (!entry || !Number.isFinite(entry.fetchedAt) || now < entry.fetchedAt || now - entry.fetchedAt >= BUSINESS_CONFIG_TTL_MS) return void 0;
630
- return normalizeBusinesses(entry.businesses);
631
- }
632
- function readBusinessConfig(host, token) {
633
- const entry = readStore().entries[cacheKey(host, token)];
634
- return entry && Number.isFinite(entry.fetchedAt) && entry.fetchedAt > 0 ? normalizeBusinesses(entry.businesses) : void 0;
635
- }
636
- function readCurrentBusinessConfig(hostOverride) {
637
- try {
638
- if (isSandboxExecutionContext()) return {};
639
- const host = hostOverride || getActiveHost();
640
- if (!host) return {};
641
- const token = peekCliToken(host);
642
- return token ? readBusinessConfig(host, token) ?? {} : {};
643
- } catch {
644
- return {};
645
- }
646
- }
647
- async function resolveBusinessConfig(host, token, fetchRemote, now = Date.now()) {
648
- const cached = peekBusinessConfig(host, token, now);
649
- if (cached !== void 0) return cached;
650
- const config = await fetchRemote().catch(() => null);
651
- if (!config) {
652
- const previous = readStore().entries[cacheKey(host, token)];
653
- remember(host, token, {
654
- businesses: normalizeBusinesses(previous?.businesses),
655
- fetchedAt: previous?.fetchedAt ?? 0,
656
- unavailableAt: now
657
- });
658
- return {};
659
- }
660
- const businesses = normalizeBusinesses(config.businesses);
661
- rememberBusinessConfig(host, token, businesses, now);
662
- return businesses;
663
- }
664
- var BusinessDisabledError = class extends PermissionError {
665
- constructor(business) {
666
- super(
667
- `The '${business}' business is not enabled for the current environment.`,
668
- "BUSINESS_NOT_ENABLED",
669
- "Contact your administrator if this business should be enabled, then run: ae-cli config refresh"
670
- );
671
- this.business = business;
672
- this.name = "BusinessDisabledError";
673
- }
674
- business;
675
- };
676
- async function readBusinessConfigForExecution(hostOverride) {
677
- try {
678
- if (isSandboxExecutionContext()) return {};
679
- const host = hostOverride || getActiveHost();
680
- if (!host) return {};
681
- const token = peekCliToken(host);
682
- if (!token) return {};
683
- return await resolveBusinessConfig(host, token, async () => {
684
- const { fetchCliConfig: fetchCliConfig2 } = await import("./compat-check-CII6B74E.js");
685
- return fetchCliConfig2(host, token);
686
- });
687
- } catch {
688
- return {};
689
- }
690
- }
691
- async function assertBusinessEnabled(business, hostOverride) {
692
- if (business && (await readBusinessConfigForExecution(hostOverride))[business] === false) {
693
- throw new BusinessDisabledError(business);
694
- }
695
- }
696
-
697
- // src/core/business-skill-sync.ts
606
+ // src/core/business-skill-refresh.ts
607
+ import crypto from "crypto";
698
608
  import fs6 from "fs";
699
609
  import path6 from "path";
700
- import { randomUUID } from "crypto";
701
610
 
702
- // src/core/skills-tool.ts
611
+ // src/core/business-skill-sync.ts
703
612
  import fs5 from "fs";
704
- import os2 from "os";
613
+ import os3 from "os";
705
614
  import path5 from "path";
615
+ import { createHash as createHash2, randomUUID } from "crypto";
616
+
617
+ // src/core/skills-tool.ts
618
+ import fs4 from "fs";
619
+ import os2 from "os";
620
+ import path4 from "path";
706
621
  import { createHash } from "crypto";
707
622
  import { createRequire, isBuiltin } from "module";
708
623
  import { pathToFileURL } from "url";
709
624
  import spawn2 from "cross-spawn";
710
625
  var MANAGED_SKILLS_TOOL_VERSION = "1.5.12";
711
626
  var TOOL_SOURCE_SHA256 = "5a2c18ddd70886d5367e39a0f88827ffd1024420e4d9db08149742386c088d2d";
627
+ function skillPathIdentity(file) {
628
+ try {
629
+ const stat = fs4.lstatSync(file, { bigint: true });
630
+ return {
631
+ dev: String(stat.dev),
632
+ ino: String(stat.ino),
633
+ type: stat.isSymbolicLink() ? "symlink" : stat.isDirectory() ? "directory" : stat.isFile() ? "file" : "other",
634
+ ...stat.isSymbolicLink() ? { link: fs4.readlinkSync(file) } : {}
635
+ };
636
+ } catch (error) {
637
+ if (error.code === "ENOENT") return null;
638
+ throw error;
639
+ }
640
+ }
712
641
  function realSkillPath(file) {
713
642
  try {
714
- return fs5.realpathSync(file);
643
+ return fs4.realpathSync(file);
715
644
  } catch (error) {
716
645
  if (error.code !== "ENOENT") throw error;
717
- const parent = path5.dirname(file);
646
+ const parent = path4.dirname(file);
718
647
  if (parent === file) throw error;
719
- return path5.join(realSkillPath(parent), path5.basename(file));
648
+ return path4.join(realSkillPath(parent), path4.basename(file));
720
649
  }
721
650
  }
722
651
  function skillPathProblem(targetDirectory, skill, sourceRoot) {
723
652
  try {
724
- const target = realSkillPath(path5.resolve(targetDirectory, skill));
725
- const source = fs5.realpathSync(sourceRoot);
726
- const overlaps = (a, b) => a === b || a.startsWith(b + path5.sep);
653
+ const target = realSkillPath(path4.resolve(targetDirectory, skill));
654
+ const source = realSkillPath(path4.resolve(sourceRoot));
655
+ const overlaps = (a, b) => a === b || a.startsWith(b + path4.sep);
727
656
  if (overlaps(target, source) || overlaps(source, target)) return "package_source_overlap";
728
- let parent = path5.resolve(targetDirectory);
657
+ let parent = path4.resolve(targetDirectory);
729
658
  while (true) {
730
659
  try {
731
- if (fs5.lstatSync(parent).isSymbolicLink()) return "copy_parent_linked";
660
+ if (fs4.lstatSync(parent).isSymbolicLink()) return "copy_parent_linked";
732
661
  } catch (error) {
733
662
  if (error.code !== "ENOENT") throw error;
734
663
  }
735
- const next = path5.dirname(parent);
664
+ const next = path4.dirname(parent);
736
665
  if (next === parent) return null;
737
666
  parent = next;
738
667
  }
@@ -742,27 +671,27 @@ function skillPathProblem(targetDirectory, skill, sourceRoot) {
742
671
  }
743
672
  function skillCopyHash(directory, source = false) {
744
673
  try {
745
- if (!fs5.lstatSync(directory).isDirectory()) throw new Error("Not a regular Skill directory.");
674
+ if (!fs4.lstatSync(directory).isDirectory()) throw new Error("Not a regular Skill directory.");
746
675
  } catch (error) {
747
676
  if (error.code === "ENOENT") return null;
748
677
  throw error;
749
678
  }
750
679
  const hash = createHash("sha256");
751
680
  const visit = (relative) => {
752
- for (const name of fs5.readdirSync(path5.join(directory, relative)).sort()) {
681
+ for (const name of fs4.readdirSync(path4.join(directory, relative)).sort()) {
753
682
  if (name === ".DS_Store") continue;
754
- const child = path5.join(relative, name);
755
- const absolute = path5.join(directory, child);
756
- const stat = fs5.lstatSync(absolute);
683
+ const child = path4.join(relative, name);
684
+ const absolute = path4.join(directory, child);
685
+ const stat = fs4.lstatSync(absolute);
757
686
  if (source && (name === "metadata.json" || stat.isDirectory() && [".git", "__pycache__", "__pypackages__"].includes(name))) continue;
758
- const normalized = child.split(path5.sep).join("/");
687
+ const normalized = child.split(path4.sep).join("/");
759
688
  if (stat.isSymbolicLink()) throw new Error("Symbolic links are not managed Skill copies.");
760
689
  if (stat.isDirectory()) {
761
690
  hash.update(`directory:${normalized}\0`);
762
691
  visit(child);
763
692
  } else if (stat.isFile()) {
764
693
  hash.update(`file:${normalized}\0${stat.size}\0`);
765
- hash.update(fs5.readFileSync(absolute));
694
+ hash.update(fs4.readFileSync(absolute));
766
695
  } else throw new Error("Unsupported Skill file type.");
767
696
  }
768
697
  };
@@ -780,6 +709,11 @@ function adaptedToolSource(source, entry) {
780
709
  let remove = source.slice(removeStart, removeEnd);
781
710
  remove = replaceOnce(remove, "const agentResult = await detectAgent();", "const agentResult = { isAgent: false };");
782
711
  remove = replaceOnce(remove, "const spinner = Y();", "const spinner = { start() {}, stop() {} };");
712
+ remove = replaceOnce(
713
+ remove,
714
+ "for (const entry of entries) if (entry.isDirectory()) skillNamesSet.add(entry.name);",
715
+ "for (const entry of entries) if (entry.isDirectory() || options.__aeCliAllowedPaths.has(join(dir, entry.name))) skillNamesSet.add(entry.name);"
716
+ );
783
717
  remove = replaceOnce(
784
718
  remove,
785
719
  "if (pathToCleanup === canonicalPath) continue;",
@@ -814,7 +748,7 @@ function adaptedToolSource(source, entry) {
814
748
  );
815
749
  source = replaceOnce(source, "main().finally(() => flushTelemetry().then(() => process.exit(0)));", "");
816
750
  const require2 = createRequire(entry);
817
- const resolveImport = (specifier) => isBuiltin(specifier) ? specifier : pathToFileURL(specifier.startsWith(".") ? path5.resolve(path5.dirname(entry), specifier) : require2.resolve(specifier)).href;
751
+ const resolveImport = (specifier) => isBuiltin(specifier) ? specifier : pathToFileURL(specifier.startsWith(".") ? path4.resolve(path4.dirname(entry), specifier) : require2.resolve(specifier)).href;
818
752
  source = source.replace(
819
753
  /\bfrom (['"])([^'"]+)\1/g,
820
754
  (_match, quote, specifier) => `from ${quote}${resolveImport(specifier)}${quote}`
@@ -827,7 +761,6 @@ function adaptedToolSource(source, entry) {
827
761
  }
828
762
  var WORKER_SOURCE = String.raw`
829
763
  import * as __aeCliFs from 'node:fs';
830
- import * as __aeCliPath from 'node:path';
831
764
  const __aeCliQuiet = () => {};
832
765
  let __aeCliTargetOverride = null;
833
766
  let __aeCliBeforeInstallMutation = null;
@@ -843,7 +776,7 @@ function __aeCliRealPath(file) {
843
776
  function __aeCliPathProblem(targetDirectory, skill, sourceRoot) {
844
777
  try {
845
778
  const target = __aeCliRealPath(resolve(targetDirectory, skill));
846
- const source = __aeCliFs.realpathSync(sourceRoot);
779
+ const source = __aeCliRealPath(resolve(sourceRoot));
847
780
  const overlaps = (a, b) => a === b || a.startsWith(b + sep);
848
781
  if (overlaps(target, source) || overlaps(source, target)) return 'package_source_overlap';
849
782
  let parent = resolve(targetDirectory);
@@ -876,46 +809,49 @@ function __aeCliHash(directory, source = false) {
876
809
  visit('');
877
810
  return hash.digest('hex');
878
811
  }
812
+ function __aeCliDirectInstallerLink(text, file, target) {
813
+ if (typeof text !== 'string') return false;
814
+ let value = text;
815
+ if (process.platform === 'win32') {
816
+ if (value.toUpperCase().startsWith('\\\\?\\UNC\\')) value = '\\\\' + value.slice(8);
817
+ else if (value.startsWith('\\\\?\\') || value.startsWith('\\??\\')) value = value.slice(4);
818
+ return [target, relative(dirname(file), target)].some(expected => value.toLowerCase() === expected.toLowerCase());
819
+ }
820
+ return value === target || value === relative(dirname(file), target);
821
+ }
879
822
  function __aeCliLegacyLinkProblem(operation, targetPath, targets, guard) {
880
823
  try {
881
824
  const canonical = resolve(getCanonicalSkillsDir(true));
882
825
  const canonicalTarget = targets.find(target => target.agent === 'universal' && target.directory === canonical);
883
826
  const link = operation.legacy_link;
827
+ const removing = operation.action === 'remove';
884
828
  if (!canonicalTarget || link.target !== join(canonical, operation.skill) || targetPath === link.target
885
- || !guard.ledger_file || operation.expected_hash !== operation.source_hash) return 'legacy_link_not_managed';
829
+ || !guard.ledger_file || (!removing && operation.expected_hash !== operation.source_hash)) return 'legacy_link_not_managed';
886
830
  const pathProblem = __aeCliPathProblem(canonical, operation.skill, operation.source_root);
887
831
  if (pathProblem) return pathProblem;
888
832
  const ledger = JSON.parse(__aeCliFs.readFileSync(guard.ledger_file, 'utf8'));
889
833
  const owned = ledger.schema_version === 1 && ledger.copies?.[link.target];
890
834
  if (!owned || owned.skill !== operation.skill || owned.agent !== canonicalTarget.agent
891
- || owned.hash !== operation.source_hash) return 'legacy_link_not_managed';
835
+ || (!removing && owned.hash !== operation.source_hash)) return 'legacy_link_not_managed';
892
836
  if (!__aeCliFs.lstatSync(targetPath).isSymbolicLink() || __aeCliFs.readlinkSync(targetPath) !== link.text
893
- || resolve(dirname(targetPath), link.text) !== link.target
894
- || __aeCliFs.realpathSync(targetPath) !== __aeCliFs.realpathSync(link.target)) return 'legacy_link_changed';
895
- if (__aeCliHash(link.target) !== operation.source_hash) return 'legacy_link_target_modified';
837
+ || !__aeCliDirectInstallerLink(link.text, targetPath, link.target)
838
+ || (!removing && __aeCliFs.realpathSync(targetPath) !== __aeCliFs.realpathSync(link.target))) return 'legacy_link_changed';
839
+ if (!removing && __aeCliHash(link.target) !== operation.source_hash) return 'legacy_link_target_modified';
896
840
  return null;
897
841
  } catch { return 'legacy_link_unreadable'; }
898
842
  }
899
- function __aeCliLinkDependsOn(file, dependency) {
900
- const absolute = resolve(file);
901
- let cursor = __aeCliPath.parse(absolute).root;
902
- const pending = absolute.slice(cursor.length).split(sep);
903
- let links = 0;
904
- while (pending.length) {
905
- const part = pending.shift();
906
- if (!part || part === '.') continue;
907
- if (part === '..') { cursor = dirname(cursor); continue; }
908
- cursor = join(cursor, part);
909
- if (cursor === dependency || cursor.startsWith(dependency + sep)) return true;
910
- if (!__aeCliFs.lstatSync(cursor).isSymbolicLink()) continue;
911
- if (++links > 64) throw new Error('Skill link chain is too deep.');
912
- const text = __aeCliFs.readlinkSync(cursor);
913
- const root = __aeCliPath.parse(text).root;
914
- cursor = root || dirname(cursor);
915
- // Expand a link before applying subsequent '..' components, matching filesystem lookup.
916
- pending.unshift(...text.slice(root.length).split(sep));
917
- }
918
- return false;
843
+ function __aeCliRemovalProblem(operation, targetPath, guard) {
844
+ try {
845
+ const ledger = guard.ledger_file && JSON.parse(__aeCliFs.readFileSync(guard.ledger_file, 'utf8'));
846
+ const owned = ledger?.schema_version === 1 && ledger.copies?.[targetPath];
847
+ if (!owned || owned.skill !== operation.skill || owned.agent !== operation.target.agent) return 'copy_not_managed';
848
+ const expected = operation.expected_node;
849
+ const current = __aeCliFs.lstatSync(targetPath, { bigint: true });
850
+ const type = current.isSymbolicLink() ? 'symlink' : current.isDirectory() ? 'directory' : current.isFile() ? 'file' : 'other';
851
+ if (!expected || expected.dev !== String(current.dev) || expected.ino !== String(current.ino) || expected.type !== type
852
+ || (type === 'symlink' && expected.link !== __aeCliFs.readlinkSync(targetPath))) return 'copy_changed';
853
+ return null;
854
+ } catch { return 'copy_unreadable'; }
919
855
  }
920
856
  async function __aeCliTargets() {
921
857
  const detected = new Set(await detectInstalledAgents());
@@ -963,24 +899,16 @@ async function __aeCliMain() {
963
899
  blockedReason = 'legacy_target_missing'; return false;
964
900
  }
965
901
  if (candidate !== targetPath) { blockedReason = 'copy_changed'; return false; }
966
- if (__aeCliHash(operation.source, true) !== operation.source_hash) { blockedReason = 'package_changed'; return false; }
902
+ if (operation.action === 'remove') {
903
+ const problem = __aeCliRemovalProblem(operation, targetPath, request.guard);
904
+ if (problem) { blockedReason = problem; return false; }
905
+ } else {
906
+ if (__aeCliHash(operation.source, true) !== operation.source_hash) { blockedReason = 'package_changed'; return false; }
907
+ if (!operation.legacy_link && __aeCliHash(targetPath) !== operation.expected_hash) { blockedReason = 'copy_changed'; return false; }
908
+ }
967
909
  if (operation.legacy_link) {
968
910
  const problem = __aeCliLegacyLinkProblem(operation, targetPath, targets, request.guard);
969
911
  if (problem) { blockedReason = problem; return false; }
970
- } else if (__aeCliHash(targetPath) !== operation.expected_hash) { blockedReason = 'copy_changed'; return false; }
971
- if (operation.action === 'remove') for (const other of targets) {
972
- try {
973
- // Preserve custom aliases too; only exact same-name installer links are migrated.
974
- for (const name of __aeCliFs.readdirSync(other.directory)) {
975
- const otherPath = join(other.directory, name);
976
- if (otherPath === targetPath) continue;
977
- try {
978
- if (__aeCliFs.lstatSync(otherPath).isSymbolicLink() && __aeCliLinkDependsOn(otherPath, targetPath)) {
979
- blockedReason = 'dependent_unmanaged_link'; return false;
980
- }
981
- } catch (error) { if (error.code !== 'ENOENT') throw error; }
982
- }
983
- } catch (error) { if (error.code !== 'ENOENT') { blockedReason = 'dependent_copy_unreadable'; return false; } }
984
912
  }
985
913
  return true;
986
914
  } catch { blockedReason = 'copy_unreadable'; return false; }
@@ -1030,19 +958,19 @@ catch { process.stdout.write(JSON.stringify({ ok: false })); process.exitCode =
1030
958
  `;
1031
959
  function createPinnedSkillsTool(options = {}) {
1032
960
  const require2 = createRequire(import.meta.url);
1033
- const packageFile = options.entry ? path5.join(path5.dirname(options.entry), "..", "package.json") : require2.resolve("skills/package.json");
1034
- const entry = options.entry ?? path5.join(path5.dirname(packageFile), "dist", "cli.mjs");
1035
- const metadata = JSON.parse(fs5.readFileSync(packageFile, "utf8"));
1036
- const source = fs5.readFileSync(entry, "utf8");
961
+ const packageFile = options.entry ? path4.join(path4.dirname(options.entry), "..", "package.json") : require2.resolve("skills/package.json");
962
+ const entry = options.entry ?? path4.join(path4.dirname(packageFile), "dist", "cli.mjs");
963
+ const metadata = JSON.parse(fs4.readFileSync(packageFile, "utf8"));
964
+ const source = fs4.readFileSync(entry, "utf8");
1037
965
  if (metadata.version !== MANAGED_SKILLS_TOOL_VERSION || createHash("sha256").update(source).digest("hex") !== TOOL_SOURCE_SHA256) {
1038
966
  throw new Error("Managed Skill synchronization requires the verified skills@1.5.12 package.");
1039
967
  }
1040
968
  const script = adaptedToolSource(source, entry);
1041
969
  const run = (request) => {
1042
- const directory = fs5.mkdtempSync(path5.join(os2.tmpdir(), "ae-cli-skills-tool-"));
1043
- const worker = path5.join(directory, "adapter.mjs");
970
+ const directory = fs4.mkdtempSync(path4.join(os2.tmpdir(), "ae-cli-skills-tool-"));
971
+ const worker = path4.join(directory, "adapter.mjs");
1044
972
  try {
1045
- fs5.writeFileSync(worker, script, { mode: 384 });
973
+ fs4.writeFileSync(worker, script, { mode: 384 });
1046
974
  const result2 = spawn2.sync(process.execPath, [worker], {
1047
975
  input: JSON.stringify(request),
1048
976
  encoding: "utf8",
@@ -1059,7 +987,7 @@ function createPinnedSkillsTool(options = {}) {
1059
987
  } catch {
1060
988
  throw new Error("Skills adapter failed. Check the pinned package and directory permissions.");
1061
989
  } finally {
1062
- fs5.rmSync(directory, { recursive: true, force: true });
990
+ fs4.rmSync(directory, { recursive: true, force: true });
1063
991
  }
1064
992
  };
1065
993
  return {
@@ -1072,14 +1000,60 @@ function createPinnedSkillsTool(options = {}) {
1072
1000
  var CONTEXT_FILE = "business-skill-context.json";
1073
1001
  var LEDGER_FILE = "business-skills.json";
1074
1002
  var LOCK_FILE = "business-skills.lock";
1003
+ var POLICY_HASH = createHash2("sha256").update(JSON.stringify({ removal_policy: 2, optional_businesses: OPTIONAL_BUSINESSES, skills: skill_businesses_default })).digest("hex");
1004
+ function historicalCliSkills(options) {
1005
+ const env = options.env ?? process.env;
1006
+ const home = env.HOME || env.USERPROFILE || os3.homedir();
1007
+ const file = env.XDG_STATE_HOME ? path5.join(env.XDG_STATE_HOME, "skills", ".skill-lock.json") : path5.join(home, ".agents", ".skill-lock.json");
1008
+ const names = /* @__PURE__ */ new Set();
1009
+ let content = "";
1010
+ const isCliSource = (value, type) => {
1011
+ if (typeof value !== "string") return false;
1012
+ if (type === "local" && path5.isAbsolute(value)) {
1013
+ const source2 = path5.resolve(value);
1014
+ if (source2 === path5.resolve(options.skillsDirectory)) return true;
1015
+ if (path5.basename(source2) !== "skills") return false;
1016
+ try {
1017
+ const pkg = JSON.parse(fs5.readFileSync(path5.join(source2, "..", "package.json"), "utf8"));
1018
+ return ["@tant/ae-cli", "@thinkingai/ae-cli"].includes(pkg.name) && typeof pkg.bin?.["ae-cli"] === "string";
1019
+ } catch {
1020
+ return false;
1021
+ }
1022
+ }
1023
+ if (!["git", "github"].includes(String(type))) return false;
1024
+ const source = value.replace(/\/+$/, "").replace(/\.git$/, "");
1025
+ return [
1026
+ "ThinkingAIAgenticEngine/ae-cli",
1027
+ "https://github.com/ThinkingAIAgenticEngine/ae-cli",
1028
+ "git@github.com:ThinkingAIAgenticEngine/ae-cli",
1029
+ "ssh://git@gitlab.thinkingdata.cn:2222/te-ai/te-cli",
1030
+ "https://gitlab.thinkingdata.cn/te-ai/te-cli",
1031
+ "http://10.27.249.150:8888/te-ai/te-cli"
1032
+ ].includes(source);
1033
+ };
1034
+ try {
1035
+ content = fs5.readFileSync(file, "utf8");
1036
+ const lock = JSON.parse(content);
1037
+ const mapped = new Set(Object.values(skill_businesses_default).flat());
1038
+ if (typeof lock.version === "number" && lock.skills && typeof lock.skills === "object") {
1039
+ for (const [name, entry] of Object.entries(lock.skills)) {
1040
+ if (!mapped.has(name) || !entry || typeof entry !== "object") continue;
1041
+ const record = entry;
1042
+ if (isCliSource(record.source, record.sourceType) || isCliSource(record.sourceUrl, record.sourceType)) names.add(name);
1043
+ }
1044
+ }
1045
+ } catch {
1046
+ }
1047
+ return { names, hash: createHash2("sha256").update(content).digest("hex") };
1048
+ }
1075
1049
  function writeJson(file, value) {
1076
1050
  const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
1077
1051
  try {
1078
- fs6.writeFileSync(temporary, JSON.stringify(value, null, 2) + "\n", { mode: 384, flag: "wx" });
1079
- fs6.renameSync(temporary, file);
1052
+ fs5.writeFileSync(temporary, JSON.stringify(value, null, 2) + "\n", { mode: 384, flag: "wx" });
1053
+ fs5.renameSync(temporary, file);
1080
1054
  } finally {
1081
1055
  try {
1082
- fs6.unlinkSync(temporary);
1056
+ fs5.unlinkSync(temporary);
1083
1057
  } catch {
1084
1058
  }
1085
1059
  }
@@ -1099,15 +1073,15 @@ function contextIdentity(options) {
1099
1073
  }
1100
1074
  function reserveBusinessSkillContext(options) {
1101
1075
  const directory = options.stateDirectory ?? getConfigDir();
1102
- fs6.mkdirSync(directory, { recursive: true, mode: 448 });
1076
+ fs5.mkdirSync(directory, { recursive: true, mode: 448 });
1103
1077
  const generation = randomUUID();
1104
- writeJson(path6.join(directory, CONTEXT_FILE), { ...contextIdentity(options), generation });
1078
+ writeJson(path5.join(directory, CONTEXT_FILE), { ...contextIdentity(options), generation });
1105
1079
  return generation;
1106
1080
  }
1107
1081
  function currentContext(options, file, generation) {
1108
1082
  try {
1109
1083
  if (options.isCurrentContext && !options.isCurrentContext()) return false;
1110
- const active = JSON.parse(fs6.readFileSync(file, "utf8"));
1084
+ const active = JSON.parse(fs5.readFileSync(file, "utf8"));
1111
1085
  const identity = contextIdentity(options);
1112
1086
  return active.generation === generation && active.host === identity.host && active.token_fingerprint === identity.token_fingerprint;
1113
1087
  } catch {
@@ -1115,12 +1089,12 @@ function currentContext(options, file, generation) {
1115
1089
  }
1116
1090
  }
1117
1091
  function isBusinessSkillContextCurrent(options) {
1118
- return currentContext(options, path6.join(options.stateDirectory ?? getConfigDir(), CONTEXT_FILE), options.generation);
1092
+ return currentContext(options, path5.join(options.stateDirectory ?? getConfigDir(), CONTEXT_FILE), options.generation);
1119
1093
  }
1120
1094
  function takeLock(file) {
1121
1095
  const owner = randomUUID();
1122
1096
  const ownerName = `owner-${process.pid}-${owner}.json`;
1123
- const candidate = fs6.mkdtempSync(`${file}.candidate-`);
1097
+ const candidate = fs5.mkdtempSync(`${file}.candidate-`);
1124
1098
  const alive = (pid) => {
1125
1099
  try {
1126
1100
  process.kill(pid, 0);
@@ -1130,29 +1104,29 @@ function takeLock(file) {
1130
1104
  }
1131
1105
  };
1132
1106
  try {
1133
- fs6.chmodSync(candidate, 448);
1134
- fs6.writeFileSync(path6.join(candidate, ownerName), JSON.stringify({ pid: process.pid, owner }), { mode: 384 });
1107
+ fs5.chmodSync(candidate, 448);
1108
+ fs5.writeFileSync(path5.join(candidate, ownerName), JSON.stringify({ pid: process.pid, owner }), { mode: 384 });
1135
1109
  for (let attempt = 0; attempt < 4; attempt++) {
1136
1110
  try {
1137
- fs6.renameSync(candidate, file);
1111
+ fs5.renameSync(candidate, file);
1138
1112
  try {
1139
- fs6.unlinkSync(`${file}.reclaim`);
1113
+ fs5.unlinkSync(`${file}.reclaim`);
1140
1114
  } catch {
1141
1115
  }
1142
1116
  return () => {
1143
1117
  try {
1144
- fs6.unlinkSync(path6.join(file, ownerName));
1118
+ fs5.unlinkSync(path5.join(file, ownerName));
1145
1119
  } catch {
1146
1120
  }
1147
1121
  try {
1148
- fs6.rmdirSync(file);
1122
+ fs5.rmdirSync(file);
1149
1123
  } catch {
1150
1124
  }
1151
1125
  };
1152
1126
  } catch (error) {
1153
1127
  let stat;
1154
1128
  try {
1155
- stat = fs6.lstatSync(file);
1129
+ stat = fs5.lstatSync(file);
1156
1130
  } catch (cause) {
1157
1131
  if (cause.code === "ENOENT") continue;
1158
1132
  throw error;
@@ -1161,12 +1135,12 @@ function takeLock(file) {
1161
1135
  if (stat.isFile()) {
1162
1136
  let pid;
1163
1137
  try {
1164
- pid = JSON.parse(fs6.readFileSync(file, "utf8")).pid;
1138
+ pid = JSON.parse(fs5.readFileSync(file, "utf8")).pid;
1165
1139
  } catch {
1166
1140
  }
1167
1141
  if (typeof pid === "number" && Number.isInteger(pid) && pid > 0 && alive(pid)) return null;
1168
1142
  try {
1169
- fs6.unlinkSync(file);
1143
+ fs5.unlinkSync(file);
1170
1144
  } catch (cause) {
1171
1145
  if (!["ENOENT", "EISDIR", "EPERM"].includes(cause.code ?? "")) throw cause;
1172
1146
  }
@@ -1175,7 +1149,7 @@ function takeLock(file) {
1175
1149
  if (!stat.isDirectory()) return null;
1176
1150
  let names;
1177
1151
  try {
1178
- names = fs6.readdirSync(file);
1152
+ names = fs5.readdirSync(file);
1179
1153
  } catch (cause) {
1180
1154
  if (cause.code === "ENOENT") continue;
1181
1155
  throw cause;
@@ -1186,13 +1160,13 @@ function takeLock(file) {
1186
1160
  }
1187
1161
  for (const name of names) {
1188
1162
  try {
1189
- fs6.unlinkSync(path6.join(file, name));
1163
+ fs5.unlinkSync(path5.join(file, name));
1190
1164
  } catch (cause) {
1191
1165
  if (cause.code !== "ENOENT") throw cause;
1192
1166
  }
1193
1167
  }
1194
1168
  try {
1195
- fs6.rmdirSync(file);
1169
+ fs5.rmdirSync(file);
1196
1170
  } catch (cause) {
1197
1171
  if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(cause.code ?? "")) throw cause;
1198
1172
  }
@@ -1200,13 +1174,13 @@ function takeLock(file) {
1200
1174
  }
1201
1175
  return null;
1202
1176
  } finally {
1203
- fs6.rmSync(candidate, { recursive: true, force: true });
1177
+ fs5.rmSync(candidate, { recursive: true, force: true });
1204
1178
  }
1205
1179
  }
1206
1180
  function readLedger(file) {
1207
1181
  let value;
1208
1182
  try {
1209
- value = JSON.parse(fs6.readFileSync(file, "utf8"));
1183
+ value = JSON.parse(fs5.readFileSync(file, "utf8"));
1210
1184
  } catch (error) {
1211
1185
  if (error.code === "ENOENT") return { schema_version: 1, copies: {} };
1212
1186
  throw new Error("Managed Skill ledger is unreadable.");
@@ -1215,23 +1189,34 @@ function readLedger(file) {
1215
1189
  throw new Error("Managed Skill ledger has an unsupported format.");
1216
1190
  }
1217
1191
  for (const [filePath, copy] of Object.entries(value.copies)) {
1218
- if (!path6.isAbsolute(filePath) || !copy || typeof copy.skill !== "string" || typeof copy.agent !== "string" || !/^[a-f0-9]{64}$/.test(copy.hash) || typeof copy.package_version !== "string") throw new Error("Managed Skill ledger has an invalid copy.");
1192
+ if (!path5.isAbsolute(filePath) || !copy || typeof copy.skill !== "string" || typeof copy.agent !== "string" || !/^[a-f0-9]{64}$/.test(copy.hash) || typeof copy.package_version !== "string") throw new Error("Managed Skill ledger has an invalid copy.");
1219
1193
  }
1220
1194
  return value;
1221
1195
  }
1222
1196
  function result(skill, target, reason) {
1223
- return { skill, agent: target.agent, path: path6.join(target.directory, skill), ...reason ? { reason } : {} };
1197
+ return { skill, agent: target.agent, path: path5.join(target.directory, skill), ...reason ? { reason } : {} };
1198
+ }
1199
+ function directInstallerLink(file, target, text) {
1200
+ if (typeof text !== "string") return false;
1201
+ let value = text;
1202
+ if (process.platform === "win32") {
1203
+ if (value.toUpperCase().startsWith("\\\\?\\UNC\\")) value = "\\\\" + value.slice(8);
1204
+ else if (value.startsWith("\\\\?\\") || value.startsWith("\\??\\")) value = value.slice(4);
1205
+ return [target, path5.relative(path5.dirname(file), target)].some((expected) => value.toLowerCase() === expected.toLowerCase());
1206
+ }
1207
+ return value === target || value === path5.relative(path5.dirname(file), target);
1224
1208
  }
1225
- function legacySkillLink(file, skill, sourceRoot, sourceHash, targets, ledger) {
1209
+ function legacySkillLink(file, skill, sourceRoot, sourceHash, targets, ledger, removing = false) {
1226
1210
  const canonical = targets.find((target2) => target2.agent === "universal");
1227
1211
  if (!canonical) return;
1228
- const target = path6.join(canonical.directory, skill);
1212
+ const target = path5.join(canonical.directory, skill);
1229
1213
  const managed = ledger.copies[target];
1230
- if (!managed || managed.skill !== skill || managed.agent !== canonical.agent || managed.hash !== sourceHash || skillPathProblem(canonical.directory, skill, sourceRoot)) return;
1214
+ if (!managed || managed.skill !== skill || managed.agent !== canonical.agent || !removing && managed.hash !== sourceHash || skillPathProblem(canonical.directory, skill, sourceRoot)) return;
1231
1215
  try {
1232
- if (!fs6.lstatSync(file).isSymbolicLink() || skillCopyHash(target) !== sourceHash) return;
1233
- const text = fs6.readlinkSync(file);
1234
- if (path6.resolve(path6.dirname(file), text) !== target || fs6.realpathSync(file) !== fs6.realpathSync(target)) return;
1216
+ if (!fs5.lstatSync(file).isSymbolicLink()) return;
1217
+ const text = fs5.readlinkSync(file);
1218
+ if (!directInstallerLink(file, target, text)) return;
1219
+ if (!removing && (skillCopyHash(target) !== sourceHash || fs5.realpathSync(file) !== fs5.realpathSync(target))) return;
1235
1220
  return { target, text };
1236
1221
  } catch {
1237
1222
  return;
@@ -1248,20 +1233,20 @@ function syncBusinessSkills(options) {
1248
1233
  managed_count: 0
1249
1234
  };
1250
1235
  const directory = options.stateDirectory ?? getConfigDir();
1251
- const contextFile = path6.join(directory, CONTEXT_FILE);
1236
+ const contextFile = path5.join(directory, CONTEXT_FILE);
1252
1237
  let unlock = null;
1253
1238
  try {
1254
1239
  if (options.isCurrentContext && !options.isCurrentContext()) {
1255
1240
  report.status = "stale";
1256
1241
  return report;
1257
1242
  }
1258
- fs6.mkdirSync(directory, { recursive: true, mode: 448 });
1243
+ fs5.mkdirSync(directory, { recursive: true, mode: 448 });
1259
1244
  const generation = options.generation ?? reserveBusinessSkillContext(options);
1260
1245
  if (!currentContext(options, contextFile, generation)) {
1261
1246
  report.status = "stale";
1262
1247
  return report;
1263
1248
  }
1264
- unlock = takeLock(path6.join(directory, LOCK_FILE));
1249
+ unlock = takeLock(path5.join(directory, LOCK_FILE));
1265
1250
  if (!unlock) {
1266
1251
  report.status = "busy";
1267
1252
  return report;
@@ -1270,26 +1255,114 @@ function syncBusinessSkills(options) {
1270
1255
  report.status = "stale";
1271
1256
  return report;
1272
1257
  }
1273
- const ledgerFile = path6.join(directory, LEDGER_FILE);
1258
+ const ledgerFile = path5.join(directory, LEDGER_FILE);
1274
1259
  const ledger = readLedger(ledgerFile);
1275
- const tool = options.tool ?? createPinnedSkillsTool({ env: options.env });
1276
- const targets = tool.targets();
1277
- const skills = readBundledSkills(options.skillsDirectory);
1278
1260
  const packageVersion = options.packageVersion ?? "unknown";
1261
+ const history = historicalCliSkills(options);
1262
+ const applied = {
1263
+ ...contextIdentity(options),
1264
+ package_version: packageVersion,
1265
+ businesses: normalizeBusinesses(options.businesses),
1266
+ source_root: fs5.realpathSync(options.skillsDirectory),
1267
+ policy_hash: POLICY_HASH,
1268
+ history_hash: history.hash
1269
+ };
1270
+ let select;
1271
+ if (options.mode !== "adopt") {
1272
+ const previous = ledger.last_applied;
1273
+ if (options.onlyIfChanged && previous && previous.package_version === packageVersion && previous.source_root === applied.source_root && previous.policy_hash === applied.policy_hash && previous.history_hash === applied.history_hash) {
1274
+ const previousStates = normalizeBusinesses(previous.businesses);
1275
+ const changed = new Set(OPTIONAL_BUSINESSES.filter((business) => previousStates[business] !== applied.businesses[business] && applied.businesses[business] !== void 0));
1276
+ if (!changed.size) {
1277
+ if (!currentContext(options, contextFile, generation)) {
1278
+ report.status = "stale";
1279
+ return report;
1280
+ }
1281
+ if (JSON.stringify(previous) !== JSON.stringify(applied)) {
1282
+ ledger.last_applied = applied;
1283
+ writeJson(ledgerFile, ledger);
1284
+ }
1285
+ report.managed_count = Object.keys(ledger.copies).length;
1286
+ report.status = "success";
1287
+ return report;
1288
+ }
1289
+ select = (name) => {
1290
+ const business = businessForSkill(name);
1291
+ return business !== void 0 && changed.has(business);
1292
+ };
1293
+ }
1294
+ if (ledger.last_applied) {
1295
+ delete ledger.last_applied;
1296
+ writeJson(ledgerFile, ledger);
1297
+ }
1298
+ }
1299
+ const bundled = readBundledSkills(options.skillsDirectory, select);
1300
+ const skills = new Set(bundled.map((skill) => skill.name));
1301
+ if (options.mode !== "adopt") {
1302
+ for (const name of [...history.names, ...Object.values(ledger.copies).map((copy) => copy.skill)]) {
1303
+ if (businessForSkill(name) && getSkillBusinessState(name, options.businesses) === false && (!select || select(name))) skills.add(name);
1304
+ }
1305
+ }
1306
+ const tool = options.tool ?? createPinnedSkillsTool({ env: options.env });
1307
+ const targets = [...tool.targets()].sort((a, b) => Number(b.agent === "universal") - Number(a.agent === "universal"));
1279
1308
  const operations = [];
1280
- for (const skill of skills) {
1281
- const source = path6.join(options.skillsDirectory, skill.name);
1282
- const sourceHash = skillCopyHash(source, true);
1283
- if (!sourceHash) throw new Error("Complete package Skill source is missing.");
1284
- const state = getSkillBusinessState(skill.name, options.businesses);
1309
+ for (const name of skills) {
1310
+ const state = getSkillBusinessState(name, options.businesses);
1285
1311
  if (options.mode !== "adopt" && state === void 0) continue;
1312
+ const source = path5.join(options.skillsDirectory, name);
1313
+ const sourceHash = bundled.some((skill) => skill.name === name) ? skillCopyHash(source, true) : null;
1314
+ if (!sourceHash && options.mode === "adopt") throw new Error("Complete package Skill source is missing.");
1286
1315
  for (const target of targets) {
1287
- const item = result(skill.name, target);
1288
- const pathProblem = skillPathProblem(target.directory, skill.name, options.skillsDirectory);
1316
+ const item = result(name, target);
1317
+ const pathProblem = skillPathProblem(target.directory, name, options.skillsDirectory);
1289
1318
  if (pathProblem) {
1290
1319
  report.skipped.push({ ...item, reason: pathProblem });
1291
1320
  continue;
1292
1321
  }
1322
+ const managed = ledger.copies[item.path];
1323
+ if (options.mode !== "adopt" && state === false) {
1324
+ let node;
1325
+ try {
1326
+ node = skillPathIdentity(item.path);
1327
+ } catch {
1328
+ report.skipped.push({ ...item, reason: "copy_unreadable_or_linked" });
1329
+ continue;
1330
+ }
1331
+ if (!node) {
1332
+ if (managed) delete ledger.copies[item.path];
1333
+ continue;
1334
+ }
1335
+ const legacyLink2 = node.type === "symlink" ? legacySkillLink(item.path, name, options.skillsDirectory, sourceHash ?? "", targets, ledger, true) : void 0;
1336
+ const canonical = targets.find((copy) => copy.agent === "universal");
1337
+ const historicalLink = node.type === "symlink" && canonical && directInstallerLink(item.path, path5.join(canonical.directory, name), node.link);
1338
+ const historicalCopy = history.names.has(name) && (target.agent === "universal" && node.type !== "symlink" || historicalLink);
1339
+ if (!managed && (legacyLink2 || historicalCopy)) {
1340
+ ledger.copies[item.path] = {
1341
+ skill: name,
1342
+ agent: target.agent,
1343
+ hash: sourceHash ?? "0".repeat(64),
1344
+ package_version: packageVersion
1345
+ };
1346
+ report.adopted.push(item);
1347
+ }
1348
+ const owned = ledger.copies[item.path];
1349
+ if (!owned || owned.skill !== name || owned.agent !== target.agent) {
1350
+ report.skipped.push({ ...item, reason: node.type === "symlink" ? "copy_unreadable_or_linked" : "copy_not_managed" });
1351
+ continue;
1352
+ }
1353
+ operations.push({
1354
+ action: "remove",
1355
+ skill: name,
1356
+ source,
1357
+ source_root: options.skillsDirectory,
1358
+ expected_hash: null,
1359
+ source_hash: sourceHash ?? "",
1360
+ target,
1361
+ expected_node: node,
1362
+ ...legacyLink2 ? { legacy_link: legacyLink2 } : {}
1363
+ });
1364
+ continue;
1365
+ }
1293
1366
  let actualHash;
1294
1367
  let legacyLink;
1295
1368
  try {
@@ -1297,7 +1370,7 @@ function syncBusinessSkills(options) {
1297
1370
  } catch {
1298
1371
  if (options.mode !== "adopt") legacyLink = legacySkillLink(
1299
1372
  item.path,
1300
- skill.name,
1373
+ name,
1301
1374
  options.skillsDirectory,
1302
1375
  sourceHash,
1303
1376
  targets,
@@ -1309,7 +1382,6 @@ function syncBusinessSkills(options) {
1309
1382
  }
1310
1383
  actualHash = sourceHash;
1311
1384
  }
1312
- const managed = ledger.copies[item.path];
1313
1385
  if (options.mode === "adopt") {
1314
1386
  if (actualHash === null) {
1315
1387
  if (managed) delete ledger.copies[item.path];
@@ -1319,27 +1391,23 @@ function syncBusinessSkills(options) {
1319
1391
  report.skipped.push({ ...item, reason: "copy_does_not_match_package" });
1320
1392
  continue;
1321
1393
  }
1322
- ledger.copies[item.path] = { skill: skill.name, agent: target.agent, hash: actualHash, package_version: packageVersion };
1394
+ ledger.copies[item.path] = { skill: name, agent: target.agent, hash: actualHash, package_version: packageVersion };
1323
1395
  report.adopted.push(item);
1324
1396
  continue;
1325
1397
  }
1326
- if (!legacyLink && actualHash !== null && (!managed || managed.skill !== skill.name || actualHash !== managed.hash)) {
1398
+ if (!legacyLink && actualHash !== null && (!managed || managed.skill !== name || actualHash !== managed.hash)) {
1327
1399
  report.skipped.push({ ...item, reason: managed ? "copy_modified" : "copy_not_managed" });
1328
1400
  continue;
1329
1401
  }
1330
- if (actualHash === null && state === false) {
1402
+ if (actualHash === sourceHash && !legacyLink) continue;
1403
+ if (actualHash === null && !target.installable) {
1331
1404
  if (managed) delete ledger.copies[item.path];
1332
1405
  continue;
1333
1406
  }
1334
- if (state === true && actualHash === sourceHash && !legacyLink) continue;
1335
- if (state === true && actualHash === null && !target.installable) {
1336
- if (managed) delete ledger.copies[item.path];
1337
- continue;
1338
- }
1339
- if (state === true && actualHash === null && !target.detected && !managed && !fs6.existsSync(target.directory)) continue;
1407
+ if (actualHash === null && !target.detected && !managed && !fs5.existsSync(target.directory)) continue;
1340
1408
  operations.push({
1341
- action: state ? "install" : "remove",
1342
- skill: skill.name,
1409
+ action: "install",
1410
+ skill: name,
1343
1411
  source,
1344
1412
  source_root: options.skillsDirectory,
1345
1413
  target,
@@ -1356,7 +1424,8 @@ function syncBusinessSkills(options) {
1356
1424
  if (options.mode === "adopt") {
1357
1425
  writeJson(ledgerFile, ledger);
1358
1426
  } else if (operations.length) {
1359
- operations.sort((a, b) => Number(Boolean(b.legacy_link)) - Number(Boolean(a.legacy_link)));
1427
+ operations.sort((a, b) => Number(Boolean(b.legacy_link || b.expected_node?.type === "symlink")) - Number(Boolean(a.legacy_link || a.expected_node?.type === "symlink")));
1428
+ writeJson(ledgerFile, ledger);
1360
1429
  const receipts = tool.apply(operations, { file: contextFile, generation, ledger_file: ledgerFile });
1361
1430
  if (receipts.length !== operations.length) throw new Error("Skills adapter returned incomplete receipts.");
1362
1431
  for (let index = 0; index < operations.length; index++) {
@@ -1367,7 +1436,7 @@ function syncBusinessSkills(options) {
1367
1436
  if (receipt.status === "skipped") report.skipped.push(item);
1368
1437
  else if (receipt.status !== "success") report.failed.push(item);
1369
1438
  else if (operation.action === "remove") {
1370
- if (skillCopyHash(item.path) !== null) {
1439
+ if (skillPathIdentity(item.path) !== null) {
1371
1440
  report.failed.push({ ...item, reason: "removal_not_verified" });
1372
1441
  continue;
1373
1442
  }
@@ -1387,6 +1456,10 @@ function syncBusinessSkills(options) {
1387
1456
  } else writeJson(ledgerFile, ledger);
1388
1457
  report.managed_count = Object.keys(ledger.copies).length;
1389
1458
  report.status = !currentContext(options, contextFile, generation) ? "stale" : report.skipped.length || report.failed.length ? "partial" : "success";
1459
+ if (options.mode !== "adopt" && report.status === "success") {
1460
+ ledger.last_applied = applied;
1461
+ writeJson(ledgerFile, ledger);
1462
+ }
1390
1463
  return report;
1391
1464
  } catch {
1392
1465
  report.status = report.installed.length || report.removed.length || report.adopted.length ? "partial" : "failed";
@@ -1396,6 +1469,162 @@ function syncBusinessSkills(options) {
1396
1469
  }
1397
1470
  }
1398
1471
 
1472
+ // src/core/business-skill-refresh.ts
1473
+ function beginBusinessSkillRefresh(host, token, enabled = true) {
1474
+ try {
1475
+ if (!enabled) return void 0;
1476
+ const normalized = normalizeUrl(host);
1477
+ const isCurrentContext = () => {
1478
+ try {
1479
+ return canManageGlobalSkills() && normalizeUrl(getActiveHost()) === normalized && peekCliToken(normalized) === token;
1480
+ } catch {
1481
+ return false;
1482
+ }
1483
+ };
1484
+ if (!isCurrentContext()) return void 0;
1485
+ const identity = { host: normalized, tokenFingerprint: crypto.createHash("sha256").update(token).digest("hex") };
1486
+ return { ...identity, generation: reserveBusinessSkillContext(identity), isCurrentContext };
1487
+ } catch {
1488
+ return void 0;
1489
+ }
1490
+ }
1491
+ function isBusinessSkillRefreshCurrent(refresh) {
1492
+ return !refresh || isBusinessSkillContextCurrent(refresh);
1493
+ }
1494
+ function syncRefreshedBusinessSkills(refresh, businesses) {
1495
+ if (!refresh || !isBusinessSkillRefreshCurrent(refresh)) return;
1496
+ const states = normalizeBusinesses(businesses);
1497
+ if (!Object.keys(states).length) return;
1498
+ try {
1499
+ const pkg = getLocalCliPackageInfo();
1500
+ const options = { ...refresh, skillsDirectory: path6.join(pkg.root, "skills"), businesses: states, packageVersion: pkg.version };
1501
+ if (!fs6.existsSync(path6.join(getConfigDir(), "business-skills.json"))) {
1502
+ const adoption = syncBusinessSkills({ ...options, mode: "adopt" });
1503
+ if (["failed", "busy", "stale"].includes(adoption.status)) {
1504
+ if (adoption.status !== "stale") process.stderr.write("[ae-cli] Skills could not be synchronized. Retry: ae-cli config refresh\n");
1505
+ return;
1506
+ }
1507
+ }
1508
+ const result2 = syncBusinessSkills({ ...options, onlyIfChanged: true });
1509
+ if (!["success", "stale"].includes(result2.status)) {
1510
+ process.stderr.write("[ae-cli] Some Skills could not be synchronized. Retry: ae-cli config refresh\n");
1511
+ }
1512
+ } catch {
1513
+ process.stderr.write("[ae-cli] Skills could not be synchronized. Retry: ae-cli config refresh\n");
1514
+ }
1515
+ }
1516
+
1517
+ // src/core/business-config.ts
1518
+ var BUSINESS_CONFIG_TTL_MS = 10 * 60 * 1e3;
1519
+ var UNAVAILABLE_TTL_MS = 5 * 60 * 1e3;
1520
+ function cachePath() {
1521
+ return path7.join(getConfigDir(), "business-config.json");
1522
+ }
1523
+ function cacheKey(host, token) {
1524
+ return `${normalizeUrl(host)}#${crypto2.createHash("sha256").update(token).digest("hex")}`;
1525
+ }
1526
+ function readStore() {
1527
+ try {
1528
+ const value = JSON.parse(fs7.readFileSync(cachePath(), "utf8"));
1529
+ if (value?.entries && typeof value.entries === "object" && !Array.isArray(value.entries)) return value;
1530
+ } catch {
1531
+ }
1532
+ return { entries: {} };
1533
+ }
1534
+ function remember(host, token, entry) {
1535
+ const store = readStore();
1536
+ store.entries[cacheKey(host, token)] = entry;
1537
+ const target = cachePath();
1538
+ const temporary = `${target}.${process.pid}.${crypto2.randomBytes(6).toString("hex")}.tmp`;
1539
+ try {
1540
+ fs7.mkdirSync(path7.dirname(target), { recursive: true });
1541
+ fs7.writeFileSync(temporary, JSON.stringify(store), { encoding: "utf8", mode: 384 });
1542
+ fs7.renameSync(temporary, target);
1543
+ fs7.chmodSync(target, 384);
1544
+ } catch {
1545
+ try {
1546
+ fs7.rmSync(temporary, { force: true });
1547
+ } catch {
1548
+ }
1549
+ }
1550
+ }
1551
+ function rememberBusinessConfig(host, token, businesses, now = Date.now()) {
1552
+ remember(host, token, { businesses: normalizeBusinesses(businesses), fetchedAt: now });
1553
+ }
1554
+ function peekBusinessConfig(host, token, now = Date.now()) {
1555
+ const entry = readStore().entries[cacheKey(host, token)];
1556
+ if (entry?.unavailableAt !== void 0 && now >= entry.unavailableAt && now - entry.unavailableAt < UNAVAILABLE_TTL_MS) return {};
1557
+ if (!entry || !Number.isFinite(entry.fetchedAt) || now < entry.fetchedAt || now - entry.fetchedAt >= BUSINESS_CONFIG_TTL_MS) return void 0;
1558
+ return normalizeBusinesses(entry.businesses);
1559
+ }
1560
+ function readBusinessConfig(host, token) {
1561
+ const entry = readStore().entries[cacheKey(host, token)];
1562
+ return entry && Number.isFinite(entry.fetchedAt) && entry.fetchedAt > 0 ? normalizeBusinesses(entry.businesses) : void 0;
1563
+ }
1564
+ function readCurrentBusinessConfig(hostOverride) {
1565
+ try {
1566
+ if (isSandboxExecutionContext()) return {};
1567
+ const host = hostOverride || getActiveHost();
1568
+ if (!host) return {};
1569
+ const token = peekCliToken(host);
1570
+ return token ? readBusinessConfig(host, token) ?? {} : {};
1571
+ } catch {
1572
+ return {};
1573
+ }
1574
+ }
1575
+ async function resolveBusinessConfig(host, token, fetchRemote, now = Date.now(), synchronizeSkills = true) {
1576
+ const cached = peekBusinessConfig(host, token, now);
1577
+ if (cached !== void 0) return cached;
1578
+ const refresh = beginBusinessSkillRefresh(host, token, synchronizeSkills);
1579
+ const config = await fetchRemote().catch(() => null);
1580
+ if (!isBusinessSkillRefreshCurrent(refresh)) return peekBusinessConfig(host, token) ?? {};
1581
+ if (!config) {
1582
+ const previous = readStore().entries[cacheKey(host, token)];
1583
+ remember(host, token, {
1584
+ businesses: normalizeBusinesses(previous?.businesses),
1585
+ fetchedAt: previous?.fetchedAt ?? 0,
1586
+ unavailableAt: now
1587
+ });
1588
+ return {};
1589
+ }
1590
+ const businesses = normalizeBusinesses(config.businesses);
1591
+ rememberBusinessConfig(host, token, businesses, now);
1592
+ syncRefreshedBusinessSkills(refresh, config.businesses);
1593
+ return businesses;
1594
+ }
1595
+ var BusinessDisabledError = class extends PermissionError {
1596
+ constructor(business) {
1597
+ super(
1598
+ `The '${business}' business is not enabled for the current environment.`,
1599
+ "BUSINESS_NOT_ENABLED",
1600
+ "Contact your administrator if this business should be enabled, then run: ae-cli config refresh"
1601
+ );
1602
+ this.business = business;
1603
+ this.name = "BusinessDisabledError";
1604
+ }
1605
+ business;
1606
+ };
1607
+ async function readBusinessConfigForExecution(hostOverride, synchronizeSkills = !hostOverride) {
1608
+ try {
1609
+ if (isSandboxExecutionContext()) return {};
1610
+ const host = hostOverride || getActiveHost();
1611
+ if (!host) return {};
1612
+ const token = peekCliToken(host);
1613
+ if (!token) return {};
1614
+ return await resolveBusinessConfig(host, token, async () => {
1615
+ const { fetchCliConfig: fetchCliConfig2 } = await import("./compat-check-ZJNCMNQV.js");
1616
+ return fetchCliConfig2(host, token);
1617
+ }, Date.now(), synchronizeSkills);
1618
+ } catch {
1619
+ return {};
1620
+ }
1621
+ }
1622
+ async function assertBusinessEnabled(business, hostOverride, synchronizeSkills = !hostOverride) {
1623
+ if (business && (await readBusinessConfigForExecution(hostOverride, synchronizeSkills))[business] === false) {
1624
+ throw new BusinessDisabledError(business);
1625
+ }
1626
+ }
1627
+
1399
1628
  // src/core/installation.ts
1400
1629
  function distribution(packageName) {
1401
1630
  if (packageName === "@thinkingai/ae-cli") return { registry: "https://registry.npmjs.org", repository: "ThinkingAIAgenticEngine/ae-cli" };
@@ -1431,7 +1660,7 @@ function failInstallation(report, stage, message, cause = "validation") {
1431
1660
  function installPlan(packageName, version, root = "<npm-root>") {
1432
1661
  const config = distribution(packageName);
1433
1662
  const target = exactVersion(version);
1434
- const executable = path7.join(root, packageName, "bin", "ae-cli.js");
1663
+ const executable = path8.join(root, packageName, "bin", "ae-cli.js");
1435
1664
  return [
1436
1665
  `npm install -g ${packageName}@${target} --registry=${config.registry}`,
1437
1666
  `node ${JSON.stringify(executable)} install`
@@ -1440,7 +1669,7 @@ function installPlan(packageName, version, root = "<npm-root>") {
1440
1669
  function currentSkillIdentity() {
1441
1670
  const host = getActiveHost();
1442
1671
  const token = host ? peekCliToken(host) : void 0;
1443
- return { host, tokenFingerprint: token ? crypto2.createHash("sha256").update(token).digest("hex") : "" };
1672
+ return { host, tokenFingerprint: token ? crypto3.createHash("sha256").update(token).digest("hex") : "" };
1444
1673
  }
1445
1674
  function skipGlobalSkillReason() {
1446
1675
  try {
@@ -1451,27 +1680,27 @@ function skipGlobalSkillReason() {
1451
1680
  }
1452
1681
  function readPackage(root) {
1453
1682
  try {
1454
- return JSON.parse(fs7.readFileSync(path7.join(root, "package.json"), "utf8"));
1683
+ return JSON.parse(fs8.readFileSync(path8.join(root, "package.json"), "utf8"));
1455
1684
  } catch {
1456
1685
  return null;
1457
1686
  }
1458
1687
  }
1459
1688
  function linked(root) {
1460
1689
  try {
1461
- return fs7.lstatSync(root).isSymbolicLink();
1690
+ return fs8.lstatSync(root).isSymbolicLink();
1462
1691
  } catch {
1463
1692
  return false;
1464
1693
  }
1465
1694
  }
1466
1695
  function cliBinBelongsToPackage(bin, packageRoot, platform) {
1467
- const entry = fs7.realpathSync(path7.join(packageRoot, "bin", "ae-cli.js"));
1468
- if (platform !== "win32") return fs7.realpathSync(bin) === entry;
1469
- const shim = fs7.readFileSync(bin, "utf8");
1696
+ const entry = fs8.realpathSync(path8.join(packageRoot, "bin", "ae-cli.js"));
1697
+ if (platform !== "win32") return fs8.realpathSync(bin) === entry;
1698
+ const shim = fs8.readFileSync(bin, "utf8");
1470
1699
  const targets = [...shim.matchAll(/"%(?:dp0%|~dp0)[\\/]([^"\r\n]+)"/gi)];
1471
1700
  return targets.some(([, relative]) => {
1472
1701
  try {
1473
- const target = path7.resolve(path7.dirname(bin), relative.replace(/\\/g, path7.sep));
1474
- return fs7.realpathSync(target).toLowerCase() === entry.toLowerCase();
1702
+ const target = path8.resolve(path8.dirname(bin), relative.replace(/\\/g, path8.sep));
1703
+ return fs8.realpathSync(target).toLowerCase() === entry.toLowerCase();
1475
1704
  } catch {
1476
1705
  return false;
1477
1706
  }
@@ -1512,9 +1741,9 @@ function runInstallation(options = {}) {
1512
1741
  const prefixResult = runner(npm, ["prefix", "-g"], 15e3);
1513
1742
  const globalRoot = rootResult.stdout.trim();
1514
1743
  const prefix = prefixResult.stdout.trim();
1515
- if (!commandSucceeded(rootResult) || !commandSucceeded(prefixResult) || !path7.isAbsolute(globalRoot) || !path7.isAbsolute(prefix) || /[\r\n]/.test(globalRoot + prefix)) return failInstallation(report, stage, "Cannot resolve npm global root and prefix. Check npm configuration.");
1516
- const packageRoot = path7.join(globalRoot, packageName);
1517
- const bin = platform === "win32" ? path7.join(prefix, "ae-cli.cmd") : path7.join(prefix, "bin", "ae-cli");
1744
+ if (!commandSucceeded(rootResult) || !commandSucceeded(prefixResult) || !path8.isAbsolute(globalRoot) || !path8.isAbsolute(prefix) || /[\r\n]/.test(globalRoot + prefix)) return failInstallation(report, stage, "Cannot resolve npm global root and prefix. Check npm configuration.");
1745
+ const packageRoot = path8.join(globalRoot, packageName);
1746
+ const bin = platform === "win32" ? path8.join(prefix, "ae-cli.cmd") : path8.join(prefix, "bin", "ae-cli");
1518
1747
  report.cli.path = bin;
1519
1748
  const env = options.env ?? process.env;
1520
1749
  const installedBefore = readPackage(packageRoot);
@@ -1537,8 +1766,8 @@ function runInstallation(options = {}) {
1537
1766
  };
1538
1767
  const generation = reserveBusinessSkillContext({ ...identity, stateDirectory });
1539
1768
  context = { ...identity, stateDirectory, generation, isCurrentContext };
1540
- if (!fs7.existsSync(path7.join(stateDirectory, "business-skills.json")) && installedBefore?.name === packageName) {
1541
- const previousSkills = path7.join(packageRoot, "skills");
1769
+ if (!fs8.existsSync(path8.join(stateDirectory, "business-skills.json")) && installedBefore?.name === packageName) {
1770
+ const previousSkills = path8.join(packageRoot, "skills");
1542
1771
  try {
1543
1772
  readBundledSkills(previousSkills);
1544
1773
  syncSkills({ ...context, skillsDirectory: previousSkills, businesses: {}, mode: "adopt", packageVersion: installedBefore.version });
@@ -1550,7 +1779,7 @@ function runInstallation(options = {}) {
1550
1779
  return failInstallation(report, "skills_local", "The active environment changed before installation. Re-run install or update for the current environment.");
1551
1780
  }
1552
1781
  }
1553
- if (options.skipCliInstall || installedBefore?.name === packageName && installedBefore.version === target && fs7.existsSync(bin)) {
1782
+ if (options.skipCliInstall || installedBefore?.name === packageName && installedBefore.version === target && fs8.existsSync(bin)) {
1554
1783
  report.cli.action = "skipped";
1555
1784
  progress("[ae-cli] [2/4] Verifying the existing CLI...");
1556
1785
  } else {
@@ -1563,16 +1792,16 @@ function runInstallation(options = {}) {
1563
1792
  stage = "package_validation";
1564
1793
  const installed = readPackage(packageRoot);
1565
1794
  if (installed?.name !== packageName || installed.version !== target) return failInstallation(report, stage, "Installed CLI package identity or version does not match the requested distribution.");
1566
- if (!fs7.existsSync(bin)) return failInstallation(report, stage, "npm did not create the global ae-cli executable. Enable npm bin-links, reinstall, and add the global executable directory to PATH.");
1795
+ if (!fs8.existsSync(bin)) return failInstallation(report, stage, "npm did not create the global ae-cli executable. Enable npm bin-links, reinstall, and add the global executable directory to PATH.");
1567
1796
  if (!cliBinBelongsToPackage(bin, packageRoot, platform)) return failInstallation(report, stage, "The global executable does not belong to the installed CLI package.");
1568
1797
  const versionResult = runner(bin, ["--version"], 15e3);
1569
1798
  if (!commandSucceeded(versionResult) || versionResult.stdout.trim() !== target) return failInstallation(report, stage, "ae-cli --version did not return the requested version. Refresh the shell command cache and check npm bin links.");
1570
- report.cli.entrypoint = fs7.realpathSync(path7.join(packageRoot, "bin", "ae-cli.js"));
1799
+ report.cli.entrypoint = fs8.realpathSync(path8.join(packageRoot, "bin", "ae-cli.js"));
1571
1800
  report.cli.verified = true;
1572
1801
  const pathKey = platform === "win32" ? Object.keys(env).find((key) => key.toLowerCase() === "path") : "PATH";
1573
- const installedPathBin = (env[pathKey ?? "PATH"] ?? "").split(platform === "win32" ? ";" : path7.delimiter).filter(Boolean).map((dir) => path7.join(dir.replace(/^"(.*)"$/, "$1"), platform === "win32" ? "ae-cli.cmd" : "ae-cli")).find((file) => fs7.existsSync(file) && !file.includes(`${path7.sep}_npx${path7.sep}`));
1574
- if (!installedPathBin || fs7.realpathSync(installedPathBin) !== fs7.realpathSync(bin)) {
1575
- report.cli.warnings.push(`Add ${path7.dirname(bin)} to the front of PATH and refresh the shell command cache. The absolute executable was verified.`);
1802
+ const installedPathBin = (env[pathKey ?? "PATH"] ?? "").split(platform === "win32" ? ";" : path8.delimiter).filter(Boolean).map((dir) => path8.join(dir.replace(/^"(.*)"$/, "$1"), platform === "win32" ? "ae-cli.cmd" : "ae-cli")).find((file) => fs8.existsSync(file) && !file.includes(`${path8.sep}_npx${path8.sep}`));
1803
+ if (!installedPathBin || fs8.realpathSync(installedPathBin) !== fs8.realpathSync(bin)) {
1804
+ report.cli.warnings.push(`Add ${path8.dirname(bin)} to the front of PATH and refresh the shell command cache. The absolute executable was verified.`);
1576
1805
  report.next_steps.push(`Use the verified executable at ${bin}, or correct PATH before invoking ae-cli.`);
1577
1806
  }
1578
1807
  if (skipSkills) {
@@ -1581,7 +1810,7 @@ function runInstallation(options = {}) {
1581
1810
  progress(`[ae-cli] [3/4] ${skipSkills}`);
1582
1811
  } else if (context) {
1583
1812
  stage = "skills_local";
1584
- const skillsPath = path7.join(packageRoot, "skills");
1813
+ const skillsPath = path8.join(packageRoot, "skills");
1585
1814
  const skills = readBundledSkills(skillsPath);
1586
1815
  if (!isBusinessSkillContextCurrent(context)) {
1587
1816
  return failInstallation(report, stage, "The active environment changed during CLI installation. Re-run install or update to synchronize its Skills.");
@@ -1644,14 +1873,14 @@ var LOCK_STALE_MS = 10 * 60 * 1e3;
1644
1873
  var SYNC_STATE_FILE = "version-sync.json";
1645
1874
  var SYNC_LOCK_FILE = "version-sync.lock";
1646
1875
  function syncStatePath() {
1647
- return path8.join(getConfigDir(), SYNC_STATE_FILE);
1876
+ return path9.join(getConfigDir(), SYNC_STATE_FILE);
1648
1877
  }
1649
1878
  function syncLockPath() {
1650
- return path8.join(getConfigDir(), SYNC_LOCK_FILE);
1879
+ return path9.join(getConfigDir(), SYNC_LOCK_FILE);
1651
1880
  }
1652
1881
  function readSyncStore() {
1653
1882
  try {
1654
- const raw = JSON.parse(fs8.readFileSync(syncStatePath(), "utf8"));
1883
+ const raw = JSON.parse(fs9.readFileSync(syncStatePath(), "utf8"));
1655
1884
  if (raw && typeof raw === "object" && raw.hosts && typeof raw.hosts === "object") {
1656
1885
  return raw;
1657
1886
  }
@@ -1661,8 +1890,8 @@ function readSyncStore() {
1661
1890
  }
1662
1891
  function writeSyncStore(store) {
1663
1892
  try {
1664
- fs8.mkdirSync(getConfigDir(), { recursive: true });
1665
- fs8.writeFileSync(syncStatePath(), JSON.stringify(store, null, 2));
1893
+ fs9.mkdirSync(getConfigDir(), { recursive: true });
1894
+ fs9.writeFileSync(syncStatePath(), JSON.stringify(store, null, 2));
1666
1895
  } catch {
1667
1896
  }
1668
1897
  }
@@ -1766,20 +1995,20 @@ function friendlyVersionSyncFailure(result2) {
1766
1995
  return `Version synchronization failed at ${result2.stage}.`;
1767
1996
  }
1768
1997
  function acquireInstallLock(now) {
1769
- fs8.mkdirSync(getConfigDir(), { recursive: true });
1998
+ fs9.mkdirSync(getConfigDir(), { recursive: true });
1770
1999
  const file = syncLockPath();
1771
2000
  try {
1772
- return fs8.openSync(file, "wx");
2001
+ return fs9.openSync(file, "wx");
1773
2002
  } catch {
1774
2003
  try {
1775
- const age = now.getTime() - fs8.statSync(file).mtimeMs;
2004
+ const age = now.getTime() - fs9.statSync(file).mtimeMs;
1776
2005
  if (age >= LOCK_STALE_MS) {
1777
- fs8.unlinkSync(file);
1778
- return fs8.openSync(file, "wx");
2006
+ fs9.unlinkSync(file);
2007
+ return fs9.openSync(file, "wx");
1779
2008
  }
1780
2009
  } catch {
1781
2010
  try {
1782
- return fs8.openSync(file, "wx");
2011
+ return fs9.openSync(file, "wx");
1783
2012
  } catch {
1784
2013
  return null;
1785
2014
  }
@@ -1789,11 +2018,11 @@ function acquireInstallLock(now) {
1789
2018
  }
1790
2019
  function releaseInstallLock(fd) {
1791
2020
  try {
1792
- fs8.closeSync(fd);
2021
+ fs9.closeSync(fd);
1793
2022
  } catch {
1794
2023
  }
1795
2024
  try {
1796
- fs8.unlinkSync(syncLockPath());
2025
+ fs9.unlinkSync(syncLockPath());
1797
2026
  } catch {
1798
2027
  }
1799
2028
  }
@@ -1854,21 +2083,21 @@ function autoSyncDirection(current, expected) {
1854
2083
  }
1855
2084
 
1856
2085
  // src/core/feature-config.ts
1857
- import crypto3 from "crypto";
1858
- import fs9 from "fs";
1859
- import path9 from "path";
2086
+ import crypto4 from "crypto";
2087
+ import fs10 from "fs";
2088
+ import path10 from "path";
1860
2089
  var FEATURE_TTL_MS = 24 * 60 * 60 * 1e3;
1861
2090
  var UNAVAILABLE_TTL_MS2 = 5 * 60 * 1e3;
1862
2091
  function cachePath2() {
1863
- return path9.join(getConfigDir(), "feature-config.json");
2092
+ return path10.join(getConfigDir(), "feature-config.json");
1864
2093
  }
1865
2094
  function cacheKey2(host, token) {
1866
- const fingerprint = crypto3.createHash("sha256").update(token).digest("hex");
2095
+ const fingerprint = crypto4.createHash("sha256").update(token).digest("hex");
1867
2096
  return `${normalizeUrl(host)}#${fingerprint}`;
1868
2097
  }
1869
2098
  function readStore2() {
1870
2099
  try {
1871
- const value = JSON.parse(fs9.readFileSync(cachePath2(), "utf8"));
2100
+ const value = JSON.parse(fs10.readFileSync(cachePath2(), "utf8"));
1872
2101
  return value?.entries && typeof value.entries === "object" ? value : { entries: {} };
1873
2102
  } catch {
1874
2103
  return { entries: {} };
@@ -1876,15 +2105,15 @@ function readStore2() {
1876
2105
  }
1877
2106
  function writeStore(store) {
1878
2107
  const target = cachePath2();
1879
- const temp = `${target}.${process.pid}.${crypto3.randomBytes(6).toString("hex")}.tmp`;
2108
+ const temp = `${target}.${process.pid}.${crypto4.randomBytes(6).toString("hex")}.tmp`;
1880
2109
  try {
1881
- fs9.mkdirSync(path9.dirname(target), { recursive: true });
1882
- fs9.writeFileSync(temp, JSON.stringify(store), { encoding: "utf8", mode: 384 });
1883
- fs9.renameSync(temp, target);
1884
- fs9.chmodSync(target, 384);
2110
+ fs10.mkdirSync(path10.dirname(target), { recursive: true });
2111
+ fs10.writeFileSync(temp, JSON.stringify(store), { encoding: "utf8", mode: 384 });
2112
+ fs10.renameSync(temp, target);
2113
+ fs10.chmodSync(target, 384);
1885
2114
  } catch {
1886
2115
  try {
1887
- fs9.rmSync(temp, { force: true });
2116
+ fs10.rmSync(temp, { force: true });
1888
2117
  } catch {
1889
2118
  }
1890
2119
  }
@@ -1897,13 +2126,25 @@ function remember2(host, token, entry) {
1897
2126
  function rememberKbAutoDiscoveryFeature(host, token, enabled) {
1898
2127
  remember2(host, token, { enabled, available: true, fetchedAt: Date.now() });
1899
2128
  }
1900
- async function resolveKbAutoDiscoveryFeature(host, token, fetchRemote) {
2129
+ function peekKbAutoDiscoveryFeature(host, token) {
2130
+ const entry = readStore2().entries[cacheKey2(host, token)];
2131
+ const ttl = entry?.available ? FEATURE_TTL_MS : UNAVAILABLE_TTL_MS2;
2132
+ if (!entry || !entry.available || Date.now() < entry.fetchedAt || Date.now() - entry.fetchedAt >= ttl) {
2133
+ return void 0;
2134
+ }
2135
+ return entry.enabled;
2136
+ }
2137
+ async function resolveKbAutoDiscoveryFeature(host, token, fetchRemote, isCurrent = () => true) {
1901
2138
  const entry = readStore2().entries[cacheKey2(host, token)];
1902
2139
  const ttl = entry?.available ? FEATURE_TTL_MS : UNAVAILABLE_TTL_MS2;
1903
2140
  if (entry && Date.now() >= entry.fetchedAt && Date.now() - entry.fetchedAt < ttl) {
1904
2141
  return { enabled: entry.enabled, source: entry.available ? "cache" : "unavailable" };
1905
2142
  }
1906
2143
  const remote = await fetchRemote().catch(() => null);
2144
+ if (!isCurrent()) {
2145
+ const latest = peekKbAutoDiscoveryFeature(host, token);
2146
+ return latest === void 0 ? { enabled: false, source: "unavailable" } : { enabled: latest, source: "cache" };
2147
+ }
1907
2148
  if (!remote) {
1908
2149
  remember2(host, token, { enabled: false, available: false, fetchedAt: Date.now() });
1909
2150
  return { enabled: false, source: "unavailable" };
@@ -1919,13 +2160,13 @@ var NOTIFY_INTERVAL_MS = 24 * 60 * 60 * 1e3;
1919
2160
  var FETCH_TIMEOUT_MS = 3e3;
1920
2161
  var CLI_CONFIG_PATH = "/v1/ta/cli/config";
1921
2162
  function cacheFilePath() {
1922
- return path10.join(getConfigDir(), "compat-check.json");
2163
+ return path11.join(getConfigDir(), "compat-check.json");
1923
2164
  }
1924
2165
  function readStore3() {
1925
2166
  try {
1926
2167
  const file = cacheFilePath();
1927
- if (!fs10.existsSync(file)) return { hosts: {} };
1928
- const raw = JSON.parse(fs10.readFileSync(file, "utf8"));
2168
+ if (!fs11.existsSync(file)) return { hosts: {} };
2169
+ const raw = JSON.parse(fs11.readFileSync(file, "utf8"));
1929
2170
  if (!raw || typeof raw !== "object" || !raw.hosts) return { hosts: {} };
1930
2171
  return raw;
1931
2172
  } catch {
@@ -1935,8 +2176,8 @@ function readStore3() {
1935
2176
  function writeStore2(store) {
1936
2177
  try {
1937
2178
  const dir = getConfigDir();
1938
- if (!fs10.existsSync(dir)) fs10.mkdirSync(dir, { recursive: true });
1939
- fs10.writeFileSync(cacheFilePath(), JSON.stringify(store, null, 2));
2179
+ if (!fs11.existsSync(dir)) fs11.mkdirSync(dir, { recursive: true });
2180
+ fs11.writeFileSync(cacheFilePath(), JSON.stringify(store, null, 2));
1940
2181
  } catch {
1941
2182
  }
1942
2183
  }
@@ -2075,7 +2316,7 @@ function setUpdateNotice(pkg, expected, cluster, verdict, state, stage, message)
2075
2316
  message: message ?? `Current ae-cli is ${pkg.version}; this host requires ${expected}. Run: ae-cli update`
2076
2317
  };
2077
2318
  }
2078
- async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2319
+ async function refreshAndMaybeNotify(host, pkg, allowAutoSync, synchronizeSkills) {
2079
2320
  const token = peekCliToken(host);
2080
2321
  if (!token) return { status: "continue" };
2081
2322
  const store = readStore3();
@@ -2085,10 +2326,13 @@ async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2085
2326
  let cluster = existing?.clusterVersion;
2086
2327
  let fetchedAt = existing?.lastFetchedAt;
2087
2328
  if (isCompatCacheStale(existing)) {
2329
+ const refresh = beginBusinessSkillRefresh(host, token, synchronizeSkills && allowAutoSync);
2088
2330
  const remote = await fetchCliConfig(host, token);
2331
+ if (!isBusinessSkillRefreshCurrent(refresh)) return { status: "continue" };
2089
2332
  if (remote) {
2090
2333
  rememberKbAutoDiscoveryFeature(host, token, remote.projectSemanticKbAutoDiscovery ?? false);
2091
2334
  rememberBusinessConfig(host, token, remote.businesses);
2335
+ syncRefreshedBusinessSkills(refresh, remote.businesses);
2092
2336
  }
2093
2337
  if (!remote?.aeCliVersion) {
2094
2338
  return { status: "continue" };
@@ -2133,7 +2377,7 @@ async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2133
2377
  return false;
2134
2378
  }
2135
2379
  };
2136
- const context = isCurrentLocalIdentity() ? { host, tokenFingerprint: createHash2("sha256").update(token).digest("hex") } : void 0;
2380
+ const context = isCurrentLocalIdentity() ? { host, tokenFingerprint: createHash3("sha256").update(token).digest("hex") } : void 0;
2137
2381
  const generation = context ? reserveBusinessSkillContext(context) : void 0;
2138
2382
  const confirmed = await fetchCliConfig(host, token);
2139
2383
  if (context && generation && !isBusinessSkillContextCurrent({
@@ -2144,6 +2388,9 @@ async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2144
2388
  if (confirmed) {
2145
2389
  rememberKbAutoDiscoveryFeature(host, token, confirmed.projectSemanticKbAutoDiscovery ?? false);
2146
2390
  rememberBusinessConfig(host, token, confirmed.businesses);
2391
+ if (context && generation && synchronizeSkills) {
2392
+ syncRefreshedBusinessSkills({ ...context, generation, isCurrentContext: isCurrentLocalIdentity }, confirmed.businesses);
2393
+ }
2147
2394
  }
2148
2395
  if (confirmed?.aeCliVersion) {
2149
2396
  expected = confirmed.aeCliVersion;
@@ -2243,7 +2490,7 @@ async function runHostCompatCheck(pkg, hostOverride, argv = process.argv) {
2243
2490
  const host = hostOverride || getActiveHost();
2244
2491
  if (!host) return { status: "continue" };
2245
2492
  try {
2246
- return await refreshAndMaybeNotify(host, pkg, !shouldSkipAutoSync(argv));
2493
+ return await refreshAndMaybeNotify(host, pkg, !shouldSkipAutoSync(argv), !hostOverride);
2247
2494
  } catch {
2248
2495
  return { status: "continue" };
2249
2496
  }
@@ -2259,14 +2506,17 @@ export {
2259
2506
  businessForCommand,
2260
2507
  businessForCapability,
2261
2508
  canManageGlobalSkills,
2509
+ reserveBusinessSkillContext,
2510
+ isBusinessSkillContextCurrent,
2511
+ syncBusinessSkills,
2512
+ beginBusinessSkillRefresh,
2513
+ isBusinessSkillRefreshCurrent,
2514
+ syncRefreshedBusinessSkills,
2262
2515
  rememberBusinessConfig,
2263
2516
  readCurrentBusinessConfig,
2264
2517
  BusinessDisabledError,
2265
2518
  readBusinessConfigForExecution,
2266
2519
  assertBusinessEnabled,
2267
- reserveBusinessSkillContext,
2268
- isBusinessSkillContextCurrent,
2269
- syncBusinessSkills,
2270
2520
  newInstallationReport,
2271
2521
  failInstallation,
2272
2522
  recordVersionSyncResult,