h3factory 0.0.0-stage → 0.2.0
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/README.md +223 -2
- package/bin/h3factory.js +87 -0
- package/cli.py +880 -0
- package/config.example.json +8 -0
- package/docs/platform_gotchas.md +118 -0
- package/docs/requirement_checklist.md +54 -0
- package/docs/schema_doc.md +216 -0
- package/docs/workflow.md +146 -0
- package/h3design/__init__.py +0 -0
- package/h3design/controls.py +414 -0
- package/h3design/dsl.py +553 -0
- package/h3design/newbuilder.py +852 -0
- package/h3platform/__init__.py +0 -0
- package/h3platform/api.py +214 -0
- package/h3platform/h3console.py +99 -0
- package/h3platform/settings.py +74 -0
- package/h3verify/__init__.py +0 -0
- package/h3verify/verify.py +217 -0
- package/package.json +51 -4
- package/projects/demo/dicts.json +10 -0
- package/projects/demo/generated/product.cs +82 -0
- package/projects/demo/groups.json +3 -0
- package/projects/demo/sheets/product.json +24 -0
- package/scripts/postinstall.js +107 -0
- package/skills/h3factory/SKILL.md +136 -0
- package/skills/h3yun-dev-assistant/BACKEND_GUIDELINES.md +120 -0
- package/skills/h3yun-dev-assistant/DEV_DOC_ROUTING.md +39 -0
- package/skills/h3yun-dev-assistant/FORM_ACTIONS_GUIDELINES.md +116 -0
- package/skills/h3yun-dev-assistant/FRONTEND_GUIDELINES.md +47 -0
- package/skills/h3yun-dev-assistant/OPENAPI_GUIDELINES.md +8 -0
- package/skills/h3yun-dev-assistant/PLATFORM_CONSTRAINTS.md +160 -0
- package/skills/h3yun-dev-assistant/POST_GUIDELINES.md +47 -0
- package/skills/h3yun-dev-assistant/PRACTICE_NOTES.md +626 -0
- package/skills/h3yun-dev-assistant/SKILL.md +70 -0
- package/skills/h3yun-dev-assistant/SQL_GUIDELINES.md +9 -0
- package/skills/h3yun-dev-assistant/TOOL_FUNCTIONS.md +96 -0
- package/templates/controller.cs.tpl +78 -0
package/README.md
CHANGED
|
@@ -1,3 +1,224 @@
|
|
|
1
|
-
#
|
|
1
|
+
# h3factory —— 氚云表单工厂
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
把「需求文档 → 设计 → 建表 → 数据 → 代码」固化成流水线。**确定性部分(建表/导入/校验/骨架代码)全部脚本化,零 LLM 依赖;智能部分(需求→设计、业务规则代码)由 Claude Code 现场完成。** 两者靠一份表单 JSON 定义接起来。
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
需求文档
|
|
7
|
+
↓ [AI 层] 按 docs/requirement_checklist.md 澄清 → 产出设计稿 + 表单 JSON → 人工过目
|
|
8
|
+
projects/<名>/sheets/*.json + dicts.json
|
|
9
|
+
↓ [工厂层] h3factory build <名>
|
|
10
|
+
氚云线上表单(编码自动注册 registry.json)
|
|
11
|
+
↓ h3factory verify <名> ← 只读回读核对(字段/隐藏规则/一行多列/子表/布局项/位置设置/NameSchema)
|
|
12
|
+
↓ h3factory gen <名> <表> ← .cs 提交时代码骨架(TODO 由 AI/人补业务规则)
|
|
13
|
+
交付:代码 +「界面手工配置清单」(必填/审批流等 UI-only 项平台 API 配不了)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
要求:**Node.js ≥ 16**、**Python ≥ 3.10**(只用标准库,无需 pip 安装依赖)。
|
|
19
|
+
|
|
20
|
+
### 从 npm 安装(推荐)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g h3factory
|
|
24
|
+
|
|
25
|
+
# 国内镜像(npmmirror 会同步公共 npm 包)
|
|
26
|
+
npm install -g h3factory --registry https://registry.npmmirror.com
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
任何支持技能目录的 Agent 装完即用,无需额外配置。
|
|
30
|
+
|
|
31
|
+
### 从 GitHub 私有仓库安装(内部/源码)
|
|
32
|
+
|
|
33
|
+
私有仓库**不要**用 `github:账号/仓库` 简写——npm 会匿名请求 codeload,私有仓会返回 404。用完整 git 地址:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# SSH(需本机已配置 GitHub SSH key)
|
|
37
|
+
npm install -g git+ssh://git@github.com/xiangduo10146814/h3factory.git
|
|
38
|
+
|
|
39
|
+
# 若 22 端口不通,改用 SSH 443(GitHub 官方支持)
|
|
40
|
+
git config --global url."ssh://git@ssh.github.com:443/".insteadOf "ssh://git@github.com/"
|
|
41
|
+
npm install -g git+ssh://git@github.com/xiangduo10146814/h3factory.git
|
|
42
|
+
|
|
43
|
+
# HTTPS + PAT(token 会留在 shell 历史,注意保密)
|
|
44
|
+
npm install -g git+https://<TOKEN>@github.com/xiangduo10146814/h3factory.git
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 从本地 tarball 安装
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm pack # 生成 h3factory-0.2.0.tgz
|
|
51
|
+
npm install -g ./h3factory-0.2.0.tgz
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
安装时 `postinstall` 会把 `skills/h3factory` 和 `skills/h3yun-dev-assistant` 复制到
|
|
55
|
+
Claude Code / Codex / Cursor / OpenCode / QwenWork / Qoder / QoderWork / Mulerun
|
|
56
|
+
的用户技能目录(不存在会创建)。技能更新由安装包管理,会覆盖本地修改。
|
|
57
|
+
|
|
58
|
+
## 快速开始
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
mkdir D:\h3work && cd /d D:\h3work # 任意工作区目录,别用 System32
|
|
62
|
+
|
|
63
|
+
h3factory auth status --json # Agent 第一步:检查凭据,ok=false 就先录 token
|
|
64
|
+
h3factory init # 人类交互式录入(或由 Agent 用 auth set --json 写入)
|
|
65
|
+
h3factory doctor # 检查 Python / 配置 / JWT 是否过期 / 技能
|
|
66
|
+
h3factory demo # 复制内置示例项目到 ./projects/demo
|
|
67
|
+
h3factory check demo # 离线校验,不联网
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
凭据字段:`baseUrl`、`engineCode`、`engineSecret`、`authorization`(Bearer JWT,**会过期**)、`appCode`。
|
|
71
|
+
Agent 写凭据用 stdin,避免出现在命令行参数里:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
h3factory auth set --json <<'JSON'
|
|
75
|
+
{"authorization": "<JWT>"}
|
|
76
|
+
JSON
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`authorization` 过期后去氚云后台重新生成粘回,再跑 `h3factory auth status` 确认。
|
|
80
|
+
|
|
81
|
+
## 工作区模型
|
|
82
|
+
|
|
83
|
+
命令在**当前目录**执行,当前目录就是工作区:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
<工作区>/
|
|
87
|
+
├─ config.json # 凭据(勿提交/分享)
|
|
88
|
+
└─ projects/<项目名>/
|
|
89
|
+
├─ config.json # 可选,覆盖工作区凭据
|
|
90
|
+
├─ dicts.json # 枚举字典
|
|
91
|
+
├─ groups.json # 可选,表单分组与顺序
|
|
92
|
+
├─ sheets/*.json # 每张表单一个定义文件
|
|
93
|
+
├─ registry.json # 平台编码注册表,勿手改
|
|
94
|
+
├─ logs/ # verify/group 报告
|
|
95
|
+
└─ generated/ # .cs 代码骨架
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
配置查找顺序:`H3FACTORY_CONFIG` → `./config.json` → `~/.h3factory/config.json`。
|
|
99
|
+
工作区也可用环境变量指定:`H3FACTORY_HOME=D:\h3work h3factory check demo`。
|
|
100
|
+
|
|
101
|
+
## 命令
|
|
102
|
+
|
|
103
|
+
| 命令 | 作用 | 联网 |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `h3factory auth status [--json]` | **凭据门禁**:检查配置与 JWT 是否可用 | 否 |
|
|
106
|
+
| `h3factory auth set --json` | 从 stdin 读 JSON 写入凭据(值不回显) | 否 |
|
|
107
|
+
| `h3factory auth set-token` | 从 stdin 读 token 写入 | 否 |
|
|
108
|
+
| `h3factory init [--no-input]` | 交互生成工作区 config.json | 否 |
|
|
109
|
+
| `h3factory demo` | 复制内置示例项目 | 否 |
|
|
110
|
+
| `h3factory doctor` | 检查运行时、配置、JWT、技能 | 否 |
|
|
111
|
+
| `h3factory check <项目> [表..]` | 本地加载并校验表单定义 | 否 |
|
|
112
|
+
| `h3factory list <项目>` | registry 各表编码与状态 | 否 |
|
|
113
|
+
| `h3factory build <项目> [表..] [--force]` | 建表;已存在且结构一致则跳过 | 是 |
|
|
114
|
+
| `h3factory verify <项目> [表..]` | LoadForm 只读回读比对 | 是 |
|
|
115
|
+
| `h3factory group <项目> [表..]` | 建分组并归位(幂等) | 是 |
|
|
116
|
+
| `h3factory import <项目> <表> <data.json> [--submit]` | 批量导数据 | 是 |
|
|
117
|
+
| `h3factory gen <项目> <表>` | 生成 .cs 提交时代码骨架 | 否 |
|
|
118
|
+
| `h3factory docs [名称]` | 列出/打印内置文档 | 否 |
|
|
119
|
+
| `h3factory skill install [--tool all\|auto\|<工具>] [--scope user\|project]` | 安装/更新技能 | 否 |
|
|
120
|
+
| `h3factory skill list` | 查看各工具已安装位置 | 否 |
|
|
121
|
+
| `h3factory --version` | 版本 | 否 |
|
|
122
|
+
|
|
123
|
+
源码目录内仍可用旧方式:`python -X utf8 cli.py <命令>`(Windows GBK 控制台必须带 `-X utf8`)。
|
|
124
|
+
|
|
125
|
+
## 与各种 Agent 配合
|
|
126
|
+
|
|
127
|
+
npm 安装后会把技能自动复制到以下用户级技能目录(目录不存在也会创建):
|
|
128
|
+
|
|
129
|
+
| Agent | 技能目录 |
|
|
130
|
+
|---|---|
|
|
131
|
+
| Claude Code | `~/.claude/skills/` |
|
|
132
|
+
| Codex | `~/.codex/skills/` |
|
|
133
|
+
| Cursor | `~/.cursor/skills/` |
|
|
134
|
+
| OpenCode | `~/.opencode/skills/` |
|
|
135
|
+
| QwenWork | `~/.qwenworkcn/skills/` |
|
|
136
|
+
| Qoder / QoderWork | `~/.qoder/skills/`、`~/.qoderwork/skills/` |
|
|
137
|
+
| Mulerun | `~/.mulerun/skills/` |
|
|
138
|
+
|
|
139
|
+
随包安装两个技能:
|
|
140
|
+
|
|
141
|
+
- `h3factory` —— 工厂总入口:凭据门禁、澄清需求、产出 sheets JSON、调用 CLI、交付清单。
|
|
142
|
+
- `h3yun-dev-assistant` —— 氚云二开规范:C# 后端、ES5 前端、SQL、控件编码、平台限制。
|
|
143
|
+
|
|
144
|
+
### Agent 会话第一步:录入 token
|
|
145
|
+
|
|
146
|
+
技能里已写成硬门禁。Agent 每次会话先执行:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
h3factory auth status --json # 看 ok / missing / jwt_expired
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
`ok=false` 时向客户要 token,并通过 stdin 写入(不放进命令行参数、不回显):
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
h3factory auth set --json <<'JSON'
|
|
156
|
+
{"authorization": "<客户提供的 JWT>"}
|
|
157
|
+
JSON
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
再次运行 `h3factory auth status --json`,`ok=true` 后才允许 `build/verify/group/import`。
|
|
161
|
+
CLI 自身也会在 `build/verify/group/import` 启动时做同样的检查,token 缺失或过期会直接拒绝执行。
|
|
162
|
+
|
|
163
|
+
**首选方式**:让客户在自己的终端运行 `h3factory auth set-token`(输入隐藏,token 不进入对话记录);
|
|
164
|
+
还缺其他字段就运行 `h3factory init`。只有客户主动在对话里贴 token 时,才用上面的 `auth set --json`。
|
|
165
|
+
|
|
166
|
+
新需求直接对 Agent 说:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
用 h3factory 帮我做这个需求:<需求文档/链接/文本>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
技能会按 `docs/requirement_checklist.md` 澄清,产出 `projects/<新项目>/` 设计并停下来等你过目;确认后才建表。
|
|
173
|
+
|
|
174
|
+
## 关键规则(血泪教训,详见 docs/platform_gotchas.md)
|
|
175
|
+
|
|
176
|
+
- **verify 只读、可重复跑**;`build --force` 才整表重存 —— 重存 = 整体替换,会抹掉界面上手工配的必填/联动,慎用。
|
|
177
|
+
- 界面手工活(必填、审批流、字段联动、只读)API 配不了,每次交付附「界面配置清单」。
|
|
178
|
+
- 表单下拉存储「名称」,代码位另用字典表转换 —— 设计时就想清「存名称还是代码」。
|
|
179
|
+
- 代码类、schema code 注册在 `projects/<名>/registry.json`,删了会发新编码、断关联。
|
|
180
|
+
- `config.json` 含凭据:不提交、不分享、不让 AI 打印。
|
|
181
|
+
|
|
182
|
+
## 源码结构
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
h3factory/
|
|
186
|
+
├─ bin/h3factory.js # npm 入口:探测 Python 3.10+ 并转调 cli.py
|
|
187
|
+
├─ cli.py # init/demo/doctor/check/list/build/verify/group/import/gen
|
|
188
|
+
├─ h3platform/ # 连接层:Console SaveForm/LoadForm + OpenAPI + 配置解析
|
|
189
|
+
├─ h3design/ # 设计层:控件工厂 / SaveForm 载荷 / JSON DSL
|
|
190
|
+
├─ h3verify/verify.py # LoadForm 只读回读比对
|
|
191
|
+
├─ skills/ # 随包安装到各 Agent 的技能
|
|
192
|
+
├─ templates/controller.cs.tpl
|
|
193
|
+
├─ docs/ # workflow / schema_doc / requirement_checklist / platform_gotchas
|
|
194
|
+
├─ scripts/postinstall.js # 技能安装
|
|
195
|
+
└─ projects/demo/ # 内置示例(打包时带上)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 开发与发布
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npm pack --dry-run # 检查包内容:不得出现 config.json / 业务 projects / logs
|
|
202
|
+
npm pack # 生成 tarball
|
|
203
|
+
npm install -g ./h3factory-0.2.0.tgz
|
|
204
|
+
h3factory check demo # 冒烟
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
发布到公共 npm(维护者):
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
npm login --registry https://registry.npmjs.org
|
|
211
|
+
npm publish # package.json 的 publishConfig 已指向 npmjs
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
代码仓库(私有):<https://github.com/xiangduo10146814/h3factory>
|
|
215
|
+
|
|
216
|
+
日常更新:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
git add .
|
|
220
|
+
git commit -m "feat: ..."
|
|
221
|
+
git push origin main # 本机 github.com:443 不通时,用 gh api / 代理推送
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
> 仓库默认不跟踪业务项目(`projects/*` 已忽略,仅保留 `projects/demo`),凭据文件也不会入库。
|
package/bin/h3factory.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* h3factory npm 入口:定位 Python 3.10+,以 UTF-8 模式转调 cli.py。
|
|
6
|
+
* 业务代码全部在 Python 内核里,这里只负责运行时探测和参数透传。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const { spawnSync, spawn } = require('child_process');
|
|
12
|
+
|
|
13
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '..');
|
|
14
|
+
const CLI_PATH = path.join(PACKAGE_ROOT, 'cli.py');
|
|
15
|
+
const rawArgs = process.argv.slice(2);
|
|
16
|
+
|
|
17
|
+
function fail(message) {
|
|
18
|
+
console.error('[h3factory] ' + message);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (rawArgs[0] === '--version' || rawArgs[0] === '-v' || rawArgs[0] === '-V') {
|
|
23
|
+
console.log(require(path.join(PACKAGE_ROOT, 'package.json')).version);
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!fs.existsSync(CLI_PATH)) {
|
|
28
|
+
fail('安装不完整:找不到 ' + CLI_PATH + ',请重新安装。');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function works(cmd, baseArgs) {
|
|
32
|
+
const probe = spawnSync(
|
|
33
|
+
cmd,
|
|
34
|
+
baseArgs.concat([
|
|
35
|
+
'-c',
|
|
36
|
+
'import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 3)',
|
|
37
|
+
]),
|
|
38
|
+
{ stdio: 'ignore', timeout: 8000, windowsHide: true }
|
|
39
|
+
);
|
|
40
|
+
return probe.status === 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const candidates = [];
|
|
44
|
+
if (process.env.H3FACTORY_PYTHON) {
|
|
45
|
+
candidates.push({ cmd: process.env.H3FACTORY_PYTHON, args: [] });
|
|
46
|
+
}
|
|
47
|
+
if (process.platform === 'win32') {
|
|
48
|
+
candidates.push({ cmd: 'py', args: ['-3'] });
|
|
49
|
+
candidates.push({ cmd: 'python', args: [] });
|
|
50
|
+
candidates.push({ cmd: 'python3', args: [] });
|
|
51
|
+
} else {
|
|
52
|
+
candidates.push({ cmd: 'python3', args: [] });
|
|
53
|
+
candidates.push({ cmd: 'python', args: [] });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let runtime = null;
|
|
57
|
+
for (const candidate of candidates) {
|
|
58
|
+
if (works(candidate.cmd, candidate.args)) {
|
|
59
|
+
runtime = candidate;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!runtime) {
|
|
65
|
+
fail(
|
|
66
|
+
'未找到 Python 3.10+。请安装 Python 并加入 PATH,' +
|
|
67
|
+
'或设置 H3FACTORY_PYTHON 指向解释器路径。'
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const args = runtime.args.concat(['-X', 'utf8', CLI_PATH], rawArgs);
|
|
72
|
+
const child = spawn(runtime.cmd, args, {
|
|
73
|
+
stdio: 'inherit',
|
|
74
|
+
windowsHide: false,
|
|
75
|
+
env: Object.assign({}, process.env, {
|
|
76
|
+
PYTHONUTF8: '1',
|
|
77
|
+
PYTHONIOENCODING: 'utf-8',
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
child.on('error', (err) => fail('启动 Python 失败: ' + err.message));
|
|
82
|
+
child.on('exit', (code, signal) => {
|
|
83
|
+
if (signal) {
|
|
84
|
+
process.exit(130);
|
|
85
|
+
}
|
|
86
|
+
process.exit(code === null ? 1 : code);
|
|
87
|
+
});
|