@thinkingai/ae-cli 6.0.20 → 6.0.22

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 (70) hide show
  1. package/README.md +1 -4
  2. package/README.zh.md +1 -4
  3. package/dist/{auth-DYC2BGLM.js → auth-I2G7OAU2.js} +2 -4
  4. package/dist/{auth-GHBMJ5ZR.js → auth-RDN6D5HU.js} +32 -104
  5. package/dist/{chunk-5OC7CYCG.js → chunk-2W7HULUD.js} +14 -14
  6. package/dist/chunk-4EUZRJPO.js +163 -0
  7. package/dist/{chunk-DMMEPCST.js → chunk-5FBLRSMU.js} +25 -115
  8. package/dist/{chunk-BJX3GXWC.js → chunk-E34XH4GW.js} +2 -2
  9. package/dist/chunk-FPE5LGVU.js +105 -0
  10. package/dist/{chunk-I5CRVM2S.js → chunk-H52CSLJW.js} +44 -17
  11. package/dist/{chunk-RSHMZ3LG.js → chunk-U6QPKCN3.js} +6 -20
  12. package/dist/{chunk-6W4QOZAL.js → chunk-WPXHCP4A.js} +23 -13
  13. package/dist/{chunk-PN3OS34E.js → chunk-XE2PI5DS.js} +1 -1
  14. package/dist/{chunk-2DUEAXV3.js → chunk-YACCPUNQ.js} +1 -1
  15. package/dist/cli-token-6AGEDJF4.js +14 -0
  16. package/dist/{client-2UJ63MVQ.js → client-VTJMUZ4O.js} +3 -3
  17. package/dist/{config-NCUGK6NS.js → config-2SDTLGOC.js} +3 -3
  18. package/dist/index.js +309 -197
  19. package/dist/metadata-JZ2OTWBK.js +420 -0
  20. package/dist/{model-SJSOZTRS.js → model-ZYMRN4VS.js} +2 -2
  21. package/dist/{raw-7NVWSVJP.js → raw-NGYHAL3F.js} +4 -4
  22. package/dist/{sync-GRVO4K3U.js → sync-JVLX6TGW.js} +3 -3
  23. package/dist/{te-agent-CYZUC4US.js → te-agent-QPZTLHPH.js} +2 -2
  24. package/dist/{te-analysis-HJ22TUAA.js → te-analysis-WWX3Z6RP.js} +46 -24
  25. package/dist/{te-audience-MYDE5WEH.js → te-audience-UXGHUVBB.js} +27 -18
  26. package/dist/{te-common-WNCZB7R7.js → te-common-7XXH73MF.js} +5 -4
  27. package/dist/{te-community-JEEFXPB3.js → te-community-QKE67HR2.js} +5 -4
  28. package/dist/{te-dataops-ZTS7XMXM.js → te-dataops-6W7NNYST.js} +4 -5
  29. package/dist/{te-engage-4XHCTS6I.js → te-engage-NCFAQFX3.js} +5 -4
  30. package/dist/{te-kb-OWM3RQRH.js → te-kb-K5BQYUCM.js} +4 -5
  31. package/dist/{te-meta-JVO4QJBH.js → te-meta-LJZBOSMO.js} +26 -19
  32. package/dist/{te-team-YY24VORI.js → te-team-DHK5R7MV.js} +5 -6
  33. package/package.json +3 -2
  34. package/skills/ae-analysis/SKILL.md +9 -2
  35. package/skills/ae-analysis/references/build_attribution_analysis_qp.md +2 -0
  36. package/skills/ae-analysis/references/build_cluster_definition.md +2 -0
  37. package/skills/ae-analysis/references/build_distribution_analysis_qp.md +2 -0
  38. package/skills/ae-analysis/references/build_event_analysis_qp.md +2 -0
  39. package/skills/ae-analysis/references/build_funnel_analysis_qp.md +2 -0
  40. package/skills/ae-analysis/references/build_heat_map_analysis_qp.md +2 -0
  41. package/skills/ae-analysis/references/build_interval_analysis_qp.md +2 -0
  42. package/skills/ae-analysis/references/build_path_analysis_qp.md +2 -0
  43. package/skills/ae-analysis/references/build_prop_analysis_qp.md +2 -0
  44. package/skills/ae-analysis/references/build_rank_list_analysis_qp.md +2 -0
  45. package/skills/ae-analysis/references/build_retention_analysis_qp.md +2 -0
  46. package/skills/ae-analysis/references/build_tag_definition.md +2 -0
  47. package/skills/ae-analysis/references/list_clusters.md +3 -1
  48. package/skills/ae-analysis/references/list_events.md +5 -2
  49. package/skills/ae-analysis/references/list_metrics.md +4 -2
  50. package/skills/ae-analysis/references/list_properties.md +4 -2
  51. package/skills/ae-analysis/references/list_tags.md +3 -1
  52. package/skills/ae-generate-tracking-code/SKILL.md +68 -31
  53. package/skills/ae-generate-tracking-code/references/snippet-delivery.md +26 -1
  54. package/skills/ae-generate-tracking-code/references/te-api.md +47 -164
  55. package/skills/ae-generate-tracking-plan/SKILL.md +109 -32
  56. package/skills/ae-generate-tracking-plan/references/te-api.md +57 -27
  57. package/skills/ae-metadata/SKILL.md +90 -0
  58. package/skills/ae-metadata/references/metadata_data_table_csv_delete.md +15 -0
  59. package/skills/ae-metadata/references/metadata_data_table_csv_write.md +29 -0
  60. package/skills/ae-metadata/references/metadata_data_table_download.md +17 -0
  61. package/skills/ae-metadata/references/metadata_data_table_get.md +24 -0
  62. package/skills/ae-metadata/references/metadata_data_table_list.md +27 -0
  63. package/skills/ae-metadata/references/metadata_data_table_property_bindings_update.md +17 -0
  64. package/skills/ae-metadata/references/metadata_data_table_sql_delete.md +15 -0
  65. package/skills/ae-metadata/references/metadata_data_table_sql_write.md +31 -0
  66. package/skills/ae-metadata/references/metadata_event_get.md +52 -0
  67. package/skills/ae-metadata/references/metadata_input_file_upload.md +29 -0
  68. package/skills/ae-metadata/references/metadata_property_dimension_table_bind_existing.md +27 -0
  69. package/skills/ae-metadata/references/metadata_property_dimension_table_create_and_bind_csv.md +30 -0
  70. package/skills/ae-metadata/references/metadata_property_get.md +54 -0
