@cleocode/skills 2026.5.84 → 2026.5.87

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 (47) hide show
  1. package/package.json +1 -1
  2. package/skills/ct-adr-recorder/SKILL.md +74 -0
  3. package/skills/ct-adr-recorder/__tests__/skill-adr-recorder.test.ts +65 -0
  4. package/skills/ct-docs-lookup/SKILL.md +116 -1
  5. package/skills/ct-docs-lookup/references/ctx7-workflow.md +198 -0
  6. package/skills/ct-docs-lookup/references/library-id-resolution.md +217 -0
  7. package/skills/ct-docs-lookup/references/version-specific-docs.md +220 -0
  8. package/skills/ct-docs-review/SKILL.md +133 -1
  9. package/skills/ct-docs-review/__tests__/skill-docs-review.test.ts +53 -0
  10. package/skills/ct-docs-review/references/inline-comment-patterns.md +268 -0
  11. package/skills/ct-docs-review/references/pr-review-mode.md +270 -0
  12. package/skills/ct-docs-review/references/style-violations.md +341 -0
  13. package/skills/ct-docs-write/SKILL.md +157 -1
  14. package/skills/ct-docs-write/__tests__/skill-docs-write.test.ts +55 -0
  15. package/skills/ct-docs-write/references/audience-targeting.md +305 -0
  16. package/skills/ct-docs-write/references/cleo-style-guide.md +234 -0
  17. package/skills/ct-docs-write/references/markdown-patterns.md +329 -0
  18. package/skills/ct-documentor/SKILL.md +11 -0
  19. package/skills/ct-documentor/references/anti-patterns.md +216 -0
  20. package/skills/ct-documentor/references/chain-orchestration.md +194 -0
  21. package/skills/ct-documentor/references/doc-types-and-templates.md +301 -0
  22. package/skills/ct-documentor/references/style-coordination.md +195 -0
  23. package/skills/ct-research-agent/SKILL.md +9 -0
  24. package/skills/ct-research-agent/references/anti-patterns.md +154 -0
  25. package/skills/ct-research-agent/references/citation-and-evidence.md +140 -0
  26. package/skills/ct-research-agent/references/source-strategy.md +116 -0
  27. package/skills/ct-research-agent/references/triggers-and-routing.md +93 -0
  28. package/skills/ct-skill-validator/SKILL.md +19 -0
  29. package/skills/ct-skill-validator/scripts/check_depth.py +306 -0
  30. package/skills/ct-spec-writer/SKILL.md +71 -1
  31. package/skills/ct-spec-writer/__tests__/skill-spec-writer.test.ts +60 -0
  32. package/skills/ct-spec-writer/references/anti-patterns.md +176 -0
  33. package/skills/ct-spec-writer/references/rfc2119-language.md +138 -0
  34. package/skills/ct-spec-writer/references/spec-templates.md +233 -0
  35. package/skills/ct-spec-writer/references/traceability-matrix.md +145 -0
  36. package/skills/ct-task-executor/SKILL.md +10 -0
  37. package/skills/ct-task-executor/references/acceptance-criteria-mapping.md +163 -0
  38. package/skills/ct-task-executor/references/anti-patterns.md +201 -0
  39. package/skills/ct-task-executor/references/common-failures.md +193 -0
  40. package/skills/ct-task-executor/references/evidence-and-gates.md +179 -0
  41. package/skills/ct-task-executor/references/implementation-patterns.md +160 -0
  42. package/skills/ct-validator/SKILL.md +9 -0
  43. package/skills/ct-validator/references/anti-patterns.md +194 -0
  44. package/skills/ct-validator/references/compliance-reports.md +199 -0
  45. package/skills/ct-validator/references/schema-checking.md +191 -0
  46. package/skills/ct-validator/references/validation-modes.md +185 -0
  47. package/skills/manifest.json +46 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/skills",
3
- "version": "2026.5.84",
3
+ "version": "2026.5.87",
4
4
  "description": "CLEO skill definitions - bundled with CLEO monorepo",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -93,6 +93,80 @@ Flags specs T4776, T4781; decomposition epic T4772; live impl T4790.
93
93
 
94
94
  A longer, realistic example with all six sections filled out lives in [references/examples.md](references/examples.md).
95
95
 
