@hupu-tech/shaper 0.0.0-stage → 0.2.2

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 (82) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +3 -0
  3. package/README.md +282 -2
  4. package/dist/api.d.ts +29 -0
  5. package/dist/auth.d.ts +80 -0
  6. package/dist/cli.js +14 -0
  7. package/dist/cloud-service.d.ts +55 -0
  8. package/dist/cloud.d.ts +71 -0
  9. package/dist/config.d.ts +21 -0
  10. package/dist/core.d.ts +17 -0
  11. package/dist/credentials.d.ts +23 -0
  12. package/dist/dev-runner.js +1 -0
  13. package/dist/dev.d.ts +66 -0
  14. package/dist/index.d.ts +9 -0
  15. package/dist/index.js +1 -0
  16. package/dist/legacy-cloud.d.ts +25 -0
  17. package/dist/runtime.d.ts +54 -0
  18. package/dist/runtime.js +1 -0
  19. package/dist/shared-2ZNSJXPO.js +15 -0
  20. package/dist/shared-BTZI42QW.js +17 -0
  21. package/dist/workspace.d.ts +84 -0
  22. package/package.json +73 -4
  23. package/skills/compat/hupu-cloud/SKILL.md +8 -0
  24. package/skills/core/hupu-business/SKILL.md +14 -0
  25. package/skills/core/hupu-business/references/runtime.md +55 -0
  26. package/skills/core/shaper-backend/SKILL.md +35 -0
  27. package/skills/core/shaper-backend/references/legacy.md +41 -0
  28. package/skills/core/shaper-backend/references/node-server.md +44 -0
  29. package/skills/core/shaper-design/SKILL.md +16 -0
  30. package/skills/core/shaper-development/SKILL.md +54 -0
  31. package/skills/core/shaper-game-development/SKILL.md +16 -0
  32. package/skills/core/shaper-product/SKILL.md +17 -0
  33. package/skills/core/shaper-product/references/ecosystem.md +10 -0
  34. package/skills/core/shaper-release/SKILL.md +17 -0
  35. package/skills/game/shaper-idle-game/SKILL.md +16 -0
  36. package/skills/manifest.json +18 -0
  37. package/templates/cloud-service/README.md +32 -0
  38. package/templates/cloud-service/cloud.json +30 -0
  39. package/templates/cloud-service/handlers.cjs +46 -0
  40. package/templates/cloud-service/migrations/202610250001_init.sql +5 -0
  41. package/templates/cloud-service/migrations/202610250002_events.sql +8 -0
  42. package/templates/h5/docs/design.md +3 -0
  43. package/templates/h5/docs/product.md +3 -0
  44. package/templates/h5/docs/validation.md +3 -0
  45. package/templates/h5/index.html +24 -0
  46. package/templates/h5/package-lock.json +828 -0
  47. package/templates/h5/package.json +15 -0
  48. package/templates/h5/public/.gitkeep +0 -0
  49. package/templates/h5/shaper.config.json +7 -0
  50. package/templates/h5/src/main.js +7 -0
  51. package/templates/h5/src/style.css +21 -0
  52. package/templates/h5/vite.config.js +4 -0
  53. package/templates/phaser/docs/design.md +3 -0
  54. package/templates/phaser/docs/product.md +3 -0
  55. package/templates/phaser/docs/validation.md +3 -0
  56. package/templates/phaser/index.html +2 -0
  57. package/templates/phaser/package-lock.json +1287 -0
  58. package/templates/phaser/package.json +19 -0
  59. package/templates/phaser/public/.gitkeep +0 -0
  60. package/templates/phaser/shaper.config.json +7 -0
  61. package/templates/phaser/src/game/create-game.ts +5 -0
  62. package/templates/phaser/src/game/rules/scoring.ts +2 -0
  63. package/templates/phaser/src/game/scenes/PlayScene.ts +15 -0
  64. package/templates/phaser/src/main.ts +4 -0
  65. package/templates/phaser/src/styles.css +1 -0
  66. package/templates/phaser/tsconfig.json +21 -0
  67. package/templates/phaser/vite.config.ts +4 -0
  68. package/templates/react/docs/design.md +3 -0
  69. package/templates/react/docs/product.md +3 -0
  70. package/templates/react/docs/validation.md +3 -0
  71. package/templates/react/index.html +2 -0
  72. package/templates/react/package-lock.json +1329 -0
  73. package/templates/react/package.json +22 -0
  74. package/templates/react/public/.gitkeep +0 -0
  75. package/templates/react/shaper.config.json +7 -0
  76. package/templates/react/src/app/App.tsx +5 -0
  77. package/templates/react/src/app/styles.css +1 -0
  78. package/templates/react/src/main.tsx +6 -0
  79. package/templates/react/tsconfig.json +21 -0
  80. package/templates/react/vite.config.ts +4 -0
  81. package/vendor/cloud-server/hupu-cloud-server-0.1.0.tgz +0 -0
  82. package/vendor/cloud-server/release.json +12 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## 0.2.2 — 2026-11-12
