@hupu-tech/shaper 0.0.0-stage → 0.2.3

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 +24 -0
  2. package/LICENSE +3 -0
  3. package/README.md +98 -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,24 @@
1
+ # Changelog
2
+
3
+ ## 0.2.3 — 2026-11-12
4
+
5
+ - 精简使用文档,聚焦安装、项目接入、开发和提审。
6
+ - 明确新建应用必须经过浏览器确认。
7
+
8
+ ## 0.2.2 — 2026-11-12
9
+
10
+ - 收紧 npm 发行白名单,移除内部文档与环境信息。
11
+ - CLI 和库入口改为压缩构建,不发布源码映射。
12
+ - 增加实际安装包及内嵌 SDK 的发行内容检查。
13
+
14
+ ## 0.2.1 — 2026-11-12
15
+
16
+ - 重写开发者 README,补齐安装、快速开始、客户端接入、工程结构、配置、交付流程及常见问题。
17
+ - CLI 与 MCP 的版本号统一读取 package.json。
18
+ - 明确公开分发、平台接口配置和各操作系统验收边界。
19
+
20
+ ## 0.2.0 — 2026-11-12
21
+
22
+ - 首次向公开 npm registry 提交 Shaper CLI、stdio MCP、核心技能和 HTML/React/Phaser 模板。
23
+ - 提供项目绑定、浏览器授权、本地预览构建、上传及提审确认入口。
24
+ - 支持默认服务配置、本地开发安装模式及 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,99 @@
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 工具中开发网页、游戏和互动体验。提供项目初始化、本地预览、上传提审,以及配套的 Skills 和 MCP。
4
+
5
+ ## 安装
6
+
7
+ 需要 Node.js 22.14+,建议使用 Node.js 24。
8
+
9
+ ```bash
10
+ npm install -g @hupu-tech/shaper
11
+ shaper install --ide cursor
12
+ ```
13
+
14
+ 将 `cursor` 换成 `codex` 或 `claude`,即可接入对应客户端。安装后按提示重启客户端。技能安装一次,多个项目共用。
15
+
16
+ ## 开始开发
17
+
18
+ 在项目目录执行网页提供的初始化命令,将 `AppID` 替换为实际应用 ID:
19
+
20
+ ```bash
21
+ shaper init --app AppID
22
+ ```
23
+
24
+ 新建应用必须在浏览器确认“创建并连接”,确认前不会创建应用或完成项目绑定。已有项目保留原代码和构建方式;应用 ID 冲突时,先核对归属,不要覆盖绑定。
25
+
26
+ 也可以从模板新建项目:
27
+
28
+ ```bash
29
+ shaper init my-project --template react
30
+ cd my-project
31
+ ```
32
+
33
+ 模板支持 `h5`、`react`、`phaser`,默认使用 `h5`。
34
+
35
+ 接下来直接向 AI 描述需求:
36
+
37
+ > 请检查当前项目配置,帮我实现需求,并启动本地预览。
38
+
39
+ 或使用命令行:
40
+
41
+ ```bash
42
+ shaper dev # 本地预览
43
+ shaper check # 检查工程配置
44
+ shaper build # 构建
45
+ ```
46
+
47
+ ## 上传与提审
48
+
49
+ ```bash
50
+ shaper deploy
51
+ shaper publish --version VersionID --description "本次更新说明"
52
+ ```
53
+
54
+ `deploy` 构建并上传,返回版本 ID 和预览信息。预览确认后,将 `VersionID` 替换为实际版本 ID;在打开的浏览器页面核对资料,确认提交后进入审核。
55
+
56
+ ## 其他 AI 工具
57
+
58
+ WorkBuddy、TRAE 等客户端需手动接入,配置方式以客户端支持为准。stdio MCP 配置示例:
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "shaper": {
64
+ "command": "shaper",
65
+ "args": ["mcp", "serve"]
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ 技能目录见安装包内的 `skills/manifest.json`。客户端找不到命令时,可使用 Node 和包内 `dist/cli.js` 的绝对路径启动 MCP。
72
+
73
+ ## 项目与后端
74
+
75
+ - `shaper.config.json`:开发、构建命令及产物目录。
76
+ - `src/`、`public/`:业务源码与静态资源。
77
+ - `docs/`、`AGENTS.md`:项目文档与 AI 开发入口。
78
+ - `.shaper/`:本地绑定和工具状态,不提交 Git。
79
+
80
+ 已有 HTML 或其他框架项目可以接入,无需统一改成 React。需要后端时,让 AI 使用后台开发技能处理云服务、数据库和网关;命令入口为 `shaper cloud --help`。
81
+
82
+ ## 升级与排查
83
+
84
+ ```bash
85
+ npm install -g @hupu-tech/shaper@latest
86
+ shaper install --ide cursor
87
+ ```
88
+
89
+ 升级后重新安装客户端集成,使技能与 MCP 使用新版。
90
+
91
+ - `shaper doctor`:检查安装和登录状态。
92
+ - `shaper status`:查看当前项目状态。
93
+ - `shaper --help`:查看命令;`shaper <命令> --help` 查看参数。
94
+
95
+ 已验证 macOS;Windows 和 Linux 完整流程尚待实机验证。
96
+
97
+ ## 许可证
98
+
99
+ 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
+ };
package/dist/core.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { AuthManager } from './auth.js';
2
+ import { ShaperApi } from './api.js';
3
+ import { CloudApi } from './cloud.js';
4
+ import { LegacyCloudApi } from './legacy-cloud.js';
5
+ export declare class Shaper {
6
+ readonly auth: AuthManager;
7
+ readonly api: ShaperApi;
8
+ readonly cloud: CloudApi;
9
+ readonly legacyCloud: LegacyCloudApi;
10
+ constructor(auth: AuthManager);
11
+ static create(server?: string): Promise<Shaper>;
12
+ status(path?: string): Promise<{
13
+ server: string;
14
+ identity: unknown;
15
+ project?: {};
16
+ }>;
17
+ }
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ declare const tokensSchema: z.ZodObject<{
3
+ accessToken: z.ZodString;
4
+ refreshToken: z.ZodOptional<z.ZodString>;
5
+ expiresAt: z.ZodNumber;
6
+ scope: z.ZodString;
7
+ }, z.core.$strict>;
8
+ export type Tokens = z.infer<typeof tokensSchema>;
9
+ export interface CredentialStore {
10
+ read(server: string): Promise<Tokens | undefined>;
11
+ write(server: string, tokens: Tokens): Promise<void>;
12
+ remove(server: string): Promise<void>;
13
+ }
14
+ /** One shared login per Shaper origin. Project directories never contain these files. */
15
+ export declare class FileCredentials implements CredentialStore {
16
+ private path;
17
+ read(server: string): Promise<Tokens | undefined>;
18
+ write(server: string, tokens: Tokens): Promise<void>;
19
+ remove(server: string): Promise<void>;
20
+ }
21
+ export declare function withCredentialLock<T>(server: string, action: () => Promise<T>): Promise<T>;
22
+ export declare function acquireLoginLock(server: string): Promise<() => Promise<void>>;
23
+ export {};
@@ -0,0 +1 @@
1
+ import{d as S,j as v,k as E,t as y}from"./shared-2ZNSJXPO.js";import{createServer as C}from"node:http";import{createServer as R}from"node:net";import{spawn as k}from"node:child_process";import{randomBytes as T,timingSafeEqual as b}from"node:crypto";import{join as I}from"node:path";import{mkdir as x}from"node:fs/promises";async function H(){let t=await v(process.argv[2]),m=process.argv[3],u=await E(t),l=await new Promise((e,o)=>{let n=R();n.once("error",o),n.listen(0,"127.0.0.1",()=>{let s=n.address();if(!s||typeof s=="string")return o(new Error("No free port"));n.close(()=>e(s.port))})}),c=u.devUrl.replaceAll("{port}",String(l));if(new URL(c).hostname!=="127.0.0.1"&&new URL(c).hostname!=="localhost")throw new Error("devUrl must be loopback");let h=T(32).toString("base64url"),r,a=!0,p=!1,g=!1,d=C(async(e,o)=>{let n=Buffer.from(e.headers.authorization??""),s=Buffer.from(`Bearer ${h}`);if(n.length!==s.length||!b(n,s)){o.writeHead(401).end();return}if(o.setHeader("Content-Type","application/json"),o.setHeader("Cache-Control","no-store"),e.method==="GET"&&e.url==="/status"){o.end(JSON.stringify({id:m,running:a,ready:p}));return}if(e.method==="POST"&&e.url==="/stop"){o.end(JSON.stringify({stopped:!0})),await i();return}o.writeHead(404).end()});async function i(){if(!g){if(g=!0,r?.pid)if(process.platform==="win32")k("taskkill",["/pid",String(r.pid),"/T","/F"],{stdio:"ignore"});else try{process.kill(-r.pid,"SIGTERM")}catch(e){if(e.code!=="ESRCH")throw e}setTimeout(()=>{if(r?.pid&&process.platform!=="win32")try{process.kill(-r.pid,"SIGKILL")}catch(e){e.code!=="ESRCH"&&console.error("Unable to terminate the development process group")}d.close(),process.exit(0)},3e3)}}await new Promise((e,o)=>{d.once("error",o),d.listen(0,"127.0.0.1",e)});let f=d.address();if(!f||typeof f=="string")throw new Error("No control port");let w=y(t);await x(w,{recursive:!0,mode:448}),await S(I(w,"session.json"),{id:m,root:t,controlUrl:`http://127.0.0.1:${f.port}`,token:h,url:c,startedAt:new Date().toISOString()}),r=k(u.devCommand.replaceAll("{port}",String(l)),{cwd:t,shell:!0,detached:process.platform!=="win32",stdio:["ignore","inherit","inherit"],env:{...process.env,SHAPER_DEV_PORT:String(l)}}),r.once("error",e=>{console.error(e.message),a=!1,i()}),r.once("exit",e=>{console.error(`Development process exited: ${e}`),a=!1,p=!1,i()}),setInterval(()=>{!a||p||fetch(c,{signal:AbortSignal.timeout(1e3),redirect:"error"}).then(e=>{p=e.ok}).catch(()=>{})},250).unref(),process.on("SIGTERM",()=>void i()),process.on("SIGINT",()=>void i())}H().catch(t=>{console.error(t instanceof Error?t.message:"Development runner failed"),process.exitCode=1});
package/dist/dev.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { z } from 'zod';
2
+ export declare const sessionSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ root: z.ZodString;
5
+ controlUrl: z.ZodString;
6
+ token: z.ZodString;
7
+ url: z.ZodString;
8
+ startedAt: z.ZodString;
9
+ }, z.core.$strict>;
10
+ export declare function sessionDirectory(root: string): string;
11
+ export declare function devStatus(path: string): Promise<{
12
+ running: boolean;
13
+ root: string;
14
+ ready?: never;
15
+ url?: never;
16
+ sessionId?: never;
17
+ } | {
18
+ root: string;
19
+ running: boolean;
20
+ ready: boolean;
21
+ url: string;
22
+ sessionId: string;
23
+ } | {
24
+ ready?: never;
25
+ root: string;
26
+ running: boolean;
27
+ url: string;
28
+ sessionId: string;
29
+ }>;
30
+ export declare function startDev(path: string): Promise<{
31
+ running: boolean;
32
+ root: string;
33
+ ready?: never;
34
+ url?: never;
35
+ sessionId?: never;
36
+ } | {
37
+ root: string;
38
+ running: boolean;
39
+ ready: boolean;
40
+ url: string;
41
+ sessionId: string;
42
+ } | {
43
+ ready?: never;
44
+ root: string;
45
+ running: boolean;
46
+ url: string;
47
+ sessionId: string;
48
+ }>;
49
+ export declare function stopDev(path: string): Promise<{
50
+ sessionId?: never;
51
+ stopped: boolean;
52
+ alreadyStopped: boolean;
53
+ } | {
54
+ alreadyStopped?: never;
55
+ stopped: boolean;
56
+ sessionId: string;
57
+ }>;
58
+ export declare function devLogs(path: string): Promise<{
59
+ root: string;
60
+ log: string;
61
+ message?: never;
62
+ } | {
63
+ root: string;
64
+ log: string;
65
+ message: string;
66
+ }>;
@@ -0,0 +1,9 @@
1
+ export { Shaper } from './core.js';
2
+ export { AuthManager } from './auth.js';
3
+ export { ShaperApi } from './api.js';
4
+ export { CloudApi, type DeployInput, type CloudRequestResult, type CloudStatus, type CloudRouteTable } from './cloud.js';
5
+ export { LegacyCloudApi } from './legacy-cloud.js';
6
+ export { ShaperError } from './config.js';
7
+ export { initProject, linkProject, buildProject, checkProject, deployWeb, publishWeb } from './workspace.js';
8
+ export { startDev, stopDev, devStatus, devLogs } from './dev.js';
9
+ export { initCloudService, buildCloudService } from './cloud-service.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{a as o,b as r,c as a,d as c,e as f,f as m,g as S}from"./shared-BTZI42QW.js";import{a as e,m as t,n as p,o as u,q as l,r as i,s as d,u as x,v as s,w as y,x as C}from"./shared-2ZNSJXPO.js";export{o as AuthManager,f as CloudApi,m as LegacyCloudApi,S as Shaper,r as ShaperApi,e as ShaperError,c as buildCloudService,u as buildProject,d as checkProject,l as deployWeb,C as devLogs,x as devStatus,a as initCloudService,t as initProject,p as linkProject,i as publishWeb,s as startDev,y as stopDev};
@@ -0,0 +1,25 @@
1
+ import { ShaperApi, type RequestResult } from './api.js';
2
+ /** 仅用于维护旧执行器资源。与 CloudApi 无继承、无自动回退。 */
3
+ export declare class LegacyCloudApi {
4
+ readonly api: ShaperApi;
5
+ constructor(api: ShaperApi);
6
+ private base;
7
+ capabilities(path: string): Promise<unknown>;
8
+ environments(path: string): Promise<unknown>;
9
+ create(path: string, environment: string, postgres?: boolean): Promise<RequestResult>;
10
+ status(path: string, environment: string): Promise<unknown>;
11
+ functions(path: string, environment: string): Promise<unknown>;
12
+ deployFunction(path: string, environment: string, name: string, directory: string, key?: string): Promise<RequestResult>;
13
+ invoke(path: string, environment: string, name: string, payload: unknown, key?: string): Promise<RequestResult>;
14
+ logs(path: string, environment: string, name: string): Promise<unknown>;
15
+ sql(path: string, environment: string, sql: string, key?: string): Promise<RequestResult>;
16
+ listObjects(path: string, environment: string, prefix?: string, cursor?: string): Promise<unknown>;
17
+ putObject(path: string, environment: string, objectKey: string, file: string, key?: string): Promise<RequestResult>;
18
+ getObject(path: string, environment: string, objectKey: string, destination: string): Promise<{
19
+ key: string;
20
+ bytes: number;
21
+ path: string;
22
+ }>;
23
+ deleteObject(path: string, environment: string, objectKey: string, key?: string): Promise<RequestResult>;
24
+ private checkContained;
25
+ }