@@ -1,181 +1,64 @@
1
- # AE Plan Query API (captured 2026-04-15)
1
+ # AE Plan Query Capability API
2
2
 
3
- ## Endpoint
3
+ This reference is for `ae-cli` maintainers. Skill users should call CLI commands, not backend APIs.
4
4
 
5
- - **Method**: GET
6
- - **URL**: `https://web-ta-demo.thinkingdata.cn/v1/ta/bury/manage/program/query?@t={timestamp}&projectId={projectId}`
7
- - **Auth**: header `authorization: bearer {token}` — token value read from `localStorage['ACCESS_TOKEN']` (JSON-encoded string) on the AE web app, also cached in `~/.ae-cli/tokens.json`
8
- - **Additional required headers**:
9
- - `x-requested-with: XMLHttpRequest`
10
- - `accept: application/json`
11
- - **Request body**: none (GET)
5
+ The code-generation skill reads the current tracking plan through the capability gateway. The CLI
6
+ must not call the legacy common-service tracking-program URL directly.
12
7
 
13
- ### URL parameters
8
+ ## Authentication
14
9
 
15
- | Param | Required | Notes |
16
- |---|---|---|
17
- | `@t` | yes (de-facto) | Unix timestamp ms — cache-buster; the server likely accepts any value |
18
- | `projectId` | yes | AE project ID, e.g. `1603` |
10
+ - Header: `cli-token: <token>`
11
+ - Do not send `authorization: bearer ...`.
12
+ - Do not read `ACCESS_TOKEN` from browser localStorage.
19
13
 
20
- ---
14
+ ## Query Capability
21
15
 
22
- ## Response shape (truncated to 2 events / 2 props each)
16
+ - Capability: `track.program.query`
17
+ - Method: `POST`
18
+ - URL: `/api/cli/analysis/v1/capabilities/track.program.query/execute`
19
+ - Input:
20
+
21
+ ```json
22
+ { "project_id": 1603 }
23
+ ```
24
+
25
+ ## Response Shape
26
+
27
+ The gateway response keeps the standard AE envelope:
23
28
 
