forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateSkillDialog.tsx
More file actions
205 lines (188 loc) · 6.39 KB
/
CreateSkillDialog.tsx
File metadata and controls
205 lines (188 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"use client";
import { useState } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { SpinnerGap, Globe, FolderOpen } from "@/components/ui/icon";
import { useTranslation } from "@/hooks/useTranslation";
import { cn } from "@/lib/utils";
interface CreateSkillDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onCreate: (name: string, scope: "global" | "project", content: string) => Promise<void>;
}
const TEMPLATES: { label: string; content: string }[] = [
{ label: "Blank", content: "" },
{
label: "Commit Helper",
content: `# Commit Helper
Review the staged changes and generate a concise, descriptive commit message following conventional commit format.
Rules:
- Use conventional commit prefixes: feat, fix, refactor, docs, test, chore
- Keep the first line under 72 characters
- Add a blank line and detailed description if needed
- Reference relevant issue numbers if applicable
`,
},
{
label: "Code Reviewer",
content: `# Code Reviewer
Review the provided code and give feedback on:
1. **Correctness** - Logic errors, edge cases, potential bugs
2. **Performance** - Inefficiencies, unnecessary allocations
3. **Readability** - Naming, structure, comments where needed
4. **Security** - Input validation, injection risks, data exposure
Be specific with line references. Suggest concrete improvements, not just problems.
`,
},
];
export function CreateSkillDialog({
open,
onOpenChange,
onCreate,
}: CreateSkillDialogProps) {
const { t } = useTranslation();
const [name, setName] = useState("");
const [scope, setScope] = useState<"global" | "project">("project");
const [templateIdx, setTemplateIdx] = useState(0);
const [creating, setCreating] = useState(false);
const [error, setError] = useState("");
const handleCreate = async () => {
const trimmed = name.trim();
if (!trimmed) {
setError(t('skills.nameRequired'));
return;
}
if (!/^[a-zA-Z0-9_-]+$/.test(trimmed)) {
setError(t('skills.nameInvalid'));
return;
}
setCreating(true);
setError("");
try {
await onCreate(trimmed, scope, TEMPLATES[templateIdx].content);
// Reset on success
setName("");
setScope("project");
setTemplateIdx(0);
onOpenChange(false);
} catch (err) {
setError(err instanceof Error ? err.message : "Failed to create skill");
} finally {
setCreating(false);
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>{t('skills.createSkill')}</DialogTitle>
<DialogDescription>
Create a new slash command skill. It will be saved as a .md file.
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-2">
{/* Name input */}
<div className="space-y-2">
<Label htmlFor="skill-name">{t('skills.skillName')}</Label>
<div className="flex items-center gap-1">
<span className="text-sm text-muted-foreground">/</span>
<Input
id="skill-name"
placeholder="my-skill"
value={name}
onChange={(e) => {
setName(e.target.value);
setError("");
}}
onKeyDown={(e) => {
if (e.key === "Enter") handleCreate();
}}
/>
</div>
</div>
{/* Scope selection */}
<div className="space-y-2">
<Label>{t('skills.scope')}</Label>
<div className="flex gap-2">
<Button
variant="outline"
onClick={() => setScope("project")}
className={cn(
"flex-1 justify-start",
scope === "project"
? "border-primary/50 bg-primary/10 text-primary"
: "border-border hover:bg-accent"
)}
>
<FolderOpen size={16} />
{t('skills.project')}
</Button>
<Button
variant="outline"
onClick={() => setScope("global")}
className={cn(
"flex-1 justify-start",
scope === "global"
? "border-status-success-border bg-status-success-muted text-status-success-foreground"
: "border-border hover:bg-accent"
)}
>
<Globe size={16} />
{t('skills.global')}
</Button>
</div>
<p className="text-xs text-muted-foreground">
{scope === "project"
? "Saved in .claude/commands/ (this project only)"
: "Saved in ~/.claude/commands/ (available everywhere)"}
</p>
</div>
{/* Template selection */}
<div className="space-y-2">
<Label>{t('skills.template')}</Label>
<div className="flex gap-2 flex-wrap">
{TEMPLATES.map((tpl, i) => (
<Button
key={tpl.label}
variant="outline"
size="xs"
onClick={() => setTemplateIdx(i)}
className={cn(
templateIdx === i
? "border-primary bg-primary/10 text-primary"
: "border-border hover:bg-accent"
)}
>
{tpl.label}
</Button>
))}
</div>
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => onOpenChange(false)}
disabled={creating}
>
{t('common.cancel')}
</Button>
<Button onClick={handleCreate} disabled={creating} className="gap-2">
{creating && <SpinnerGap size={16} className="animate-spin" />}
{t('skills.createSkill')}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}