Skip to content

Commit e61a56a

Browse files
committed
feat(zod): use ask CLI as primary source for version-accurate docs
Mirrors the use-better-auth pattern: lead with `ask src zod` / `ask docs zod` to read the lockfile-pinned source (with comments and tests), demoting node_modules/zod/dist to a fallback for environments where ask isn't installed. - New 'Finding Documentation' section in SKILL.md showing the SRC=$(ask src zod) idiom for reading docs, verifying symbols, and finding canonical examples in tests - versions.md 'When in doubt' switched to ask-first verification with explicit @Version pinning examples for v4.3.6 and v3.25.76 - 'When typecheck or runtime fails' debug snippet now greps $(ask src zod)/packages/zod/src instead of node_modules/zod/dist
1 parent 5892e1d commit e61a56a

2 files changed

Lines changed: 91 additions & 14 deletions

File tree

plugins/zod/skills/use-zod/SKILL.md

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ description: 'Answer questions about the Zod schema validation library and help
55

66
## Prerequisites
77

8-
Before writing Zod code, verify the installed version and entry points in the current project:
8+
Verify the `ask` CLI is available (`which ask`). It is the primary tool for reading the exact version installed in this project — it resolves the version from the lockfile, fetches docs/source once, and caches them at `~/.ask/`. If `ask` is not installed, fall back to `node_modules/zod/` and the official site at https://zod.dev (which tracks the latest published v4, not necessarily the installed version).
9+
10+
Before writing Zod code, verify the installed version and entry points:
911

1012
```bash
11-
# installed version (drives everything below)
13+
# installed version drives everything below
1214
cat node_modules/zod/package.json 2>/dev/null | jq -r .version
1315

14-
# subpath exports — confirms which import paths resolve
16+
# subpath exports — confirms which import paths resolve (zod, zod/mini, zod/v3, zod/v4)
1517
cat node_modules/zod/package.json 2>/dev/null | jq '.exports | keys'
1618
```
1719

@@ -39,15 +41,72 @@ Zod 4 (released 2026) was a major rewrite. Many APIs that were canonical in v3 a
3941

4042
When working with Zod:
4143