24
29
  ```json
25
30
  {
26
31
  "return_code": 0,
27
- "return_message": "ok",
32
+ "return_message": "success",
28
33
  "showStackMessage": null,
29
34
  "data": {
30
35
  "projectId": 1603,
31
- "createTime": "2026-04-15 15:45:17",
32
-
33
- "events": [
34
- {
35
- "eventName": "admin_skill_review",
36
- "displayName": "管理员审核",
37
- "eventDesc": "管理员通过/驳回/归档 skill",
38
- "eventTag": "admin",
39
- "creator": "周津",
40
- "createTime": "2026-04-15 15:45:17",
41
- "lastUpdateAuth": "周津",
42
- "lastUpdateTime": "2026-04-15 15:45:17",
43
- "hasReported": false,
44
- "props": ["review_action", "review_reason", "skill_id", "skill_name"],
45
- "propInfosOnEvent": [
46
- { "name": "review_action", "hasReported": false },
47
- { "name": "review_reason", "hasReported": false }
48
- ]
49
- },
50
- {
51
- "eventName": "page_view",
52
- "displayName": "页面浏览",
53
- "eventDesc": "任意页面打开",
54
- "eventTag": "common",
55
- "creator": "周津",
56
- "createTime": "2026-04-15 15:45:17",
57
- "lastUpdateAuth": "周津",
58
- "lastUpdateTime": "2026-04-15 15:45:17",
59
- "hasReported": false
60
- // props / propInfosOnEvent absent when event has no bound properties
61
- }
62
- ],
63
-
64
- "eventProps": [
65
- {
66
- "name": "login_method",
67
- "displayName": "登录方式",
68
- "type": "string",
69
- "desc": "feishu_sso",
70
- "creator": "周津",
71
- "createTime": "2026-04-15 15:45:17",
72
- "lastUpdateAuth": "周津",
73
- "lastUpdateTime": "2026-04-15 15:45:17"
74
- // NOTE: no hasReported field on eventProps items
75
- },
76
- {
77
- "name": "session_duration_ms",
78
- "displayName": "会话时长毫秒",
79
- "type": "number",
80
- "desc": "登出时本次会话累计时长",
81
- "creator": "周津",
82
- "createTime": "2026-04-15 15:45:17",
83
- "lastUpdateAuth": "周津",
84
- "lastUpdateTime": "2026-04-15 15:45:17"
85
- }
86
- ],
87
-
88
- "commonEventProps": [
89
- {
90
- "name": "is_embed",
91
- "displayName": "是否嵌入模式",
92
- "type": "bool",
93
- "desc": "是否在 CRM iframe 嵌入中访问",
94
- "creator": "周津",
95
- "createTime": "2026-04-15 15:45:17",
96
- "lastUpdateAuth": "周津",
97
- "lastUpdateTime": "2026-04-15 15:45:17",
98
- "hasReported": false
99
- },
100
- {
101
- "name": "page_name",
102
- "displayName": "页面名称",
103
- "type": "string",
104
- "desc": "当前页面标识,如 home/submit/detail/admin",
105
- "creator": "周津",
106
- "createTime": "2026-04-15 15:45:17",
107
- "lastUpdateAuth": "周津",
108
- "lastUpdateTime": "2026-04-15 15:45:17",
109
- "hasReported": false
110
- }
111
- ],
112
-
113
- "userProps": [
114
- {
115
- "name": "admin_review_count",
116
- "displayName": "审核处理数",
117
- "type": "number",
118
- "desc": "管理员累计审核的 skill 数",
119
- "updateType": "user_add",
120
- "updateTypeName": "user_add",
121
- "propTag": "",
122
- "creator": "周津",
123
- "createTime": "2026-04-15 15:45:17",
124
- "lastUpdateAuth": "周津",
125
- "lastUpdateTime": "2026-04-15 15:45:17",
126
- "hasReported": false
127
- }
128
- ]
36
+ "events": [],
37
+ "eventProps": [],
38
+ "commonEventProps": [],
39
+ "userProps": []
129
40
  }
130
41
  }
131
42
  ```
132
43
 
133
- ---
134
-
135
- ## Field mapping to Draft
136
-
137
- The planned `normalize()` function assumes `data.event_properties[]`, `data.common_event_properties[]`, `data.user_properties[]`. **Reality differs** — see caveats below.
138
-
139
- | AE response field | Draft field (src/plan/types.ts) | Notes |
140
- |---|---|---|
141
- | `data.events[].eventName` | `events[].event_name` | camelCase → snake_case |
142
- | `data.events[].displayName` | `events[].display_name` | camelCase → snake_case |
143
- | `data.events[].eventDesc` | `events[].event_desc` | camelCase → snake_case |
144
- | `data.events[].eventTag` | `events[].event_tag` | camelCase → snake_case |
145
- | `data.events[].props[]` | `events[].properties[]` | array of property name strings |
146
- | `data.events[].propInfosOnEvent[]` | `events[].property_infos[]` | array of `{name, hasReported}` |
147
- | `data.eventProps[].name` | `event_properties[].name` | key rename: `eventProps` → `event_properties` |
148
- | `data.eventProps[].type` | `event_properties[].type` | same |
149
- | `data.eventProps[].displayName` | `event_properties[].display_name` | camelCase → snake_case |
150
- | `data.eventProps[].desc` | `event_properties[].description` | key rename |
151
- | `data.commonEventProps[].name` | `common_event_properties[].name` | key rename: `commonEventProps` → `common_event_properties` |
152
- | `data.userProps[].name` | `user_properties[].name` | key rename: `userProps` → `user_properties` |
153
- | `data.userProps[].updateType` | `user_properties[].update_type` | user property specific |
154
- | `data.userProps[].propTag` | `user_properties[].prop_tag` | user property specific |
155
- | `return_code` | — | top-level; `0` = success |
156
- | `return_message` | — | top-level; `"ok"` on success |
157
-
158
- ---
159
-
160
- ## Caveats
161
-
162
- 1. **Key naming is camelCase throughout** — all field names in the response use camelCase (`eventName`, `displayName`, `eventProps`, etc.). The draft plan assumed snake_case keys like `event_name`. `normalize()` must do a full camelCase → snake_case conversion, or map fields explicitly.
163
-
164
- 2. **Array key name mismatches vs plan assumption**:
165
- - Response uses `eventProps` (not `event_properties`)
166
- - Response uses `commonEventProps` (not `common_event_properties`)
167
- - Response uses `userProps` (not `user_properties`)
168
-
169
- 3. **`eventProps` are global, not scoped per event** — all event properties live in one flat `data.eventProps[]` array. Per-event bindings are in `data.events[].props` (name strings) and `data.events[].propInfosOnEvent` (`{name, hasReported}` objects). Events with no bound properties omit both `props` and `propInfosOnEvent` fields entirely.
170
-
171
- 4. **`hasReported` field inconsistency** — `commonEventProps` and `userProps` items include `hasReported`; `eventProps` items do NOT include this field.
172
-
173
- 5. **`@t` cache-buster** — the `@t` query param is a Unix timestamp in milliseconds. It appears to be required (the page always sends it) but likely just busts CDN/proxy caching. Use `Date.now()` when constructing requests.
174
-
175
- 6. **No pagination observed** — the single request returns all 17 events, 21 event props, 6 common props, 9 user props in one shot. No pagination headers or page/limit params were observed.
176
-
177
- 7. **`userProps[].updateType` and `updateTypeName`** — both fields are present on user properties (e.g., `"user_add"`). The xlsx schema's `更新方式` column maps to this.
178
-
179
- 8. **`propTag`** — present on `userProps` items (maps to xlsx `属性标签` column), absent on event/common props.
180
-
181
- 9. **`eventProps` lack `hasReported`** — unlike events and common/user props, individual event property definitions in `eventProps[]` do not carry `hasReported`. The flag does appear inside `propInfosOnEvent[]` on the event object itself.
44
+ The CLI normalizes the capability output before converting it to the tracking draft shape.
45
+
46
+ ## Field Mapping to Draft
47
+
48
+ | AE response field | Draft field |
49
+ |---|---|
50
+ | `data.events[].eventName` | `events[].event_name` |
51
+ | `data.events[].displayName` | `events[].display_name` |
52
+ | `data.events[].eventDesc` | `events[].event_desc` |
53
+ | `data.events[].eventTag` | `events[].event_tag` |
54
+ | `data.events[].props[]` | `events[].properties[]` |
55
+ | `data.events[].propInfosOnEvent[]` | `events[].property_infos[]` |
56
+ | `data.eventProps[].name` | `event_properties[].name` |
57
+ | `data.eventProps[].displayName` | `event_properties[].display_name` |
58
+ | `data.eventProps[].desc` | `event_properties[].description` |
59
+ | `data.commonEventProps[].name` | `common_event_properties[].name` |
60
+ | `data.userProps[].name` | `user_properties[].name` |
61
+ | `data.userProps[].updateType` | `user_properties[].update_type` |
62
+ | `data.userProps[].propTag` | `user_properties[].prop_tag` |
63
+
64
+ Empty projects may return a success envelope without `data`; treat that as an empty plan.
@@ -92,14 +92,44 @@ After user responds, record to `meta.scenario` and generate `meta.plan_name`.
92
92
 