96
+ ## Through SDK (preferred)
97
+
98
+ ADRs are first-class docs SSoT records — drafted via
99
+ `cleo docs add --type adr`, attached to the originating consensus task,
100
+ and numbered through the slug. This is the canonical write path; the
101
+ legacy "write to `docs/adr/ADR-NNNN.md` and commit" pattern is
102
+ deprecated below.
103
+
104
+ ### Draft the ADR attached to its consensus task
105
+
106
+ ```bash
107
+ cleo docs add T4798 docs/adr/ADR-0042.md \
108
+ --type adr \
109
+ --slug adr-0042-drizzle-v1-beta \
110
+ --desc "ADR-0042: Adopt Drizzle ORM v1 beta for all SQLite access (status: proposed)" \
111
+ --labels "adr,proposed"
112
+ ```
113
+
114
+ - `--type adr` is the canonical taxonomy value. The closed set is
115
+ `spec | adr | research | handoff | note | llm-readme`.
116
+ - `--slug` MUST follow `adr-<NNNN>-<short-topic>`. The numeric segment
117
+ is the canonical ADR id; the topic segment makes the slug human
118
+ readable. Collisions return `E_SLUG_TAKEN` with 3 alternatives.
119
+ - The owner ID is the consensus task whose verdict drives the ADR
120
+ (`T4798` above). This is how downstream supersession cascades find
121
+ the chain — never attach an ADR to an arbitrary task.
122
+
123
+ ### Persist the decision row alongside the doc blob
124
+
125
+ `cleo docs add --type adr` writes the document and the docs-side
126
+ manifest entry, but per Immutable Constraint ADR-006 the canonical
127
+ `decisions` table MUST also be populated via Drizzle. The two writes
128
+ are paired: doc blob first (SSoT-of-the-prose), then the relational
129
+ row (SSoT-of-the-decision). Skipping either is a validation failure.
130
+
131
+ ### Publish the ADR to a git-tracked path
132
+
133
+ ```bash
134
+ cleo docs publish --for T4798 --to docs/adr/ADR-0042.md
135
+ ```
136
+
137
+ Atomic tmp-then-rename. The published file lands in the next commit;
138
+ the SSoT blob remains the canonical version-history root.
139
+
140
+ ### Fetch the ADR back by slug (for HITL review + downstream supersession)
141
+
142
+ ```bash
143
+ cleo docs fetch adr-0042-drizzle-v1-beta # latest version
144
+ cleo docs versions --for T4798 # every SHA version
145
+ ```
146
+
147
+ The HITL reviewer reads the proposed ADR via `cleo docs fetch` rather
148
+ than the on-disk file so the review anchors on the canonical SSoT
149
+ blob — drift between the published file and the blob is its own
150
+ review finding.
151
+
152
+ ### List ADRs by type or status
153
+
154
+ ```bash
155
+ cleo docs list --type adr --project # every ADR in the project
156
+ cleo docs list --task T4798 --type adr # ADRs attached to T4798
157
+ ```
158
+
159
+ ## Deprecated: Direct filesystem write
160
+
161
+ The legacy "write to `docs/adr/ADR-NNNN.md` and commit" pattern is
162
+ deprecated. The on-disk file drifts from the SSoT, the ADR has no
163
+ slug for the supersession cascade to retrieve it by, and the
164
+ consensus-task↔ADR linkage exists only as a frontmatter field
165
+ (`consensus_manifest_id`) rather than a relational owner edge.
166
+ Migrate to `cleo docs add --type adr --slug adr-<NNNN>-<topic>` for
167
+ every new ADR — and use `cleo docs sync --from docs/adr/ADR-NNNN.md
168
+ --for <taskId>` to back-fill existing on-disk ADRs into the SSoT.
169
+
96
170
  ## HITL Approval Gate
97
171
 
