@thinkingai/ae-cli 6.1.30 → 6.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/README.zh.md +11 -5
- package/bin/ai-monitor.js +2 -0
- package/dist/ai-monitor-MKMHSSNI.js +32 -0
- package/dist/ai-monitor.js +135 -0
- package/dist/{auth-ADZHUIJR.js → auth-CZHHPZOQ.js} +10 -9
- package/dist/{automation-FD2QZUP6.js → automation-FLCPFMN4.js} +4 -4
- package/dist/{capability-QXFRJYZD.js → capability-64KVJFIA.js} +27 -31
- package/dist/{chunk-YULUBP3R.js → chunk-3ULDJJTZ.js} +1 -1
- package/dist/{chunk-HRUOV6EQ.js → chunk-4XKTRCRK.js} +15 -15
- package/dist/{chunk-JSBLCLFE.js → chunk-5M5LBRR3.js} +1 -1
- package/dist/chunk-6M7ZEDT2.js +182 -0
- package/dist/{chunk-KPQY44JQ.js → chunk-AWW2T2WL.js} +3 -0
- package/dist/chunk-BNBCMCYN.js +563 -0
- package/dist/chunk-CF6JTT2U.js +64 -0
- package/dist/{chunk-CG773QXN.js → chunk-DWBYNGSR.js} +564 -314
- package/dist/{chunk-VDICGXCY.js → chunk-F2VFZUGG.js} +2 -2
- package/dist/{chunk-TFORY6WY.js → chunk-FCAA7I2D.js} +2 -2
- package/dist/{chunk-SOSFRU3O.js → chunk-HTZ2MLYA.js} +47 -21
- package/dist/{chunk-AWVZTN2B.js → chunk-HVMCPKOZ.js} +1 -1
- package/dist/chunk-IDDWEZ7F.js +1285 -0
- package/dist/{chunk-E25OSZLJ.js → chunk-KTJXD27G.js} +2 -2
- package/dist/{chunk-AVXDJAFC.js → chunk-NLEXY2TM.js} +47 -12
- package/dist/{chunk-YVG6QD3V.js → chunk-P7QDCWJ6.js} +98 -7
- package/dist/{chunk-EUFP4M2A.js → chunk-T7WF4HYW.js} +84 -32
- package/dist/{chunk-Y3AM6LIO.js → chunk-TMQGS4TO.js} +15 -10
- package/dist/{compat-check-HERBTQZN.js → compat-check-ZJNCMNQV.js} +2 -2
- package/dist/{config-E3KANXMK.js → config-FSH2NMNZ.js} +25 -12
- package/dist/{context-CDB5H5PD.js → context-YAQG6YQC.js} +2 -2
- package/dist/{evaluation-LR4YDYWL.js → evaluation-2JSF4V47.js} +13 -158
- package/dist/index.js +81 -583
- package/dist/{memory-SNFR5M23.js → memory-VEZZVAAP.js} +4 -4
- package/dist/{metadata-EXQYDZTH.js → metadata-3IWHX3V4.js} +7 -7
- package/dist/{model-KEVCEXWD.js → model-T7H7Q6BG.js} +2 -2
- package/dist/{personal-semantic-preference-ETY3KU2O.js → personal-semantic-preference-YITU23SA.js} +6 -6
- package/dist/{project-semantic-UHRMVOJF.js → project-semantic-MHEXJF3C.js} +15 -13
- package/dist/{sync-XKEBXESC.js → sync-AQHVCSPI.js} +4 -4
- package/dist/{te-agent-S6UQR4IE.js → te-agent-RXI7WOH4.js} +5 -5
- package/dist/{te-analysis-WOFFCIBC.js → te-analysis-CZY74HVF.js} +380 -191
- package/dist/{te-community-R7B6QYOO.js → te-community-DKCYUBCM.js} +6 -6
- package/dist/{te-dataops-KPILYVHA.js → te-dataops-QEH6VE56.js} +3 -3
- package/dist/{te-engage-IAUM6ONX.js → te-engage-WK7WKDKF.js} +6 -6
- package/dist/{te-experiment-TMLRA7B3.js → te-experiment-LH3RPIOE.js} +274 -29
- package/dist/{te-kb-GKWPSLSY.js → te-kb-UPORIOVN.js} +16 -7
- package/dist/{te-system-CYWSK3UN.js → te-system-AL4B4XZL.js} +2 -2
- package/dist/{te-team-ISN52YNG.js → te-team-LLVTO2G4.js} +5 -5
- package/dist/{things-DDQ52Z3Q.js → things-XLMLBYQR.js} +5 -5
- package/dist/{update-CTLNTX35.js → update-7J5UQHSK.js} +3 -3
- package/dist/{workspace-2CKQX2XL.js → workspace-FF2HXJGR.js} +4 -4
- package/package.json +9 -7
- package/skills/ae-ai-monitor/SKILL.md +179 -0
- package/skills/ae-ai-monitor/references/read-commands.md +866 -0
- package/skills/ae-analysis/SKILL.md +10 -4
- package/skills/ae-analysis/references/adhoc_export.md +3 -1
- package/skills/ae-analysis/references/ai_models/path.md +5 -6
- package/skills/ae-analysis/references/ai_models.md +1 -0
- package/skills/ae-analysis/references/analysis_gateway_assets.md +2 -0
- package/skills/ae-analysis/references/asset_search.md +1 -1
- package/skills/ae-analysis/references/bad_case_begin.md +12 -0
- package/skills/ae-analysis/references/bad_case_get.md +12 -0
- package/skills/ae-analysis/references/bad_case_history.md +12 -0
- package/skills/ae-analysis/references/bad_case_list.md +12 -0
- package/skills/ae-analysis/references/bad_case_review.md +51 -0
- package/skills/ae-analysis/references/bad_case_run.md +12 -0
- package/skills/ae-analysis/references/bad_case_submit.md +12 -0
- package/skills/ae-analysis/references/bad_case_submit_to_page.md +12 -0
- package/skills/ae-analysis/references/bad_case_sync_evaluation.md +11 -0
- package/skills/ae-analysis/references/bi_panel_list.md +1 -1
- package/skills/ae-analysis/references/bi_panel_share.md +3 -1
- package/skills/ae-analysis/references/catalog_list.md +2 -0
- package/skills/ae-analysis/references/command_index.md +38 -29
- package/skills/ae-analysis/references/dashboard_daily_report_update.md +2 -0
- package/skills/ae-analysis/references/dashboard_handover.md +3 -1
- package/skills/ae-analysis/references/dashboard_list.md +3 -3
- package/skills/ae-analysis/references/dashboard_report_data_export.md +1 -1
- package/skills/ae-analysis/references/dashboard_share.md +3 -1
- package/skills/ae-analysis/references/dashboard_update.md +3 -2
- package/skills/ae-analysis/references/filter_value_list.md +2 -0
- package/skills/ae-analysis/references/folder_share.md +8 -2
- package/skills/ae-analysis/references/governance_recommendation_run_update.md +3 -1
- package/skills/ae-analysis/references/project_data_power_upsert.md +3 -1
- package/skills/ae-analysis/references/project_mark_time_create.md +2 -0
- package/skills/ae-analysis/references/project_mark_time_update.md +2 -0
- package/skills/ae-analysis/references/project_member_add.md +3 -1
- package/skills/ae-analysis/references/project_member_batch_update.md +3 -1
- package/skills/ae-analysis/references/project_member_handover_run.md +3 -1
- package/skills/ae-analysis/references/project_member_update.md +3 -1
- package/skills/ae-analysis/references/project_owner_update.md +3 -1
- package/skills/ae-analysis/references/project_role_upsert.md +5 -3
- package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +16 -1
- package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +14 -1
- package/skills/ae-analysis/references/project_space_share.md +8 -2
- package/skills/ae-analysis/references/property_get.md +2 -0
- package/skills/ae-analysis/references/public_link_list.md +3 -1
- package/skills/ae-analysis/references/query_cancel.md +4 -1
- package/skills/ae-analysis/references/report_data_run.md +1 -1
- package/skills/ae-analysis/references/report_list.md +3 -3
- package/skills/ae-analysis/references/scenario_append.md +2 -2
- package/skills/ae-analysis/references/scenario_collect.md +15 -4
- package/skills/ae-analysis/references/scenario_list.md +2 -1
- package/skills/ae-analysis/references/system_oauth2_update.md +3 -1
- package/skills/ae-analysis/references/system_third_party_login_upsert.md +4 -2
- package/skills/ae-analysis/references/user_tag_create.md +4 -1
- package/skills/ae-analysis/references/user_tag_get.md +2 -0
- package/skills/ae-analysis/references/user_tag_models.md +8 -2
- package/skills/ae-analysis/references/user_tag_update.md +5 -2
- package/skills/ae-analysis/references/virtual_property_create.md +12 -1
- package/skills/ae-analysis/references/virtual_property_sql_rule_update.md +10 -0
- package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +55 -13
- package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +2 -2
- package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-rules.md +2 -2
- package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +7 -1
- package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/wait-compile-run.mjs +79 -0
- package/skills/ae-automation/SKILL.md +4 -2
- package/skills/ae-capability/SKILL.md +9 -5
- package/skills/ae-community/SKILL.md +1 -0
- package/skills/ae-dataops/SKILL.md +1 -0
- package/skills/ae-engage/SKILL.md +1 -0
- package/skills/ae-evaluation/SKILL.md +17 -2
- package/skills/ae-experiment/SKILL.md +38 -11
- package/skills/ae-experiment/references/experiment_approval.md +171 -0
- package/skills/ae-experiment/references/manage_experiment.md +11 -2
- package/skills/ae-experiment/references/save_experiment.md +28 -8
- package/skills/ae-experiment/references/save_submit_experiment.md +18 -3
- package/skills/ae-experiment/references/save_submit_external_experiment.md +57 -3
- package/skills/ae-generate-tracking-plan/SKILL.md +5 -0
- package/skills/ae-kb/SKILL.md +5 -3
- package/skills/ae-kb/references/analysis-workflow.md +11 -2
- package/skills/ae-kb/references/query-workflow.md +3 -1
- package/skills/ae-kb/references/versions.md +1 -1
- package/skills/ae-metadata/SKILL.md +1 -0
- package/skills/ae-migrate-tracking-code/SKILL.md +2 -1
- package/skills/ae-team/SKILL.md +1 -1
- package/skills/ae-tracking-matrix/SKILL.md +170 -0
- package/skills/ae-tracking-matrix/assets//345/237/213/347/202/271/346/250/241/347/211/210.xlsx +0 -0
- package/skills/ae-tracking-matrix/i18n.yaml +12 -0
- package/skills/ae-tracking-matrix/references/ae-capabilities.md +93 -0
- package/skills/ae-tracking-matrix/references/business-semantic-checks.md +30 -0
- package/skills/ae-tracking-matrix/references/categories/acquaintance_social_tracking_plan_template.md +256 -0
- package/skills/ae-tracking-matrix/references/categories/blockchain_game_tracking_plan_template.md +213 -0
- package/skills/ae-tracking-matrix/references/categories/card_game_tracking_plan_template.md +407 -0
- package/skills/ae-tracking-matrix/references/categories/casual_game_tracking_plan_template.md +218 -0
- package/skills/ae-tracking-matrix/references/categories/casual_music.md +112 -0
- package/skills/ae-tracking-matrix/references/categories/chess_cards_tracking_plan_template.md +301 -0
- package/skills/ae-tracking-matrix/references/categories/ecommerce_tracking_plan_template.md +356 -0
- package/skills/ae-tracking-matrix/references/categories/fishing.md +775 -0
- package/skills/ae-tracking-matrix/references/categories/game_basic_module_tracking_plan.md +89 -0
- package/skills/ae-tracking-matrix/references/categories/idle_card.md +27 -0
- package/skills/ae-tracking-matrix/references/categories/idle_game_tracking_plan_template.md +415 -0
- package/skills/ae-tracking-matrix/references/categories/interactive_video.md +133 -0
- package/skills/ae-tracking-matrix/references/categories/merge.md +639 -0
- package/skills/ae-tracking-matrix/references/categories/mmo_mobile_tracking_plan_template.md +406 -0
- package/skills/ae-tracking-matrix/references/categories/mmo_web.md +230 -0
- package/skills/ae-tracking-matrix/references/categories/music.md +137 -0
- package/skills/ae-tracking-matrix/references/categories/online_education_tracking_plan_template.md +414 -0
- package/skills/ae-tracking-matrix/references/categories/qipai_mj.md +199 -0
- package/skills/ae-tracking-matrix/references/categories/reading_tracking_plan_template.md +158 -0
- package/skills/ae-tracking-matrix/references/categories/roguelike_tracking_plan_template.md +546 -0
- package/skills/ae-tracking-matrix/references/categories/rpg.md +195 -0
- package/skills/ae-tracking-matrix/references/categories/short_drama_tracking_plan_template.md +115 -0
- package/skills/ae-tracking-matrix/references/categories/simulation_business_tracking_plan_template.md +151 -0
- package/skills/ae-tracking-matrix/references/categories/slg_tracking_plan_template.md +260 -0
- package/skills/ae-tracking-matrix/references/categories/slots_tracking_plan_template.md +232 -0
- package/skills/ae-tracking-matrix/references/categories/stranger_social_tracking_plan_template.md +359 -0
- package/skills/ae-tracking-matrix/references/categories/tower_defense.md +365 -0
- package/skills/ae-tracking-matrix/references/categories/video_editor_tracking_plan_template.md +211 -0
- package/skills/ae-tracking-matrix/references/categories/wechat_minigame.md +132 -0
- package/skills/ae-tracking-matrix/references/category-registry.md +77 -0
- package/skills/ae-tracking-matrix/references/data-verification/diagnosis_kb.md +230 -0
- package/skills/ae-tracking-matrix/references/data-verification/sql_checks.md +406 -0
- package/skills/ae-tracking-matrix/references/data-verification/tracking_plan_comparison.md +128 -0
- package/skills/ae-tracking-matrix/references/eval-cases.md +74 -0
- package/skills/ae-tracking-matrix/references/naming-dict.md +238 -0
- package/skills/ae-tracking-matrix/references/optimization-checklist.md +85 -0
- package/skills/ae-tracking-matrix/references/plan-generation/export-schema.md +142 -0
- package/skills/ae-tracking-matrix/references/plan-generation/module-baseline.md +47 -0
- package/skills/ae-tracking-matrix/references/plan-generation/reference.md +794 -0
- package/skills/ae-tracking-matrix/references/plan-generation/template-catalog.md +94 -0
- package/skills/ae-tracking-matrix/references/scene-routing.md +80 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/android.md +3787 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/c.md +827 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-lua.md +655 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-x.md +953 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocoscreator.md +1128 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/corona.md +714 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/egret.md +1268 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/flutter.md +776 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/h5-and-app-sdk-integration.md +182 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/ios.md +2755 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/javascript.md +1182 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/layaair.md +1300 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/macos.md +1369 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/mini-program-mini-game.md +1692 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/openharmony.md +902 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/react-native.md +763 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/uni-app.md +1107 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/unity.md +1532 -0
- package/skills/ae-tracking-matrix/references/sdk/client-sdk/unreal.md +845 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/android_sdk_faq.md +228 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/ios_sdk_faq.md +149 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/java_sdk_faq.md +407 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/javascript_sdk_faq.md +163 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/minigame_sdk_faq.md +149 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/miniprogram_sdk_faq.md +153 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/python_sdk_faq.md +232 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/sdk_log_guide.md +314 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/sdk_usage_notes.md +117 -0
- package/skills/ae-tracking-matrix/references/sdk/faq/unity_sdk_faq.md +148 -0
- package/skills/ae-tracking-matrix/references/sdk/integration-tools/filebeat-logstash-guide.md +645 -0
- package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_guide.md +307 -0
- package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_parser_plugin.md +347 -0
- package/skills/ae-tracking-matrix/references/sdk/integration-tools/restful_api_notes.md +72 -0
- package/skills/ae-tracking-matrix/references/sdk/integration-tools/ta-datax-writer-guide.md +264 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/c.md +566 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/erlang.md +409 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/golang.md +446 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/java.md +557 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/lua.md +457 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/nodejs.md +490 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/php.md +523 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/python.md +484 -0
- package/skills/ae-tracking-matrix/references/sdk/server-sdk/ruby.md +442 -0
- package/skills/ae-tracking-matrix/references/sdk/te-data-rules/data-rules.md +391 -0
- package/skills/ae-tracking-matrix/references/sdk/te-data-rules/first-event-validation.md +91 -0
- package/skills/ae-tracking-matrix/references/sdk/te-data-rules/preset-properties-system-fields.md +635 -0
- package/skills/ae-tracking-matrix/references/sdk/te-data-rules/updatable-events.md +113 -0
- package/skills/ae-tracking-matrix/references/sdk/te-data-rules/user-identification-rules.md +466 -0
- package/skills/ae-tracking-matrix/references/standard-base/README.md +22 -0
- package/skills/ae-tracking-matrix/references/standard-base/basic_event_data.md +174 -0
- package/skills/ae-tracking-matrix/references/standard-base/common_event_properties.md +20 -0
- package/skills/ae-tracking-matrix/references/standard-base/common_event_properties_setup.md +7 -0
- package/skills/ae-tracking-matrix/references/standard-base/data_type_design_principles.md +14 -0
- package/skills/ae-tracking-matrix/references/standard-base/gameplay_event_data.md +370 -0
- package/skills/ae-tracking-matrix/references/standard-base/id_system_faq.md +47 -0
- package/skills/ae-tracking-matrix/references/standard-base/integration_must_know.md +37 -0
- package/skills/ae-tracking-matrix/references/standard-base/multi_platform_integration_notes.md +27 -0
- package/skills/ae-tracking-matrix/references/standard-base/multi_user_id_system_recommendations.md +23 -0
- package/skills/ae-tracking-matrix/references/standard-base/tracking_notes.md +14 -0
- package/skills/ae-tracking-matrix/references/standard-base/user_data.md +46 -0
- package/skills/ae-tracking-matrix/references/standard-base/user_id_system.md +13 -0
- package/skills/ae-tracking-matrix/references/system-fields.md +297 -0
- package/skills/ae-tracking-matrix/references/te-field-translations.md +1791 -0
- package/skills/ae-tracking-matrix/references/workflows/data-verification.md +232 -0
- package/skills/ae-tracking-matrix/references/workflows/feasibility-analysis.md +829 -0
- package/skills/ae-tracking-matrix/references/workflows/integration-qna.md +355 -0
- package/skills/ae-tracking-matrix/references/workflows/plan-generation.md +283 -0
- package/skills/ae-tracking-matrix/references/workflows/plan-lint.md +168 -0
- package/skills/ae-tracking-matrix/references/workflows/plan-review-optimize.md +205 -0
- package/skills/ae-tracking-matrix/references/workflows/prd-to-suggestions.md +75 -0
- package/skills/ae-tracking-matrix/references/workflows/troubleshooting.md +36 -0
- package/skills/ae-tracking-matrix/references/workflows/validated-upload.md +107 -0
- package/skills/ae-tracking-matrix/scripts/build_template_catalog.py +114 -0
- package/skills/ae-tracking-matrix/scripts/export_tracking_plan.py +53 -0
- package/skills/ae-tracking-matrix/scripts/finalize_plan.py +166 -0
- package/skills/ae-tracking-matrix/scripts/lint_tracking_plan.py +674 -0
- package/skills/ae-tracking-matrix/scripts/plan_contract.py +200 -0
- package/skills/ae-tracking-matrix/scripts/plan_types.py +60 -0
- package/skills/ae-tracking-matrix/scripts/prepare_delivery.py +169 -0
- package/skills/ae-tracking-matrix/scripts/sync_plan.py +296 -0
- package/skills/ae-tracking-matrix/scripts/upload_plan.py +340 -0
- package/dist/chunk-AMBFK2K3.js +0 -28
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Shared, local-only contract for chat, 11-sheet XLSX and upload gates.
|
|
3
|
+
|
|
4
|
+
No API calls, credential reads, translations or implicit business-field fixes.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from copy import deepcopy
|
|
9
|
+
import hashlib
|
|
10
|
+
import json
|
|
11
|
+
import re
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from plan_types import normalize_property_type, normalize_update_method
|
|
15
|
+
|
|
16
|
+
DATA_HEADERS = {
|
|
17
|
+
"#用户ID体系": ["游戏类型", "属性名", "属性显示名", "属性说明", "赋值说明"],
|
|
18
|
+
"#事件数据": ["事件名(必填)", "事件显示名", "事件说明", "事件标签", "采集端", "属性名(必填)", "属性显示名", "属性类型(必填)", "属性说明"],
|
|
19
|
+
"#公共事件属性": ["属性名(必填)", "属性显示名", "属性类型(必填)", "属性说明"],
|
|
20
|
+
"#用户数据": ["属性名(必填)", "属性显示名", "属性类型(必填)", "更新方式", "属性说明"],
|
|
21
|
+
}
|
|
22
|
+
SHEET_NAMES = ("接入必知", "埋点注意事项", "#用户ID体系", "#事件数据", "#公共事件属性", "#用户数据", "数据类型设计原则", "公共事件属性设置方式", "多端接入注意点", "多用户ID体系的埋点建议", "ID体系常见疑问")
|
|
23
|
+
INSTRUCTION_SHEETS = tuple(s for s in SHEET_NAMES if s not in DATA_HEADERS)
|
|
24
|
+
PLAN_UPDATE_METHODS = {"user_set", "user_setOnce", "user_add", "user_append"}
|
|
25
|
+
BUSINESS_CONTEXT_FIELDS = ("business_context", "notes", "timezone", "metric_mapping", "change_log", "assumptions", "open_questions", "blocking_unknowns")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def business_context_text(plan):
|
|
29
|
+
# Retained in a data-header comment, never by altering the seven instruction sheets.
|
|
30
|
+
return json.dumps({key: plan.get("meta", {}).get(key) for key in BUSINESS_CONTEXT_FIELDS}, ensure_ascii=False, sort_keys=True, indent=2)
|
|
31
|
+
NAME_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,49}$")
|
|
32
|
+
PROP_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$")
|
|
33
|
+
XML_ILLEGAL_RE = re.compile(r"[\x00-\x08\x0B\x0C\x0E-\x1F]")
|
|
34
|
+
DEFAULT_TEMPLATE = Path(__file__).resolve().parents[1] / "assets" / "埋点模版.xlsx"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class PlanError(ValueError):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def string(value, path, required=False):
|
|
42
|
+
if value is None and not required:
|
|
43
|
+
return ""
|
|
44
|
+
if not isinstance(value, str):
|
|
45
|
+
raise PlanError(f"{path}: expected a string, not {type(value).__name__}")
|
|
46
|
+
if required and not value.strip():
|
|
47
|
+
raise PlanError(f"{path}: required non-empty string")
|
|
48
|
+
if XML_ILLEGAL_RE.search(value):
|
|
49
|
+
raise PlanError(f"{path}: illegal XML control character")
|
|
50
|
+
if len(value) > 32767:
|
|
51
|
+
raise PlanError(f"{path}: exceeds Excel's cell text limit")
|
|
52
|
+
return value
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def records(value, path):
|
|
56
|
+
if not isinstance(value, list):
|
|
57
|
+
raise PlanError(f"{path}: expected an array")
|
|
58
|
+
if any(not isinstance(v, dict) for v in value):
|
|
59
|
+
raise PlanError(f"{path}: entries must be objects")
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def named(record, key, path, prop=False):
|
|
64
|
+
name = string(record.get(key), f"{path}.{key}", True)
|
|
65
|
+
rule = PROP_RE if prop else NAME_RE
|
|
66
|
+
if len(name) > 50 or not rule.fullmatch(name):
|
|
67
|
+
raise PlanError(f"{path}.{key}: invalid custom {'property' if prop else 'event'} name {name!r}; system # fields belong in the ID sheet, not custom properties")
|
|
68
|
+
return name
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def allowed_keys(record, allowed, path):
|
|
72
|
+
extras = set(record) - set(allowed)
|
|
73
|
+
if extras:
|
|
74
|
+
raise PlanError(f"{path}: unsupported fields {sorted(extras)}; preserve their business meaning explicitly in description/remarks instead of silently dropping them")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def merge_notes(record, path):
|
|
78
|
+
if "remarks" in record:
|
|
79
|
+
notes = string(record.pop("remarks"), f"{path}.remarks")
|
|
80
|
+
if notes:
|
|
81
|
+
record["description"] += ("\n" if record["description"] else "") + notes
|
|
82
|
+
if len(record["description"]) > 32767:
|
|
83
|
+
raise PlanError(f"{path}: combined description exceeds Excel's cell text limit")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def normalize_plan(source):
|
|
87
|
+
if not isinstance(source, dict):
|
|
88
|
+
raise PlanError("root: expected an object")
|
|
89
|
+
allowed_keys(source, {"meta", "user_id_sheet", "events", "common_event_properties", "user_properties"}, "root")
|
|
90
|
+
plan = deepcopy(source)
|
|
91
|
+
meta = plan.setdefault("meta", {})
|
|
92
|
+
if not isinstance(meta, dict):
|
|
93
|
+
raise PlanError("meta: expected an object")
|
|
94
|
+
meta["xlsx_language"] = "zh"
|
|
95
|
+
for key in ("user_id_sheet", "events", "common_event_properties", "user_properties"):
|
|
96
|
+
if key not in plan:
|
|
97
|
+
raise PlanError(f"{key}: required array (may be empty except events)")
|
|
98
|
+
records(plan[key], key)
|
|
99
|
+
if not plan["events"]:
|
|
100
|
+
raise PlanError("events: an empty tracking plan is not a deliverable")
|
|
101
|
+
|
|
102
|
+
def prop(record, path, user=False):
|
|
103
|
+
allowed_keys(record, {"property_name", "display_name", "property_type", "description", "remarks"} | ({"update_method"} if user else set()), path)
|
|
104
|
+
named(record, "property_name", path, True)
|
|
105
|
+
for key in ("display_name", "description"):
|
|
106
|
+
record[key] = string(record.get(key), f"{path}.{key}", True)
|
|
107
|
+
merge_notes(record, path)
|
|
108
|
+
try:
|
|
109
|
+
record["property_type"] = normalize_property_type(record.get("property_type"))
|
|
110
|
+
except ValueError as exc:
|
|
111
|
+
raise PlanError(f"{path}.property_type: {exc}") from exc
|
|
112
|
+
if user:
|
|
113
|
+
try:
|
|
114
|
+
record["update_method"] = normalize_update_method(record.get("update_method"))
|
|
115
|
+
except ValueError as exc:
|
|
116
|
+
raise PlanError(f"{path}.update_method: {exc}") from exc
|
|
117
|
+
if record["update_method"] not in PLAN_UPDATE_METHODS:
|
|
118
|
+
raise PlanError(f"{path}.update_method: timing is not a plan update operation; confirm one of {sorted(PLAN_UPDATE_METHODS)}")
|
|
119
|
+
if record["update_method"] == "user_add" and record["property_type"] != "数值":
|
|
120
|
+
raise PlanError(f"{path}: user_add requires a numeric property")
|
|
121
|
+
if record["update_method"] == "user_append" and record["property_type"] != "列表":
|
|
122
|
+
raise PlanError(f"{path}: user_append requires a list property")
|
|
123
|
+
|
|
124
|
+
for i, record in enumerate(plan["user_id_sheet"]):
|
|
125
|
+
allowed_keys(record, {"product_type", "property_name", "display_name", "description", "assignment", "remarks"}, f"user_id_sheet[{i}]")
|
|
126
|
+
for key in ("product_type", "property_name", "display_name", "description", "assignment", "remarks"):
|
|
127
|
+
record[key] = string(record.get(key, ""), f"user_id_sheet[{i}].{key}", key in ("property_name", "display_name", "assignment"))
|
|
128
|
+
seen_events = set()
|
|
129
|
+
for i, event in enumerate(plan["events"]):
|
|
130
|
+
path = f"events[{i}]"
|
|
131
|
+
allowed_keys(event, {"event_name", "display_name", "description", "tag", "platform", "properties", "remarks"}, path)
|
|
132
|
+
name = named(event, "event_name", path)
|
|
133
|
+
if name in seen_events:
|
|
134
|
+
raise PlanError(f"{path}: duplicate event {name}")
|
|
135
|
+
seen_events.add(name)
|
|
136
|
+
for key in ("display_name", "description"):
|
|
137
|
+
event[key] = string(event.get(key), f"{path}.{key}", True)
|
|
138
|
+
merge_notes(event, path)
|
|
139
|
+
event["tag"] = string(event.get("tag", ""), f"{path}.tag")
|
|
140
|
+
platform = string(event.get("platform", ""), f"{path}.platform").strip()
|
|
141
|
+
platforms = {"": "", "C": "client", "S": "server", "client": "client", "server": "server", "both": "client,server", "S+C": "client,server", "C+S": "client,server", "client,server": "client,server"}
|
|
142
|
+
if platform not in platforms:
|
|
143
|
+
raise PlanError(f"{path}.platform: use client/server/both (legacy C/S accepted)")
|
|
144
|
+
event["platform"] = platforms[platform]
|
|
145
|
+
event.setdefault("properties", [])
|
|
146
|
+
seen_props = set()
|
|
147
|
+
for j, record in enumerate(records(event["properties"], f"{path}.properties")):
|
|
148
|
+
prop(record, f"{path}.properties[{j}]")
|
|
149
|
+
if record["property_name"] in seen_props:
|
|
150
|
+
raise PlanError(f"{path}: duplicate property {record['property_name']}")
|
|
151
|
+
seen_props.add(record["property_name"])
|
|
152
|
+
for key in ("common_event_properties", "user_properties"):
|
|
153
|
+
seen = set()
|
|
154
|
+
for i, record in enumerate(plan[key]):
|
|
155
|
+
prop(record, f"{key}[{i}]", key == "user_properties")
|
|
156
|
+
if record["property_name"] in seen:
|
|
157
|
+
raise PlanError(f"{key}: duplicate property {record['property_name']}")
|
|
158
|
+
seen.add(record["property_name"])
|
|
159
|
+
return plan
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def data_rows(plan):
|
|
163
|
+
"""Canonical import rows, shared with round-trip verification."""
|
|
164
|
+
rows = {key: [] for key in DATA_HEADERS}
|
|
165
|
+
for p in plan["user_id_sheet"]:
|
|
166
|
+
description = p["description"]
|
|
167
|
+
if p.get("remarks"):
|
|
168
|
+
description += ("\n" if description else "") + p["remarks"]
|
|
169
|
+
rows["#用户ID体系"].append([p["product_type"], p["property_name"], p["display_name"], description, p["assignment"]])
|
|
170
|
+
for event in plan["events"]:
|
|
171
|
+
base = [event["event_name"], event["display_name"], event["description"], event["tag"], event["platform"]]
|
|
172
|
+
for p in event["properties"] or [None]:
|
|
173
|
+
rows["#事件数据"].append(base + ([p["property_name"], p["display_name"], p["property_type"], p["description"]] if p else ["", "", "", ""]))
|
|
174
|
+
for p in plan["common_event_properties"]:
|
|
175
|
+
rows["#公共事件属性"].append([p["property_name"], p["display_name"], p["property_type"], p["description"]])
|
|
176
|
+
for p in plan["user_properties"]:
|
|
177
|
+
rows["#用户数据"].append([p["property_name"], p["display_name"], p["property_type"], p["update_method"], p["description"]])
|
|
178
|
+
return rows
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def counts(plan):
|
|
182
|
+
return {"events": len(plan["events"]), "event_property_rows": sum(len(e["properties"]) for e in plan["events"]), "event_properties_unique": len({p["property_name"] for e in plan["events"] for p in e["properties"]}), "common_event_properties": len(plan["common_event_properties"]), "user_properties": len(plan["user_properties"]), "id_rules": len(plan["user_id_sheet"])}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def json_bytes(value):
|
|
186
|
+
return (json.dumps(value, ensure_ascii=False, sort_keys=True, indent=2) + "\n").encode("utf-8")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def file_sha256(path):
|
|
190
|
+
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def ensure_new_path(path, protected=()):
|
|
194
|
+
path = Path(path)
|
|
195
|
+
resolved = path.resolve()
|
|
196
|
+
if any(resolved == Path(p).resolve() for p in protected):
|
|
197
|
+
raise PlanError(f"Output aliases a protected input: {path}")
|
|
198
|
+
if path.exists() or path.is_symlink():
|
|
199
|
+
raise PlanError(f"Refusing to overwrite existing output: {path}")
|
|
200
|
+
return path
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Shared, lossless tracking-plan enum normalization (no I/O or SDK calls)."""
|
|
2
|
+
|
|
3
|
+
VALID_PROP_TYPES = frozenset({"文本", "数值", "布尔", "时间", "对象", "对象组", "列表"})
|
|
4
|
+
|
|
5
|
+
_TYPE_ALIASES = {
|
|
6
|
+
**{value: value for value in VALID_PROP_TYPES},
|
|
7
|
+
"字符串": "文本",
|
|
8
|
+
"text": "文本",
|
|
9
|
+
"string": "文本",
|
|
10
|
+
"number": "数值",
|
|
11
|
+
"boolean": "布尔",
|
|
12
|
+
"bool": "布尔",
|
|
13
|
+
"datetime": "时间",
|
|
14
|
+
"date": "时间",
|
|
15
|
+
"time": "时间",
|
|
16
|
+
"object": "对象",
|
|
17
|
+
"row": "对象",
|
|
18
|
+
"object_group": "对象组",
|
|
19
|
+
"object group": "对象组",
|
|
20
|
+
"array_row": "对象组",
|
|
21
|
+
"array row": "对象组",
|
|
22
|
+
"object[]": "对象组",
|
|
23
|
+
"object array": "对象组",
|
|
24
|
+
"object_array": "对象组",
|
|
25
|
+
"list": "列表",
|
|
26
|
+
"array_string": "列表",
|
|
27
|
+
"string[]": "列表",
|
|
28
|
+
"string array": "列表",
|
|
29
|
+
"string_array": "列表",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Plan declaration enums are narrower than SDK operations. In particular,
|
|
33
|
+
# deletion/unset/unique-append SDK APIs are NOT valid plan update methods.
|
|
34
|
+
CANONICAL_UPDATE_METHODS = frozenset({"user_set", "user_setOnce", "user_add", "user_append"})
|
|
35
|
+
LEGACY_UPDATE_METHODS = frozenset({"上报时", "登录时", "仅首次"})
|
|
36
|
+
VALID_UPDATE_METHODS = CANONICAL_UPDATE_METHODS | LEGACY_UPDATE_METHODS
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def normalize_property_type(value) -> str:
|
|
40
|
+
"""Return one of the seven Chinese types; English aliases ignore case.
|
|
41
|
+
|
|
42
|
+
Whitespace is trimmed. Object and object-group semantics remain distinct.
|
|
43
|
+
Blank, non-string and unknown values raise ValueError rather than guessing.
|
|
44
|
+
"""
|
|
45
|
+
if isinstance(value, str):
|
|
46
|
+
canonical = _TYPE_ALIASES.get(value.strip().casefold())
|
|
47
|
+
if canonical is not None:
|
|
48
|
+
return canonical
|
|
49
|
+
raise ValueError(f"Unknown property type: {value!r}")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def normalize_update_method(value) -> str:
|
|
53
|
+
"""Preserve a supported API operation or legacy timing, trimming whitespace.
|
|
54
|
+
|
|
55
|
+
API spelling is case-sensitive; unknown/blank/non-string values raise
|
|
56
|
+
ValueError. No API operation is translated into a legacy timing label.
|
|
57
|
+
"""
|
|
58
|
+
if isinstance(value, str) and value.strip() in VALID_UPDATE_METHODS:
|
|
59
|
+
return value.strip()
|
|
60
|
+
raise ValueError(f"Unknown update method: {value!r}")
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Prepare a conversation-first delivery, with optional 11-sheet XLSX output.
|
|
3
|
+
|
|
4
|
+
All artifacts derive from one normalized source. This command is entirely local;
|
|
5
|
+
it NEVER uploads. Conversation-only mode defers Excel until the user chooses it.
|
|
6
|
+
A clean lint is not equivalent to semantic review or consent.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
import argparse
|
|
10
|
+
import html
|
|
11
|
+
import json
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
|
|
17
|
+
from finalize_plan import write_finalized_plan
|
|
18
|
+
from plan_contract import (DEFAULT_TEMPLATE, PlanError, normalize_plan, counts,
|
|
19
|
+
json_bytes, file_sha256)
|
|
20
|
+
|
|
21
|
+
REVIEW_CHECKS = (
|
|
22
|
+
("metric_coverage", "Metrics can be computed from the selected events, grain and windows"),
|
|
23
|
+
("identity", "Identity rules match account/guest/multi-role design"),
|
|
24
|
+
("trigger_semantics", "Names, triggers, examples and reporting granularity agree"),
|
|
25
|
+
("property_registry", "Same-name properties have consistent meaning/type/unit/enumeration"),
|
|
26
|
+
("preset_fields", "No duplicated preset fields or invented auto-collection guarantees"),
|
|
27
|
+
("object_structure", "Object/object-group cardinality and child schemas are appropriate"),
|
|
28
|
+
("correlation", "Request/result and exposure/click chains have valid join keys"),
|
|
29
|
+
("reporting_authority", "Client/server authority and dual-report deduplication are explicit"),
|
|
30
|
+
("ads_chain", "IAA: ad_show/complete/reward/fail covered; revenue callback/TBC explicitly addressed"),
|
|
31
|
+
("attribution", "First-touch first_media_source/first_campaign separated from current attribution"),
|
|
32
|
+
("user_updates", "User update operation matches type; SDK deletion is not a plan declaration"),
|
|
33
|
+
("privacy", "Personal data fields have a stated need and minimization review"),
|
|
34
|
+
("existing_plan_diff", "Additions/renames/removals and existing-plan conflicts are disclosed"),
|
|
35
|
+
("language_and_counts", "Reply language follows the user; event/property counts match source"),
|
|
36
|
+
("unknowns_and_delivery", "No blocking unknowns; chat and selected delivery artifacts are consistent; no unrequested Excel"),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def cell(value):
|
|
41
|
+
value=html.escape(str(value),quote=False)
|
|
42
|
+
for char in ("\\", "|", "`", "[", "]", "*", "_"):
|
|
43
|
+
value=value.replace(char,"\\"+char)
|
|
44
|
+
return value.replace("\r\n","\n").replace("\n","<br>")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def table(headers, rows):
|
|
48
|
+
result=["| "+" | ".join(cell(v) for v in headers)+" |", "| "+" | ".join("---" for _ in headers)+" |"]
|
|
49
|
+
result.extend("| "+" | ".join(cell(v) for v in row)+" |" for row in rows)
|
|
50
|
+
return "\n".join(result)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def render_context(value, zh):
|
|
54
|
+
if value is None or value == "" or value == [] or value == {}:
|
|
55
|
+
return "待确认/未提供;不据此推断事实。" if zh else "TBC / not supplied; no fact is inferred."
|
|
56
|
+
if isinstance(value,str):
|
|
57
|
+
return cell(value)
|
|
58
|
+
if isinstance(value,list) and all(isinstance(v,str) for v in value):
|
|
59
|
+
return "\n".join("- "+cell(v) for v in value)
|
|
60
|
+
if isinstance(value,list) and value and all(isinstance(v,dict) for v in value):
|
|
61
|
+
headers=list(dict.fromkeys(key for item in value for key in item))
|
|
62
|
+
return table(headers,[[item.get(key,"") for key in headers] for item in value])
|
|
63
|
+
if isinstance(value,dict):
|
|
64
|
+
return table(["字段","内容"] if zh else ["Field","Value"],list(value.items()))
|
|
65
|
+
return cell(value)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def render_conversation(plan, language="zh", machine_passed=False, review_only=False):
|
|
69
|
+
zh=language=="zh"
|
|
70
|
+
metrics=counts(plan)
|
|
71
|
+
title=plan.get("meta",{}).get("product_name") or ("埋点方案" if zh else "Tracking plan")
|
|
72
|
+
if review_only:
|
|
73
|
+
intro=("这是可在对话中直接审阅的方案概览。当前仅生成会话内容,尚未生成 Excel,也未同步至埋点管理页面。" if zh else "Review this plan overview in the conversation. No Excel file has been generated and nothing has been synced to Tracking Management.")
|
|
74
|
+
schema_note=("请先审阅方案并选择交付方式;选择之前不会自动生成 Excel 或执行同步。" if zh else "Review the plan and choose a delivery method; no Excel generation or sync starts before your choice.")
|
|
75
|
+
else:
|
|
76
|
+
intro=("这是可在对话中直接审阅的方案;配套完整 11-sheet 文件为 `plan.xlsx`。两者来自同一份方案数据。" if zh else "Review this plan directly in the conversation. The accompanying `plan.xlsx` contains all 11 sheets and uses the same source data.")
|
|
77
|
+
schema_note=("文件固定使用中文导入表头和类型枚举,业务内容不强制翻译。" if zh else "The XLSX uses the verified Chinese import headers and type enums; business content is not translated.")
|
|
78
|
+
parts=[f"# {cell(title)}", intro,
|
|
79
|
+
(f"事件:{metrics['events']};事件属性行:{metrics['event_property_rows']};去重事件属性:{metrics['event_properties_unique']};公共属性:{metrics['common_event_properties']};用户属性:{metrics['user_properties']}。" if zh else f"Events: {metrics['events']}; event-property rows: {metrics['event_property_rows']}; unique event properties: {metrics['event_properties_unique']}; common properties: {metrics['common_event_properties']}; user properties: {metrics['user_properties']}."),
|
|
80
|
+
schema_note, "## "+("用户 ID 体系" if zh else "Identity rules")]
|
|
81
|
+
ids=[[p['product_type'],p['property_name'],p['display_name'],p['assignment'],p['description'],p.get('remarks','')] for p in plan['user_id_sheet']]
|
|
82
|
+
parts.append(table(["产品类型","属性名","显示名","赋值规则","说明","备注"] if zh else ["Product","Property","Display name","Assignment","Description","Notes"], ids))
|
|
83
|
+
parts.append("## "+("事件总览" if zh else "Event overview"))
|
|
84
|
+
parts.append(table(["事件名","显示名","触发说明","模块","采集端","属性数"] if zh else ["Event","Display name","Trigger","Module","Collection side","Properties"],[[e['event_name'],e['display_name'],e['description'],e['tag'],e['platform'],len(e['properties'])] for e in plan['events']]))
|
|
85
|
+
parts.append("## "+("事件属性明细" if zh else "Event property details"))
|
|
86
|
+
rows=[[e['event_name'],p['property_name'],p['display_name'],p['property_type'],p['description']] for e in plan['events'] for p in e['properties']]
|
|
87
|
+
parts.append(table(["事件","属性名","显示名","类型","说明"] if zh else ["Event","Property","Display name","Type","Description"],rows))
|
|
88
|
+
parts.append("## "+("公共事件属性" if zh else "Common event properties"))
|
|
89
|
+
parts.append(table(["属性名","显示名","类型","说明"] if zh else ["Property","Display name","Type","Description"],[[p['property_name'],p['display_name'],p['property_type'],p['description']] for p in plan['common_event_properties']]))
|
|
90
|
+
parts.append("## "+("用户属性" if zh else "User properties"))
|
|
91
|
+
parts.append(table(["属性名","显示名","类型","更新操作","说明"] if zh else ["Property","Display name","Type","Update operation","Description"],[[p['property_name'],p['display_name'],p['property_type'],p['update_method'],p['description']] for p in plan['user_properties']]))
|
|
92
|
+
for key,cn,en in (("business_context","业务范围与口径","Business scope and definitions"),("notes","埋点注意事项","Tracking notes"),("timezone","时区说明","Timezone"),("metric_mapping","指标与事件映射","Metric-to-event mapping"),("change_log","变更与差异","Change log and differences"),("assumptions","假设与依据","Assumptions and evidence"),("open_questions","待确认项","Open questions"),("blocking_unknowns","阻塞项","Blocking unknowns")):
|
|
93
|
+
parts.append("## "+(cn if zh else en))
|
|
94
|
+
parts.append(render_context(plan.get('meta',{}).get(key),zh))
|
|
95
|
+
if review_only:
|
|
96
|
+
parts.append("## "+("请选择交付方式" if zh else "Choose a delivery method"))
|
|
97
|
+
if zh:
|
|
98
|
+
parts.append("1. **直接同步至数数埋点管理页面**:不生成本地 Excel。完成目标项目、已有方案冲突和业务语义检查后,我会再向你确认具体项目与同步范围。\n2. **生成本地 Excel 文件**:选择后才生成完整 11-sheet Excel,并执行对应校验。")
|
|
99
|
+
parts.append("请回复“同步至埋点管理”或“生成本地 Excel”。当前尚未生成 Excel,也未执行同步。")
|
|
100
|
+
else:
|
|
101
|
+
parts.append("1. **Sync directly to ThinkingData Tracking Management**: no local Excel deliverable. After target, baseline-conflict and semantic checks, I will confirm the exact project and sync scope with you.\n2. **Generate a local Excel file**: the complete 11-sheet workbook and its validation run only after you choose this option.")
|
|
102
|
+
parts.append("Reply 'Sync to Tracking Management' or 'Generate local Excel'. No Excel has been generated and no sync has run.")
|
|
103
|
+
else:
|
|
104
|
+
parts.append("## "+("验证与上传" if zh else "Validation and upload"))
|
|
105
|
+
if zh:
|
|
106
|
+
parts.append("机器校验:"+("通过。" if machine_passed else "未通过,需修复后重新生成。"))
|
|
107
|
+
parts.append("业务语义复核、目标项目与已有方案冲突检查尚未完成。机器校验通过不代表所有业务验收通过。全部门禁完成后,提供一次明确的“上传到埋点管理”确认;确认前不上传,不删除或覆盖现有方案。")
|
|
108
|
+
else:
|
|
109
|
+
parts.append("Machine validation: "+("passed." if machine_passed else "failed; fix the source and regenerate."))
|
|
110
|
+
parts.append("Semantic review, target-project verification and existing-plan conflict checks remain pending. A clean lint is not full business acceptance. Once all gates pass, offer one explicit 'Upload to Tracking Management' confirmation. Do not upload before consent or delete/replace an existing plan.")
|
|
111
|
+
return "\n\n".join(parts)+"\n"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def prepare(plan_path, output_dir, language="zh", template=DEFAULT_TEMPLATE, review_only=False):
|
|
115
|
+
root=Path(output_dir)
|
|
116
|
+
if root.exists() or root.is_symlink():
|
|
117
|
+
raise PlanError(f"Output directory must be new: {root}")
|
|
118
|
+
if language not in ("zh","en"):
|
|
119
|
+
raise PlanError("This deterministic conversation renderer supports zh/en; do not silently substitute another language")
|
|
120
|
+
with open(plan_path,encoding="utf-8") as f: source=json.load(f)
|
|
121
|
+
normalized=normalize_plan(source)
|
|
122
|
+
normalized['meta']['reply_language']=language
|
|
123
|
+
root.mkdir(parents=True,exist_ok=False)
|
|
124
|
+
source_out=root/'plan.normalized.json'
|
|
125
|
+
with source_out.open('xb') as f: f.write(json_bytes(normalized))
|
|
126
|
+
result=None
|
|
127
|
+
if review_only:
|
|
128
|
+
metrics=counts(normalized)
|
|
129
|
+
passed=None
|
|
130
|
+
else:
|
|
131
|
+
normalized, metrics=write_finalized_plan(normalized,root/'plan.xlsx',template,(plan_path,source_out))
|
|
132
|
+
command=[sys.executable,str(Path(__file__).with_name('lint_tracking_plan.py')),'--input',str(root/'plan.xlsx'),'--strict-delivery','--template',str(template)]
|
|
133
|
+
result=subprocess.run(command,capture_output=True,text=True,check=False)
|
|
134
|
+
with (root/'lint.txt').open('x',encoding='utf-8') as f: f.write(result.stdout+result.stderr)
|
|
135
|
+
passed=result.returncode==0
|
|
136
|
+
with (root/'conversation.md').open('x',encoding='utf-8') as f: f.write(render_conversation(normalized,language,passed,review_only))
|
|
137
|
+
artifact_names=('plan.normalized.json','conversation.md') if review_only else ('plan.normalized.json','plan.xlsx','conversation.md')
|
|
138
|
+
fingerprints={name:file_sha256(root/name) for name in artifact_names}
|
|
139
|
+
machine_validation=({"passed":None,"status":"not_run_excel_not_requested"} if review_only else {"passed":passed,"exit_code":result.returncode,"strict_delivery":True,"round_trip":True,"instruction_sheets_preserved":True,"template_sha256":file_sha256(template)})
|
|
140
|
+
status="review_ready_delivery_choice_pending" if review_only else ("machine_passed_semantic_pending" if passed else "machine_failed")
|
|
141
|
+
pending=(["delivery_choice","semantic_review"] if review_only else ["semantic_review","verified_target_and_baseline","user_upload_confirmation","remote_readback"])
|
|
142
|
+
validation={"schema_version":1,"package_version":"2.0.2","created_at":datetime.now(timezone.utc).isoformat(),"status":status,"machine_validation":machine_validation,"counts":metrics,"fingerprints":fingerprints,"xlsx_language":"zh","reply_language":language,"delivery_choice_pending":review_only,"upload_eligible":False,"upload_status":"not_requested","pending":pending}
|
|
143
|
+
with (root/'validation.json').open('xb') as f: f.write(json_bytes(validation))
|
|
144
|
+
review={"schema_version":1,"status":"pending","fingerprints":fingerprints,"reviewer":"","checks":[{"id":key,"description":description,"status":"pending","evidence":""} for key,description in REVIEW_CHECKS],"blocking_unknowns":[],"target":{"project_id":None,"host":""},"baseline_sha256":"","conflicts_resolved":False,"notes":"Complete using real evidence; never auto-mark all checks passed. This file is not upload consent."}
|
|
145
|
+
with (root/'semantic-review.template.json').open('xb') as f: f.write(json_bytes(review))
|
|
146
|
+
return validation
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def main(argv=None):
|
|
150
|
+
ap=argparse.ArgumentParser(description=__doc__)
|
|
151
|
+
ap.add_argument('--plan',required=True)
|
|
152
|
+
ap.add_argument('--output-dir',required=True)
|
|
153
|
+
ap.add_argument('--language',choices=['zh','en'],default='zh')
|
|
154
|
+
ap.add_argument('--template',default=str(DEFAULT_TEMPLATE))
|
|
155
|
+
ap.add_argument('--conversation-only',action='store_true',
|
|
156
|
+
help='Render the review first; do not generate XLSX before a delivery choice')
|
|
157
|
+
args=ap.parse_args(argv)
|
|
158
|
+
try:
|
|
159
|
+
result=prepare(args.plan,args.output_dir,args.language,args.template,
|
|
160
|
+
review_only=args.conversation_only)
|
|
161
|
+
print(json.dumps(result,ensure_ascii=False,indent=2))
|
|
162
|
+
return 0 if args.conversation_only or result['machine_validation']['passed'] else 2
|
|
163
|
+
except (ValueError,OSError,KeyError) as exc:
|
|
164
|
+
print(f"ERROR: {exc}",file=sys.stderr)
|
|
165
|
+
return 1
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__=='__main__':
|
|
169
|
+
raise SystemExit(main())
|