93
93
  ### Item 2 — Source Material + Business Dimension (combined)
94
94
 
95
- Ask: **"Choose your source material (up to 2):"**
95
+ Before asking, decide whether the current runtime is an agent sandbox. The agent may judge this from runtime context such as sandbox-provisioned `cli-token.json`, restricted filesystem access, or absence of the user's local files. Do not ask the user just to decide sandbox visibility.
96
96
 
97
- User can multi-select (max 2):
97
+ Product document and Codebase are local-material options. **Hide both options in sandbox environments**. When options are hidden, renumber the visible list contiguously from 1; never show skipped numbers.
98
98
 
99
- 1. **Product document** (local path, image file, or folder) — Extract events and properties from product docs; supports md/pdf/docx/URL/images (png/jpg/jpeg/webp)
100
- 2. **Detailed description** (conversational) — Describe app business flow, core features, user behaviors, monetization model, etc.
101
- 3. **Codebase** (local project path) — Analyze source code to extract events and properties
102
- 4. **Pre-built template** (built-in industry and game genre templates) — Select a built-in template (run `AE_LANG=<user_lang> ae-cli tracking plan list-templates` to see available templates)
99
+ If **not** in a sandbox environment, ask exactly:
100
+
101
+ ```text
102
+ Choose your source material (up to 2):
103
+
104
+ 1 - Product document (local path, image file, or folder; hidden in sandbox) — Extract events and properties from product docs; supports md/pdf/docx/URL/images (png/jpg/jpeg/webp)
105
+ 2 - Detailed description (conversational) — Describe app business flow, core features, user behaviors, monetization model, etc.
106
+ 3 - Codebase (local project path; hidden in sandbox) — Analyze source code to extract events and properties
107
+ 4 - Pre-built template (built-in industry and game genre templates) — Select a built-in template
108
+
109
+ Reply with number(s), e.g. 1 or 1,4. Select up to 2.
110
+ ```
111
+
112
+ If in a sandbox environment, ask exactly:
113
+
114
+ ```text
115
+ Choose your source material (up to 2):
116
+
117
+ 1 - Detailed description (conversational) — Describe app business flow, core features, user behaviors, monetization model, etc.
118
+ 2 - Pre-built template (built-in industry and game genre templates) — Select a built-in template
119
+
120
+ Reply with number(s), e.g. 1 or 1,2. Select up to 2.
121
+ ```
122
+
123
+ Do not rewrite this source material list as unnumbered bullets, cards, or prose. The user must be able to reply with the visible numbers.
124
+
125
+ User can multi-select (max 2). Interpret numbers by the **visible list shown to the user**, not by the non-sandbox canonical list.
126
+
127
+ Canonical source material options:
128
+
129
+ - **Product document** (local path, image file, or folder; hidden in sandbox) — Extract events and properties from product docs; supports md/pdf/docx/URL/images (png/jpg/jpeg/webp)
130
+ - **Detailed description** (conversational) — Describe app business flow, core features, user behaviors, monetization model, etc.
131
+ - **Codebase** (local project path; hidden in sandbox) — Analyze source code to extract events and properties
132
+ - **Pre-built template** (built-in industry and game genre templates) — Select a built-in template (run `AE_LANG=<user_lang> ae-cli tracking plan list-templates --json` to see available templates)
103
133
 
