Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:42:15 +08:00
commit a6aed6b6ce
7 changed files with 768 additions and 0 deletions

203
commands/create.md Normal file
View File

@@ -0,0 +1,203 @@
---
description: Create a new plugin scaffold with configurable components
argument-hint: [plugin-name]
model: claude-sonnet-4-5-20250929
allowed-tools: Bash, Write, Edit, Read, Glob, AskUserQuestion
---
# Create New Plugin
Generate a new plugin scaffold with configurable components following the SideQuest marketplace patterns.
## Instructions
You are a plugin scaffolding specialist. Create well-structured Claude Code plugins using the established patterns.
### Input
The plugin name is provided as `$1` (or `$ARGUMENTS`).
### Validation
1. **Plugin name** must be in kebab-case format:
- Lowercase letters, numbers, and hyphens only
- Must start with a letter
- No consecutive hyphens
- Examples: `my-plugin`, `code-analyzer`, `git-helper`
2. **Check for conflicts**:
- Verify `plugins/{name}` directory doesn't already exist
- Check marketplace.json for existing plugin with same name
### Step 1: Component Selection
Use `AskUserQuestion` to ask the user which components to include:
**Question**: "Which components should this plugin include?"
| Component | Description |
|-----------|-------------|
| commands | Slash commands (e.g., `/plugin:action`) |
| mcp-server | MCP server with tools for Claude to call |
| hooks | Event hooks (PostToolUse, PreToolUse, etc.) |
| skills | Autonomous capabilities Claude can invoke |
Enable multi-select. Default to all components if user doesn't specify.
### Step 2: Implementation Type Selection
Use `AskUserQuestion` to ask about implementation type:
**Question**: "What implementation type?"
| Type | Description |
|------|-------------|
| Markdown only | Commands/skills are just prompts, no code (stub scripts) |
| TypeScript | Includes CLI tools, utilities, or testable logic (full scripts + src/) |
**Auto-select TypeScript** if `mcp-server` component was chosen (MCP always needs code).
### Directory Structure
Based on selections, create:
```
MARKDOWN ONLY: TYPESCRIPT:
plugins/{name}/ plugins/{name}/
├── .claude-plugin/ ├── .claude-plugin/
│ └── plugin.json │ └── plugin.json
├── package.json ←(stubs) ├── package.json ←(full)
├── commands/ ├── tsconfig.json
│ └── sample.md ├── src/
└── skills/ │ ├── index.ts
└── {name}/ │ └── index.test.ts
└── SKILL.md ├── commands/
│ └── sample.md
└── skills/
└── {name}/
└── SKILL.md
```
### Package.json Differences
**Markdown only (stub scripts):**
```json
{
"scripts": {
"test": "echo 'No tests'",
"typecheck": "echo 'No typecheck'"
}
}
```
**TypeScript (full scripts):**
```json
{
"scripts": {
"test": "bun test --recursive",
"typecheck": "tsc --noEmit",
"format": "biome format --write .",
"lint": "biome lint .",
"check": "biome check --write ."
},
"devDependencies": {
"@types/bun": "latest"
}
}
```
### Author Information
Default to git config:
- Name: `git config user.name`
- Email: `git config user.email`
### File Generation
Use templates from `$PLUGIN_DIR/src/templates.ts`:
1. **package.json**: Use `packageJsonForType()` based on implementation type
2. **plugin.json**: Metadata with name, description, version, author
3. **tsconfig.json**: Only for TypeScript type
4. **src/index.ts**: Only for TypeScript type
5. **src/index.test.ts**: Only for TypeScript type
6. **sample.md**: Command with frontmatter and usage example
7. **index.ts**: MCP server using `mcpez` library
8. **.mcp.json**: Server configuration with `${CLAUDE_PLUGIN_ROOT}`
9. **hooks.json**: Empty hooks structure with comments
10. **SKILL.md**: Skill with frontmatter and instructions
### Marketplace Registration
After generating files, update `.claude-plugin/marketplace.json`:
1. Read current marketplace.json
2. Add new plugin entry to the `plugins` array:
```json
{
"name": "{name}",
"source": "./plugins/{name}",
"description": "{description}",
"version": "1.0.0",
"author": { "name": "{author}" },
"category": "development",
"keywords": ["{name}"]
}
```
3. Write updated marketplace.json
### Post-Generation Steps
After creating the plugin:
1. **Run setup commands** (TypeScript only):
```bash
cd plugins/{name} && bun install
```
2. **Verify generation** (TypeScript only):
```bash
bun test --recursive
```
3. **Output summary**:
- List all created files
- Show implementation type chosen
- Show next steps for the user
- Mention `/plugin-template:strip` if they want to remove TypeScript later
- Mention `/plugin-template:upgrade` if they want to add TypeScript later
### Example Usage
```
User: /plugin-template:create my-awesome-plugin
```
Expected flow:
1. Validate plugin name
2. Ask which components to include (multi-select)
3. Ask implementation type (unless mcp-server forces TypeScript)
4. Create directory structure
5. Generate all files
6. Register in marketplace
7. Run bun install (if TypeScript)
8. Show summary with next steps
### Error Handling
- If plugin name is invalid, explain the format requirements
- If directory already exists, ask user if they want to overwrite
- If marketplace.json update fails, show manual steps
- Always clean up partial generation on failure
### Important Notes
- Follow the @sidequest namespace convention
- Use Biome for formatting (configured in root biome.json)
- MCP servers use mcpez library
- All paths should use `${CLAUDE_PLUGIN_ROOT}` for portability
- Generated code should pass typecheck and lint
- If user chose mcp-server, TypeScript is auto-selected
Now create the plugin scaffold based on the provided name and user preferences.

