@h-ai/cli 0.1.0-alpha5

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 (109) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +167 -0
  3. package/dist/chunk-2H7UOFLK.js +10 -0
  4. package/dist/chunk-2H7UOFLK.js.map +1 -0
  5. package/dist/chunk-LANIDJC7.js +659 -0
  6. package/dist/chunk-LANIDJC7.js.map +1 -0
  7. package/dist/chunk-YV7WPUI6.js +206 -0
  8. package/dist/chunk-YV7WPUI6.js.map +1 -0
  9. package/dist/config-templates-S5RI2MC6.js +5 -0
  10. package/dist/config-templates-S5RI2MC6.js.map +1 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +1645 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/skill-templates-N5DU5FNX.js +5 -0
  15. package/dist/skill-templates-N5DU5FNX.js.map +1 -0
  16. package/dist/src-XJ6YXNAF.js +15030 -0
  17. package/dist/src-XJ6YXNAF.js.map +1 -0
  18. package/package.json +59 -0
  19. package/templates/README.md +126 -0
  20. package/templates/apps/admin/messages/en-US.json +33 -0
  21. package/templates/apps/admin/messages/zh-CN.json +33 -0
  22. package/templates/apps/admin/src/routes/+layout.svelte.hbs +30 -0
  23. package/templates/apps/admin/src/routes/+page.svelte.hbs +35 -0
  24. package/templates/apps/admin/src/routes/admin/+layout.svelte.hbs +44 -0
  25. package/templates/apps/admin/src/routes/admin/+page.svelte.hbs +45 -0
  26. package/templates/apps/admin/src/routes/admin/settings/+page.svelte.hbs +37 -0
  27. package/templates/apps/admin/src/routes/api/health/+server.ts +12 -0
  28. package/templates/apps/android-app/.env.hbs +3 -0
  29. package/templates/apps/android-app/capacitor.config.ts.hbs +12 -0
  30. package/templates/apps/android-app/messages/en-US.json +24 -0
  31. package/templates/apps/android-app/messages/zh-CN.json +24 -0
  32. package/templates/apps/android-app/src/lib/api.ts.hbs +30 -0
  33. package/templates/apps/android-app/src/lib/capacitor.ts +21 -0
  34. package/templates/apps/android-app/src/routes/+layout.svelte.hbs +42 -0
  35. package/templates/apps/android-app/src/routes/+layout.ts +7 -0
  36. package/templates/apps/android-app/src/routes/+page.svelte.hbs +27 -0
  37. package/templates/apps/api/src/routes/+layout.svelte +14 -0
  38. package/templates/apps/api/src/routes/+page.svelte +11 -0
  39. package/templates/apps/api/src/routes/api/v1/health/+server.ts +14 -0
  40. package/templates/apps/api/src/routes/api/v1/items/+server.ts +37 -0
  41. package/templates/apps/api/src/routes/api/v1/items/[id]/+server.ts +30 -0
  42. package/templates/apps/h5/messages/en-US.json +37 -0
  43. package/templates/apps/h5/messages/zh-CN.json +37 -0
  44. package/templates/apps/h5/src/routes/+layout.svelte.hbs +57 -0
  45. package/templates/apps/h5/src/routes/+page.svelte.hbs +27 -0
  46. package/templates/apps/h5/src/routes/discover/+page.svelte.hbs +27 -0
  47. package/templates/apps/h5/src/routes/profile/+page.svelte.hbs +27 -0
  48. package/templates/apps/website/messages/en-US.json +32 -0
  49. package/templates/apps/website/messages/zh-CN.json +32 -0
  50. package/templates/apps/website/src/routes/+layout.svelte.hbs +66 -0
  51. package/templates/apps/website/src/routes/+page.svelte.hbs +33 -0
  52. package/templates/apps/website/src/routes/about/+page.svelte.hbs +27 -0
  53. package/templates/apps/website/src/routes/api/health/+server.ts +12 -0
  54. package/templates/apps/website/src/routes/contact/+page.svelte.hbs +59 -0
  55. package/templates/apps/website/src/routes/services/+page.svelte.hbs +63 -0
  56. package/templates/base/e2e/helpers.ts +49 -0
  57. package/templates/base/package.json.hbs +67 -0
  58. package/templates/base/playwright.config.ts +32 -0
  59. package/templates/base/src/app.css +2 -0
  60. package/templates/base/src/app.d.ts.hbs +18 -0
  61. package/templates/base/src/app.html.hbs +16 -0
  62. package/templates/base/src/hooks.server.ts.hbs +123 -0
  63. package/templates/base/src/lib/server/init.ts.hbs +190 -0
  64. package/templates/base/svelte.config.js.hbs +30 -0
  65. package/templates/base/tsconfig.json +8 -0
  66. package/templates/base/vite.config.ts.hbs +27 -0
  67. package/templates/features/ai/routes/api/chat/+server.ts +26 -0
  68. package/templates/features/datapipe/routes/api/datapipe/pipeline/+server.ts +41 -0
  69. package/templates/features/iam/routes-admin/(auth)/+layout.svelte.hbs +21 -0
  70. package/templates/features/iam/routes-admin/(auth)/auth/login/+page.svelte.hbs +98 -0
  71. package/templates/features/iam/routes-admin/(auth)/auth/register/+page.svelte.hbs +124 -0
  72. package/templates/features/iam/routes-h5/auth/login/+page.svelte.hbs +98 -0
  73. package/templates/features/iam/routes-h5/auth/register/+page.svelte.hbs +114 -0
  74. package/templates/features/iam/routes-shared/api/auth/login/+server.ts +32 -0
  75. package/templates/features/iam/routes-shared/api/auth/logout/+server.ts +15 -0
  76. package/templates/features/iam/routes-shared/api/auth/me/+server.ts +12 -0
  77. package/templates/features/iam/routes-shared/api/auth/register/+server.ts +26 -0
  78. package/templates/features/payment/routes/api/v1/payment/create/+server.ts +30 -0
  79. package/templates/features/payment/routes/api/v1/payment/notify/[provider]/+server.ts +42 -0
  80. package/templates/features/payment/routes/api/v1/payment/query/[orderNo]/+server.ts +25 -0
  81. package/templates/features/storage/routes/api/upload/+server.ts +35 -0
  82. package/templates/features/vecdb/routes/api/vecdb/search/+server.ts +36 -0
  83. package/templates/i18n/project.inlang/settings.json +11 -0
  84. package/templates/skills/AGENTS.md +26 -0
  85. package/templates/skills/CLAUDE.md +12 -0
  86. package/templates/skills/copilot-instructions.md +61 -0
  87. package/templates/skills/hai-ai/SKILL.md +659 -0
  88. package/templates/skills/hai-api-client/SKILL.md +346 -0
  89. package/templates/skills/hai-app-create/SKILL.md +371 -0
  90. package/templates/skills/hai-app-review/SKILL.md +156 -0
  91. package/templates/skills/hai-app-tests/SKILL.md +468 -0
  92. package/templates/skills/hai-audit/SKILL.md +141 -0
  93. package/templates/skills/hai-build/SKILL.md +319 -0
  94. package/templates/skills/hai-cache/SKILL.md +184 -0
  95. package/templates/skills/hai-capacitor/SKILL.md +389 -0
  96. package/templates/skills/hai-core/SKILL.md +544 -0
  97. package/templates/skills/hai-crypto/SKILL.md +183 -0
  98. package/templates/skills/hai-datapipe/SKILL.md +214 -0
  99. package/templates/skills/hai-deploy/SKILL.md +210 -0
  100. package/templates/skills/hai-iam/SKILL.md +355 -0
  101. package/templates/skills/hai-kit/SKILL.md +319 -0
  102. package/templates/skills/hai-payment/SKILL.md +289 -0
  103. package/templates/skills/hai-reach/SKILL.md +325 -0
  104. package/templates/skills/hai-reldb/SKILL.md +459 -0
  105. package/templates/skills/hai-scheduler/SKILL.md +242 -0
  106. package/templates/skills/hai-storage/SKILL.md +230 -0
  107. package/templates/skills/hai-ui/SKILL.md +275 -0
  108. package/templates/skills/hai-vecdb/SKILL.md +273 -0
  109. package/templates/skills/opencode.json +11 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * VecDB Search API — vecdb 功能示例
