@pikku/skills 0.12.22 → 0.12.25

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 (101) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/dist/skills.gen.js +1 -1
  3. package/package.json +1 -1
  4. package/skills/pikku-addon/SKILL.md +2 -2
  5. package/skills/pikku-agent/SKILL.md +67 -316
  6. package/skills/pikku-agent/references/agents.md +299 -0
  7. package/skills/{pikku-ai-vercel/SKILL.md → pikku-agent/references/runner-vercel.md} +2 -24
  8. package/skills/{pikku-ai-voice/SKILL.md → pikku-agent/references/voice.md} +1 -22
  9. package/skills/pikku-architect/SKILL.md +264 -0
  10. package/skills/pikku-auth/SKILL.md +89 -0
  11. package/skills/{pikku-better-auth/SKILL.md → pikku-auth/references/better-auth.md} +1 -27
  12. package/skills/{pikku-jose/SKILL.md → pikku-auth/references/jose.md} +1 -23
  13. package/skills/{pikku-machine-auth/SKILL.md → pikku-auth/references/machine-auth.md} +0 -23
  14. package/skills/{pikku-permissions/SKILL.md → pikku-auth/references/permissions.md} +1 -20
  15. package/skills/{pikku-security/SKILL.md → pikku-auth/references/sessions.md} +0 -20
  16. package/skills/pikku-build/SKILL.md +87 -0
  17. package/skills/{pikku-build-app/SKILL.md → pikku-build/references/app.md} +75 -23
  18. package/skills/{pikku-feature/SKILL.md → pikku-build/references/feature.md} +1 -8
  19. package/skills/{pikku-build-app → pikku-build}/references/multi-app.md +1 -1
  20. package/skills/{pikku-build-platform/SKILL.md → pikku-build/references/platform.md} +22 -37
  21. package/skills/{pikku-template-clone/SKILL.md → pikku-build/references/post-clone.md} +0 -6
  22. package/skills/{pikku-build-quick/SKILL.md → pikku-build/references/quick.md} +4 -20
  23. package/skills/{pikku-build-app → pikku-build}/references/ship.md +7 -1
  24. package/skills/pikku-concepts/SKILL.md +72 -7
  25. package/skills/pikku-concepts/references/concept-mapping.md +8 -8
  26. package/skills/pikku-deploy/SKILL.md +158 -0
  27. package/skills/{pikku-deploy-azure/SKILL.md → pikku-deploy/references/azure.md} +18 -50
  28. package/skills/pikku-deploy/references/cloudflare.md +104 -0
  29. package/skills/pikku-deploy/references/express.md +92 -0
  30. package/skills/{pikku-deploy-fastify/SKILL.md → pikku-deploy/references/fastify.md} +8 -32
  31. package/skills/{pikku-deploy-lambda/SKILL.md → pikku-deploy/references/lambda.md} +6 -27
  32. package/skills/{pikku-deploy-nextjs/SKILL.md → pikku-deploy/references/nextjs.md} +9 -33
  33. package/skills/pikku-deploy/references/uws.md +72 -0
  34. package/skills/pikku-deploy/references/ws.md +75 -0
  35. package/skills/pikku-emails/SKILL.md +3 -2
  36. package/skills/pikku-fabric/SKILL.md +12 -2
  37. package/skills/{pikku-fabric-debug/SKILL.md → pikku-fabric/references/debugging.md} +0 -6
  38. package/skills/pikku-i18n/SKILL.md +60 -207
  39. package/skills/{pikku-paraglide/SKILL.md → pikku-i18n/references/enum-labels.md} +0 -6
  40. package/skills/pikku-i18n/references/messages.md +218 -0
  41. package/skills/{pikku-rtl/SKILL.md → pikku-i18n/references/rtl.md} +3 -9
  42. package/skills/pikku-knowledge/SKILL.md +14 -0
  43. package/skills/pikku-kysely/SKILL.md +13 -13
  44. package/skills/pikku-meta/SKILL.md +58 -130
  45. package/skills/{pikku-deps/SKILL.md → pikku-meta/references/audit.md} +1 -17
  46. package/skills/pikku-meta/references/meta.md +114 -0
  47. package/skills/{pikku-versioning/SKILL.md → pikku-meta/references/versioning.md} +0 -26
  48. package/skills/pikku-middleware/SKILL.md +5 -5
  49. package/skills/pikku-n8n-import/SKILL.md +0 -1
  50. package/skills/pikku-react/SKILL.md +50 -298
  51. package/skills/pikku-react/references/client.md +293 -0
  52. package/skills/{pikku-react-query/SKILL.md → pikku-react/references/react-query.md} +2 -22
  53. package/skills/{pikku-workflows-client/SKILL.md → pikku-react/references/workflows.md} +1 -22
  54. package/skills/pikku-scenario/SKILL.md +60 -45
  55. package/skills/pikku-scenario/references/persona-run.md +148 -0
  56. package/skills/pikku-service-backends/SKILL.md +154 -0
  57. package/skills/pikku-service-backends/references/aws.md +106 -0
  58. package/skills/pikku-service-backends/references/backblaze.md +57 -0
  59. package/skills/pikku-service-backends/references/mongodb.md +90 -0
  60. package/skills/pikku-service-backends/references/redis.md +75 -0
  61. package/skills/pikku-service-backends/references/schema.md +63 -0
  62. package/skills/pikku-services/SKILL.md +68 -291
  63. package/skills/{pikku-audit/SKILL.md → pikku-services/references/audit.md} +0 -22
  64. package/skills/{pikku-config/SKILL.md → pikku-services/references/config.md} +1 -25
  65. package/skills/{pikku-pino/SKILL.md → pikku-services/references/pino.md} +0 -20
  66. package/skills/pikku-services/references/services.md +272 -0
  67. package/skills/pikku-software-archaeology/README.md +5 -1
  68. package/skills/pikku-software-archaeology/SKILL.md +15 -2
  69. package/skills/{pikku-product-second-opinion/example/sample-report.md → pikku-software-archaeology/example/second-opinion-sample-report.md} +1 -1
  70. package/skills/pikku-software-archaeology/references/blueprint.schema.json +1 -1
  71. package/skills/pikku-software-archaeology/references/pikku-mapping.md +3 -3
  72. package/skills/{pikku-product-second-opinion/SKILL.md → pikku-software-archaeology/references/second-opinion.md} +4 -9
  73. package/skills/pikku-webhook/SKILL.md +199 -0
  74. package/skills/pikku-wiring/SKILL.md +180 -0
  75. package/skills/{pikku-websocket/SKILL.md → pikku-wiring/references/channel.md} +2 -35
  76. package/skills/{pikku-cli/SKILL.md → pikku-wiring/references/cli.md} +1 -33
  77. package/skills/{pikku-gateway-slack/SKILL.md → pikku-wiring/references/gateway-slack.md} +0 -23
  78. package/skills/{pikku-http/SKILL.md → pikku-wiring/references/http.md} +3 -39
  79. package/skills/{pikku-mcp/SKILL.md → pikku-wiring/references/mcp.md} +0 -33
  80. package/skills/{pikku-queue/SKILL.md → pikku-wiring/references/queue.md} +1 -33
  81. package/skills/{pikku-realtime/SKILL.md → pikku-wiring/references/realtime.md} +2 -25
  82. package/skills/{pikku-rpc/SKILL.md → pikku-wiring/references/rpc.md} +0 -32
  83. package/skills/{pikku-schedule/SKILL.md → pikku-wiring/references/scheduler.md} +1 -35
  84. package/skills/{pikku-trigger/SKILL.md → pikku-wiring/references/trigger.md} +0 -43
  85. package/skills/pikku-workflow/SKILL.md +2 -2
  86. package/skills/pikku-aws/SKILL.md +0 -161
  87. package/skills/pikku-backblaze/SKILL.md +0 -104
  88. package/skills/pikku-deploy-cloudflare/SKILL.md +0 -123
  89. package/skills/pikku-deploy-express/SKILL.md +0 -122
  90. package/skills/pikku-deploy-uws/SKILL.md +0 -144
  91. package/skills/pikku-mongodb/SKILL.md +0 -113
  92. package/skills/pikku-product-second-opinion/README.md +0 -43
  93. package/skills/pikku-redis/SKILL.md +0 -99
  94. package/skills/pikku-schema-ajv/SKILL.md +0 -83
  95. package/skills/pikku-schema-cfworker/SKILL.md +0 -82
  96. package/skills/pikku-ws/SKILL.md +0 -87
  97. /package/skills/{pikku-build-app → pikku-build}/references/theming.md +0 -0
  98. /package/skills/{pikku-product-second-opinion/references/report-template.md → pikku-software-archaeology/references/second-opinion-report-template.md} +0 -0
  99. /package/skills/{pikku-cli/references/complete-example.md → pikku-wiring/references/cli-complete-example.md} +0 -0
  100. /package/skills/{pikku-http → pikku-wiring}/references/http-options.md +0 -0
  101. /package/skills/{pikku-realtime/references/other-routes.md → pikku-wiring/references/realtime-other-routes.md} +0 -0
