@h-ai/cli 0.1.0-alpha.12 → 0.1.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: hai-crypto
3
- description: 使用 @h-ai/crypto 进行加密(非对称/哈希/对称)与密码哈希;当需求涉及加密、解密、签名、验签、哈希、密码存储或密钥管理时使用。
3
+ description: 使用 @h-ai/crypto 进行加密(非对称/哈希/对称)、密码哈希与传输加密;当需求涉及加密、解密、签名、验签、哈希、密码存储、密钥管理或 crypto.transport 时使用。
4
4
  ---
5
5
 
6
6
  # hai-crypto
@@ -19,6 +19,7 @@ description: 使用 @h-ai/crypto 进行加密(非对称/哈希/对称)与密
19
19
  | `crypto.hash` 哈希 | ✅ | ✅ | SM3 哈希、HMAC |
20
20
  | `crypto.symmetric` 对称加密 | ✅ | ✅ | SM4 ECB/CBC |
21
21
  | `crypto.password` 密码哈希 | ✅ | ❌ | 依赖 Node.js crypto(服务端专用) |
22
+ | `crypto.transport` 传输加密 | ✅ | ✅ | 服务端管理器 + 客户端 encryptedFetch |
22
23
 
23
24
  浏览器端主要用于 kit 传输加密场景(`kit.client.create({ transport: { crypto } })`),一般不需要直接调用 crypto API。
24
25
 
@@ -30,6 +31,7 @@ description: 使用 @h-ai/crypto 进行加密(非对称/哈希/对称)与密
30
31
  - 哈希计算与 HMAC
31
32
  - 对称加密/解密(ECB/CBC 模式)
32
33
  - 密码存储与验证(加盐迭代哈希)
34
+ - 传输加密:为 serv / kit / api-client 提供统一协议、密钥协商和请求响应加解密
33
35
 
34
36
  ---
35
37
 