104
134
  Based on user selection, determine source material type and record to `meta.source_type`:
105
135
 
@@ -168,7 +198,7 @@ Platform validation: Use `business-dimension-mapping.md` Chapter 5 decision rule
168
198
 
169
199
  After business dimension confirmation, auto-detect matching templates based on app type:
170
200
  ```bash
171
- AE_LANG=<user_lang> ae-cli tracking plan list-templates
201
+ AE_LANG=<user_lang> ae-cli tracking plan list-templates --json
172
202
  ```
173
203
 
174
204
  Show matching templates to user for confirmation. Confirmed templates serve as baseline and participate in Phase 1 event merging.
@@ -189,6 +219,8 @@ Show matching templates to user for confirmation. Confirmed templates serve as b
189
219
 
190
220
  Ask: **"What is your client platform? (multi-select OK, e.g. Android + iOS) Will you integrate a server-side SDK?"**
191
221
 
222
+ After asking this Item 3 question, **stop and wait for the user's answer**. Do not display Item 4 in the same response.
223
+
192
224
  > **Language filter**: The following SDKs have Chinese-only documentation and are **visible to Chinese users only**: `Mini-program`, `Mini-game`, `OpenHarmony`, `LayaAir`, `Egret`, `Cocos2d-Lua`. Do not show these to non-Chinese users.
193
225
 
194
226
  **Client integration** (multi-select OK):
@@ -270,6 +302,14 @@ Record to `client_platform_languages`:
270
302
 
271
303
  `none` mode: Suitable for historical data import, batch data sync, third-party system integration, etc. Refine phase does not inject SDK auto-track events.
272
304
 
305
+ **Item 3 confirmation gate**:
306
+
307
+ After the user answers Item 3, normalize the SDK configuration and ask only the missing follow-up questions (for Android/iOS programming language or `Other` server language).
308
+
309
+ Then summarize the normalized SDK config and ask: **"Confirm this SDK integration config? Reply ok to continue to Item 4, or describe changes."**
310
+
311
+ Do not display Item 4 or ask identity questions until the user explicitly confirms this SDK integration config.
312
+
273
313
  ### Item 4 — User Identity System (visitor ID + account ID combined)
274
314
 
275
315
  Ask: **"What is the visitor ID generation strategy?"**
@@ -426,8 +466,8 @@ Draft
426
466
  Priority from low to high: **template → codebase → prd → chat → autotrack**
427
467
 
428
468
  - **template**: User-selected industry template (see "Template Lookup Convention" below) as baseline; each item marked `source: "template"`
429
- - Templates prefer `.md` distilled files (`tracking-plan-template/*.md`), fall back to `.xlsx`
430
- - Import command: `AE_LANG=<user_lang> ae-cli tracking code import-template --template <path> --out .ae-cli/draft.json`
469
+ - Templates are resolved by ae-cli from the ae-cli package root and user template directory
470
+ - Import command: `AE_LANG=<user_lang> ae-cli tracking code import-template --template-name "<template name>" --out .ae-cli/draft.json`
431
471
  - ⚠️ **Must validate immediately after template import** (see Phase 1.6); template content may not be fully correct
432
472
  - ⚠️ **Template content is in Chinese; must translate after import**: Read draft.json, translate `display_name`, `event_desc`, `event_tag`, and property `display_name`/`desc` to user's language, then write back. Only `event_name`, property `name`, `type` identifiers remain as-is.
433
473
  - ⚠️ **event_tag also needs translation**: `业务事件`→user's language (e.g. EN: `Business Event`), `系统事件`→user's language (e.g. EN: `System Event`; autotrack events are handled automatically by CLI, no need to re-translate)
@@ -601,21 +641,23 @@ Next: Phase 2 — Refine to confirm the plan.
601
641
  Run the following command to dynamically discover available templates:
602
642
 
603
643
  ```bash
604
- AE_LANG=<user_lang> ae-cli tracking plan list-templates
644
+ AE_LANG=<user_lang> ae-cli tracking plan list-templates --json
605
645
  ```
606
646
 
607
647
  **Language rules**: Template file names are in Chinese. When displaying to users, **must translate to user's current language**; **do NOT** include the original Chinese name (e.g. show only "Card Game v1", not "Card Game (卡牌游戏) v1").
608
648
 
649
+ Built-in templates are resolved by ae-cli from the ae-cli package root. User templates are resolved from the ae-cli user template directory. Do **not** manually construct `./tracking-plan-template/...` paths from the user's current workspace.
650
+
609
651
  Search directories in order:
