Slice · AI prompt
Polymorphic-target threaded comments. Consumer picks `TargetRef = { kind, id, subId? }` (e.g. page+block, blog+slug, task+id). Reply nesting is real: `parentId` end-to-end + `buildThread(flat) → CommentNode[]` tree (oldest-first, orphan-safe). Renderless <CommentsThread> + <CommentsAnchor> wrappers; useComments(bindings, opts) returns items + `tree` + openCount + CRUD + forbiddenWords guard. Adapter pattern — see contract-negotiations §1.
# Install `comments` — Comments — Threaded
> Polymorphic-target threaded comments.
📚 Knowledge base : https://resource.rahmanef.com/llms.txt
📦 Slice detail : https://resource.rahmanef.com/slices/comments
🧠 JSON catalog : https://resource.rahmanef.com/api/knowledge?slice=comments
🔗 Source : https://github.com/rahmanef63/resource-site/tree/main/frontend/slices/comments
## 1. Install
```bash
npx rahman-resources add comments
# alias: npx rr add comments
```
The CLI copies `frontend/slices/comments/` into your project + augments `.env.example` + installs npm deps automatically. Run it from your project root.
## 2. What it ships
- shadcn primitives: `button`, `textarea`, `avatar`
- peer slices (cascade install):
- `convex-auth` — Comment author identity from convex-auth.
- convex feature paths: `convex/features/comments`
## 3. Wire it up
Run `rr add comments`. Wire Convex bindings ({ list, create, update, resolve, remove }) then use <CommentsThread target={{ kind, id, subId? }} bindings={bindings} forbiddenWords={[...]}>{render-prop}</CommentsThread> OR <CommentsAnchor target=... bindings=... pathMap={(t)=>...}>. v0.2.0 polymorphic — pick `kind` literal per host domain.
## Rules of engagement
- shadcn-only UI primitives. No raw `<button>` / `<dialog>` / native date or file inputs.
- 200-line hard cap per source file (extract neighbours when over).
- All Convex queries hit an index (`.withIndex(...)`); never bare `.collect()`.
- Public mutations/queries declare `args:` validators + authz.
- Full ruleset: https://resource.rahmanef.com/best-practice
The agent will fetch /llms.txt for the full ruleset and use /api/knowledge for the JSON catalog.