98
172
  When a draft reaches `proposed`, the skill MUST:
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Regression test for ct-adr-recorder/SKILL.md (T9643 / Epic T9629 / Saga T9625).
3
+ *
4
+ * Pins the SDK-first ADR contract: ADRs MUST be drafted via
5
+ * `cleo docs add --type adr --slug adr-<NNNN>-<topic>` so the document
6
+ * is owned by the originating consensus task and addressable by slug
7
+ * for the HITL approval gate and the downstream supersession cascade.
8
+ * The relational `decisions` row (ADR-006) is paired with the doc blob
9
+ * but persisted separately via Drizzle.
10
+ *
11
+ * @task T9643
12
+ * @epic T9629
13
+ * @saga T9625
14
+ */
15
+
16
+ import { readFileSync } from 'node:fs';
17
+ import { dirname, join, resolve } from 'node:path';
18
+ import { fileURLToPath } from 'node:url';
19
+ import { describe, expect, it } from 'vitest';
20
+
21
+ const thisFile = fileURLToPath(import.meta.url);
22
+ const skillRoot = resolve(dirname(thisFile), '..');
23
+ const skillPath = join(skillRoot, 'SKILL.md');
24
+ const skillContent = readFileSync(skillPath, 'utf-8');
25
+
26
+ describe('ct-adr-recorder SKILL.md — SDK-first contract (T9643)', () => {
27
+ it('teaches `cleo docs add --type adr` as the canonical write path', () => {
28
+ expect(skillContent).toMatch(/cleo docs add[\s\S]+--type adr/);
29
+ });
30
+
31
+ it('shows the `adr-<NNNN>-<topic>` slug convention', () => {
32
+ expect(skillContent).toMatch(/adr-<NNNN>-<.*?topic/i);
33
+ });
34
+
35
+ it('attaches the ADR to the consensus task via the owner ID', () => {
36
+ // The example MUST use a T### owner ID to demonstrate consensus-task linkage
37
+ expect(skillContent).toMatch(/cleo docs add\s+T\d+\s/);
38
+ });
39
+
40
+ it('keeps the relational `decisions` write paired with the doc blob (ADR-006)', () => {
41
+ expect(skillContent).toMatch(/decisions[\s\S]+Drizzle/i);
42
+ expect(skillContent).toContain('ADR-006');
43
+ });
44
+
45
+ it('shows `cleo docs publish --for ... --to docs/adr/...` for git publication', () => {
46
+ expect(skillContent).toMatch(/cleo docs publish[\s\S]+--for[\s\S]+--to[\s\S]+docs\/adr/);
47
+ });
48
+
49
+ it('shows `cleo docs fetch <slug>` for HITL review + supersession', () => {
50
+ expect(skillContent).toContain('cleo docs fetch');
51
+ });
52
+
53
+ it('shows `cleo docs list --type adr` for ADR discovery', () => {
54
+ expect(skillContent).toMatch(/cleo docs list[\s\S]+--type adr/);
55
+ });
56
+
57
+ it('marks the old direct-filesystem write as deprecated with a migration note', () => {
58
+ expect(skillContent).toContain('Deprecated: Direct filesystem write');
59
+ expect(skillContent).toMatch(/cleo docs (add|sync)/);
60
+ });
61
+
62
+ it('references E_SLUG_TAKEN for collision handling', () => {
63
+ expect(skillContent).toContain('E_SLUG_TAKEN');
64
+ });
65
+ });
@@ -63,4 +63,119 @@ Incorporate the fetched documentation into your response:
63
63
 
64
64
  - **Be specific**: Pass the user's full question as the query for better results
65
65
  - **Version awareness**: When users mention versions ("Next.js 15", "React 19"), use version-specific library IDs if available from the resolution step
