@thinkingai/ae-cli 6.0.58 → 6.0.60

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 (253) hide show
  1. package/README.md +10 -5
  2. package/README.zh.md +10 -5
  3. package/bin/ai-monitor.js +2 -0
  4. package/dist/ai-monitor-FCXSLHAP.js +32 -0
  5. package/dist/ai-monitor.js +135 -0
  6. package/dist/{auth-A5OO4VS4.js → auth-ATK2SLEV.js} +10 -9
  7. package/dist/{automation-FD2QZUP6.js → automation-FLCPFMN4.js} +4 -4
  8. package/dist/{capability-SKI4GHF4.js → capability-6KTSOI7L.js} +31 -35
  9. package/dist/{chunk-UYJMEHAF.js → chunk-2ETRY2CU.js} +15 -15
  10. package/dist/{chunk-QWSA3EOD.js → chunk-5E7MTTFN.js} +2 -2
  11. package/dist/{chunk-JSBLCLFE.js → chunk-5M5LBRR3.js} +1 -1
  12. package/dist/chunk-6M7ZEDT2.js +182 -0
  13. package/dist/{chunk-KPQY44JQ.js → chunk-AWW2T2WL.js} +3 -0
  14. package/dist/chunk-AXTO4FTM.js +1285 -0
  15. package/dist/{chunk-HQCY3QCA.js → chunk-BEYLCUZX.js} +17 -12
  16. package/dist/chunk-CF6JTT2U.js +64 -0
  17. package/dist/{chunk-VDICGXCY.js → chunk-F2VFZUGG.js} +2 -2
  18. package/dist/{chunk-K2Z7QHDR.js → chunk-HSZAIPUX.js} +47 -12
  19. package/dist/{chunk-SOSFRU3O.js → chunk-HTZ2MLYA.js} +47 -21
  20. package/dist/{chunk-AWVZTN2B.js → chunk-HVMCPKOZ.js} +1 -1
  21. package/dist/{chunk-E25OSZLJ.js → chunk-KTJXD27G.js} +2 -2
  22. package/dist/{chunk-GBSACKFB.js → chunk-LOR4IA26.js} +564 -314
  23. package/dist/{chunk-YVG6QD3V.js → chunk-P7QDCWJ6.js} +98 -7
  24. package/dist/{chunk-EEARZNHE.js → chunk-SDKW6LYE.js} +88 -36
  25. package/dist/{chunk-WMDO53YK.js → chunk-VJUXKVRE.js} +1 -1
  26. package/dist/chunk-VRMGHQKE.js +556 -0
  27. package/dist/{compat-check-WFEKVLTH.js → compat-check-XD2U7PZ2.js} +2 -2
  28. package/dist/{config-U4I7X25P.js → config-U3GDWU6E.js} +25 -12
  29. package/dist/{context-CDB5H5PD.js → context-YAQG6YQC.js} +2 -2
  30. package/dist/{evaluation-LR4YDYWL.js → evaluation-2JSF4V47.js} +13 -158
  31. package/dist/index.js +84 -579
  32. package/dist/{memory-SNFR5M23.js → memory-WEB27VI6.js} +7 -7
  33. package/dist/{metadata-6QM6EED5.js → metadata-7FYE4234.js} +7 -7
  34. package/dist/{model-KEVCEXWD.js → model-T7H7Q6BG.js} +2 -2
  35. package/dist/{personal-semantic-preference-7VXQPP2N.js → personal-semantic-preference-O6VXM74A.js} +6 -6
  36. package/dist/{project-semantic-PSEPYH2L.js → project-semantic-2GGFJWW6.js} +15 -13
  37. package/dist/{sync-22ACDK5Z.js → sync-ULBB7WO5.js} +4 -4
  38. package/dist/{te-agent-BJ36B4QI.js → te-agent-6RMF7LUV.js} +5 -5
  39. package/dist/{te-analysis-WQ6D6YG4.js → te-analysis-HSYC7GNV.js} +382 -193
  40. package/dist/{te-community-VRWMFGI6.js → te-community-FLKZGQKB.js} +9 -9
  41. package/dist/{te-dataops-YTLFTTW7.js → te-dataops-OQQGTCUA.js} +3 -3
  42. package/dist/{te-engage-V2QW7TIC.js → te-engage-RIEBHL5T.js} +9 -9
  43. package/dist/{te-kb-4AQLISDR.js → te-kb-4HG2FMHJ.js} +18 -9
  44. package/dist/{te-system-CYWSK3UN.js → te-system-AL4B4XZL.js} +2 -2
  45. package/dist/{te-team-6ELNGBWT.js → te-team-5O4UVUWE.js} +5 -5
  46. package/dist/{things-HFWLGCUH.js → things-TSJ64GBT.js} +5 -5
  47. package/dist/{update-3CRVVHV5.js → update-Q5LURAWV.js} +3 -3
  48. package/dist/{workspace-2CKQX2XL.js → workspace-FF2HXJGR.js} +4 -4
  49. package/package.json +8 -6
  50. package/skills/ae-ai-monitor/SKILL.md +179 -0
  51. package/skills/ae-ai-monitor/references/read-commands.md +866 -0
  52. package/skills/ae-analysis/SKILL.md +10 -4
  53. package/skills/ae-analysis/references/adhoc_export.md +3 -1
  54. package/skills/ae-analysis/references/ai_models.md +1 -0
  55. package/skills/ae-analysis/references/analysis_gateway_assets.md +2 -0
  56. package/skills/ae-analysis/references/asset_search.md +1 -1
  57. package/skills/ae-analysis/references/bad_case_begin.md +12 -0
  58. package/skills/ae-analysis/references/bad_case_get.md +12 -0
  59. package/skills/ae-analysis/references/bad_case_history.md +12 -0
  60. package/skills/ae-analysis/references/bad_case_list.md +12 -0
  61. package/skills/ae-analysis/references/bad_case_review.md +51 -0
  62. package/skills/ae-analysis/references/bad_case_run.md +12 -0
  63. package/skills/ae-analysis/references/bad_case_submit.md +12 -0
  64. package/skills/ae-analysis/references/bad_case_submit_to_page.md +12 -0
  65. package/skills/ae-analysis/references/bad_case_sync_evaluation.md +11 -0
  66. package/skills/ae-analysis/references/bi_panel_list.md +1 -1
  67. package/skills/ae-analysis/references/bi_panel_share.md +3 -1
  68. package/skills/ae-analysis/references/catalog_list.md +2 -0
  69. package/skills/ae-analysis/references/command_index.md +38 -29
  70. package/skills/ae-analysis/references/dashboard_daily_report_update.md +2 -0
  71. package/skills/ae-analysis/references/dashboard_handover.md +3 -1
  72. package/skills/ae-analysis/references/dashboard_list.md +3 -3
  73. package/skills/ae-analysis/references/dashboard_report_data_export.md +1 -1
  74. package/skills/ae-analysis/references/dashboard_share.md +3 -1
  75. package/skills/ae-analysis/references/dashboard_update.md +3 -2
  76. package/skills/ae-analysis/references/filter_value_list.md +2 -0
  77. package/skills/ae-analysis/references/folder_share.md +8 -2
  78. package/skills/ae-analysis/references/governance_recommendation_run_update.md +3 -1
  79. package/skills/ae-analysis/references/project_data_power_upsert.md +3 -1
  80. package/skills/ae-analysis/references/project_mark_time_create.md +2 -0
  81. package/skills/ae-analysis/references/project_mark_time_update.md +2 -0
  82. package/skills/ae-analysis/references/project_member_add.md +3 -1
  83. package/skills/ae-analysis/references/project_member_batch_update.md +3 -1
  84. package/skills/ae-analysis/references/project_member_handover_run.md +3 -1
  85. package/skills/ae-analysis/references/project_member_update.md +3 -1
  86. package/skills/ae-analysis/references/project_owner_update.md +3 -1
  87. package/skills/ae-analysis/references/project_role_upsert.md +5 -3
  88. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +16 -1
  89. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +14 -1
  90. package/skills/ae-analysis/references/project_space_share.md +8 -2
  91. package/skills/ae-analysis/references/property_get.md +2 -0
  92. package/skills/ae-analysis/references/public_link_list.md +3 -1
  93. package/skills/ae-analysis/references/query_cancel.md +4 -1
  94. package/skills/ae-analysis/references/report_data_run.md +1 -1
  95. package/skills/ae-analysis/references/report_list.md +3 -3
  96. package/skills/ae-analysis/references/scenario_append.md +2 -2
  97. package/skills/ae-analysis/references/scenario_collect.md +15 -4
  98. package/skills/ae-analysis/references/scenario_list.md +2 -1
  99. package/skills/ae-analysis/references/system_oauth2_update.md +3 -1
  100. package/skills/ae-analysis/references/system_third_party_login_upsert.md +4 -2
  101. package/skills/ae-analysis/references/user_tag_create.md +4 -1
  102. package/skills/ae-analysis/references/user_tag_get.md +2 -0
  103. package/skills/ae-analysis/references/user_tag_models.md +8 -2
  104. package/skills/ae-analysis/references/user_tag_update.md +5 -2
  105. package/skills/ae-analysis/references/virtual_property_create.md +12 -1
  106. package/skills/ae-analysis/references/virtual_property_sql_rule_update.md +10 -0
  107. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +55 -13
  108. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +2 -2
  109. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-rules.md +2 -2
  110. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +7 -1
  111. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/wait-compile-run.mjs +79 -0
  112. package/skills/ae-automation/SKILL.md +4 -2
  113. package/skills/ae-capability/SKILL.md +9 -5
  114. package/skills/ae-community/SKILL.md +1 -0
  115. package/skills/ae-dataops/SKILL.md +1 -0
  116. package/skills/ae-engage/SKILL.md +1 -0
  117. package/skills/ae-evaluation/SKILL.md +17 -2
  118. package/skills/ae-generate-tracking-plan/SKILL.md +5 -0
  119. package/skills/ae-kb/SKILL.md +5 -3
  120. package/skills/ae-kb/references/analysis-workflow.md +11 -2
  121. package/skills/ae-kb/references/query-workflow.md +3 -1
  122. package/skills/ae-kb/references/versions.md +1 -1
  123. package/skills/ae-metadata/SKILL.md +1 -0
  124. package/skills/ae-migrate-tracking-code/SKILL.md +2 -1
  125. package/skills/ae-team/SKILL.md +1 -1
  126. package/skills/ae-tracking-matrix/SKILL.md +170 -0
  127. package/skills/ae-tracking-matrix/assets//345/237/213/347/202/271/346/250/241/347/211/210.xlsx +0 -0
  128. package/skills/ae-tracking-matrix/i18n.yaml +12 -0
  129. package/skills/ae-tracking-matrix/references/ae-capabilities.md +93 -0
  130. package/skills/ae-tracking-matrix/references/business-semantic-checks.md +30 -0
  131. package/skills/ae-tracking-matrix/references/categories/acquaintance_social_tracking_plan_template.md +256 -0
  132. package/skills/ae-tracking-matrix/references/categories/blockchain_game_tracking_plan_template.md +213 -0
  133. package/skills/ae-tracking-matrix/references/categories/card_game_tracking_plan_template.md +407 -0
  134. package/skills/ae-tracking-matrix/references/categories/casual_game_tracking_plan_template.md +218 -0
  135. package/skills/ae-tracking-matrix/references/categories/casual_music.md +112 -0
  136. package/skills/ae-tracking-matrix/references/categories/chess_cards_tracking_plan_template.md +301 -0
  137. package/skills/ae-tracking-matrix/references/categories/ecommerce_tracking_plan_template.md +356 -0
  138. package/skills/ae-tracking-matrix/references/categories/fishing.md +775 -0
  139. package/skills/ae-tracking-matrix/references/categories/game_basic_module_tracking_plan.md +89 -0
  140. package/skills/ae-tracking-matrix/references/categories/idle_card.md +27 -0
  141. package/skills/ae-tracking-matrix/references/categories/idle_game_tracking_plan_template.md +415 -0
  142. package/skills/ae-tracking-matrix/references/categories/interactive_video.md +133 -0
  143. package/skills/ae-tracking-matrix/references/categories/merge.md +639 -0
  144. package/skills/ae-tracking-matrix/references/categories/mmo_mobile_tracking_plan_template.md +406 -0
  145. package/skills/ae-tracking-matrix/references/categories/mmo_web.md +230 -0
  146. package/skills/ae-tracking-matrix/references/categories/music.md +137 -0
  147. package/skills/ae-tracking-matrix/references/categories/online_education_tracking_plan_template.md +414 -0
  148. package/skills/ae-tracking-matrix/references/categories/qipai_mj.md +199 -0
  149. package/skills/ae-tracking-matrix/references/categories/reading_tracking_plan_template.md +158 -0
  150. package/skills/ae-tracking-matrix/references/categories/roguelike_tracking_plan_template.md +546 -0
  151. package/skills/ae-tracking-matrix/references/categories/rpg.md +195 -0
  152. package/skills/ae-tracking-matrix/references/categories/short_drama_tracking_plan_template.md +115 -0
  153. package/skills/ae-tracking-matrix/references/categories/simulation_business_tracking_plan_template.md +151 -0
  154. package/skills/ae-tracking-matrix/references/categories/slg_tracking_plan_template.md +260 -0
  155. package/skills/ae-tracking-matrix/references/categories/slots_tracking_plan_template.md +232 -0
  156. package/skills/ae-tracking-matrix/references/categories/stranger_social_tracking_plan_template.md +359 -0
  157. package/skills/ae-tracking-matrix/references/categories/tower_defense.md +365 -0
  158. package/skills/ae-tracking-matrix/references/categories/video_editor_tracking_plan_template.md +211 -0
  159. package/skills/ae-tracking-matrix/references/categories/wechat_minigame.md +132 -0
  160. package/skills/ae-tracking-matrix/references/category-registry.md +77 -0
  161. package/skills/ae-tracking-matrix/references/data-verification/diagnosis_kb.md +230 -0
  162. package/skills/ae-tracking-matrix/references/data-verification/sql_checks.md +406 -0
  163. package/skills/ae-tracking-matrix/references/data-verification/tracking_plan_comparison.md +128 -0
  164. package/skills/ae-tracking-matrix/references/eval-cases.md +74 -0
  165. package/skills/ae-tracking-matrix/references/naming-dict.md +238 -0
  166. package/skills/ae-tracking-matrix/references/optimization-checklist.md +85 -0
  167. package/skills/ae-tracking-matrix/references/plan-generation/export-schema.md +142 -0
  168. package/skills/ae-tracking-matrix/references/plan-generation/module-baseline.md +47 -0
  169. package/skills/ae-tracking-matrix/references/plan-generation/reference.md +794 -0
  170. package/skills/ae-tracking-matrix/references/plan-generation/template-catalog.md +94 -0
  171. package/skills/ae-tracking-matrix/references/scene-routing.md +80 -0
  172. package/skills/ae-tracking-matrix/references/sdk/client-sdk/android.md +3787 -0
  173. package/skills/ae-tracking-matrix/references/sdk/client-sdk/c.md +827 -0
  174. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-lua.md +655 -0
  175. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-x.md +953 -0
  176. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocoscreator.md +1128 -0
  177. package/skills/ae-tracking-matrix/references/sdk/client-sdk/corona.md +714 -0
  178. package/skills/ae-tracking-matrix/references/sdk/client-sdk/egret.md +1268 -0
  179. package/skills/ae-tracking-matrix/references/sdk/client-sdk/flutter.md +776 -0
  180. package/skills/ae-tracking-matrix/references/sdk/client-sdk/h5-and-app-sdk-integration.md +182 -0
  181. package/skills/ae-tracking-matrix/references/sdk/client-sdk/ios.md +2755 -0
  182. package/skills/ae-tracking-matrix/references/sdk/client-sdk/javascript.md +1182 -0
  183. package/skills/ae-tracking-matrix/references/sdk/client-sdk/layaair.md +1300 -0
  184. package/skills/ae-tracking-matrix/references/sdk/client-sdk/macos.md +1369 -0
  185. package/skills/ae-tracking-matrix/references/sdk/client-sdk/mini-program-mini-game.md +1692 -0
  186. package/skills/ae-tracking-matrix/references/sdk/client-sdk/openharmony.md +902 -0
  187. package/skills/ae-tracking-matrix/references/sdk/client-sdk/react-native.md +763 -0
  188. package/skills/ae-tracking-matrix/references/sdk/client-sdk/uni-app.md +1107 -0
  189. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unity.md +1532 -0
  190. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unreal.md +845 -0
  191. package/skills/ae-tracking-matrix/references/sdk/faq/android_sdk_faq.md +228 -0
  192. package/skills/ae-tracking-matrix/references/sdk/faq/ios_sdk_faq.md +149 -0
  193. package/skills/ae-tracking-matrix/references/sdk/faq/java_sdk_faq.md +407 -0
  194. package/skills/ae-tracking-matrix/references/sdk/faq/javascript_sdk_faq.md +163 -0
  195. package/skills/ae-tracking-matrix/references/sdk/faq/minigame_sdk_faq.md +149 -0
  196. package/skills/ae-tracking-matrix/references/sdk/faq/miniprogram_sdk_faq.md +153 -0
  197. package/skills/ae-tracking-matrix/references/sdk/faq/python_sdk_faq.md +232 -0
  198. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_log_guide.md +314 -0
  199. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_usage_notes.md +117 -0
  200. package/skills/ae-tracking-matrix/references/sdk/faq/unity_sdk_faq.md +148 -0
  201. package/skills/ae-tracking-matrix/references/sdk/integration-tools/filebeat-logstash-guide.md +645 -0
  202. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_guide.md +307 -0
  203. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_parser_plugin.md +347 -0
  204. package/skills/ae-tracking-matrix/references/sdk/integration-tools/restful_api_notes.md +72 -0
  205. package/skills/ae-tracking-matrix/references/sdk/integration-tools/ta-datax-writer-guide.md +264 -0
  206. package/skills/ae-tracking-matrix/references/sdk/server-sdk/c.md +566 -0
  207. package/skills/ae-tracking-matrix/references/sdk/server-sdk/erlang.md +409 -0
  208. package/skills/ae-tracking-matrix/references/sdk/server-sdk/golang.md +446 -0
  209. package/skills/ae-tracking-matrix/references/sdk/server-sdk/java.md +557 -0
  210. package/skills/ae-tracking-matrix/references/sdk/server-sdk/lua.md +457 -0
  211. package/skills/ae-tracking-matrix/references/sdk/server-sdk/nodejs.md +490 -0
  212. package/skills/ae-tracking-matrix/references/sdk/server-sdk/php.md +523 -0
  213. package/skills/ae-tracking-matrix/references/sdk/server-sdk/python.md +484 -0
  214. package/skills/ae-tracking-matrix/references/sdk/server-sdk/ruby.md +442 -0
  215. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/data-rules.md +391 -0
  216. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/first-event-validation.md +91 -0
  217. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/preset-properties-system-fields.md +635 -0
  218. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/updatable-events.md +113 -0
  219. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/user-identification-rules.md +466 -0
  220. package/skills/ae-tracking-matrix/references/standard-base/README.md +22 -0
  221. package/skills/ae-tracking-matrix/references/standard-base/basic_event_data.md +174 -0
  222. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties.md +20 -0
  223. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties_setup.md +7 -0
  224. package/skills/ae-tracking-matrix/references/standard-base/data_type_design_principles.md +14 -0
  225. package/skills/ae-tracking-matrix/references/standard-base/gameplay_event_data.md +370 -0
  226. package/skills/ae-tracking-matrix/references/standard-base/id_system_faq.md +47 -0
  227. package/skills/ae-tracking-matrix/references/standard-base/integration_must_know.md +37 -0
  228. package/skills/ae-tracking-matrix/references/standard-base/multi_platform_integration_notes.md +27 -0
  229. package/skills/ae-tracking-matrix/references/standard-base/multi_user_id_system_recommendations.md +23 -0
  230. package/skills/ae-tracking-matrix/references/standard-base/tracking_notes.md +14 -0
  231. package/skills/ae-tracking-matrix/references/standard-base/user_data.md +46 -0
  232. package/skills/ae-tracking-matrix/references/standard-base/user_id_system.md +13 -0
  233. package/skills/ae-tracking-matrix/references/system-fields.md +297 -0
  234. package/skills/ae-tracking-matrix/references/te-field-translations.md +1791 -0
  235. package/skills/ae-tracking-matrix/references/workflows/data-verification.md +232 -0
  236. package/skills/ae-tracking-matrix/references/workflows/feasibility-analysis.md +829 -0
  237. package/skills/ae-tracking-matrix/references/workflows/integration-qna.md +355 -0
  238. package/skills/ae-tracking-matrix/references/workflows/plan-generation.md +283 -0
  239. package/skills/ae-tracking-matrix/references/workflows/plan-lint.md +168 -0
  240. package/skills/ae-tracking-matrix/references/workflows/plan-review-optimize.md +205 -0
  241. package/skills/ae-tracking-matrix/references/workflows/prd-to-suggestions.md +75 -0
  242. package/skills/ae-tracking-matrix/references/workflows/troubleshooting.md +36 -0
  243. package/skills/ae-tracking-matrix/references/workflows/validated-upload.md +107 -0
  244. package/skills/ae-tracking-matrix/scripts/build_template_catalog.py +114 -0
  245. package/skills/ae-tracking-matrix/scripts/export_tracking_plan.py +53 -0
  246. package/skills/ae-tracking-matrix/scripts/finalize_plan.py +166 -0
  247. package/skills/ae-tracking-matrix/scripts/lint_tracking_plan.py +674 -0
  248. package/skills/ae-tracking-matrix/scripts/plan_contract.py +200 -0
  249. package/skills/ae-tracking-matrix/scripts/plan_types.py +60 -0
  250. package/skills/ae-tracking-matrix/scripts/prepare_delivery.py +169 -0
  251. package/skills/ae-tracking-matrix/scripts/sync_plan.py +296 -0
  252. package/skills/ae-tracking-matrix/scripts/upload_plan.py +340 -0
  253. package/dist/chunk-AMBFK2K3.js +0 -28
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  peekCliToken
4
- } from "./chunk-SOSFRU3O.js";
4
+ } from "./chunk-HTZ2MLYA.js";
5
5
  import {
6
6
  getActiveHost,
7
7
  getConfigDir,
@@ -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"
@@ -434,6 +448,7 @@ var skill_businesses_default = {
434
448
  ],
435
449
  agent: [
436
450
  "ae-agent",
451
+ "ae-ai-monitor",
437
452
  "ae-automation",
438
453
  "ae-current-context",
439
454
  "ae-evaluation",
@@ -477,7 +492,9 @@ var COMMAND_BUSINESSES = {
477
492
  evaluation: "agent",
478
493
  sync: "agent",
479
494
  model: "agent",
480
- context: "agent"
495
+ context: "agent",
496
+ "ai-monitor": "agent",
497
+ ai_monitor: "agent"
481
498
  };
482
499
  var AGENT_SYSTEM_COMMANDS = /* @__PURE__ */ new Set([
483
500
  "channel",
@@ -580,153 +597,65 @@ function canManageGlobalSkills() {
580
597
  return !readExternalCliToken() && !isSandboxExecutionContext();
581
598
  }
582
599
 
583
- // src/core/business-config.ts
584
- var BUSINESS_CONFIG_TTL_MS = 10 * 60 * 1e3;
585
- var UNAVAILABLE_TTL_MS = 5 * 60 * 1e3;
586
- function cachePath() {
587
- return path4.join(getConfigDir(), "business-config.json");
588
- }
589
- function cacheKey(host, token) {
590
- return `${normalizeUrl(host)}#${crypto.createHash("sha256").update(token).digest("hex")}`;
591
- }
592
- function readStore() {
593
- try {
594
- const value = JSON.parse(fs4.readFileSync(cachePath(), "utf8"));
595
- if (value?.entries && typeof value.entries === "object" && !Array.isArray(value.entries)) return value;
596
- } catch {
597
- }
598
- return { entries: {} };
599
- }
600
- function remember(host, token, entry) {
601
- const store = readStore();
602
- store.entries[cacheKey(host, token)] = entry;
603
- const target = cachePath();
604
- const temporary = `${target}.${process.pid}.${crypto.randomBytes(6).toString("hex")}.tmp`;
605
- try {
606
- fs4.mkdirSync(path4.dirname(target), { recursive: true });
607
- fs4.writeFileSync(temporary, JSON.stringify(store), { encoding: "utf8", mode: 384 });
608
- fs4.renameSync(temporary, target);
609
- fs4.chmodSync(target, 384);
610
- } catch {
611
- try {
612
- fs4.rmSync(temporary, { force: true });
613
- } catch {
614
- }
615
- }
616
- }
617
- function rememberBusinessConfig(host, token, businesses, now = Date.now()) {
618
- remember(host, token, { businesses: normalizeBusinesses(businesses), fetchedAt: now });
619
- }
620
- function peekBusinessConfig(host, token, now = Date.now()) {
621
- const entry = readStore().entries[cacheKey(host, token)];
622
- if (entry?.unavailableAt !== void 0 && now >= entry.unavailableAt && now - entry.unavailableAt < UNAVAILABLE_TTL_MS) return {};
623
- if (!entry || !Number.isFinite(entry.fetchedAt) || now < entry.fetchedAt || now - entry.fetchedAt >= BUSINESS_CONFIG_TTL_MS) return void 0;
624
- return normalizeBusinesses(entry.businesses);
625
- }
626
- function readBusinessConfig(host, token) {
627
- const entry = readStore().entries[cacheKey(host, token)];
628
- return entry && Number.isFinite(entry.fetchedAt) && entry.fetchedAt > 0 ? normalizeBusinesses(entry.businesses) : void 0;
629
- }
630
- function readCurrentBusinessConfig(hostOverride) {
631
- try {
632
- if (isSandboxExecutionContext()) return {};
633
- const host = hostOverride || getActiveHost();
634
- if (!host) return {};
635
- const token = peekCliToken(host);
636
- return token ? readBusinessConfig(host, token) ?? {} : {};
637
- } catch {
638
- return {};
639
- }
640
- }
641
- async function resolveBusinessConfig(host, token, fetchRemote, now = Date.now()) {
642
- const cached = peekBusinessConfig(host, token, now);
643
- if (cached !== void 0) return cached;
644
- const config = await fetchRemote().catch(() => null);
645
- if (!config) {
646
- const previous = readStore().entries[cacheKey(host, token)];
647
- remember(host, token, {
648
- businesses: normalizeBusinesses(previous?.businesses),
649
- fetchedAt: previous?.fetchedAt ?? 0,
650
- unavailableAt: now
651
- });
652
- return {};
653
- }
654
- const businesses = normalizeBusinesses(config.businesses);
655
- rememberBusinessConfig(host, token, businesses, now);
656
- return businesses;
657
- }
658
- var BusinessDisabledError = class extends PermissionError {
659
- constructor(business) {
660
- super(
661
- `The '${business}' business is not enabled for the current environment.`,
662
- "BUSINESS_NOT_ENABLED",
663
- "Contact your administrator if this business should be enabled, then run: ae-cli config refresh"
664
- );
665
- this.business = business;
666
- this.name = "BusinessDisabledError";
667
- }
668
- business;
669
- };
670
- async function readBusinessConfigForExecution(hostOverride) {
671
- try {
672
- if (isSandboxExecutionContext()) return {};
673
- const host = hostOverride || getActiveHost();
674
- if (!host) return {};
675
- const token = peekCliToken(host);
676
- if (!token) return {};
677
- return await resolveBusinessConfig(host, token, async () => {
678
- const { fetchCliConfig: fetchCliConfig2 } = await import("./compat-check-WFEKVLTH.js");
679
- return fetchCliConfig2(host, token);
680
- });
681
- } catch {
682
- return {};
683
- }
684
- }
685
- async function assertBusinessEnabled(business, hostOverride) {
686
- if (business && (await readBusinessConfigForExecution(hostOverride))[business] === false) {
687
- throw new BusinessDisabledError(business);
688
- }
689
- }
690
-
691
- // src/core/business-skill-sync.ts
600
+ // src/core/business-skill-refresh.ts
601
+ import crypto from "crypto";
692
602
  import fs6 from "fs";
693
603
  import path6 from "path";
694
- import { randomUUID } from "crypto";
695
604
 
696
- // src/core/skills-tool.ts
605
+ // src/core/business-skill-sync.ts
697
606
  import fs5 from "fs";
698
- import os2 from "os";
607
+ import os3 from "os";
699
608
  import path5 from "path";
609
+ import { createHash as createHash2, randomUUID } from "crypto";
610
+
611
+ // src/core/skills-tool.ts
612
+ import fs4 from "fs";
613
+ import os2 from "os";
614
+ import path4 from "path";
700
615
  import { createHash } from "crypto";
701
616
  import { createRequire, isBuiltin } from "module";
702
617
  import { pathToFileURL } from "url";
703
618
  import spawn2 from "cross-spawn";
704
619
  var MANAGED_SKILLS_TOOL_VERSION = "1.5.12";
705
620
  var TOOL_SOURCE_SHA256 = "5a2c18ddd70886d5367e39a0f88827ffd1024420e4d9db08149742386c088d2d";
621
+ function skillPathIdentity(file) {
622
+ try {
623
+ const stat = fs4.lstatSync(file, { bigint: true });
624
+ return {
625
+ dev: String(stat.dev),
626
+ ino: String(stat.ino),
627
+ type: stat.isSymbolicLink() ? "symlink" : stat.isDirectory() ? "directory" : stat.isFile() ? "file" : "other",
628
+ ...stat.isSymbolicLink() ? { link: fs4.readlinkSync(file) } : {}
629
+ };
630
+ } catch (error) {
631
+ if (error.code === "ENOENT") return null;
632
+ throw error;
633
+ }
634
+ }
706
635
  function realSkillPath(file) {
707
636
  try {
708
- return fs5.realpathSync(file);
637
+ return fs4.realpathSync(file);
709
638
  } catch (error) {
710
639
  if (error.code !== "ENOENT") throw error;
711
- const parent = path5.dirname(file);
640
+ const parent = path4.dirname(file);
712
641
  if (parent === file) throw error;
713
- return path5.join(realSkillPath(parent), path5.basename(file));
642
+ return path4.join(realSkillPath(parent), path4.basename(file));
714
643
  }
715
644
  }
716
645
  function skillPathProblem(targetDirectory, skill, sourceRoot) {
717
646
  try {
718
- const target = realSkillPath(path5.resolve(targetDirectory, skill));
719
- const source = fs5.realpathSync(sourceRoot);
720
- const overlaps = (a, b) => a === b || a.startsWith(b + path5.sep);
647
+ const target = realSkillPath(path4.resolve(targetDirectory, skill));
648
+ const source = realSkillPath(path4.resolve(sourceRoot));
649
+ const overlaps = (a, b) => a === b || a.startsWith(b + path4.sep);
721
650
  if (overlaps(target, source) || overlaps(source, target)) return "package_source_overlap";
722
- let parent = path5.resolve(targetDirectory);
651
+ let parent = path4.resolve(targetDirectory);
723
652
  while (true) {
724
653
  try {
725
- if (fs5.lstatSync(parent).isSymbolicLink()) return "copy_parent_linked";
654
+ if (fs4.lstatSync(parent).isSymbolicLink()) return "copy_parent_linked";
726
655
  } catch (error) {
727
656
  if (error.code !== "ENOENT") throw error;
728
657
  }
729
- const next = path5.dirname(parent);
658
+ const next = path4.dirname(parent);
730
659
  if (next === parent) return null;
731
660
  parent = next;
732
661
  }
@@ -736,27 +665,27 @@ function skillPathProblem(targetDirectory, skill, sourceRoot) {
736
665
  }
737
666
  function skillCopyHash(directory, source = false) {
738
667
  try {
739
- if (!fs5.lstatSync(directory).isDirectory()) throw new Error("Not a regular Skill directory.");
668
+ if (!fs4.lstatSync(directory).isDirectory()) throw new Error("Not a regular Skill directory.");
740
669
  } catch (error) {
741
670
  if (error.code === "ENOENT") return null;
742
671
  throw error;
743
672
  }
744
673
  const hash = createHash("sha256");
745
674
  const visit = (relative) => {
746
- for (const name of fs5.readdirSync(path5.join(directory, relative)).sort()) {
675
+ for (const name of fs4.readdirSync(path4.join(directory, relative)).sort()) {
747
676
  if (name === ".DS_Store") continue;
748
- const child = path5.join(relative, name);
749
- const absolute = path5.join(directory, child);
750
- const stat = fs5.lstatSync(absolute);
677
+ const child = path4.join(relative, name);
678
+ const absolute = path4.join(directory, child);
679
+ const stat = fs4.lstatSync(absolute);
751
680
  if (source && (name === "metadata.json" || stat.isDirectory() && [".git", "__pycache__", "__pypackages__"].includes(name))) continue;
752
- const normalized = child.split(path5.sep).join("/");
681
+ const normalized = child.split(path4.sep).join("/");
753
682
  if (stat.isSymbolicLink()) throw new Error("Symbolic links are not managed Skill copies.");
754
683
  if (stat.isDirectory()) {
755
684
  hash.update(`directory:${normalized}\0`);
756
685
  visit(child);
757
686
  } else if (stat.isFile()) {
758
687
  hash.update(`file:${normalized}\0${stat.size}\0`);
759
- hash.update(fs5.readFileSync(absolute));
688
+ hash.update(fs4.readFileSync(absolute));
760
689
  } else throw new Error("Unsupported Skill file type.");
761
690
  }
762
691
  };
@@ -774,6 +703,11 @@ function adaptedToolSource(source, entry) {
774
703
  let remove = source.slice(removeStart, removeEnd);
775
704
  remove = replaceOnce(remove, "const agentResult = await detectAgent();", "const agentResult = { isAgent: false };");
776
705
  remove = replaceOnce(remove, "const spinner = Y();", "const spinner = { start() {}, stop() {} };");
706
+ remove = replaceOnce(
707
+ remove,
708
+ "for (const entry of entries) if (entry.isDirectory()) skillNamesSet.add(entry.name);",
709
+ "for (const entry of entries) if (entry.isDirectory() || options.__aeCliAllowedPaths.has(join(dir, entry.name))) skillNamesSet.add(entry.name);"
710
+ );
777
711
  remove = replaceOnce(
778
712
  remove,
779
713
  "if (pathToCleanup === canonicalPath) continue;",
@@ -808,7 +742,7 @@ function adaptedToolSource(source, entry) {
808
742
  );
809
743
  source = replaceOnce(source, "main().finally(() => flushTelemetry().then(() => process.exit(0)));", "");
810
744
  const require2 = createRequire(entry);
811
- const resolveImport = (specifier) => isBuiltin(specifier) ? specifier : pathToFileURL(specifier.startsWith(".") ? path5.resolve(path5.dirname(entry), specifier) : require2.resolve(specifier)).href;
745
+ const resolveImport = (specifier) => isBuiltin(specifier) ? specifier : pathToFileURL(specifier.startsWith(".") ? path4.resolve(path4.dirname(entry), specifier) : require2.resolve(specifier)).href;
812
746
  source = source.replace(
813
747
  /\bfrom (['"])([^'"]+)\1/g,
814
748
  (_match, quote, specifier) => `from ${quote}${resolveImport(specifier)}${quote}`
@@ -821,7 +755,6 @@ function adaptedToolSource(source, entry) {
821
755
  }
822
756
  var WORKER_SOURCE = String.raw`
823
757
  import * as __aeCliFs from 'node:fs';
824
- import * as __aeCliPath from 'node:path';
825
758
  const __aeCliQuiet = () => {};
826
759
  let __aeCliTargetOverride = null;
827
760
  let __aeCliBeforeInstallMutation = null;
@@ -837,7 +770,7 @@ function __aeCliRealPath(file) {
837
770
  function __aeCliPathProblem(targetDirectory, skill, sourceRoot) {
838
771
  try {
839
772
  const target = __aeCliRealPath(resolve(targetDirectory, skill));
840
- const source = __aeCliFs.realpathSync(sourceRoot);
773
+ const source = __aeCliRealPath(resolve(sourceRoot));
841
774
  const overlaps = (a, b) => a === b || a.startsWith(b + sep);
842
775
  if (overlaps(target, source) || overlaps(source, target)) return 'package_source_overlap';
843
776
  let parent = resolve(targetDirectory);
@@ -870,46 +803,49 @@ function __aeCliHash(directory, source = false) {
870
803
  visit('');
871
804
  return hash.digest('hex');
872
805
  }
806
+ function __aeCliDirectInstallerLink(text, file, target) {
807
+ if (typeof text !== 'string') return false;
808
+ let value = text;
809
+ if (process.platform === 'win32') {
810
+ if (value.toUpperCase().startsWith('\\\\?\\UNC\\')) value = '\\\\' + value.slice(8);
811
+ else if (value.startsWith('\\\\?\\') || value.startsWith('\\??\\')) value = value.slice(4);
812
+ return [target, relative(dirname(file), target)].some(expected => value.toLowerCase() === expected.toLowerCase());
813
+ }
814
+ return value === target || value === relative(dirname(file), target);
815
+ }
873
816
  function __aeCliLegacyLinkProblem(operation, targetPath, targets, guard) {
874
817
  try {
875
818
  const canonical = resolve(getCanonicalSkillsDir(true));
876
819
  const canonicalTarget = targets.find(target => target.agent === 'universal' && target.directory === canonical);
877
820
  const link = operation.legacy_link;
821
+ const removing = operation.action === 'remove';
878
822
  if (!canonicalTarget || link.target !== join(canonical, operation.skill) || targetPath === link.target
879
- || !guard.ledger_file || operation.expected_hash !== operation.source_hash) return 'legacy_link_not_managed';
823
+ || !guard.ledger_file || (!removing && operation.expected_hash !== operation.source_hash)) return 'legacy_link_not_managed';
880
824
  const pathProblem = __aeCliPathProblem(canonical, operation.skill, operation.source_root);
881
825
  if (pathProblem) return pathProblem;
882
826
  const ledger = JSON.parse(__aeCliFs.readFileSync(guard.ledger_file, 'utf8'));
883
827
  const owned = ledger.schema_version === 1 && ledger.copies?.[link.target];
884
828
  if (!owned || owned.skill !== operation.skill || owned.agent !== canonicalTarget.agent
885
- || owned.hash !== operation.source_hash) return 'legacy_link_not_managed';
829
+ || (!removing && owned.hash !== operation.source_hash)) return 'legacy_link_not_managed';
886
830
  if (!__aeCliFs.lstatSync(targetPath).isSymbolicLink() || __aeCliFs.readlinkSync(targetPath) !== link.text
887
- || resolve(dirname(targetPath), link.text) !== link.target
888
- || __aeCliFs.realpathSync(targetPath) !== __aeCliFs.realpathSync(link.target)) return 'legacy_link_changed';
889
- if (__aeCliHash(link.target) !== operation.source_hash) return 'legacy_link_target_modified';
831
+ || !__aeCliDirectInstallerLink(link.text, targetPath, link.target)
832
+ || (!removing && __aeCliFs.realpathSync(targetPath) !== __aeCliFs.realpathSync(link.target))) return 'legacy_link_changed';
833
+ if (!removing && __aeCliHash(link.target) !== operation.source_hash) return 'legacy_link_target_modified';
890
834
  return null;
891
835
  } catch { return 'legacy_link_unreadable'; }
892
836
  }
893
- function __aeCliLinkDependsOn(file, dependency) {
894
- const absolute = resolve(file);
895
- let cursor = __aeCliPath.parse(absolute).root;
896
- const pending = absolute.slice(cursor.length).split(sep);
897
- let links = 0;
898
- while (pending.length) {
899
- const part = pending.shift();
900
- if (!part || part === '.') continue;
901
- if (part === '..') { cursor = dirname(cursor); continue; }
902
- cursor = join(cursor, part);
903
- if (cursor === dependency || cursor.startsWith(dependency + sep)) return true;
904
- if (!__aeCliFs.lstatSync(cursor).isSymbolicLink()) continue;
905
- if (++links > 64) throw new Error('Skill link chain is too deep.');
906
- const text = __aeCliFs.readlinkSync(cursor);
907
- const root = __aeCliPath.parse(text).root;
908
- cursor = root || dirname(cursor);
909
- // Expand a link before applying subsequent '..' components, matching filesystem lookup.
910
- pending.unshift(...text.slice(root.length).split(sep));
911
- }
912
- return false;
837
+ function __aeCliRemovalProblem(operation, targetPath, guard) {
838
+ try {
839
+ const ledger = guard.ledger_file && JSON.parse(__aeCliFs.readFileSync(guard.ledger_file, 'utf8'));
840
+ const owned = ledger?.schema_version === 1 && ledger.copies?.[targetPath];
841
+ if (!owned || owned.skill !== operation.skill || owned.agent !== operation.target.agent) return 'copy_not_managed';
842
+ const expected = operation.expected_node;
843
+ const current = __aeCliFs.lstatSync(targetPath, { bigint: true });
844
+ const type = current.isSymbolicLink() ? 'symlink' : current.isDirectory() ? 'directory' : current.isFile() ? 'file' : 'other';
845
+ if (!expected || expected.dev !== String(current.dev) || expected.ino !== String(current.ino) || expected.type !== type
846
+ || (type === 'symlink' && expected.link !== __aeCliFs.readlinkSync(targetPath))) return 'copy_changed';
847
+ return null;
848
+ } catch { return 'copy_unreadable'; }
913
849
  }
914
850
  async function __aeCliTargets() {
915
851
  const detected = new Set(await detectInstalledAgents());
@@ -957,24 +893,16 @@ async function __aeCliMain() {
957
893
  blockedReason = 'legacy_target_missing'; return false;
958
894
  }
959
895
  if (candidate !== targetPath) { blockedReason = 'copy_changed'; return false; }
960
- if (__aeCliHash(operation.source, true) !== operation.source_hash) { blockedReason = 'package_changed'; return false; }
896
+ if (operation.action === 'remove') {
897
+ const problem = __aeCliRemovalProblem(operation, targetPath, request.guard);
898
+ if (problem) { blockedReason = problem; return false; }
899
+ } else {
900
+ if (__aeCliHash(operation.source, true) !== operation.source_hash) { blockedReason = 'package_changed'; return false; }
901
+ if (!operation.legacy_link && __aeCliHash(targetPath) !== operation.expected_hash) { blockedReason = 'copy_changed'; return false; }
902
+ }
961
903
  if (operation.legacy_link) {
962
904
  const problem = __aeCliLegacyLinkProblem(operation, targetPath, targets, request.guard);
963
905
  if (problem) { blockedReason = problem; return false; }
964
- } else if (__aeCliHash(targetPath) !== operation.expected_hash) { blockedReason = 'copy_changed'; return false; }
965
- if (operation.action === 'remove') for (const other of targets) {
966
- try {
967
- // Preserve custom aliases too; only exact same-name installer links are migrated.
968
- for (const name of __aeCliFs.readdirSync(other.directory)) {
969
- const otherPath = join(other.directory, name);
970
- if (otherPath === targetPath) continue;
971
- try {
972
- if (__aeCliFs.lstatSync(otherPath).isSymbolicLink() && __aeCliLinkDependsOn(otherPath, targetPath)) {
973
- blockedReason = 'dependent_unmanaged_link'; return false;
974
- }
975
- } catch (error) { if (error.code !== 'ENOENT') throw error; }
976
- }
977
- } catch (error) { if (error.code !== 'ENOENT') { blockedReason = 'dependent_copy_unreadable'; return false; } }
978
906
  }
979
907
  return true;
980
908
  } catch { blockedReason = 'copy_unreadable'; return false; }
@@ -1024,19 +952,19 @@ catch { process.stdout.write(JSON.stringify({ ok: false })); process.exitCode =
1024
952
  `;
1025
953
  function createPinnedSkillsTool(options = {}) {
1026
954
  const require2 = createRequire(import.meta.url);
1027
- const packageFile = options.entry ? path5.join(path5.dirname(options.entry), "..", "package.json") : require2.resolve("skills/package.json");
1028
- const entry = options.entry ?? path5.join(path5.dirname(packageFile), "dist", "cli.mjs");
1029
- const metadata = JSON.parse(fs5.readFileSync(packageFile, "utf8"));
1030
- const source = fs5.readFileSync(entry, "utf8");
955
+ const packageFile = options.entry ? path4.join(path4.dirname(options.entry), "..", "package.json") : require2.resolve("skills/package.json");
956
+ const entry = options.entry ?? path4.join(path4.dirname(packageFile), "dist", "cli.mjs");
957
+ const metadata = JSON.parse(fs4.readFileSync(packageFile, "utf8"));
958
+ const source = fs4.readFileSync(entry, "utf8");
1031
959
  if (metadata.version !== MANAGED_SKILLS_TOOL_VERSION || createHash("sha256").update(source).digest("hex") !== TOOL_SOURCE_SHA256) {
1032
960
  throw new Error("Managed Skill synchronization requires the verified skills@1.5.12 package.");
1033
961
  }
1034
962
  const script = adaptedToolSource(source, entry);
1035
963
  const run = (request) => {
1036
- const directory = fs5.mkdtempSync(path5.join(os2.tmpdir(), "ae-cli-skills-tool-"));
1037
- const worker = path5.join(directory, "adapter.mjs");
964
+ const directory = fs4.mkdtempSync(path4.join(os2.tmpdir(), "ae-cli-skills-tool-"));
965
+ const worker = path4.join(directory, "adapter.mjs");
1038
966
  try {
1039
- fs5.writeFileSync(worker, script, { mode: 384 });
967
+ fs4.writeFileSync(worker, script, { mode: 384 });
1040
968
  const result2 = spawn2.sync(process.execPath, [worker], {
1041
969
  input: JSON.stringify(request),
1042
970
  encoding: "utf8",
@@ -1053,7 +981,7 @@ function createPinnedSkillsTool(options = {}) {
1053
981
  } catch {
1054
982
  throw new Error("Skills adapter failed. Check the pinned package and directory permissions.");
1055
983
  } finally {
1056
- fs5.rmSync(directory, { recursive: true, force: true });
984
+ fs4.rmSync(directory, { recursive: true, force: true });
1057
985
  }
1058
986
  };
1059
987
  return {
@@ -1066,14 +994,60 @@ function createPinnedSkillsTool(options = {}) {
1066
994
  var CONTEXT_FILE = "business-skill-context.json";
1067
995
  var LEDGER_FILE = "business-skills.json";
1068
996
  var LOCK_FILE = "business-skills.lock";
997
+ var POLICY_HASH = createHash2("sha256").update(JSON.stringify({ removal_policy: 2, optional_businesses: OPTIONAL_BUSINESSES, skills: skill_businesses_default })).digest("hex");
998
+ function historicalCliSkills(options) {
999
+ const env = options.env ?? process.env;
1000
+ const home = env.HOME || env.USERPROFILE || os3.homedir();
1001
+ const file = env.XDG_STATE_HOME ? path5.join(env.XDG_STATE_HOME, "skills", ".skill-lock.json") : path5.join(home, ".agents", ".skill-lock.json");
1002
+ const names = /* @__PURE__ */ new Set();
1003
+ let content = "";
1004
+ const isCliSource = (value, type) => {
1005
+ if (typeof value !== "string") return false;
1006
+ if (type === "local" && path5.isAbsolute(value)) {
1007
+ const source2 = path5.resolve(value);
1008
+ if (source2 === path5.resolve(options.skillsDirectory)) return true;
1009
+ if (path5.basename(source2) !== "skills") return false;
1010
+ try {
1011
+ const pkg = JSON.parse(fs5.readFileSync(path5.join(source2, "..", "package.json"), "utf8"));
1012
+ return ["@tant/ae-cli", "@thinkingai/ae-cli"].includes(pkg.name) && typeof pkg.bin?.["ae-cli"] === "string";
1013
+ } catch {
1014
+ return false;
1015
+ }
1016
+ }
1017
+ if (!["git", "github"].includes(String(type))) return false;
1018
+ const source = value.replace(/\/+$/, "").replace(/\.git$/, "");
1019
+ return [
1020
+ "ThinkingAIAgenticEngine/ae-cli",
1021
+ "https://github.com/ThinkingAIAgenticEngine/ae-cli",
1022
+ "git@github.com:ThinkingAIAgenticEngine/ae-cli",
1023
+ "ssh://git@gitlab.thinkingdata.cn:2222/te-ai/te-cli",
1024
+ "https://gitlab.thinkingdata.cn/te-ai/te-cli",
1025
+ "http://10.27.249.150:8888/te-ai/te-cli"
1026
+ ].includes(source);
1027
+ };
1028
+ try {
1029
+ content = fs5.readFileSync(file, "utf8");
1030
+ const lock = JSON.parse(content);
1031
+ const mapped = new Set(Object.values(skill_businesses_default).flat());
1032
+ if (typeof lock.version === "number" && lock.skills && typeof lock.skills === "object") {
1033
+ for (const [name, entry] of Object.entries(lock.skills)) {
1034
+ if (!mapped.has(name) || !entry || typeof entry !== "object") continue;
1035
+ const record = entry;
1036
+ if (isCliSource(record.source, record.sourceType) || isCliSource(record.sourceUrl, record.sourceType)) names.add(name);
1037
+ }
1038
+ }
1039
+ } catch {
1040
+ }
1041
+ return { names, hash: createHash2("sha256").update(content).digest("hex") };
1042
+ }
1069
1043
  function writeJson(file, value) {
1070
1044
  const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
1071
1045
  try {
1072
- fs6.writeFileSync(temporary, JSON.stringify(value, null, 2) + "\n", { mode: 384, flag: "wx" });
1073
- fs6.renameSync(temporary, file);
1046
+ fs5.writeFileSync(temporary, JSON.stringify(value, null, 2) + "\n", { mode: 384, flag: "wx" });
1047
+ fs5.renameSync(temporary, file);
1074
1048
  } finally {
1075
1049
  try {
1076
- fs6.unlinkSync(temporary);
1050
+ fs5.unlinkSync(temporary);
1077
1051
  } catch {
1078
1052
  }
1079
1053
  }
@@ -1093,15 +1067,15 @@ function contextIdentity(options) {
1093
1067
  }
1094
1068
  function reserveBusinessSkillContext(options) {
1095
1069
  const directory = options.stateDirectory ?? getConfigDir();
1096
- fs6.mkdirSync(directory, { recursive: true, mode: 448 });
1070
+ fs5.mkdirSync(directory, { recursive: true, mode: 448 });
1097
1071
  const generation = randomUUID();
1098
- writeJson(path6.join(directory, CONTEXT_FILE), { ...contextIdentity(options), generation });
1072
+ writeJson(path5.join(directory, CONTEXT_FILE), { ...contextIdentity(options), generation });
1099
1073
  return generation;
1100
1074
  }
1101
1075
  function currentContext(options, file, generation) {
1102
1076
  try {
1103
1077
  if (options.isCurrentContext && !options.isCurrentContext()) return false;
1104
- const active = JSON.parse(fs6.readFileSync(file, "utf8"));
1078
+ const active = JSON.parse(fs5.readFileSync(file, "utf8"));
1105
1079
  const identity = contextIdentity(options);
1106
1080
  return active.generation === generation && active.host === identity.host && active.token_fingerprint === identity.token_fingerprint;
1107
1081
  } catch {
@@ -1109,12 +1083,12 @@ function currentContext(options, file, generation) {
1109
1083
  }
1110
1084
  }
1111
1085
  function isBusinessSkillContextCurrent(options) {
1112
- return currentContext(options, path6.join(options.stateDirectory ?? getConfigDir(), CONTEXT_FILE), options.generation);
1086
+ return currentContext(options, path5.join(options.stateDirectory ?? getConfigDir(), CONTEXT_FILE), options.generation);
1113
1087
  }
1114
1088
  function takeLock(file) {
1115
1089
  const owner = randomUUID();
1116
1090
  const ownerName = `owner-${process.pid}-${owner}.json`;
1117
- const candidate = fs6.mkdtempSync(`${file}.candidate-`);
1091
+ const candidate = fs5.mkdtempSync(`${file}.candidate-`);
1118
1092
  const alive = (pid) => {
1119
1093
  try {
1120
1094
  process.kill(pid, 0);
@@ -1124,29 +1098,29 @@ function takeLock(file) {
1124
1098
  }
1125
1099
  };
1126
1100
  try {
1127
- fs6.chmodSync(candidate, 448);
1128
- fs6.writeFileSync(path6.join(candidate, ownerName), JSON.stringify({ pid: process.pid, owner }), { mode: 384 });
1101
+ fs5.chmodSync(candidate, 448);
1102
+ fs5.writeFileSync(path5.join(candidate, ownerName), JSON.stringify({ pid: process.pid, owner }), { mode: 384 });
1129
1103
  for (let attempt = 0; attempt < 4; attempt++) {
1130
1104
  try {
1131
- fs6.renameSync(candidate, file);
1105
+ fs5.renameSync(candidate, file);
1132
1106
  try {
1133
- fs6.unlinkSync(`${file}.reclaim`);
1107
+ fs5.unlinkSync(`${file}.reclaim`);
1134
1108
  } catch {
1135
1109
  }
1136
1110
  return () => {
1137
1111
  try {
1138
- fs6.unlinkSync(path6.join(file, ownerName));
1112
+ fs5.unlinkSync(path5.join(file, ownerName));
1139
1113
  } catch {
1140
1114
  }
1141
1115
  try {
1142
- fs6.rmdirSync(file);
1116
+ fs5.rmdirSync(file);
1143
1117
  } catch {
1144
1118
  }
1145
1119
  };
1146
1120
  } catch (error) {
1147
1121
  let stat;
1148
1122
  try {
1149
- stat = fs6.lstatSync(file);
1123
+ stat = fs5.lstatSync(file);
1150
1124
  } catch (cause) {
1151
1125
  if (cause.code === "ENOENT") continue;
1152
1126
  throw error;
@@ -1155,12 +1129,12 @@ function takeLock(file) {
1155
1129
  if (stat.isFile()) {
1156
1130
  let pid;
1157
1131
  try {
1158
- pid = JSON.parse(fs6.readFileSync(file, "utf8")).pid;
1132
+ pid = JSON.parse(fs5.readFileSync(file, "utf8")).pid;
1159
1133
  } catch {
1160
1134
  }
1161
1135
  if (typeof pid === "number" && Number.isInteger(pid) && pid > 0 && alive(pid)) return null;
1162
1136
  try {
1163
- fs6.unlinkSync(file);
1137
+ fs5.unlinkSync(file);
1164
1138
  } catch (cause) {
1165
1139
  if (!["ENOENT", "EISDIR", "EPERM"].includes(cause.code ?? "")) throw cause;
1166
1140
  }
@@ -1169,7 +1143,7 @@ function takeLock(file) {
1169
1143
  if (!stat.isDirectory()) return null;
1170
1144
  let names;
1171
1145
  try {
1172
- names = fs6.readdirSync(file);
1146
+ names = fs5.readdirSync(file);
1173
1147
  } catch (cause) {
1174
1148
  if (cause.code === "ENOENT") continue;
1175
1149
  throw cause;
@@ -1180,13 +1154,13 @@ function takeLock(file) {
1180
1154
  }
1181
1155
  for (const name of names) {
1182
1156
  try {
1183
- fs6.unlinkSync(path6.join(file, name));
1157
+ fs5.unlinkSync(path5.join(file, name));
1184
1158
  } catch (cause) {
1185
1159
  if (cause.code !== "ENOENT") throw cause;
1186
1160
  }
1187
1161
  }
1188
1162
  try {
1189
- fs6.rmdirSync(file);
1163
+ fs5.rmdirSync(file);
1190
1164
  } catch (cause) {
1191
1165
  if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(cause.code ?? "")) throw cause;
1192
1166
  }
@@ -1194,13 +1168,13 @@ function takeLock(file) {
1194
1168
  }
1195
1169
  return null;
1196
1170
  } finally {
1197
- fs6.rmSync(candidate, { recursive: true, force: true });
1171
+ fs5.rmSync(candidate, { recursive: true, force: true });
1198
1172
  }
1199
1173
  }
1200
1174
  function readLedger(file) {
1201
1175
  let value;
1202
1176
  try {
1203
- value = JSON.parse(fs6.readFileSync(file, "utf8"));
1177
+ value = JSON.parse(fs5.readFileSync(file, "utf8"));
1204
1178
  } catch (error) {
1205
1179
  if (error.code === "ENOENT") return { schema_version: 1, copies: {} };
1206
1180
  throw new Error("Managed Skill ledger is unreadable.");
@@ -1209,23 +1183,34 @@ function readLedger(file) {
1209
1183
  throw new Error("Managed Skill ledger has an unsupported format.");
1210
1184
  }
1211
1185
  for (const [filePath, copy] of Object.entries(value.copies)) {
1212
- 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.");
1186
+ 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.");
1213
1187
  }
1214
1188
  return value;
1215
1189
  }
1216
1190
  function result(skill, target, reason) {
1217
- return { skill, agent: target.agent, path: path6.join(target.directory, skill), ...reason ? { reason } : {} };
1191
+ return { skill, agent: target.agent, path: path5.join(target.directory, skill), ...reason ? { reason } : {} };
1192
+ }
1193
+ function directInstallerLink(file, target, text) {
1194
+ if (typeof text !== "string") return false;
1195
+ let value = text;
1196
+ if (process.platform === "win32") {
1197
+ if (value.toUpperCase().startsWith("\\\\?\\UNC\\")) value = "\\\\" + value.slice(8);
1198
+ else if (value.startsWith("\\\\?\\") || value.startsWith("\\??\\")) value = value.slice(4);
1199
+ return [target, path5.relative(path5.dirname(file), target)].some((expected) => value.toLowerCase() === expected.toLowerCase());
1200
+ }
1201
+ return value === target || value === path5.relative(path5.dirname(file), target);
1218
1202
  }
1219
- function legacySkillLink(file, skill, sourceRoot, sourceHash, targets, ledger) {
1203
+ function legacySkillLink(file, skill, sourceRoot, sourceHash, targets, ledger, removing = false) {
1220
1204
  const canonical = targets.find((target2) => target2.agent === "universal");
1221
1205
  if (!canonical) return;
1222
- const target = path6.join(canonical.directory, skill);
1206
+ const target = path5.join(canonical.directory, skill);
1223
1207
  const managed = ledger.copies[target];
1224
- if (!managed || managed.skill !== skill || managed.agent !== canonical.agent || managed.hash !== sourceHash || skillPathProblem(canonical.directory, skill, sourceRoot)) return;
1208
+ if (!managed || managed.skill !== skill || managed.agent !== canonical.agent || !removing && managed.hash !== sourceHash || skillPathProblem(canonical.directory, skill, sourceRoot)) return;
1225
1209
  try {
1226
- if (!fs6.lstatSync(file).isSymbolicLink() || skillCopyHash(target) !== sourceHash) return;
1227
- const text = fs6.readlinkSync(file);
1228
- if (path6.resolve(path6.dirname(file), text) !== target || fs6.realpathSync(file) !== fs6.realpathSync(target)) return;
1210
+ if (!fs5.lstatSync(file).isSymbolicLink()) return;
1211
+ const text = fs5.readlinkSync(file);
1212
+ if (!directInstallerLink(file, target, text)) return;
1213
+ if (!removing && (skillCopyHash(target) !== sourceHash || fs5.realpathSync(file) !== fs5.realpathSync(target))) return;
1229
1214
  return { target, text };
1230
1215
  } catch {
1231
1216
  return;
@@ -1242,20 +1227,20 @@ function syncBusinessSkills(options) {
1242
1227
  managed_count: 0
1243
1228
  };
1244
1229
  const directory = options.stateDirectory ?? getConfigDir();
1245
- const contextFile = path6.join(directory, CONTEXT_FILE);
1230
+ const contextFile = path5.join(directory, CONTEXT_FILE);
1246
1231
  let unlock = null;
1247
1232
  try {
1248
1233
  if (options.isCurrentContext && !options.isCurrentContext()) {
1249
1234
  report.status = "stale";
1250
1235
  return report;
1251
1236
  }
1252
- fs6.mkdirSync(directory, { recursive: true, mode: 448 });
1237
+ fs5.mkdirSync(directory, { recursive: true, mode: 448 });
1253
1238
  const generation = options.generation ?? reserveBusinessSkillContext(options);
1254
1239
  if (!currentContext(options, contextFile, generation)) {
1255
1240
  report.status = "stale";
1256
1241
  return report;
1257
1242
  }
1258
- unlock = takeLock(path6.join(directory, LOCK_FILE));
1243
+ unlock = takeLock(path5.join(directory, LOCK_FILE));
1259
1244
  if (!unlock) {
1260
1245
  report.status = "busy";
1261
1246
  return report;
@@ -1264,26 +1249,114 @@ function syncBusinessSkills(options) {
1264
1249
  report.status = "stale";
1265
1250
  return report;
1266
1251
  }
1267
- const ledgerFile = path6.join(directory, LEDGER_FILE);
1252
+ const ledgerFile = path5.join(directory, LEDGER_FILE);
1268
1253
  const ledger = readLedger(ledgerFile);
1269
- const tool = options.tool ?? createPinnedSkillsTool({ env: options.env });
1270
- const targets = tool.targets();
1271
- const skills = readBundledSkills(options.skillsDirectory);
1272
1254
  const packageVersion = options.packageVersion ?? "unknown";
1255
+ const history = historicalCliSkills(options);
1256
+ const applied = {
1257
+ ...contextIdentity(options),
1258
+ package_version: packageVersion,
1259
+ businesses: normalizeBusinesses(options.businesses),
1260
+ source_root: fs5.realpathSync(options.skillsDirectory),
1261
+ policy_hash: POLICY_HASH,
1262
+ history_hash: history.hash
1263
+ };
1264
+ let select;
1265
+ if (options.mode !== "adopt") {
1266
+ const previous = ledger.last_applied;
1267
+ 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) {
1268
+ const previousStates = normalizeBusinesses(previous.businesses);
1269
+ const changed = new Set(OPTIONAL_BUSINESSES.filter((business) => previousStates[business] !== applied.businesses[business] && applied.businesses[business] !== void 0));
1270
+ if (!changed.size) {
1271
+ if (!currentContext(options, contextFile, generation)) {
1272
+ report.status = "stale";
1273
+ return report;
1274
+ }
1275
+ if (JSON.stringify(previous) !== JSON.stringify(applied)) {
1276
+ ledger.last_applied = applied;
1277
+ writeJson(ledgerFile, ledger);
1278
+ }
1279
+ report.managed_count = Object.keys(ledger.copies).length;
1280
+ report.status = "success";
1281
+ return report;
1282
+ }
1283
+ select = (name) => {
1284
+ const business = businessForSkill(name);
1285
+ return business !== void 0 && changed.has(business);
1286
+ };
1287
+ }
1288
+ if (ledger.last_applied) {
1289
+ delete ledger.last_applied;
1290
+ writeJson(ledgerFile, ledger);
1291
+ }
1292
+ }
1293
+ const bundled = readBundledSkills(options.skillsDirectory, select);
1294
+ const skills = new Set(bundled.map((skill) => skill.name));
1295
+ if (options.mode !== "adopt") {
1296
+ for (const name of [...history.names, ...Object.values(ledger.copies).map((copy) => copy.skill)]) {
1297
+ if (businessForSkill(name) && getSkillBusinessState(name, options.businesses) === false && (!select || select(name))) skills.add(name);
1298
+ }
1299
+ }
1300
+ const tool = options.tool ?? createPinnedSkillsTool({ env: options.env });
1301
+ const targets = [...tool.targets()].sort((a, b) => Number(b.agent === "universal") - Number(a.agent === "universal"));
1273
1302
  const operations = [];
1274
- for (const skill of skills) {
1275
- const source = path6.join(options.skillsDirectory, skill.name);
1276
- const sourceHash = skillCopyHash(source, true);
1277
- if (!sourceHash) throw new Error("Complete package Skill source is missing.");
1278
- const state = getSkillBusinessState(skill.name, options.businesses);
1303
+ for (const name of skills) {
1304
+ const state = getSkillBusinessState(name, options.businesses);
1279
1305
  if (options.mode !== "adopt" && state === void 0) continue;
1306
+ const source = path5.join(options.skillsDirectory, name);
1307
+ const sourceHash = bundled.some((skill) => skill.name === name) ? skillCopyHash(source, true) : null;
1308
+ if (!sourceHash && options.mode === "adopt") throw new Error("Complete package Skill source is missing.");
1280
1309
  for (const target of targets) {
1281
- const item = result(skill.name, target);
1282
- const pathProblem = skillPathProblem(target.directory, skill.name, options.skillsDirectory);
1310
+ const item = result(name, target);
1311
+ const pathProblem = skillPathProblem(target.directory, name, options.skillsDirectory);
1283
1312
  if (pathProblem) {
1284
1313
  report.skipped.push({ ...item, reason: pathProblem });
1285
1314
  continue;
1286
1315
  }
1316
+ const managed = ledger.copies[item.path];
1317
+ if (options.mode !== "adopt" && state === false) {
1318
+ let node;
1319
+ try {
1320
+ node = skillPathIdentity(item.path);
1321
+ } catch {
1322
+ report.skipped.push({ ...item, reason: "copy_unreadable_or_linked" });
1323
+ continue;
1324
+ }
1325
+ if (!node) {
1326
+ if (managed) delete ledger.copies[item.path];
1327
+ continue;
1328
+ }
1329
+ const legacyLink2 = node.type === "symlink" ? legacySkillLink(item.path, name, options.skillsDirectory, sourceHash ?? "", targets, ledger, true) : void 0;
1330
+ const canonical = targets.find((copy) => copy.agent === "universal");
1331
+ const historicalLink = node.type === "symlink" && canonical && directInstallerLink(item.path, path5.join(canonical.directory, name), node.link);
1332
+ const historicalCopy = history.names.has(name) && (target.agent === "universal" && node.type !== "symlink" || historicalLink);
1333
+ if (!managed && (legacyLink2 || historicalCopy)) {
1334
+ ledger.copies[item.path] = {
1335
+ skill: name,
1336
+ agent: target.agent,
1337
+ hash: sourceHash ?? "0".repeat(64),
1338
+ package_version: packageVersion
1339
+ };
1340
+ report.adopted.push(item);
1341
+ }
1342
+ const owned = ledger.copies[item.path];
1343
+ if (!owned || owned.skill !== name || owned.agent !== target.agent) {
1344
+ report.skipped.push({ ...item, reason: node.type === "symlink" ? "copy_unreadable_or_linked" : "copy_not_managed" });
1345
+ continue;
1346
+ }
1347
+ operations.push({
1348
+ action: "remove",
1349
+ skill: name,
1350
+ source,
1351
+ source_root: options.skillsDirectory,
1352
+ expected_hash: null,
1353
+ source_hash: sourceHash ?? "",
1354
+ target,
1355
+ expected_node: node,
1356
+ ...legacyLink2 ? { legacy_link: legacyLink2 } : {}
1357
+ });
1358
+ continue;
1359
+ }
1287
1360
  let actualHash;
1288
1361
  let legacyLink;
1289
1362
  try {
@@ -1291,7 +1364,7 @@ function syncBusinessSkills(options) {
1291
1364
  } catch {
1292
1365
  if (options.mode !== "adopt") legacyLink = legacySkillLink(
1293
1366
  item.path,
1294
- skill.name,
1367
+ name,
1295
1368
  options.skillsDirectory,
1296
1369
  sourceHash,
1297
1370
  targets,
@@ -1303,7 +1376,6 @@ function syncBusinessSkills(options) {
1303
1376
  }
1304
1377
  actualHash = sourceHash;
1305
1378
  }
1306
- const managed = ledger.copies[item.path];
1307
1379
  if (options.mode === "adopt") {
1308
1380
  if (actualHash === null) {
1309
1381
  if (managed) delete ledger.copies[item.path];
@@ -1313,27 +1385,23 @@ function syncBusinessSkills(options) {
1313
1385
  report.skipped.push({ ...item, reason: "copy_does_not_match_package" });
1314
1386
  continue;
1315
1387
  }
1316
- ledger.copies[item.path] = { skill: skill.name, agent: target.agent, hash: actualHash, package_version: packageVersion };
1388
+ ledger.copies[item.path] = { skill: name, agent: target.agent, hash: actualHash, package_version: packageVersion };
1317
1389
  report.adopted.push(item);
1318
1390
  continue;
1319
1391
  }
1320
- if (!legacyLink && actualHash !== null && (!managed || managed.skill !== skill.name || actualHash !== managed.hash)) {
1392
+ if (!legacyLink && actualHash !== null && (!managed || managed.skill !== name || actualHash !== managed.hash)) {
1321
1393
  report.skipped.push({ ...item, reason: managed ? "copy_modified" : "copy_not_managed" });
1322
1394
  continue;
1323
1395
  }
1324
- if (actualHash === null && state === false) {
1396
+ if (actualHash === sourceHash && !legacyLink) continue;
1397
+ if (actualHash === null && !target.installable) {
1325
1398
  if (managed) delete ledger.copies[item.path];
1326
1399
  continue;
1327
1400
  }
1328
- if (state === true && actualHash === sourceHash && !legacyLink) continue;
1329
- if (state === true && actualHash === null && !target.installable) {
1330
- if (managed) delete ledger.copies[item.path];
1331
- continue;
1332
- }
1333
- if (state === true && actualHash === null && !target.detected && !managed && !fs6.existsSync(target.directory)) continue;
1401
+ if (actualHash === null && !target.detected && !managed && !fs5.existsSync(target.directory)) continue;
1334
1402
  operations.push({
1335
- action: state ? "install" : "remove",
1336
- skill: skill.name,
1403
+ action: "install",
1404
+ skill: name,
1337
1405
  source,
1338
1406
  source_root: options.skillsDirectory,
1339
1407
  target,
@@ -1350,7 +1418,8 @@ function syncBusinessSkills(options) {
1350
1418
  if (options.mode === "adopt") {
1351
1419
  writeJson(ledgerFile, ledger);
1352
1420
  } else if (operations.length) {
1353
- operations.sort((a, b) => Number(Boolean(b.legacy_link)) - Number(Boolean(a.legacy_link)));
1421
+ operations.sort((a, b) => Number(Boolean(b.legacy_link || b.expected_node?.type === "symlink")) - Number(Boolean(a.legacy_link || a.expected_node?.type === "symlink")));
1422
+ writeJson(ledgerFile, ledger);
1354
1423
  const receipts = tool.apply(operations, { file: contextFile, generation, ledger_file: ledgerFile });
1355
1424
  if (receipts.length !== operations.length) throw new Error("Skills adapter returned incomplete receipts.");
1356
1425
  for (let index = 0; index < operations.length; index++) {
@@ -1361,7 +1430,7 @@ function syncBusinessSkills(options) {
1361
1430
  if (receipt.status === "skipped") report.skipped.push(item);
1362
1431
  else if (receipt.status !== "success") report.failed.push(item);
1363
1432
  else if (operation.action === "remove") {
1364
- if (skillCopyHash(item.path) !== null) {
1433
+ if (skillPathIdentity(item.path) !== null) {
1365
1434
  report.failed.push({ ...item, reason: "removal_not_verified" });
1366
1435
  continue;
1367
1436
  }
@@ -1381,6 +1450,10 @@ function syncBusinessSkills(options) {
1381
1450
  } else writeJson(ledgerFile, ledger);
1382
1451
  report.managed_count = Object.keys(ledger.copies).length;
1383
1452
  report.status = !currentContext(options, contextFile, generation) ? "stale" : report.skipped.length || report.failed.length ? "partial" : "success";
1453
+ if (options.mode !== "adopt" && report.status === "success") {
1454
+ ledger.last_applied = applied;
1455
+ writeJson(ledgerFile, ledger);
1456
+ }
1384
1457
  return report;
1385
1458
  } catch {
1386
1459
  report.status = report.installed.length || report.removed.length || report.adopted.length ? "partial" : "failed";
@@ -1390,6 +1463,162 @@ function syncBusinessSkills(options) {
1390
1463
  }
1391
1464
  }
1392
1465
 
1466
+ // src/core/business-skill-refresh.ts
1467
+ function beginBusinessSkillRefresh(host, token, enabled = true) {
1468
+ try {
1469
+ if (!enabled) return void 0;
1470
+ const normalized = normalizeUrl(host);
1471
+ const isCurrentContext = () => {
1472
+ try {
1473
+ return canManageGlobalSkills() && normalizeUrl(getActiveHost()) === normalized && peekCliToken(normalized) === token;
1474
+ } catch {
1475
+ return false;
1476
+ }
1477
+ };
1478
+ if (!isCurrentContext()) return void 0;
1479
+ const identity = { host: normalized, tokenFingerprint: crypto.createHash("sha256").update(token).digest("hex") };
1480
+ return { ...identity, generation: reserveBusinessSkillContext(identity), isCurrentContext };
1481
+ } catch {
1482
+ return void 0;
1483
+ }
1484
+ }
1485
+ function isBusinessSkillRefreshCurrent(refresh) {
1486
+ return !refresh || isBusinessSkillContextCurrent(refresh);
1487
+ }
1488
+ function syncRefreshedBusinessSkills(refresh, businesses) {
1489
+ if (!refresh || !isBusinessSkillRefreshCurrent(refresh)) return;
1490
+ const states = normalizeBusinesses(businesses);
1491
+ if (!Object.keys(states).length) return;
1492
+ try {
1493
+ const pkg = getLocalCliPackageInfo();
1494
+ const options = { ...refresh, skillsDirectory: path6.join(pkg.root, "skills"), businesses: states, packageVersion: pkg.version };
1495
+ if (!fs6.existsSync(path6.join(getConfigDir(), "business-skills.json"))) {
1496
+ const adoption = syncBusinessSkills({ ...options, mode: "adopt" });
1497
+ if (["failed", "busy", "stale"].includes(adoption.status)) {
1498
+ if (adoption.status !== "stale") process.stderr.write("[ae-cli] Skills could not be synchronized. Retry: ae-cli config refresh\n");
1499
+ return;
1500
+ }
1501
+ }
1502
+ const result2 = syncBusinessSkills({ ...options, onlyIfChanged: true });
1503
+ if (!["success", "stale"].includes(result2.status)) {
1504
+ process.stderr.write("[ae-cli] Some Skills could not be synchronized. Retry: ae-cli config refresh\n");
1505
+ }
1506
+ } catch {
1507
+ process.stderr.write("[ae-cli] Skills could not be synchronized. Retry: ae-cli config refresh\n");
1508
+ }
1509
+ }
1510
+
1511
+ // src/core/business-config.ts
1512
+ var BUSINESS_CONFIG_TTL_MS = 10 * 60 * 1e3;
1513
+ var UNAVAILABLE_TTL_MS = 5 * 60 * 1e3;
1514
+ function cachePath() {
1515
+ return path7.join(getConfigDir(), "business-config.json");
1516
+ }
1517
+ function cacheKey(host, token) {
1518
+ return `${normalizeUrl(host)}#${crypto2.createHash("sha256").update(token).digest("hex")}`;
1519
+ }
1520
+ function readStore() {
1521
+ try {
1522
+ const value = JSON.parse(fs7.readFileSync(cachePath(), "utf8"));
1523
+ if (value?.entries && typeof value.entries === "object" && !Array.isArray(value.entries)) return value;
1524
+ } catch {
1525
+ }
1526
+ return { entries: {} };
1527
+ }
1528
+ function remember(host, token, entry) {
1529
+ const store = readStore();
1530
+ store.entries[cacheKey(host, token)] = entry;
1531
+ const target = cachePath();
1532
+ const temporary = `${target}.${process.pid}.${crypto2.randomBytes(6).toString("hex")}.tmp`;
1533
+ try {
1534
+ fs7.mkdirSync(path7.dirname(target), { recursive: true });
1535
+ fs7.writeFileSync(temporary, JSON.stringify(store), { encoding: "utf8", mode: 384 });
1536
+ fs7.renameSync(temporary, target);
1537
+ fs7.chmodSync(target, 384);
1538
+ } catch {
1539
+ try {
1540
+ fs7.rmSync(temporary, { force: true });
1541
+ } catch {
1542
+ }
1543
+ }
1544
+ }
1545
+ function rememberBusinessConfig(host, token, businesses, now = Date.now()) {
1546
+ remember(host, token, { businesses: normalizeBusinesses(businesses), fetchedAt: now });
1547
+ }
1548
+ function peekBusinessConfig(host, token, now = Date.now()) {
1549
+ const entry = readStore().entries[cacheKey(host, token)];
1550
+ if (entry?.unavailableAt !== void 0 && now >= entry.unavailableAt && now - entry.unavailableAt < UNAVAILABLE_TTL_MS) return {};
1551
+ if (!entry || !Number.isFinite(entry.fetchedAt) || now < entry.fetchedAt || now - entry.fetchedAt >= BUSINESS_CONFIG_TTL_MS) return void 0;
1552
+ return normalizeBusinesses(entry.businesses);
1553
+ }
1554
+ function readBusinessConfig(host, token) {
1555
+ const entry = readStore().entries[cacheKey(host, token)];
1556
+ return entry && Number.isFinite(entry.fetchedAt) && entry.fetchedAt > 0 ? normalizeBusinesses(entry.businesses) : void 0;
1557
+ }
1558
+ function readCurrentBusinessConfig(hostOverride) {
1559
+ try {
1560
+ if (isSandboxExecutionContext()) return {};
1561
+ const host = hostOverride || getActiveHost();
1562
+ if (!host) return {};
1563
+ const token = peekCliToken(host);
1564
+ return token ? readBusinessConfig(host, token) ?? {} : {};
1565
+ } catch {
1566
+ return {};
1567
+ }
1568
+ }
1569
+ async function resolveBusinessConfig(host, token, fetchRemote, now = Date.now(), synchronizeSkills = true) {
1570
+ const cached = peekBusinessConfig(host, token, now);
1571
+ if (cached !== void 0) return cached;
1572
+ const refresh = beginBusinessSkillRefresh(host, token, synchronizeSkills);
1573
+ const config = await fetchRemote().catch(() => null);
1574
+ if (!isBusinessSkillRefreshCurrent(refresh)) return peekBusinessConfig(host, token) ?? {};
1575
+ if (!config) {
1576
+ const previous = readStore().entries[cacheKey(host, token)];
1577
+ remember(host, token, {
1578
+ businesses: normalizeBusinesses(previous?.businesses),
1579
+ fetchedAt: previous?.fetchedAt ?? 0,
1580
+ unavailableAt: now
1581
+ });
1582
+ return {};
1583
+ }
1584
+ const businesses = normalizeBusinesses(config.businesses);
1585
+ rememberBusinessConfig(host, token, businesses, now);
1586
+ syncRefreshedBusinessSkills(refresh, config.businesses);
1587
+ return businesses;
1588
+ }
1589
+ var BusinessDisabledError = class extends PermissionError {
1590
+ constructor(business) {
1591
+ super(
1592
+ `The '${business}' business is not enabled for the current environment.`,
1593
+ "BUSINESS_NOT_ENABLED",
1594
+ "Contact your administrator if this business should be enabled, then run: ae-cli config refresh"
1595
+ );
1596
+ this.business = business;
1597
+ this.name = "BusinessDisabledError";
1598
+ }
1599
+ business;
1600
+ };
1601
+ async function readBusinessConfigForExecution(hostOverride, synchronizeSkills = !hostOverride) {
1602
+ try {
1603
+ if (isSandboxExecutionContext()) return {};
1604
+ const host = hostOverride || getActiveHost();
1605
+ if (!host) return {};
1606
+ const token = peekCliToken(host);
1607
+ if (!token) return {};
1608
+ return await resolveBusinessConfig(host, token, async () => {
1609
+ const { fetchCliConfig: fetchCliConfig2 } = await import("./compat-check-XD2U7PZ2.js");
1610
+ return fetchCliConfig2(host, token);
1611
+ }, Date.now(), synchronizeSkills);
1612
+ } catch {
1613
+ return {};
1614
+ }
1615
+ }
1616
+ async function assertBusinessEnabled(business, hostOverride, synchronizeSkills = !hostOverride) {
1617
+ if (business && (await readBusinessConfigForExecution(hostOverride, synchronizeSkills))[business] === false) {
1618
+ throw new BusinessDisabledError(business);
1619
+ }
1620
+ }
1621
+
1393
1622
  // src/core/installation.ts
1394
1623
  function distribution(packageName) {
1395
1624
  if (packageName === "@thinkingai/ae-cli") return { registry: "https://registry.npmjs.org", repository: "ThinkingAIAgenticEngine/ae-cli" };
@@ -1425,7 +1654,7 @@ function failInstallation(report, stage, message, cause = "validation") {
1425
1654
  function installPlan(packageName, version, root = "<npm-root>") {
1426
1655
  const config = distribution(packageName);
1427
1656
  const target = exactVersion(version);
1428
- const executable = path7.join(root, packageName, "bin", "ae-cli.js");
1657
+ const executable = path8.join(root, packageName, "bin", "ae-cli.js");
1429
1658
  return [
1430
1659
  `npm install -g ${packageName}@${target} --registry=${config.registry}`,
1431
1660
  `node ${JSON.stringify(executable)} install`
@@ -1434,7 +1663,7 @@ function installPlan(packageName, version, root = "<npm-root>") {
1434
1663
  function currentSkillIdentity() {
1435
1664
  const host = getActiveHost();
1436
1665
  const token = host ? peekCliToken(host) : void 0;
1437
- return { host, tokenFingerprint: token ? crypto2.createHash("sha256").update(token).digest("hex") : "" };
1666
+ return { host, tokenFingerprint: token ? crypto3.createHash("sha256").update(token).digest("hex") : "" };
1438
1667
  }
1439
1668
  function skipGlobalSkillReason() {
1440
1669
  try {
@@ -1445,27 +1674,27 @@ function skipGlobalSkillReason() {
1445
1674
  }
1446
1675
  function readPackage(root) {
1447
1676
  try {
1448
- return JSON.parse(fs7.readFileSync(path7.join(root, "package.json"), "utf8"));
1677
+ return JSON.parse(fs8.readFileSync(path8.join(root, "package.json"), "utf8"));
1449
1678
  } catch {
1450
1679
  return null;
1451
1680
  }
1452
1681
  }
1453
1682
  function linked(root) {
1454
1683
  try {
1455
- return fs7.lstatSync(root).isSymbolicLink();
1684
+ return fs8.lstatSync(root).isSymbolicLink();
1456
1685
  } catch {
1457
1686
  return false;
1458
1687
  }
1459
1688
  }
1460
1689
  function cliBinBelongsToPackage(bin, packageRoot, platform) {
1461
- const entry = fs7.realpathSync(path7.join(packageRoot, "bin", "ae-cli.js"));
1462
- if (platform !== "win32") return fs7.realpathSync(bin) === entry;
1463
- const shim = fs7.readFileSync(bin, "utf8");
1690
+ const entry = fs8.realpathSync(path8.join(packageRoot, "bin", "ae-cli.js"));
1691
+ if (platform !== "win32") return fs8.realpathSync(bin) === entry;
1692
+ const shim = fs8.readFileSync(bin, "utf8");
1464
1693
  const targets = [...shim.matchAll(/"%(?:dp0%|~dp0)[\\/]([^"\r\n]+)"/gi)];
1465
1694
  return targets.some(([, relative]) => {
1466
1695
  try {
1467
- const target = path7.resolve(path7.dirname(bin), relative.replace(/\\/g, path7.sep));
1468
- return fs7.realpathSync(target).toLowerCase() === entry.toLowerCase();
1696
+ const target = path8.resolve(path8.dirname(bin), relative.replace(/\\/g, path8.sep));
1697
+ return fs8.realpathSync(target).toLowerCase() === entry.toLowerCase();
1469
1698
  } catch {
1470
1699
  return false;
1471
1700
  }
@@ -1506,9 +1735,9 @@ function runInstallation(options = {}) {
1506
1735
  const prefixResult = runner(npm, ["prefix", "-g"], 15e3);
1507
1736
  const globalRoot = rootResult.stdout.trim();
1508
1737
  const prefix = prefixResult.stdout.trim();
1509
- 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.");
1510
- const packageRoot = path7.join(globalRoot, packageName);
1511
- const bin = platform === "win32" ? path7.join(prefix, "ae-cli.cmd") : path7.join(prefix, "bin", "ae-cli");
1738
+ 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.");
1739
+ const packageRoot = path8.join(globalRoot, packageName);
1740
+ const bin = platform === "win32" ? path8.join(prefix, "ae-cli.cmd") : path8.join(prefix, "bin", "ae-cli");
1512
1741
  report.cli.path = bin;
1513
1742
  const env = options.env ?? process.env;
1514
1743
  const installedBefore = readPackage(packageRoot);
@@ -1531,8 +1760,8 @@ function runInstallation(options = {}) {
1531
1760
  };
1532
1761
  const generation = reserveBusinessSkillContext({ ...identity, stateDirectory });
1533
1762
  context = { ...identity, stateDirectory, generation, isCurrentContext };
1534
- if (!fs7.existsSync(path7.join(stateDirectory, "business-skills.json")) && installedBefore?.name === packageName) {
1535
- const previousSkills = path7.join(packageRoot, "skills");
1763
+ if (!fs8.existsSync(path8.join(stateDirectory, "business-skills.json")) && installedBefore?.name === packageName) {
1764
+ const previousSkills = path8.join(packageRoot, "skills");
1536
1765
  try {
1537
1766
  readBundledSkills(previousSkills);
1538
1767
  syncSkills({ ...context, skillsDirectory: previousSkills, businesses: {}, mode: "adopt", packageVersion: installedBefore.version });
@@ -1544,7 +1773,7 @@ function runInstallation(options = {}) {
1544
1773
  return failInstallation(report, "skills_local", "The active environment changed before installation. Re-run install or update for the current environment.");
1545
1774
  }
1546
1775
  }
1547
- if (options.skipCliInstall || installedBefore?.name === packageName && installedBefore.version === target && fs7.existsSync(bin)) {
1776
+ if (options.skipCliInstall || installedBefore?.name === packageName && installedBefore.version === target && fs8.existsSync(bin)) {
1548
1777
  report.cli.action = "skipped";
1549
1778
  progress("[ae-cli] [2/4] Verifying the existing CLI...");
1550
1779
  } else {
@@ -1557,16 +1786,16 @@ function runInstallation(options = {}) {
1557
1786
  stage = "package_validation";
1558
1787
  const installed = readPackage(packageRoot);
1559
1788
  if (installed?.name !== packageName || installed.version !== target) return failInstallation(report, stage, "Installed CLI package identity or version does not match the requested distribution.");
1560
- 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.");
1789
+ 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.");
1561
1790
  if (!cliBinBelongsToPackage(bin, packageRoot, platform)) return failInstallation(report, stage, "The global executable does not belong to the installed CLI package.");
1562
1791
  const versionResult = runner(bin, ["--version"], 15e3);
1563
1792
  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.");
1564
- report.cli.entrypoint = fs7.realpathSync(path7.join(packageRoot, "bin", "ae-cli.js"));
1793
+ report.cli.entrypoint = fs8.realpathSync(path8.join(packageRoot, "bin", "ae-cli.js"));
1565
1794
  report.cli.verified = true;
1566
1795
  const pathKey = platform === "win32" ? Object.keys(env).find((key) => key.toLowerCase() === "path") : "PATH";
1567
- 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}`));
1568
- if (!installedPathBin || fs7.realpathSync(installedPathBin) !== fs7.realpathSync(bin)) {
1569
- report.cli.warnings.push(`Add ${path7.dirname(bin)} to the front of PATH and refresh the shell command cache. The absolute executable was verified.`);
1796
+ 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}`));
1797
+ if (!installedPathBin || fs8.realpathSync(installedPathBin) !== fs8.realpathSync(bin)) {
1798
+ report.cli.warnings.push(`Add ${path8.dirname(bin)} to the front of PATH and refresh the shell command cache. The absolute executable was verified.`);
1570
1799
  report.next_steps.push(`Use the verified executable at ${bin}, or correct PATH before invoking ae-cli.`);
1571
1800
  }
1572
1801
  if (skipSkills) {
@@ -1575,7 +1804,7 @@ function runInstallation(options = {}) {
1575
1804
  progress(`[ae-cli] [3/4] ${skipSkills}`);
1576
1805
  } else if (context) {
1577
1806
  stage = "skills_local";
1578
- const skillsPath = path7.join(packageRoot, "skills");
1807
+ const skillsPath = path8.join(packageRoot, "skills");
1579
1808
  const skills = readBundledSkills(skillsPath);
1580
1809
  if (!isBusinessSkillContextCurrent(context)) {
1581
1810
  return failInstallation(report, stage, "The active environment changed during CLI installation. Re-run install or update to synchronize its Skills.");
@@ -1638,14 +1867,14 @@ var LOCK_STALE_MS = 10 * 60 * 1e3;
1638
1867
  var SYNC_STATE_FILE = "version-sync.json";
1639
1868
  var SYNC_LOCK_FILE = "version-sync.lock";
1640
1869
  function syncStatePath() {
1641
- return path8.join(getConfigDir(), SYNC_STATE_FILE);
1870
+ return path9.join(getConfigDir(), SYNC_STATE_FILE);
1642
1871
  }
1643
1872
  function syncLockPath() {
1644
- return path8.join(getConfigDir(), SYNC_LOCK_FILE);
1873
+ return path9.join(getConfigDir(), SYNC_LOCK_FILE);
1645
1874
  }
1646
1875
  function readSyncStore() {
1647
1876
  try {
1648
- const raw = JSON.parse(fs8.readFileSync(syncStatePath(), "utf8"));
1877
+ const raw = JSON.parse(fs9.readFileSync(syncStatePath(), "utf8"));
1649
1878
  if (raw && typeof raw === "object" && raw.hosts && typeof raw.hosts === "object") {
1650
1879
  return raw;
1651
1880
  }
@@ -1655,8 +1884,8 @@ function readSyncStore() {
1655
1884
  }
1656
1885
  function writeSyncStore(store) {
1657
1886
  try {
1658
- fs8.mkdirSync(getConfigDir(), { recursive: true });
1659
- fs8.writeFileSync(syncStatePath(), JSON.stringify(store, null, 2));
1887
+ fs9.mkdirSync(getConfigDir(), { recursive: true });
1888
+ fs9.writeFileSync(syncStatePath(), JSON.stringify(store, null, 2));
1660
1889
  } catch {
1661
1890
  }
1662
1891
  }
@@ -1760,20 +1989,20 @@ function friendlyVersionSyncFailure(result2) {
1760
1989
  return `Version synchronization failed at ${result2.stage}.`;
1761
1990
  }
1762
1991
  function acquireInstallLock(now) {
1763
- fs8.mkdirSync(getConfigDir(), { recursive: true });
1992
+ fs9.mkdirSync(getConfigDir(), { recursive: true });
1764
1993
  const file = syncLockPath();
1765
1994
  try {
1766
- return fs8.openSync(file, "wx");
1995
+ return fs9.openSync(file, "wx");
1767
1996
  } catch {
1768
1997
  try {
1769
- const age = now.getTime() - fs8.statSync(file).mtimeMs;
1998
+ const age = now.getTime() - fs9.statSync(file).mtimeMs;
1770
1999
  if (age >= LOCK_STALE_MS) {
1771
- fs8.unlinkSync(file);
1772
- return fs8.openSync(file, "wx");
2000
+ fs9.unlinkSync(file);
2001
+ return fs9.openSync(file, "wx");
1773
2002
  }
1774
2003
  } catch {
1775
2004
  try {
1776
- return fs8.openSync(file, "wx");
2005
+ return fs9.openSync(file, "wx");
1777
2006
  } catch {
1778
2007
  return null;
1779
2008
  }
@@ -1783,11 +2012,11 @@ function acquireInstallLock(now) {
1783
2012
  }
1784
2013
  function releaseInstallLock(fd) {
1785
2014
  try {
1786
- fs8.closeSync(fd);
2015
+ fs9.closeSync(fd);
1787
2016
  } catch {
1788
2017
  }
1789
2018
  try {
1790
- fs8.unlinkSync(syncLockPath());
2019
+ fs9.unlinkSync(syncLockPath());
1791
2020
  } catch {
1792
2021
  }
1793
2022
  }
@@ -1848,21 +2077,21 @@ function autoSyncDirection(current, expected) {
1848
2077
  }
1849
2078
 
1850
2079
  // src/core/feature-config.ts
1851
- import crypto3 from "crypto";
1852
- import fs9 from "fs";
1853
- import path9 from "path";
2080
+ import crypto4 from "crypto";
2081
+ import fs10 from "fs";
2082
+ import path10 from "path";
1854
2083
  var FEATURE_TTL_MS = 24 * 60 * 60 * 1e3;
1855
2084
  var UNAVAILABLE_TTL_MS2 = 5 * 60 * 1e3;
1856
2085
  function cachePath2() {
1857
- return path9.join(getConfigDir(), "feature-config.json");
2086
+ return path10.join(getConfigDir(), "feature-config.json");
1858
2087
  }
1859
2088
  function cacheKey2(host, token) {
1860
- const fingerprint = crypto3.createHash("sha256").update(token).digest("hex");
2089
+ const fingerprint = crypto4.createHash("sha256").update(token).digest("hex");
1861
2090
  return `${normalizeUrl(host)}#${fingerprint}`;
1862
2091
  }
1863
2092
  function readStore2() {
1864
2093
  try {
1865
- const value = JSON.parse(fs9.readFileSync(cachePath2(), "utf8"));
2094
+ const value = JSON.parse(fs10.readFileSync(cachePath2(), "utf8"));
1866
2095
  return value?.entries && typeof value.entries === "object" ? value : { entries: {} };
1867
2096
  } catch {
1868
2097
  return { entries: {} };
@@ -1870,15 +2099,15 @@ function readStore2() {
1870
2099
  }
1871
2100
  function writeStore(store) {
1872
2101
  const target = cachePath2();
1873
- const temp = `${target}.${process.pid}.${crypto3.randomBytes(6).toString("hex")}.tmp`;
2102
+ const temp = `${target}.${process.pid}.${crypto4.randomBytes(6).toString("hex")}.tmp`;
1874
2103
  try {
1875
- fs9.mkdirSync(path9.dirname(target), { recursive: true });
1876
- fs9.writeFileSync(temp, JSON.stringify(store), { encoding: "utf8", mode: 384 });
1877
- fs9.renameSync(temp, target);
1878
- fs9.chmodSync(target, 384);
2104
+ fs10.mkdirSync(path10.dirname(target), { recursive: true });
2105
+ fs10.writeFileSync(temp, JSON.stringify(store), { encoding: "utf8", mode: 384 });
2106
+ fs10.renameSync(temp, target);
2107
+ fs10.chmodSync(target, 384);
1879
2108
  } catch {
1880
2109
  try {
1881
- fs9.rmSync(temp, { force: true });
2110
+ fs10.rmSync(temp, { force: true });
1882
2111
  } catch {
1883
2112
  }
1884
2113
  }
@@ -1891,13 +2120,25 @@ function remember2(host, token, entry) {
1891
2120
  function rememberKbAutoDiscoveryFeature(host, token, enabled) {
1892
2121
  remember2(host, token, { enabled, available: true, fetchedAt: Date.now() });
1893
2122
  }
1894
- async function resolveKbAutoDiscoveryFeature(host, token, fetchRemote) {
2123
+ function peekKbAutoDiscoveryFeature(host, token) {
2124
+ const entry = readStore2().entries[cacheKey2(host, token)];
2125
+ const ttl = entry?.available ? FEATURE_TTL_MS : UNAVAILABLE_TTL_MS2;
2126
+ if (!entry || !entry.available || Date.now() < entry.fetchedAt || Date.now() - entry.fetchedAt >= ttl) {
2127
+ return void 0;
2128
+ }
2129
+ return entry.enabled;
2130
+ }
2131
+ async function resolveKbAutoDiscoveryFeature(host, token, fetchRemote, isCurrent = () => true) {
1895
2132
  const entry = readStore2().entries[cacheKey2(host, token)];
1896
2133
  const ttl = entry?.available ? FEATURE_TTL_MS : UNAVAILABLE_TTL_MS2;
1897
2134
  if (entry && Date.now() >= entry.fetchedAt && Date.now() - entry.fetchedAt < ttl) {
1898
2135
  return { enabled: entry.enabled, source: entry.available ? "cache" : "unavailable" };
1899
2136
  }
1900
2137
  const remote = await fetchRemote().catch(() => null);
2138
+ if (!isCurrent()) {
2139
+ const latest = peekKbAutoDiscoveryFeature(host, token);
2140
+ return latest === void 0 ? { enabled: false, source: "unavailable" } : { enabled: latest, source: "cache" };
2141
+ }
1901
2142
  if (!remote) {
1902
2143
  remember2(host, token, { enabled: false, available: false, fetchedAt: Date.now() });
1903
2144
  return { enabled: false, source: "unavailable" };
@@ -1913,13 +2154,13 @@ var NOTIFY_INTERVAL_MS = 24 * 60 * 60 * 1e3;
1913
2154
  var FETCH_TIMEOUT_MS = 3e3;
1914
2155
  var CLI_CONFIG_PATH = "/v1/ta/cli/config";
1915
2156
  function cacheFilePath() {
1916
- return path10.join(getConfigDir(), "compat-check.json");
2157
+ return path11.join(getConfigDir(), "compat-check.json");
1917
2158
  }
1918
2159
  function readStore3() {
1919
2160
  try {
1920
2161
  const file = cacheFilePath();
1921
- if (!fs10.existsSync(file)) return { hosts: {} };
1922
- const raw = JSON.parse(fs10.readFileSync(file, "utf8"));
2162
+ if (!fs11.existsSync(file)) return { hosts: {} };
2163
+ const raw = JSON.parse(fs11.readFileSync(file, "utf8"));
1923
2164
  if (!raw || typeof raw !== "object" || !raw.hosts) return { hosts: {} };
1924
2165
  return raw;
1925
2166
  } catch {
@@ -1929,8 +2170,8 @@ function readStore3() {
1929
2170
  function writeStore2(store) {
1930
2171
  try {
1931
2172
  const dir = getConfigDir();
1932
- if (!fs10.existsSync(dir)) fs10.mkdirSync(dir, { recursive: true });
1933
- fs10.writeFileSync(cacheFilePath(), JSON.stringify(store, null, 2));
2173
+ if (!fs11.existsSync(dir)) fs11.mkdirSync(dir, { recursive: true });
2174
+ fs11.writeFileSync(cacheFilePath(), JSON.stringify(store, null, 2));
1934
2175
  } catch {
1935
2176
  }
1936
2177
  }
@@ -2069,7 +2310,7 @@ function setUpdateNotice(pkg, expected, cluster, verdict, state, stage, message)
2069
2310
  message: message ?? `Current ae-cli is ${pkg.version}; this host requires ${expected}. Run: ae-cli update`
2070
2311
  };
2071
2312
  }
2072
- async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2313
+ async function refreshAndMaybeNotify(host, pkg, allowAutoSync, synchronizeSkills) {
2073
2314
  const token = peekCliToken(host);
2074
2315
  if (!token) return { status: "continue" };
2075
2316
  const store = readStore3();
@@ -2079,10 +2320,13 @@ async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2079
2320
  let cluster = existing?.clusterVersion;
2080
2321
  let fetchedAt = existing?.lastFetchedAt;
2081
2322
  if (isCompatCacheStale(existing)) {
2323
+ const refresh = beginBusinessSkillRefresh(host, token, synchronizeSkills && allowAutoSync);
2082
2324
  const remote = await fetchCliConfig(host, token);
2325
+ if (!isBusinessSkillRefreshCurrent(refresh)) return { status: "continue" };
2083
2326
  if (remote) {
2084
2327
  rememberKbAutoDiscoveryFeature(host, token, remote.projectSemanticKbAutoDiscovery ?? false);
2085
2328
  rememberBusinessConfig(host, token, remote.businesses);
2329
+ syncRefreshedBusinessSkills(refresh, remote.businesses);
2086
2330
  }
2087
2331
  if (!remote?.aeCliVersion) {
2088
2332
  return { status: "continue" };
@@ -2127,7 +2371,7 @@ async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2127
2371
  return false;
2128
2372
  }
2129
2373
  };
2130
- const context = isCurrentLocalIdentity() ? { host, tokenFingerprint: createHash2("sha256").update(token).digest("hex") } : void 0;
2374
+ const context = isCurrentLocalIdentity() ? { host, tokenFingerprint: createHash3("sha256").update(token).digest("hex") } : void 0;
2131
2375
  const generation = context ? reserveBusinessSkillContext(context) : void 0;
2132
2376
  const confirmed = await fetchCliConfig(host, token);
2133
2377
  if (context && generation && !isBusinessSkillContextCurrent({
@@ -2138,6 +2382,9 @@ async function refreshAndMaybeNotify(host, pkg, allowAutoSync) {
2138
2382
  if (confirmed) {
2139
2383
  rememberKbAutoDiscoveryFeature(host, token, confirmed.projectSemanticKbAutoDiscovery ?? false);
2140
2384
  rememberBusinessConfig(host, token, confirmed.businesses);
2385
+ if (context && generation && synchronizeSkills) {
2386
+ syncRefreshedBusinessSkills({ ...context, generation, isCurrentContext: isCurrentLocalIdentity }, confirmed.businesses);
2387
+ }
2141
2388
  }
2142
2389
  if (confirmed?.aeCliVersion) {
2143
2390
  expected = confirmed.aeCliVersion;
@@ -2237,7 +2484,7 @@ async function runHostCompatCheck(pkg, hostOverride, argv = process.argv) {
2237
2484
  const host = hostOverride || getActiveHost();
2238
2485
  if (!host) return { status: "continue" };
2239
2486
  try {
2240
- return await refreshAndMaybeNotify(host, pkg, !shouldSkipAutoSync(argv));
2487
+ return await refreshAndMaybeNotify(host, pkg, !shouldSkipAutoSync(argv), !hostOverride);
2241
2488
  } catch {
2242
2489
  return { status: "continue" };
2243
2490
  }
@@ -2253,14 +2500,17 @@ export {
2253
2500
  businessForCommand,
2254
2501
  businessForCapability,
2255
2502
  canManageGlobalSkills,
2503
+ reserveBusinessSkillContext,
2504
+ isBusinessSkillContextCurrent,
2505
+ syncBusinessSkills,
2506
+ beginBusinessSkillRefresh,
2507
+ isBusinessSkillRefreshCurrent,
2508
+ syncRefreshedBusinessSkills,
2256
2509
  rememberBusinessConfig,
2257
2510
  readCurrentBusinessConfig,
2258
2511
  BusinessDisabledError,
2259
2512
  readBusinessConfigForExecution,
2260
2513
  assertBusinessEnabled,
2261
- reserveBusinessSkillContext,
2262
- isBusinessSkillContextCurrent,
2263
- syncBusinessSkills,
2264
2514
  newInstallationReport,
2265
2515
  failInstallation,
2266
2516
  recordVersionSyncResult,