safebyok-convex 0.0.0-stage → 0.0.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.
- package/.claude/skills/LICENSE-convex-agent-skills +201 -0
- package/.claude/skills/README.md +115 -0
- package/.claude/skills/convex-create-component/SKILL.md +330 -0
- package/.claude/skills/convex-create-component/references/advanced-patterns.md +152 -0
- package/.claude/skills/convex-create-component/references/packaged-components.md +61 -0
- package/.claude/skills/convex-docs/SKILL.md +31 -0
- package/.claude/skills/convex-expert/SKILL.md +42 -0
- package/.claude/skills/convex-reviewer/SKILL.md +32 -0
- package/.claude/skills/convex-test/SKILL.md +23 -0
- package/.claude/skills/convex-verify/SKILL.md +40 -0
- package/LICENSE +201 -0
- package/README.md +169 -2
- package/eslint.config.mjs +85 -0
- package/package.json +44 -3
- package/src/component/_generated/api.ts +16 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/convex.config.ts +14 -0
- package/src/component/schema.ts +20 -0
- package/src/component/validators.ts +125 -0
- package/src/component/vaults.ts +218 -0
- package/src/component-api.ts +20 -0
- package/src/convex-vault-db.ts +188 -0
- package/src/index.ts +9 -0
- package/src/refusals.ts +26 -0
- package/src/server.ts +157 -0
- package/src/test.ts +38 -0
- package/tests/component/validators.test.ts +160 -0
- package/tests/component/vaults.test.ts +351 -0
- package/tests/convex-vault-db.test.ts +332 -0
- package/tests/fake-deployment.ts +229 -0
- package/tests/helpers.ts +102 -0
- package/tests/refusals.test.ts +25 -0
- package/tests/server.test.ts +139 -0
- package/tests/test.test.ts +25 -0
- package/tsconfig.json +33 -0
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Convex agent skills for safebyok-convex
|
|
2
|
+
|
|
3
|
+
Six of Convex's official agent skills, chosen for what this package does: author a packaged
|
|
4
|
+
Convex **component**, write its **schema and validators**, its **queries and mutations**, test
|
|
5
|
+
them with **`convex-test`**, and review them. They are scoped to `packages/safebyok-convex/`:
|
|
6
|
+
Claude Code loads a nested `.claude/skills/` the first time it reads or edits a file below this
|
|
7
|
+
package (or sooner, with `/add-dir packages/safebyok-convex`), and not before.
|
|
8
|
+
|
|
9
|
+
Nothing here is executable: every file is Markdown, outside every lint, typecheck and test glob.
|
|
10
|
+
|
|
11
|
+
## Source
|
|
12
|
+
|
|
13
|
+
| | |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| Repository | [get-convex/agent-skills](https://github.com/get-convex/agent-skills), the source [docs.convex.dev/ai/agent-skills](https://docs.convex.dev/ai/agent-skills) names and `npx convex ai-files install` installs from |
|
|
16
|
+
| Commit | `191a5c33a7e7a22ec9d5ff13930f84748bbcf8f8` (2026-10-13, "Sync from convex-agents@cfccf3e"); retrieved 2026-10-14 |
|
|
17
|
+
| License | Apache-2.0, copied beside this file as `LICENSE-convex-agent-skills` |
|
|
18
|
+
|
|
19
|
+
Copied by hand from a clone, not by `npx skills add` or `npx convex ai-files install`: both run
|
|
20
|
+
code fetched at install time, and the latter also writes into a `convex/` directory and the
|
|
21
|
+
repo's `CLAUDE.md`. To update, clone the repository at a newer commit, diff each kept file
|
|
22
|
+
against it, and carry the local changes below across.
|
|
23
|
+
|
|
24
|
+
## What is here, and what to read it for
|
|
25
|
+
|
|
26
|
+
| Skill | Files | Read it for |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `convex-create-component` | `SKILL.md`, `references/packaged-components.md`, `references/advanced-patterns.md` | Authoring the component: `defineComponent`, component-owned tables, the boundary rules (no `ctx.auth` or `process.env` inside, host IDs as strings, the host's re-export wrappers), package exports and build order, class-based wrappers like `.api({ getUserId })` |
|
|
29
|
+
| `convex-expert` | `SKILL.md` | Schema, validators and functions: object form, `args` and `returns` on everything, `v.union` of `v.literal`, indexes over `.filter`, bounded reads, the import table, `null` not `undefined` |
|
|
30
|
+
| `convex-test` | `SKILL.md` | The `convex-test` recipe: `convexTest(schema)`, `t.run`, `t.query` and `t.mutation` |
|
|
31
|
+
| `convex-verify` | `SKILL.md` | The `edge-runtime` vitest configuration `convex-test` needs, and proving refusals: the wrong user, no user, data scoped to its owner |
|
|
32
|
+
| `convex-reviewer` | `SKILL.md` | A review pass over component functions: auth on every function, indexes, validators |
|
|
33
|
+
| `convex-docs` | `SKILL.md` | Pinning the installed `convex` version and checking its `.d.ts` before trusting memory or a doc page |
|
|
34
|
+
|
|
35
|
+
Not covered by any Convex skill, so read the sources instead:
|
|
36
|
+
|
|
37
|
+
* **The client** (`ConvexClient`, `ConvexReactClient`, `onUpdate`, `watchQuery`):
|
|
38
|
+
[JavaScript clients](https://docs.convex.dev/client/javascript/overview.md),
|
|
39
|
+
[ConvexClient](https://docs.convex.dev/api/classes/browser.ConvexClient.md),
|
|
40
|
+
[ConvexReactClient](https://docs.convex.dev/api/classes/react.ConvexReactClient.md), and the
|
|
41
|
+
installed types, `node_modules/convex/dist/esm-types/browser/simple_client.d.ts` and
|
|
42
|
+
`.../react/client.d.ts`.
|
|
43
|
+
* **`ConvexError` and its `data`**: [Application Errors](https://docs.convex.dev/functions/error-handling/application-errors.md)
|
|
44
|
+
and `node_modules/convex/dist/esm-types/values/errors.d.ts`.
|
|
45
|
+
* **Transactions and serializability**: [OCC and Atomicity](https://docs.convex.dev/database/advanced/occ.md).
|
|
46
|
+
* **Components and testing them**: [Authoring Components](https://docs.convex.dev/components/authoring.md),
|
|
47
|
+
[convex-test](https://docs.convex.dev/testing/convex-test.md), and `node_modules/convex-test/README.md`.
|
|
48
|
+
* Convex's own **guidelines** (`https://version.convex.dev/v1/guidelines`, what `ai-files`
|
|
49
|
+
installs) are dense and current, but carry no license, so they are not copied here.
|
|
50
|
+
|
|
51
|
+
## Local changes
|
|
52
|
+
|
|
53
|
+
Apache-2.0 asks that changed files say so: each changed file opens with a note pointing here.
|
|
54
|
+
|
|
55
|
+
* `convex-create-component/SKILL.md`: the shape is settled as packaged, so the "ask the user"
|
|
56
|
+
step, the local and hybrid rows and references, and the local default are gone; `npx convex
|
|
57
|
+
dev` is replaced by codegen and `pnpm justify` (validation step, checklist), with "stop and ask
|
|
58
|
+
the Coach" for a login or a deployment; `convex-helpers` is marked as needing the Coach's yes.
|
|
59
|
+
* `convex-create-component/references/advanced-patterns.md`: a handler that used `args` without
|
|
60
|
+
taking it now takes it; a note says the example's read of an app-owned table is illustration only.
|
|
61
|
+
* `convex-create-component/references/packaged-components.md`: the scaffolder (`npx
|
|
62
|
+
create-convex@latest --component`) and the build flow's `npx convex dev
|
|
63
|
+
--typecheck-components` are gone, with a note that that step is the Coach's.
|
|
64
|
+
* `convex-expert/SKILL.md`: the self-verify rule that pushed to a deployment (and could set
|
|
65
|
+
`CONVEX_AGENT_MODE=anonymous`, rebinding `.env.local`) is replaced by codegen and `pnpm
|
|
66
|
+
justify`; the step steering LLM features to `@convex-dev/agent` and `@convex-dev/workflow` is
|
|
67
|
+
gone; the `v.id` rule, the internal-by-default rule and the `convex/`-directory rule say how
|
|
68
|
+
they read inside a component.
|
|
69
|
+
* `convex-verify/SKILL.md`: the steps that emitted findings to a "bus" whose schema is not in the
|
|
70
|
+
repository, and the hand-offs to skills not installed here, are gone; a note says how
|
|
71
|
+
identities reach a component (the host's `getUserId`) and that tests follow `STYLE.md`.
|
|
72
|
+
* `convex-reviewer/SKILL.md`: a note maps its `ctx.auth` check onto this package's `getUserId`.
|
|
73
|
+
|
|
74
|
+
`convex-test/SKILL.md` and `convex-docs/SKILL.md` are unchanged.
|
|
75
|
+
|
|
76
|
+
## Left out
|
|
77
|
+
|
|
78
|
+
From `convex-create-component`: `references/local-components.md` and
|
|
79
|
+
`references/hybrid-components.md` (this is a packaged component), `agents/openai.yaml` (Codex
|
|
80
|
+
metadata), `assets/icon.svg` (an icon).
|
|
81
|
+
|
|
82
|
+
The other 27 skills at this commit:
|
|
83
|
+
|
|
84
|
+
* `convex`: a router and product pitch; it has the agent fetch and follow instructions served from a Convex site.
|
|
85
|
+
* `convex-add`: adds capabilities to an app from a remote catalog, installing as it goes.
|
|
86
|
+
* `convex-advisor`: performance findings from a live deployment's insights.
|
|
87
|
+
* `convex-agent`: AI agents and RAG.
|
|
88
|
+
* `convex-auth`: auth providers; generates keys and sets deployment env vars.
|
|
89
|
+
* `convex-authz`: rewrites an app's authorization around its users table; this package has neither.
|
|
90
|
+
* `convex-backup`: deployment backups and restores.
|
|
91
|
+
* `convex-billing`: Stripe billing over HTTP actions.
|
|
92
|
+
* `convex-cost`: spend analysis of a live deployment.
|
|
93
|
+
* `convex-crons`: scheduled jobs.
|
|
94
|
+
* `convex-deploy-guard`: deployment targeting.
|
|
95
|
+
* `convex-design`: a product pitch and app scaffolding, with the same push-to-deploy rule.
|
|
96
|
+
* `convex-domains`: DNS and custom domains.
|
|
97
|
+
* `convex-env`: deployment env vars.
|
|
98
|
+
* `convex-explain-app`: explains an existing app.
|
|
99
|
+
* `convex-improve-convex-plugin`: pipes a remote script into a shell and uploads the session transcript.
|
|
100
|
+
* `convex-insights`: logs and health of a live deployment.
|
|
101
|
+
* `convex-launch-readiness`: an aggregate of audits left out here.
|
|
102
|
+
* `convex-migrate`: app data migrations.
|
|
103
|
+
* `convex-migrate-rehearse`: production migration rehearsals.
|
|
104
|
+
* `convex-monitor`: watches a live deployment, through a tool that does not exist here.
|
|
105
|
+
* `convex-optimize`: an app audit and upgrade workflow.
|
|
106
|
+
* `convex-quickstart`: app scaffolding.
|
|
107
|
+
* `convex-seed`: seeds a deployment's data.
|
|
108
|
+
* `convex-self-heal`: production error triage into PRs.
|
|
109
|
+
* `convex-sentinel`: production error capture.
|
|
110
|
+
* `convex-suggest`: suggests `@convex-dev` components, through a detector not in the repository.
|
|
111
|
+
|
|
112
|
+
Also left out: Convex's plugins for Claude Code
|
|
113
|
+
([get-convex/convex-backend-skill](https://github.com/get-convex/convex-backend-skill)), Cursor
|
|
114
|
+
and Codex. Their skills are the same generated text, and they add session hooks that run code,
|
|
115
|
+
telemetry on by default, a remote freshness check, background log monitors and an MCP server.
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: convex-create-component
|
|
3
|
+
description:
|
|
4
|
+
Builds reusable Convex components with isolated tables and app-facing APIs.
|
|
5
|
+
Use for new components, reusable backend modules, integrations, or component
|
|
6
|
+
boundary work.
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Convex Create Component
|
|
10
|
+
|
|
11
|
+
> **Changed for safebyok-convex** from get-convex/agent-skills at `191a5c33` (Apache-2.0; the
|
|
12
|
+
> changes are listed in `../README.md`). Here the shape is settled: `safebyok-convex` is a
|
|
13
|
+
> **packaged** component (`whiteboard/20261014-convex/design.md`), whose host app authenticates
|
|
14
|
+
> through a `getUserId(ctx)` callback rather than `@convex-dev/auth`. Never run `npx convex dev`
|
|
15
|
+
> or push to a deployment; if codegen needs a Convex login or a deployment, stop and ask the
|
|
16
|
+
> Coach for that exact step.
|
|
17
|
+
|
|
18
|
+
Create reusable Convex components with clear boundaries and a small app-facing
|
|
19
|
+
API.
|
|
20
|
+
|
|
21
|
+
## When to Use
|
|
22
|
+
|
|
23
|
+
- Creating a new Convex component in an existing app
|
|
24
|
+
- Extracting reusable backend logic into a component
|
|
25
|
+
- Building a third-party integration that should own its own tables and
|
|
26
|
+
workflows
|
|
27
|
+
- Packaging Convex functionality for reuse across multiple apps
|
|
28
|
+
|
|
29
|
+
## When Not to Use
|
|
30
|
+
|
|
31
|
+
- One-off business logic that belongs in the main app
|
|
32
|
+
- Thin utilities that do not need Convex tables or functions
|
|
33
|
+
- App-level orchestration that should stay in `convex/`
|
|
34
|
+
- Cases where a normal TypeScript library is enough
|
|
35
|
+
|
|
36
|
+
## Workflow
|
|
37
|
+
|
|
38
|
+
1. Confirm what you are building against `whiteboard/20261014-convex/design.md`
|
|
39
|
+
and the sprint plan, rather than asking afresh.
|
|
40
|
+
2. Read `references/packaged-components.md`: the shape is settled (below).
|
|
41
|
+
3. Decide whether a component is justified. Prefer normal app code or a regular
|
|
42
|
+
library if the feature does not need isolated tables, backend functions, or
|
|
43
|
+
reusable persistent state.
|
|
44
|
+
4. Make a short plan for:
|
|
45
|
+
- what tables the component owns
|
|
46
|
+
- what public functions it exposes
|
|
47
|
+
- what data must be passed in from the app (auth, env vars, parent IDs)
|
|
48
|
+
- what stays in the app as wrappers or HTTP mounts
|
|
49
|
+
5. Create the component structure with `convex.config.ts`, `schema.ts`, and
|
|
50
|
+
function files.
|
|
51
|
+
6. Implement functions using the component's own `./_generated/server` imports,
|
|
52
|
+
not the app's generated files.
|
|
53
|
+
7. Wire the component into the app with `app.use(...)`. If the app does not
|
|
54
|
+
already have `convex/convex.config.ts`, create it.
|
|
55
|
+
8. Call the component from the app through `components.<name>` using
|
|
56
|
+
`ctx.runQuery`, `ctx.runMutation`, or `ctx.runAction`.
|
|
57
|
+
9. If React clients, HTTP callers, or public APIs need access, create wrapper
|
|
58
|
+
functions in the app instead of exposing component functions directly.
|
|
59
|
+
10. Run codegen (see Validation) and `pnpm justify` inside
|
|
60
|
+
`packages/safebyok-convex/`, and fix codegen, type, or boundary issues
|
|
61
|
+
before finishing.
|
|
62
|
+
|
|
63
|
+
## Choose the Shape
|
|
64
|
+
|
|
65
|
+
| Goal | Shape | Reference |
|
|
66
|
+
| ---------------------------- | -------- | ----------------------------------- |
|
|
67
|
+
| Publish or share across apps | Packaged | `references/packaged-components.md` |
|
|
68
|
+
|
|
69
|
+
This package is a packaged component. Upstream's local and hybrid references
|
|
70
|
+
were left out of this install.
|
|
71
|
+
|
|
72
|
+
## Default Approach
|
|
73
|
+
|
|
74
|
+
Upstream's default, a local component inside one app, does not apply here. The
|
|
75
|
+
skeleton below uses the local layout (`convex/components/<componentName>/`) only
|
|
76
|
+
to illustrate; the parts carry over to a package unchanged:
|
|
77
|
+
|
|
78
|
+
- Define it with `defineComponent(...)` in its own `convex.config.ts`
|
|
79
|
+
- The host installs it from its `convex/convex.config.ts` with `app.use(...)`
|
|
80
|
+
- Codegen generates the component's own `_generated/` files
|
|
81
|
+
|
|
82
|
+
## Component Skeleton
|
|
83
|
+
|
|
84
|
+
A minimal local component with a table and two functions, plus the app wiring.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// convex/components/notifications/convex.config.ts
|
|
88
|
+
import { defineComponent } from "convex/server";
|
|
89
|
+
|
|
90
|
+
export default defineComponent("notifications");
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// convex/components/notifications/schema.ts
|
|
95
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
96
|
+
import { v } from "convex/values";
|
|
97
|
+
|
|
98
|
+
export default defineSchema({
|
|
99
|
+
notifications: defineTable({
|
|
100
|
+
userId: v.string(),
|
|
101
|
+
message: v.string(),
|
|
102
|
+
read: v.boolean(),
|
|
103
|
+
}).index("by_user_read", ["userId", "read"]),
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// convex/components/notifications/lib.ts
|
|
109
|
+
import { v } from "convex/values";
|
|
110
|
+
import { mutation, query } from "./_generated/server.js";
|
|
111
|
+
|
|
112
|
+
export const send = mutation({
|
|
113
|
+
args: { userId: v.string(), message: v.string() },
|
|
114
|
+
returns: v.id("notifications"),
|
|
115
|
+
handler: async (ctx, args) => {
|
|
116
|
+
return await ctx.db.insert("notifications", {
|
|
117
|
+
userId: args.userId,
|
|
118
|
+
message: args.message,
|
|
119
|
+
read: false,
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export const listUnread = query({
|
|
125
|
+
args: { userId: v.string() },
|
|
126
|
+
returns: v.array(
|
|
127
|
+
v.object({
|
|
128
|
+
_id: v.id("notifications"),
|
|
129
|
+
_creationTime: v.number(),
|
|
130
|
+
userId: v.string(),
|
|
131
|
+
message: v.string(),
|
|
132
|
+
read: v.boolean(),
|
|
133
|
+
}),
|
|
134
|
+
),
|
|
135
|
+
handler: async (ctx, args) => {
|
|
136
|
+
return await ctx.db
|
|
137
|
+
.query("notifications")
|
|
138
|
+
.withIndex("by_user_read", (q) =>
|
|
139
|
+
q.eq("userId", args.userId).eq("read", false),
|
|
140
|
+
)
|
|
141
|
+
.collect();
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
// convex/convex.config.ts
|
|
148
|
+
import { defineApp } from "convex/server";
|
|
149
|
+
import notifications from "./components/notifications/convex.config.js";
|
|
150
|
+
|
|
151
|
+
const app = defineApp();
|
|
152
|
+
app.use(notifications);
|
|
153
|
+
|
|
154
|
+
export default app;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
// convex/notifications.ts (app-side wrapper)
|
|
159
|
+
import { v } from "convex/values";
|
|
160
|
+
import { mutation, query } from "./_generated/server";
|
|
161
|
+
import { components } from "./_generated/api";
|
|
162
|
+
import { getAuthUserId } from "@convex-dev/auth/server";
|
|
163
|
+
|
|
164
|
+
export const sendNotification = mutation({
|
|
165
|
+
args: { message: v.string() },
|
|
166
|
+
returns: v.null(),
|
|
167
|
+
handler: async (ctx, args) => {
|
|
168
|
+
const userId = await getAuthUserId(ctx);
|
|
169
|
+
if (!userId) throw new Error("Not authenticated");
|
|
170
|
+
|
|
171
|
+
await ctx.runMutation(components.notifications.lib.send, {
|
|
172
|
+
userId,
|
|
173
|
+
message: args.message,
|
|
174
|
+
});
|
|
175
|
+
return null;
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export const myUnread = query({
|
|
180
|
+
args: {},
|
|
181
|
+
handler: async (ctx) => {
|
|
182
|
+
const userId = await getAuthUserId(ctx);
|
|
183
|
+
if (!userId) throw new Error("Not authenticated");
|
|
184
|
+
|
|
185
|
+
return await ctx.runQuery(components.notifications.lib.listUnread, {
|
|
186
|
+
userId,
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Note the reference path shape: a function in
|
|
193
|
+
`convex/components/notifications/lib.ts` is called as
|
|
194
|
+
`components.notifications.lib.send` from the app.
|
|
195
|
+
|
|
196
|
+
## Critical Rules
|
|
197
|
+
|
|
198
|
+
- Keep authentication in the app, because `ctx.auth` is not available inside
|
|
199
|
+
components.
|
|
200
|
+
- Keep environment access in the app, because component functions cannot read
|
|
201
|
+
`process.env`.
|
|
202
|
+
- Pass parent app IDs across the boundary as strings, because `Id` types become
|
|
203
|
+
plain strings in the app-facing `ComponentApi`.
|
|
204
|
+
- Do not use `v.id("parentTable")` for app-owned tables inside component args or
|
|
205
|
+
schema, because the component has no access to the app's table namespace.
|
|
206
|
+
- Import `query`, `mutation`, and `action` from the component's own
|
|
207
|
+
`./_generated/server`, not the app's generated files.
|
|
208
|
+
- Do not expose component functions directly to clients. Create app wrappers
|
|
209
|
+
when client access is needed, because components are internal and need
|
|
210
|
+
auth/env wiring the app provides.
|
|
211
|
+
- If the component defines HTTP handlers, mount the routes in the app's
|
|
212
|
+
`convex/http.ts`, because components cannot register their own HTTP routes.
|
|
213
|
+
- If the component needs pagination, use `paginator` from `convex-helpers`
|
|
214
|
+
instead of built-in `.paginate()`, because `.paginate()` does not work across
|
|
215
|
+
the component boundary. (`convex-helpers` is not a dependency of this
|
|
216
|
+
package, and adding it needs the Coach's yes.)
|
|
217
|
+
- Define indexes for queried fields instead of using Convex `.filter()` after a
|
|
218
|
+
database query.
|
|
219
|
+
- Add `args` and `returns` validators to all public component functions, because
|
|
220
|
+
the component boundary requires explicit type contracts.
|
|
221
|
+
|
|
222
|
+
## Patterns
|
|
223
|
+
|
|
224
|
+
### Authentication and environment access
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
// Bad: component code cannot rely on app auth or env
|
|
228
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
229
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// Good: the app resolves auth and env, then passes explicit values
|
|
234
|
+
const userId = await getAuthUserId(ctx);
|
|
235
|
+
if (!userId) throw new Error("Not authenticated");
|
|
236
|
+
|
|
237
|
+
await ctx.runAction(components.translator.translate, {
|
|
238
|
+
userId,
|
|
239
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
240
|
+
text: args.text,
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Client-facing API
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
// Bad: assuming a component function is directly callable by clients
|
|
248
|
+
export const send = components.notifications.send;
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
// Good: re-export through an app mutation or query
|
|
253
|
+
export const sendNotification = mutation({
|
|
254
|
+
args: { message: v.string() },
|
|
255
|
+
returns: v.null(),
|
|
256
|
+
handler: async (ctx, args) => {
|
|
257
|
+
const userId = await getAuthUserId(ctx);
|
|
258
|
+
if (!userId) throw new Error("Not authenticated");
|
|
259
|
+
|
|
260
|
+
await ctx.runMutation(components.notifications.lib.send, {
|
|
261
|
+
userId,
|
|
262
|
+
message: args.message,
|
|
263
|
+
});
|
|
264
|
+
return null;
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### IDs across the boundary
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
// Bad: parent app table IDs are not valid component validators
|
|
273
|
+
args: {
|
|
274
|
+
userId: v.id("users"),
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
// Good: treat parent-owned IDs as strings at the boundary
|
|
280
|
+
args: {
|
|
281
|
+
userId: v.string(),
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Advanced Patterns
|
|
286
|
+
|
|
287
|
+
For additional patterns including function handles for callbacks, deriving
|
|
288
|
+
validators from schema, static configuration with a globals table, and
|
|
289
|
+
class-based client wrappers, see `references/advanced-patterns.md`.
|
|
290
|
+
|
|
291
|
+
## Validation
|
|
292
|
+
|
|
293
|
+
Try validation in this order:
|
|
294
|
+
|
|
295
|
+
1. `npx convex codegen --component-dir <path to the component>`
|
|
296
|
+
2. `npx convex codegen`
|
|
297
|
+
|
|
298
|
+
Never `npx convex dev` here: it provisions or pushes to a deployment.
|
|
299
|
+
|
|
300
|
+
Important:
|
|
301
|
+
|
|
302
|
+
- Fresh repos may fail these commands until `CONVEX_DEPLOYMENT` is configured.
|
|
303
|
+
- Until codegen runs, component-local `./_generated/*` imports and app-side
|
|
304
|
+
`components.<name>...` references will not typecheck.
|
|
305
|
+
- If validation blocks on Convex login or deployment setup, stop and ask the
|
|
306
|
+
user for that exact step instead of guessing.
|
|
307
|
+
|
|
308
|
+
## Reference Files
|
|
309
|
+
|
|
310
|
+
- `references/packaged-components.md`: the package layout, build order, exports
|
|
311
|
+
and testing
|
|
312
|
+
- `references/advanced-patterns.md`: function handles, validators derived from
|
|
313
|
+
the schema, and class-based client wrappers
|
|
314
|
+
|
|
315
|
+
Official docs:
|
|
316
|
+
[Authoring Components](https://docs.convex.dev/components/authoring)
|
|
317
|
+
|
|
318
|
+
## Checklist
|
|
319
|
+
|
|
320
|
+
- [ ] Confirmed the plan against the design
|
|
321
|
+
- [ ] Read `references/packaged-components.md`
|
|
322
|
+
- [ ] Confirmed a component is the right abstraction
|
|
323
|
+
- [ ] Planned tables, public API, boundaries, and app wrappers
|
|
324
|
+
- [ ] Component lives under `convex/components/<name>/` (or package layout if
|
|
325
|
+
publishing)
|
|
326
|
+
- [ ] Component imports from its own `./_generated/server`
|
|
327
|
+
- [ ] Auth, env access, and HTTP routes stay in the app
|
|
328
|
+
- [ ] Parent app IDs cross the boundary as `v.string()`
|
|
329
|
+
- [ ] Public functions have `args` and `returns` validators
|
|
330
|
+
- [ ] Ran codegen and `pnpm justify`, and fixed codegen or type issues
|