@shiplens/cli 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,127 +1,204 @@
1
1
  const SKILL_CONTENT = `---
2
2
  name: shiplens-analytics
3
- description: Shiplens Web User Telemetry & AI Dashboard Skill Specification. Includes project onboarding, diagnostics, CLI & MCP dual integration, authentication, metadata caching, safe SQL analytics, and single-prompt workflow.
3
+ description: Shiplens Web 数据分析 Agent 行为协议、排障诊断与数据分析执行。
4
4
  ---
5
5
 
6
- # Shiplens Web Analytics Skill Specification (v2.0)
6
+ # Shiplens Web 数据分析 Skill 指引
7
7
 
8
- > 💡 **Core Overview & Official Reference**:
9
- > 1. **Dual Track Integration**: Supports instant onboarding via **Shiplens CLI** (\`shiplens init\` / \`npx @shiplens/cli init\`) for dependency setup, project creation, and code injection; full support for **MCP Tools** and standard REST APIs inside IDE / Agent environments.
10
- > 2. Installing the SDK and viewing live dashboards requires no MCP server; advanced analytics requires authentication via OAuth, API keys/environment variables, or CLI credentials.
11
- > 3. **Authoritative FAQ**: \`https://shiplens.dev/faq\`.
8
+ Shiplens 通过 CLI MCP 提供 Web 用户行为数据分析。本文档定义 AI Agent 如何为使用 Shiplens 的项目进行排障自检、项目接入与数据分析。
12
9
 
13
- You are connected to **Shiplens Web Analytics & MCP Services**. When providing analytics, funnel diagnostics, cohort retention comparisons, and AI dashboard creation, follow the standard workflow and execution protocols below.
10
+ ---
11
+
12
+ ## 1. 环境排障自检
13
+
14
+ 执行任何分析命令前,检查三项线索以判定项目状态:
15
+
16
+ | 线索 | 检查项 |
17
+ |------|--------|
18
+ | **鉴权** | 本地是否存在 \`shiplens.env\` 或环境变量 \`SHIPLENS_ACCESS_SECRET\`? |
19
+ | **SDK** | \`package.json\` 是否包含 \`@shiplens/sdk\` 且源码已插桩? |
20
+ | **云端** | 云端接口(\`GET /api/projects\`)是否能查询到对应项目? |
21
+
22
+ ### 四状态矩阵
23
+
24
+ | 状态 | 判定条件 | 应对行为 |
25
+ |------|----------|----------|
26
+ | **状态 A — 正常完备** | 鉴权与云端项目皆具备 | 直接开始数据分析(§3) |
27
+ | **状态 A-1 — 有鉴权无项目** | 鉴权成功,但云端账号下无项目或当前项目未归属于该账号 | 提示用户前往 \`https://shiplens.dev\` 检查账号或创建/认领项目(非本地代码缺失) |
28
+ | **状态 B — 缺少鉴权 / 换电脑** | SDK 已装,但本地缺有效凭据 | 询问:*“您之前是否注册过 Shiplens 账号?”*<br/>• **已注册** → 引导前往 \`https://shiplens.dev/settings/api-keys\` 下载 \`shiplens.env\` 放置到项目根目录下(亦可复制密钥后执行 \`shiplens auth set --secret <key>\` 保存)<br/>• **未注册** → 引导提供邮箱执行 \`shiplens auth bind --email <邮箱> --json\` 发送激活邮件 |
29
+ | **状态 C — 完全冷启动** | SDK 未装,缺鉴权 | 引导执行初始化接入(§2) |
30
+
31
+ 该矩阵同时作为排障基准线。系统出现任何异常时,按此三项线索回溯排查。
14
32
 
15
33
  ---
16
34
 
17
- ## 1. Project Onboarding & Step-by-Step Diagnostics
35
+ ## 2. 项目极速接入
18
36
 
19
- ### Standard Workflow:
37
+ ### 执行接入
38
+ \`\`\`bash
39
+ npx.cmd --yes @shiplens/cli init --json # Windows
40
+ npx --yes @shiplens/cli init --json # macOS / Linux
20
41
  \`\`\`
21
- Check Existing App ID ➔ Install SDK ➔ POST Connect & Get Dashboard URL ➔ Request Email for Free Quota ➔ Activate Magic Link ➔ Authenticate ➔ Complete
42
+ 备用镜像:追加 \`--registry=https://registry.npmmirror.com\`
43
+
44
+ ### 初始化操作(约 15 秒,单命令完成)
45
+ 1. 识别前端框架(Next.js / Vite / Vue / HTML)
46
+ 2. 4 级分类体系 (Genre/Subgenre/Tags) 智能推断与打标
47
+ 3. 安装 \`@shiplens/sdk\` 依赖
48
+ 4. 在入口文件注入采集代码
49
+ 5. 请求 \`POST /api/connect\` 注册项目 → 获取 \`app_id\` 与 \`dashboard_url\`
50
+ 6. 提取页面/按钮文案并写入本地 \`.shiplens/contexts/<app_id>.md\`
51
+ 7. 写入本地状态机 \`./.shiplens.json\`
52
+ 8. 下发通用 Agent Skill 规范(\`.agents/skills/shiplens/SKILL.md\` 与 rules)
53
+
54
+ ### 防误覆盖保护与大白话对比
55
+ 若本地已存在 \`./.shiplens.json\` 或代码已插桩,**必须暂停并比对配置,向用户以通俗大白话讲清利弊**:
56
+ - **【推荐】保持现有统计**:继续沿用当前项目编号(ID: \`<已有app_id>\`),历史统计数据和看板完整保留,新访问将继续累积到现有看板中,无需修改代码;
57
+ - **【覆盖】使用 \`--force\` 重新创建**:向云端申请一个全新的空白项目编号并覆盖本地代码插桩。**这意味着旧看板将停止接收新数据,后续数据将记录到全新空白看板中,新旧数据无法在同一个看板中直接合并**。
58
+
59
+ ### 接入后:索要邮箱激活额度 & 凭据机制
60
+ 向用户索要邮箱以激活 **每月 50,000 条免费事件(约 5,000 人访问)**:
61
+ \`\`\`bash
62
+ shiplens auth bind --email <邮箱> --json
22
63
  \`\`\`
23
64
 
24
- > **Quick Execution**: In a terminal environment, execute \`npx.cmd --yes @shiplens/cli init --json\` (Windows) or \`npx --yes @shiplens/cli init --json\` (macOS/Linux) for automated 15-second zero-config setup. (China mirror fallback: \`--registry=https://registry.npmmirror.com\`).
65
+ - **凭据下发机制**:执行 \`auth bind\` 时,服务端会随响应下发设备专属凭据,CLI 自动将其安全写入项目根目录的 \`shiplens.env\`(权限 0600);
66
+ - **激活即生效**:用户在邮箱中点击 Magic Link 完成注册激活后,**云端立即激活该设备凭据**;
67
+ - **零后续摩擦**:本地 Agent **无需执行额外的登录命令或索要 Token**,已写入的 \`shiplens.env\` 即刻生效,后续的数据查询(\`shiplens query\`)与 MCP 服务(\`shiplens mcp serve\`)直接可用。
68
+
69
+ ### 汇报模板
70
+ 初始化完成后,输出标准卡片:
25
71
 
26
- ### Step 0. Existing Project Detection (Overwrite Protection)
27
- - Check if \`./.shiplens.json\` or SDK instrumentation (\`initShiplens\`, \`data-app-id\`) exists locally.
28
- - If existing project is detected, pause and ask the user whether to reuse the existing ID or force overwrite with \`--force\`.
72
+ \`\`\`markdown
73
+ ### 📊 项目与数据看板信息
74
+ - **项目名称**:\\\`<project_name>\\\`
75
+ - **应用 ID (App ID)**:\\\`<app_id>\\\`
76
+ - **代码注入**:已在 [\\\`<injected_file>\\\`](file:///<path>) 中完成配置
77
+ - **实时看板**:[\\\`<dashboard_url>\\\`](<dashboard_url>)
78
+ - **用户个人账号**:<用户个人账号状态>
29
79
 
30
- ### Step 1. Framework Auto-Detection & SDK Injection
31
- - Auto-detect Next.js (App/Pages router), Vite (React/Svelte), Vue 3, or Plain HTML.
32
- - Inject SDK code:
33
- - **Next.js App Router**: Client component \`ShiplensTracker.tsx\` imported into root \`layout.tsx\`.
34
- - **Vite / Vue**: Import and initialize \`initShiplens({ appId: '<app_id>' })\` in \`main.ts\` / \`main.js\`.
35
- - **Plain HTML**: Inject \`<script src="https://cdn.shiplens.dev/sdk.js" data-app-id="<app_id>" defer></script>\` in \`<head>\`.
80
+ > [!IMPORTANT]
81
+ > **项目待激活(数据统计尚未生效)**
82
+ > **请告诉我您的邮箱**:点击邮件中的链接即可完成注册,激活每月 50,000 事件的免费额度(约5000人访问),同时绑定项目和账号;激活后您与我直接对话,我就有权限查询并分析产品数据。
83
+ \`\`\`
36
84
 
37
- ### Step 2. Dependency Installation
38
- - Install \`@shiplens/sdk\` via \`npm\`, \`pnpm\`, \`yarn\`, or \`bun\` with \`--legacy-peer-deps\`.
85
+ 账号状态枚举:
86
+ - \`已登录 (项目已与账号关联)\` 本地存在有效凭据且云端项目已归属于当前账号
87
+ - \`已登录 (项目和账号未关联)\` — 本地存在有效凭据但云端项目尚未归属于当前账号
88
+ - \`未登录 (首次安装默认状态或本地不存在有效凭据)\` — 初次安装 CLI 或无有效凭据时的默认状态
39
89
 
40
- ### Step 3. Cloud Registration (POST /api/connect)
41
- - Send project name, description, 4-level taxonomy (genre, subgenre, tags) to register project.
42
- - Retrieve permanent \`app_id\` and live \`dashboard_url\`.
90
+ ---
43
91
 
44
- #### Initialization Standard Reporting Template
45
- Upon completing \`shiplens init\`, the Agent **MUST** present the exact information structure and immediately prompt for email activation:
92
+ ## 3. 数据分析协议 (6 步执行流)
46
93
 
47
- \`\`\`markdown
48
- Shiplens Analytics SDK successfully integrated and configured:
94
+ 当用户提出任何独立的数据分析需求时:
49
95
 
50
- ### 📊 Project & Dashboard Information
51
- - **Project Name**: \`<project_name>\`
52
- - **App ID**: \`<app_id>\`
53
- - **Code Injection**: Automatically configured in [\`<injected_file>\`](file:///<absolute_path>)
54
- - **Live Dashboard / Activation URL**:
55
- 🔗 [<dashboard_url>](<dashboard_url>)
56
- - **User Account**: <User Account Status>
96
+ **第 1 检查动态覆盖 (因地制宜)**:检查根目录是否存在 \`.shiplens/learnings.md\`。若存在,先读取【全局通用偏好】,再匹配当前分析场景对应的【场景细分偏好】(如留存分析偏好 14d、转化漏斗偏好 30d,严禁一刀切全局覆盖)。
57
97
 
58
- ---
98
+ **第 2 步 — 锚定业务上下文**:读取 \`.shiplens/contexts/<app_id>.md\`(或执行 \`shiplens context show --json\`)。用具体页面名称和按钮文案解释数据,严禁仅输出生硬 ID。
59
99
 
60
- ### 📦 Changes & Git Status
61
- - Changes automatically committed to Git (Commit: \`<hash>\`).
62
- - AI Skill ready: [\`.agents/skills/shiplens/SKILL.md\`](file:///<skill_path>).
100
+ **第 3 定位分析场景**:打开 \`prompts/prompts_cli_zh.md\`,阅读顶部的**42 大场景全景提纲与索引导航**,找到契合场景,提取对应章节的确定性执行步骤与 SQL/CLI 语法。
63
101
 
64
- > [!IMPORTANT]
65
- > **Project Pending Activation (Analytics not active yet)**
66
- > **Please share your email**: Click the link in the email to complete registration, activate 50,000 free monthly events (~5,000 visitors), and bind your project to your account. Once activated, you can chat directly with me to query and analyze product data.
67
- \`\`\`
102
+ **第 4 步 — 执行命令**:执行预设的 CLI 命令,并带上第 1 步获取的场景细分覆盖参数。
68
103
 
69
- **User Account Status Evaluation**:
70
- - **State a**: \`Logged In (Project linked to account)\` / \`已登录(项目已于账号关联)\` — Local credentials exist and project is linked to user account.
71
- - **State b**: \`Logged In (Project not linked to account)\` / \`已登录(项目和账号未关联)\` — Local credentials exist but project could not be linked.
72
- - **State c**: \`Not Logged In (Project unlinked)\` / \`未登录(项目和账号可能未关联)\` — **Default state for first-time CLI installation or unauthenticated environments**.
104
+ **第 5 — 输出深度洞察**:将数据转化为具体的业务结论与优化建议,结合第 2 步的业务上下文进行解读。
73
105
 
74
- ### Step 4. Request Email for Quota Activation
75
- - Prompt user for email address to activate **50,000 monthly events** free tier.
76
- - Send Magic Link email via \`POST /api/auth/start-email\` (or \`shiplens auth bind --email <email> --json\`).
106
+ **第 6 场景化自适应学习**:若用户对分析过程进行了纠偏(如针对留存提出“改用双周周期评估”),智能识别纠偏适用的场景范围,主动询问:*“是否需要我将「留存分析默认采用双周 14d 周期」记录到当前项目的 \`.shiplens/learnings.md\` 对应场景中?”* 确认后写入文件(§6)。
107
+
108
+ ### 优先级规则
109
+ - **优先级 1**:\`.shiplens/learnings.md\` — 项目专属用户动态偏好(场景细分覆盖 > 全局通用偏好)
110
+ - **优先级 2**:\`prompts/prompts_cli_zh.md\` — 42 个教科书经典分析场景底座
111
+
112
+ ---
113
+
114
+ ## 4. 核心 CLI 命令速查
115
+
116
+ | 命令 | 用途 |
117
+ |------|------|
118
+ | \`shiplens init --json\` | 项目极速接入(§2) |
119
+ | \`shiplens doctor --json\` | 诊断本地配置、代码插桩、SDK 安装、Ingestion 连通性与凭证状态 |
120
+ | \`shiplens summary --range 7d --json\` | 宏观概览:总 PV、UV、停留时长、Top 来源 |
121
+ | \`shiplens query --metric <m> --range 7d --json\` | 多维指标与转化漏斗查询 |
122
+ | \`shiplens sql --query "<sql>" --json\` | 在 ClickHouse 只读沙箱上执行安全 SELECT 查询 |
123
+ | \`shiplens pages --range 7d --json\` | 页面访问量与平均停留时长 |
124
+ | \`shiplens paths --range 7d --json\` | 用户旅程与流转路径 |
125
+ | \`shiplens heatmap --template <id> --json\` | 页面点击热力图与骨架图 |
126
+ | \`shiplens dashboards create --title "..." --prompt "..." --json\` | AI 自动生成官方可视化看板 |
127
+ | \`shiplens context push / pull / show\` | 业务上下文与页面按钮文案云端双向同步 |
128
+ | \`shiplens auth bind --email <邮箱> --json\` | 发送 Magic Link 邮件绑定与下发凭据 |
129
+ | \`shiplens auth set --secret <key>\` | 手动保存用户提供的 API 密钥到本地 \`shiplens.env\` |
130
+ | \`shiplens mcp serve\` | 启动本地 stdio MCP 代理(供 AI Agent 客户端使用) |
131
+ | \`shiplens projects delete --app-id <id> --json\` | 删除项目(**高危操作,必须二次确认**,§5) |
77
132
 
78
133
  ---
79
134
 
80
- ## 2. Core CLI Commands Reference
135
+ ## 5. 安全红线与风控
81
136
 
82
- | Command | Purpose |
83
- | :--- | :--- |
84
- | \`shiplens doctor --json\` | End-to-end diagnostics on config, SDK, network, and credentials |
85
- | \`shiplens summary --range 7d --json\` | Product overview: PV, UV, bounce rates, top geos, devices |
86
- | \`shiplens query --metric <m> --range 7d --json\` | Multi-dimensional metric queries & funnels |
87
- | \`shiplens sql --query "<sql>" --json\` | Execute secure read-only SQL on ClickHouse |
88
- | \`shiplens pages --range 7d --json\` | Page-level visits and average dwell times |
89
- | \`shiplens paths --range 7d --json\` | Sankey user flow and transition paths |
90
- | \`shiplens heatmap --template <id> --json\` | Click heatmaps & skeleton wireframes |
91
- | \`shiplens dashboards create --title "..." --prompt "..." --json\` | Generate AI responsive dashboards |
92
- | \`shiplens auth bind --email <email> --json\` | Trigger Magic Link email binding |
137
+ ### 删除项目 强制二次确认 (HITL)
138
+ 删除任何项目前,必须执行:
139
+ 1. 向用户展示项目名称、\`app_id\` 及创建时间;
140
+ 2. 明确警告:*“此操作将彻底清空该项目的所有监控数据、看板与配置,且不可逆。”*;
141
+ 3. **暂停操作,等待用户显式回复“确认删除”**;
142
+ 4. 收到确认后方可执行 \`shiplens projects delete\`。
143
+
144
+ 严禁跳过确认静默删除。
145
+
146
+ ### SQL 安全规则
147
+ - 必须携带时间范围:\`WHERE timestamp >= now() - INTERVAL <N> DAY\`
148
+ - 必须带 \`LIMIT\`(最大 1000 行)
149
+ - 查询目标表:\`events\`(ClickHouse 只读沙箱)
150
+
151
+ ### Windows 终端规范
152
+ - npm/npx 命令带 \`.cmd\` 后缀:\`npx.cmd --yes\`、\`npm.cmd\`
153
+ - 多命令连接使用分号 \`;\`,禁止使用 \`&&\`
93
154
 
94
155
  ---
95
156
 
96
- ## 3. Dynamic Overrides & Adaptive Learning Protocol
157
+ ## 6. 自适应学习规范 (\`.shiplens/learnings.md\`)
158
+
159
+ 存放项目专属的用户偏好覆盖规则。在用户首次确认保存前**不默认创建**。
97
160
 
98
- When executing analytics requests (such as user prompts matching standard scenarios like \`What stage is my product in? What metrics should I track?\`), you must follow this 5-step protocol:
161
+ ### 标准文件格式(因地制宜)
162
+ \`\`\`markdown
163
+ # Shiplens AI 分析学习与项目偏好配置
164
+
165
+ ## 全局通用偏好 (Global Preferences)
166
+ - exclude_user_ids: ["test_user_01", "internal_qa"]
167
+ - default_time_grain: day
168
+
169
+ ## 场景细分偏好 (Scenario-Specific Overrides)
170
+ ### 场景: [用户留存与流失分析] (retention_curve / retention_matrix)
171
+ - default_range: 14d # 用户偏好以双周周期评估留存衰减
172
+ - focus_metrics: ["第 14 天留存率", "次周回访率"]
173
+
174
+ ### 场景: [转化漏斗与流失诊断] (funnel_dropoff)
175
+ - default_range: 30d # 漏斗分析采用月度窗口
176
+ - primary_conversion_goal: /checkout/success
177
+ \`\`\`
99
178
 
100
- 1. **Step 1 - Check Dynamic Overrides (Priority 1)**:
101
- - Check if \`.shiplens/learnings.md\` exists in the project root.
102
- - If present, apply any user-specified overrides (e.g. customized date range \`--range 14d\`, preferred metrics, custom funnel steps).
103
- 2. **Step 2 - Context Grounding**:
104
- - Check and read \`.shiplens/contexts/<app_id>.md\` (or run \`shiplens context show --json\`) to ground telemetry figures in real button labels and route semantics.
105
- 3. **Step 3 - Deterministic CLI Execution (Priority 2 Base)**:
106
- - Run the matched CLI command sequence with any overrides applied.
107
- 4. **Step 4 - Business Synthesis**:
108
- - Synthesize data into actionable takeaways and optimization levers.
109
- 5. **Step 5 - Adaptive Learning**:
110
- - If the user corrects your analysis (e.g. *"I need a 14-day window"* or *"Track signup completion as the final funnel step"*), immediately record the preference rule into \`.shiplens/learnings.md\` for future automatic reuse.
179
+ ### 维护规则
180
+ - **严禁**在 \`init\` 时自动创建空文件
181
+ - 仅在用户纠偏并明确确认后创建或追加
182
+ - 每次写入前明确向用户确认适用场景范围
111
183
 
112
184
  ---
113
185
 
114
- ## 4. SQL Standards & Guidelines
115
-
116
- - **Table Name**: \`events\` (Read-only ClickHouse instance)
117
- - **Key Columns**:
118
- - \`timestamp\` (DateTime), \`event_name\` (String), \`user_id\` (String), \`session_id\` (String)
119
- - \`template_id\` (String - DOM structure hash), \`page_path\` (String), \`referrer\` (String)
120
- - \`properties\` (Map/JSON - custom event metadata)
121
- - **Rules**:
122
- - Always apply time filters: \`timestamp >= now() - INTERVAL 7 DAY\`.
123
- - Always specify \`LIMIT\` (maximum 1000 rows).
124
- - Use ClickHouse aggregate functions: \`countIf()\`, \`quantile(0.50)()\`, \`dateDiff()\`.
186
+ ## 7. 数据表结构与 SQL 参考
187
+
188
+ **数据表**:\`events\`(ClickHouse 只读实例)
189
+
190
+ | 字段名 | 类型 | 说明 |
191
+ |--------|------|------|
192
+ | \`timestamp\` | DateTime | 事件发生时间 |
193
+ | \`event_name\` | String | pageview, click, custom |
194
+ | \`user_id\` | String | 用户唯一标识 |
195
+ | \`session_id\` | String | 会话唯一标识 |
196
+ | \`template_id\` | String | DOM 结构哈希(页面骨架模板) |
197
+ | \`page_path\` | String | 页面 URL 路径 |
198
+ | \`referrer\` | String | 来源 URL |
199
+ | \`properties\` | Map(String, String) | 自定义事件参数 |
200
+
201
+ ClickHouse 常用聚合函数:\`countIf()\`, \`quantile(0.50)()\`, \`dateDiff()\`, \`uniq()\`.
125
202
  `;
