@esreekarreddy/ai-prompts 1.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/LICENSE +21 -0
- package/README.md +361 -0
- package/chains/_index.md +33 -0
- package/chains/bug-fix.md +222 -0
- package/chains/new-feature.md +216 -0
- package/chains/production-launch.md +291 -0
- package/chains/refactor.md +210 -0
- package/chains/security-hardening.md +242 -0
- package/contexts/guides/api-design.md +229 -0
- package/contexts/guides/error-handling.md +219 -0
- package/contexts/patterns/agentic-coding.md +368 -0
- package/contexts/patterns/mcp-server-patterns.md +267 -0
- package/contexts/patterns/repository-pattern.md +163 -0
- package/contexts/patterns/service-layer.md +185 -0
- package/contexts/stacks/fastapi.md +187 -0
- package/contexts/stacks/nextjs-14.md +149 -0
- package/contexts/stacks/prisma.md +228 -0
- package/dist/index.d.ts +129 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +284 -0
- package/dist/index.js.map +1 -0
- package/examples/architecture-docs/sample-architecture.md +270 -0
- package/examples/code-reviews/sample-review.md +232 -0
- package/examples/prds/sample-prd.md +179 -0
- package/instructions/_index.md +57 -0
- package/instructions/personas/code-reviewer.md +83 -0
- package/instructions/personas/devops-engineer.md +90 -0
- package/instructions/personas/security-expert.md +69 -0
- package/instructions/personas/senior-engineer.md +243 -0
- package/instructions/personas/ux-engineer.md +88 -0
- package/instructions/standards/fastapi.md +241 -0
- package/instructions/standards/go.md +427 -0
- package/instructions/standards/nextjs.md +350 -0
- package/instructions/standards/nodejs.md +284 -0
- package/instructions/standards/python.md +245 -0
- package/instructions/standards/react.md +227 -0
- package/instructions/standards/rust.md +318 -0
- package/instructions/standards/typescript-react.md +822 -0
- package/instructions/standards/typescript.md +294 -0
- package/instructions/workflows/feature-development.md +222 -0
- package/instructions/workflows/incident-response.md +192 -0
- package/instructions/workflows/pr-review.md +149 -0
- package/instructions/workflows/tdd.md +160 -0
- package/package.json +84 -0
- package/prompts/_index.md +70 -0
- package/prompts/agentic/agentic-loop.md +83 -0
- package/prompts/agentic/context-manager.md +37 -0
- package/prompts/agentic/test-driven-fix.md +41 -0
- package/prompts/analysis/deep-debugger.md +488 -0
- package/prompts/design/design-system-extractor.md +147 -0
- package/prompts/development/code-cleaner.md +119 -0
- package/prompts/development/debugger.md +64 -0
- package/prompts/development/tech-debt-audit.md +88 -0
- package/prompts/planning/architecture-analyzer.md +72 -0
- package/prompts/planning/implementation-plan.md +98 -0
- package/prompts/planning/prd-generator.md +66 -0
- package/prompts/planning/scope-killer.md +74 -0
- package/prompts/quality/critical-path-tester.md +133 -0
- package/prompts/quality/pre-launch-checklist.md +137 -0
- package/prompts/quality/security-audit.md +115 -0
- package/prompts/quality/security-fixer.md +117 -0
- package/prompts/quality/security-hardening.md +157 -0
- package/prompts/system/master-system-prompt.md +252 -0
- package/skills/_index.md +60 -0
- package/skills/code-review-advanced.md +435 -0
- package/skills/code-review.md +86 -0
- package/skills/debugging.md +86 -0
- package/skills/documentation.md +97 -0
- package/skills/pr-description.md +116 -0
- package/skills/project-setup.md +123 -0
- package/skills/refactoring.md +93 -0
- package/skills/testing.md +134 -0
- package/snippets/_index.md +57 -0
- package/snippets/constraints/mvp-only.md +50 -0
- package/snippets/constraints/no-external-deps.md +45 -0
- package/snippets/constraints/read-only.md +45 -0
- package/snippets/constraints/security-first.md +50 -0
- package/snippets/modifiers/be-ruthless.md +52 -0
- package/snippets/modifiers/be-thorough.md +50 -0
- package/snippets/modifiers/effort-high.md +56 -0
- package/snippets/modifiers/explain-reasoning.md +50 -0
- package/snippets/modifiers/megathink.md +314 -0
- package/snippets/modifiers/meta-cot.md +101 -0
- package/snippets/modifiers/no-code-yet.md +55 -0
- package/snippets/modifiers/step-by-step.md +50 -0
- package/snippets/modifiers/ultrathink.md +359 -0
- package/snippets/output-formats/checklist.md +61 -0
- package/snippets/output-formats/json.md +53 -0
- package/snippets/output-formats/markdown-table.md +44 -0
- package/snippets/output-formats/numbered-list.md +44 -0
- package/templates/_index.md +101 -0
- package/templates/claude-md/auto-enhance.md +258 -0
- package/templates/claude-md/cli-tool.md +243 -0
- package/templates/claude-md/full.md +449 -0
- package/templates/claude-md/minimal.md +52 -0
- package/templates/claude-md/nextjs-app.md +207 -0
- package/templates/claude-md/nodejs-service.md +251 -0
- package/templates/claude-md/python-api.md +236 -0
- package/templates/copilot/instructions.md +33 -0
- package/templates/cursor-rules/fullstack.txt +98 -0
- package/templates/cursor-rules/minimal.txt +20 -0
- package/templates/cursor-rules/nextjs.txt +61 -0
- package/templates/cursor-rules/python.txt +79 -0
- package/templates/docs/adr-template.md +119 -0
- package/templates/docs/api-spec-template.md +277 -0
- package/templates/docs/prd-template.md +140 -0
- package/templates/docs/runbook-template.md +238 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# AI Library Auto-Enhancement Integration
|
|
2
|
+
|
|
3
|
+
Add this snippet to your project's `CLAUDE.md` or `.claude/instructions.md` to enable automatic prompt enhancement.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick Setup (Copy This)
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## AI Library Integration
|
|
11
|
+
|
|
12
|
+
You have access to the AI Library MCP server with powerful prompts, skills, and workflows.
|
|
13
|
+
|
|
14
|
+
### Automatic Enhancement Protocol
|
|
15
|
+
|
|
16
|
+
**CRITICAL: For any substantial task, ALWAYS enhance first:**
|
|
17
|
+
|
|
18
|
+
1. **Before starting work**, call `enhance_prompt` with the user's request
|
|
19
|
+
2. **Load recommended prompts** using `get_prompt` for each suggestion
|
|
20
|
+
3. **Apply the guidance** to produce higher-quality output
|
|
21
|
+
|
|
22
|
+
### When to Enhance
|
|
23
|
+
|
|
24
|
+
ALWAYS call `enhance_prompt` when asked to:
|
|
25
|
+
- Build, create, or implement features
|
|
26
|
+
- Fix bugs or debug issues
|
|
27
|
+
- Review or refactor code
|
|
28
|
+
- Design systems or architecture
|
|
29
|
+
- Write documentation or specs
|
|
30
|
+
|
|
31
|
+
### Enhancement Examples
|
|
32
|
+
|
|
33
|
+
**User asks:** "Build a user authentication system"
|
|
34
|
+
**You do:**
|
|
35
|
+
1. `enhance_prompt("Build a user authentication system")` → gets security-review, new-feature chain
|
|
36
|
+
2. `get_prompt("security-review")` → load security guidance
|
|
37
|
+
3. `run_chain("new-feature")` → follow structured development flow
|
|
38
|
+
4. Build with all context applied
|
|
39
|
+
|
|
40
|
+
**User asks:** "This API is slow, fix it"
|
|
41
|
+
**You do:**
|
|
42
|
+
1. `enhance_prompt("This API is slow, fix it")` → gets deep-debugger, performance patterns
|
|
43
|
+
2. `get_prompt("deep-debugger")` → load systematic debugging methodology
|
|
44
|
+
3. Apply the 5-phase debugging process
|
|
45
|
+
|
|
46
|
+
### Thinking Depth
|
|
47
|
+
|
|
48
|
+
For complex problems, use thinking modifiers:
|
|
49
|
+
- `get_prompt("ultrathink")` - Deep analysis with multiple perspectives
|
|
50
|
+
- `get_prompt("megathink")` - Maximum depth for architecture decisions
|
|
51
|
+
|
|
52
|
+
### Available Tools
|
|
53
|
+
|
|
54
|
+
- `list_prompts` - Browse all available prompts
|
|
55
|
+
- `get_prompt(name)` - Load a specific prompt
|
|
56
|
+
- `search_prompts(query)` - Find relevant prompts
|
|
57
|
+
- `enhance_prompt(request)` - Auto-detect and suggest prompts
|
|
58
|
+
- `run_chain(name)` - Execute multi-step workflows
|
|
59
|
+
- `compose_prompt(prompts[])` - Combine multiple prompts
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Full Integration (Recommended for Teams)
|
|
65
|
+
|
|
66
|
+
For comprehensive integration, add this expanded version:
|
|
67
|
+
|
|
68
|
+
```markdown
|
|
69
|
+
## AI Library Integration
|
|
70
|
+
|
|
71
|
+
You have access to the AI Library MCP server - a curated collection of world-class prompts, skills, and workflows developed to Anthropic engineer standards.
|
|
72
|
+
|
|
73
|
+
### Core Principle
|
|
74
|
+
|
|
75
|
+
**Never work without context.** The library contains hard-won patterns for:
|
|
76
|
+
- Secure, performant code
|
|
77
|
+
- Systematic debugging
|
|
78
|
+
- Thorough code review
|
|
79
|
+
- Production-ready features
|
|
80
|
+
|
|
81
|
+
### Automatic Enhancement Protocol
|
|
82
|
+
|
|
83
|
+
**For EVERY substantial task:**
|
|
84
|
+
|
|
85
|
+
1. **Enhance First**
|
|
86
|
+
- Call `enhance_prompt(user_request)` immediately
|
|
87
|
+
- This detects task type and returns relevant resources
|
|
88
|
+
|
|
89
|
+
2. **Load Resources**
|
|
90
|
+
- Call `get_prompt(name)` for each recommended prompt
|
|
91
|
+
- These contain detailed methodologies and checklists
|
|
92
|
+
|
|
93
|
+
3. **Apply Guidance**
|
|
94
|
+
- Integrate the patterns into your work
|
|
95
|
+
- Follow any checklists or phase structures
|
|
96
|
+
|
|
97
|
+
4. **Use Chains for Multi-Step Work**
|
|
98
|
+
- `run_chain("new-feature")` for feature development
|
|
99
|
+
- `run_chain("bug-fix")` for debugging
|
|
100
|
+
- `run_chain("code-review")` for thorough reviews
|
|
101
|
+
|
|
102
|
+
### Task-Specific Protocols
|
|
103
|
+
|
|
104
|
+
#### Building Features
|
|
105
|
+
```
|
|
106
|
+
enhance_prompt("build X") → new-feature chain, prd-generator
|
|
107
|
+
get_prompt("prd-generator") → create proper requirements
|
|
108
|
+
run_chain("new-feature") → follow implementation phases
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Debugging
|
|
112
|
+
```
|
|
113
|
+
enhance_prompt("fix/debug X") → deep-debugger, systematic approach
|
|
114
|
+
get_prompt("deep-debugger") → 5-phase methodology
|
|
115
|
+
Apply: Observe → Hypothesize → Test → Fix → Verify
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Code Review
|
|
119
|
+
```
|
|
120
|
+
enhance_prompt("review X") → code-review-advanced
|
|
121
|
+
get_prompt("code-review-advanced") → 4-lens analysis
|
|
122
|
+
Check: Correctness → Security → Performance → Maintainability
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Architecture
|
|
126
|
+
```
|
|
127
|
+
enhance_prompt("design/architect X") → megathink, system-design
|
|
128
|
+
get_prompt("megathink") → maximum thinking depth
|
|
129
|
+
Apply structured analysis before any code
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Thinking Depth Modifiers
|
|
133
|
+
|
|
134
|
+
Load these for complex reasoning:
|
|
135
|
+
|
|
136
|
+
| Modifier | When to Use |
|
|
137
|
+
|----------|-------------|
|
|
138
|
+
| `ultrathink` | Multi-file changes, tricky bugs, design decisions |
|
|
139
|
+
| `megathink` | Architecture, security-critical, breaking changes |
|
|
140
|
+
|
|
141
|
+
### Quality Standards
|
|
142
|
+
|
|
143
|
+
When the library prompts specify standards, follow them:
|
|
144
|
+
- Security checklists must pass before completion
|
|
145
|
+
- Performance considerations must be documented
|
|
146
|
+
- Edge cases must be explicitly handled
|
|
147
|
+
- Error handling must be comprehensive
|
|
148
|
+
|
|
149
|
+
### Available Tools Reference
|
|
150
|
+
|
|
151
|
+
| Tool | Purpose |
|
|
152
|
+
|------|---------|
|
|
153
|
+
| `list_prompts` | Browse all prompts by category |
|
|
154
|
+
| `get_prompt(name)` | Load specific prompt content |
|
|
155
|
+
| `search_prompts(query)` | Find prompts by keyword |
|
|
156
|
+
| `enhance_prompt(request)` | Auto-enhance any request |
|
|
157
|
+
| `run_chain(name)` | Execute workflow chains |
|
|
158
|
+
| `compose_prompt(names[])` | Combine multiple prompts |
|
|
159
|
+
| `get_context(name)` | Load stack/pattern guides |
|
|
160
|
+
| `quick_prompt(type, context)` | Generate instant prompts |
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Minimal Integration (Just the Essentials)
|
|
166
|
+
|
|
167
|
+
For quick setup, add just this:
|
|
168
|
+
|
|
169
|
+
```markdown
|
|
170
|
+
## AI Library
|
|
171
|
+
|
|
172
|
+
Use `enhance_prompt(request)` before any substantial task.
|
|
173
|
+
Use `get_prompt("ultrathink")` for complex problems.
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## How It Works
|
|
179
|
+
|
|
180
|
+
### The Enhancement Flow
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
User Request
|
|
184
|
+
↓
|
|
185
|
+
enhance_prompt() ← Detects: building? debugging? reviewing?
|
|
186
|
+
↓
|
|
187
|
+
Returns: Relevant prompts, chains, guidance
|
|
188
|
+
↓
|
|
189
|
+
get_prompt() ← Load each recommended resource
|
|
190
|
+
↓
|
|
191
|
+
Apply patterns to produce better output
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Why This Works
|
|
195
|
+
|
|
196
|
+
1. **No forgotten context** - Enhancement catches what you might miss
|
|
197
|
+
2. **Consistent quality** - Same methodology every time
|
|
198
|
+
3. **Security by default** - Security prompts auto-loaded for auth, data, APIs
|
|
199
|
+
4. **Faster debugging** - Systematic approach beats random trying
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Verification
|
|
204
|
+
|
|
205
|
+
To verify the integration is working:
|
|
206
|
+
|
|
207
|
+
1. Ask Claude to "build a login form"
|
|
208
|
+
2. Claude should automatically call `enhance_prompt`
|
|
209
|
+
3. Claude should load security and feature prompts
|
|
210
|
+
4. The implementation should follow structured methodology
|
|
211
|
+
|
|
212
|
+
If Claude doesn't auto-enhance, ensure:
|
|
213
|
+
- The MCP server is running
|
|
214
|
+
- The CLAUDE.md snippet is in your project
|
|
215
|
+
- You're using a supported Claude interface
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Customization
|
|
220
|
+
|
|
221
|
+
### Add Project-Specific Prompts
|
|
222
|
+
|
|
223
|
+
Extend the library with your patterns:
|
|
224
|
+
|
|
225
|
+
```markdown
|
|
226
|
+
### Project-Specific Enhancement
|
|
227
|
+
|
|
228
|
+
In addition to AI Library tools, also load:
|
|
229
|
+
- Our API design doc at `/docs/api-standards.md`
|
|
230
|
+
- Our component patterns at `/docs/component-guide.md`
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Enforce Specific Standards
|
|
234
|
+
|
|
235
|
+
```markdown
|
|
236
|
+
### Mandatory Standards
|
|
237
|
+
|
|
238
|
+
ALWAYS apply these after enhancement:
|
|
239
|
+
- Run `get_prompt("security-review")` for any auth/data code
|
|
240
|
+
- Use `get_prompt("typescript-react")` for frontend work
|
|
241
|
+
- Apply `get_prompt("code-review-advanced")` before completing PRs
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Troubleshooting
|
|
247
|
+
|
|
248
|
+
**Claude isn't using enhance_prompt automatically**
|
|
249
|
+
- Add explicit instruction: "ALWAYS call enhance_prompt FIRST for any substantial task"
|
|
250
|
+
- Check MCP server is connected in Claude Desktop settings
|
|
251
|
+
|
|
252
|
+
**Prompts aren't loading**
|
|
253
|
+
- Run `list_prompts` to verify server connection
|
|
254
|
+
- Check server logs for errors
|
|
255
|
+
|
|
256
|
+
**Enhancement suggestions don't match task**
|
|
257
|
+
- The `enhance_prompt` tool uses keyword detection
|
|
258
|
+
- For edge cases, manually call `search_prompts(query)`
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# CLAUDE.md - CLI Tool Template
|
|
2
|
+
|
|
3
|
+
> Project context for command-line tools
|
|
4
|
+
|
|
5
|
+
Copy this file to your project root as `CLAUDE.md`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Project: [CLI Name]
|
|
10
|
+
|
|
11
|
+
A command-line tool for [purpose].
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Install dependencies
|
|
17
|
+
npm install
|
|
18
|
+
|
|
19
|
+
# Run in development
|
|
20
|
+
npm run dev -- [command] [args]
|
|
21
|
+
|
|
22
|
+
# Build
|
|
23
|
+
npm run build
|
|
24
|
+
|
|
25
|
+
# Install globally (for testing)
|
|
26
|
+
npm link
|
|
27
|
+
|
|
28
|
+
# Run tests
|
|
29
|
+
npm test
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Tech Stack
|
|
33
|
+
|
|
34
|
+
- **Language**: TypeScript
|
|
35
|
+
- **CLI Framework**: Commander.js / Yargs
|
|
36
|
+
- **Output**: Chalk + Ora (spinners)
|
|
37
|
+
- **Config**: Cosmiconfig
|
|
38
|
+
- **Testing**: Vitest
|
|
39
|
+
|
|
40
|
+
## Project Structure
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
.
|
|
44
|
+
├── src/
|
|
45
|
+
│ ├── index.ts # Entry point
|
|
46
|
+
│ ├── cli.ts # CLI setup and commands
|
|
47
|
+
│ ├── commands/
|
|
48
|
+
│ │ ├── init.ts
|
|
49
|
+
│ │ ├── run.ts
|
|
50
|
+
│ │ └── config.ts
|
|
51
|
+
│ ├── lib/
|
|
52
|
+
│ │ ├── config.ts # Config loading
|
|
53
|
+
│ │ ├── logger.ts # Console output
|
|
54
|
+
│ │ └── utils.ts
|
|
55
|
+
│ └── types/
|
|
56
|
+
│ └── index.ts
|
|
57
|
+
├── tests/
|
|
58
|
+
├── bin/
|
|
59
|
+
│ └── cli.js # Executable entry
|
|
60
|
+
├── package.json
|
|
61
|
+
└── tsconfig.json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## CLI Structure
|
|
65
|
+
|
|
66
|
+
### Entry Point
|
|
67
|
+
```typescript
|
|
68
|
+
// src/cli.ts
|
|
69
|
+
import { Command } from 'commander';
|
|
70
|
+
import { initCommand } from './commands/init';
|
|
71
|
+
import { runCommand } from './commands/run';
|
|
72
|
+
|
|
73
|
+
const program = new Command();
|
|
74
|
+
|
|
75
|
+
program
|
|
76
|
+
.name('mycli')
|
|
77
|
+
.description('Description of what this CLI does')
|
|
78
|
+
.version('1.0.0');
|
|
79
|
+
|
|
80
|
+
program
|
|
81
|
+
.command('init')
|
|
82
|
+
.description('Initialize a new project')
|
|
83
|
+
.option('-t, --template <name>', 'Template to use', 'default')
|
|
84
|
+
.action(initCommand);
|
|
85
|
+
|
|
86
|
+
program
|
|
87
|
+
.command('run <file>')
|
|
88
|
+
.description('Run a file')
|
|
89
|
+
.option('-w, --watch', 'Watch for changes')
|
|
90
|
+
.action(runCommand);
|
|
91
|
+
|
|
92
|
+
program.parse();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Command Pattern
|
|
96
|
+
```typescript
|
|
97
|
+
// src/commands/init.ts
|
|
98
|
+
import { logger } from '../lib/logger';
|
|
99
|
+
import { loadConfig } from '../lib/config';
|
|
100
|
+
|
|
101
|
+
interface InitOptions {
|
|
102
|
+
template: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function initCommand(options: InitOptions) {
|
|
106
|
+
const spinner = logger.spinner('Initializing project...');
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
// Do the work
|
|
110
|
+
await createProject(options.template);
|
|
111
|
+
|
|
112
|
+
spinner.succeed('Project initialized!');
|
|
113
|
+
} catch (error) {
|
|
114
|
+
spinner.fail('Failed to initialize');
|
|
115
|
+
logger.error(error.message);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Logger Utility
|
|
122
|
+
```typescript
|
|
123
|
+
// src/lib/logger.ts
|
|
124
|
+
import chalk from 'chalk';
|
|
125
|
+
import ora from 'ora';
|
|
126
|
+
|
|
127
|
+
export const logger = {
|
|
128
|
+
info: (msg: string) => console.log(chalk.blue('ℹ'), msg),
|
|
129
|
+
success: (msg: string) => console.log(chalk.green('✓'), msg),
|
|
130
|
+
warn: (msg: string) => console.log(chalk.yellow('⚠'), msg),
|
|
131
|
+
error: (msg: string) => console.log(chalk.red('✗'), msg),
|
|
132
|
+
spinner: (msg: string) => ora(msg).start(),
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Configuration Loading
|
|
137
|
+
```typescript
|
|
138
|
+
// src/lib/config.ts
|
|
139
|
+
import { cosmiconfig } from 'cosmiconfig';
|
|
140
|
+
|
|
141
|
+
const explorer = cosmiconfig('mycli');
|
|
142
|
+
|
|
143
|
+
export async function loadConfig() {
|
|
144
|
+
const result = await explorer.search();
|
|
145
|
+
if (!result) {
|
|
146
|
+
return getDefaultConfig();
|
|
147
|
+
}
|
|
148
|
+
return { ...getDefaultConfig(), ...result.config };
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Coding Standards
|
|
153
|
+
|
|
154
|
+
### Error Handling
|
|
155
|
+
```typescript
|
|
156
|
+
// Always exit with proper codes
|
|
157
|
+
process.exit(0); // Success
|
|
158
|
+
process.exit(1); // Error
|
|
159
|
+
|
|
160
|
+
// Catch and format errors
|
|
161
|
+
try {
|
|
162
|
+
await riskyOperation();
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error instanceof UserError) {
|
|
165
|
+
logger.error(error.message);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
// Unexpected error - show stack in debug mode
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### User Prompts
|
|
174
|
+
```typescript
|
|
175
|
+
import { confirm, input, select } from '@inquirer/prompts';
|
|
176
|
+
|
|
177
|
+
const name = await input({ message: 'Project name:' });
|
|
178
|
+
const confirmed = await confirm({ message: 'Continue?' });
|
|
179
|
+
const choice = await select({
|
|
180
|
+
message: 'Select template:',
|
|
181
|
+
choices: [
|
|
182
|
+
{ value: 'basic', name: 'Basic' },
|
|
183
|
+
{ value: 'full', name: 'Full' },
|
|
184
|
+
],
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Progress Indication
|
|
189
|
+
```typescript
|
|
190
|
+
import ora from 'ora';
|
|
191
|
+
|
|
192
|
+
const spinner = ora('Loading...').start();
|
|
193
|
+
// Do work
|
|
194
|
+
spinner.text = 'Processing...';
|
|
195
|
+
// More work
|
|
196
|
+
spinner.succeed('Done!');
|
|
197
|
+
// Or on error
|
|
198
|
+
spinner.fail('Failed');
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Testing CLIs
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
// tests/cli.test.ts
|
|
205
|
+
import { execSync } from 'child_process';
|
|
206
|
+
|
|
207
|
+
describe('CLI', () => {
|
|
208
|
+
it('should show help', () => {
|
|
209
|
+
const output = execSync('node ./bin/cli.js --help').toString();
|
|
210
|
+
expect(output).toContain('Usage:');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should init project', () => {
|
|
214
|
+
const output = execSync('node ./bin/cli.js init --template basic').toString();
|
|
215
|
+
expect(output).toContain('initialized');
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Package.json Setup
|
|
221
|
+
|
|
222
|
+
```json
|
|
223
|
+
{
|
|
224
|
+
"name": "mycli",
|
|
225
|
+
"bin": {
|
|
226
|
+
"mycli": "./bin/cli.js"
|
|
227
|
+
},
|
|
228
|
+
"files": ["bin", "dist"],
|
|
229
|
+
"scripts": {
|
|
230
|
+
"dev": "tsx src/cli.ts",
|
|
231
|
+
"build": "tsc",
|
|
232
|
+
"prepublishOnly": "npm run build"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Executable Entry
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
// bin/cli.js
|
|
241
|
+
#!/usr/bin/env node
|
|
242
|
+
require('../dist/cli.js');
|
|
243
|
+
```
|