4
+
5
+ - 收紧 npm 发行白名单,移除内部文档与环境信息。
6
+ - CLI 和库入口改为压缩构建,不发布源码映射。
7
+ - 增加实际安装包及内嵌 SDK 的发行内容检查。
8
+
9
+ ## 0.2.1 — 2026-11-12
10
+
11
+ - 重写开发者 README,补齐安装、快速开始、客户端接入、工程结构、配置、交付流程及常见问题。
12
+ - CLI 与 MCP 的版本号统一读取 package.json。
13
+ - 明确公开分发、平台接口配置和各操作系统验收边界。
14
+
15
+ ## 0.2.0 — 2026-11-12
16
+
17
+ - 首次向公开 npm registry 提交 Shaper CLI、stdio MCP、核心技能和 HTML/React/Phaser 模板。
18
+ - 提供项目绑定、浏览器授权、本地预览构建、上传及提审确认入口。
19
+ - 支持默认服务配置、本地开发安装模式及 Windows 安装路径适配。
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2026 Hupu. All rights reserved.
2
+
3
+ Private project. No license to redistribute or reuse is granted by this file.
package/README.md CHANGED
@@ -1,3 +1,283 @@
1
- # Temporary Holding Version
1
+ # Shaper
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **在你熟悉的 AI 工具中开发网页、游戏和互动体验。**
4
+
5
+ Shaper 将项目初始化、本地预览、平台上传和审核流程连接起来。一个 npm 包提供命令行工具(CLI)、标准 stdio MCP 服务和开发技能(Skills),支持通过 AI 对话或终端完成开发。
6
+
7
+ ```bash
8
+ npm install -g @hupu-tech/shaper
9
+ shaper install --ide cursor
10
+ ```
11
+
12
+ [安装](#安装) · [快速开始](#快速开始) · [接入-ai-工具](#接入-ai-工具) · [项目结构](#项目结构) · [常用命令](#常用命令) · [常见问题](#常见问题)
13
+
14
+ ## 功能
15
+
16
+ - **AI 工具接入**:为 Codex、Cursor、Claude Code 安装 MCP 和用户级技能。
17
+ - **项目初始化**:提供 HTML、React、Phaser 模板;已有工程保留原代码和构建方式。
18
+ - **本地开发**:启动预览、查看日志、检查配置和构建产物。
19
+ - **平台交付**:上传生成预览,在浏览器核对资料后提交审核。
20
+ - **后台开发**:按需接入应用云服务、部署后台源码和执行版本化数据库迁移。
21
+ - **统一应用归属**:网页、CLI、MCP 复用同一个 App ID,避免重复创建和错误关联。
22
+
23
+ ## 环境要求
24
+
25
+ - Node.js **22.14 或以上**,建议使用 Node.js 24。
26
+ - npm,以及一个拥有对应 Shaper 平台访问权限的账号。
27
+ - 通过 AI 开发时,需要支持 Skills 或 stdio MCP 的客户端。
28
+
29
+ 已在 macOS 验证构建和安装流程。Windows 已适配 npm 命令入口、技能 junction 和凭据目录权限,完整实机验收仍在进行;Linux 完整链路也尚未验收。登录、上传和云能力需要目标 Shaper 服务启用对应接口。
30
+
31
+ ## 安装
32
+
33
+ 全局安装后,可在任意业务项目目录使用 `shaper`:
34
+
35
+ ```bash
36
+ npm install -g @hupu-tech/shaper
37
+ shaper --version
38
+ ```
39
+
40
+ 也可以不全局安装,使用 npx 执行命令:
41
+
42
+ ```bash
43
+ npx -y @hupu-tech/shaper --help
44
+ npx -y @hupu-tech/shaper install --ide cursor
45
+ ```
46
+
47
+ 安装开发工具不会创建平台应用,也不会自动提交审核。
48
+
49
+ ## 快速开始
50
+
51
+ ### 1. 连接你的 AI 工具
52
+
53
+ 按实际使用的客户端选择一条:
54
+
55
+ ```bash
56
+ shaper install --ide cursor
57
+ shaper install --ide codex
58
+ shaper install --ide claude
59
+ ```
60
+
61
+ 安装后按提示重启客户端或重新加载 MCP。你也可以一次安装到多个客户端:
62
+
63
+ ```bash
64
+ shaper install --ide codex,cursor,claude
65
+ ```
66
+
67
+ ### 2. 初始化业务项目
68
+
69
+ 从 Shaper 网页开始创作时,复制网页生成的命令,在**业务项目目录**运行。将示例中的 `AppID` 替换为网页提供的真实值:
70
+
71
+ ```bash
72
+ shaper init --app AppID
73
+ ```
74
+
75
+ 已有应用会直接验证并关联;尚未创建的预分配 ID 会打开浏览器,完成登录及“创建并连接”确认后继续。
76
+
77
+ 也可以直接创建一个新目录:
78
+
79
+ ```bash
80
+ shaper init my-project --template react
81
+ cd my-project
82
+ ```
83
+
84
+ 模板支持 `h5`、`react`、`phaser`,未指定时使用 `h5`。空目录初始化会保存预分配 ID,经浏览器确认后创建应用,重试复用同一 ID。
85
+
86
+ **已有项目先核对原 App ID。** 已绑定或已识别的旧 ID 与命令目标冲突时,初始化会停止;已有源码但无法确定归属时,需要明确指定应用。不要使用新建应用来绕过权限或绑定错误。
87
+
88
+ ### 3. 开发和预览
89
+
90
+ 接入 AI 后,可以直接告诉它:
91
+
92
+ > 请检查当前项目的 Shaper 绑定和工程配置,帮我实现需求,并启动本地预览。保留已有代码和构建方式。
93
+
94
+ 也可以在终端操作:
95
+
96
+ ```bash
97
+ shaper dev
98
+ shaper logs
99
+ shaper check
100
+ shaper build
101
+ ```
102
+
103
+ `dev` 返回本地预览地址。`check` 检查工程配置,不代表业务行为已经验证;完成开发后仍需检查实际页面与交互。
104
+
105
+ ### 4. 上传和提审
106
+
107
+ ```bash
108
+ shaper deploy
109
+ ```
110
+
111
+ 命令构建并上传当前应用,返回版本 ID 和预览信息。确认页面效果后,将下面的 `VersionID` 替换为上传返回的版本 ID:
112
+
113
+ ```bash
114
+ shaper publish --version VersionID --description "本次更新说明"
115
+ ```
116
+
117
+ 该命令准备资料并打开浏览器确认页。你可以补充封面、修改应用信息,**点击提交后才进入审核**。打开确认页不等于已提审,审核通过也需以平台实际发布状态为准。
118
+
119
+ ## 接入 AI 工具
120
+
121
+ | 客户端 | 接入方式 |
122
+ | --- | --- |
123
+ | Codex | `shaper install --ide codex` |
124
+ | Cursor | `shaper install --ide cursor` |
125
+ | Claude Code | `shaper install --ide claude` |
126
+ | WorkBuddy、TRAE 等其他客户端 | 按客户端支持的方式手动配置 Skills 和 stdio MCP,目前没有自动安装参数 |
127
+
128
+ 手动 MCP 配置示例:
129
+
130
+ ```json
131
+ {
132
+ "mcpServers": {
133
+ "shaper": {
134
+ "command": "shaper",
135
+ "args": ["mcp", "serve"]
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ 不同客户端的配置文件位置和结构可能不同。若 GUI 客户端找不到 `shaper`,使用 Node 可执行文件绝对路径作为 command,将安装包中 `dist/cli.js` 的绝对路径放在 args 首位,后面接 `mcp`、`serve`;Windows 可用这种方式避开 `.cmd` 启动差异。`npm root -g` 可查询全局包目录。
142
+
143
+ 手动安装技能时,读取包内 `skills/manifest.json`,按客户端规范接入对应技能目录。不要给未支持的客户端套用 `--ide cursor` 等参数。
144
+
145
+ 默认提供七个核心技能:
146
+
147
+ | 技能 | 职责 |
148
+ | --- | --- |
149
+ | `shaper-product` | 明确目标、用户流程和完成条件 |
150
+ | `shaper-design` | 视觉、交互及体验设计 |
151
+ | `shaper-development` | 项目归属、工程接入和前端开发 |
152
+ | `shaper-game-development` | 玩法实现与游戏开发流程 |
153
+ | `shaper-backend` | 应用云服务、后台部署和数据库迁移 |
154
+ | `hupu-business` | 虎扑用户、分享及容器能力接入 |
155
+ | `shaper-release` | 构建、预览、提审确认和结果检查 |
156
+
157
+ 可选安装离线养成玩法技能:
158
+
159
+ ```bash
160
+ shaper install --ide cursor --skills shaper-idle-game
161
+ ```
162
+
163
+ 技能按用户级安装,后续项目复用;`init` 不把整套技能复制到每个项目。
164
+
165
+ ## 项目结构
166
+
167
+ 新模板采用统一结构,React 和 Phaser 的差异放在业务源码中:
168
+
169
+ ```text
170
+ my-project/
171
+ ├─ package.json
172
+ ├─ package-lock.json
173
+ ├─ shaper.config.json # 开发命令、构建命令、产物目录
174
+ ├─ index.html
175
+ ├─ src/ # 业务源码
176
+ ├─ public/ # 保留路径的静态资源
177
+ ├─ docs/
178
+ │ ├─ product.md
179
+ │ ├─ design.md
180
+ │ └─ validation.md
181
+ ├─ AGENTS.md # AI 项目入口
182
+ ├─ dist/ # 构建生成
183
+ └─ .shaper/ # 本地绑定与工具状态,不提交 Git
184
+ ```
185
+
186
+ 已有 HTML 或其他打包工程无需为了接入而整体搬迁。缺失的启动、构建配置需要结合原工程调整,并验证实际产物;不保证任意旧项目都能机械转换。
187
+
188
+ ## 常用命令
189
+
190
+ 在业务项目目录执行;完整参数以 `shaper <命令> --help` 为准。
191
+
192
+ | 命令 | 用途 |
193
+ | --- | --- |
194
+ | `shaper config` | 查看有效服务地址 |
195
+ | `shaper doctor` | 查看安装与登录状态 |
196
+ | `shaper status` | 查看当前项目绑定、版本和预览状态 |
197
+ | `shaper login` / `shaper logout` | 登录或退出当前服务的共用账号 |
198
+ | `shaper projects` | 列出已获授权的应用 |
199
+ | `shaper init` | 初始化或接入项目 |
200
+ | `shaper dev` / `shaper stop` | 启动或停止本地预览 |
201
+ | `shaper logs` | 查看本地运行日志 |
202
+ | `shaper check` / `shaper build` | 检查配置或构建网页 |
203
+ | `shaper deploy` | 上传当前应用的构建产物 |
204
+ | `shaper publish` | 打开指定版本的提审确认页 |
205
+
206
+ `shaper link --app AppID` 用于明确更换目录关联,应先确认目标应用和影响;它不迁移源码或云资源。
207
+
208
+ ## 服务地址与登录
209
+
210
+ CLI 和 MCP 共用全局配置,设置服务地址无需先登录:
211
+
212
+ ```bash
213
+ shaper config --server https://shaper.example.com
214
+ shaper config
215
+ ```
216
+
217
+ 上例是占位地址,请替换为平台提供的服务地址。未配置时默认使用 `https://shaper.hupu.com`。服务地址必须是 HTTPS origin,本机回环 HTTP 地址仅用于本地调试。
218
+
219
+ - 全局目录:macOS/Linux 为 `~/.config/shaper`,Windows 为 `%USERPROFILE%\.config\shaper`。
220
+ - `SHAPER_CONFIG_HOME` 可指定独立配置目录;`SHAPER_SERVER` 可覆盖当前进程的默认服务。
221
+ - 修改地址后重启已运行的 MCP;环境变量需要由相应客户端进程继承。
222
+ - 登录凭据按服务保存,项目只保存 App ID 和服务地址。切换服务不会迁移应用。
223
+ - 同一服务的多个项目和 Agent 共用登录;补充授权保留已有权限,退出会影响该服务的全部本地项目。
224
+
225
+ 已有应用需要补充权限时使用 `shaper login --app AppID`;需要云权限时使用 `shaper login --cloud`。初始化尚未创建的应用时直接用 `init --app`,由初始化流程完成浏览器确认。
226
+
227
+ ## 应用云服务
228
+
229
+ 需要后端时再接入,不是所有网页都需要开通云服务。先初始化并关联应用,然后:
230
+
231
+ ```bash
232
+ shaper login --cloud
233
+ shaper cloud init cloud/functions/api
234
+ shaper cloud enable
235
+ shaper cloud status
236
+ ```
237
+
238
+ 资源就绪后维护后台代码和数据库迁移,再使用 `shaper cloud deploy --directory cloud/functions/api` 部署。云资源可能产生费用,以平台提供的套餐和权限为准。
239
+
240
+ 后台结构按职责分开:
241
+
242
+ ```text
243
+ cloud/
244
+ ├─ functions/api/ # 服务源码和运行配置
245
+ ├─ database/migrations/ # 版本化 SQL 迁移
246
+ └─ gateway/routes.json # 路由声明
247
+ ```
248
+
249
+ 返回 `queued` / `running` 只代表已受理或执行中。使用 `shaper cloud operation OperationID` 查询最终结果;依赖迁移的代码须等迁移成功后再部署。网页上传与后台部署分别执行;一期每个应用只有一份活动后台服务。
250
+
251
+ ## 升级与卸载
252
+
253
+ 升级全局 CLI 后,重新安装客户端集成,使 MCP 和技能使用新版快照:
254
+
255
+ ```bash
256
+ npm install -g @hupu-tech/shaper@latest
257
+ shaper install --ide cursor
258
+ ```
259
+
260
+ 也可用 `shaper update --version 0.2.2 --ide cursor` 安装指定客户端运行时版本;该命令不替代全局 npm 包升级。
261
+
262
+ ```bash
263
+ shaper uninstall
264
+ npm uninstall -g @hupu-tech/shaper
265
+ ```
266
+
267
+ `shaper uninstall` 只移除本工具管理的客户端配置与技能链接,保留登录和运行时缓存。若需撤销登录,在卸载 CLI 前执行 `shaper logout`。
268
+
269
+ ## 常见问题
270
+
271
+ **安装成功,AI 仍找不到工具?** 重新加载 MCP 或重启客户端,并运行 `shaper doctor`。手动接入时检查客户端是否能找到 command;优先使用绝对路径。
272
+
273
+ **初始化提示应用 ID 冲突?** 当前目录可能属于另一个应用。核对原绑定和网页入口,回到原应用继续或使用新的空目录;不要删除绑定来绕过冲突。
274
+
275
+ **登录页面无法打开或服务未启用?** 用 `shaper config` 核对服务公开地址。CLI 配置地址不会自动启用后端 OAuth,需要服务端完成授权配置。
276
+
277
+ **上传成功为什么还没上线?** 上传、确认提审、审核和发布是不同状态。完成浏览器确认后,在平台查看该版本的实际审核结果。
278
+
279
+ **可以使用 Vue 或其他技术栈吗?** 可以保留已有工程,通过 `shaper.config.json` 配置真实开发、构建命令和输出目录。内置模板只是起点,不代表只允许三种技术栈;仍需符合平台交付包约束。
280
+
281
+ ## 许可证
282
+
283
+ Copyright © 2026 Hupu。当前包标记为 `UNLICENSED`,保留所有权利。公开分发不代表采用开源许可证,具体条款见包内 LICENSE。
package/dist/api.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { AuthManager } from './auth.js';
2
+ export type RequestResult<T = unknown> = {
3
+ status: 'running' | 'succeeded' | 'failed' | 'uncertain';
4
+ result: T | null;
5
+ error_code: string | null;
6
+ };
7
+ export declare class ShaperApi {
8
+ readonly auth: AuthManager;
9
+ constructor(auth: AuthManager);
10
+ request<T>(path: string, options?: {
11
+ method?: string;
12
+ body?: unknown;
13
+ file?: Uint8Array;
14
+ key?: string;
15
+ anonymous?: boolean;
16
+ }): Promise<T>;
17
+ me(): Promise<import("./auth.js").Identity>;
18
+ projects(): Promise<{
19
+ projects: {
20
+ id: string;
21
+ name: string;
22
+ }[];
23
+ }>;
24
+ project(appId: string): Promise<{
25
+ appId: string;
26
+ name: string;
27
+ versions: unknown[];
28
+ }>;
29
+ }
package/dist/auth.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ import * as oauth from 'oauth4webapi';
2
+ import { type CredentialStore } from './credentials.js';
3
+ export declare const defaultScopes = "openid offline_access projects:read projects:write web:deploy web:publish";
4
+ export declare const cloudScopes = "openid offline_access projects:read projects:write web:deploy web:publish cloud:read cloud:write";
5
+ export type Identity = {
6
+ user: {
7
+ id: string;
8
+ displayName: string;
9
+ };
10
+ grant: {
11
+ id: string;
12
+ scopes: string[];
13
+ appIds: string[];
14
+ allApps: boolean;
15
+ };
16
+ };
17
+ export type LoginOptions = {
18
+ cloud?: boolean;
19
+ openBrowser?: boolean;
20
+ appId?: string;
21
+ initialize?: boolean;
22
+ applicationName?: string;
23
+ reauthorize?: boolean;
24
+ };
25
+ /** Global account login; every CLI/MCP request reads the same origin's current credentials. */
26
+ export declare class AuthManager {
27
+ readonly credentials: CredentialStore;
28
+ private readonly flows;
29
+ private metadata?;
30
+ readonly server: string;
31
+ constructor(server: string, credentials?: CredentialStore);
32
+ private options;
33
+ discovery(): Promise<oauth.AuthorizationServer>;
34
+ private save;
35
+ accessToken(): Promise<string>;
36
+ private request;
37
+ identity(): Promise<Identity>;
38
+ start(options?: LoginOptions): Promise<{
39
+ flowId: `${string}-${string}-${string}-${string}-${string}`;
40
+ status: 'pending';
41
+ authorizationUrl: string;
42
+ expiresIn: number;
43
+ } | {
44
+ user: {
45
+ id: string;
46
+ displayName: string;
47
+ };
48
+ grant: {
49
+ id: string;
50
+ scopes: string[];
51
+ appIds: string[];
52
+ allApps: boolean;
53
+ };
54
+ status: 'complete';
55
+ authenticated: boolean;
56
+ reused: boolean;
57
+ }>;
58
+ status(id: string): {
59
+ flowId: string;
60
+ status: 'pending' | 'complete' | 'failed';
61
+ message?: string;
62
+ };
63
+ wait(id: string): Promise<{
64
+ user: {
65
+ id: string;
66
+ displayName: string;
67
+ };
68
+ grant: {
69
+ id: string;
70
+ scopes: string[];
71
+ appIds: string[];
72
+ allApps: boolean;
73
+ };
74
+ authenticated: boolean;
75
+ }>;
76
+ logout(): Promise<{
77
+ revoked: boolean;
78
+ }>;
79
+ close(): Promise<void>;
80
+ }
package/dist/cli.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import{c as B,d as G,g as c}from"./shared-BTZI42QW.js";import{a as m,b as y,d as J,e as q,f as be,g as se,h as $,i as D,m as K,n as z,o as V,q as Q,r as U,s as H,v as W,w as Y,x as Z}from"./shared-2ZNSJXPO.js";import{Command as rt}from"commander";import{readFile as Te}from"node:fs/promises";import{resolve as l}from"node:path";import{readFileSync as De}from"node:fs";var X=JSON.parse(De(new URL("../package.json",import.meta.url),"utf8")).version;import{mkdir as P,readFile as x,writeFile as le,mkdtemp as Je,lstat as te,readlink as ee,symlink as Ce,unlink as me,rm as L,rename as qe}from"node:fs/promises";import{dirname as de,join as u,resolve as $e}from"node:path";import{homedir as Ke,tmpdir as ze}from"node:os";import{execa as Ie}from"execa";import{realpath as Fe}from"node:fs/promises";import{dirname as Ae,resolve as Me,toNamespacedPath as ke}from"node:path";async function _e(e,o){let i=Me(Ae(e),o);try{return ke(await Fe(i))}catch(n){if(n.code!=="ENOENT")throw n;return ke(i)}}async function N(e,o,i){if(o===void 0||i===void 0)return!1;let[n,t]=await Promise.all([_e(e,o),_e(e,i)]);return n===t}import{createHash as Ve,randomUUID as Ee}from"node:crypto";import*as pe from"@iarna/toml";import{parse as Qe,modify as Ue,applyEdits as He}from"jsonc-parser";import Ne from"proper-lockfile";import{Client as Be}from"@modelcontextprotocol/sdk/client/index.js";import{StdioClientTransport as Ge}from"@modelcontextprotocol/sdk/client/stdio.js";var We=["codex","cursor","claude"],Se="# >>> Shaper managed MCP >>>",ce="# <<< Shaper managed MCP <<<",F=()=>u(y(),"installation.json");async function A(e){return x(e,"utf8").catch(o=>{if(o.code==="ENOENT")return"";throw o})}function Ye(e){let o=[],i=Qe(e||"{}",o,{allowTrailingComma:!0});if(o.length||!i||typeof i!="object"||Array.isArray(i))throw new m("INVALID_IDE_CONFIG","IDE \u914D\u7F6E\u65E0\u6CD5\u89E3\u6790\uFF0C\u8BF7\u5148\u4FEE\u590D\u914D\u7F6E\u6587\u4EF6\u3002");return i}function ue(e,o){return JSON.stringify(e)===JSON.stringify(o)}function Ze(e,o){return u(o,e==="codex"?".codex/config.toml":e==="cursor"?".cursor/mcp.json":".claude.json")}function xe(e,o,i,n){if(e==="codex"){let k=pe.parse(o).mcp_servers?.shaper,h=o.indexOf(Se),S=o.indexOf(ce),I=h>=0&&S>h;if(k&&(!I||!n||!ue(k,n)))throw new m("IDE_CONFIG_CONFLICT","Codex \u7684 shaper MCP \u914D\u7F6E\u4E0D\u5C5E\u4E8E\u672C\u6B21\u5B89\u88C5\uFF0C\u5DF2\u4FDD\u7559\u539F\u914D\u7F6E\u3002");let C=I?o.slice(0,h)+o.slice(S+ce.length).replace(/^\r?\n/,""):o,T=i?`${C.trimEnd()}
3
+
4
+ ${Se}
5
+ [mcp_servers.shaper]
6
+ command = ${JSON.stringify(i.command)}
7
+ args = ${JSON.stringify(i.args)}
8
+ ${ce}
9
+ `:C;return pe.parse(T),T}let w=Ye(o).mcpServers?.shaper;if(w&&(!n||!ue(w,n)))throw new m("IDE_CONFIG_CONFLICT",`${e} \u7684 shaper MCP \u914D\u7F6E\u5DF2\u5B58\u5728\u6216\u5DF2\u88AB\u4FEE\u6539\uFF0C\u5DF2\u4FDD\u7559\u539F\u914D\u7F6E\u3002`);return He(o||`{}
10
+ `,Ue(o||`{}
11
+ `,["mcpServers","shaper"],i,{formattingOptions:{insertSpaces:!0,tabSize:2}}))}async function we(e,o,i){await P(de(e),{recursive:!0});try{if((await te(e)).isSymbolicLink())throw new m("UNSAFE_IDE_CONFIG",`IDE \u914D\u7F6E\u662F\u7B26\u53F7\u94FE\u63A5\uFF0C\u8BF7\u624B\u52A8\u914D\u7F6E\uFF1A${e}`)}catch(t){if(t.code!=="ENOENT")throw t}if(await A(e)!==o)throw new m("IDE_CONFIG_CHANGED",`\u914D\u7F6E\u5728\u5B89\u88C5\u671F\u95F4\u53D1\u751F\u53D8\u5316\uFF1A${e}`);if(o){let t=u(y(),"backups",`${Date.now()}-${Ee()}.bak`);await P(de(t),{recursive:!0,mode:448}),await le(t,o,{mode:384,flag:"wx"})}let n=`${e}.${Ee()}.tmp`;await le(n,i,{mode:384,flag:"wx"}),await qe(n,e)}async function oe(){try{return await q(F())}catch(e){if(e.code==="ENOENT")return;throw e}}async function Oe(){let e;try{e=await q(u(y(),"install-pending.json"))}catch(o){if(o.code==="ENOENT")return;throw o}if(e.next&&ue(await oe(),e.next)){await L(u(y(),"install-pending.json"));return}for(let o of e.edits){let i=await A(o.path);if(i!==o.before&&i!==o.after)throw new m("INSTALL_RECOVERY_CONFLICT",`\u5B89\u88C5\u4E2D\u65AD\u540E\u914D\u7F6E\u5DF2\u88AB\u6539\u52A8\uFF0C\u4FDD\u7559\u73B0\u573A\uFF1A${o.path}`)}for(let o of e.skills)try{if(!(await te(o.path)).isSymbolicLink())throw new m("INSTALL_RECOVERY_CONFLICT",`\u5B89\u88C5\u4E2D\u65AD\u540E\u6280\u80FD\u5DF2\u88AB\u6539\u52A8\uFF1A${o.path}`);let i=await ee(o.path);if(!await N(o.path,i,o.target)&&!await N(o.path,i,o.previous))throw new m("INSTALL_RECOVERY_CONFLICT",`\u5B89\u88C5\u4E2D\u65AD\u540E\u6280\u80FD\u94FE\u63A5\u5DF2\u88AB\u6539\u52A8\uFF1A${o.path}`)}catch(i){if(i.code!=="ENOENT")throw i}for(let o of e.edits)await A(o.path)===o.after&&await we(o.path,o.after,o.before);for(let o of e.skills){let i=await ee(o.path).catch(t=>{if(t.code!=="ENOENT")throw t}),n=await N(o.path,i,o.previous);!n&&await N(o.path,i,o.target)&&await me(o.path),o.previous&&!n&&await Ce(o.previous,o.path,process.platform==="win32"?"junction":"dir")}e.previous?await J(F(),e.previous):await L(F(),{force:!0}),await L(u(y(),"install-pending.json"))}async function Xe(e){if(e&&!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(e))throw new m("INVALID_VERSION","\u66F4\u65B0\u7248\u672C\u5FC5\u987B\u662F\u5B8C\u6574\u7684\u7248\u672C\u53F7\u3002");let o=await Je(u(ze(),"shaper-install-"));try{let i=await Ie("npm",["pack",...e?[`@hupu-tech/shaper@${e}`]:[],"--ignore-scripts","--json","--pack-destination",o],{cwd:D,timeout:18e4,maxBuffer:1048576}),n=JSON.parse(i.stdout)[0],t=u(o,n.filename),w=Ve("sha256").update(await x(t)).digest("hex").slice(0,16),g=u(y(),"runtimes",`${n.version}-${w}`),k=u(g,"node_modules","@hupu-tech","shaper","dist","cli.js");try{await x(u(g,".complete"))}catch(h){if(h.code!=="ENOENT")throw h;await P(g,{recursive:!0,mode:448}),await Ie("npm",["install","--prefix",g,t,"--omit=dev","--ignore-scripts","--no-audit","--no-fund"],{timeout:24e4,maxBuffer:4*1024*1024}),await le(u(g,".complete"),`${w}
12
+ `,{mode:384})}return await x(k),{root:u(g,"node_modules","@hupu-tech","shaper"),version:n.version,entry:k}}finally{await L(o,{recursive:!0,force:!0})}}async function et(e){let o=new Ge({...e,stderr:"pipe"}),i=new Be({name:"shaper-installer",version:"1.0.0"});try{await i.connect(o,{timeout:15e3});let n=await i.listTools();if(!n.tools.some(t=>t.name==="shaper_status"))throw new m("MCP_VERIFICATION_FAILED","MCP \u672A\u8FD4\u56DE Shaper \u5DE5\u5177\u3002");return{tools:n.tools.length,protocol:"stdio"}}finally{await i.close(),await o.close()}}async function fe(e,o={}){if(!e.length||e.some(n=>!We.includes(n)))throw new m("INVALID_IDE","\u652F\u6301 codex\u3001cursor\u3001claude\u3002");await P(y(),{recursive:!0,mode:448});let i=await Ne.lock(y(),{retries:0});try{await Oe();let n=$e(o.home??Ke()),t=await oe();if(o.dev&&o.version)throw new m("INVALID_ARGUMENT","\u672C\u5730\u8C03\u8BD5\u6A21\u5F0F\u4E0D\u80FD\u6307\u5B9A\u53D1\u884C\u7248\u672C\u3002");let w=o.dev?{root:D,entry:u(D,"dist","cli.js"),version:(await q(u(D,"package.json"))).version}:await Xe(o.version);o.dev&&await x(w.entry).catch(()=>{throw new m("BUILD_REQUIRED","\u8BF7\u5148\u5728\u672C\u5730\u5305\u76EE\u5F55\u6267\u884C pnpm build\u3002")});let g={command:process.execPath,args:[w.entry,"mcp","serve"]},k=await et(g),h=[...new Set(e)].map(a=>({ide:a,path:Ze(a,n),entry:g})),S=await Promise.all(h.map(async a=>{let f=await A(a.path);return{...a,before:f,after:xe(a.ide,f,g,t?.entries.find(re=>re.path===a.path)?.entry)}})),I=new Set(e.map(a=>u(n,a==="codex"?".agents/skills":`.${a}/skills`))),C=JSON.parse(await x(u(w.root,"skills/manifest.json"),"utf8")),T=o.skills??[];for(let a of T)if(!C.optional.some(f=>f.split("/").at(-1)===a))throw new m("UNKNOWN_SKILL",`\u672A\u77E5\u4E13\u4E1A\u6280\u80FD\uFF1A${a}`);let ye=[...C.default,...C.compatibility,...C.optional.filter(a=>T.includes(a.split("/").at(-1))||t?.skills.some(f=>f.path.endsWith("/"+a.split("/").at(-1))))];if(ye.some(a=>!/^(core|game|compat)\/[a-z0-9-]+$/.test(a)))throw new m("INVALID_SKILL_MANIFEST","\u6280\u80FD\u53D1\u884C\u6E05\u5355\u65E0\u6548\u3002");let R=[];for(let a of I)for(let f of ye){let re=f.split("/").at(-1),j=u(a,re),he=u(w.root,"skills",f);await x(u(he,"SKILL.md"));let ve;try{let M=await te(j),ae=t?.skills.find(Re=>Re.path===j);if(!M.isSymbolicLink()||!ae||!await N(j,await ee(j),ae.target))throw new m("SKILL_CONFLICT",`\u5DF2\u5B58\u5728\u6280\u80FD\uFF0C\u5B89\u88C5\u672A\u8986\u76D6\uFF1A${j}`);ve=ae.target}catch(M){if(M.code!=="ENOENT")throw M}R.push({path:j,target:he,previous:ve})}let ge={schemaVersion:1,runtime:w.root,version:w.version,entries:[...(t?.entries??[]).filter(a=>!h.some(f=>f.path===a.path)),...h],skills:[...(t?.skills??[]).filter(a=>!R.some(f=>f.path===a.path)),...R.map(({path:a,target:f})=>({path:a,target:f}))]};await J(u(y(),"install-pending.json"),{edits:S,skills:R,previous:t,next:ge});for(let a of S)await we(a.path,a.before,a.after);for(let a of R)await P(de(a.path),{recursive:!0}),a.previous&&await me(a.path),await Ce(a.target,a.path,process.platform==="win32"?"junction":"dir");return await J(F(),ge),await L(u(y(),"install-pending.json"),{force:!0}),{installed:!0,mode:o.dev?"development":"snapshot",runtime:w.root,version:w.version,ides:e,...k,restartIde:!0,cli:{command:process.execPath,args:[w.entry]}}}finally{await i()}}async function je(){await P(y(),{recursive:!0,mode:448});let e=await Ne.lock(y(),{retries:0});try{await Oe();let o=await oe();if(!o)return{uninstalled:!0,alreadyAbsent:!0};let i=await Promise.all(o.entries.map(async n=>{let t=await A(n.path);return{...n,before:t,after:xe(n.ide,t,void 0,n.entry)}}));for(let n of o.skills)try{if(!(await te(n.path)).isSymbolicLink()||!await N(n.path,await ee(n.path),n.target))throw new m("SKILL_CONFLICT",`\u6280\u80FD\u5DF2\u88AB\u4FEE\u6539\uFF0C\u5378\u8F7D\u4FDD\u7559\uFF1A${n.path}`)}catch(t){if(t.code!=="ENOENT")throw t}for(let n of i)await we(n.path,n.before,n.after);for(let n of o.skills)await me(n.path).catch(t=>{if(t.code!=="ENOENT")throw t});return await L(F(),{force:!0}),{uninstalled:!0,credentialsRetained:!0,runtimeRetained:!0}}finally{await e()}}async function Le(){let e=await oe();return e?{installed:!0,version:e.version,ides:e.entries.map(o=>o.ide),runtime:e.runtime}:{installed:!1}}import{McpServer as tt}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as ot}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as s}from"zod";import{isAbsolute as nt}from"node:path";var d=s.string().min(1).refine(nt,"workspace must be an absolute path").describe("Absolute local project directory. Never infer from the MCP process working directory."),b=s.string().regex(/^[a-z][a-z0-9-]{0,31}$/),ne=s.string().min(1).max(64),O=s.string().min(16).max(100).optional();function it(e,o={}){let i=new tt({name:"shaper",version:X},{instructions:"Use installed Shaper skills for workflows. Always pass the intended absolute workspace. All sessions share one login per Shaper server. Reuse it; request additional permissions only when needed. Browser consent adds permissions without replacing existing access. Local binding contains only the server and app ID, never tokens. Never choose a recent app as a fallback. Web delivery and backend service deployment have separate targets. Queued, running or uncertain results do not confirm completion. Use hupu_cloud_operation to confirm asynchronous results."});function n(t,w,g,k,h="write"){i.registerTool(w,{description:g,inputSchema:t,annotations:{readOnlyHint:h==="read",destructiveHint:h==="destructive",openWorldHint:!0}},async S=>{try{let I=await k(S);return{content:[{type:"text",text:JSON.stringify(I,null,2)}]}}catch(I){return{isError:!0,content:[{type:"text",text:JSON.stringify($(I))}]}}})}return n({workspace:d.optional()},"shaper_status","Read current identity, local project binding and development session. Does not start services.",t=>e.status(t.workspace),"read"),n({cloud:s.boolean().default(!1),openBrowser:s.boolean().default(!0),appId:s.string().min(1).max(200).optional(),reauthorize:s.boolean().default(!1)},"shaper_auth_start","Reuse the global login when permissions suffice. Otherwise start browser consent and return a flow ID. appId adds access to an existing application; cloud=true adds cloud permissions. Existing permissions are retained. reauthorize=true opens consent explicitly.",t=>e.auth.start(t)),n({flowId:s.string()},"shaper_auth_status","Read browser authorization result for a flow started by this MCP session.",t=>e.auth.status(t.flowId),"read"),n({},"shaper_logout","Sign out globally for this Shaper server. All local projects and Agent sessions share this login.",()=>e.auth.logout(),"destructive"),n({},"shaper_projects","List applications available to this authorization.",()=>e.api.projects(),"read"),n({workspace:d,template:s.enum(["h5","react","phaser"]).optional(),name:ne.optional(),appId:s.string().optional(),installDependencies:s.boolean().default(!0)},"shaper_init","Create a vanilla HTML, React or Phaser project and a Shaper application, or initialize an existing source directory. Resolve existing identity first; missing apps require browser creation consent. A pending result requires finishing authorization and retrying with the same workspace/appId. Never overwrite a conflicting existing binding.",t=>K(e.api,t.workspace,t)),n({workspace:d,appId:s.string()},"shaper_link","Associate the local source directory with an existing authorized Shaper application.",t=>z(e.api,t.workspace,t.appId)),n({workspace:d},"shaper_dev_start","Start a local development server using shaper.config.json and return its verified URL.",t=>W(t.workspace)),n({workspace:d},"shaper_dev_stop","Stop the development session managed for this project.",t=>Y(t.workspace)),n({workspace:d},"shaper_dev_logs","Read recent local development output.",t=>Z(t.workspace),"read"),n({workspace:d},"shaper_build","Run the project build command and verify the web output.",t=>V(t.workspace)),n({workspace:d},"shaper_check","Check project configuration; this is not a behavior or cloud connectivity test.",t=>H(t.workspace),"read"),n({workspace:d},"shaper_web_deploy","Build and upload web code through Shaper; return request status, validation and preview details.",t=>Q(e.api,t.workspace)),n({workspace:d,versionId:s.string(),description:s.string().min(1),coverPath:s.string().optional()},"shaper_web_publish","Prepare review details and open a browser confirmation page. This does NOT submit review: the user edits details and submits in the browser. Cover is optional here and can be supplied in the browser.",t=>U(e.api,t.workspace,t.versionId,t.description,t.coverPath)),n({workspace:d,directory:s.string().optional()},"hupu_cloud_init","Create a local Node backend source directory; does not provision resources or overwrite existing code.",t=>B(t.workspace,t.directory)),n({workspace:d,directory:s.string().optional()},"hupu_cloud_build","Build backend artifacts locally. Deployment also builds by default, so this is only needed to inspect or reuse artifacts.",t=>G(t.workspace,t.directory)),n({workspace:d},"hupu_cloud_status","Read application cloud readiness and current release. No test/production environments or resource profiles are selected by developers.",t=>e.cloud.status(t.workspace),"read"),n({workspace:d,operationId:s.string()},"hupu_cloud_operation","Query the original cloud operation until succeeded or failed. Queued/running are not completion; never resubmit with a new key to bypass an unknown result.",t=>e.cloud.operation(t.workspace,t.operationId),"read"),n({workspace:d},"hupu_cloud_enable","Enable cloud resources for this application; may incur resource charges. Reuses existing resources. Check cloud status for resource readiness before deploying.",t=>e.cloud.enable(t.workspace)),n({workspace:d,directory:s.string().optional(),manifestFile:s.string().optional(),bundleFile:s.string().optional(),idempotencyKey:O},"hupu_cloud_deploy","Publish the whole backend service and its declared routes. Default: build cloud/functions/api (legacy functions/api is detected). Alternatively pass both manifestFile and bundleFile, without directory. Confirm required migrations have completed before deploying. Queued means accepted, not deployed. One application has one active service.",t=>e.cloud.deploy(t.workspace,{...t.directory!==void 0?{directory:t.directory}:{},...t.manifestFile!==void 0?{manifestFile:t.manifestFile}:{},...t.bundleFile!==void 0?{bundleFile:t.bundleFile}:{}},t.idempotencyKey)),n({workspace:d,version:s.string(),file:s.string(),idempotencyKey:O},"hupu_cloud_database_migrate","Submit a versioned PostgreSQL migration file. Queued/running only confirms acceptance or execution. Without succeeded, platform confirmation is required before dependent changes; no migration completion query or retry is exposed. Applied versions are immutable.",t=>e.cloud.migrate(t.workspace,t.version,t.file,t.idempotencyKey)),n({workspace:d},"hupu_cloud_routes","Inspect effective routes. To change routes, edit cloud.json and deploy the service so source and runtime agree.",t=>e.cloud.routes(t.workspace),"read"),o.legacyCloud&&(n({workspace:d},"hupu_legacy_cloud_capabilities","Read Hupu Cloud runtimes, database dialect and environment-creation capabilities for this app.",t=>e.legacyCloud.capabilities(t.workspace),"read"),n({workspace:d},"hupu_legacy_cloud_environments","List cloud environments belonging to this Shaper application.",t=>e.legacyCloud.environments(t.workspace),"read"),n({workspace:d,environment:b,postgres:s.boolean().default(!1)},"hupu_legacy_cloud_create","Provision an environment for this app using the platform-approved plan. This may incur cloud charges. PostgreSQL must be requested at creation.",t=>e.legacyCloud.create(t.workspace,t.environment,t.postgres)),n({workspace:d,environment:b},"hupu_legacy_cloud_status","Refresh the readiness of this Hupu Cloud environment.",t=>e.legacyCloud.status(t.workspace,t.environment),"read"),n({workspace:d,environment:b},"hupu_legacy_cloud_functions","List cloud functions and deployment states.",t=>e.legacyCloud.functions(t.workspace,t.environment),"read"),n({workspace:d,environment:b,name:ne,directory:s.string(),idempotencyKey:O},"hupu_legacy_cloud_function_deploy","Legacy event-function deployment only (index.js exporting main). For new HTTP backends use hupu_cloud_init and hupu_cloud_deploy.",t=>e.legacyCloud.deployFunction(t.workspace,t.environment,t.name,t.directory,t.idempotencyKey)),n({workspace:d,environment:b,name:ne,payload:s.unknown(),idempotencyKey:O},"hupu_legacy_cloud_function_invoke","Invoke a cloud function with JSON input; report execution status and output.",t=>e.legacyCloud.invoke(t.workspace,t.environment,t.name,t.payload,t.idempotencyKey)),n({workspace:d,environment:b,name:ne},"hupu_legacy_cloud_function_logs","Read recent function logs.",t=>e.legacyCloud.logs(t.workspace,t.environment,t.name),"read"),n({workspace:d,environment:b,sql:s.string().min(1).max(6e4),idempotencyKey:O},"hupu_legacy_cloud_database_query","Execute privileged PostgreSQL SQL in the selected app environment. This can mutate or delete data; follow the requested business scope.",t=>e.legacyCloud.sql(t.workspace,t.environment,t.sql,t.idempotencyKey),"destructive"),n({workspace:d,environment:b,prefix:s.string().optional(),cursor:s.string().optional()},"hupu_legacy_cloud_storage_list","List private cloud objects, with pagination.",t=>e.legacyCloud.listObjects(t.workspace,t.environment,t.prefix,t.cursor),"read"),n({workspace:d,environment:b,objectKey:s.string(),file:s.string(),idempotencyKey:O},"hupu_legacy_cloud_storage_upload","Upload a project file (maximum 10 MiB) to private application storage. Replaces the same object key.",t=>e.legacyCloud.putObject(t.workspace,t.environment,t.objectKey,t.file,t.idempotencyKey)),n({workspace:d,environment:b,objectKey:s.string(),destination:s.string()},"hupu_legacy_cloud_storage_download","Download a cloud object to a new file inside the project; existing files are never overwritten.",t=>e.legacyCloud.getObject(t.workspace,t.environment,t.objectKey,t.destination)),n({workspace:d,environment:b,objectKey:s.string(),idempotencyKey:O},"hupu_legacy_cloud_storage_delete","Delete the explicitly requested object from application storage.",t=>e.legacyCloud.deleteObject(t.workspace,t.environment,t.objectKey,t.idempotencyKey),"destructive")),i}async function Pe(e={}){let o=await c.create(),i=it(o,e);await i.connect(new ot);let n=async()=>{await o.auth.close(),await i.close()};process.once("SIGTERM",()=>{n()}),process.once("SIGINT",()=>{n()}),process.stdin.once("end",()=>{n()})}var p=new rt().name("shaper").description("Shaper \u672C\u5730\u5F00\u53D1\u3001\u7F51\u9875\u4EA4\u4ED8\u4E0E\u864E\u6251\u4E91\u5DE5\u5177").version(X),ie=e=>process.stdout.write(JSON.stringify(e,null,2)+`
13
+ `),r=e=>async(...o)=>{ie(await e(...o))};p.command("install").description("\u5168\u5C40\u5B89\u88C5 MCP \u548C Skills \u5230\u6307\u5B9A IDE").requiredOption("--ide <names>","codex,cursor,claude").option("--dev","\u76F4\u63A5\u4F7F\u7528\u5F53\u524D\u672C\u5730\u5305\u8FD0\u884C MCP \u548C\u6280\u80FD\uFF0C\u4E0D\u590D\u5236\u53D1\u884C\u5FEB\u7167").option("--skills <names>","\u9644\u52A0\u4E13\u4E1A\u6280\u80FD\uFF0C\u9017\u53F7\u5206\u9694").action(r(async e=>fe(e.ide.split(","),{skills:e.skills?.split(","),dev:e.dev===!0})));p.command("update").description("\u5B89\u88C5\u6307\u5B9A\u53D1\u5E03\u7248\u672C\uFF0C\u4FDD\u7559\u539F IDE \u8BBE\u7F6E").requiredOption("--version <version>").requiredOption("--ide <names>").action(r(async e=>fe(e.ide.split(","),{version:e.version})));p.command("uninstall").description("\u79FB\u9664\u672C\u5DE5\u5177\u7BA1\u7406\u7684 IDE \u914D\u7F6E\u548C\u6280\u80FD\u94FE\u63A5").action(r(je));p.command("doctor").description("\u68C0\u67E5\u5B89\u88C5\u4E0E\u9879\u76EE\u72B6\u6001").option("--cwd <directory>").action(r(async e=>({installation:await Le(),status:await(await c.create()).status(e.cwd&&l(e.cwd))})));p.command("config").description("\u67E5\u770B\u6216\u8BBE\u7F6E CLI / MCP \u5171\u7528\u7684\u9ED8\u8BA4\u670D\u52A1\uFF1B\u4E0D\u9700\u8981\u767B\u5F55").option("--server <origin>","\u4FDD\u5B58\u9ED8\u8BA4\u670D\u52A1\u5730\u5740").action(r(async e=>(e.server&&await se(e.server),{server:await be(),configDirectory:y(),source:process.env.SHAPER_SERVER?"SHAPER_SERVER":"global config or default",...e.server?{saved:!0,configuredServer:e.server,restartMcp:!0}:{}})));p.command("login").description("\u8FDE\u63A5\u5168\u5C40\u8D26\u53F7\uFF1B\u5DF2\u6709\u6743\u9650\u76F4\u63A5\u590D\u7528").option("--server <origin>").option("--cloud","\u8FFD\u52A0\u4E91\u51FD\u6570\u548C\u6570\u636E\u5E93\u7BA1\u7406\u6743\u9650").option("--app <appId>","\u4E3A\u5DF2\u6709\u5E94\u7528\u8865\u5145\u6388\u6743").option("--reauthorize","\u6253\u5F00\u7F51\u9875\u589E\u52A0\u6388\u6743\u8303\u56F4").option("--no-browser","\u4EC5\u8F93\u51FA\u6388\u6743\u94FE\u63A5").action(async e=>{let o=await c.create(e.server);try{let i=await o.auth.start({cloud:e.cloud===!0,openBrowser:e.browser!==!1,reauthorize:e.reauthorize===!0,...e.app?{appId:e.app}:{}});ie(i),i.status==="pending"&&ie(await o.auth.wait(i.flowId)),e.server&&await se(o.auth.server)}finally{await o.auth.close()}});p.command("logout").description("\u9000\u51FA\u5168\u5C40\u8D26\u53F7\uFF0C\u5F53\u524D\u670D\u52A1\u7684\u6240\u6709\u672C\u5730\u9879\u76EE\u90FD\u9700\u8981\u91CD\u65B0\u767B\u5F55").action(r(async()=>(await c.create()).auth.logout()));p.command("whoami").description("\u8BFB\u53D6\u5F53\u524D\u767B\u5F55\u8EAB\u4EFD\u4E0E\u6388\u6743\u8303\u56F4").action(r(async()=>(await c.create()).api.me()));p.command("init").argument("[directory]","\u5DE5\u7A0B\u76EE\u5F55",".").option("--name <name>").option("--app <appId>","\u5173\u8054\u6307\u5B9A\u5E94\u7528\uFF1B\u5C1A\u672A\u521B\u5EFA\u65F6\u5728\u6D4F\u89C8\u5668\u786E\u8BA4\u521B\u5EFA").option("--template <name>","\u7A7A\u76EE\u5F55\u6A21\u677F\uFF1Ah5\u3001react\u3001phaser").option("--no-install","\u8DF3\u8FC7\u4F9D\u8D56\u5B89\u88C5").action(r(async(e,o)=>K((await c.create()).api,l(e),{...o.name?{name:o.name}:{},...o.app?{appId:o.app}:{},waitForAuthorization:!0,template:o.template,installDependencies:o.install!==!1})));p.command("link").requiredOption("--app <appId>").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>z((await c.create()).api,l(e.cwd),e.app)));p.command("projects").action(r(async()=>(await c.create()).api.projects()));p.command("status").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>(await c.create()).status(l(e.cwd))));p.command("dev").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>W(l(e.cwd))));p.command("stop").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>Y(l(e.cwd))));p.command("logs").description("\u8BFB\u53D6\u672C\u5730\u5F00\u53D1\u670D\u52A1\u65E5\u5FD7").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>Z(l(e.cwd))));p.command("build").description("\u6784\u5EFA\u7F51\u9875\u5236\u54C1").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>V(l(e.cwd))));p.command("check").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(async e=>{let o=await H(l(e.cwd));ie(o),o.passed||(process.exitCode=1)});p.command("deploy").description("\u6784\u5EFA\u7F51\u9875\u5E76\u4EA4\u4ED8\u5230 Shaper \u9884\u89C8").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>Q((await c.create()).api,l(e.cwd))));p.command("publish").description("\u6253\u5F00\u6D4F\u89C8\u5668\u786E\u8BA4\u6307\u5B9A\u7248\u672C\u7684\u5BA1\u6838\u63D0\u4EA4").requiredOption("--version <versionId>").requiredOption("--description <text>").option("--cover <file>","\u53EF\u9009\u5DE5\u7A0B\u5185\u5C01\u9762\uFF0C\u4E5F\u53EF\u5728\u6D4F\u89C8\u5668\u8865\u5145").option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".").action(r(async e=>U((await c.create()).api,l(e.cwd),e.version,e.description,e.cover)));var E=p.command("cloud").description("\u5E94\u7528\u4E91\u670D\u52A1\uFF1A\u5F00\u901A\u3001\u53D1\u5E03\u3001\u6570\u636E\u5E93\u8FC1\u79FB\u3001\u72B6\u6001\u548C\u8DEF\u7531");function _(e,o,i){return e.command(o).description(i).option("--cwd <directory>","\u5DE5\u7A0B\u76EE\u5F55",".")}_(E,"init [directory]","\u521B\u5EFA\u540E\u53F0\u670D\u52A1\u6E90\u7801\u76EE\u5F55\uFF0C\u9ED8\u8BA4 cloud/functions/api\uFF0C\u4E0D\u8986\u76D6\u5DF2\u6709\u4EE3\u7801").action(r(async(e,o)=>B(l(o.cwd),e)));_(E,"build [directory]","\u6784\u5EFA\u540E\u53F0\u670D\u52A1\u5236\u54C1\uFF1B\u4E0D\u90E8\u7F72").action(r(async(e,o)=>G(l(o.cwd),e)));_(E,"status","\u67E5\u770B\u5E94\u7528\u4E91\u670D\u52A1\u662F\u5426\u5C31\u7EEA\u3001\u5F53\u524D\u90E8\u7F72\u4E86\u4EC0\u4E48").action(r(async e=>(await c.create()).cloud.status(l(e.cwd))));_(E,"operation <operationId>","\u67E5\u8BE2\u539F\u4E91\u64CD\u4F5C\u7684\u6700\u7EC8\u7ED3\u679C\uFF0C\u4E0D\u91CD\u590D\u63D0\u4EA4").action(r(async(e,o)=>(await c.create()).cloud.operation(l(o.cwd),e)));_(E,"enable","\u5F00\u901A\u5E94\u7528\u4E91\u670D\u52A1\uFF0C\u91CD\u590D\u8C03\u7528\u590D\u7528\u5DF2\u6709\u8D44\u6E90").action(r(async e=>(await c.create()).cloud.enable(l(e.cwd))));_(E,"deploy","\u53D1\u5E03\u540E\u53F0\u670D\u52A1\u4E0E cloud.json \u8DEF\u7531\uFF1B\u9ED8\u8BA4\u4ECE cloud/functions/api \u6784\u5EFA").option("--directory <directory>","\u6E90\u7801\u76EE\u5F55\uFF1B\u4E0D\u80FD\u4E0E\u5236\u54C1\u53C2\u6570\u6DF7\u7528").option("--manifest <file>","\u5DF2\u6709\u5236\u54C1\u7684 manifest\uFF1B\u987B\u540C\u65F6\u63D0\u4F9B --bundle").option("--bundle <file>","\u5DF2\u6709\u5236\u54C1\u7684 bundle\uFF1B\u987B\u540C\u65F6\u63D0\u4F9B --manifest").option("--key <key>","\u8BF7\u6C42\u5E42\u7B49\u952E\uFF1B\u9ED8\u8BA4\u6309\u5185\u5BB9\u751F\u6210").action(r(async e=>(await c.create()).cloud.deploy(l(e.cwd),{...e.directory!==void 0?{directory:e.directory}:{},...e.manifest!==void 0?{manifestFile:e.manifest}:{},...e.bundle!==void 0?{bundleFile:e.bundle}:{}},e.key)));var at=E.command("db").description("\u5E94\u7528\u7684\u6570\u636E\u5E93\u53D8\u66F4");_(at,"migrate","\u63D0\u4EA4\u7248\u672C\u5316 PostgreSQL \u8FC1\u79FB").requiredOption("--version <version>").requiredOption("--file <file>").option("--key <key>").action(r(async e=>(await c.create()).cloud.migrate(l(e.cwd),e.version,e.file,e.key)));_(E,"routes","\u67E5\u770B\u5DF2\u751F\u6548\u8DEF\u7531\uFF1B\u4FEE\u6539 cloud.json \u540E\u91CD\u65B0 deploy").action(r(async e=>(await c.create()).cloud.routes(l(e.cwd))));var st=p.command("legacy").description("\u5B58\u91CF\u7CFB\u7EDF\u517C\u5BB9\u5DE5\u5177"),ct=st.command("cloud").description("\u65E7\u4E8B\u4EF6\u51FD\u6570\u6267\u884C\u5668\uFF1B\u4E0D\u80FD\u64CD\u4F5C\u65B0\u7248\u5E94\u7528\u4E91\u8D44\u6E90");function v(e,o){return _(ct,e,o)}v("capabilities","\u8BFB\u53D6\u8FD0\u884C\u65F6\u3001\u6570\u636E\u5E93\u65B9\u8A00\u4E0E\u5957\u9910\u914D\u7F6E").action(r(async e=>(await c.create()).legacyCloud.capabilities(l(e.cwd))));v("list","\u5217\u51FA\u5F53\u524D\u5E94\u7528\u7684\u4E91\u73AF\u5883").action(r(async e=>(await c.create()).legacyCloud.environments(l(e.cwd))));v("create <environment>","\u6309\u5E73\u53F0\u5957\u9910\u5F00\u901A\u4E91\u73AF\u5883\uFF0C\u53EF\u80FD\u4EA7\u751F\u8D39\u7528").option("--postgres","\u540C\u65F6\u5F00\u901A PostgreSQL").action(r(async(e,o)=>(await c.create()).legacyCloud.create(l(o.cwd),e,o.postgres===!0)));v("status <environment>","\u8BFB\u53D6\u771F\u5B9E\u4E91\u73AF\u5883\u72B6\u6001").action(r(async(e,o)=>(await c.create()).legacyCloud.status(l(o.cwd),e)));v("functions <environment>","\u5217\u51FA\u4E91\u51FD\u6570\u53CA\u72B6\u6001").action(r(async(e,o)=>(await c.create()).legacyCloud.functions(l(o.cwd),e)));v("deploy <environment> <name> <directory>","\u90E8\u7F72\u5DF2\u6253\u5305\u7684\u4E91\u51FD\u6570\u76EE\u5F55").option("--key <key>","\u8BF7\u6C42\u5E42\u7B49\u952E").action(r(async(e,o,i,n)=>(await c.create()).legacyCloud.deployFunction(l(n.cwd),e,o,i,n.key)));v("invoke <environment> <name>","\u6267\u884C\u4E91\u51FD\u6570").option("--input <file>","JSON \u8F93\u5165\u6587\u4EF6").option("--key <key>").action(r(async(e,o,i)=>(await c.create()).legacyCloud.invoke(l(i.cwd),e,o,i.input?JSON.parse(await Te(i.input,"utf8")):{},i.key)));v("logs <environment> <name>","\u67E5\u770B\u4E91\u51FD\u6570\u65E5\u5FD7").action(r(async(e,o,i)=>(await c.create()).legacyCloud.logs(l(i.cwd),e,o)));v("sql <environment>","\u6267\u884C\u6570\u636E\u5E93\u7BA1\u7406 SQL").requiredOption("--file <file>","SQL \u6587\u4EF6").option("--key <key>").action(r(async(e,o)=>(await c.create()).legacyCloud.sql(l(o.cwd),e,await Te(o.file,"utf8"),o.key)));v("storage-list <environment>","\u5217\u51FA\u4E91\u5B58\u50A8\u5BF9\u8C61").option("--prefix <prefix>").option("--cursor <cursor>").action(r(async(e,o)=>(await c.create()).legacyCloud.listObjects(l(o.cwd),e,o.prefix,o.cursor)));v("storage-put <environment> <objectKey> <file>","\u4E0A\u4F20\u5DE5\u7A0B\u5185\u6587\u4EF6\u5230\u79C1\u6709\u4E91\u5B58\u50A8").option("--key <key>").action(r(async(e,o,i,n)=>(await c.create()).legacyCloud.putObject(l(n.cwd),e,o,i,n.key)));v("storage-get <environment> <objectKey> <destination>","\u4E0B\u8F7D\u5230\u5DE5\u7A0B\u5185\u7684\u65B0\u6587\u4EF6").action(r(async(e,o,i,n)=>(await c.create()).legacyCloud.getObject(l(n.cwd),e,o,i)));v("storage-delete <environment> <objectKey>","\u5220\u9664\u6307\u5B9A\u4E91\u5B58\u50A8\u5BF9\u8C61").option("--key <key>").action(r(async(e,o,i)=>(await c.create()).legacyCloud.deleteObject(l(i.cwd),e,o,i.key)));p.command("mcp").command("serve").description("\u542F\u52A8 stdio MCP \u670D\u52A1").option("--legacy-cloud","\u989D\u5916\u5F00\u653E\u65E7\u4E91\u7EF4\u62A4\u5DE5\u5177").action(async e=>Pe({legacyCloud:e.legacyCloud===!0}));try{await p.parseAsync()}catch(e){process.stderr.write(JSON.stringify($(e))+`
14
+ `),process.exitCode=1}
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ export declare const serviceManifestSchema: z.ZodObject<{
3
+ version: z.ZodLiteral<1>;
4
+ runtime: z.ZodLiteral<"nodejs20">;
5
+ memoryMB: z.ZodNumber;
6
+ timeoutSeconds: z.ZodNumber;
7
+ routes: z.ZodArray<z.ZodObject<{
8
+ method: z.ZodEnum<{
9
+ DELETE: "DELETE";
10
+ GET: "GET";
11
+ HEAD: "HEAD";
12
+ PATCH: "PATCH";
13
+ POST: "POST";
14
+ PUT: "PUT";
15
+ }>;
16
+ path: z.ZodString;
17
+ access: z.ZodEnum<{
18
+ public: "public";
19
+ user: "user";
20
+ }>;
21
+ handler: z.ZodString;
22
+ }, z.core.$strict>>;
23
+ serverSdk: z.ZodObject<{
24
+ name: z.ZodLiteral<"@hupu/cloud-server">;
25
+ version: z.ZodString;
26
+ }, z.core.$strict>;
27
+ }, z.core.$strict>;
28
+ /** 仅生成本地源码,不开通环境、不安装依赖、不覆盖现有服务。 */
29
+ export declare function initCloudService(workspace: string, target?: string): Promise<{
30
+ directory: string;
31
+ files: string[];
32
+ serverSdk: {
33
+ name: "@hupu/cloud-server";
34
+ version: string;
35
+ };
36
+ next: string;
37
+ }>;
38
+ /** 不执行项目 build 脚本;Toolkit 负责固定 Node/CJS 构建和 SDK 外置规则。 */
39
+ export declare function buildCloudService(workspace: string, target?: string): Promise<{
40
+ directory: string;
41
+ manifestFile: string;
42
+ bundleFile: string;
43
+ sha256: string;
44
+ bytes: number;
45
+ serverSdk: {
46
+ name: "@hupu/cloud-server";
47
+ version: string;
48
+ };
49
+ routes: {
50
+ method: "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT";
51
+ path: string;
52
+ access: "public" | "user";
53
+ handler: string;
54
+ }[];
55
+ }>;
@@ -0,0 +1,71 @@
1
+ import { ShaperApi } from './api.js';
2
+ export type CloudRequestResult = {
3
+ operationId?: string;
4
+ status: 'queued' | 'running' | 'succeeded' | 'failed';
5
+ error?: string;
6
+ };
7
+ export type CloudStatus = {
8
+ appId: string;
9
+ status: string;
10
+ release?: {
11
+ digest: string;
12
+ deployedAt: string;
13
+ };
14
+ };
15
+ export type CloudRouteTable = {
16
+ appId: string;
17
+ revision: string;
18
+ routes: {
19
+ id: string;
20
+ method: string;
21
+ path: string;
22
+ access: 'public' | 'user';
23
+ handler: string;
24
+ }[];
25
+ };
26
+ export type DeployInput = {
27
+ directory?: string;
28
+ manifestFile?: string;
29
+ bundleFile?: string;
30
+ };
31
+ /** 开发者云用例。传输层 cloud-v2 是现有 Shaper 契约,不进入业务命名。 */
32
+ export declare class CloudApi {
33
+ readonly api: ShaperApi;
34
+ constructor(api: ShaperApi);
35
+ status(path: string): Promise<CloudStatus>;
36
+ operation(path: string, operationId: string): Promise<CloudRequestResult>;
37
+ enable(path: string): Promise<{
38
+ cloud: CloudStatus;
39
+ } & CloudRequestResult>;
40
+ deploy(path: string, input?: DeployInput, key?: string): Promise<{
41
+ operationId?: string;
42
+ status: 'queued' | 'running' | 'succeeded' | 'failed';
43
+ error?: string;
44
+ artifact: {
45
+ directory: string;
46
+ manifestFile: string;
47
+ bundleFile: string;
48
+ sha256: string;
49
+ bytes: number;
50
+ serverSdk: {
51
+ name: "@hupu/cloud-server";
52
+ version: string;
53
+ };
54
+ routes: {
55
+ method: "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT";
56
+ path: string;
57
+ access: "public" | "user";
58
+ handler: string;
59
+ }[];
60
+ } | {
61
+ manifestFile: string;
62
+ bundleFile: string;
63
+ };
64
+ }>;
65
+ routes(path: string): Promise<CloudRouteTable>;
66
+ migrate(path: string, version: string, file: string, key?: string): Promise<CloudRequestResult>;
67
+ private source;
68
+ private upload;
69
+ private target;
70
+ private checkContained;
71
+ }
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ export declare class ShaperError extends Error {
3
+ readonly code: string;
4
+ readonly details?: unknown;
5
+ constructor(code: string, message: string, details?: unknown);
6
+ }
7
+ export declare const userConfigSchema: z.ZodObject<{
8
+ schemaVersion: z.ZodLiteral<1>;
9
+ server: z.ZodString;
10
+ }, z.core.$strict>;
11
+ export declare function configRoot(): string;
12
+ export declare function validateServer(value: string): string;
13
+ export declare function atomicJson(path: string, value: unknown): Promise<void>;
14
+ export declare function readJson(path: string): Promise<unknown>;
15
+ export declare function serverConfig(): Promise<string>;
16
+ export declare function setServer(server: string): Promise<void>;
17
+ export declare function safeError(error: unknown): {
18
+ code: string;
19
+ message: string;
20
+ details?: {} | null;
21
+ };