66
- - **Prefer official sources**: When multiple matches exist, prefer official/primary packages over community forks
66
+ - **Prefer official sources**: When multiple matches exist, prefer official/primary packages over community forks
67
+
68
+ ## Why Context7 (not training data)
69
+
70
+ The user's global rule is explicit: prefer Context7 over training data for any
71
+ library, framework, SDK, API, CLI tool, or cloud service — even well-known ones
72
+ like React, Next.js, Prisma, Express, Tailwind, Django, or Spring Boot. This
73
+ includes API syntax, configuration, version migration, library-specific
74
+ debugging, setup instructions, and CLI tool usage. Use even when you think
75
+ you know the answer; training data may not reflect recent changes.
76
+
77
+ ## Three-Command Budget
78
+
79
+ The user rules cap a docs lookup at three CLI invocations per question. The
80
+ budget fits the standard workflow:
81
+
82
+ 1. `npx ctx7@latest library "<name>" "<question>"` — one call to resolve.
83
+ 2. `npx ctx7@latest docs <id> "<question>"` — one call to fetch.
84
+ 3. (Optional) `npx ctx7@latest docs <id> "<question>" --research` — one
85
+ retry with sandboxed agents pulling source + web search.
86
+
87
+ Going over budget is a signal: the library name is wrong, the question
88
+ is too broad, or Context7 doesn't cover this library. In any of those
89
+ cases, refine before retrying — don't burn more calls.
90
+
91
+ ## When NOT to Use This Skill
92
+
93
+ The user rules explicitly exclude these from docs-lookup:
94
+
95
+ - **Refactoring** — re-shaping existing code; no library lookup needed.
96
+ - **Scripts written from scratch** — general programming, not library API.
97
+ - **Debugging business logic** — use codebase tools (Grep, GitNexus), not
98
+ external docs.
99
+ - **Code review** — quality assessment, not library reference.
100
+ - **General programming concepts** — pure CS questions; training data is fine.
101
+
102
+ Use docs-lookup ONLY for: API syntax, configuration questions, version
103
+ migration issues, library-specific debugging, setup instructions, and CLI
104
+ tool usage.
105
+
106
+ ## Authentication and Quotas
107
+
108
+ The `ctx7` CLI runs anonymously with a limited free quota. When quota
109
+ exhausts:
110
+
111
+ ```text
112
+ Error: Quota exceeded.
113
+ Run `npx ctx7@latest login` for higher limits.
114
+ Or set CONTEXT7_API_KEY env var with your key.
115
+ ```
116
+
117
+ Surface the error to the user (or include in `needs_followup`). NEVER
118
+ silently fall back to training data — that violates the skill's contract.
119
+
120
+ ## Sensitive Data
121
+
122
+ Queries to Context7 are logged on the Context7 side. Never include:
123
+
124
+ - API keys, tokens, passwords
125
+ - Internal hostnames or URLs
126
+ - Customer-identifying data
127
+ - Source code excerpts from private repos
128
+
129
+ Use generic phrasing. If the actual API call needs a specific value,
130
+ describe it abstractly ("how do I authenticate with an API key" instead
131
+ of "use API key sk_live_abc123 to...").
132
+
133
+ ## Multi-Library Composition
134
+
135
+ A single question may touch multiple libraries — common in modern stacks
136
+ (SvelteKit + Better-Auth + Drizzle, Next.js + Prisma + Tailwind, etc.).
137
+ Resolve each library independently with the right version pin, then
138
+ synthesize.
139
+
140
+ The three-command budget applies per-library; a question spanning
141
+ three libraries gets nine commands. Stay focused — fetch the specific
142
+ integration point each time, not the entire library surface.
143
+
144
+ ## Citing Versions in Answers
145
+
146
+ Every code example produced from a version-pinned fetch MUST cite the
147
+ version. The reader copies the code and runs it; when their version
148
+ differs, the citation is the first thing they check.
149
+
150
+ ```markdown
151
+ Use `defineRelations` (Drizzle ORM v1.0.0-beta and later):
152
+
153
+ ```typescript
154
+ import { defineRelations } from "drizzle-orm";
155
+ // ...
156
+ ```
157
+ ```
158
+
159
+ Without the version note, the reader who is on Drizzle 0.x will be
160
+ confused when the import fails.
161
+
162
+ ## Common Failure Modes
163
+
164
+ | Symptom | Cause | Fix |
165
+ |---------|-------|-----|
166
+ | "Library not found" | Wrong name format | Use official punctuation: "Next.js" not "nextjs" |
167
+ | Stale answer | No version pin | Detect installed version from lockfile, pin |
168
+ | Generic answer when specifics needed | Vague query | Pass full question text, not single words |
169
+ | Quota exceeded | Anonymous over-use | `ctx7 login` or set `CONTEXT7_API_KEY` |
170
+ | Hallucinated API | Skipped Context7 | Always run Step 1+2 before answering library questions |
171
+ | Wrong fork picked | Took top result blindly | Read descriptions; prefer official org |
172
+
173
+ ---
174
+
175
+ ## See references/
176
+
177
+ Progressive disclosure — load on demand only:
178
+
179
+ - `references/ctx7-workflow.md` — two-step loop, query formatting, research mode, budget
180
+ - `references/library-id-resolution.md` — signals for picking the right ID; disambiguation procedure
181
+ - `references/version-specific-docs.md` — version pinning, migrations, deprecations, drift detection
@@ -0,0 +1,198 @@
1
+ # ctx7 Workflow
2
+
3
+ `ct-docs-lookup` is the CLEO-side wrapper around the `ctx7` CLI. The
4
+ underlying contract is set in the user's global rules
5
+ (`~/.claude/rules/context7.md`) and the project's `MCP_Context7.md`.
6
+ This reference codifies the workflow with concrete examples and
7
+ recovery procedures.
8
+
9
+ ## Why Context7
10
+
11
+ The skill's purpose statement is direct: when the user asks about a
12
+ library, framework, or needs code examples, fetch current documentation
13
+ instead of relying on training data. Training data is stale — the
14
+ project's user rules say so explicitly.
15
+
16
+ This applies even when you think you know the answer. API surfaces of
17
+ React, Next.js, Prisma, Tailwind, Drizzle, Svelte, Supabase, and friends
18
+ move faster than any model's cutoff. Verify against current docs.
19
+
20
+ ## The Two-Step Loop
21
+
22
+ The ctx7 CLI is shipped as `npx ctx7@latest`. The workflow is two calls.
23
+
24
+ ```bash
25
+ # Step 1 — resolve the official library ID
26
+ npx ctx7@latest library "<library-name>" "<user-question>"
27
+
28
+ # Step 2 — fetch docs for the resolved ID
29
+ npx ctx7@latest docs <libraryId> "<user-question>"
30
+ ```
31
+
32
+ The output of Step 1 is a list of candidate library IDs in the form
33
+ `/org/project`. Pick the best match (see `library-id-resolution.md` for
34
+ the heuristics) and pass it to Step 2.
35
+
36
+ ## Step 1: Library Resolution
37
+
38
+ Use the official library name with proper punctuation:
39
+
40
+ | ❌ Wrong | ✅ Correct |
41
+ |----------|------------|
42
+ | `"nextjs"` | `"Next.js"` |
43
+ | `"customerio"` | `"Customer.io"` |
44
+ | `"threejs"` | `"Three.js"` |
45
+ | `"reactdom"` | `"React DOM"` |
46
+ | `"vuejs"` | `"Vue.js"` |
47
+ | `"tailwindcss"` | `"Tailwind CSS"` |
48
+
49
+ The library name matches what the project documents itself as. When
50
+ unsure, search the project's GitHub README for the official name.
51
+
52
+ Pass the user's full question as the second arg — specific queries
53
+ return better matches than single words.
54
+
55
+ ```bash
56
+ # GOOD
57
+ npx ctx7@latest library "Drizzle ORM" "how do I define relations in v1"
58
+
59
+ # BAD — too generic, ranks poorly
60
+ npx ctx7@latest library "drizzle" "relations"
61
+ ```
62
+
63
+ ## Step 1 Output Interpretation
64
+
65
+ The CLI returns candidates with several signals — pick by:
66
+
67
+ 1. **Exact name match.** "Next.js" should resolve to `/vercel/next.js`
68
+ over `/some-fork/next.js-clone`.
69
+ 2. **Source reputation.** Look for High or Medium source labels.
70
+ 3. **Code snippet count.** More snippets = better-indexed library.
71
+ 4. **Benchmark score.** Higher is better; reflects retrieval quality.
72
+
73
+ If the top candidate doesn't match exactly what the user asked for —
74
+ e.g., they said "Next.js 15" and the top candidate is generic — try
75
+ again with refined terms or version-specific names.
76
+
77
+ ## Step 2: Docs Fetch
78
+
79
+ Once you have the library ID:
80
+
81
+ ```bash
82
+ npx ctx7@latest docs /vercel/next.js "how do I configure middleware to inject auth headers"
83
+ ```
84
+
85
+ The output is documentation excerpts with citations. Use these directly
86
+ in your answer — they are current, sourced, and citable.
87
+
88
+ ## Version-Specific Docs
89
+
90
+ When the user names a version, use the version-specific form:
91
+
92
+ ```bash
93
+ # General
94
+ npx ctx7@latest docs /vercel/next.js "..."
95
+
96
+ # Pinned to v14.3.0
97
+ npx ctx7@latest docs /vercel/next.js/v14.3.0 "..."
98
+
99
+ # Pinned to v15 (latest 15.x)
100
+ npx ctx7@latest docs /vercel/next.js/v15 "..."
101
+ ```
102
+
103
+ The Step 1 output enumerates available versions. Pick the version
104
+ matching the project's actual installed version (check
105
+ `package.json` / `Cargo.toml` / `requirements.txt`).
106
+
107
+ ## Research Mode (Fallback)
108
+
109
+ If the default fetch doesn't satisfy the question, retry with
110
+ `--research`:
111
+
112
+ ```bash
113
+ npx ctx7@latest docs /vercel/next.js "..." --research
114
+ ```
115
+
116
+ This launches sandboxed agents that git-pull the actual source repos
117
+ plus live web search, then synthesizes a fresh answer. More costly
118
+ (longer, more tokens), so use only when:
119
+
120
+ - Default fetch returned a generic answer when specifics were needed.
121
+ - The question references a recent change that may not be indexed yet.
122
+ - The user explicitly asked for research-grade depth.
123
+
124
+ ## Auth and Quotas
125
+
126
+ The `ctx7` CLI runs anonymously by default with limited quota. When
127
+ quota is exhausted:
128
+
129
+ ```bash
130
+ # Error message will be something like:
131
+ # Error: Quota exceeded. Run `npx ctx7@latest login` or set CONTEXT7_API_KEY
132
+ ```
133
+
134
+ Instruct the user (or surface in `needs_followup`) to either:
135
+ - Run `npx ctx7@latest login` (one-time browser auth)
136
+ - Set `CONTEXT7_API_KEY` env var with their key
137
+
138
+ Do NOT silently fall back to training data — that violates the skill's
139
+ contract. The whole point is current docs, not stale recall.
140
+
141
+ ## Budget Discipline
142
+
143
+ The user rules cap the workflow at "no more than 3 commands per
144
+ question". For most lookups this is plenty:
145
+ - 1 call: library resolution
146
+ - 1 call: docs fetch
147
+ - 1 call (optional): retry with `--research` if needed
148
+
149
+ Going over budget signals one of:
150
+ - Wrong library name (refine and retry)
151
+ - Question too broad (narrow the question first)
152
+ - Genuine library mismatch (Context7 doesn't cover this library — use
153
+ web search via WebSearch/WebFetch as alternative)
154
+
155
+ ## Sensitive Data
156
+
157
+ Never include API keys, passwords, credentials, or internal URLs in
158
+ queries. The query is logged on the Context7 side.
159
+
160
+ ```bash
161
+ # WRONG
162
+ npx ctx7@latest docs /supabase/supabase "use API key sk_live_abc123 to..."
163
+
164
+ # RIGHT
165
+ npx ctx7@latest docs /supabase/supabase "how do I authenticate the client with an API key"
166
+ ```
167
+
168
+ ## End-to-End Example
169
+
170
+ ```bash
171
+ # User asked: "How do I do streaming server actions in Next.js 15?"
172
+
173
+ # Step 1 — resolve
174
+ $ npx ctx7@latest library "Next.js" "How do I do streaming server actions in Next.js 15?"
175
+ > /vercel/next.js/v15 (benchmark 0.87, snippets 1240, source: High)
176
+ > /vercel/next.js (benchmark 0.85, snippets 5230, source: High)
177
+ > ...
178
+
179
+ # Step 2 — fetch (use version-pinned ID)
180
+ $ npx ctx7@latest docs /vercel/next.js/v15 "How do I do streaming server actions in Next.js 15?"
181
+ > [docs excerpt with streaming example, citation]
182
+
183
+ # Compose answer using the fetched docs, citing version
184
+ ```
185
+
186
+ ## When NOT to Use This Skill
187
+
188
+ See `library-id-resolution.md` for the boundary with debugging tasks,
189
+ and `version-specific-docs.md` for when the answer doesn't depend on
190
+ a specific library. Quick summary:
191
+
192
+ - ❌ Don't use for refactoring (no library lookup needed)
193
+ - ❌ Don't use for scripts written from scratch
194
+ - ❌ Don't use for debugging business logic (use codebase tools)
195
+ - ❌ Don't use for code review
196
+ - ❌ Don't use for general programming concepts
197
+ - ✅ Use for API syntax, configuration, version migration, library-specific
198
+ debugging, setup instructions, CLI tool usage
@@ -0,0 +1,217 @@
1
+ # Library ID Resolution
2
+
3
+ The Context7 library catalog uses `/org/project` IDs. Picking the right
4
+ ID is the difference between fetching authoritative docs and fetching
5
+ a community fork's stale README. This reference codifies the
6
+ disambiguation heuristics with concrete examples.
7
+
8
+ ## ID Anatomy
9
+
10
+ ```
11
+ /vercel/next.js
12
+ └org─┘ └proj─┘
13
+
14
+ /vercel/next.js/v14.3.0
15
+ └org─┘ └proj─┘ └version┘
16
+ ```
17
+
18
+ - The `org` is typically the GitHub org or the company name.
19
+ - The `project` is the official package name.
20
+ - The optional `version` is a tag or release branch.
21
+
22
+ ## Resolution Output Format
23
+
24
+ A typical Step 1 (`ctx7 library`) output:
25
+
26
+ ```text
27
+ Top matches for "Next.js" against query "configure middleware":
28
+
29
+ 1. /vercel/next.js
30
+ - Source: High
31
+ - Description: The React Framework for the Web.
32
+ - Code snippets: 5230
33
+ - Benchmark: 0.85
34
+
35
+ 2. /vercel/next.js/v15
36
+ - Source: High
37
+ - Description: Next.js v15 release line.
38
+ - Code snippets: 1240
39
+ - Benchmark: 0.87
40
+
41
+ 3. /community/next-with-foo
42
+ - Source: Medium
43
+ - Description: Next.js + Foo starter template.
44
+ - Code snippets: 87
45
+ - Benchmark: 0.42
46
+
47
+ 4. /old-org/nextjs-legacy
48
+ - Source: Low
49
+ - Description: Pre-app-router Next.js patterns.
50
+ - Code snippets: 412
51
+ - Benchmark: 0.39
52
+ ```
53
+
54
+ Five signals to weigh.
55
+
56
+ ## Signal 1: Exact Name Match
57
+
58
+ The user said "Next.js". Candidates 1 and 2 are exact matches; 3 is
59
+ "next-with-foo" (a derivative); 4 is "nextjs-legacy" (suffixed).
60
+
61
+ Prefer the canonical name. The derivative or suffixed projects are
62
+ appropriate ONLY when the user explicitly named them.
63
+
64
+ ## Signal 2: Source Reputation
65
+
66
+ `High` > `Medium` > `Low`. Source reputation reflects how authoritative
67
+ Context7 considers the project. Official org-owned repos are High.
68
+ Community forks are typically Medium. Abandoned or low-quality projects
69
+ are Low.
70
+
71
+ When multiple High candidates exist, look further. When the only
72
+ High candidate is the obvious one, pick it.
73
+
74
+ ## Signal 3: Code Snippet Count
75
+
76
+ More snippets = better-indexed library = higher chance of finding the
77
+ exact API the user asked about. The unversioned ID usually has higher
78
+ snippet counts than version-pinned IDs because it aggregates across
79
+ versions.
80
+
81
+ For general questions, prefer unversioned IDs. For version-specific
82
+ questions, accept the lower snippet count of the pinned ID.
83
+
84
+ ## Signal 4: Benchmark Score
85
+
86
+ The benchmark is a retrieval-quality measure produced by Context7 —
87
+ higher means the candidate library has good documentation that
88
+ indexes well. Use as a tiebreaker only.
89
+
90
+ In the example above, candidate 2 has a slightly higher benchmark
91
+ (0.87) than candidate 1 (0.85) because v15-specific queries score
92
+ better against the pinned slice. For a v15-specific question, prefer
93
+ candidate 2.
94
+
95
+ ## Signal 5: Query Alignment
96
+
97
+ The user's query in Step 1 affects ranking. If the query mentioned
98
+ "middleware", candidates whose docs cover middleware will rank higher.
99
+ This is why passing the FULL user question (not a single word) yields
100
+ better resolution.
101
+
102
+ ## Common Pitfalls
103
+
104
+ ### Pitfall: Picking the version-pinned ID for a general question
105
+
106
+ The user asked "What does Next.js do?" — a general question.
107
+
108
+ - ❌ Pick `/vercel/next.js/v15` — too narrow; misses cross-version context.
109
+ - ✅ Pick `/vercel/next.js` — covers the whole project.
110
+
111
+ ### Pitfall: Picking the unversioned ID for a version-specific question
112
+
113
+ The user asked "How do I migrate from Next.js 14 to 15?"
114
+
115
+ - ❌ Pick `/vercel/next.js` — might return mixed-version docs.
116
+ - ✅ Pick `/vercel/next.js/v15` — gets the migration guide for 15.
117
+ - ✅ Better: pick `/vercel/next.js/v15` for "to" and `/vercel/next.js/v14`
118
+ for "from", and run two fetches.
119
+
120
+ ### Pitfall: Picking the community fork when the user wants the official
121
+
122
+ The user asked "How do I use Tailwind utilities?"
123
+
124
+ - ❌ Pick `/some-community/tailwind-with-extras` — not what they meant.
125
+ - ✅ Pick `/tailwindlabs/tailwindcss` — the official.
126
+
127
+ Community forks rank LOW on the "what user meant" axis even when they
128
+ rank high on other signals. Default to the official.
129
+
130
+ ### Pitfall: Picking the highest snippet count regardless of relevance
131
+
132
+ The user asked about Vue 3 composition API.
133
+
134
+ - ❌ Pick `/vuejs/vue` (high snippet count, but it's the Vue 2 line).
135
+ - ✅ Pick `/vuejs/core` or `/vuejs/vue-next` (Vue 3).
136
+
137
+ Always read the description, not just the count. Old projects accumulate
138
+ snippets because they've been around longer — they may no longer be
139
+ current.
140
+
141
+ ## Disambiguation Procedure
142
+
143
+ When two candidates look equally good:
144
+
145
+ 1. **Read the descriptions.** They usually disambiguate.
146
+ 2. **Check the org.** Official org = the project's home; community
147
+ org = derivative.
148
+ 3. **Check the project's GitHub URL** if Context7 includes it. The URL
149
+ matches what the project's README cites.
150
+ 4. **Try both.** Compare the outputs of Step 2 for each candidate. The
151
+ one that better answers the question is the right one.
152
+
153
+ ## When Resolution Fails
154
+
155
+ Sometimes Step 1 returns no good match. The library may not be in
156
+ Context7's catalog, or the name was wrong. Recovery:
157
+
158
+ ```bash
159
+ # Retry with the formal name from the project's GitHub
160
+ npx ctx7@latest library "TanStack Query" "..." # not "react-query"
161
+
162
+ # Retry with the alternative spelling
163
+ npx ctx7@latest library "GitHub Actions" "..." # not "gh-actions"
164
+
165
+ # Retry with a more specific query
166
+ npx ctx7@latest library "Next.js" "App Router middleware in v15"
167
+
168
+ # If all retries fail, fall back to WebSearch / WebFetch
169
+ # (but tell the user the library isn't in Context7's catalog)
170
+ ```
171
+
172
+ ## Version Resolution Specifics
173
+
174
+ When a project has many versions, Step 1's output lists them. Pick by:
175
+
176
+ 1. **Match the project's installed version.** Check `package.json`,
177
+ `Cargo.toml`, `requirements.txt`, etc.
178
+ 2. **If the user named a version, use that.**
179
+ 3. **If neither, use the latest stable (highest version number that
180
+ isn't pre-release).**
181
+
182
+ ```bash
183
+ # Project installed Next.js 14.3.x
184
+ $ jq '.dependencies.next' package.json
185
+ "14.3.0"
186
+
187
+ # Use the pinned version
188
+ npx ctx7@latest docs /vercel/next.js/v14.3.0 "..."
189
+ ```
190
+
191
+ This catches the case where the user asks about behavior that differs
192
+ between versions; using the wrong version pin gives a confidently
193
+ wrong answer.
194
+
195
+ ## Caching
196
+
197
+ Library IDs rarely change. If you resolved `/vercel/next.js/v15` for
198
+ one query, you can re-use it for the next query about the same library
199
+ without running Step 1 again. Just remember to refresh the resolution
200
+ when:
201
+
202
+ - Asking about a different major version.
203
+ - The project's installed version changed.
204
+ - The previous fetch didn't satisfy the question (maybe the wrong ID
205
+ was picked).
206
+
207
+ ## When NOT to Use Library Lookup
208
+
209
+ The user rules are explicit: not for refactoring, scripts-from-scratch,
210
+ business-logic debugging, code review, or general programming concepts.
211
+
212
+ If the question is "how do I structure my repository?" — that is a
213
+ general programming question. Use general knowledge plus codebase
214
+ inspection, not Context7.
215
+
216
+ If the question is "how does Next.js's app router handle parallel
217
+ routes?" — that is a library API question. Use Context7.