42-
1. Resolve the installed version first (`node_modules/zod/package.json`).
43-
2. If unsure whether an API exists in the installed version, grep the bundled `.d.ts`: `rg -n "treeifyError|formatError" node_modules/zod/dist`.
44-
3. Check upstream docs **at the matching version pin** (links below in [`references/versions.md`](references/versions.md)) — not at `main`, which tracks the latest release.
44+
1. Resolve the installed version against the local checkout with `ask` (see [Finding Documentation](#finding-documentation) below).
45+
2. Verify every API name, method signature, and option shape against the source or bundled `.d.ts` before generating code. Never invent method names.
46+
3. Cross-reference upstream docs **at the matching version pin** ([`references/versions.md`](references/versions.md) has the v4.3.6 / v3.25.76 links) — not `main`, which tracks the latest release.
4547
4. Run typecheck after every change. Zod schemas are heavily inferred and silent type drift is rare.
46-
5. Never invent method names. If the user references an API you don't recognise, look it up before answering.
47-
6. Surface deprecations to the user instead of silently emitting either pattern.
48+
5. Surface deprecations to the user instead of silently emitting either pattern (e.g. `.superRefine` works but is deprecated in v4 — say so).
4849

4950
If documentation cannot be found locally or remotely to back an answer, say so explicitly.
5051

52+
## Finding Documentation
53+
54+
Resolve the source checkout and docs directory once with `ask`; reuse the paths across reads:
55+
56+
```bash
57+
SRC=$(ask src zod) # checkout root
58+
DOCS=$(ask docs zod | head -n1) # candidate docs dir
59+
```
60+
61+
Both pin to the version in the project's lockfile. To inspect a specific version regardless of the project, append `@version`:
62+
63+
```bash
64+
SRC_V4=$(ask src zod@4.3.6)
65+
SRC_V3=$(ask src zod@3.25.76)
66+
```
67+
68+
### Read the README and docs content
69+
70+
```bash
71+
cat "$DOCS/README.md"
72+
ls "$SRC/packages/docs/content" # v4 docs source (mdx)
73+
cat "$SRC/packages/docs/content/api.mdx" # full API reference
74+
cat "$SRC/packages/docs/content/error-formatting.mdx"
75+
cat "$SRC/packages/docs/content/error-customization.mdx"
76+
cat "$SRC/packages/docs/content/codecs.mdx" # v4.1+ only
77+
```
78+
79+
### Verify a symbol exists in the installed version
80+
81+
```bash
82+
# top-level functions (v4): treeifyError, prettifyError, flattenError, codec, config
83+
rg -n "^export (function|const) (treeifyError|prettifyError|flattenError|codec|config)\\b" "$SRC/packages/zod/src"
84+
85+
# instance methods on schemas
86+
rg -n "(\\.refine|\\.check|\\.superRefine|\\.overwrite|\\.transform|\\.parseAsync)\\b" "$SRC/packages/zod/src"
87+
88+
# subpath exports
89+
cat "$SRC/packages/zod/package.json" | jq '.exports | keys'
90+
```
91+
92+
### Find canonical example shapes (tests are the most reliable source)
93+
94+
```bash
95+
fd -e test.ts . "$SRC/packages/zod/tests"
96+
rg -n "discriminatedUnion|z\\.codec|treeifyError" "$SRC/packages/zod/tests"
97+
```
98+
99+
### Fallback when `ask` is unavailable
100+
101+
```bash
102+
SRC=./node_modules/zod
103+
ls $SRC/dist
104+
rg "treeifyError" $SRC/dist # confirm v4 helpers shipped in this build
105+
cat $SRC/package.json | jq .version
106+
```
107+
108+
Use https://zod.dev only to cross-reference — it always tracks the latest published v4.
109+
51110
## Version detection — branch v4 vs v3 paths
52111

53112
```bash
@@ -109,11 +168,11 @@ Before searching source code, check the most common Zod failure modes:
109168
5. **`.superRefine` flagged as deprecated** (v4) — replace with `.check()` per [`references/parsing-and-errors.md`](references/parsing-and-errors.md).
110169
6. **Custom error not surfacing** — confirm you're using the unified `error` param (v4) and not the legacy `message`/`errorMap` shape (v3).
111170

112-
If the symptom is not listed:
171+
If the symptom is not listed, resolve the source and grep the error string:
113172

114173
```bash
115-
# resolve the error string inside installed source
116-
rg -n "error string fragment" node_modules/zod/dist
174+
rg -n "error string fragment" "$(ask src zod)/packages/zod/src"
175+
# fallback: rg -n "error string fragment" node_modules/zod/dist
117176
```
118177

119178
## References

plugins/zod/skills/use-zod/references/versions.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,27 @@ Always link the user to docs at the version that matches their installed package
120120

121121
## When in doubt
122122

123-
1. `cat node_modules/zod/package.json | jq .version` — read the actual version.
124-
2. `cat node_modules/zod/package.json | jq '.exports | keys'` — confirm available subpaths.
125-
3. `rg -n "<symbol>" node_modules/zod/dist` — verify the symbol exists in the installed build before suggesting it.
123+
Prefer `ask` over `node_modules/` — it resolves the project's lockfile-pinned version and gives you full source (with comments and tests), not just the compiled output.
124+
125+
```bash
126+
SRC=$(ask src zod)
127+
cat "$SRC/packages/zod/package.json" | jq .version # actual installed version
128+
cat "$SRC/packages/zod/package.json" | jq '.exports | keys' # available subpaths
129+
rg -n "<symbol>" "$SRC/packages/zod/src" # verify symbol exists
130+
```
131+
132+
Pin to a specific version regardless of the project:
133+
134+
```bash
135+
ask src zod@4.3.6 # latest v4
136+
ask src zod@3.25.76 # latest v3 (with v4 bridge)
137+
```
138+
139+
Fallback when `ask` is unavailable:
140+
141+
1. `cat node_modules/zod/package.json | jq .version`
142+
2. `cat node_modules/zod/package.json | jq '.exports | keys'`
143+
3. `rg -n "<symbol>" node_modules/zod/dist`
126144

127145
<!--
128146
Source references:

0 commit comments

Comments
 (0)