610
652
 
611
- 1. `./tracking-plan-template/` — Project root (development)
612
- 2. `~/.ae-cli/templates/` — `ae-cli tracking` CLI user directory after installation (future default)
653
+ 1. `<ae-cli package root>/tracking-plan-template/` — bundled templates
654
+ 2. `~/.ae-cli/templates/` — user-provided template directory
613
655
 
614
656
  Each template prefers `.md` distilled file (if same-name `.md` exists, return md path; otherwise return xlsx path).
615
- Auto-detect format on import:
657
+ Display translated template names to the user, but keep the original `name` from the JSON result for import. Auto-detect format on import:
616
658
 
617
659
  ```bash
618
- AE_LANG=<user_lang> ae-cli tracking code import-template --template <path> --out .ae-cli/draft.json
660
+ AE_LANG=<user_lang> ae-cli tracking code import-template --template-name "<template name>" --out .ae-cli/draft.json
619
661
  ```
620
662
 
621
663
  ---
@@ -633,13 +675,22 @@ In order, one conversation round per segment:
633
675
  Per-segment flow:
634
676
 
635
677
  1. Display corresponding section of current draft
636
- 2. Ask **"Does this look correct? `ok` to proceed to next segment, or describe what to change"**
678
+ 2. Ask a segment-specific confirmation question. Always include the current segment number, current segment key, and next segment key:
679
+ ```text
680
+ Segment <n>/5 <segment_key> confirmed? Reply ok to continue to Segment <n+1>/5 <next_segment_key>, or describe changes.
681
+ ```
682
+ For Segment 5:
683
+ ```text
684
+ Segment 5/5 props confirmed? Reply ok to archive the plan and continue to Phase 3, or describe changes.
685
+ ```
637
686
  3. User gives natural language instructions → update `.ae-cli/draft.json` → re-run:
638
687
  ```bash
639
688
  AE_LANG=<user_lang> ae-cli tracking plan draft --in .ae-cli/draft.json --out .ae-cli/draft.xlsx
640
689
  ```
641
690
  4. User `ok` → proceed to next segment
642
691
 
692
+ `ok` is a refine state-machine input, not a repeated-message error. If the user replies `ok` multiple times in a row, advance exactly one segment per `ok` in order. Before each confirmation prompt, print the new segment heading first, so consecutive confirmations do not look like the same question repeated.
693
+
643
694
  User may say **"Go back to segment N"** at any time to jump to any segment (N = 1-5).
644
695
 
645
696
  ---
@@ -849,33 +900,59 @@ At the start of Phase 3, tell user:
849
900
  ```
850
901
  ## Phase 3 — Upload Preparation
851
902
  Next steps:
852
- 1. AE web address
853
- 2. Login to AE to get token
903
+ 1. Check active AE host and login status
904
+ 2. Login to AE to get token if needed
854
905
  3. AE project ID
855
906
  ```
856
907
 
857
- ### 3.1 Get AE Web Address
908
+ ### 3.1 Check Active AE Host and Login Status
858
909
 
859
- ❌ **Do NOT provide unconfirmed example URLs here.** Simply ask the user directly.
910
+ Do not ask for the AE web address first. ae-cli stores an active AE host, and auth commands can use it directly.
860
911
 
861
- Ask user: **"What is the AE web address?"**
912
+ First check current auth/host status:
862
913
 
863
- After user responds, save to `.ae-cli/draft.json` `meta.host` field.
914
+ ```bash
915
+ ae-cli auth status
916
+ ```
917
+
918
+ If an active host is configured, save that host to `.ae-cli/draft.json` `meta.host`. If `auth status` reports `authenticated: true`, skip login and continue to project ID.
919
+
920
+ Only if ae-cli reports no active host / no AE host configured, ask the user:
921
+
922
+ **"What is the AE web address?"**
923
+
924
+ After user responds, configure it and save the same value to `.ae-cli/draft.json` `meta.host`:
925
+
926
+ ```bash
927
+ ae-cli config set-host <host>
928
+ ```
929
+
930
+ If `auth status` reports unauthenticated, use the agent split-flow. Do **not** run blocking `ae-cli auth login` directly from an AI agent.
864
931
 
865
- Guide getting and saving token based on AE web address:
932
+ Step 1 — request an authorization URL and return control to the user:
866
933
 
867
934
  ```bash
868
- ae-cli auth login --host <host>
935
+ ae-cli auth login --no-wait
936
+ ```
937
+
938
+ Show the returned `verification_url` to the user and ask them to complete authorization. Keep the returned `device_code` for the next step.
939
+
940
+ Step 2 — after the user says authorization is complete, finish login:
941
+
942
+ ```bash
943
+ ae-cli auth login --device-code <device_code>
869
944
  ae-cli auth status
870
945
  ```
871
946
 
947
+ Do not retry with `ae-cli auth login --host <host>` unless the previous command explicitly failed because no active host was configured. In that case, configure the host first, then restart the split-flow with `--no-wait`.
948
+
872
949
  Common error tips and self-recovery:
873
950
 