@@ -1,113 +0,0 @@
1
- ---
2
- name: pikku-mongodb
3
- description: >-
4
- Use when setting up MongoDB database services in a Pikku app. Covers PikkuMongoDB connection,
5
- channel stores, workflow services, secret services, AI storage, agent runs, and deployment
6
- services. TRIGGER when: code uses PikkuMongoDB, MongoDBChannelStore, MongoDBWorkflowService,
7
- MongoDBSecretService, or user asks about MongoDB setup with Pikku. DO NOT TRIGGER when: user
8
- asks about SQL databases (use pikku-kysely) or Redis (use pikku-redis).
9
- ---
10
-
11
- # Pikku MongoDB
12
-
13
- ## Agent Operating Procedure
14
-
15
- Use this skill as an execution checklist, not reference material.
16
-
17
- 1. Discover before editing. Run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
18
- 2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
19
- 3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
20
- 4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
21
- 5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
22
-
23
- `@pikku/mongodb` provides MongoDB-backed implementations of Pikku's core service interfaces.
24
-
25
- ## Installation
26
-
27
- ```bash
28
- yarn add @pikku/mongodb
29
- ```
30
-
31
- ## API Reference
32
-
33
- ### `PikkuMongoDB` (Connection Wrapper)
34
-
35
- ```typescript
36
- import { PikkuMongoDB } from '@pikku/mongodb'
37
-
38
- const mongo = new PikkuMongoDB(
39
- logger: Logger,
40
- clientOrUri: MongoClient | string,
41
- dbName: string,
42
- options?: MongoClientOptions
43
- )
44
-
45
- await mongo.init()
46
- mongo.db // Db instance for queries
47
- await mongo.close()
48
- ```
49
-
50
- ### Available Services
51
-
52
- | Service | Interface | Purpose |
53
- | ---------------------------- | ------------------------------------------- | ---------------------------------------------- |
54
- | `MongoDBChannelStore` | `ChannelStore` | WebSocket channel state persistence |
55
- | `MongoDBEventHubStore` | `EventHubStore` | Event hub state persistence |
56
- | `MongoDBWorkflowService` | `PikkuWorkflowService` | Workflow definition storage |
57
- | `MongoDBWorkflowRunService` | `WorkflowRunService` | Workflow execution tracking |
58
- | `MongoDBDeploymentService` | `DeploymentService` | Deployment state management |
59
- | `MongoDBAgentStorageService` | `AgentStorageService, AgentRunStateService` | AI conversation/run storage |
60
- | `MongoDBAgentRunService` | `AgentRunService` | Agent execution tracking |
61
- | `MongoDBSecretService` | `SecretService` | Encrypted secret storage (envelope encryption) |
62
- | `MongoDBSessionStore` | `SessionStore` | Persisted user sessions |
63
-
64
- All services take a `Db` instance in their constructor and have an `init()` method that creates collections/indexes.
65
-
66
- ### Secret Service
67
-
68
- Envelope encryption: `key` derives the KEK that wraps each secret's own DEK.
69
- Keeping `previousKey` set is what makes `rotateKEK()` possible — it re-wraps
70
- every secret onto the current key and returns the new version.
71
-
72
- ```typescript
73
- import { MongoDBSecretService } from '@pikku/mongodb'
74
-
75
- const secrets = new MongoDBSecretService(mongo.db, {
76
- key: 'your-key-encryption-passphrase',
77
- keyVersion: 2, // defaults to 1
78
- previousKey: 'the-passphrase-you-are-rotating-away-from',
79
- audit: true, // log write/delete/rotate through the audit sink
80
- auditReads: false, // reads too — noisy, off by default
81
- })
82
- await secrets.init()
83
-
84
- await secrets.setSecret('api-key', { key: 'sk-...' })
85
- const value = await secrets.getSecret<{ key: string }>('api-key')
86
- await secrets.rotateKEK()
87
- ```
88
-
89
- ## Usage Patterns
90
-
91
- ### Full Setup
92
-
93
- ```typescript
94
- import {
95
- PikkuMongoDB,
96
- MongoDBChannelStore,
97
- MongoDBWorkflowService,
98
- } from '@pikku/mongodb'
99
-
100
- const createSingletonServices = pikkuServices(async (config) => {
101
- const logger = new PinoLogger()
102
- const mongo = new PikkuMongoDB(logger, config.mongoUri, 'myapp')
103
- await mongo.init()
104
-
105
- const channelStore = new MongoDBChannelStore(mongo.db)
106
- await channelStore.init()
107
-
108
- const workflowService = new MongoDBWorkflowService(mongo.db)
109
- await workflowService.init()
110
-
111
- return { config, logger, database: mongo, channelStore, workflowService }
112
- })
113
- ```
@@ -1,43 +0,0 @@
1
- # pikku-product-second-opinion
2
-
3
- Turns a `pikku-software-archaeology` blueprint into a **plain-language report for a
4
- non-technical owner** — a founder/PM stuck with an app they didn't build.
5
- Explains how it works and how it could be better, in business terms.
6
-
7
- ```
8
- Existing repo → pikku-software-archaeology → .knowledge/ blueprint → pikku-product-second-opinion → founder report
9
- (facts) (extract) (machine-readable) (translate + advise) (markdown + web page)
10
- ```
11
-
12
- ## The split from pikku-software-archaeology
13
-
14
- - **pikku-software-archaeology** extracts _facts_ into `.knowledge/` for a machine (Pikku) to rebuild from. Engineer/generator audience.
15
- - **pikku-product-second-opinion** reads that blueprint and writes an _opinionated report_ for a human to decide from. Non-technical audience.
16
-
17
- One extracts; one advises. This skill consumes the other's output — it doesn't re-read the code.
18
-
19
- ## What the report is calibrated to (locked by the author)
20
-
21
- - **Layered depth** — a one-page executive summary, then a section per major area for anyone who wants detail.
22
- - **Direct but fair tone** — names problems plainly, always with why-it-matters and credit for what's good.
23
- - **Both formats** — a markdown copy in the repo plus a clean, shareable web page (rendered via the `artifact-design` skill).
24
-
25
- ## The rules that make it work
26
-
27
- 1. **Translate, don't dump.** Every technical concept becomes a business outcome or a plain description. The jargon→plain table is in `SKILL.md`.
28
- 2. **Every problem carries impact + severity + effort.** A problem with no "what it means for you" doesn't ship.
29
- 3. **Always credit what works.** All-criticism reports get dismissed.
30
- 4. **Argue improvements in business outcomes** (more reliable / faster / cheaper / safer / easier to hand off), and say whether each is a cheap **rewire** or an expensive **rebuild** — never recommend a rewrite just because the code is messy.
31
- 5. **Mark confidence.** Certain and "I'd need to check" are different sentences.
32
- 6. **Cover the frontend and the other ways the app is used** when the blueprint has them — walk the screens as a journey, call out consistency, and flag the custom-logic pieces (charts/tables/editors) as the real work vs the cheap standard pieces. Name the ways the product can be driven (people/web, developers/API+SDK, AI agents/MCP, power users/CLI) — often a genuine strength.
33
- 7. **Give honest technology tradeoffs — both sides.** Every stack bet (framework, auth, hosting, key libraries) gets what-it-buys AND what-it-costs in business terms, tied to the founder's stage/goals. Don't cheerlead, don't trash, and **don't soften the disadvantages**. The app's own bets are derived from the blueprint (`architecture.json`/`integrations.json`/`frontend.json` + the repo's manifest) — never from a list in the skill, because a verdict you could write before reading the blueprint isn't a second opinion. Separately, and only when a rebuild is actually being recommended, the target stack (Pikku, Better Auth, TanStack Start) gets the _same_ both-sides treatment with cons first-class — pinning someone's dependency for being pre-1.0 while staying quiet about the replacement being pre-1.0 too is a pitch, not an opinion.
34
-
35
- ## Files
36
-
37
- ```
38
- pikku-product-second-opinion/
39
- ├── SKILL.md # method + voice rules + red flags
40
- ├── README.md # this file
41
- ├── references/report-template.md # the layered structure to fill in
42
- └── example/sample-report.md # worked example (competitor-tracking area, founder voice)
43
- ```
@@ -1,99 +0,0 @@
1
- ---
2
- name: pikku-redis
3
- description: >-
4
- Use when setting up Redis-backed services in a Pikku app. Covers channel stores, workflow
5
- services, secret services, event hubs, agent runs, and deployment services backed by Redis.
6
- TRIGGER when: code uses RedisChannelStore, RedisWorkflowService, RedisSecretService, or user
7
- asks about Redis setup with Pikku. DO NOT TRIGGER when: user asks about BullMQ queues (use
8
- pikku-queue) or SQL databases (use pikku-kysely).
9
- ---
10
-
11
- # Pikku Redis
12
-
13
- ## Agent Operating Procedure
14
-
15
- Use this skill as an execution checklist, not reference material.
16
-
17
- 1. Discover before editing. Run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
18
- 2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
19
- 3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
20
- 4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
21
- 5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
22
-
23
- `@pikku/redis` provides Redis-backed implementations of Pikku's core service interfaces using [ioredis](https://github.com/redis/ioredis).
24
-
25
- ## Installation
26
-
27
- ```bash
28
- yarn add @pikku/redis
29
- ```
30
-
31
- ## API Reference
32
-
33
- ### Available Services
34
-
35
- All services accept a Redis connection (ioredis `Redis` instance, `RedisOptions`, or connection string) in their constructor.
36
-
37
- | Service | Interface | Purpose |
38
- | ------------------------- | ---------------------- | ---------------------------------------------- |
39
- | `RedisChannelStore` | `ChannelStore` | WebSocket channel state persistence |
40
- | `RedisEventHubStore` | `EventHubStore` | Event hub state persistence |
41
- | `RedisWorkflowService` | `PikkuWorkflowService` | Workflow definition storage |
42
- | `RedisWorkflowRunService` | `WorkflowRunService` | Workflow execution tracking |
43
- | `RedisDeploymentService` | `DeploymentService` | Deployment state management |
44
- | `RedisAgentRunService` | `AgentRunService` | Agent execution tracking |
45
- | `RedisSecretService` | `SecretService` | Encrypted secret storage (envelope encryption) |
46
- | `RedisSessionStore` | `SessionStore` | Persisted user sessions |
47
-
48
- ### Secret Service
49
-
50
- Envelope encryption: `key` derives the KEK that wraps each secret's own DEK.
51
- Keeping `previousKey` set is what makes `rotateKEK()` possible — it re-wraps
52
- every secret onto the current key and returns the new version.
53
-
54
- ```typescript
55
- import { RedisSecretService } from '@pikku/redis'
56
-
57
- const secrets = new RedisSecretService(
58
- connectionOrConfig: Redis | RedisOptions | string,
59
- config: {
60
- key: string // the KEK passphrase
61
- keyVersion?: number // defaults to 1
62
- previousKey?: string // required to rotate
63
- keyPrefix?: string // namespaces the redis keys
64
- }
65
- )
66
-
67
- await secrets.getSecret<T = string>(key: string): Promise<T>
68
- await secrets.getSecrets<T>(keys: (keyof T & string)[]): Promise<Partial<T>>
69
- await secrets.hasSecret(key: string): Promise<boolean>
70
- await secrets.setSecret(key: string, value: unknown): Promise<void>
71
- await secrets.deleteSecret(key: string): Promise<void>
72
- await secrets.rotateKEK(): Promise<number>
73
- await secrets.close(): Promise<void>
74
- ```
75
-
76
- ## Usage Patterns
77
-
78
- ### Full Setup
79
-
80
- ```typescript
81
- import {
82
- RedisChannelStore,
83
- RedisWorkflowService,
84
- RedisSecretService,
85
- } from '@pikku/redis'
86
-
87
- const createSingletonServices = pikkuServices(async (config) => {
88
- const logger = new PinoLogger()
89
-
90
- const channelStore = new RedisChannelStore(config.redisUrl)
91
- const workflowService = new RedisWorkflowService(config.redisUrl)
92
-
93
- const secrets = new RedisSecretService(config.redisUrl, {
94
- key: config.kekPassphrase,
95
- })
96
-
97
- return { config, logger, channelStore, workflowService, secrets }
98
- })
99
- ```
@@ -1,83 +0,0 @@
1
- ---
2
- name: pikku-schema-ajv
3
- description: >-
4
- Use when setting up JSON schema validation with AJV in a Pikku app. Covers AjvSchemaService for
5
- request/response validation. TRIGGER when: code uses AjvSchemaService, user asks about AJV, JSON
6
- schema validation, or @pikku/schema-ajv. DO NOT TRIGGER when: user asks about Cloudflare Workers
7
- schema validation (use pikku-schema-cfworker).
8
- ---
9
-
10
- # Pikku Schema AJV (JSON Schema Validation)
11
-
12
- ## Agent Operating Procedure
13
-
14
- Use this skill as an execution checklist, not reference material.
15
-
16
- 1. Discover before editing. Run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
17
- 2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
18
- 3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
19
- 4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
20
- 5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
21
-
22
- `@pikku/schema-ajv` provides JSON schema validation using [AJV](https://ajv.js.org/). Implements the `SchemaService` interface from `@pikku/core`. This is the default schema validator for Node.js environments.
23
-
24
- ## Installation
25
-
26
- ```bash
27
- yarn add @pikku/schema-ajv
28
- ```
29
-
30
- ## API Reference
31
-
32
- ### `AjvSchemaService`
33
-
34
- ```typescript
35
- import { AjvSchemaService } from '@pikku/schema-ajv'
36
-
37
- const schema = new AjvSchemaService(logger: Logger)
38
- ```
39
-
40
- **Methods:**
41
-
42
- - `compileSchema(name: string, schema: any): void` — Compile and register a JSON schema under `name`
43
- - `validateSchema(schemaName: string, json: any): void` — Validate data against a compiled schema (throws on failure)
44
- - `getSchemaNames(): Set<string>` — Get all registered schema names
45
- - `getSchemaKeys(schemaName: string): string[]` — Top-level property keys, or `[]` if the schema has no `properties`
46
-
47
- The first argument is the **name**, the second the schema — the parameter is
48
- called `schema` in the source, which reads backwards.
49
-
50
- ### Behaviour that matters
51
-
52
- - **Registration is name-keyed and never re-compiles.** A second
53
- `compileSchema('X', …)` with a different schema is a no-op; the first one wins
54
- for the process lifetime. `@pikku/schema-cfworker` _does_ recompile on a
55
- changed value, so a dev hot-reload after codegen picks up a changed schema
56
- there but not here — restart the process instead.
57
- - **AJV is a module-level singleton**, shared by every `AjvSchemaService` you
58
- construct, so compiled schema names are global to the process.
59
- - **`useDefaults: true` mutates the validated object**, filling in schema
60
- defaults in place. `coerceTypes: false`, so a query-string `"1"` will not
61
- become `1` — the wiring layer is what coerces, not this service.
62
- - `ajv-formats` is registered, so `format` keywords (`email`, `uuid`, `date-time`)
63
- are enforced.
64
- - A failed validation throws `UnprocessableContentError` (a 422). A _missing_
65
- schema throws a bare string, `Missing validator for <name>` — not an `Error`,
66
- so `catch (e) { e.message }` reads `undefined`. That normally means codegen
67
- didn't run.
68
-
69
- ## Usage Patterns
70
-
71
- ### With Pikku Services
72
-
73
- ```typescript
74
- import { AjvSchemaService } from '@pikku/schema-ajv'
75
-
76
- const createSingletonServices = pikkuServices(async (config) => {
77
- const logger = new ConsoleLogger()
78
- const schema = new AjvSchemaService(logger)
79
- return { config, logger, schema }
80
- })
81
- ```
82
-
83
- Pikku automatically uses the schema service to validate function inputs and outputs when schemas are defined in your function definitions.
@@ -1,82 +0,0 @@
1
- ---
2
- name: pikku-schema-cfworker
3
- description: >-
4
- Use when setting up JSON schema validation for Cloudflare Workers in a Pikku app. Covers
5
- CFWorkerSchemaService as a lightweight alternative to AJV. TRIGGER when: code uses
6
- CFWorkerSchemaService, user asks about schema validation on Cloudflare Workers, or
7
- @pikku/schema-cfworker. DO NOT TRIGGER when: user asks about AJV schema validation (use
8
- pikku-schema-ajv).
9
- ---
10
-
11
- # Pikku Schema CFWorker (Cloudflare Workers Validation)
12
-
13
- ## Agent Operating Procedure
14
-
15
- Use this skill as an execution checklist, not reference material.
16
-
17
- 1. Discover before editing. Run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
18
- 2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
19
- 3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
20
- 4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
21
- 5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
22
-
23
- `@pikku/schema-cfworker` provides JSON schema validation using [@cfworker/json-schema](https://github.com/cfworker/cfworker), a lightweight validator compatible with Cloudflare Workers (no `eval` or `new Function`). Implements the `SchemaService` interface from `@pikku/core`.
24
-
25
- ## Installation
26
-
27
- ```bash
28
- yarn add @pikku/schema-cfworker
29
- ```
30
-
31
- ## API Reference
32
-
33
- ### `CFWorkerSchemaService`
34
-
35
- ```typescript
36
- import { CFWorkerSchemaService } from '@pikku/schema-cfworker'
37
-
38
- const schema = new CFWorkerSchemaService(logger: Logger)
39
- ```
40
-
41
- **Methods:**
42
-
43
- - `compileSchema(name: string, schema: any): void` — Compile and register a JSON schema under `name`
44
- - `validateSchema(schemaName: string, json: any): void` — Validate data against a compiled schema (throws on failure)
45
- - `getSchemaNames(): Set<string>` — Get all registered schema names
46
- - `getSchemaKeys(schemaName: string): string[]` — Top-level property keys, or `[]` if the schema has no `properties`
47
-
48
- ### Where it differs from AJV
49
-
50
- These two are not drop-in equivalents, and the differences are the kind that
51
- surface as behaviour changes rather than compile errors:
52
-
53
- - **No `useDefaults`.** AJV fills schema defaults into the validated object in
54
- place; this validator does not. A field you relied on being defaulted arrives
55
- `undefined` on Workers.
56
- - **It re-compiles when the schema value changes.** AJV caches by name forever;
57
- here a `compileSchema` with a different value for the same name replaces the
58
- validator, which is what lets a dev hot-reload pick up regenerated schemas.
59
- - **Each validator gets a deep clone of the schema** (`@cfworker/json-schema`
60
- mutates what it is given, which throws on a frozen generated object).
61
- - A compile failure throws `Error('Failed to compile schema: <name>')` with the
62
- underlying cause swallowed — check the schema by hand when you see it.
63
-
64
- A failed validation throws `UnprocessableContentError` (422) with the validator
65
- errors joined; a _missing_ schema throws a bare string, `Missing validator for
66
- <name>`, not an `Error`.
67
-
68
- ## Usage Patterns
69
-
70
- ### With Cloudflare Workers
71
-
72
- ```typescript
73
- import { CFWorkerSchemaService } from '@pikku/schema-cfworker'
74
-
75
- const createSingletonServices = pikkuServices(async (config) => {
76
- const logger = new ConsoleLogger()
77
- const schema = new CFWorkerSchemaService(logger)
78
- return { config, logger, schema }
79
- })
80
- ```
81
-
82
- Use this instead of `@pikku/schema-ajv` when deploying to Cloudflare Workers, as AJV uses `eval` which is not permitted in the Workers runtime.
@@ -1,87 +0,0 @@
1
- ---
2
- name: pikku-ws
3
- description: >-
4
- Use when setting up a WebSocket server with the ws library in a Pikku app. Covers the ws runtime
5
- adapter for Pikku channels. TRIGGER when: code uses @pikku/ws, user asks about ws library
6
- WebSocket server, or Node.js WebSocket runtime. DO NOT TRIGGER when: user asks about WebSocket
7
- wiring/channels (use pikku-websocket) or uWebSockets (use pikku-deploy-uws).
8
- installGroups: [fabric]
9
- ---
10
-
11
- # Pikku WS (WebSocket Server Runtime)
12
-
13
- ## Agent Operating Procedure
14
-
15
- Use this skill as an execution checklist, not reference material.
16
-
17
- 1. Discover before editing. Run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
18
- 2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
19
- 3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
20
- 4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
21
- 5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
22
-
23
- `@pikku/ws` provides a WebSocket server runtime using the [ws](https://github.com/websockets/ws) library, connecting Pikku's channel system to a Node.js WebSocket server.
24
-
25
- ## Installation
26
-
27
- ```bash
28
- yarn add @pikku/ws ws
29
- ```
30
-
31
- ## Usage Patterns
32
-
33
- ### Basic Setup
34
-
35
- The package exports one function, `pikkuWebsocketHandler` — there is no server
36
- class. You own the `http.Server` and the `WebSocketServer`; the handler attaches
37
- the upgrade and message plumbing to them.
38
-
39
- ```typescript
40
- import { DEFAULT_WS_MAX_PAYLOAD, pikkuWebsocketHandler } from '@pikku/ws'
41
- import { stopSingletonServices } from '@pikku/core'
42
- import { Server } from 'http'
43
- import { WebSocketServer } from 'ws'
44
-
45
- import '../.pikku/pikku-bootstrap.gen.js'
46
- import { createConfig, createSingletonServices } from './services.js'
47
-
48
- const config = await createConfig()
49
- const singletonServices = await createSingletonServices(config)
50
-
51
- const server = new Server()
52
- const wss = new WebSocketServer({
53
- noServer: true,
54
- maxPayload: DEFAULT_WS_MAX_PAYLOAD,
55
- })
56
-
57
- pikkuWebsocketHandler({
58
- server,
59
- wss,
60
- logger: singletonServices.logger,
61
- logRoutes: true, // print the wired channels at startup
62
- loadSchemas: true, // compile input schemas up front
63
- })
64
-
65
- server.listen(4002, 'localhost')
66
- ```
67
-
68
- `noServer: true` is not optional decoration — the handler performs the upgrade
69
- itself so it can run pikku's HTTP middleware chain (auth, cors) against the
70
- upgrade request before a channel exists. Letting `ws` bind the server directly
71
- would skip that.
72
-
73
- Services come from the bootstrap import and the global singleton registry, which
74
- is why nothing is passed in. The event hub is taken from
75
- `singletonServices.eventHub` when it is a `LocalEventHubService`, and a local one
76
- is created otherwise — so a single-process app gets pub/sub for free, while a
77
- multi-instance deployment must register a distributed hub (see `pikku-realtime`).
78
-
79
- The options type also extends `RunHTTPWiringOptions`, so per-request settings
80
- such as `respondWith404`, `coerceDataFromSchema` and `bubbleErrors` are accepted
81
- here too.
82
-
83
- On shutdown, call `stopSingletonServices()` then close `wss` and `server`.
84
-
85
- See `pikku-websocket` for channel wiring details, and
86
- `pikku-deploy-fastify`/`pikku-deploy-express` when the WebSocket server shares a
87
- port with an HTTP app.