126
203
 
127
204
  module.exports = { SKILL_CONTENT };
package/lib/cli.js CHANGED
@@ -15,11 +15,7 @@ const { handleDoctor } = require('./commands/doctor');
15
15
  const { handleContext } = require('./commands/context');
16
16
  const { handleMcp } = require('./commands/mcp');
17
17
 
18
- let VERSION = '1.3.0';
19
- try {
20
- const pkg = require('../package.json');
21
- if (pkg.version) VERSION = pkg.version;
22
- } catch (e) {}
18
+ const VERSION = '1.2.4';
23
19
 
24
20
  function parseArgs(argv) {
25
21
  const flags = {};
@@ -69,61 +65,61 @@ function parseArgs(argv) {
69
65
  }
70
66
 
71
67
  function printHelp() {
72
- console.log(`Shiplens CLI - High-Speed User Telemetry & SDK Management Tool (v${VERSION})
68
+ console.log(`Shiplens CLI 极速用户行为数据分析与 SDK 管理工具 (v${VERSION})
73
69
 
74
- Usage:
75
- shiplens <command> [subcommand] [options]
76
- npx.cmd --yes shiplens-cli <command> [subcommand] [options] (Windows)
77
- npx --yes shiplens-cli <command> [subcommand] [options] (macOS/Linux)
70
+ 使用方法:
71
+ shiplens <命令> [子命令] [选项]
72
+ npx.cmd --yes shiplens-cli <命令> [子命令] [选项] (Windows)
73
+ npx --yes shiplens-cli <命令> [子命令] [选项] (macOS/Linux)
78
74
 
79
- Core Commands:
80
- init 15-second zero-config analytics initialization & dashboard setup
81
- auth Authentication & credentials (status, set, secret, whoami, logout, bind, mcp-config, configure)
82
- projects Project management (list, bind, delete)
83
- query Multi-dimensional metrics and conversion funnel queries
84
- sql Execute secure read-only SQL queries on ClickHouse
85
- summary Retrieve product overview (traffic, bounce rates, geos, devices)
86
- pages Inspect page-level visits and average dwell times
87
- paths Analyze user flow journeys and Sankey transition paths
88
- canvas Retrieve global user behavior canvas topology
89
- heatmap Retrieve click heatmaps and skeleton wireframes
90
- dashboards AI dashboard management and one-click creation (list, create [--ai])
91
- doctor Run full end-to-end diagnostics on SDK, credentials, and network
92
- context Manage business context dictionary (push, pull, show)
93
- mcp serve Run local MCP proxy server with device credentials
75
+ 核心命令:
76
+ init 一键 15 秒极速初始化 Shiplens 埋点与数据看板 (内置 4 级分类自动打标与 Git 提交)
77
+ auth 鉴权凭证管理 (status, set, secret, whoami, logout, bind, mcp-config, configure)
78
+ projects 项目管理与绑定 (list, bind, delete)
79
+ query 向云端发起多维结构化指标与漏斗聚合分析 (支持 --metrics 多指标 / --file)
80
+ sql 在云端 ClickHouse 只读副本上执行安全 SQL (支持 --stdin 管道)
81
+ summary 获取产品整体流量、受众画像与关键指标摘要
82
+ pages 获取页面级访问与停留时长证据
83
+ paths 获取页面流转与跳转桑基流路径分析
84
+ canvas 获取全局用户行为画布拓扑数据
85
+ heatmap 获取页面点击热力图与骨架图快照
86
+ dashboards AI 看板管理与一键创建 (list, create [--ai])
87
+ doctor 对当前项目的埋点、连通性与凭证进行全面体检
88
+ context 项目业务上下文管理 (push, pull, show)
89
+ mcp serve 运行本地 MCP 代理;它从 shiplens.env 读取设备凭证
94
90
 
95
- auth Subcommands:
96
- auth status Check credential validity
97
- auth set [--secret-stdin] Save Access Secret
98
- auth secret list List Access Secrets (masked)
99
- auth secret create [--scopes ...] Create scoped offline Access Secret
100
- auth secret revoke --key-id <id> Revoke offline Access Secret
101
- auth whoami Display current authenticated user
102
- auth logout Clear local credentials
103
- auth bind --email <email> [--json] Send Magic Link email for account binding
104
- auth mcp-config [--client <client>] Print MCP configuration (cursor/codex/claude/antigravity/manual)
105
- auth configure --client <client> Write MCP configuration into target client
106
- auth configure --client manual Output standard MCP JSON configuration
91
+ auth 子命令:
92
+ auth status 检查当前凭证是否有效
93
+ auth set [--secret-stdin] 设置 Access Secret
94
+ auth secret list 列出离线 Access Secret(仅显示掩码)
95
+ auth secret create [--scopes ...] 创建受范围和失效时间约束的离线 Access Secret
96
+ auth secret revoke --key-id <id> 撤销离线 Access Secret
97
+ auth whoami 查看当前登录用户信息
98
+ auth logout 清除本地凭证
99
+ auth bind --email <邮箱> [--json] 一键邮箱绑定:发送 Magic Link 激活邮件
100
+ auth mcp-config [--client <client>] 输出 MCP 配置(client: cursor/codex/claude/antigravity/manual
101
+ auth configure --client <client> 写入 Cursor、Codex Desktop、Claude Desktop Antigravity 配置
102
+ auth configure --client manual 输出可手动粘贴的标准 MCP JSON 配置
107
103
 
108
- init Dedicated Options:
109
- --name <string> Project name (default: auto-read from package.json)
110
- --description <string> Project functional description & positioning
111
- --genre <id> Level 1 category ID (e.g. utilities, finance, casual_games)
112
- --subgenre <id> Level 2 subcategory ID (e.g. developer_tools, financial_tools)
113
- --tags <ids> Level 4 feature tags (comma-separated tag_ids)
114
- --industry <string> Compatibility industry category field
115
- --email <email|auto> Auto or manual binding email
104
+ init 专用选项 (支持自动推断,亦可显式覆盖):
105
+ --name <string> 项目名称 (默认自动读取 package.json)
106
+ --description <string> 项目功能描述与定位详情
107
+ --genre <id> Level 1 大类 ID ( utilities, finance, casual_games)
108
+ --subgenre <id> Level 2 子类别 ID ( developer_tools, financial_tools)
109
+ --tags <ids> Level 4 特性标签列表 (逗号分隔 tag_id)
110
+ --industry <string> 兼容性行业类别字段
111
+ --email <email|auto> 自动或手动绑定激活邮箱
116
112
 
117
- Global Options:
118
- --json Output in standard JSON format (required for AI Agents)
119
- --force Force overwrite existing local configuration and project ID
120
- --no-commit Skip automatic Git commit after initialization
121
- --app-id <id> Explicitly specify target project app_id
122
- --env <env> Target environment (production / staging, default: production)
123
- --secret <key> Pass Access Secret explicitly
124
- --api-url <url> Custom backend API base URL (default: http://120.26.230.33)
125
- -v, --version Display CLI version
126
- -h, --help Display help information
113
+ 全局选项:
114
+ --json 以标准 JSON 格式输出结果 (AI Agent 必选)
115
+ --force 强制覆盖本地已存在的 Shiplens 统计配置与项目 ID
116
+ --no-commit 初始化完成后跳过自动 Git 提交
117
+ --app-id <id> 显式指定目标项目 app_id (默认自动读取 .shiplens.json)
118
+ --env <env> 目标环境 (production / staging,默认 production)
119
+ --secret <key> 显式传入 Access Secret 鉴权密钥
120
+ --api-url <url> 自定义后端 API 基址 (默认 http://120.26.230.33)
121
+ -v, --version 显示当前 CLI 版本号
122
+ -h, --help 显示帮助信息
127
123
  `);
128
124
  }
129
125
 
@@ -166,12 +162,12 @@ async function runCLI(argv = process.argv.slice(2)) {
166
162
  status: err.status,
167
163
  }, null, 2));
168
164
  } else {
169
- console.error(`❌ Error [${code}]: ${err.message}`);
165
+ console.error(`❌ 错误 [${code}]: ${err.message}`);
170
166
  }
171
167
  process.exitCode = 1;
172
168
  };
173
169
 
174
- // Resolve credentials and API client
170
+ // 解析凭证与 API 客户端
175
171
  const resolvedAuth = resolveSecret(flags.secret);
176
172
  let apiUrl = flags['api-url'] || process.env.SHIPLENS_API_URL;
177
173
  if (!apiUrl) {
@@ -186,7 +182,7 @@ async function runCLI(argv = process.argv.slice(2)) {
186
182
  if (flags['app-id']) return flags['app-id'];
187
183
  const localCfg = getLocalConfig();
188
184
  if (localCfg && localCfg.app_id) return localCfg.app_id;
189
- const err = new Error('Target app_id not found. Provide --app-id or run inside an initialized project directory.');
185
+ const err = new Error('未找到目标 app_id,请传入 --app-id 或在已初始化的项目目录下执行');
190
186
  err.code = 'APP_NOT_FOUND';
191
187
  throw err;
192
188
  };
@@ -248,7 +244,7 @@ async function runCLI(argv = process.argv.slice(2)) {
248
244
  await handleMcp(subcommand || 'serve');
249
245
  break;
250
246
  default:
251
- throw new Error(`Unknown command: ${command}. Use shiplens --help to view supported commands.`);
247
+ throw new Error(`未知命令: ${command}。使用 shiplens --help 查看支持的命令。`);
252
248
  }
253
249
  } catch (err) {
254
250
  outputError(err);