874
951
  | Error | Cause | What to Tell the User |
875
952
  |---|---|---|
876
- | `Chrome JS-from-AppleEvents disabled` | Chrome disabled AppleScript JS execution | Chrome menu View → Developer → Allow JavaScript from Apple Events, then retry |
877
- | `not_mac` | Not macOS | Manually set `export AE_TOKEN=<uuid>` (get from DevTools → Application → Local Storage → `ACCESS_TOKEN`, strip quotes) |
878
- | `NO_TAB_FOUND` | Not logged into AE in Chrome | Open and login to TE in Chrome first, then retry |
953
+ | `Device authorize request failed` | The agent runtime cannot reach the authorization service | Report that no device code was created and include the exact error |
954
+ | `not_mac` | A legacy browser-token flow was attempted | Retry the split-flow device-code login; do not ask the user for browser tokens |
955
+ | `NO_TAB_FOUND` | A legacy browser-token flow was attempted | Retry the split-flow device-code login; do not ask the user to open Chrome |
879
956
 
880
957
  Token cached for 20 hours; same host avoids re-auth.
881
958
 
@@ -901,9 +978,11 @@ Checking project's existing plan...
901
978
  Before uploading, check if the project already has a tracking plan:
902
979
 
903
980
  ```bash
904
- AE_LANG=<user_lang> ae-cli tracking plan fetch --project <projectId> --host <host> > .ae-cli/existing-plan.json
981
+ AE_LANG=<user_lang> ae-cli tracking plan fetch --project <projectId> > .ae-cli/existing-plan.json
905
982
  ```
906
983
 
984
+ Do not add `--host` here unless the user explicitly provides a reachable override for this command. In agent sandboxes, ae-cli can resolve the request host from the sandbox-provisioned `cli-token.json`; passing a stale Kubernetes internal host can bypass that fallback.
985
+
907
986
  **Result assessment**:
908
987
  - File empty or command error `404` → project has no plan; upload directly
909
988
  - File has content → project has an existing plan; show summary + **conflict detection**
@@ -1008,12 +1087,10 @@ AE_LANG=<user_lang> ae-cli tracking plan upload --project <projectId> --xlsx .ae
1008
1087
  - **With `--replace`**: Delete existing project plan first then upload (when user chooses "Replace", or severe conflict switches to replace)
1009
1088
  - **Without `--replace`**: AE merge-by-name merge (no conflicts, or advisory only with user confirmation to append)
1010
1089
 
1011
- If CLI returns exit code 13 (language mismatch), the AE project language differs from xlsx language. Do NOT silently retry; must prompt user:
1012
- > "AE project language is {aeLang}, but current xlsx is {xlsxLang}. Switch AE language?"
1013
-
1014
- After user confirms, re-upload with `--switch-lang`:
1090
+ Upload language is controlled locally by `AE_LANG`, `--lang`, or `draft.meta.lang`. Do not call AE user language config APIs and do not use `--switch-lang`. If the xlsx language is wrong, regenerate the xlsx with the intended language before uploading:
1015
1091
  ```bash
1016
- AE_LANG=<user_lang> ae-cli tracking plan upload --project <projectId> --xlsx .ae-cli/draft.xlsx --draft .ae-cli/draft.json --switch-lang [--replace]
1092
+ AE_LANG=<user_lang> ae-cli tracking plan draft --in .ae-cli/draft.json --out .ae-cli/draft.xlsx
1093
+ AE_LANG=<user_lang> ae-cli tracking plan upload --project <projectId> --xlsx .ae-cli/draft.xlsx --draft .ae-cli/draft.json [--replace]
1017
1094
  ```
1018
1095
 
1019
1096
  On successful upload, prompt user to verify in AE Admin. **Provide the full URL** (tracking plan page URL format: `https://<host>/#/data/plan`).
@@ -1,23 +1,22 @@
1
- # AE Backend API (internal reference)
1
+ # AE Tracking Capability API (internal reference)
2
2
 
3
- > **Terminology**: 认证 = authentication | Token = bearer token from localStorage `ACCESS_TOKEN` | 端点 = endpoint | 抓包 = traffic capture | 埋点方案 = tracking plan | 上传 = upload | 删除 = delete | 查询 = query/fetch
3
+ > **Terminology**: authentication = CLI token | capability = gateway-registered operation | tracking plan = program | upload = save xlsx | delete = clear program | query/fetch = read program
4
4
 
5
- > This file is the implementation basis for `src/client.ts`, maintained for internal contributors.
5
+ > This file is the implementation basis for `src/core/tracking-client.ts`, maintained for internal contributors.
6
6
  > **Skill body should not reference this document** — skill users interact via CLI commands and do not need to know underlying endpoints.
7
7
  > xlsx format contract is in `xlsx-schema.md`, not here.
8
8
 
9
- Capture environment: `https://web-ta-demo.thinkingdata.cn`. If endpoints change, re-run the
10
- chrome-devtools capture flow from `docs/superpowers/plans/2026-04-15-ae-tracking-skill.md` Task 3.
9
+ The AE CLI must call common-service through capability gateway URLs under `/api/cli/`.
10
+ The legacy common-service endpoints are wrapped server-side by these capabilities and must not be
11
+ called directly from `ae-cli`.
11
12
 