3
+ */
4
+ import type { RequestEvent } from '@sveltejs/kit'
5
+ import { kit } from '@h-ai/kit'
6
+ import { vecdb } from '@h-ai/vecdb'
7
+
8
+ const DEMO_COLLECTION = 'documents'
9
+
10
+ export async function POST({ request, locals }: RequestEvent) {
11
+ const body = await request.json().catch(() => null) as { vector?: number[] } | null
12
+ const vector = body?.vector
13
+
14
+ if (!Array.isArray(vector) || vector.length === 0) {
15
+ return kit.response.badRequest('vector is required')
16
+ }
17
+
18
+ const collectionExists = await vecdb.collection.exists(DEMO_COLLECTION)
19
+ if (!collectionExists.success) {
20
+ return kit.response.internalError(collectionExists.error.message)
21
+ }
22
+
23
+ if (!collectionExists.data) {
24
+ return kit.response.badRequest('vecdb demo collection not initialized')
25
+ }
26
+
27
+ const result = await vecdb.vector.search(DEMO_COLLECTION, vector, { topK: 5 })
28
+ if (!result.success) {
29
+ return kit.response.internalError(result.error.message)
30
+ }
31
+
32
+ return kit.response.ok({
33
+ topK: 5,
34
+ results: result.data,
35
+ }, locals.requestId)
36
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://inlang.com/schema/project-settings",
3
+ "baseLocale": "zh-CN",
4
+ "locales": ["zh-CN", "en-US"],
5
+ "modules": [
6
+ "../../node_modules/@inlang/plugin-message-format/dist/index.js"
7
+ ],
8
+ "plugin.inlang.messageFormat": {
9
+ "pathPattern": "./messages/{locale}.json"
10
+ }
11
+ }
@@ -0,0 +1,26 @@
1
+ # AGENTS.md
2
+
3
+ > 通用 AI 编程助手指引。详细 Skill 文件位于 `.agents/skills/` 目录。
4
+
5
+ ## 项目概述
6
+
7
+ 本项目使用 hai-framework 构建,基于 SvelteKit 2 + Svelte 5 (Runes) + TailwindCSS 4 + DaisyUI 5 + TypeScript 5.7+。
8
+
9
+ ## 核心规范
10
+
11
+ - 统一模式:`module.init(config) → use → module.close()`,所有操作返回 `HaiResult<T>`
12
+ - **TDD 驱动开发**:先写测试(Red)→ 确认失败 → 再实现(Green)→ 确认通过 → 重构(Refactor)
13
+ - 禁止 `any`(使用 `unknown` + 缩窄),禁止 `console.log`(使用 `core.logger`)
14
+ - 用户可见文本走 i18n,代码注释中文,日志英文
15
+ - HaiResult 错误直接透传,不重新包装
16
+ - 框架模块公共 API 不抛异常,统一返回 `HaiResult<T>`;不要用 `try/catch` 处理模块返回的错误
17
+ - 质量门禁:`pnpm typecheck && pnpm lint && pnpm test && pnpm --filter <app> test:e2e`
18
+
19
+ ## Skills 参考
20
+
21
+ 所有详细指南位于 `.agents/skills/` 目录,按需阅读:
22
+
23
+ - **入口**:`hai-build/SKILL.md` — 项目架构总览与 Skill 导航
24
+ - **框架模块**:`hai-core/`、`hai-kit/`、`hai-reldb/`、`hai-iam/`、`hai-crypto/`、`hai-cache/`、`hai-storage/`、`hai-ai/`
25
+ - **UI 组件**:`hai-ui/SKILL.md`
26
+ - **TDD 开发流程**:`hai-app-tests/`(TDD 测试先行)、`hai-app-create/`(TDD 实现)、`hai-app-review/`(TDD 重构审查)
@@ -0,0 +1,12 @@
1
+ # CLAUDE.md
2
+
3
+ @AGENTS.md
4
+
5
+ > Claude Code 项目指引。共享规范通过 `@AGENTS.md` 复用;共享参考资料位于 `.agents/skills/` 目录。
6
+
7
+ ## 使用说明
8
+
9
+ - 本文件是 Claude Code 的原生项目级指引入口。
10
+ - 项目概述、核心规范与工作流约定统一维护在 `AGENTS.md`;Claude Code 通过 `@AGENTS.md` 复用这些共享规范,避免双份文档漂移。
11
+ - 共享的模块与工作流参考资料维护在 `.agents/skills/` 中;需要具体用法时,可按路径阅读对应 `SKILL.md`。
12
+ - 当前模板为了保持单一 Skill 树,不额外生成 `.claude/skills/`;如需 Claude Code 的原生 project skills 自动发现,需要单独维护该目录。
@@ -0,0 +1,61 @@
1
+ # GitHub Copilot 项目指令
2
+
3
+ > 本文件作为 GitHub Copilot 的项目级指引,指向 `.agents/skills/` 中的详细 Skill 文件。
4
+
5
+ ## 项目概述
6
+
7
+ 本项目使用 [hai-framework](https://github.com/nicehero/hai-framework) 构建,基于 SvelteKit 2 + Svelte 5 (Runes) + TailwindCSS 4 + DaisyUI 5 + TypeScript 5.7+。
8
+
9
+ ## 技术栈要点
10
+
11
+ - **前端框架**:Svelte 5 (Runes: `$props()`, `$state()`, `$derived()`, `$effect()`)
12
+ - **路由/SSR**:SvelteKit 2(文件路由、Handle Hook、load 函数)
13
+ - **样式**:TailwindCSS 4 + DaisyUI 5
14
+ - **后端框架**:hai-framework (`@h-ai/core`, `@h-ai/kit`, `@h-ai/reldb`, `@h-ai/iam` 等)
15
+ - **统一模式**:`module.init(config) → use → module.close()`,所有操作返回 `HaiResult<T>`
16
+ - **单元测试**:Vitest
17
+ - **E2E 测试**:Playwright
18
+ - **包管理**:pnpm
19
+
20
+ ## 编码规范
21
+
22
+ - 禁止 `any`(使用 `unknown` + 缩窄)
23
+ - 禁止 `console.log`(使用 `core.logger`)
24
+ - 禁止硬编码密钥
25
+ - `xx-main.ts` 仅做生命周期管理和 API 编排,禁止在 main 中编写具体业务逻辑(委托给 `xx-functions.ts` / `xx-runner.ts` 等)
26
+ - 用户可见文本必须走 i18n(`$lib/paraglide/messages.js`)
27
+ - HaiResult 错误直接透传,不重新包装
28
+ - 框架模块公共 API 不抛异常,统一返回 `HaiResult<T>`;不要用 `try/catch` 处理模块返回的错误
29
+ - 日志消息英文、简洁动宾结构
30
+ - 代码注释中文
31
+
32
+ ## Skills 目录
33
+
34
+ 详细的开发指南位于 `.agents/skills/` 目录:
35
+
36
+ | Skill | 说明 |
37
+ | ---------------- | ----------------------------------------------------- |
38
+ | `hai-build` | 项目架构、模块依赖、初始化顺序、编码标准 |
39
+ | `hai-core` | 配置加载、日志、i18n、HaiResult 模型、模块生命周期 |
40
+ | `hai-kit` | SvelteKit 集成:Handle Hook、守卫、中间件、响应、校验 |
41
+ | `hai-ui` | UI 组件库:三层架构、自动导入、主题、i18n |
42
+ | `hai-reldb` | 数据库操作:DDL、SQL、CRUD、事务、分页 |
43
+ | `hai-iam` | 认证与权限:密码/OTP/LDAP、会话、RBAC |
44
+ | `hai-crypto` | 加密:SM2/SM3/SM4、密码哈希、随机生成 |
45
+ | `hai-cache` | 缓存:内存/Redis、TTL、集合操作、分布式锁 |
46
+ | `hai-storage` | 存储:本地/S3、上传下载、预签名 URL |
47
+ | `hai-ai` | AI:LLM 调用、MCP 服务器、工具定义、流处理 |
48
+ | `hai-app-create` | TDD 驱动的功能创建(先测试后实现) |
49
+ | `hai-app-review` | 应用代码审查(含 TDD 合规检查) |
50
+ | `hai-app-tests` | TDD 测试规范(Vitest 单元测试 + Playwright E2E) |
51
+
52
+ ## 开发流程
53
+
54
+ **必须遵循 TDD**:先写测试(Red)→ 确认失败 → 再实现(Green)→ 确认通过 → 重构(Refactor)。
55
+
56
+ ## 质量门禁
57
+
58
+ ```bash
59
+ pnpm typecheck && pnpm lint && pnpm test
60
+ pnpm --filter <app-name> test:e2e # E2E 测试
61
+ ```