@kokimoki/kit 1.6.7 → 1.8.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.
@@ -0,0 +1,389 @@
1
+ ---
2
+ description: Vite plugin and development tools for Kokimoki apps
3
+ applyTo: "**/vite.config.{ts,js,mts,mjs}"
4
+ ---
5
+
6
+ # Kokimoki Kit
7
+
8
+ The `@kokimoki/kit` package provides the Vite plugin and development tools for building Kokimoki apps.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @kokimoki/kit
14
+ ```
15
+
16
+ ## Plugin Configuration
17
+
18
+ Add the plugin to your `vite.config.ts`:
19
+
20
+ ```typescript
21
+ import { defineConfig } from "vite";
22
+ import { kokimokiKitPlugin } from "@kokimoki/kit";
23
+ import { z } from "@kokimoki/kit";
24
+
25
+ export default defineConfig({
26
+ plugins: [
27
+ kokimokiKitPlugin({
28
+ // Required: Your concept ID from Kokimoki
29
+ conceptId: "your-concept-id",
30
+
31
+ // Required: Deploy configurations
32
+ deployCodes: [
33
+ {
34
+ name: "default",
35
+ description: "Default game mode",
36
+ clientContext: { mode: "standard" },
37
+ },
38
+ {
39
+ name: "tournament",
40
+ description: "Tournament mode with stricter rules",
41
+ clientContext: { mode: "tournament", maxPlayers: 100 },
42
+ },
43
+ ],
44
+
45
+ // Optional: Project config schema (validated in admin panel)
46
+ schema: z.object({
47
+ title: z.string(),
48
+ maxPlayers: z.number().min(2).max(100),
49
+ timeLimit: z.number().optional(),
50
+ }),
51
+
52
+ // Optional: Store schemas for validation
53
+ stores: [
54
+ {
55
+ pattern: "game",
56
+ schema: z.object({
57
+ status: z.enum(["waiting", "playing", "finished"]),
58
+ round: z.number(),
59
+ }),
60
+ },
61
+ {
62
+ pattern: "player-*",
63
+ schema: z.object({
64
+ name: z.string(),
65
+ score: z.number(),
66
+ }),
67
+ local: true, // Local store (per-client)
68
+ },
69
+ ],
70
+
71
+ // Optional: i18n configuration
72
+ i18nPath: "./src/i18n",
73
+ i18nPrimaryLng: "en", // Source language for AI translations
74
+
75
+ // Optional: Custom API endpoint
76
+ endpoint: "https://api.kokimoki.com",
77
+ host: "y-wss.kokimoki.com",
78
+
79
+ // Optional: Dev view layout (see Dev Frame section)
80
+ devView: [
81
+ [{ label: "host", clientContext: { mode: "host" } }],
82
+ [
83
+ { label: "player1", clientContext: { mode: "player" } },
84
+ { label: "player2", clientContext: { mode: "player" } },
85
+ ],
86
+ ],
87
+ }),
88
+ ],
89
+ });
90
+ ```
91
+
92
+ ## Configuration Options
93
+
94
+ ### Required Options
95
+
96
+ | Option | Type | Description |
97
+ | ------------- | -------- | --------------------------------- |
98
+ | `conceptId` | `string` | Your concept ID from Kokimoki |
99
+ | `deployCodes` | `array` | List of deployment configurations |
100
+
101
+ ### Optional Options
102
+
103
+ | Option | Type | Description |
104
+ | -------------------------- | ---------------- | -------------------------------------------------- |
105
+ | `schema` | `ZodType` | Zod schema for project configuration |
106
+ | `stores` | `array` | Store definitions with patterns and schemas |
107
+ | `i18nPath` | `string` | Path to i18n folder (e.g., `./src/i18n`) |
108
+ | `i18nPrimaryLng` | `string` | Source language code (default: `"en"`) |
109
+ | `endpoint` | `string` | API endpoint (default: `https://api.kokimoki.com`) |
110
+ | `host` | `string` | WebSocket host (default: `y-wss.kokimoki.com`) |
111
+ | `devView` | `array \| false` | Dev frame layout or `false` to disable |
112
+ | `defaultAppMeta` | `object` | Default meta tags for SEO and social sharing |
113
+ | `defaultProjectStylePath` | `string` | Path to default project style file |
114
+
115
+ ## App Meta
116
+
117
+ The `defaultAppMeta` option configures HTML meta tags for SEO and social sharing previews. These defaults are injected into the HTML at build time and used as the initial state for `kmClient.metaStore`.
118
+
119
+ ### Configuration
120
+
121
+ ```typescript
122
+ kokimokiKitPlugin({
123
+ // ...
124
+ defaultAppMeta: {
125
+ lang: "en",
126
+ title: "My Game",
127
+ description: "An awesome multiplayer game",
128
+ ogTitle: "My Game",
129
+ ogDescription: "Join the fun!",
130
+ ogImage: "/og-image.png",
131
+ favicon: "/favicon.png",
132
+ },
133
+ });
134
+ ```
135
+
136
+ ### Fields
137
+
138
+ | Field | Description |
139
+ | --------------- | ---------------------------------------------------- |
140
+ | `lang` | HTML `lang` attribute (e.g., `"en"`, `"de"`) |
141
+ | `title` | Document title (browser tab) |
142
+ | `description` | Meta description for SEO |
143
+ | `ogTitle` | Open Graph title (defaults to `title` if not set) |
144
+ | `ogDescription` | Open Graph description (defaults to `description`) |
145
+ | `ogImage` | Open Graph image URL (use relative path like `/og-image.png`) |
146
+ | `favicon` | Favicon URL (use relative path like `/favicon.png`) |
147
+
148
+ ### Asset Path Resolution
149
+
150
+ Relative paths (starting with `/`) for `ogImage` and `favicon` are automatically prefixed with the assets base URL in production builds. This ensures images work correctly when served from a CDN.
151
+
152
+ ### Runtime Updates
153
+
154
+ The meta state can be updated at runtime via `kmClient.metaStore`:
155
+
156
+ ```typescript
157
+ await kmClient.transact([kmClient.metaStore], ([meta]) => {
158
+ meta.title = "Game Room: Epic Battle";
159
+ meta.ogImage = "https://example.com/custom-preview.png";
160
+ });
161
+ ```
162
+
163
+ ## Dev Frame
164
+
165
+ The dev frame provides a multi-window view for testing different player modes simultaneously during development.
166
+
167
+ ### Configuration
168
+
169
+ ```typescript
170
+ devView: [
171
+ // Row 1: Host and presenter
172
+ [
173
+ { label: "host", clientContext: { mode: "host", playerCode: "admin" } },
174
+ { label: "presenter", clientContext: { mode: "presenter" } },
175
+ ],
176
+ // Row 2: Three players
177
+ [
178
+ { label: "player1", clientContext: { mode: "player" } },
179
+ { label: "player2", clientContext: { mode: "player" } },
180
+ { label: "player3", clientContext: { mode: "player" } },
181
+ ],
182
+ ];
183
+ ```
184
+
185
+ ### DevFrameCell Interface
186
+
187
+ ```typescript
188
+ interface DevFrameCell {
189
+ /** Label shown in the frame header (must be unique) */
190
+ label: string;
191
+ /** Client context passed to the app via URL */
192
+ clientContext: unknown;
193
+ }
194
+ ```
195
+
196
+ ### Features
197
+
198
+ - **Grid layout**: Each inner array is a row of frames
199
+ - **Unique labels**: Each cell must have a unique label
200
+ - **New tab button**: Open any frame in a separate tab
201
+ - **Reset button**: Clear frame's local storage and reload
202
+ - **Error overlay**: Shows errors with reload option
203
+
204
+ ### Disabling Dev Frame
205
+
206
+ Set `devView: false` to disable the dev frame entirely:
207
+
208
+ ```typescript
209
+ kokimokiKitPlugin({
210
+ conceptId: "...",
211
+ deployCodes: [...],
212
+ devView: false,
213
+ })
214
+ ```
215
+
216
+ ## Store Schemas
217
+
218
+ Define schemas to validate store state during development:
219
+
220
+ ```typescript
221
+ stores: [
222
+ // Global store - shared across all clients
223
+ {
224
+ pattern: "game",
225
+ schema: z.object({
226
+ status: z.enum(["waiting", "playing", "finished"]),
227
+ players: z.record(
228
+ z.string(),
229
+ z.object({
230
+ name: z.string(),
231
+ score: z.number(),
232
+ })
233
+ ),
234
+ }),
235
+ },
236
+
237
+ // Wildcard pattern - matches player-abc123, player-xyz789, etc.
238
+ {
239
+ pattern: "player-*",
240
+ schema: z.object({
241
+ name: z.string(),
242
+ avatar: z.string().optional(),
243
+ }),
244
+ local: true, // Local store (client-specific)
245
+ },
246
+
247
+ // Dynamic stores - chat rooms, teams, etc.
248
+ {
249
+ pattern: "chat-*",
250
+ schema: z.object({
251
+ messages: z.record(
252
+ z.string(),
253
+ z.object({
254
+ text: z.string(),
255
+ sender: z.string(),
256
+ })
257
+ ),
258
+ }),
259
+ },
260
+ ];
261
+ ```
262
+
263
+ ## i18n Integration
264
+
265
+ The plugin syncs translations to your dev app automatically.
266
+
267
+ ### Folder Structure
268
+
269
+ ```
270
+ src/i18n/
271
+ ├── en/
272
+ │ ├── ui.json
273
+ │ └── game.json
274
+ ├── et/
275
+ │ ├── ui.json
276
+ │ └── game.json
277
+ └── de/
278
+ ├── ui.json
279
+ └── game.json
280
+ ```
281
+
282
+ ### Configuration
283
+
284
+ ```typescript
285
+ kokimokiKitPlugin({
286
+ // ...
287
+ i18nPath: "./src/i18n",
288
+ i18nPrimaryLng: "en", // Source language for AI translations
289
+ });
290
+ ```
291
+
292
+ ### HMR Support
293
+
294
+ - Translation files are watched for changes
295
+ - Changes are synced to the dev app in real-time
296
+ - No need to restart the dev server
297
+
298
+ ## Zod Re-export
299
+
300
+ The kit re-exports Zod for convenience:
301
+
302
+ ```typescript
303
+ import { z } from "@kokimoki/kit";
304
+
305
+ const mySchema = z.object({
306
+ name: z.string(),
307
+ count: z.number(),
308
+ });
309
+ ```
310
+
311
+ ## Project Files
312
+
313
+ ### .kokimoki Directory
314
+
315
+ The plugin creates a `.kokimoki` directory in your project root:
316
+
317
+ ```
318
+ .kokimoki/
319
+ ├── app-id # Dev app ID (cached)
320
+ └── stores-hash # Hash of store schemas (for change detection)
321
+ ```
322
+
323
+ **Add to `.gitignore`:**
324
+
325
+ ```gitignore
326
+ .kokimoki/
327
+ ```
328
+
329
+ ### Credentials
330
+
331
+ Global credentials are stored in `~/.kokimoki`:
332
+
333
+ ```json
334
+ {
335
+ "apiKeys": {
336
+ "org-id-1": "api-key-1",
337
+ "org-id-2": "api-key-2"
338
+ }
339
+ }
340
+ ```
341
+
342
+ Use `npx @kokimoki/cli login` to authenticate.
343
+
344
+ ## Style Preprocessing
345
+
346
+ The plugin processes CSS files with theme color variables:
347
+
348
+ - Converts color names to hex values
349
+ - Generates RGB tuple variables for opacity support
350
+ - Processes palette color scales (50-900)
351
+
352
+ ### Supported Variables
353
+
354
+ ```css
355
+ :root {
356
+ --color-primary-500: #3b82f6;
357
+ --color-secondary-500: #10b981;
358
+ --on-primary: 255 255 255;
359
+ --on-secondary: 255 255 255;
360
+ }
361
+ ```
362
+
363
+ ## Production Build
364
+
365
+ During production builds, the plugin:
366
+
367
+ 1. Validates all store schemas
368
+ 2. Generates production loading screen
369
+ 3. Embeds i18n metadata for runtime loading
370
+ 4. Removes dev frame and development overlays
371
+
372
+ ## Error Handling
373
+
374
+ ### Common Errors
375
+
376
+ | Error | Cause | Solution |
377
+ | --------------------- | ------------------ | -------------------------------- |
378
+ | `CONCEPT_NOT_FOUND` | Invalid concept ID | Check your `conceptId` in config |
379
+ | `NO_CREDENTIALS` | Not logged in | Run `npx @kokimoki/cli login` |
380
+ | `DEV_APP_INIT_FAILED` | API error | Check network and API endpoint |
381
+
382
+ ### Store Schema Changes
383
+
384
+ If you change store schemas, the plugin detects this and shows a warning page with two options:
385
+
386
+ - **Keep Current State**: Dismiss the warning and continue with existing data
387
+ - **Reset State**: Clear the dev app state and localStorage to start fresh
388
+
389
+ No dev server restart is required.
package/llms.txt ADDED
@@ -0,0 +1,46 @@
1
+ # Kokimoki Kit Documentation
2
+
3
+ > Documentation for @kokimoki/kit - Vite plugin and development tools for Kokimoki apps.
4
+
5
+ ## Instruction Files
6
+
7
+ The following instruction files provide detailed guidance for AI assistants:
8
+
9
+ ### Plugin Configuration
10
+ - docs/kokimoki-kit.instructions.md: Complete guide to configuring the Vite plugin, including dev frame setup, store schemas, i18n integration, and style preprocessing.
11
+
12
+ ## Key Concepts
13
+
14
+ - **kokimokiKitPlugin**: Vite plugin that integrates Kokimoki into your build
15
+ - **conceptId**: Unique identifier for your Kokimoki project/concept
16
+ - **deployCodes**: Named configurations for different deployment scenarios
17
+ - **devView**: Multi-window grid layout for development testing
18
+ - **stores**: Schema definitions for validating store state
19
+ - **i18nPath**: Folder path for translation files with auto-sync
20
+
21
+ ## Configuration Structure
22
+
23
+ ```typescript
24
+ kokimokiKitPlugin({
25
+ conceptId: string, // Required
26
+ deployCodes: DeployCode[], // Required
27
+ schema?: ZodType, // Project config schema
28
+ stores?: StoreConfig[], // Store schemas
29
+ i18nPath?: string, // i18n folder path
30
+ i18nPrimaryLng?: string, // Source language (default: 'en')
31
+ devView?: DevFrameCell[][] | false, // Dev frame layout
32
+ endpoint?: string, // API endpoint
33
+ host?: string, // WebSocket host
34
+ })
35
+ ```
36
+
37
+ ## Related Packages
38
+
39
+ - @kokimoki/app: Core SDK for runtime (stores, transactions, AI, storage, i18n, leaderboard)
40
+ - @kokimoki/cli: CLI for project creation, login, and deployment
41
+
42
+ ## File Patterns
43
+
44
+ Instruction files use YAML frontmatter with:
45
+ - `description`: Brief description of the file's purpose
46
+ - `applyTo`: Glob pattern for when the instructions apply (e.g., "**/vite.config.{ts,js}")
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@kokimoki/kit",
3
- "version": "1.6.7",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "docs",
10
+ "llms.txt"
9
11
  ],
10
12
  "scripts": {
11
13
  "test": "ts-mocha src/**/*.spec.ts --exit",
@@ -24,10 +26,16 @@
24
26
  "bson-objectid": "^2.0.4",
25
27
  "colorjs.io": "^0.5.2",
26
28
  "colornames": "^1.1.1",
29
+ "node-html-parser": "^7.0.1",
27
30
  "yaml": "^2.7.0",
28
- "zod": "^3.25.30"
31
+ "zod": "^4.3.5"
29
32
  },
30
33
  "peerDependencies": {
31
34
  "vite": ">=4 <=6"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "vite": {
38
+ "optional": true
39
+ }
32
40
  }
33
41
  }