151
commands/strip.md Normal file
View File

@@ -0,0 +1,151 @@
---
description: Strip TypeScript from a plugin, converting it to markdown-only
argument-hint: [plugin-name]
model: claude-sonnet-4-5-20250929
allowed-tools: Bash, Write, Edit, Read, Glob, AskUserQuestion
---
# Strip TypeScript from Plugin
Remove TypeScript setup from a plugin, converting it to markdown-only mode with stub scripts.
## Instructions
You are a plugin maintenance specialist. Safely strip TypeScript from plugins while preserving markdown content.
### Input
The plugin name is provided as `$1` (or `$ARGUMENTS`).
### Validation
1. **Verify plugin exists**:
- Check `plugins/{name}` directory exists
- If not found, show error and list available plugins
2. **Verify it's a TypeScript plugin**:
- Check for `tsconfig.json` presence
- If already markdown-only, inform user and exit
3. **Check for MCP server**:
- If `mcp-servers/` exists, warn user that MCP requires TypeScript
- Ask if they want to proceed anyway (will break MCP functionality)
### Confirmation Required
**CRITICAL**: Before making any changes, use `AskUserQuestion`:
**Question**: "Are you sure you want to strip TypeScript from '{name}'?"
Show what will be deleted:
- `tsconfig.json`
- `src/` directory (all files)
- `devDependencies` from package.json
Show what will be modified:
- `package.json` scripts will become stubs
Options:
1. **Yes, strip TypeScript** - Proceed with removal
2. **No, cancel** - Abort operation
### Files to Delete
```
plugins/{name}/
├── tsconfig.json ❌ DELETE
└── src/ ❌ DELETE (entire directory)
├── index.ts ❌
├── index.test.ts ❌
└── ... ❌
```
### Files to Modify
**package.json** - Replace scripts with stubs:
Before:
```json
{
"scripts": {
"test": "bun test --recursive",
"typecheck": "tsc --noEmit",
"format": "biome format --write .",
"lint": "biome lint .",
"check": "biome check --write ."
},
"devDependencies": {
"@types/bun": "latest"
}
}
```
After:
```json
{
"scripts": {
"test": "echo 'No tests'",
"typecheck": "echo 'No typecheck'"
}
}
```
### Execution Steps
1. **Confirm with user** (AskUserQuestion)
2. **Delete tsconfig.json**:
```bash
rm plugins/{name}/tsconfig.json
```
3. **Delete src/ directory**:
```bash
rm -rf plugins/{name}/src
```
4. **Update package.json**:
- Read current package.json
- Replace scripts with stub versions
- Remove devDependencies
- Write updated package.json
### Files to Preserve
Do NOT touch these:
- `.claude-plugin/plugin.json`
- `commands/` directory
- `skills/` directory
- `hooks/` directory
- `mcp-servers/` directory (warn but preserve)
- `.mcp.json`
### Output Summary
After stripping:
```
Stripped TypeScript from 'my-plugin'
Deleted:
- tsconfig.json
- src/index.ts
- src/index.test.ts
Modified:
- package.json (scripts now use stubs)
Plugin is now markdown-only.
To add TypeScript back later:
/plugin-template:upgrade my-plugin
```
### Error Handling
- If plugin doesn't exist, list available plugins
- If already markdown-only, inform user (no action needed)
- If deletion fails, show error and rollback suggestions
- If package.json update fails, show manual fix steps
### Example Usage
```
User: /plugin-template:strip my-plugin

166
commands/upgrade.md Normal file
View File

@@ -0,0 +1,166 @@
---
description: Add TypeScript setup to a markdown-only plugin
argument-hint: [plugin-name]
model: claude-sonnet-4-5-20250929
allowed-tools: Bash, Write, Edit, Read, Glob
---
# Upgrade Plugin to TypeScript
Add TypeScript setup to a markdown-only plugin, enabling CLI tools, utilities, and testable logic.
## Instructions
You are a plugin maintenance specialist. Safely upgrade plugins to TypeScript while preserving existing content.
### Input
The plugin name is provided as `$1` (or `$ARGUMENTS`).
### Validation
1. **Verify plugin exists**:
- Check `plugins/{name}` directory exists
- If not found, show error and list available plugins
2. **Verify it's a markdown-only plugin**:
- Check for absence of `tsconfig.json`
- If already TypeScript, inform user and exit
### Files to Create
```
plugins/{name}/
├── tsconfig.json ✨ CREATE
└── src/ ✨ CREATE
├── index.ts ✨ CREATE
└── index.test.ts ✨ CREATE
```
### Files to Modify
**package.json** - Replace stub scripts with full TypeScript scripts:
Before:
```json
{
"scripts": {
"test": "echo 'No tests'",
"typecheck": "echo 'No typecheck'"
}
}
```
After:
```json
{
"scripts": {
"test": "bun test --recursive",
"typecheck": "tsc --noEmit",
"format": "biome format --write .",
"format:check": "biome format .",
"lint": "biome lint .",
"check": "biome check --write ."
},
"devDependencies": {
"@types/bun": "latest"
}
}
```
### Template Content
**tsconfig.json**:
```json
{
"extends": "../../tsconfig.base.json",
"include": ["src/**/*.ts"],
"exclude": ["**/node_modules/**"]
}
```
**src/index.ts** - Use template from `$PLUGIN_DIR/src/templates.ts`:
- Export interface for plugin result type
- Export sample function with JSDoc
- Ready for user to add their logic
**src/index.test.ts** - Use template from `$PLUGIN_DIR/src/templates.ts`:
- Import from bun:test
- Basic test for sample function
- Ready for user to add more tests
### Execution Steps
1. **Create tsconfig.json**
2. **Create src/ directory**
3. **Create src/index.ts** with template
4. **Create src/index.test.ts** with template
5. **Update package.json**:
- Read current package.json
- Add full scripts
- Add devDependencies
- Write updated package.json
6. **Run bun install**
7. **Run tests to verify**
### Files to Preserve
Do NOT touch these:
- `.claude-plugin/plugin.json`
- `commands/` directory
- `skills/` directory
- `hooks/` directory
- `mcp-servers/` directory
- `.mcp.json`
### Post-Upgrade Steps
```bash
cd plugins/{name} && bun install && bun test
```
### Output Summary
After upgrading:
```
Upgraded 'my-plugin' to TypeScript
Created:
- tsconfig.json
- src/index.ts
- src/index.test.ts
Modified:
- package.json (full scripts + devDependencies)
Next steps:
1. Edit src/index.ts to add your logic
2. Add tests to src/index.test.ts
3. Run 'bun test' to verify
To strip TypeScript later:
/plugin-template:strip my-plugin
```
### Error Handling
- If plugin doesn't exist, list available plugins
- If already TypeScript, inform user (no action needed)
- If file creation fails, show error and cleanup steps
- If bun install fails, show manual steps
### Example Usage
```
User: /plugin-template:upgrade my-plugin
```
Expected flow:
1. Validate plugin exists and is markdown-only
2. Create tsconfig.json
3. Create src/index.ts and src/index.test.ts
4. Update package.json with full scripts
5. Run bun install
6. Run bun test to verify
7. Show summary with next steps