modu-platform 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +117 -2
- package/bin/modu.js +67 -0
- package/package.json +19 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025-2026 the modu authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
#
|
|
1
|
+
# modu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
modu 命令行:低代码业务平台的二进制命令面。**纯二进制分发**——本包不含任何源码,`npm install` 只下载当前平台的预编译单文件二进制。
|
|
4
|
+
|
|
5
|
+
应用侧通过 modu 命令完成 MCP 启动、项目建立、研发、运维等全部活动。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -g modu-platform # 全局命令 modu
|
|
11
|
+
npx -y modu-platform <verb> # 一次性执行(注意:包名是 modu-platform,不要用 npx modu)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
> npm 上裸名 `modu` 是一个无关的第三方占位包(0.0.0,不可用),命令与包名的对应关系是:包 `modu-platform` → 命令 `modu`。
|
|
15
|
+
|
|
16
|
+
## 命令
|
|
17
|
+
|
|
18
|
+
安装后 `modu` 是唯一入口(服务端子命令缺省 `serve`):
|
|
19
|
+
|
|
20
|
+
| 动词 | 作用 |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `modu new --dir <dir> [--id] [--title] [--dry] [--json]` | **造项目工程**(骨架与 studio「创建工程」同一份;不写 `iam.json`) |
|
|
23
|
+
| `modu serve [--project <dir>]` | 服务端命令管道(缺省动词;`--project` 单应用,等价 `MODU_PROJECT_DIR`) |
|
|
24
|
+
| `modu hub --project <dir> [--port] [--dist]` | 本地运行 hub:静态托管(缺省用二进制**内嵌壳**,零仓库起站;`--dist` 可覆盖)+ 只读配置端点 |
|
|
25
|
+
| `modu check --project <dir>` | 交付态项目自检(`--fix` 剥离陈旧全量拷贝) |
|
|
26
|
+
| `modu validate <file\|dir\|--presets>` | PageSpec 校验(与浏览器同一 validateSpec) |
|
|
27
|
+
| `modu test <projectDir>` | DSL 测试工件(跑生产执行器) |
|
|
28
|
+
| `modu admin iam <get\|validate\|set\|migrate>` | IAM 管理通道 |
|
|
29
|
+
| `modu admin credential set --project <dir> --password <pw> [--username] [--dsn]` | **设初始口令**(打破「首个账号没口令登不进去」) |
|
|
30
|
+
| `modu backup` / `modu restore` | 项目库备份 / 恢复 |
|
|
31
|
+
| `modu env <create\|list\|promote>` | 派生环境(UAT / 预发) |
|
|
32
|
+
| `modu cockpit --project <dir>` | 驾驶舱 sidecar(只读六面 + 提案端点,只绑 127.0.0.1) |
|
|
33
|
+
| `modu change <list\|show\|apply\|rollback>` | 变更集管理 |
|
|
34
|
+
| `modu release <show\|note>` | 发布记录 |
|
|
35
|
+
| `modu mcp` | 启动 MCP stdio 服务(JSON-RPC) |
|
|
36
|
+
| `modu help` / `modu --help` | 用法(缺少动词时也会打印) |
|
|
37
|
+
|
|
38
|
+
## 从零起一个应用(六条命令)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
modu new --dir ../demo-app --id demo-app --title "我的第一个应用"
|
|
42
|
+
modu admin iam set --project ../demo-app --file iam.min.json # 组织/角色/超管(可先 validate)
|
|
43
|
+
modu admin credential set --project ../demo-app --password '改我' # 只在 serve 停着时
|
|
44
|
+
modu check --project ../demo-app
|
|
45
|
+
MODU_PROJECT_DIR=../demo-app modu serve # 业务 API,缺省 :5190
|
|
46
|
+
modu hub --project ../demo-app --port 3300 # 工作台,另开一个终端
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
打开 <http://127.0.0.1:3300> → 用上一步的账号登录(口令由服务端校验,拿到 JWT)。
|
|
50
|
+
|
|
51
|
+
## 0.1.1 升级说明(2026-11-16)
|
|
52
|
+
|
|
53
|
+
### 新增
|
|
54
|
+
|
|
55
|
+
| 能力 | 说明 |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `modu new` | 安装态即可造项目,不再需要仓库脚本 `scripts/project-new.mjs`。支持 `--dry`(只列将创建的文件)与 `--json`(单文档)。目标目录非空时拒绝覆盖,不做删除。 |
|
|
58
|
+
| `modu admin credential set` | 设初始口令。设口令的端点要求已登录,而新项目没有凭据可登——这条命令用同一份 `AuthCredentialStore` 在 CLI 侧打破死锁。口令强度走 core 的同一把尺;**serve 持数据目录锁时拒绝**(PGlite 单写者),`--dsn` 模式不受此限。 |
|
|
59
|
+
| serve → hub 运行态握手 | `serve` 起来后把「项目 → 服务地址」写进本机临时目录(`<tmp>/modu-serve-state/<项目路径 sha1>.json`,退出即删);`hub` 读它装配 `/__srv__` 反代。**不再需要记 `?server=`,也不需要配 CORS。** |
|
|
60
|
+
| hub 探测 + 校验 | 没有运行态、也没有任何显式配置时,hub 探一次 `127.0.0.1:${VITE_PORT_SERVER:-5190}`,**`/health` 的 `projectId` 必须等于本案 `project.json` 的 id** 才采用;不匹配一律放弃。日志会写「探测到 … 正服务本项目(projectId=…)」。 |
|
|
61
|
+
| 壳的服务端登录 | 登录页在服务端模式下 `POST <server>/api/auth/login`,成功存 JWT 并重载;`AuthGate` 认 JWT。系统管理的分区 tab 也认 JWT 身份(`currentUserId()` 从令牌载荷取 `sub`)。 |
|
|
62
|
+
|
|
63
|
+
### 升级后要改什么
|
|
64
|
+
|
|
65
|
+
1. **`modu serve --project <dir>` 现在真的生效了。** 0.1.0 会静默忽略它(服务照样起、`/health` 报「没有任何应用」)。如果你之前靠 `MODU_PROJECT_DIR` 兜底,两种写法现在都对;旗标没给值会**快速失败**,不再静默。
|
|
66
|
+
2. **不再需要 `?server=` 与 `MODU_CORS_ORIGINS`。** hub 会自动装配同源反代 `/__srv__`。若你先前把 `http://127.0.0.1:5190` 写进了书签或脚本,可以去掉;显式 `--server` / `MODU_HUB_SERVER` / `project.json#server` 仍然优先。
|
|
67
|
+
3. **hub 的 `/` 重定向会带 `server=/__srv__`。** 壳的登录门按 URL 参数选认证通道;如果你有自己的反代或网关,确认它保留这个查询参数,否则会退回「本地项目模式」(登录页会出现「项目账号/直登」)。
|
|
68
|
+
4. **登录页行为变了。** 服务端模式下不再显示「项目账号/直登」,只有口令登录;口令错误时显示服务端文案,**不回落本地库**(混用会让本地任意账号进服务端页面)。真要用浏览器本地账号,用本地项目模式(不带 `server` 绑定)。
|
|
69
|
+
5. **系统管理页依赖 JWT 身份。** tab 的可见性由 `canRead()` 决定,而它要先解析出「当前是谁」。如果令牌被替换成非 JWT 或丢失 `sub`,页面会**只剩总览且不报错**——这是最容易误判成「功能没了」的一种状态。
|
|
70
|
+
|
|
71
|
+
### 已知边界
|
|
72
|
+
|
|
73
|
+
- `auth: "none"` 的项目 `features` **不得含 `system`**(系统管理不允许匿名可达,平台校验会报错)。要免登录开发,用 `MODU_AUTH_DISABLED=1` + `MODU_DEV_ACTOR=<iam 里的超管用户名>`,且仅限本机开发态。
|
|
74
|
+
- **PGlite 单写者**:`credential set`、`backup`、`restore` 这类要开项目库的动作,先停 serve(恢复用 `--dsn` 指向真 PG 时不受限)。
|
|
75
|
+
- 运行态握手是本机事实:**跨用户、跨容器、跨机器不生效**。那种场景显式给 `--server`,或让 `project.json` 声明 `server`。
|
|
76
|
+
- 空项目的默认页是平台自带的管理台(「Oct Modu · 低码管理平台」)。业务页面从你加第一张表/第一个页面开始出现。
|
|
77
|
+
|
|
78
|
+
## MCP 配置
|
|
79
|
+
|
|
80
|
+
`modu mcp` 直接启动 MCP stdio 服务(标准 JSON-RPC over stdio,22+ 工具),供 AI 宿主接入:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"mcpServers": {
|
|
85
|
+
"modu": { "command": "modu", "args": ["mcp"] }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
工具面覆盖:项目建立(`project_create` 建项目骨架)、研发(`list_materials` / `validate_spec` / `spec_apply` 等)、数据源接入等。`spec_apply` 默认走提案制,`--allow-apply` 显式开启直写:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{ "command": "modu", "args": ["mcp", "--allow-apply"] }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 安装态能力边界
|
|
97
|
+
|
|
98
|
+
本包是**纯二进制载体**,与仓库态 CLI 的边界:
|
|
99
|
+
|
|
100
|
+
- `project_build` / `project_serve` 等需要仓库态的子进程工具明确拒绝(不假成功)——本地运行请用 `modu hub`;
|
|
101
|
+
- `doctor` / `catalog` / `prompt` / `grow` / `drift` / `migrate` 等工程脚手架动词不在此载体(建项目用 `modu new`,或用 MCP 的 `project_create`;校验与测试用 `modu validate` / `modu test`);
|
|
102
|
+
- 运行时无 Node 依赖要求——二进制自包含(PGlite / wasm 与 workbench 壳产物已内嵌,`modu hub` 不需要仓库里的 dist),Node 只用于执行本包的入口脚本。
|
|
103
|
+
|
|
104
|
+
## 平台支持
|
|
105
|
+
|
|
106
|
+
安装时按平台自动选择二进制包(optionalDependencies):
|
|
107
|
+
|
|
108
|
+
| 包 | 平台 |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `modu-platform-darwin-arm64` | macOS arm64 |
|
|
111
|
+
| `modu-platform-linux-x64` | Linux x64 |
|
|
112
|
+
| `modu-platform-windows-x64` | Windows x64 |
|
|
113
|
+
|
|
114
|
+
不支持的平台会明确报错退出,不会假成功。平台包被跳过(`--omit=optional`)时,`modu` 会报出修复指引。
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
Apache-2.0
|
package/bin/modu.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* modu-platform wrapper —— `bin` 入口,按 platform/arch 定位平台包里的单文件二进制并透传。
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要这一层:npm bin 只能指向主包内文件,跨平台必须经主包分发(esbuild 式)。
|
|
6
|
+
* 平台包(modu-platform-<platform>-<arch>,optionalDependencies)无 bin、无 exports,
|
|
7
|
+
* 本文件经 require.resolve 子路径定位其中的二进制。
|
|
8
|
+
*
|
|
9
|
+
* mcp 动词在此拦截:`modu mcp` 直接启动并排的 modu-mcp-<platform>(stdio JSON-RPC),
|
|
10
|
+
* 让应用侧 {"command":"modu","args":["mcp"]} 真正起 MCP(cli-surface.md §3.1④)——
|
|
11
|
+
* modu 服务端二进制内的 mcp 分支只是指路(退出 1),不承载协议。
|
|
12
|
+
*/
|
|
13
|
+
"use strict";
|
|
14
|
+
|
|
15
|
+
const { spawn } = require("node:child_process");
|
|
16
|
+
|
|
17
|
+
// 与 modu-server/build.binary.mjs 的 TARGETS 同源:目录名 / 双产物文件名
|
|
18
|
+
const TARGETS = {
|
|
19
|
+
"darwin arm64": ["modu-platform-darwin-arm64", "modu-darwin-arm64", "modu-mcp-darwin-arm64"],
|
|
20
|
+
"linux x64": ["modu-platform-linux-x64", "modu-linux-x64", "modu-mcp-linux-x64"],
|
|
21
|
+
"win32 x64": ["modu-platform-windows-x64", "modu-windows-x64.exe", "modu-mcp-windows-x64.exe"],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const target = TARGETS[`${process.platform} ${process.arch}`];
|
|
25
|
+
if (!target) {
|
|
26
|
+
console.error(`modu 不支持当前平台 ${process.platform}-${process.arch}(支持:darwin-arm64 / linux-x64 / windows-x64)。`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const [platformPkg, serverBin, mcpBin] = target;
|
|
30
|
+
|
|
31
|
+
// require.resolve 以本包位置为起点(modu-platform 与平台包在宿主 node_modules 平级)
|
|
32
|
+
function resolveBinary(subpath) {
|
|
33
|
+
try {
|
|
34
|
+
return require.resolve(`${platformPkg}/${subpath}`);
|
|
35
|
+
} catch {
|
|
36
|
+
console.error(`找不到平台二进制:${platformPkg}/${subpath}`);
|
|
37
|
+
console.error("常见原因:平台包未安装(npm 安装时 optional 被跳过,如 --omit=optional / --no-optional)。");
|
|
38
|
+
console.error(`修复:重装 modu-platform,或直接安装平台包:npm i -g ${platformPkg}。`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const userArgs = process.argv.slice(2);
|
|
44
|
+
const isMcp = userArgs[0] === "mcp";
|
|
45
|
+
const binary = resolveBinary(isMcp ? mcpBin : serverBin);
|
|
46
|
+
// modu-mcp 直接吃 MCP 参数(--allow-apply 等),不带 "mcp" 动词
|
|
47
|
+
const args = isMcp ? userArgs.slice(1) : userArgs;
|
|
48
|
+
|
|
49
|
+
const child = spawn(binary, args, { stdio: "inherit", env: process.env, windowsHide: true });
|
|
50
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
51
|
+
process.on(signal, () => {
|
|
52
|
+
try {
|
|
53
|
+
child.kill(signal);
|
|
54
|
+
} catch {
|
|
55
|
+
/* 子进程已退出 */
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
child.on("error", (error) => {
|
|
60
|
+
console.error(`modu 启动失败:${error.message}`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
|
63
|
+
child.on("exit", (code, signal) => {
|
|
64
|
+
// 信号杀 → 128+n(shell 约定);SIGINT=2 / SIGTERM=15 / SIGHUP=1
|
|
65
|
+
const signalNumbers = { SIGINT: 2, SIGTERM: 15, SIGHUP: 1 };
|
|
66
|
+
process.exit(signal ? 128 + (signalNumbers[signal] ?? 15) : (code ?? 1));
|
|
67
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modu-platform",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "modu 命令行:低代码业务平台的二进制命令面(MCP 启动 · 项目建立 · 研发 · 运维)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"bin": {
|
|
7
|
+
"modu": "bin/modu.js"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"optionalDependencies": {
|
|
17
|
+
"modu-platform-darwin-arm64": "0.1.1",
|
|
18
|
+
"modu-platform-linux-x64": "0.1.1",
|
|
19
|
+
"modu-platform-windows-x64": "0.1.1"
|
|
20
|
+
}
|
|
21
|
+
}
|