@hiai-gg/hiai-docs 0.0.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.
Files changed (216) hide show
  1. package/.all-contributorsrc +18 -0
  2. package/.claude/settings.local.json +61 -0
  3. package/.dockerignore +113 -0
  4. package/.env.example +68 -0
  5. package/.github/FUNDING.yml +5 -0
  6. package/.github/ISSUE_TEMPLATE/bug_report.md +74 -0
  7. package/.github/ISSUE_TEMPLATE/feature_request.md +78 -0
  8. package/.github/dependabot.yml +136 -0
  9. package/.github/pull_request_template.md +96 -0
  10. package/.github/workflows/ci.yml +283 -0
  11. package/AGENTS.md +237 -0
  12. package/CODE_OF_CONDUCT.md +134 -0
  13. package/CONTRIBUTING.md +77 -0
  14. package/Caddyfile +50 -0
  15. package/Dockerfile.backend +60 -0
  16. package/LICENSE +21 -0
  17. package/README.md +284 -0
  18. package/RELEASE_CHECKLIST.md +34 -0
  19. package/SECURITY.md +60 -0
  20. package/backend/package.json +43 -0
  21. package/backend/src/__tests__/auth-helpers.test.ts +51 -0
  22. package/backend/src/__tests__/chunker.test.ts +65 -0
  23. package/backend/src/__tests__/config.test.ts +91 -0
  24. package/backend/src/__tests__/csrf.test.ts +91 -0
  25. package/backend/src/__tests__/embedding.test.ts +48 -0
  26. package/backend/src/__tests__/rate-limit.test.ts +46 -0
  27. package/backend/src/__tests__/routes.test.ts +38 -0
  28. package/backend/src/__tests__/schema.test.ts +31 -0
  29. package/backend/src/__tests__/validation.test.ts +556 -0
  30. package/backend/src/api/middleware/auth.ts +56 -0
  31. package/backend/src/api/middleware/csrf.ts +91 -0
  32. package/backend/src/api/middleware/rate-limit.ts +77 -0
  33. package/backend/src/api/middleware/webhook-verify.ts +22 -0
  34. package/backend/src/api/routes/attachments.ts +280 -0
  35. package/backend/src/api/routes/auth.ts +52 -0
  36. package/backend/src/api/routes/collaboration.ts +121 -0
  37. package/backend/src/api/routes/documents.ts +664 -0
  38. package/backend/src/api/routes/folders.ts +226 -0
  39. package/backend/src/api/routes/search.ts +354 -0
  40. package/backend/src/api/routes/share.ts +512 -0
  41. package/backend/src/api/routes/tags.ts +247 -0
  42. package/backend/src/api/routes/versions.ts +99 -0
  43. package/backend/src/api/routes/webhooks.ts +43 -0
  44. package/backend/src/embedding/chunker.ts +74 -0
  45. package/backend/src/embedding/index.ts +117 -0
  46. package/backend/src/embedding/providers/ollama.ts +63 -0
  47. package/backend/src/embedding/providers/openrouter.ts +71 -0
  48. package/backend/src/embedding/utils.ts +13 -0
  49. package/backend/src/embedding/worker.ts +89 -0
  50. package/backend/src/index.ts +147 -0
  51. package/backend/src/lib/auth-helpers.ts +27 -0
  52. package/backend/src/lib/auth.ts +35 -0
  53. package/backend/src/lib/config.ts +73 -0
  54. package/backend/src/lib/db.ts +7 -0
  55. package/backend/src/lib/embedding-queue.ts +12 -0
  56. package/backend/src/lib/logger.ts +18 -0
  57. package/backend/src/lib/markdown-to-doc.ts +45 -0
  58. package/backend/src/lib/minio.ts +46 -0
  59. package/backend/src/lib/redis.ts +19 -0
  60. package/backend/src/lib/yjs-provider.ts +182 -0
  61. package/backend/tests/integration/_harness.ts +754 -0
  62. package/backend/tests/integration/auth.test.ts +296 -0
  63. package/backend/tests/integration/routes.documents.test.ts +459 -0
  64. package/backend/tests/integration/routes.folders.test.ts +337 -0
  65. package/backend/tests/integration/routes.search.test.ts +322 -0
  66. package/backend/tests/integration/routes.share.test.ts +773 -0
  67. package/backend/tests/integration/routes.tags.test.ts +425 -0
  68. package/backend/tests/integration/routes.versions.test.ts +233 -0
  69. package/backend/tsconfig.json +18 -0
  70. package/docker-compose.yml +218 -0
  71. package/docs/API.md +328 -0
  72. package/docs/ARCHITECTURE.md +75 -0
  73. package/docs/DEPLOYMENT.md +113 -0
  74. package/docs/PRODUCTION_STATUS.md +61 -0
  75. package/docs/openapi.json +385 -0
  76. package/frontend/.svelte-kit.old/ambient.d.ts +230 -0
  77. package/frontend/.svelte-kit.old/env.d.ts +1 -0
  78. package/frontend/.svelte-kit.old/generated/client/app.js +46 -0
  79. package/frontend/.svelte-kit.old/generated/client/matchers.js +1 -0
  80. package/frontend/.svelte-kit.old/generated/client/nodes/0.js +3 -0
  81. package/frontend/.svelte-kit.old/generated/client/nodes/1.js +1 -0
  82. package/frontend/.svelte-kit.old/generated/client/nodes/10.js +3 -0
  83. package/frontend/.svelte-kit.old/generated/client/nodes/2.js +1 -0
  84. package/frontend/.svelte-kit.old/generated/client/nodes/3.js +1 -0
  85. package/frontend/.svelte-kit.old/generated/client/nodes/4.js +1 -0
  86. package/frontend/.svelte-kit.old/generated/client/nodes/5.js +3 -0
  87. package/frontend/.svelte-kit.old/generated/client/nodes/6.js +1 -0
  88. package/frontend/.svelte-kit.old/generated/client/nodes/7.js +3 -0
  89. package/frontend/.svelte-kit.old/generated/client/nodes/8.js +1 -0
  90. package/frontend/.svelte-kit.old/generated/client/nodes/9.js +3 -0
  91. package/frontend/.svelte-kit.old/generated/root.js +3 -0
  92. package/frontend/.svelte-kit.old/generated/root.svelte +80 -0
  93. package/frontend/.svelte-kit.old/generated/server/internal.js +55 -0
  94. package/frontend/.svelte-kit.old/non-ambient.d.ts +59 -0
  95. package/frontend/.svelte-kit.old/tsconfig.json +59 -0
  96. package/frontend/.svelte-kit.old/types/route_meta_data.json +40 -0
  97. package/frontend/.svelte-kit.old/types/src/routes/$types.d.ts +21 -0
  98. package/frontend/.svelte-kit.old/types/src/routes/(app)/$types.d.ts +30 -0
  99. package/frontend/.svelte-kit.old/types/src/routes/(app)/docs/[id]/$types.d.ts +27 -0
  100. package/frontend/.svelte-kit.old/types/src/routes/(app)/docs/[id]/proxy+page.ts +25 -0
  101. package/frontend/.svelte-kit.old/types/src/routes/api/[...path]/$types.d.ts +10 -0
  102. package/frontend/.svelte-kit.old/types/src/routes/folders/[id]/$types.d.ts +27 -0
  103. package/frontend/.svelte-kit.old/types/src/routes/folders/[id]/proxy+page.ts +15 -0
  104. package/frontend/.svelte-kit.old/types/src/routes/login/$types.d.ts +17 -0
  105. package/frontend/.svelte-kit.old/types/src/routes/register/$types.d.ts +17 -0
  106. package/frontend/.svelte-kit.old/types/src/routes/s/[token]/$types.d.ts +20 -0
  107. package/frontend/.svelte-kit.old/types/src/routes/s/[token]/proxy+page.ts +6 -0
  108. package/frontend/.svelte-kit.old/types/src/routes/search/$types.d.ts +19 -0
  109. package/frontend/.svelte-kit.old/types/src/routes/search/proxy+page.ts +26 -0
  110. package/frontend/.svelte-kit.old/types/src/routes/settings/$types.d.ts +17 -0
  111. package/frontend/Dockerfile +44 -0
  112. package/frontend/biome.json +40 -0
  113. package/frontend/components.json +18 -0
  114. package/frontend/messages/en.json +434 -0
  115. package/frontend/package.json +70 -0
  116. package/frontend/project.inlang/settings.json +12 -0
  117. package/frontend/src/app.css +6 -0
  118. package/frontend/src/app.d.ts +13 -0
  119. package/frontend/src/app.html +30 -0
  120. package/frontend/src/hooks.server.ts +10 -0
  121. package/frontend/src/hooks.ts +10 -0
  122. package/frontend/src/lib/api/attachments.ts +45 -0
  123. package/frontend/src/lib/api/client.test.ts +15 -0
  124. package/frontend/src/lib/api/client.ts +57 -0
  125. package/frontend/src/lib/api/documents.ts +83 -0
  126. package/frontend/src/lib/api/folders.ts +180 -0
  127. package/frontend/src/lib/api/search.test.ts +52 -0
  128. package/frontend/src/lib/api/search.ts +128 -0
  129. package/frontend/src/lib/api/settings.ts +95 -0
  130. package/frontend/src/lib/api/share.ts +71 -0
  131. package/frontend/src/lib/api/tags.test.ts +91 -0
  132. package/frontend/src/lib/api/tags.ts +87 -0
  133. package/frontend/src/lib/auth-client.ts +10 -0
  134. package/frontend/src/lib/collaboration.ts +63 -0
  135. package/frontend/src/lib/components/AttachmentUpload.svelte +110 -0
  136. package/frontend/src/lib/components/DatePicker.svelte +322 -0
  137. package/frontend/src/lib/components/DocumentCard.svelte +166 -0
  138. package/frontend/src/lib/components/EmptyState.svelte +49 -0
  139. package/frontend/src/lib/components/FolderCard.svelte +93 -0
  140. package/frontend/src/lib/components/ScrollToTop.svelte +72 -0
  141. package/frontend/src/lib/components/SearchBar.svelte +47 -0
  142. package/frontend/src/lib/components/SearchResult.svelte +115 -0
  143. package/frontend/src/lib/components/SettingsDialog.svelte +271 -0
  144. package/frontend/src/lib/components/ShareDialog.svelte +158 -0
  145. package/frontend/src/lib/components/ShareLink.svelte +98 -0
  146. package/frontend/src/lib/components/TagCreateDialog.svelte +284 -0
  147. package/frontend/src/lib/components/VersionDiff.svelte +55 -0
  148. package/frontend/src/lib/components/VersionHistory.svelte +96 -0
  149. package/frontend/src/lib/components/editor/DocumentTitle.svelte +87 -0
  150. package/frontend/src/lib/components/editor/EditorToolbar.svelte +1367 -0
  151. package/frontend/src/lib/components/editor/HiAiEditor.svelte +531 -0
  152. package/frontend/src/lib/components/editor/LinkDialog.svelte +134 -0
  153. package/frontend/src/lib/components/editor/MarkdownToggle.svelte +88 -0
  154. package/frontend/src/lib/components/editor/editorExtensions.ts +53 -0
  155. package/frontend/src/lib/components/editor/markdown.ts +38 -0
  156. package/frontend/src/lib/components/sidebar/FolderTree.svelte +731 -0
  157. package/frontend/src/lib/components/sidebar/RecentDocs.svelte +311 -0
  158. package/frontend/src/lib/components/sidebar/Sidebar.svelte +156 -0
  159. package/frontend/src/lib/components/sidebar/TagList.svelte +200 -0
  160. package/frontend/src/lib/components/ui/confirm-dialog/ConfirmDialog.svelte +76 -0
  161. package/frontend/src/lib/components/ui/confirm-dialog/index.ts +1 -0
  162. package/frontend/src/lib/stores/tag-store.svelte.ts +56 -0
  163. package/frontend/src/lib/stores/theme.svelte.ts +97 -0
  164. package/frontend/src/lib/svelte.d.ts +6 -0
  165. package/frontend/src/lib/types.ts +44 -0
  166. package/frontend/src/lib/utils/clipboard.ts +17 -0
  167. package/frontend/src/lib/utils/strip-markdown.ts +59 -0
  168. package/frontend/src/lib/utils.ts +33 -0
  169. package/frontend/src/routes/(app)/+layout.svelte +17 -0
  170. package/frontend/src/routes/(app)/+page.server.ts +10 -0
  171. package/frontend/src/routes/(app)/+page.svelte +303 -0
  172. package/frontend/src/routes/(app)/docs/[id]/+page.server.ts +10 -0
  173. package/frontend/src/routes/(app)/docs/[id]/+page.svelte +1108 -0
  174. package/frontend/src/routes/(app)/docs/[id]/+page.ts +24 -0
  175. package/frontend/src/routes/(app)/search/+page.svelte +593 -0
  176. package/frontend/src/routes/(app)/search/+page.ts +25 -0
  177. package/frontend/src/routes/+error.svelte +12 -0
  178. package/frontend/src/routes/+layout.svelte +18 -0
  179. package/frontend/src/routes/+layout.ts +2 -0
  180. package/frontend/src/routes/api/[...path]/+server.ts +111 -0
  181. package/frontend/src/routes/folders/[id]/+page.server.ts +10 -0
  182. package/frontend/src/routes/folders/[id]/+page.svelte +319 -0
  183. package/frontend/src/routes/folders/[id]/+page.ts +14 -0
  184. package/frontend/src/routes/login/+page.svelte +90 -0
  185. package/frontend/src/routes/register/+page.svelte +97 -0
  186. package/frontend/src/routes/s/[token]/+page.svelte +496 -0
  187. package/frontend/src/routes/s/[token]/+page.ts +5 -0
  188. package/frontend/src/routes/settings/+page.svelte +175 -0
  189. package/frontend/static/favicon.png +0 -0
  190. package/frontend/static/logo.png +0 -0
  191. package/frontend/svelte.config.js +15 -0
  192. package/frontend/tsconfig.json +15 -0
  193. package/frontend/vite.config.ts +25 -0
  194. package/init.sql +9 -0
  195. package/logo.png +0 -0
  196. package/package.json +39 -0
  197. package/package.public.json +39 -0
  198. package/packages/db/drizzle.config.ts +10 -0
  199. package/packages/db/package.json +30 -0
  200. package/packages/db/src/client.ts +9 -0
  201. package/packages/db/src/index.ts +2 -0
  202. package/packages/db/src/migrations/0000_nice_bedlam.sql +165 -0
  203. package/packages/db/src/migrations/0001_w2_3_test.sql +5 -0
  204. package/packages/db/src/migrations/0002_rename_content_json.sql +2 -0
  205. package/packages/db/src/migrations/meta/0000_snapshot.json +1331 -0
  206. package/packages/db/src/migrations/meta/0001_snapshot.json +1399 -0
  207. package/packages/db/src/migrations/meta/0002_snapshot.json +1399 -0
  208. package/packages/db/src/migrations/meta/_journal.json +27 -0
  209. package/packages/db/src/schema.ts +378 -0
  210. package/packages/db/tsconfig.json +17 -0
  211. package/scripts/export-openapi.ts +37 -0
  212. package/scripts/health-check.sh +75 -0
  213. package/scripts/migrate.sh +135 -0
  214. package/scripts/prework_backup.sh +25 -0
  215. package/scripts/release.sh +83 -0
  216. package/tsconfig.json +25 -0