@@ -139,6 +141,44 @@ if (hashed.success) {
139
141
  哈希格式:`$hai$<iterations>$<salt>$<hash>`
140
142
  **PasswordConfig**:`{ saltLength?: number, iterations?: number }`
141
143
 
144
+ ### 传输加密 — `crypto.transport`
145
+
146
+ 所有传输加密工厂必须从 `crypto.transport` 访问,不从子目录导入内部工厂。
147
+
148
+ | 方法 | 签名 | 说明 |
149
+ | --- | --- | --- |
150
+ | `createServer` | `(options?) => HaiResult<TransportEncryptionManager>` | 创建服务端传输加密管理器 |
151
+ | `createClient` | `({ keyExchangeUrl, fetch? }) => TransportClient` | 创建客户端 encryptedFetch 会话 |
152
+ | `protocol` | `TRANSPORT_PROTOCOL` | 协议常量:`X-Client-Id`、`X-Encrypted`、默认协商路径 |
153
+
154
+ ```typescript
155
+ const server = crypto.transport.createServer({ maxClients: 10000 })
156
+ if (!server.success)
157
+ return server
158
+
159
+ const client = crypto.transport.createClient({
160
+ keyExchangeUrl: 'https://api.example.com/api/v1/_hai/key-exchange',
161
+ })
162
+
163
+ const resp = await client.encryptedFetch('https://api.example.com/api/v1/echo', {
164
+ method: 'POST',
165
+ body: JSON.stringify({ hello: 'world' }),
166
+ })
167
+ ```
168
+
169
+ 使用流程:
170
+ 1. 先 `await crypto.init()`。
171
+ 2. 服务端 `createServer()` 后暴露一个 POST 密钥协商端点:接收 `clientPublicKey`,返回 `serverPublicKey + clientId`。
172
+ 3. 客户端 `createClient({ keyExchangeUrl })` 后,首次 `init()` / `encryptedFetch()` 会自动做密钥协商。
173
+ 4. 协商完成后,请求附带 `X-Client-Id`;若请求有 body,则自动包装成 `{ encryptedKey, ciphertext, iv }`。
174
+ 5. 服务端先 `decryptRequest()`,业务处理后再 `encryptResponse(clientId, data)`。
175
+ 6. 客户端收到 `X-Encrypted: true` 的响应后自动解密;`destroy()` 可清空当前会话。
176
+
177
+ 常规应用优先使用上层封装:
178
+ - serv:`serv.createApp({ transport: { crypto } })`
179
+ - kit:`kit.createHandle({ crypto: { crypto, transport: true } })` + `kit.client.create({ transport: { crypto } })`
180
+ - api-client:`apiClient.init({ transport: { crypto } })`
181
+
142
182
  ---
143
183
 
144
184
  ## 错误码 — `HaiCryptoError`
@@ -196,3 +236,4 @@ if (verifyResult.success && verifyResult.data) {
196
236
  - `hai-core`:配置与 HaiResult 模型
197
237
  - `hai-iam`:密码哈希(内部自动调用 crypto.password)
198
238
  - `hai-kit`:SvelteKit 集成(传输加密)
239
+ - `hai-serv` / `hai-api-client`:跨域 HTTP API 的透明传输加密
@@ -0,0 +1,98 @@
1
+ ---
2
+ name: hai-framework-sync
3
+ description: 管理 hai-framework 与应用仓库之间的依赖、技能模板、Copilot/AGENTS 指令和本地联调同步;当需求涉及 hai-framework 源头修改、skills 同步、framework:use:local、framework:watch、版本漂移或双仓 PR 时使用。
4
+ ---
5
+
6
+ # hai-framework-sync — hai-framework 与应用仓库同步规范
7
+
8
+ > hai-framework 是能力与 skill 模板源头;应用仓库消费这些能力,并可以有少量项目本地覆盖。同步的目标是减少漂移,而不是把两个仓库混成一个仓库。
9
+
10
+ ---
11
+
12
+ ## 适用场景
13
+
14
+ - 修改 `.agents/skills/**`,且内容应成为所有 hai-framework 应用通用规范
15
+ - 修改 `packages/cli/templates/skills/**`
16
+ - 调整 `AGENTS.md`、`CLAUDE.md`、`opencode.json`、Copilot 指令模板
17
+ - 使用 `framework:use:local` / `framework:watch` 联调本地 hai-framework
18
+ - 排查应用仓库与 hai-framework npm 版本不一致
19
+ - 规划双仓 PR 或同步发布
20
+
21
+ ---
22
+
23
+ ## 同步原则
24
+
25
+ 1. **通用规范先改 hai-framework**:可复用的 skill、模板、AI 工作流从 `packages/cli/templates/skills/` 起源。
26
+ 2. **应用仓库只保留项目差异**:业务上下文、项目私有路径、产品决策可以留在应用仓库。
27
+ 3. **默认 CI 使用 npm 依赖**:确保 PR 能代表真实安装环境;本地路径联调必须显式开启。
28
+ 4. **双仓改动要成套**:framework 模板、应用本地 `.agents/skills`、AGENTS/Copilot 路由同时更新。
29
+ 5. **不复制敏感聊天记录**:只同步脱敏后的团队规则和流程。
30
+
31
+ ---
32
+
33
+ ## 标准同步流程
34
+
35
+ ### 1. 判断来源
36
+
37
+ | 变更类型 | 首选位置 |
38
+ | --- | --- |
39
+ | 通用 hai 模块用法 | `hai-framework/packages/cli/templates/skills/hai-*/SKILL.md` |
40
+ | 通用 CI/PR/Issue/AI 协作流程 | `hai-framework/packages/cli/templates/skills/` |
41
+ | 应用私有业务规则 | 应用仓库 `AGENTS.md` 或本地 skill |
42
+ | Copilot/Claude/OpenCode 入口模板 | hai-framework 模板 + 应用仓库入口文件 |
43
+
44
+ ### 2. 修改源头
45
+
46
+ 先在 hai-framework 模板中修改或新增 skill。
47
+
48
+ ### 3. 同步到应用仓库
49
+
50
+ 把源头 skill 复制到应用仓库 `.agents/skills/<skill>/SKILL.md`,并同步入口引用:
51
+
52
+ - `AGENTS.md`
53
+ - `.github/copilot-instructions.md`
54
+ - `CLAUDE.md`(如存在)
55
+ - `opencode.json`(如结构变化)
56
+
57
+ ### 4. 验证
58
+
59
+ 按变更类型选择验证方式:
60
+
61
+ - 仅模板 / skill 变更:检查 diff、入口引用与模板泛化程度。
62
+ - 同步到应用仓库:按 `hai-ci` 定义的质量门禁运行。
63
+ - 涉及 framework runtime 时,再选择:
64
+
65
+ ```bash
66
+ pnpm framework:status
67
+ pnpm framework:use:local <package>
68
+ pnpm framework:watch <package>
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 漂移检查清单
74
+
75
+ - [ ] framework 模板和应用 `.agents/skills` 对同名 skill 内容一致,除非 PR 明确说明本地覆盖
76
+ - [ ] `AGENTS.md` 的 skill 列表包含新增/重命名 skill
77
+ - [ ] Copilot/Claude/OpenCode 入口能找到新增 skill
78
+ - [ ] CI 默认不依赖 `/home/.../hai-framework` 本地路径
79
+ - [ ] 本地联调结束后可恢复 npm 模式
80
+ - [ ] README 或 PR 描述说明双仓改动顺序
81
+
82
+ ---
83
+
84
+ ## 禁止事项
85
+
86
+ - ❌ 只改应用 `.agents/skills`,忘记更新 hai-framework 模板中的通用规范
87
+ - ❌ 在 CI 默认路径中依赖本机绝对路径
88
+ - ❌ 把 unpublished framework 行为当成已发布 npm 行为
89
+ - ❌ 把聊天记录原文、token、私有 URL 写入模板
90
+ - ❌ 双仓 PR 没有关联 issue 或同步说明
91
+
92
+ ---
93
+
94
+ ## 相关 Skills
95
+
96
+ - `hai-ci` — CI 对 npm/local framework 模式的验证策略
97
+ - `hai-pr-review` — 双仓 PR 审查要点
98
+ - `hai-build` — 应用开发入口
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: hai-iam
3
- description: 使用 @h-ai/iam 进行身份认证(密码/OTP/LDAP/API Key)、统一 Bearer Token 管理(TokenPair/refresh/revoke)与 RBAC 授权(角色/权限/通配符);当需求涉及登录、注册、权限检查、角色管理、Token 认证或 API 契约时使用。
3
+ description: 使用 @h-ai/iam 进行身份认证(密码/OTP/LDAP/API Key)、统一 Bearer Token 管理(TokenPair/refresh/revoke)与 RBAC 授权;当需求涉及登录、注册、权限检查、角色管理、Token 认证或通过 @h-ai/api-contract 暴露 IAM API 时使用。
4
4
  ---
5
5
 
6
6
  # hai-iam
@@ -11,7 +11,7 @@ description: 使用 @h-ai/iam 进行身份认证(密码/OTP/LDAP/API Key)、
11
11
 
12
12
  ## 运行环境
13
13
 
14
- > ⚠️ **服务端模块(Node.js only)。** 浏览器端通过 `api.call(iamEndpoints.xxx)` 或 `apiFetch` 调用 IAM API 端点(参见 hai-api-client / hai-kit SKILL)。`@h-ai/iam/api` 子路径导出的 Zod Schema 和 EndpointDef 可在浏览器端使用。
14
+ > ⚠️ **服务端模块(Node.js only)。** 浏览器端通过 `@h-ai/api-client` 的 typed client 调用 IAM API,例如 `apiClient.iam.auth.login()`。HTTP 契约统一来自 `@h-ai/api-contract`。
15
15
 
16
16
  ---
17
17
 
@@ -33,7 +33,7 @@ description: 使用 @h-ai/iam 进行身份认证(密码/OTP/LDAP/API Key)、
33
33
  - API Key 管理(创建、吊销、验证)
34
34
  - 密码重置流程
35
35
  - 与 kit 集成的认证守卫
36
- - API 契约定义(`@h-ai/iam/api`)
36
+ - 通过 `@h-ai/api-contract` 暴露 IAM HTTP contract
37
37
 
38
38
  ---
39
39
 
@@ -204,34 +204,14 @@ interface TokenPair {
204
204
 
205
205
  ---
206
206
 
207
- ## API 契约 — `@h-ai/iam/api`
207
+ ## HTTP API 契约
208
208
 
209
- ```typescript
210
- import { iamEndpoints } from '@h-ai/iam/api'
211
-
212
- // 9 个端点契约,含 Zod schema
213
- iamEndpoints.login // POST /api/v1/auth/login
214
- iamEndpoints.loginWithOtp // POST /api/v1/auth/login-otp
215
- iamEndpoints.sendOtp // POST /api/v1/auth/send-otp
216
- iamEndpoints.logout // POST /api/v1/auth/logout
217
- iamEndpoints.register // POST /api/v1/auth/register
218
- iamEndpoints.currentUser // GET /api/v1/auth/me
219
- iamEndpoints.refreshToken // POST /api/v1/auth/refresh
220
- iamEndpoints.changePassword // POST /api/v1/auth/change-password
221
- iamEndpoints.resetPassword // POST /api/v1/auth/reset-password
222
- ```
223
-
224
- 服务端使用 `kit.fromContract()`,客户端使用 `api.call()`:
209
+ IAM HTTP API 统一由 `@h-ai/api-contract` 的 `apiContract.iam` 定义,由 `@h-ai/serv/features/iam` 绑定到本模块。
225
210
 
226
211
  ```typescript
227
- // 服务端
228
- export const POST = kit.fromContract(iamEndpoints.login, async (input) => {
229
- const result = await iam.auth.login(input)
230
- return result.success ? kit.response.ok(result.data) : kit.response.unauthorized()
231
- })
212
+ import { apiClient } from '@h-ai/api-client'
232
213
 
233
- // 客户端
234
- const result = await api.call(iamEndpoints.login, { username, password })
214
+ const result = await apiClient.iam.auth.login({ identifier: username, password })
235
215
  ```
236
216
 
237
217
  ---
@@ -322,23 +302,21 @@ export const handle = kit.sequence(haiHandle)
322
302
  ### 客户端认证流程
323
303
 
324
304
  ```typescript
325
- import { iamEndpoints } from '@h-ai/iam/api'
326
-
327
305
  // 登录 → 保存 Token
328
- const login = await api.call(iamEndpoints.login, { username, password })
306
+ const login = await apiClient.iam.auth.login({ identifier: username, password })
329
307
  if (login.success) {
330
- await api.auth.setTokens(login.data.tokens)
308
+ await apiClient.auth.setTokens(login.data.tokens)
331
309
  }
332
310
 
333
311
  // 获取当前用户
334
- const me = await api.call(iamEndpoints.currentUser, {})
312
+ const me = await apiClient.iam.auth.currentUser()
335
313
 
336
- // Token 过期时,api-client 自动调用 refreshUrl 刷新
314
+ // Token 过期时,api-client 自动调用 refreshPath 刷新
337
315
  // 刷新失败时,清除 Token 并跳转登录页
338
316
 
339
317
  // 登出
340
- await api.call(iamEndpoints.logout, {})
341
- await api.auth.clear()
318
+ await apiClient.iam.auth.logout({})
319
+ await apiClient.auth.clear()
342
320
  ```
343
321
 
344
322
  ### 自动会话失效