12
- ## 认证
13
+ ## Authentication
13
14
 
14
- ### Token
15
- - localStorage key:`ACCESS_TOKEN`
16
- - 存储形态:**JSON 编码字符串**(带双引号),使用前须 `replace(/^["']|["']$/g, '')`
15
+ All capability requests use the CLI token chain:
17
16
 
18
- ### 两种传 token 方式(按端点区分)
19
- - **GET/JSON 类接口**:Header `authorization: bearer <token>`(全小写)
20
- - **Excel 上传接口**:**form field `access_token`**,裸 UUID,**不用** Authorization header
17
+ - Header: `cli-token: <token>`
18
+ - Do not send `authorization: bearer ...`.
19
+ - Do not send `access_token` form fields.
21
20
 
22
21
  ## 响应统一包装
23
22
 
@@ -25,16 +24,22 @@ chrome-devtools capture flow from `docs/superpowers/plans/2026-04-15-ae-tracking
25
24
  { "return_code": 0, "return_message": "success", "showStackMessage": false, "data": ... }
26
25
  ```
27
26
  - `return_code === 0` 为成功;非 0 抛错,取 `return_message`
28
- - 某些端点(如 `excel-save` / 空项目 `query`)成功时无 `data`
27
+ - Empty project query may return no `data`.
29
28
 
30
- ## 端点
29
+ ## Capabilities
31
30
 
32
- ### 1. GET `/v1/ta/bury/manage/program/query`
31
+ ### 1. `track.program.query`
33
32
 
34
33
  获取项目唯一的埋点方案。
35
34
 
36
- - Query:`projectId` 必填 number
37
- - Header:`authorization: bearer <token>`
35
+ - Method: `POST`
36
+ - URL: `/api/cli/analysis/v1/capabilities/track.program.query/execute`
37
+ - Input:
38
+
39
+ ```json
40
+ { "project_id": 1603 }
41
+ ```
42
+
38
43
  - Response `data` 结构(事件池 / 事件属性池 / 公共属性 / 用户属性):
39
44
 
40
45
  ```jsonc
@@ -55,21 +60,46 @@ chrome-devtools capture flow from `docs/superpowers/plans/2026-04-15-ae-tracking
55
60
 
56
61
  空项目:`data` 不存在,直接 `{ return_code: 0, return_message: "success" }`。
57
62
 
58
- ### 2. GET `/v1/ta/bury/manage/program/delete?projectId=<id>`
63
+ ### 2. `track.program.delete`
59
64
 
60
65
  一次清空整个项目的方案(事件 / 事件属性 / 公共属性 / 用户属性)。
61
66
 
62
- ### 3. POST `/v1/ta/bury/manage/program/excel-save`
67
+ - Method: `POST`
68
+ - URL: `/api/cli/analysis/v1/capabilities/track.program.delete/execute`
69
+ - Input:
70
+
71
+ ```json
72
+ { "project_id": 1603 }
73
+ ```
74
+
75
+ ### 3. `track.program.excel_save`
63
76
 
64
77
  批量上传 xlsx。
65
78
 
66
- - Content-Type:`multipart/form-data`
67
- - Form fields(全必填):
68
- - `file` — xlsx 二进制
69
- - `projectId` — 文本
70
- - `access_token` — 文本,裸 UUID
71
- - **无** Authorization header
72
- - Response:`{ return_code: 0, return_message: "success" }`(无 data)
79
+ Upload is a two-step capability-gateway flow:
80
+
81
+ 1. Upload the xlsx as an input file.
82
+
83
+ - Method: `POST`
84
+ - URL: `/api/cli/analysis/v1/input-files`
85
+ - Content-Type: `multipart/form-data`
86
+ - Form fields:
87
+ - `project_id`
88
+ - `purpose`: `track.program.xlsx`
89
+ - `file`: xlsx binary
90
+ - Response includes `input_file_id`.
91
+
92
+ 2. Execute the save capability.
93
+
94
+ - Method: `POST`
95
+ - URL: `/api/cli/analysis/v1/capabilities/track.program.excel_save/execute`
96
+ - Input:
97
+
98
+ ```json
99
+ { "project_id": 1603, "input_file_id": "..." }
100
+ ```
101
+
102
+ - Response: `{ return_code: 0, return_message: "success" }` on success.
73
103
 
74
104
  **合并语义**:对事件走 **merge-by-name**(同名不覆盖、新名新增)。若要完全替换,
75
105
  必须先调 `delete` 端点清空再上传。
@@ -96,5 +126,5 @@ chrome-devtools capture flow from `docs/superpowers/plans/2026-04-15-ae-tracking
96
126
 
97
127
  ## v2(暂未实现)
98
128
 
99
- - UI「逐个添加」通向单事件 CRUD 接口(`POST /v1/ta/bury/manage/event/*` 族),v1 走 excel-save 统一入口
129
+ - UI「逐个添加」通向单事件 CRUD 接口,v1 走 `track.program.excel_save` 统一入口
100
130
  - 列项目、校验错误响应等见 plan 文档的"未抓端点"清单