@@ -0,0 +1,283 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ tags:
7
+ - 'v*'
8
+ pull_request:
9
+ branches: [main]
10
+
11
+ # Cancel in-progress runs for the same branch / PR
12
+ concurrency:
13
+ group: ${{ github.workflow }}-${{ github.ref }}
14
+ cancel-in-progress: true
15
+
16
+ # Minimum permissions; jobs that need more request them explicitly
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ # ---------------------------------------------------------------------------
22
+ # 1. Lint — Biome 2.4.15 (configured in root biome.json)
23
+ # ---------------------------------------------------------------------------
24
+ lint:
25
+ name: Lint
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: oven-sh/setup-bun@v2
30
+ with:
31
+ bun-version: latest
32
+ - run: bun install
33
+ - run: bun run lint
34
+
35
+ # ---------------------------------------------------------------------------
36
+ # 2. Typecheck — `bun run typecheck` (root)
37
+ # ---------------------------------------------------------------------------
38
+ typecheck:
39
+ name: Typecheck
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+ - uses: oven-sh/setup-bun@v2
44
+ with:
45
+ bun-version: latest
46
+ - run: bun install
47
+ - run: bun run typecheck
48
+
49
+ # ---------------------------------------------------------------------------
50
+ # 3. Test — Bun test runner with PostgreSQL + Redis services
51
+ # ---------------------------------------------------------------------------
52
+ test:
53
+ name: Test
54
+ runs-on: ubuntu-latest
55
+ services:
56
+ postgres:
57
+ image: pgvector/pgvector:pg18
58
+ env:
59
+ POSTGRES_DB: hiai_docs_test
60
+ POSTGRES_USER: aiuser
61
+ POSTGRES_PASSWORD: testpassword
62
+ ports:
63
+ - 5432:5432
64
+ options: >-
65
+ --health-cmd "pg_isready -U aiuser -d hiai_docs_test"
66
+ --health-interval 10s
67
+ --health-timeout 5s
68
+ --health-retries 5
69
+ redis:
70
+ image: redis:8-alpine
71
+ ports:
72
+ - 6379:6379
73
+ options: >-
74
+ --health-cmd "redis-cli ping"
75
+ --health-interval 10s
76
+ --health-timeout 5s
77
+ --health-retries 5
78
+ env:
79
+ DATABASE_URL: postgresql://aiuser:testpassword@localhost:5432/hiai_docs_test
80
+ REDIS_URL: redis://localhost:6379
81
+ BETTER_AUTH_SECRET: test-secret-key-minimum-32-chars-long
82
+ BETTER_AUTH_URL: http://localhost:50700
83
+ NODE_ENV: test
84
+ steps:
85
+ - uses: actions/checkout@v4
86
+ - uses: oven-sh/setup-bun@v2
87
+ with:
88
+ bun-version: latest
89
+ - run: bun install
90
+ - run: cd packages/db && bun run db:migrate
91
+ - run: bun run test
92
+
93
+ # ---------------------------------------------------------------------------
94
+ # 4. Docker build — validate compose, build both images, security scan
95
+ # ---------------------------------------------------------------------------
96
+ docker-build:
97
+ name: Docker Build & Scan
98
+ runs-on: ubuntu-latest
99
+ steps:
100
+ - name: Checkout
101
+ uses: actions/checkout@v4
102
+
103
+ # Materialise a synthetic .env so `docker compose config` resolves vars
104
+ - name: Prepare .env for compose validation
105
+ run: |
106
+ cp .env.example .env
107
+ # Replace example secrets with deterministic test values
108
+ sed -i 's/^BETTER_AUTH_SECRET=.*/BETTER_AUTH_SECRET=ci-validation-secret-32-chars-long-xxx/' .env
109
+ sed -i 's/^CSRF_SECRET=.*/CSRF_SECRET=ci-csrf-secret-32-chars-long-yyy/' .env
110
+ sed -i 's/^MINIO_SECRET_KEY=.*/MINIO_SECRET_KEY=ci-minio-secret-32-chars-long-zzz/' .env
111
+ sed -i 's/^WEBHOOK_SECRET=.*/WEBHOOK_SECRET=ci-webhook-secret-32-chars-long-aaa/' .env
112
+
113
+ # A) Validate docker-compose.yml — catches bad interpolations & schema errors
114
+ - name: Validate docker compose
115
+ run: docker compose config --quiet
116
+
117
+ # B) Set up buildx with GitHub Actions cache
118
+ - name: Set up Docker Buildx
119
+ uses: docker/setup-buildx-action@v3
120
+ with:
121
+ driver-opts: image=moby/buildkit:latest
122
+
123
+ - name: Cache Docker layers
124
+ uses: actions/cache@v4
125
+ with:
126
+ path: /tmp/.buildx-cache
127
+ key: ${{ runner.os }}-buildx-${{ github.sha }}
128
+ restore-keys: |
129
+ ${{ runner.os }}-buildx-
130
+
131
+ # C) Build the backend image (root context, dockerfile: backend/Dockerfile)
132
+ - name: Build backend image (api)
133
+ uses: docker/build-push-action@v6
134
+ with:
135
+ context: .
136
+ file: Dockerfile.backend
137
+ tags: hiai-docs/api:ci-${{ github.sha }}
138
+ labels: |
139
+ org.opencontainers.image.title=hiai-docs-api
140
+ org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
141
+ org.opencontainers.image.revision=${{ github.sha }}
142
+ load: true
143
+ cache-from: type=local,src=/tmp/.buildx-cache
144
+ cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
145
+
146
+ # D) Build the frontend image (root context, dockerfile: frontend/Dockerfile)
147
+ - name: Build frontend image (web)
148
+ uses: docker/build-push-action@v6
149
+ with:
150
+ context: .
151
+ file: frontend/Dockerfile
152
+ tags: hiai-docs/web:ci-${{ github.sha }}
153
+ labels: |
154
+ org.opencontainers.image.title=hiai-docs-web
155
+ org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
156
+ org.opencontainers.image.revision=${{ github.sha }}
157
+ load: true
158
+ cache-from: type=local,src=/tmp/.buildx-cache
159
+ cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
160
+
161
+ # E) Smoke test — start the built image and curl its health endpoint
162
+ - name: Smoke test backend image
163
+ env:
164
+ BETTER_AUTH_SECRET: ci-smoke-secret-32-chars-long-bbb
165
+ CSRF_SECRET: ci-csrf-secret-32-chars-long-ccc
166
+ MINIO_SECRET_KEY: ci-minio-secret-32-chars-long-ddd
167
+ WEBHOOK_SECRET: ci-webhook-secret-32-chars-long-eee
168
+ DATABASE_URL: postgresql://x:y@127.0.0.1:5432/z
169
+ REDIS_URL: redis://127.0.0.1:6379
170
+ API_PORT: 50700
171
+ NODE_ENV: production
172
+ run: |
173
+ # Quick boot check — image must start, listen, and respond to /api/health
174
+ docker run --rm -d --name hiai-docs-api-smoke \
175
+ -e BETTER_AUTH_SECRET -e CSRF_SECRET -e MINIO_SECRET_KEY \
176
+ -e WEBHOOK_SECRET -e DATABASE_URL -e REDIS_URL \
177
+ -e API_PORT -e NODE_ENV \
178
+ -p 50700:50700 hiai-docs/api:ci-${{ github.sha }}
179
+ sleep 5
180
+ # Server is expected to fail DB connection in CI — we only verify the
181
+ # image boots and the Bun runtime starts. A 5xx on /api/health is OK
182
+ # as long as the port is open.
183
+ curl -sS -o /dev/null -w "HTTP %{http_code}\n" http://127.0.0.1:50700/api/health || true
184
+ docker stop hiai-docs-api-smoke || true
185
+
186
+ # F) Security scan — Trivy (preferred; Docker Scout as fallback)
187
+ - name: Security scan with Trivy
188
+ uses: aquasecurity/trivy-action@0.24.0
189
+ with:
190
+ image-ref: hiai-docs/api:ci-${{ github.sha }}
191
+ format: "table"
192
+ exit-code: "0" # warn-only on PRs; tighten to "1" on protected branches
193
+ ignore-unfixed: true
194
+ vuln-type: "os,library"
195
+ severity: "CRITICAL,HIGH"
196
+ output: "trivy-api.sarif"
197
+ - name: Upload Trivy SARIF (backend)
198
+ if: always()
199
+ uses: github/codeql-action/upload-sarif@v3
200
+ with:
201
+ sarif_file: trivy-api.sarif
202
+ category: trivy-api
203
+
204
+ - name: Security scan frontend with Trivy
205
+ uses: aquasecurity/trivy-action@0.24.0
206
+ with:
207
+ image-ref: hiai-docs/web:ci-${{ github.sha }}
208
+ format: "table"
209
+ exit-code: "0"
210
+ ignore-unfixed: true
211
+ vuln-type: "os,library"
212
+ severity: "CRITICAL,HIGH"
213
+ output: "trivy-web.sarif"
214
+ - name: Upload Trivy SARIF (frontend)
215
+ if: always()
216
+ uses: github/codeql-action/upload-sarif@v3
217
+ with:
218
+ sarif_file: trivy-web.sarif
219
+ category: trivy-web
220
+
221
+ # G) Finalise cache (atomic swap)
222
+ - name: Move cache
223
+ run: |
224
+ rm -rf /tmp/.buildx-cache
225
+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
226
+
227
+ # H) Tag & Push to Docker Hub (only on tag release)
228
+ - name: Log in to Docker Hub
229
+ if: startsWith(github.ref, 'refs/tags/v')
230
+ uses: docker/login-action@v3
231
+ with:
232
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
233
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
234
+
235
+ - name: Tag and push API image
236
+ if: startsWith(github.ref, 'refs/tags/v')
237
+ run: |
238
+ docker tag hiai-docs/api:ci-${{ github.sha }} vgalibov/hiai-docs:api-${{ github.ref_name }}
239
+ docker push vgalibov/hiai-docs:api-${{ github.ref_name }}
240
+
241
+ - name: Tag and push Web image
242
+ if: startsWith(github.ref, 'refs/tags/v')
243
+ run: |
244
+ docker tag hiai-docs/web:ci-${{ github.sha }} vgalibov/hiai-docs:web-${{ github.ref_name }}
245
+ docker push vgalibov/hiai-docs:web-${{ github.ref_name }}
246
+
247
+ # ---------------------------------------------------------------------------
248
+ # 5. Publish NPM — publish package `@hiai-gg/hiai-docs` to NPM
249
+ # ---------------------------------------------------------------------------
250
+ publish-npm:
251
+ name: Publish NPM Package
252
+ needs: [lint, typecheck, test, docker-build]
253
+ if: startsWith(github.ref, 'refs/tags/v')
254
+ runs-on: ubuntu-latest
255
+ steps:
256
+ - uses: actions/checkout@v4
257
+ - uses: oven-sh/setup-bun@v2
258
+ with:
259
+ bun-version: latest
260
+
261
+ - name: Install dependencies
262
+ run: bun install
263
+
264
+ - name: Prepare public package.json
265
+ run: |
266
+ # Swap package.json with package.public.json for publishing
267
+ # We also extract the version from the git tag (removing 'v' prefix if present)
268
+ TAG_VERSION="${{ github.ref_name }}"
269
+ CLEAN_VERSION="${TAG_VERSION#v}"
270
+
271
+ # Replace name and version in package.public.json
272
+ bun -e "
273
+ const fs = require('fs');
274
+ const pkg = JSON.parse(fs.readFileSync('package.public.json', 'utf8'));
275
+ pkg.name = '@hiai-gg/hiai-docs';
276
+ pkg.version = '${CLEAN_VERSION}';
277
+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
278
+ "
279
+
280
+ - name: Publish to NPM
281
+ run: bun publish --no-git-checks --access public
282
+ env:
283
+ NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
package/AGENTS.md ADDED
@@ -0,0 +1,237 @@
1
+ # hiai-docs
2
+
3
+ > Standalone, open-source, AI-native knowledge base. Markdown-first, auto-embeddings, self-hostable.
4
+
5
+ ## 📍 Источник правды экосистемы (читать первым)
6
+
7
+ hiai-docs — часть экосистемы HiAi (модуль документов + источник дизайн-токенов). Общая правда — в корне `projects/`:
8
+ - [`../HIAI_CONVENTIONS.md`](../HIAI_CONVENTIONS.md) — правила, топология, дизайн-токены, plugin-контракт.
9
+ - [`../HIAI_ECOSYSTEM_UNIFICATION_PLAN.md`](../HIAI_ECOSYSTEM_UNIFICATION_PLAN.md) — программа унификации (U0–U5).
10
+
11
+ ### Project Documents (Index)
12
+ `README.md` · `AGENTS.md` (this one) · `todo.md` - core. `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, `SECURITY.md` - standard.
13
+
14
+ ## Identity & Purpose
15
+
16
+ **hiai-docs** is a self-hosted knowledge base with built-in vector embeddings for RAG-ready semantic search. Alternative to Outline/Docmost with focus on simplicity, AI integration, and data ownership.
17
+
18
+ **Open-source (MIT).** All paths, keys, dependencies via `.env`. Zero hardcoded secrets.
19
+
20
+ ## Runtime Contract
21
+
22
+ | Property | Value |
23
+ |----------|-------|
24
+ | **Runtime** | Bun 1.3.14+ |
25
+ | **Backend** | Elysia 1.4.28+ (ESM-only) |
26
+ | **Frontend** | SvelteKit 2.60+ + Svelte 5.55+ |
27
+ | **UI** | shadcn-svelte 1.2.7+ (new-york style) + Tailwind CSS v4 |
28
+ | **Editor** | svelte-tiptap + TipTap v3 (WYSIWYG + raw MD toggle) |
29
+ | **ORM** | Drizzle ORM 0.45.2+ |
30
+ | **Database** | PostgreSQL 18.4 + pgvector |
31
+ | **Cache** | Redis 8.6+ |
32
+ | **Auth** | Better Auth |
33
+ | **Storage** | MinIO (S3-compatible) |
34
+ | **Embeddings** | Ollama (configurable, API fallback) |
35
+ | **Logging** | Pino |
36
+ | **Validation** | Zod |
37
+ | **API Port** | 50700 |
38
+ | **Frontend Port** | 50701 |
39
+ | **Module System** | ESM-only, TypeScript strict |
40
+
41
+ ## Canonical Commands
42
+
43
+ | Task | Command | Working Dir |
44
+ |------|---------|-------------|
45
+ | **Install** | `bun install` | Root |
46
+ | **Dev (all)** | `bun run dev:all` | Root |
47
+ | **Dev (api)** | `bun run dev` | `backend/` |
48
+ | **Dev (web)** | `bun run dev` | `frontend/` |
49
+ | **Lint** | `bun run lint` | Root |
50
+ | **Typecheck** | `bun run typecheck` | Root |
51
+ | **Test** | `bun test` | `backend/` or `frontend/` |
52
+ | **DB Push** | `bun run db:push` | `packages/db/` |
53
+ | **DB Generate** | `bun run db:generate` | `packages/db/` |
54
+ | **DB Migrate** | `bun run db:migrate` | `packages/db/` |
55
+ | **Docker Up** | `docker compose up -d` | Root |
56
+ | **Docker Down** | `docker compose down` | Root |
57
+ | **Backup** | `scripts/prework_backup.sh hiai-docs` | Root |
58
+
59
+ ## Health Checks
60
+
61
+ ```bash
62
+ # API health
63
+ curl -fsS http://localhost:50700/api/health
64
+
65
+ # Database
66
+ psql -h localhost -p 5433 -U aiuser -d hiai_docs -c "SELECT NOW();"
67
+
68
+ # Redis
69
+ redis-cli -p 6380 ping
70
+
71
+ # Ollama
72
+ curl -fsS http://localhost:11434/api/tags
73
+
74
+ # MinIO
75
+ curl -fsS http://localhost:9000/minio/health/live
76
+ ```
77
+
78
+ ## Architecture
79
+
80
+ ### Data Isolation
81
+
82
+ - **Current:** User-scoped (`owner_id` on every table)
83
+ - **Future:** `tenant_id` nullable column reserved for multi-tenancy
84
+ - Every query MUST include `WHERE owner_id = $1`
85
+ - No cross-user data access except via share_links
86
+
87
+ ### Module Boundaries
88
+
89
+ ```
90
+ backend/src/
91
+ ├── api/ # HTTP layer (routes, middleware)
92
+ │ ├── routes/ # Route handlers
93
+ │ └── middleware/ # Auth, rate-limit, logging
94
+ ├── embedding/ # Embedding pipeline (isolated from API)
95
+ ├── lib/ # Shared utilities (db, config, logger)
96
+ └── index.ts # Entry point
97
+ ```
98
+
99
+ - `api/` MUST NOT export internal functions — only route registrations
100
+ - `embedding/` MUST NOT import from `api/` — use event bus or queue
101
+ - `lib/` MUST NOT import from `api/` or `embedding/`
102
+
103
+ ### Embedding Pipeline
104
+
105
+ ```
106
+ document.save() → chunk(500 tokens, 50 overlap) → embed(provider) → store(pgvector)
107
+ ↓ on failure
108
+ fallback(provider) → dummy vector
109
+ ```
110
+
111
+ Configured via `.env`:
112
+ ```
113
+ EMBEDDING_PROVIDER=ollama|openrouter|voyage
114
+ EMBEDDING_FALLBACK_PROVIDER=openrouter
115
+ ```
116
+
117
+ ### Search
118
+
119
+ Hybrid search: `0.4 * full_text + 0.6 * semantic_cosine` (configurable weights)
120
+
121
+ ## Coding Guidelines
122
+
123
+ ### Hard Rules
124
+
125
+ - **Bun-native:** No npm/yarn, no Node-only packages, no CommonJS
126
+ - **ESM-only:** All imports use ESM syntax
127
+ - **TypeScript strict:** No `any`, proper Zod validation on all inputs
128
+ - **English only:** Code, comments, docs, README, AGENTS.md — zero Russian
129
+ - **No Playwright:** Use agent-browser for E2E testing
130
+ - **No root file sprawl:** Every file belongs in a canonical directory
131
+ - **Environment-driven:** All config in `.env`, zero hardcoded paths/keys
132
+ - **No autonomous git pushes:** Push requires explicit user authorization
133
+
134
+ ### TypeScript Config
135
+
136
+ ```jsonc
137
+ {
138
+ "compilerOptions": {
139
+ "target": "ESNext",
140
+ "module": "ESNext",
141
+ "moduleResolution": "bundler",
142
+ "strict": true,
143
+ "noUncheckedIndexedAccess": true
144
+ }
145
+ }
146
+ ```
147
+
148
+ ### Dev Quirks & Known Workarounds
149
+
150
+ These are non-obvious project decisions pinned in `package.json` / Dockerfiles. Do not "clean up" without first understanding the constraint.
151
+
152
+ - **`@sinclair/typebox@^0.34.0` (root devDependency)** — Forces a single Typebox version across the workspace to resolve a peer-dep conflict with Elysia 1.4.28. Required for `bun install` to succeed; do not remove.
153
+ - **`bun test --path-ignore-patterns='*node_modules*'`** — Bun 1.3's smart test discovery walks into hoisted `node_modules` and tries to run upstream library tests, which fail on missing fixtures. The path-ignore flag scopes test discovery to our own `src/` and `tests/` directories. Keep this flag on every `test` script.
154
+ - **Paraglide v2 SvelteKit integration** — i18n is driven by `@inlang/paraglide-js@2.x` directly. The deprecated `@inlang/paraglide-sveltekit` adapter is NOT used. Setup:
155
+ - `frontend/vite.config.ts` registers `paraglideVitePlugin({ project, outdir, strategy })`.
156
+ - `frontend/src/hooks.ts` exports a `reroute` hook calling `deLocalizeUrl(request.url).pathname`.
157
+ - `frontend/src/hooks.server.ts` exports `handle` wrapping `paraglideMiddleware()` from the generated `$lib/paraglide/server.js`.
158
+ - Components use `import * as m from "$lib/paraglide/messages.js"` and `import { getLocale } from "$lib/paraglide/runtime"`.
159
+ - The `frontend/Dockerfile` does NOT need any `sed` patch — `@inlang/sdk@2.x` no longer triggers Bun's `NameTooLong` error.
160
+
161
+ ### Svelte Rules
162
+
163
+ - Svelte 5 runes enforced globally (`runes: true`)
164
+ - `$props()` for component props, `{@render children?.()}` for slots
165
+ - `$derived.by()` for multi-line derived values
166
+ - `$effect()` returns void — cleanup inside body
167
+ - `import type` only for type-only imports (not for bind:this targets)
168
+ - `import { page } from '$app/state'` (not `$app/stores`)
169
+ - `./$types` generated at build time — ignore IDE errors
170
+
171
+ ### API Rules
172
+
173
+ - Every route validated with Zod schemas
174
+ - Rate limiting on all public endpoints (Redis-based)
175
+ - Pino logger with structured logging
176
+ - Better Auth session check on all protected routes
177
+ - `set.status` for HTTP status codes (Elysia pattern)
178
+
179
+ ## Development
180
+
181
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on code style, testing, and PR workflow.
182
+
183
+ ## Docker Services
184
+
185
+ | Container | Image | Port | Purpose |
186
+ |-----------|-------|------|---------|
187
+ | postgres | pgvector/pgvector:pg18 | 5433:5432 | Database |
188
+ | redis | redis:8-alpine | 6380:6379 | Cache/queue |
189
+ | ollama | ollama/ollama | 11434:11434 | Embeddings |
190
+ | minio | minio/minio | 9000:9000, 9001:9001 | File storage |
191
+ | api | custom | 50700:50700 | Elysia backend |
192
+ | web | custom | 50701:50701 | SvelteKit frontend |
193
+ | caddy | caddy:2-alpine | 80:80, 443:443 | Reverse proxy |
194
+
195
+ ## Multi-Agent Development
196
+
197
+ ### Wave Structure
198
+
199
+ Phases are designed for parallel agent execution:
200
+ - **Foundation wave:** Schema + Docker + config (sequential, shared state)
201
+ - **Backend wave:** API routes (parallel by domain: docs, folders, search, share, tags)
202
+ - **Frontend wave:** Pages + components (parallel by page)
203
+ - **Integration wave:** API + frontend wiring (sequential)
204
+ - **Polish wave:** Tests + docs + deploy (parallel)
205
+
206
+ ### File Ownership Matrix
207
+
208
+ Each agent claims exclusive file ownership to prevent conflicts:
209
+ - Backend routes: one agent per route domain
210
+ - Frontend pages: one agent per page
211
+ - Shared utilities: foundation agent only
212
+ - Schema: foundation agent only
213
+
214
+ ### Post-Agent Cleanup
215
+
216
+ After parallel agent waves:
217
+ 1. Run `bun run typecheck` — fix all TS errors
218
+ 2. Run `bun test` — fix failing tests
219
+ 3. Run `bun run lint` — fix lint issues
220
+ 4. Verify no duplicate imports/exports
221
+ 5. Verify no orphaned files
222
+
223
+ ## CLOSURE_PROTOCOL
224
+
225
+ ### Mandatory Task Finalization
226
+
227
+ End every response with a structured `<CLOSURE>` block:
228
+
229
+ ```xml
230
+ <CLOSURE>
231
+ {
232
+ "reasoning": "Concise summary of what was achieved.",
233
+ "evidence": ["File paths", "Test results", "LSP diagnostics"],
234
+ "readiness": "done" | "accept" | "reject"
235
+ }
236
+ </CLOSURE>
237
+ ```
@@ -0,0 +1,134 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ - Demonstrating empathy and kindness toward other people
21
+ - Being respectful of differing opinions, viewpoints, and experiences
22
+ - Giving and gracefully accepting constructive feedback
23
+ - Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ - Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ - The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ - Trolling, insulting or derogatory comments, and personal or political attacks
33
+ - Public or private harassment
34
+ - Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ - Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at:
63
+
64
+ **hiai@webs.cool**
65
+
66
+ All complaints will be reviewed and investigated promptly and fairly.
67
+
68
+ All community leaders are obligated to respect the privacy and security of the
69
+ reporter of any incident.
70
+
71
+ ## Enforcement Guidelines
72
+
73
+ Community leaders will follow these Community Impact Guidelines in determining
74
+ the consequences of any action they deem in violation of this Code of Conduct:
75
+
76
+ ### 1. Correction
77
+
78
+ **Community Impact**: Use of inappropriate language or other behavior deemed
79
+ unprofessional or unwelcome in the community.
80
+
81
+ **Consequence**: A private, written warning from community leaders, providing
82
+ clarity around the nature of the violation and an explanation of why the
83
+ behavior was inappropriate. A public apology may be requested.
84
+
85
+ ### 2. Warning
86
+
87
+ **Community Impact**: A violation through a single incident or series
88
+ of actions.
89
+
90
+ **Consequence**: A warning with consequences for continued behavior. No
91
+ interaction with the people involved, including unsolicited interaction with
92
+ those enforcing the Code of Conduct, for a specified period of time. This
93
+ includes avoiding interactions in community spaces as well as external channels
94
+ like social media. Violating these terms may lead to a temporary or
95
+ permanent ban.
96
+
97
+ ### 3. Temporary Ban
98
+
99
+ **Community Impact**: A serious violation of community standards, including
100
+ sustained inappropriate behavior.
101
+
102
+ **Consequence**: A temporary ban from any sort of interaction or public
103
+ communication with the community for a specified period of time. No public or
104
+ private interaction with the people involved, including unsolicited interaction
105
+ with those enforcing the Code of Conduct, is allowed during this period.
106
+ Violating these terms may lead to a permanent ban.
107
+
108
+ ### 4. Permanent Ban
109
+
110
+ **Community Impact**: Demonstrating a pattern of violation of community
111
+ standards, including sustained inappropriate behavior, harassment of an
112
+ individual, or aggression toward or disparagement of classes of individuals.
113
+
114
+ **Consequence**: A permanent ban from any sort of public interaction within
115
+ the community.
116
+
117
+ ## Attribution
118
+
119
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
120
+ version 2.1, available at
121
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
122
+
123
+ Community Impact Guidelines were inspired by
124
+ [Mozilla's code of conduct enforcement ladder][mozilla coc].
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ [https://www.contributor-covenant.org/faq][faq]. Translations are available
128
+ at [https://www.contributor-covenant.org/translations][translations].
129
+
130
+ [homepage]: https://www.contributor-covenant.org
131
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
132
+ [mozilla coc]: https://github.com/mozilla/diversity
133
+ [faq]: https://www.contributor-covenant.org/faq
134
+ [translations]: https://www.contributor-covenant.org/translations