Skills: manage and import your own, switch on per chat, search instead of listing
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e150de3c93
commit
a84a3acaa0
20 files changed
+943
-26
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { useState } from "react";
|
||||
import { patch } from "../api";
|
||||
import { toast } from "../dialogs";
|
||||
import { useFetch } from "../hooks";
|
||||
import { useT } from "../i18n";
|
||||
import { Spinner } from "./Activity";
|
||||
import { Icon } from "./Icon";
|
||||
|
||||
interface SkillInfo {
|
||||
name: string;
|
||||
description: string;
|
||||
files: string[];
|
||||
user?: boolean;
|
||||
}
|
||||
|
||||
/** Switch skills on for one chat: their full instructions go into every turn. */
|
||||
export function ChatSkillsDialog({ sessionId, cwd, active, onClose }: { sessionId: string; cwd: string; active: string[]; onClose: () => void }) {
|
||||
const t = useT();
|
||||
const { data } = useFetch<{ skills: SkillInfo[] }>(`/commands?cwd=${encodeURIComponent(cwd)}`);
|
||||
const [picked, setPicked] = useState<string[]>(active);
|
||||
const [filter, setFilter] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const all = data?.skills ?? [];
|
||||
// Chosen skills first, then the rest.
|
||||
const shown = all
|
||||
.filter((s) => !filter.trim() || `${s.name} ${s.description}`.toLowerCase().includes(filter.trim().toLowerCase()))
|
||||
.sort((a, b) => Number(picked.includes(b.name)) - Number(picked.includes(a.name)) || a.name.localeCompare(b.name));
|
||||
const toggle = (n: string) => setPicked((p) => (p.includes(n) ? p.filter((x) => x !== n) : [...p, n]));
|
||||
const save = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await patch(`/sessions/${sessionId}`, { skills: picked });
|
||||
onClose();
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop" onClick={onClose}>
|
||||
<div className="modal draft-modal" role="dialog" aria-label={t("skills.chatTitle")} onClick={(e) => e.stopPropagation()}>
|
||||
<h3>{t("skills.chatTitle")}</h3>
|
||||
<div className="hint" style={{ marginBottom: 8 }}>
|
||||
{t("skills.chatHint")}
|
||||
</div>
|
||||
{!data ? (
|
||||
<Spinner />
|
||||
) : all.length === 0 ? (
|
||||
<div className="empty">{t("skills.empty")}</div>
|
||||
) : (
|
||||
<>
|
||||
{all.length > 6 && <input autoFocus style={{ width: "100%" }} placeholder={t("skills.filter")} value={filter} onChange={(e) => setFilter(e.target.value)} />}
|
||||
<div className="issue-list">
|
||||
{shown.map((s) => (
|
||||
<label key={s.name} className="row" style={{ gap: 8, alignItems: "flex-start", padding: "2px 0" }}>
|
||||
<input type="checkbox" checked={picked.includes(s.name)} onChange={() => toggle(s.name)} />
|
||||
<span>
|
||||
<code>{s.name}</code>
|
||||
{s.files.length > 0 && <span className="hint"> · {t("skills.files", { n: s.files.length })}</span>}
|
||||
<div className="hint">{s.description}</div>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
{picked.length > 4 && <div className="notice">{t("skills.manyActive")}</div>}
|
||||
</>
|
||||
)}
|
||||
<div className="row" style={{ marginTop: 10, justifyContent: "flex-end", gap: 6 }}>
|
||||
<button onClick={onClose} disabled={busy}>
|
||||
{t("common.cancel")}
|
||||
</button>
|
||||
<button className="primary" onClick={() => void save()} disabled={busy}>
|
||||
{busy ? <Spinner small /> : <Icon name="check" />} {t("common.save")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { Composer } from "./Composer";
|
||||
import { ShareDialog } from "./ShareDialog";
|
||||
import { RenameDialog } from "./RenameDialog";
|
||||
import { InstructionsDialog } from "./InstructionsDialog";
|
||||
import { ChatSkillsDialog } from "./ChatSkills";
|
||||
import { RegenerateButton } from "./Regenerate";
|
||||
import { WorktreeChip } from "./WorktreeChip";
|
||||
import { QueueList } from "./QueueList";
|
||||
@@ -565,6 +566,7 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
|
||||
// The Telegram switch in the ⋯ menu only matters with a paired bot.
|
||||
const telegramPaired = useFetch<{ paired: boolean }>("/account/telegram").data?.paired ?? false;
|
||||
const [editingInstructions, setEditingInstructions] = useState(false);
|
||||
const [pickingSkills, setPickingSkills] = useState(false);
|
||||
const [showApprovals, setShowApprovals] = useState(false);
|
||||
const [planning, setPlanning] = useState(false);
|
||||
const models = useModels();
|
||||
@@ -823,6 +825,11 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
|
||||
<Icon name="edit" /> {t("instructions.chip")}
|
||||
</button>
|
||||
)}
|
||||
{!!session.skills?.length && (
|
||||
<button className="chip" style={{ border: "none" }} onClick={() => !readOnly && setPickingSkills(true)} title={session.skills.join(", ")}>
|
||||
<Icon name="scroll" /> {t("skills.chip", { n: session.skills.length })}
|
||||
</button>
|
||||
)}
|
||||
{readOnly && <span className="chip">{t("chat.readOnly")}</span>}
|
||||
{!readOnly && (
|
||||
<>
|
||||
@@ -886,6 +893,16 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
|
||||
>
|
||||
<Icon name="edit" /> {t("instructions.title")}
|
||||
</a>
|
||||
<a
|
||||
href="#"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
(e.currentTarget.closest("details") as HTMLDetailsElement).open = false;
|
||||
setPickingSkills(true);
|
||||
}}
|
||||
>
|
||||
<Icon name="scroll" /> {t("skills.chatTitle")}
|
||||
</a>
|
||||
<ColorSwatches value={session.color} onChange={(color) => void update({ color })} />
|
||||
<IconPicker value={session.icon} color={session.color} onChange={(icon) => void update({ icon })} />
|
||||
<a href="#" onClick={(e) => (e.preventDefault(), ((e.currentTarget.closest("details") as HTMLDetailsElement).open = false), void planJob())} title={t("job.planHint")}>
|
||||
@@ -1086,6 +1103,7 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
|
||||
)}
|
||||
</div>
|
||||
{showApprovals && <ProjectPermissions sessionId={sessionId} cwd={session.cwd} onClose={() => setShowApprovals(false)} />}
|
||||
{pickingSkills && <ChatSkillsDialog sessionId={sessionId} cwd={session.cwd} active={session.skills ?? []} onClose={() => setPickingSkills(false)} />}
|
||||
{editingInstructions && <InstructionsDialog sessionId={sessionId} value={session.instructions ?? ""} onClose={() => setEditingInstructions(false)} />}
|
||||
{editingTitle && <RenameDialog sessionId={sessionId} title={session.title} onClose={() => setEditingTitle(false)} />}
|
||||
{sharing && <ShareDialog sessionId={sessionId} onClose={() => setSharing(false)} />}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { Folders } from "./settings/Folders";
|
||||
import { Users } from "./settings/Users";
|
||||
import { Audit } from "./settings/Audit";
|
||||
import { Tools } from "./settings/Tools";
|
||||
import { Skills } from "./settings/Skills";
|
||||
import { confirmDialog, promptDialog, toast } from "../dialogs";
|
||||
|
||||
type Json = any;
|
||||
@@ -1088,8 +1089,8 @@ function Raw({ reload }: { reload: () => void }) {
|
||||
|
||||
// --- page -------------------------------------------------------------------
|
||||
|
||||
const ADMIN_TABS = ["general", "providers", "agents", "mcp", "permissions", "users", "folders", "tools", "audit", "templates", "modes", "account", "raw"] as const;
|
||||
const USER_TABS = ["general", "templates", "modes", "account"] as const;
|
||||
const ADMIN_TABS = ["general", "providers", "agents", "mcp", "permissions", "users", "folders", "tools", "audit", "templates", "modes", "skills", "account", "raw"] as const;
|
||||
const USER_TABS = ["general", "templates", "modes", "skills", "account"] as const;
|
||||
const TAB_ICONS: Record<string, string> = {
|
||||
general: "gear",
|
||||
providers: "brain",
|
||||
@@ -1102,6 +1103,7 @@ const TAB_ICONS: Record<string, string> = {
|
||||
audit: "scroll",
|
||||
templates: "template",
|
||||
modes: "sparkle",
|
||||
skills: "scroll",
|
||||
account: "user",
|
||||
raw: "file-text",
|
||||
};
|
||||
@@ -1139,6 +1141,7 @@ export function Settings({ tab, onMenu }: { tab?: string; onMenu: () => void })
|
||||
{active === "account" && <Account />}
|
||||
{active === "templates" && <Templates />}
|
||||
{active === "modes" && <PersonalModes />}
|
||||
{active === "skills" && <Skills />}
|
||||
{cfg && active === "users" && <Users />}
|
||||
{cfg && active === "folders" && <Folders />}
|
||||
{cfg && active === "audit" && <Audit />}
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
import { useState } from "react";
|
||||
import { del, get, post, put } from "../../api";
|
||||
import { confirmDialog, promptDialog, toast } from "../../dialogs";
|
||||
import { useFetch } from "../../hooks";
|
||||
import { useT } from "../../i18n";
|
||||
import { Icon } from "../Icon";
|
||||
import { Spinner } from "../Activity";
|
||||
|
||||
interface SkillInfo {
|
||||
name: string;
|
||||
description: string;
|
||||
files: string[];
|
||||
}
|
||||
interface SkillFile {
|
||||
path: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
const TEMPLATE = `---
|
||||
name: my-skill
|
||||
description: When to use this skill, in one or two sentences
|
||||
---
|
||||
|
||||
# Instructions
|
||||
|
||||
Describe what the agent should do.
|
||||
`;
|
||||
|
||||
/** The user's own skills: SKILL.md plus further files; created here or imported from GitHub. */
|
||||
export function Skills() {
|
||||
const t = useT();
|
||||
const { data, reload } = useFetch<{ skills: SkillInfo[] }>("/skills");
|
||||
const [editing, setEditing] = useState<{ name: string; isNew: boolean }>();
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [filter, setFilter] = useState("");
|
||||
const list = (data?.skills ?? []).filter((s) => !filter.trim() || `${s.name} ${s.description}`.toLowerCase().includes(filter.trim().toLowerCase()));
|
||||
|
||||
const remove = async (s: SkillInfo) => {
|
||||
if (!(await confirmDialog({ message: t("skills.confirmDelete", { name: s.name }), danger: true }))) return;
|
||||
try {
|
||||
await del(`/skills/${s.name}`);
|
||||
reload();
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="panel">
|
||||
<h3>
|
||||
<Icon name="sparkle" /> {t("skills.title")}
|
||||
</h3>
|
||||
<div className="hint" style={{ marginBottom: 8 }}>
|
||||
{t("skills.hint")}
|
||||
</div>
|
||||
<div className="row" style={{ gap: 6, marginBottom: 8 }}>
|
||||
<button className="primary" onClick={() => setEditing({ name: "", isNew: true })}>
|
||||
<Icon name="plus" /> {t("skills.new")}
|
||||
</button>
|
||||
<button onClick={() => setImporting(true)}>
|
||||
<Icon name="git" /> {t("skills.import")}
|
||||
</button>
|
||||
<span className="spacer" />
|
||||
{(data?.skills.length ?? 0) > 8 && <input placeholder={t("skills.filter")} value={filter} onChange={(e) => setFilter(e.target.value)} />}
|
||||
</div>
|
||||
{!data ? (
|
||||
<Spinner />
|
||||
) : list.length === 0 ? (
|
||||
<div className="empty">{t("skills.empty")}</div>
|
||||
) : (
|
||||
list.map((s) => (
|
||||
<div key={s.name} className="row" style={{ gap: 8, padding: "6px 0", borderBottom: "1px solid var(--border)" }}>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<code>{s.name}</code>
|
||||
{s.files.length > 0 && <span className="chip" style={{ marginLeft: 6 }}>{t("skills.files", { n: s.files.length })}</span>}
|
||||
<div className="hint" style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
|
||||
{s.description}
|
||||
</div>
|
||||
</div>
|
||||
<button className="small" onClick={() => setEditing({ name: s.name, isNew: false })}>
|
||||
<Icon name="edit" /> {t("common.edit")}
|
||||
</button>
|
||||
<button className="small danger" onClick={() => void remove(s)} aria-label={t("common.delete")}>
|
||||
<Icon name="trash" />
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
{editing && (
|
||||
<SkillEditor
|
||||
name={editing.name}
|
||||
isNew={editing.isNew}
|
||||
onClose={(saved) => {
|
||||
setEditing(undefined);
|
||||
if (saved) reload();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{importing && (
|
||||
<ImportDialog
|
||||
onClose={(done) => {
|
||||
setImporting(false);
|
||||
if (done) reload();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SkillEditor({ name: initial, isNew, onClose }: { name: string; isNew: boolean; onClose: (saved: boolean) => void }) {
|
||||
const t = useT();
|
||||
const [name, setName] = useState(initial);
|
||||
const [files, setFiles] = useState<SkillFile[]>(isNew ? [{ path: "SKILL.md", content: TEMPLATE }] : []);
|
||||
const [loaded, setLoaded] = useState(isNew);
|
||||
const [current, setCurrent] = useState("SKILL.md");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string>();
|
||||
|
||||
useState(() => {
|
||||
if (!isNew)
|
||||
get<{ files: SkillFile[] }>(`/skills/${initial}`)
|
||||
.then((d) => (setFiles(d.files), setLoaded(true)))
|
||||
.catch((e) => (setError(e.message), setLoaded(true)));
|
||||
});
|
||||
|
||||
const file = files.find((f) => f.path === current) ?? files[0];
|
||||
const setContent = (content: string) => setFiles(files.map((f) => (f.path === file?.path ? { ...f, content } : f)));
|
||||
const addFile = async () => {
|
||||
const p = await promptDialog({ message: t("skills.addFile"), placeholder: "references/guide.md", confirmLabel: t("common.add") });
|
||||
const path = p?.trim().replace(/^\/+/, "");
|
||||
if (!path) return;
|
||||
if (files.some((f) => f.path === path)) return setCurrent(path);
|
||||
setFiles([...files, { path, content: "" }]);
|
||||
setCurrent(path);
|
||||
};
|
||||
const removeFile = () => {
|
||||
if (!file || file.path === "SKILL.md") return;
|
||||
setFiles(files.filter((f) => f.path !== file.path));
|
||||
setCurrent("SKILL.md");
|
||||
};
|
||||
const save = async () => {
|
||||
setBusy(true);
|
||||
setError(undefined);
|
||||
try {
|
||||
await put(`/skills/${name.trim()}`, { files });
|
||||
onClose(true);
|
||||
} catch (e: any) {
|
||||
setError(e.message);
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop">
|
||||
<div className="modal draft-modal" role="dialog" aria-label={t("skills.edit")}>
|
||||
<h3>{isNew ? t("skills.new") : t("skills.edit")}</h3>
|
||||
{!loaded ? (
|
||||
<Spinner />
|
||||
) : (
|
||||
<>
|
||||
<label style={{ display: "block", marginBottom: 8 }}>
|
||||
<span className="hint">{t("skills.name")}</span>
|
||||
<input className="mono" style={{ width: "100%" }} value={name} disabled={!isNew} placeholder="frontend" onChange={(e) => setName(e.target.value.toLowerCase().replace(/[^a-z0-9_-]/g, "-"))} />
|
||||
</label>
|
||||
<div className="row" style={{ gap: 4, flexWrap: "wrap", marginBottom: 6 }}>
|
||||
{files.map((f) => (
|
||||
<button key={f.path} className={`small ${f.path === file?.path ? "primary" : ""}`} onClick={() => setCurrent(f.path)}>
|
||||
{f.path}
|
||||
</button>
|
||||
))}
|
||||
<button className="small ghost" onClick={() => void addFile()}>
|
||||
<Icon name="plus" /> {t("skills.file")}
|
||||
</button>
|
||||
{file && file.path !== "SKILL.md" && (
|
||||
<button className="small danger" onClick={removeFile} aria-label={t("common.delete")}>
|
||||
<Icon name="trash" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<textarea className="mono" rows={18} style={{ width: "100%" }} value={file?.content ?? ""} onChange={(e) => setContent(e.target.value)} spellCheck={false} />
|
||||
<div className="hint">{t("skills.fileHint")}</div>
|
||||
</>
|
||||
)}
|
||||
{error && <div className="notice err">{error}</div>}
|
||||
<div className="row" style={{ marginTop: 10, justifyContent: "flex-end", gap: 6 }}>
|
||||
<button onClick={() => onClose(false)} disabled={busy}>
|
||||
{t("common.cancel")}
|
||||
</button>
|
||||
<button className="primary" onClick={() => void save()} disabled={busy || !loaded || !name.trim() || !files.some((f) => f.path === "SKILL.md")}>
|
||||
{busy ? <Spinner small /> : <Icon name="check" />} {t("common.save")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface Found {
|
||||
path: string;
|
||||
name: string;
|
||||
files: number;
|
||||
}
|
||||
|
||||
function ImportDialog({ onClose }: { onClose: (done: boolean) => void }) {
|
||||
const t = useT();
|
||||
const [url, setUrl] = useState("");
|
||||
const [found, setFound] = useState<Found[]>();
|
||||
const [picked, setPicked] = useState<Set<string>>(new Set());
|
||||
const [filter, setFilter] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string>();
|
||||
|
||||
const scan = async () => {
|
||||
setBusy(true);
|
||||
setError(undefined);
|
||||
try {
|
||||
const r = await post<{ skills: Found[] }>("/skills/github/scan", { url: url.trim() });
|
||||
setFound(r.skills);
|
||||
setPicked(new Set());
|
||||
if (r.skills.length === 0) setError(t("skills.noneFound"));
|
||||
} catch (e: any) {
|
||||
setError(e.message);
|
||||
}
|
||||
setBusy(false);
|
||||
};
|
||||
const shown = (found ?? []).filter((s) => !filter.trim() || s.path.toLowerCase().includes(filter.trim().toLowerCase()));
|
||||
const toggle = (p: string) => setPicked((s) => (s.has(p) ? new Set([...s].filter((x) => x !== p)) : new Set(s).add(p)));
|
||||
const run = async () => {
|
||||
setBusy(true);
|
||||
setError(undefined);
|
||||
try {
|
||||
const r = await post<{ saved: unknown[]; skipped: { path: string; why: string }[] }>("/skills/github/import", { url: url.trim(), paths: [...picked] });
|
||||
toast(t("skills.imported", { n: r.saved.length }) + (r.skipped.length ? ` (${r.skipped.length} ${t("skills.skipped")})` : ""), "success");
|
||||
onClose(true);
|
||||
} catch (e: any) {
|
||||
setError(e.message);
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop">
|
||||
<div className="modal draft-modal" role="dialog" aria-label={t("skills.import")}>
|
||||
<h3>{t("skills.import")}</h3>
|
||||
<div className="hint" style={{ marginBottom: 8 }}>
|
||||
{t("skills.importHint")}
|
||||
</div>
|
||||
<div className="row" style={{ gap: 6 }}>
|
||||
<input className="mono" style={{ flex: 1 }} value={url} placeholder="https://github.com/owner/repo/tree/main/skills" onChange={(e) => setUrl(e.target.value)} onKeyDown={(e) => e.key === "Enter" && url.trim() && !busy && void scan()} />
|
||||
<button onClick={() => void scan()} disabled={busy || !url.trim()}>
|
||||
{busy && !found ? <Spinner small /> : <Icon name="search" />} {t("skills.scan")}
|
||||
</button>
|
||||
</div>
|
||||
{found && found.length > 0 && (
|
||||
<>
|
||||
<div className="row" style={{ gap: 6, margin: "8px 0" }}>
|
||||
<input style={{ flex: 1 }} placeholder={t("skills.filter")} value={filter} onChange={(e) => setFilter(e.target.value)} />
|
||||
<button className="small" onClick={() => setPicked(new Set([...picked, ...shown.map((s) => s.path)]))}>
|
||||
{t("skills.selectShown", { n: shown.length })}
|
||||
</button>
|
||||
<button className="small ghost" onClick={() => setPicked(new Set())}>
|
||||
{t("skills.selectNone")}
|
||||
</button>
|
||||
</div>
|
||||
<div className="issue-list">
|
||||
{shown.map((s) => (
|
||||
<label key={s.path} className="row" style={{ gap: 8, padding: "2px 0" }}>
|
||||
<input type="checkbox" checked={picked.has(s.path)} onChange={() => toggle(s.path)} />
|
||||
<span>
|
||||
<code>{s.name}</code> <span className="hint">{s.path} · {t("skills.files", { n: s.files })}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{error && <div className="notice err">{error}</div>}
|
||||
<div className="row" style={{ marginTop: 10, justifyContent: "flex-end", gap: 6 }}>
|
||||
<button onClick={() => onClose(false)} disabled={busy}>
|
||||
{t("common.cancel")}
|
||||
</button>
|
||||
<button className="primary" onClick={() => void run()} disabled={busy || picked.size === 0}>
|
||||
{busy && found ? <Spinner small /> : <Icon name="check" />} {t("skills.importN", { n: picked.size })}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user